[BACK]Return to client.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cvs

Annotation of src/usr.bin/cvs/client.c, Revision 1.32

1.32    ! xsa         1: /*     $OpenBSD: client.c,v 1.31 2006/12/15 08:26:18 xsa Exp $ */
1.1       jfb         2: /*
1.9       joris       3:  * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
1.1       jfb         4:  *
1.9       joris       5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1       jfb        16:  */
                     17:
1.9       joris      18: #include "includes.h"
1.1       jfb        19:
                     20: #include "cvs.h"
                     21: #include "log.h"
1.9       joris      22: #include "diff.h"
                     23: #include "remote.h"
1.1       jfb        24:
1.9       joris      25: struct cvs_req cvs_requests[] = {
                     26:        /* this is what our client will use, the server should support it */
                     27:        { "Root",               1,      cvs_server_root, REQ_NEEDED },
                     28:        { "Valid-responses",    1,      cvs_server_validresp, REQ_NEEDED },
                     29:        { "valid-requests",     1,      cvs_server_validreq, REQ_NEEDED },
                     30:        { "Directory",          0,      cvs_server_directory, REQ_NEEDED },
1.32    ! xsa        31:        { "Static-directory",   0,      cvs_server_static_directory, REQ_NEEDED },
1.30      xsa        32:        { "Sticky",             0,      cvs_server_sticky, REQ_NEEDED },
1.9       joris      33:        { "Entry",              0,      cvs_server_entry, REQ_NEEDED },
                     34:        { "Modified",           0,      cvs_server_modified, REQ_NEEDED },
                     35:        { "UseUnchanged",       0,      cvs_server_useunchanged, REQ_NEEDED },
                     36:        { "Unchanged",          0,      cvs_server_unchanged, REQ_NEEDED },
                     37:        { "Questionable",       0,      cvs_server_questionable, REQ_NEEDED },
                     38:        { "Argument",           0,      cvs_server_argument, REQ_NEEDED },
1.24      xsa        39:        { "Argumentx",          0,      cvs_server_argumentx, REQ_NEEDED },
                     40:        { "Global_option",      0,      cvs_server_globalopt, REQ_NEEDED },
1.26      xsa        41:        { "Set",                0,      cvs_server_set, REQ_NEEDED },
1.1       jfb        42:
1.9       joris      43:        /*
                     44:         * used to tell the server what is going on in our
                     45:         * working copy, unsupported until we are told otherwise
                     46:         */
                     47:        { "Max-dotdot",                 0,      NULL, 0 },
                     48:        { "Checkin-prog",               0,      NULL, 0 },
                     49:        { "Update-prog",                0,      NULL, 0 },
                     50:        { "Kopt",                       0,      NULL, 0 },
                     51:        { "Checkin-time",               0,      NULL, 0 },
                     52:        { "Is-modified",                0,      NULL, 0 },
                     53:        { "Notify",                     0,      NULL, 0 },
                     54:        { "Case",                       0,      NULL, 0 },
                     55:        { "Gzip-stream",                0,      NULL, 0 },
1.25      xsa        56:        { "wrapper-sendme-rcsOptions",  0,      NULL, 0 },
1.9       joris      57:        { "Kerberos-encrypt",           0,      NULL, 0 },
                     58:        { "Gssapi-encrypt",             0,      NULL, 0 },
                     59:        { "Gssapi-authenticate",        0,      NULL, 0 },
                     60:        { "expand-modules",             0,      NULL, 0 },
                     61:
                     62:        /* commands that might be supported */
                     63:        { "ci",                         0,      cvs_server_commit, 0 },
                     64:        { "co",                         0,      NULL, 0 },
1.25      xsa        65:        { "update",                     0,      cvs_server_update, 0 },
1.9       joris      66:        { "diff",                       0,      cvs_server_diff, 0 },
1.25      xsa        67:        { "log",                        0,      cvs_server_log, 0 },
                     68:        { "rlog",                       0,      NULL, 0 },
                     69:        { "add",                        0,      cvs_server_add, 0 },
                     70:        { "remove",                     0,      cvs_server_remove, 0 },
                     71:        { "update-patches",             0,      NULL, 0 },
                     72:        { "gzip-file-contents",         0,      NULL, 0 },
1.9       joris      73:        { "status",                     0,      cvs_server_status, 0 },
                     74:        { "rdiff",                      0,      NULL, 0 },
1.25      xsa        75:        { "tag",                        0,      cvs_server_tag, 0 },
1.9       joris      76:        { "rtag",                       0,      NULL, 0 },
                     77:        { "import",                     0,      NULL, 0 },
1.25      xsa        78:        { "admin",                      0,      cvs_server_admin, 0 },
                     79:        { "export",                     0,      NULL, 0 },
                     80:        { "history",                    0,      NULL, 0 },
                     81:        { "release",                    0,      NULL, 0 },
1.9       joris      82:        { "watch-on",                   0,      NULL, 0 },
                     83:        { "watch-off",                  0,      NULL, 0 },
                     84:        { "watch-add",                  0,      NULL, 0 },
                     85:        { "watch-remove",               0,      NULL, 0 },
1.25      xsa        86:        { "watchers",                   0,      NULL, 0 },
                     87:        { "editors",                    0,      NULL, 0 },
                     88:        { "init",                       0,      cvs_server_init, 0 },
1.27      xsa        89:        { "annotate",                   0,      cvs_server_annotate, 0 },
1.25      xsa        90:        { "rannotate",                  0,      NULL, 0 },
1.9       joris      91:        { "noop",                       0,      NULL, 0 },
1.25      xsa        92:        { "version",                    0,      cvs_server_version, 0 },
1.9       joris      93:        { "",                           -1,     NULL, 0 }
                     94: };
                     95:
1.16      xsa        96: static void     client_check_directory(char *);
                     97: static char    *client_get_supported_responses(void);
                     98: static char    *lastdir = NULL;
                     99: static int      end_of_response = 0;
                    100:
                    101: static void    cvs_client_initlog(void);
                    102:
                    103: /*
                    104:  * File descriptors for protocol logging when the CVS_CLIENT_LOG environment
                    105:  * variable is set.
                    106:  */
                    107: static int     cvs_client_logon = 0;
                    108: static int     cvs_client_inlog_fd = -1;
                    109: static int     cvs_client_outlog_fd = -1;
                    110:
1.9       joris     111:
                    112: static char *
                    113: client_get_supported_responses(void)
                    114: {
                    115:        BUF *bp;
                    116:        char *d;
                    117:        int i, first;
                    118:
                    119:        first = 0;
                    120:        bp = cvs_buf_alloc(512, BUF_AUTOEXT);
                    121:        for (i = 0; cvs_responses[i].supported != -1; i++) {
                    122:                if (cvs_responses[i].hdlr == NULL)
                    123:                        continue;
                    124:
                    125:                if (first != 0)
                    126:                        cvs_buf_append(bp, " ", 1);
                    127:                else
                    128:                        first++;
                    129:                cvs_buf_append(bp, cvs_responses[i].name,
                    130:                    strlen(cvs_responses[i].name));
                    131:        }
                    132:
                    133:        cvs_buf_putc(bp, '\0');
                    134:        d = cvs_buf_release(bp);
                    135:        return (d);
                    136: }
1.1       jfb       137:
1.10      joris     138: static void
                    139: client_check_directory(char *data)
                    140: {
                    141:        int l;
                    142:        CVSENTRIES *entlist;
                    143:        char *entry, *parent, *base;
                    144:
                    145:        STRIP_SLASH(data);
                    146:
                    147:        cvs_mkpath(data);
                    148:
                    149:        if ((base = basename(data)) == NULL)
                    150:                fatal("client_check_directory: overflow");
                    151:
                    152:        if ((parent = dirname(data)) == NULL)
                    153:                fatal("client_check_directory: overflow");
1.11      joris     154:
                    155:        if (!strcmp(parent, "."))
                    156:                return;
1.10      joris     157:
                    158:        entry = xmalloc(CVS_ENT_MAXLINELEN);
                    159:        l = snprintf(entry, CVS_ENT_MAXLINELEN, "D/%s////", base);
                    160:        if (l == -1 || l >= CVS_ENT_MAXLINELEN)
                    161:                fatal("client_check_directory: overflow");
                    162:
                    163:        entlist = cvs_ent_open(parent);
                    164:        cvs_ent_add(entlist, entry);
                    165:        cvs_ent_close(entlist, ENT_SYNC);
                    166:
                    167:        xfree(entry);
                    168: }
                    169:
1.9       joris     170: void
                    171: cvs_client_connect_to_server(void)
                    172: {
1.26      xsa       173:        struct cvs_var *vp;
1.9       joris     174:        char *cmd, *argv[9], *resp;
                    175:        int ifd[2], ofd[2], argc;
1.1       jfb       176:
1.9       joris     177:        switch (current_cvsroot->cr_method) {
                    178:        case CVS_METHOD_PSERVER:
                    179:        case CVS_METHOD_KSERVER:
                    180:        case CVS_METHOD_GSERVER:
                    181:        case CVS_METHOD_FORK:
                    182:        case CVS_METHOD_EXT:
1.14      joris     183:                fatal("the specified connection method is not supported");
1.9       joris     184:        default:
                    185:                break;
                    186:        }
                    187:
                    188:        if (pipe(ifd) == -1)
                    189:                fatal("cvs_client_connect: %s", strerror(errno));
                    190:        if (pipe(ofd) == -1)
                    191:                fatal("cvs_client_connect: %s", strerror(errno));
                    192:
                    193:        switch (fork()) {
                    194:        case -1:
                    195:                fatal("cvs_client_connect: fork failed: %s", strerror(errno));
                    196:        case 0:
                    197:                if (dup2(ifd[0], STDIN_FILENO) == -1)
                    198:                        fatal("cvs_client_connect: %s", strerror(errno));
                    199:                if (dup2(ofd[1], STDOUT_FILENO) == -1)
                    200:                        fatal("cvs_client_connect: %s", strerror(errno));
1.1       jfb       201:
1.9       joris     202:                close(ifd[1]);
                    203:                close(ofd[0]);
1.1       jfb       204:
1.9       joris     205:                if ((cmd = getenv("CVS_SERVER")) == NULL)
                    206:                        cmd = CVS_SERVER_DEFAULT;
1.1       jfb       207:
                    208:                argc = 0;
                    209:                argv[argc++] = cvs_rsh;
                    210:
1.9       joris     211:                if (current_cvsroot->cr_user != NULL) {
1.1       jfb       212:                        argv[argc++] = "-l";
1.9       joris     213:                        argv[argc++] = current_cvsroot->cr_user;
1.1       jfb       214:                }
                    215:
1.9       joris     216:                argv[argc++] = current_cvsroot->cr_host;
                    217:                argv[argc++] = cmd;
1.1       jfb       218:                argv[argc++] = "server";
                    219:                argv[argc] = NULL;
                    220:
1.9       joris     221:                cvs_log(LP_TRACE, "connecting to server %s",
                    222:                    current_cvsroot->cr_host);
                    223:
1.1       jfb       224:                execvp(argv[0], argv);
1.9       joris     225:                fatal("cvs_client_connect: failed to execute cvs server");
                    226:        default:
                    227:                break;
1.1       jfb       228:        }
                    229:
1.9       joris     230:        close(ifd[0]);
                    231:        close(ofd[1]);
                    232:
                    233:        if ((current_cvsroot->cr_srvin = fdopen(ifd[1], "w")) == NULL)
                    234:                fatal("cvs_client_connect: %s", strerror(errno));
                    235:        if ((current_cvsroot->cr_srvout = fdopen(ofd[0], "r")) == NULL)
                    236:                fatal("cvs_client_connect: %s", strerror(errno));
1.1       jfb       237:
1.9       joris     238:        setvbuf(current_cvsroot->cr_srvin, NULL,_IOLBF, 0);
                    239:        setvbuf(current_cvsroot->cr_srvout, NULL, _IOLBF, 0);
1.1       jfb       240:
1.16      xsa       241:        cvs_client_initlog();
                    242:
1.18      xsa       243:        if (cvs_cmdop != CVS_OP_INIT)
                    244:                cvs_client_send_request("Root %s", current_cvsroot->cr_dir);
1.1       jfb       245:
1.9       joris     246:        resp = client_get_supported_responses();
                    247:        cvs_client_send_request("Valid-responses %s", resp);
                    248:        xfree(resp);
1.1       jfb       249:
1.9       joris     250:        cvs_client_send_request("valid-requests");
                    251:        cvs_client_get_responses();
1.1       jfb       252:
1.28      xsa       253:        cvs_client_send_request("UseUnchanged");
                    254:
1.20      xsa       255:        if (cvs_nolog == 1)
                    256:                cvs_client_send_request("Global_option -l");
                    257:
1.19      xsa       258:        if (cvs_noexec == 1)
                    259:                cvs_client_send_request("Global_option -n");
                    260:
                    261:        if (verbosity == 0)
                    262:                cvs_client_send_request("Global_option -Q");
1.20      xsa       263:
                    264:        /* Be quiet. This is the default in OpenCVS. */
                    265:        cvs_client_send_request("Global_option -q");
1.19      xsa       266:
                    267:        if (cvs_readonly == 1)
                    268:                cvs_client_send_request("Global_option -r");
                    269:
                    270:        if (cvs_trace == 1)
1.9       joris     271:                cvs_client_send_request("Global_option -t");
1.1       jfb       272:
1.9       joris     273:        if (verbosity == 2)
                    274:                cvs_client_send_request("Global_option -V");
1.26      xsa       275:
                    276:        /* XXX: If 'Set' is supported? */
                    277:        TAILQ_FOREACH(vp, &cvs_variables, cv_link)
                    278:                cvs_client_send_request("Set %s=%s", vp->cv_name, vp->cv_val);
1.1       jfb       279: }
                    280:
1.9       joris     281: void
                    282: cvs_client_send_request(char *fmt, ...)
                    283: {
                    284:        va_list ap;
                    285:        char *data, *s;
                    286:        struct cvs_req *req;
                    287:
                    288:        va_start(ap, fmt);
                    289:        vasprintf(&data, fmt, ap);
                    290:        va_end(ap);
1.1       jfb       291:
1.9       joris     292:        if ((s = strchr(data, ' ')) != NULL)
                    293:                *s = '\0';
1.1       jfb       294:
1.9       joris     295:        req = cvs_remote_get_request_info(data);
                    296:        if (req == NULL)
                    297:                fatal("'%s' is an unknown request", data);
1.1       jfb       298:
1.9       joris     299:        if (req->supported != 1)
                    300:                fatal("remote cvs server does not support '%s'", data);
1.1       jfb       301:
1.9       joris     302:        if (s != NULL)
                    303:                *s = ' ';
1.1       jfb       304:
1.12      joris     305:        cvs_log(LP_TRACE, "%s", data);
1.16      xsa       306:
                    307:        if (cvs_client_inlog_fd != -1) {
                    308:                BUF *bp;
                    309:
                    310:                bp = cvs_buf_alloc(strlen(data), BUF_AUTOEXT);
                    311:
                    312:                if (cvs_buf_append(bp, data, strlen(data)) < 0)
                    313:                        fatal("cvs_client_send_request: cvs_buf_append");
                    314:
                    315:                cvs_buf_putc(bp, '\n');
                    316:
                    317:                if (cvs_buf_write_fd(bp, cvs_client_inlog_fd) < 0)
                    318:                        fatal("cvs_client_send_request: cvs_buf_write_fd");
                    319:
                    320:                cvs_buf_free(bp);
                    321:        }
                    322:
1.9       joris     323:        cvs_remote_output(data);
                    324:        xfree(data);
                    325: }
1.1       jfb       326:
1.9       joris     327: void
                    328: cvs_client_read_response(void)
1.1       jfb       329: {
1.9       joris     330:        char *cmd, *data;
                    331:        struct cvs_resp *resp;
1.1       jfb       332:
1.9       joris     333:        cmd = cvs_remote_input();
                    334:        if ((data = strchr(cmd, ' ')) != NULL)
                    335:                (*data++) = '\0';
1.1       jfb       336:
1.9       joris     337:        resp = cvs_remote_get_response_info(cmd);
                    338:        if (resp == NULL)
                    339:                fatal("response '%s' is not supported by our client", cmd);
1.1       jfb       340:
1.9       joris     341:        if (resp->hdlr == NULL)
                    342:                fatal("opencvs client does not support '%s'", cmd);
1.1       jfb       343:
1.16      xsa       344:        if (cvs_client_outlog_fd != -1) {
                    345:                BUF *bp;
                    346:
                    347:                bp = cvs_buf_alloc(strlen(cmd), BUF_AUTOEXT);
                    348:
                    349:                if (cvs_buf_append(bp, cmd, strlen(cmd)) < 0)
                    350:                        fatal("cvs_client_read_response: cvs_buf_append");
                    351:
                    352:                if (cvs_buf_append(bp,
                    353:                    (data == NULL) ? "" : " ",
                    354:                    (data == NULL) ? 0 : 1) < 0) {
                    355:                        fatal("cvs_client_read_response: cvs_buf_append");
                    356:                }
                    357:
                    358:                if (cvs_buf_append(bp,
                    359:                    (data == NULL) ? "" : data,
                    360:                    (data == NULL) ? 0 : strlen(data)) < 0) {
                    361:                        fatal("cvs_client_read_response: cvs_buf_append");
                    362:                }
                    363:
                    364:                cvs_buf_putc(bp, '\n');
                    365:
                    366:                if (cvs_buf_write_fd(bp, cvs_client_outlog_fd) < 0)
                    367:                        fatal("cvs_client_read_response: cvs_buf_write_fd");
                    368:
                    369:                cvs_buf_free(bp);
                    370:        }
                    371:
1.9       joris     372:        (*resp->hdlr)(data);
1.16      xsa       373:
1.9       joris     374:        xfree(cmd);
1.1       jfb       375: }
                    376:
1.9       joris     377: void
                    378: cvs_client_get_responses(void)
                    379: {
                    380:        while (end_of_response != 1)
                    381:                cvs_client_read_response();
1.1       jfb       382:
1.9       joris     383:        end_of_response = 0;
                    384: }
1.1       jfb       385:
1.9       joris     386: void
                    387: cvs_client_senddir(const char *dir)
1.1       jfb       388: {
1.29      xsa       389:        int nb;
                    390:        char *d, *date, *repo, *tag;
                    391:
                    392:        d = NULL;
1.9       joris     393:
                    394:        if (lastdir != NULL && !strcmp(dir, lastdir))
                    395:                return;
1.1       jfb       396:
1.9       joris     397:        repo = xmalloc(MAXPATHLEN);
                    398:        cvs_get_repository_path(dir, repo, MAXPATHLEN);
1.31      xsa       399:
                    400:        cvs_client_send_request("Directory %s\n%s", dir, repo);
                    401:
1.9       joris     402:        xfree(repo);
1.29      xsa       403:
                    404:        d = xstrdup(dir);
                    405:        cvs_parse_tagfile(d, &tag, &date, &nb);
                    406:
                    407:        if (tag != NULL || date != NULL) {
                    408:                char buf[128];
                    409:
                    410:                if (tag != NULL && nb != NULL) {
                    411:                        if (strlcpy(buf, "N", sizeof(buf)) >= sizeof(buf))
                    412:                                fatal("cvs_client_senddir: truncation");
                    413:                } else if (tag != NULL) {
                    414:                        if (strlcpy(buf, "T", sizeof(buf)) >= sizeof(buf))
                    415:                                fatal("cvs_client_senddir: truncation");
                    416:                } else {
                    417:                        if (strlcpy(buf, "D", sizeof(buf)) >= sizeof(buf))
                    418:                                fatal("cvs_client_senddir: truncation");
                    419:                }
                    420:
                    421:                if (strlcat(buf, tag ? tag : date, sizeof(buf)) >= sizeof(buf))
                    422:                        fatal("cvs_client_senddir: truncation");
                    423:
                    424:                cvs_client_send_request("Sticky %s", buf);
                    425:
                    426:                if (tag != NULL)
                    427:                        xfree(tag);
                    428:                if (date != NULL)
                    429:                        xfree(date);
                    430:        }
                    431:        if (d != NULL)
                    432:                xfree(d);
1.1       jfb       433:
1.9       joris     434:        if (lastdir != NULL)
                    435:                xfree(lastdir);
                    436:        lastdir = xstrdup(dir);
                    437: }
1.1       jfb       438:
1.9       joris     439: void
                    440: cvs_client_sendfile(struct cvs_file *cf)
1.1       jfb       441: {
1.9       joris     442:        int l;
                    443:        size_t len;
                    444:        char rev[16], timebuf[64], sticky[32];
1.1       jfb       445:
1.9       joris     446:        if (cf->file_type != CVS_FILE)
                    447:                return;
1.1       jfb       448:
1.9       joris     449:        cvs_client_senddir(cf->file_wd);
                    450:        cvs_remote_classify_file(cf);
                    451:
1.10      joris     452:        if (cf->file_type == CVS_DIR)
                    453:                return;
                    454:
1.9       joris     455:        if (cf->file_ent != NULL) {
                    456:                if (cf->file_status == FILE_ADDED) {
                    457:                        len = strlcpy(rev, "0", sizeof(rev));
                    458:                        if (len >= sizeof(rev))
                    459:                                fatal("cvs_client_sendfile: truncation");
                    460:
                    461:                        len = strlcpy(timebuf, "Initial ", sizeof(timebuf));
                    462:                        if (len >= sizeof(timebuf))
                    463:                                fatal("cvs_client_sendfile: truncation");
                    464:
                    465:                        len = strlcat(timebuf, cf->file_name, sizeof(timebuf));
                    466:                        if (len >= sizeof(timebuf))
                    467:                                fatal("cvs_client_sendfile: truncation");
                    468:                } else {
                    469:                        rcsnum_tostr(cf->file_ent->ce_rev, rev, sizeof(rev));
                    470:                        ctime_r(&cf->file_ent->ce_mtime, timebuf);
                    471:                }
1.1       jfb       472:
1.9       joris     473:                if (cf->file_ent->ce_conflict == NULL) {
                    474:                        if (timebuf[strlen(timebuf) - 1] == '\n')
                    475:                                timebuf[strlen(timebuf) - 1] = '\0';
                    476:                } else {
                    477:                        len = strlcpy(timebuf, cf->file_ent->ce_conflict,
                    478:                            sizeof(timebuf));
                    479:                        if (len >= sizeof(timebuf))
                    480:                                fatal("cvs_client_sendfile: truncation");
                    481:                }
1.1       jfb       482:
1.9       joris     483:                sticky[0] = '\0';
                    484:                if (cf->file_ent->ce_tag != NULL) {
                    485:                        l = snprintf(sticky, sizeof(sticky), "T%s",
                    486:                            cf->file_ent->ce_tag);
                    487:                        if (l == -1 || l >= (int)sizeof(sticky))
                    488:                                fatal("cvs_client_sendfile: overflow");
1.1       jfb       489:                }
                    490:
1.13      joris     491:                cvs_client_send_request("Entry /%s/%s%s/%s//%s",
1.9       joris     492:                    cf->file_name, (cf->file_status == FILE_REMOVED) ? "-" : "",
                    493:                   rev, timebuf, sticky);
                    494:        }
                    495:
                    496:        switch (cf->file_status) {
                    497:        case FILE_UNKNOWN:
                    498:                if (cf->fd != -1)
                    499:                        cvs_client_send_request("Questionable %s",
                    500:                            cf->file_name);
                    501:                break;
                    502:        case FILE_ADDED:
                    503:        case FILE_MODIFIED:
                    504:                cvs_client_send_request("Modified %s", cf->file_name);
                    505:                cvs_remote_send_file(cf->file_path);
                    506:                break;
                    507:        case FILE_UPTODATE:
                    508:                cvs_client_send_request("Unchanged %s", cf->file_name);
                    509:                break;
1.1       jfb       510:        }
1.9       joris     511: }
1.1       jfb       512:
1.9       joris     513: void
                    514: cvs_client_send_files(char **argv, int argc)
                    515: {
                    516:        int i;
1.1       jfb       517:
1.9       joris     518:        for (i = 0; i < argc; i++)
                    519:                cvs_client_send_request("Argument %s", argv[i]);
                    520: }
1.1       jfb       521:
1.9       joris     522: void
                    523: cvs_client_ok(char *data)
                    524: {
                    525:        end_of_response = 1;
1.1       jfb       526: }
                    527:
1.9       joris     528: void
                    529: cvs_client_error(char *data)
                    530: {
                    531:        end_of_response = 1;
                    532: }
1.1       jfb       533:
1.9       joris     534: void
                    535: cvs_client_validreq(char *data)
1.1       jfb       536: {
1.9       joris     537:        int i;
                    538:        char *sp, *ep;
                    539:        struct cvs_req *req;
                    540:
                    541:        sp = data;
                    542:        do {
                    543:                if ((ep = strchr(sp, ' ')) != NULL)
                    544:                        *ep = '\0';
                    545:
                    546:                req = cvs_remote_get_request_info(sp);
                    547:                if (req != NULL)
                    548:                        req->supported = 1;
                    549:
                    550:                if (ep != NULL)
                    551:                        sp = ep + 1;
                    552:        } while (ep != NULL);
                    553:
                    554:        for (i = 0; cvs_requests[i].supported != -1; i++) {
                    555:                req = &cvs_requests[i];
                    556:                if ((req->flags & REQ_NEEDED) &&
                    557:                    req->supported != 1) {
                    558:                        fatal("server does not support required '%s'",
                    559:                            req->name);
                    560:                }
1.1       jfb       561:        }
1.9       joris     562: }
1.1       jfb       563:
1.9       joris     564: void
                    565: cvs_client_e(char *data)
                    566: {
                    567:        cvs_printf("%s\n", data);
                    568: }
1.1       jfb       569:
1.9       joris     570: void
                    571: cvs_client_m(char *data)
                    572: {
                    573:        cvs_printf("%s\n", data);
                    574: }
1.1       jfb       575:
1.9       joris     576: void
                    577: cvs_client_checkedin(char *data)
                    578: {
                    579:        int l;
                    580:        CVSENTRIES *entlist;
                    581:        struct cvs_ent *ent, *newent;
                    582:        char *dir, *entry, rev[16], timebuf[64], sticky[16];
1.1       jfb       583:
1.9       joris     584:        dir = cvs_remote_input();
                    585:        entry = cvs_remote_input();
                    586:        xfree(dir);
1.1       jfb       587:
1.9       joris     588:        entlist = cvs_ent_open(data);
                    589:        newent = cvs_ent_parse(entry);
                    590:        ent = cvs_ent_get(entlist, newent->ce_name);
                    591:        xfree(entry);
1.1       jfb       592:
1.9       joris     593:        entry = xmalloc(CVS_ENT_MAXLINELEN);
1.1       jfb       594:
1.9       joris     595:        rcsnum_tostr(newent->ce_rev, rev, sizeof(rev));
                    596:        ctime_r(&ent->ce_mtime, timebuf);
                    597:        if (timebuf[strlen(timebuf) - 1] == '\n')
                    598:                timebuf[strlen(timebuf) - 1] = '\0';
1.1       jfb       599:
1.9       joris     600:        sticky[0] = '\0';
                    601:        if (ent->ce_tag != NULL) {
                    602:                l = snprintf(sticky, sizeof(sticky), "T%s", ent->ce_tag);
                    603:                if (l == -1 || l >= (int)sizeof(sticky))
                    604:                        fatal("cvs_client_checkedin: overflow");
1.2       jfb       605:        }
1.1       jfb       606:
1.9       joris     607:        l = snprintf(entry, CVS_ENT_MAXLINELEN, "/%s/%s/%s//%s/",
                    608:            newent->ce_name, rev, timebuf, sticky);
                    609:        if (l == -1 || l >= CVS_ENT_MAXLINELEN)
                    610:                fatal("cvs_client_checkedin: overflow");
                    611:
                    612:        cvs_ent_free(ent);
                    613:        cvs_ent_free(newent);
                    614:        cvs_ent_add(entlist, entry);
                    615:        cvs_ent_close(entlist, ENT_SYNC);
1.1       jfb       616:
1.9       joris     617:        xfree(entry);
1.1       jfb       618: }
                    619:
1.9       joris     620: void
                    621: cvs_client_updated(char *data)
                    622: {
                    623:        BUF *bp;
                    624:        int l, fd;
                    625:        time_t now;
                    626:        mode_t fmode;
                    627:        size_t flen;
                    628:        CVSENTRIES *ent;
                    629:        struct cvs_ent *e;
                    630:        const char *errstr;
                    631:        struct timeval tv[2];
                    632:        char timebuf[32], *repo, *rpath, *entry, *mode;
                    633:        char revbuf[32], *len, *fpath, *wdir;
                    634:
1.10      joris     635:        client_check_directory(data);
1.9       joris     636:
                    637:        rpath = cvs_remote_input();
                    638:        entry = cvs_remote_input();
                    639:        mode = cvs_remote_input();
                    640:        len = cvs_remote_input();
                    641:
                    642:        repo = xmalloc(MAXPATHLEN);
                    643:        cvs_get_repository_path(".", repo, MAXPATHLEN);
                    644:
                    645:        if (strlen(repo) + 1 > strlen(rpath))
                    646:                fatal("received a repository path that is too short");
                    647:
                    648:        fpath = rpath + strlen(repo) + 1;
                    649:        if ((wdir = dirname(fpath)) == NULL)
                    650:                fatal("cvs_client_updated: dirname: %s", strerror(errno));
                    651:        xfree(repo);
                    652:
                    653:        flen = strtonum(len, 0, INT_MAX, &errstr);
                    654:        if (errstr != NULL)
                    655:                fatal("cvs_client_updated: %s: %s", len, errstr);
                    656:        xfree(len);
                    657:
                    658:        cvs_strtomode(mode, &fmode);
                    659:        xfree(mode);
                    660:
                    661:        time(&now);
                    662:        now = cvs_hack_time(now, 0);
                    663:        ctime_r(&now, timebuf);
                    664:        if (timebuf[strlen(timebuf) - 1] == '\n')
                    665:                timebuf[strlen(timebuf) - 1] = '\0';
                    666:
                    667:        e = cvs_ent_parse(entry);
                    668:        xfree(entry);
                    669:        rcsnum_tostr(e->ce_rev, revbuf, sizeof(revbuf));
                    670:        entry = xmalloc(CVS_ENT_MAXLINELEN);
                    671:        l = snprintf(entry, CVS_ENT_MAXLINELEN, "/%s/%s/%s//", e->ce_name,
                    672:            revbuf, timebuf);
                    673:        if (l == -1 || l >= CVS_ENT_MAXLINELEN)
                    674:                fatal("cvs_client_updated: overflow");
                    675:
                    676:        cvs_ent_free(e);
                    677:        ent = cvs_ent_open(wdir);
                    678:        cvs_ent_add(ent, entry);
                    679:        cvs_ent_close(ent, ENT_SYNC);
                    680:        xfree(entry);
                    681:
                    682:        bp = cvs_remote_receive_file(flen);
                    683:        if ((fd = open(fpath, O_CREAT | O_WRONLY | O_TRUNC)) == -1)
                    684:                fatal("cvs_client_updated: open: %s: %s",
                    685:                    fpath, strerror(errno));
1.1       jfb       686:
1.9       joris     687:        if (cvs_buf_write_fd(bp, fd) == -1)
                    688:                fatal("cvs_client_updated: cvs_buf_write_fd failed for %s",
                    689:                    fpath);
1.1       jfb       690:
1.9       joris     691:        cvs_buf_free(bp);
1.1       jfb       692:
1.9       joris     693:        now = cvs_hack_time(now, 0);
                    694:        tv[0].tv_sec = now;
                    695:        tv[0].tv_usec = 0;
                    696:        tv[1] = tv[0];
1.1       jfb       697:
1.9       joris     698:        if (futimes(fd, tv) == -1)
                    699:                fatal("cvs_client_updated: futimes: %s", strerror(errno));
1.1       jfb       700:
1.9       joris     701:        if (fchmod(fd, fmode) == -1)
                    702:                fatal("cvs_client_updated: fchmod: %s", strerror(errno));
1.1       jfb       703:
1.9       joris     704:        (void)close(fd);
1.1       jfb       705:
1.9       joris     706:        xfree(rpath);
1.1       jfb       707: }
                    708:
1.9       joris     709: void
                    710: cvs_client_merged(char *data)
                    711: {
                    712: }
1.1       jfb       713:
1.9       joris     714: void
                    715: cvs_client_removed(char *data)
                    716: {
1.13      joris     717:        char *dir;
                    718:
                    719:        dir = cvs_remote_input();
                    720:        xfree(dir);
1.9       joris     721: }
1.1       jfb       722:
1.9       joris     723: void
                    724: cvs_client_remove_entry(char *data)
1.1       jfb       725: {
1.9       joris     726:        char *dir;
1.1       jfb       727:
1.9       joris     728:        dir = cvs_remote_input();
                    729:        xfree(dir);
1.16      xsa       730: }
                    731: /*
                    732:  * cvs_client_initlog()
                    733:  *
                    734:  * Initialize protocol logging if the CVS_CLIENT_LOG environment variable is
                    735:  * set.  In this case, the variable's value is used as a path to which the
                    736:  * appropriate suffix is added (".in" for client input and ".out" for server
                    737:  * output).
                    738:  */
                    739: static void
                    740: cvs_client_initlog(void)
                    741: {
                    742:        int l;
                    743:        u_int i;
                    744:        char *env, *envdup, buf[MAXPATHLEN], fpath[MAXPATHLEN];
                    745:        char rpath[MAXPATHLEN], *s;
                    746:        struct stat st;
                    747:        time_t now;
                    748:        struct passwd *pwd;
                    749:
                    750:        /* avoid doing it more than once */
                    751:        if (cvs_client_logon)
                    752:                return;
                    753:
                    754:        if ((env = getenv("CVS_CLIENT_LOG")) == NULL)
                    755:                return;
                    756:
                    757:        envdup = xstrdup(env);
                    758:        if ((s = strchr(envdup, '%')) != NULL)
                    759:                *s = '\0';
                    760:
                    761:        if (strlcpy(buf, env, sizeof(buf)) >= sizeof(buf))
                    762:                fatal("cvs_client_initlog: truncation");
                    763:
                    764:        if (strlcpy(rpath, envdup, sizeof(rpath)) >= sizeof(rpath))
                    765:                fatal("cvs_client_initlog: truncation");
                    766:
                    767:        xfree(envdup);
                    768:
                    769:        s = buf;
                    770:        while ((s = strchr(s, '%')) != NULL) {
                    771:                s++;
                    772:                switch (*s) {
                    773:                case 'c':
                    774:                        if (strlcpy(fpath, cvs_command, sizeof(fpath)) >=
                    775:                            sizeof(fpath))
                    776:                                fatal("cvs_client_initlog: truncation");
                    777:                        break;
                    778:                case 'd':
                    779:                        time(&now);
                    780:                        if (strlcpy(fpath, ctime(&now), sizeof(fpath)) >=
                    781:                            sizeof(fpath))
                    782:                                fatal("cvs_client_initlog: truncation");
                    783:                        break;
                    784:                case 'p':
                    785:                        snprintf(fpath, sizeof(fpath), "%d", getpid());
                    786:                        break;
                    787:                case 'u':
                    788:                        if ((pwd = getpwuid(getuid())) != NULL) {
                    789:                                if (strlcpy(fpath, pwd->pw_name,
                    790:                                    sizeof(fpath)) >= sizeof(fpath))
                    791:                                        fatal("cvs_client_initlog: truncation");
                    792:                        } else {
                    793:                                fpath[0] = '\0';
                    794:                        }
                    795:                        endpwent();
                    796:                        break;
                    797:                default:
                    798:                        fpath[0] = '\0';
                    799:                        break;
                    800:                }
                    801:
                    802:                if (fpath[0] != '\0') {
                    803:                        if (strlcat(rpath, "-", sizeof(rpath)) >= sizeof(rpath))
                    804:                                fatal("cvs_client_initlog: truncation");
                    805:
                    806:                        if (strlcat(rpath, fpath, sizeof(rpath))
                    807:                            >= sizeof(rpath))
                    808:                                fatal("cvs_client_initlog: truncation");
                    809:                }
                    810:        }
                    811:
                    812:        for (i = 0; i < UINT_MAX; i++) {
                    813:                l = snprintf(fpath, sizeof(fpath), "%s-%d.in", rpath, i);
                    814:                if (l == -1 || l >= (int)sizeof(fpath))
                    815:                        fatal("cvs_client_initlog: overflow");
                    816:
                    817:                if (stat(fpath, &st) != -1)
                    818:                        continue;
                    819:
                    820:                if (errno != ENOENT)
                    821:                        fatal("cvs_client_initlog() stat failed '%s'",
                    822:                            strerror(errno));
                    823:
                    824:                break;
                    825:        }
                    826:
                    827:        if ((cvs_client_inlog_fd = open(fpath,
                    828:            O_RDWR | O_CREAT | O_TRUNC, 0644)) == NULL) {
                    829:                fatal("cvs_client_initlog: open `%s': %s",
                    830:                    fpath, strerror(errno));
                    831:        }
                    832:
                    833:        for (i = 0; i < UINT_MAX; i++) {
                    834:                l = snprintf(fpath, sizeof(fpath), "%s-%d.out", rpath, i);
                    835:                if (l == -1 || l >= (int)sizeof(fpath))
                    836:                        fatal("cvs_client_initlog: overflow");
                    837:
                    838:                if (stat(fpath, &st) != -1)
                    839:                        continue;
                    840:
                    841:                if (errno != ENOENT)
                    842:                        fatal("cvs_client_initlog() stat failed '%s'",
                    843:                            strerror(errno));
                    844:
                    845:                break;
                    846:        }
                    847:
                    848:        if ((cvs_client_outlog_fd = open(fpath,
                    849:            O_RDWR | O_CREAT | O_TRUNC, 0644)) == NULL) {
                    850:                fatal("cvs_client_initlog: open `%s': %s",
                    851:                    fpath, strerror(errno));
                    852:        }
                    853:
                    854:        cvs_client_logon = 1;
1.1       jfb       855: }