[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.15

1.15    ! xsa         1: /*     $OpenBSD: client.c,v 1.14 2006/07/20 15:14:22 joris 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:        { "Global_option",      0,      cvs_server_globalopt, REQ_NEEDED },
                     31:        { "Directory",          0,      cvs_server_directory, REQ_NEEDED },
                     32:        { "Entry",              0,      cvs_server_entry, REQ_NEEDED },
                     33:        { "Modified",           0,      cvs_server_modified, REQ_NEEDED },
                     34:        { "UseUnchanged",       0,      cvs_server_useunchanged, REQ_NEEDED },
                     35:        { "Unchanged",          0,      cvs_server_unchanged, REQ_NEEDED },
                     36:        { "Questionable",       0,      cvs_server_questionable, REQ_NEEDED },
                     37:        { "Argument",           0,      cvs_server_argument, REQ_NEEDED },
1.1       jfb        38:
1.9       joris      39:        /*
                     40:         * used to tell the server what is going on in our
                     41:         * working copy, unsupported until we are told otherwise
                     42:         */
                     43:        { "Max-dotdot",                 0,      NULL, 0 },
                     44:        { "Static-directory",           0,      NULL, 0 },
                     45:        { "Sticky",                     0,      NULL, 0 },
                     46:        { "Checkin-prog",               0,      NULL, 0 },
                     47:        { "Update-prog",                0,      NULL, 0 },
                     48:        { "Kopt",                       0,      NULL, 0 },
                     49:        { "Checkin-time",               0,      NULL, 0 },
                     50:        { "Is-modified",                0,      NULL, 0 },
                     51:        { "Notify",                     0,      NULL, 0 },
                     52:        { "Case",                       0,      NULL, 0 },
                     53:        { "Argumentx",                  0,      NULL, 0 },
                     54:        { "Gzip-stream",                0,      NULL, 0 },
                     55:        { "Kerberos-encrypt",           0,      NULL, 0 },
                     56:        { "Gssapi-encrypt",             0,      NULL, 0 },
                     57:        { "Gssapi-authenticate",        0,      NULL, 0 },
                     58:        { "Set",                        0,      NULL, 0 },
                     59:        { "expand-modules",             0,      NULL, 0 },
                     60:
                     61:        /* commands that might be supported */
                     62:        { "ci",                         0,      cvs_server_commit, 0 },
                     63:        { "co",                         0,      NULL, 0 },
                     64:        { "diff",                       0,      cvs_server_diff, 0 },
                     65:        { "tag",                        0,      NULL, 0 },
                     66:        { "status",                     0,      cvs_server_status, 0 },
                     67:        { "admin",                      0,      NULL, 0 },
                     68:        { "history",                    0,      NULL, 0 },
                     69:        { "watchers",                   0,      NULL, 0 },
                     70:        { "editors",                    0,      NULL, 0 },
                     71:        { "annotate",                   0,      NULL, 0 },
                     72:        { "log",                        0,      cvs_server_log, 0 },
                     73:        { "export",                     0,      NULL, 0 },
                     74:        { "rdiff",                      0,      NULL, 0 },
                     75:        { "rtag",                       0,      NULL, 0 },
                     76:        { "init",                       0,      NULL, 0 },
                     77:        { "update",                     0,      cvs_server_update, 0 },
                     78:        { "import",                     0,      NULL, 0 },
1.15    ! xsa        79:        { "add",                        0,      cvs_server_add, 0 },
        !            80:        { "remove",                     0,      cvs_server_remove, 0 },
1.9       joris      81:        { "watch-on",                   0,      NULL, 0 },
                     82:        { "watch-off",                  0,      NULL, 0 },
                     83:        { "watch-add",                  0,      NULL, 0 },
                     84:        { "watch-remove",               0,      NULL, 0 },
                     85:        { "release",                    0,      NULL, 0 },
                     86:        { "noop",                       0,      NULL, 0 },
                     87:        { "update-patches",             0,      NULL, 0 },
                     88:        { "gzip-file-contents",         0,      NULL, 0 },
                     89:        { "wrapper-sendme-rcsOptions",  0,      NULL, 0 },
                     90:        { "",                           -1,     NULL, 0 }
                     91: };
                     92:
1.10      joris      93: static void client_check_directory(char *);
1.9       joris      94: static char *client_get_supported_responses(void);
                     95: static char *lastdir = NULL;
                     96: static int end_of_response = 0;
                     97:
                     98: static char *
                     99: client_get_supported_responses(void)
                    100: {
                    101:        BUF *bp;
                    102:        char *d;
                    103:        int i, first;
                    104:
                    105:        first = 0;
                    106:        bp = cvs_buf_alloc(512, BUF_AUTOEXT);
                    107:        for (i = 0; cvs_responses[i].supported != -1; i++) {
                    108:                if (cvs_responses[i].hdlr == NULL)
                    109:                        continue;
                    110:
                    111:                if (first != 0)
                    112:                        cvs_buf_append(bp, " ", 1);
                    113:                else
                    114:                        first++;
                    115:                cvs_buf_append(bp, cvs_responses[i].name,
                    116:                    strlen(cvs_responses[i].name));
                    117:        }
                    118:
                    119:        cvs_buf_putc(bp, '\0');
                    120:        d = cvs_buf_release(bp);
                    121:        return (d);
                    122: }
1.1       jfb       123:
1.10      joris     124: static void
                    125: client_check_directory(char *data)
                    126: {
                    127:        int l;
                    128:        CVSENTRIES *entlist;
                    129:        char *entry, *parent, *base;
                    130:
                    131:        STRIP_SLASH(data);
                    132:
                    133:        cvs_mkpath(data);
                    134:
                    135:        if ((base = basename(data)) == NULL)
                    136:                fatal("client_check_directory: overflow");
                    137:
                    138:        if ((parent = dirname(data)) == NULL)
                    139:                fatal("client_check_directory: overflow");
1.11      joris     140:
                    141:        if (!strcmp(parent, "."))
                    142:                return;
1.10      joris     143:
                    144:        entry = xmalloc(CVS_ENT_MAXLINELEN);
                    145:        l = snprintf(entry, CVS_ENT_MAXLINELEN, "D/%s////", base);
                    146:        if (l == -1 || l >= CVS_ENT_MAXLINELEN)
                    147:                fatal("client_check_directory: overflow");
                    148:
                    149:        entlist = cvs_ent_open(parent);
                    150:        cvs_ent_add(entlist, entry);
                    151:        cvs_ent_close(entlist, ENT_SYNC);
                    152:
                    153:        xfree(entry);
                    154: }
                    155:
1.9       joris     156: void
                    157: cvs_client_connect_to_server(void)
                    158: {
                    159:        char *cmd, *argv[9], *resp;
                    160:        int ifd[2], ofd[2], argc;
1.1       jfb       161:
1.9       joris     162:        switch (current_cvsroot->cr_method) {
                    163:        case CVS_METHOD_PSERVER:
                    164:        case CVS_METHOD_KSERVER:
                    165:        case CVS_METHOD_GSERVER:
                    166:        case CVS_METHOD_FORK:
                    167:        case CVS_METHOD_EXT:
1.14      joris     168:                fatal("the specified connection method is not supported");
1.9       joris     169:        default:
                    170:                break;
                    171:        }
                    172:
                    173:        if (pipe(ifd) == -1)
                    174:                fatal("cvs_client_connect: %s", strerror(errno));
                    175:        if (pipe(ofd) == -1)
                    176:                fatal("cvs_client_connect: %s", strerror(errno));
                    177:
                    178:        switch (fork()) {
                    179:        case -1:
                    180:                fatal("cvs_client_connect: fork failed: %s", strerror(errno));
                    181:        case 0:
                    182:                if (dup2(ifd[0], STDIN_FILENO) == -1)
                    183:                        fatal("cvs_client_connect: %s", strerror(errno));
                    184:                if (dup2(ofd[1], STDOUT_FILENO) == -1)
                    185:                        fatal("cvs_client_connect: %s", strerror(errno));
1.1       jfb       186:
1.9       joris     187:                close(ifd[1]);
                    188:                close(ofd[0]);
1.1       jfb       189:
1.9       joris     190:                if ((cmd = getenv("CVS_SERVER")) == NULL)
                    191:                        cmd = CVS_SERVER_DEFAULT;
1.1       jfb       192:
                    193:                argc = 0;
                    194:                argv[argc++] = cvs_rsh;
                    195:
1.9       joris     196:                if (current_cvsroot->cr_user != NULL) {
1.1       jfb       197:                        argv[argc++] = "-l";
1.9       joris     198:                        argv[argc++] = current_cvsroot->cr_user;
1.1       jfb       199:                }
                    200:
1.9       joris     201:                argv[argc++] = current_cvsroot->cr_host;
                    202:                argv[argc++] = cmd;
1.1       jfb       203:                argv[argc++] = "server";
                    204:                argv[argc] = NULL;
                    205:
1.9       joris     206:                cvs_log(LP_TRACE, "connecting to server %s",
                    207:                    current_cvsroot->cr_host);
                    208:
1.1       jfb       209:                execvp(argv[0], argv);
1.9       joris     210:                fatal("cvs_client_connect: failed to execute cvs server");
                    211:        default:
                    212:                break;
1.1       jfb       213:        }
                    214:
1.9       joris     215:        close(ifd[0]);
                    216:        close(ofd[1]);
                    217:
                    218:        if ((current_cvsroot->cr_srvin = fdopen(ifd[1], "w")) == NULL)
                    219:                fatal("cvs_client_connect: %s", strerror(errno));
                    220:        if ((current_cvsroot->cr_srvout = fdopen(ofd[0], "r")) == NULL)
                    221:                fatal("cvs_client_connect: %s", strerror(errno));
1.1       jfb       222:
1.9       joris     223:        setvbuf(current_cvsroot->cr_srvin, NULL,_IOLBF, 0);
                    224:        setvbuf(current_cvsroot->cr_srvout, NULL, _IOLBF, 0);
1.1       jfb       225:
1.9       joris     226:        cvs_client_send_request("Root %s", current_cvsroot->cr_dir);
1.1       jfb       227:
1.9       joris     228:        resp = client_get_supported_responses();
                    229:        cvs_client_send_request("Valid-responses %s", resp);
                    230:        xfree(resp);
1.1       jfb       231:
1.9       joris     232:        cvs_client_send_request("valid-requests");
                    233:        cvs_client_get_responses();
1.1       jfb       234:
1.9       joris     235:        if (cvs_trace)
                    236:                cvs_client_send_request("Global_option -t");
1.1       jfb       237:
1.9       joris     238:        if (verbosity == 2)
                    239:                cvs_client_send_request("Global_option -V");
1.1       jfb       240:
1.9       joris     241:        cvs_client_send_request("UseUnchanged");
1.1       jfb       242: }
                    243:
1.9       joris     244: void
                    245: cvs_client_send_request(char *fmt, ...)
                    246: {
                    247:        va_list ap;
                    248:        char *data, *s;
                    249:        struct cvs_req *req;
                    250:
                    251:        va_start(ap, fmt);
                    252:        vasprintf(&data, fmt, ap);
                    253:        va_end(ap);
1.1       jfb       254:
1.9       joris     255:        if ((s = strchr(data, ' ')) != NULL)
                    256:                *s = '\0';
1.1       jfb       257:
1.9       joris     258:        req = cvs_remote_get_request_info(data);
                    259:        if (req == NULL)
                    260:                fatal("'%s' is an unknown request", data);
1.1       jfb       261:
1.9       joris     262:        if (req->supported != 1)
                    263:                fatal("remote cvs server does not support '%s'", data);
1.1       jfb       264:
1.9       joris     265:        if (s != NULL)
                    266:                *s = ' ';
1.1       jfb       267:
1.12      joris     268:        cvs_log(LP_TRACE, "%s", data);
1.9       joris     269:        cvs_remote_output(data);
                    270:        xfree(data);
                    271: }
1.1       jfb       272:
1.9       joris     273: void
                    274: cvs_client_read_response(void)
1.1       jfb       275: {
1.9       joris     276:        char *cmd, *data;
                    277:        struct cvs_resp *resp;
1.1       jfb       278:
1.9       joris     279:        cmd = cvs_remote_input();
                    280:        if ((data = strchr(cmd, ' ')) != NULL)
                    281:                (*data++) = '\0';
1.1       jfb       282:
1.9       joris     283:        resp = cvs_remote_get_response_info(cmd);
                    284:        if (resp == NULL)
                    285:                fatal("response '%s' is not supported by our client", cmd);
1.1       jfb       286:
1.9       joris     287:        if (resp->hdlr == NULL)
                    288:                fatal("opencvs client does not support '%s'", cmd);
1.1       jfb       289:
1.9       joris     290:        (*resp->hdlr)(data);
                    291:        xfree(cmd);
1.1       jfb       292: }
                    293:
1.9       joris     294: void
                    295: cvs_client_get_responses(void)
                    296: {
                    297:        while (end_of_response != 1)
                    298:                cvs_client_read_response();
1.1       jfb       299:
1.9       joris     300:        end_of_response = 0;
                    301: }
1.1       jfb       302:
1.9       joris     303: void
                    304: cvs_client_senddir(const char *dir)
1.1       jfb       305: {
1.9       joris     306:        char *repo;
                    307:
                    308:        if (lastdir != NULL && !strcmp(dir, lastdir))
                    309:                return;
1.1       jfb       310:
1.9       joris     311:        cvs_client_send_request("Directory %s", dir);
1.1       jfb       312:
1.9       joris     313:        repo = xmalloc(MAXPATHLEN);
                    314:        cvs_get_repository_path(dir, repo, MAXPATHLEN);
                    315:        cvs_remote_output(repo);
                    316:        xfree(repo);
1.1       jfb       317:
1.9       joris     318:        if (lastdir != NULL)
                    319:                xfree(lastdir);
                    320:        lastdir = xstrdup(dir);
                    321: }
1.1       jfb       322:
1.9       joris     323: void
                    324: cvs_client_sendfile(struct cvs_file *cf)
1.1       jfb       325: {
1.9       joris     326:        int l;
                    327:        size_t len;
                    328:        char rev[16], timebuf[64], sticky[32];
1.1       jfb       329:
1.9       joris     330:        if (cf->file_type != CVS_FILE)
                    331:                return;
1.1       jfb       332:
1.9       joris     333:        cvs_client_senddir(cf->file_wd);
                    334:        cvs_remote_classify_file(cf);
                    335:
1.10      joris     336:        if (cf->file_type == CVS_DIR)
                    337:                return;
                    338:
1.9       joris     339:        if (cf->file_ent != NULL) {
                    340:                if (cf->file_status == FILE_ADDED) {
                    341:                        len = strlcpy(rev, "0", sizeof(rev));
                    342:                        if (len >= sizeof(rev))
                    343:                                fatal("cvs_client_sendfile: truncation");
                    344:
                    345:                        len = strlcpy(timebuf, "Initial ", sizeof(timebuf));
                    346:                        if (len >= sizeof(timebuf))
                    347:                                fatal("cvs_client_sendfile: truncation");
                    348:
                    349:                        len = strlcat(timebuf, cf->file_name, sizeof(timebuf));
                    350:                        if (len >= sizeof(timebuf))
                    351:                                fatal("cvs_client_sendfile: truncation");
                    352:                } else {
                    353:                        rcsnum_tostr(cf->file_ent->ce_rev, rev, sizeof(rev));
                    354:                        ctime_r(&cf->file_ent->ce_mtime, timebuf);
                    355:                }
1.1       jfb       356:
1.9       joris     357:                if (cf->file_ent->ce_conflict == NULL) {
                    358:                        if (timebuf[strlen(timebuf) - 1] == '\n')
                    359:                                timebuf[strlen(timebuf) - 1] = '\0';
                    360:                } else {
                    361:                        len = strlcpy(timebuf, cf->file_ent->ce_conflict,
                    362:                            sizeof(timebuf));
                    363:                        if (len >= sizeof(timebuf))
                    364:                                fatal("cvs_client_sendfile: truncation");
                    365:                }
1.1       jfb       366:
1.9       joris     367:                sticky[0] = '\0';
                    368:                if (cf->file_ent->ce_tag != NULL) {
                    369:                        l = snprintf(sticky, sizeof(sticky), "T%s",
                    370:                            cf->file_ent->ce_tag);
                    371:                        if (l == -1 || l >= (int)sizeof(sticky))
                    372:                                fatal("cvs_client_sendfile: overflow");
1.1       jfb       373:                }
                    374:
1.13      joris     375:                cvs_client_send_request("Entry /%s/%s%s/%s//%s",
1.9       joris     376:                    cf->file_name, (cf->file_status == FILE_REMOVED) ? "-" : "",
                    377:                   rev, timebuf, sticky);
                    378:        }
                    379:
                    380:        switch (cf->file_status) {
                    381:        case FILE_UNKNOWN:
                    382:                if (cf->fd != -1)
                    383:                        cvs_client_send_request("Questionable %s",
                    384:                            cf->file_name);
                    385:                break;
                    386:        case FILE_ADDED:
                    387:        case FILE_MODIFIED:
                    388:                cvs_client_send_request("Modified %s", cf->file_name);
                    389:                cvs_remote_send_file(cf->file_path);
                    390:                break;
                    391:        case FILE_UPTODATE:
                    392:                cvs_client_send_request("Unchanged %s", cf->file_name);
                    393:                break;
1.1       jfb       394:        }
1.9       joris     395: }
1.1       jfb       396:
1.9       joris     397: void
                    398: cvs_client_send_files(char **argv, int argc)
                    399: {
                    400:        int i;
1.1       jfb       401:
1.9       joris     402:        for (i = 0; i < argc; i++)
                    403:                cvs_client_send_request("Argument %s", argv[i]);
                    404: }
1.1       jfb       405:
1.9       joris     406: void
                    407: cvs_client_ok(char *data)
                    408: {
                    409:        end_of_response = 1;
1.1       jfb       410: }
                    411:
1.9       joris     412: void
                    413: cvs_client_error(char *data)
                    414: {
                    415:        end_of_response = 1;
                    416: }
1.1       jfb       417:
1.9       joris     418: void
                    419: cvs_client_validreq(char *data)
1.1       jfb       420: {
1.9       joris     421:        int i;
                    422:        char *sp, *ep;
                    423:        struct cvs_req *req;
                    424:
                    425:        sp = data;
                    426:        do {
                    427:                if ((ep = strchr(sp, ' ')) != NULL)
                    428:                        *ep = '\0';
                    429:
                    430:                req = cvs_remote_get_request_info(sp);
                    431:                if (req != NULL)
                    432:                        req->supported = 1;
                    433:
                    434:                if (ep != NULL)
                    435:                        sp = ep + 1;
                    436:        } while (ep != NULL);
                    437:
                    438:        for (i = 0; cvs_requests[i].supported != -1; i++) {
                    439:                req = &cvs_requests[i];
                    440:                if ((req->flags & REQ_NEEDED) &&
                    441:                    req->supported != 1) {
                    442:                        fatal("server does not support required '%s'",
                    443:                            req->name);
                    444:                }
1.1       jfb       445:        }
1.9       joris     446: }
1.1       jfb       447:
1.9       joris     448: void
                    449: cvs_client_e(char *data)
                    450: {
                    451:        cvs_printf("%s\n", data);
                    452: }
1.1       jfb       453:
1.9       joris     454: void
                    455: cvs_client_m(char *data)
                    456: {
                    457:        cvs_printf("%s\n", data);
                    458: }
1.1       jfb       459:
1.9       joris     460: void
                    461: cvs_client_checkedin(char *data)
                    462: {
                    463:        int l;
                    464:        CVSENTRIES *entlist;
                    465:        struct cvs_ent *ent, *newent;
                    466:        char *dir, *entry, rev[16], timebuf[64], sticky[16];
1.1       jfb       467:
1.9       joris     468:        dir = cvs_remote_input();
                    469:        entry = cvs_remote_input();
                    470:        xfree(dir);
1.1       jfb       471:
1.9       joris     472:        entlist = cvs_ent_open(data);
                    473:        newent = cvs_ent_parse(entry);
                    474:        ent = cvs_ent_get(entlist, newent->ce_name);
                    475:        xfree(entry);
1.1       jfb       476:
1.9       joris     477:        entry = xmalloc(CVS_ENT_MAXLINELEN);
1.1       jfb       478:
1.9       joris     479:        rcsnum_tostr(newent->ce_rev, rev, sizeof(rev));
                    480:        ctime_r(&ent->ce_mtime, timebuf);
                    481:        if (timebuf[strlen(timebuf) - 1] == '\n')
                    482:                timebuf[strlen(timebuf) - 1] = '\0';
1.1       jfb       483:
1.9       joris     484:        sticky[0] = '\0';
                    485:        if (ent->ce_tag != NULL) {
                    486:                l = snprintf(sticky, sizeof(sticky), "T%s", ent->ce_tag);
                    487:                if (l == -1 || l >= (int)sizeof(sticky))
                    488:                        fatal("cvs_client_checkedin: overflow");
1.2       jfb       489:        }
1.1       jfb       490:
1.9       joris     491:        l = snprintf(entry, CVS_ENT_MAXLINELEN, "/%s/%s/%s//%s/",
                    492:            newent->ce_name, rev, timebuf, sticky);
                    493:        if (l == -1 || l >= CVS_ENT_MAXLINELEN)
                    494:                fatal("cvs_client_checkedin: overflow");
                    495:
                    496:        cvs_ent_free(ent);
                    497:        cvs_ent_free(newent);
                    498:        cvs_ent_add(entlist, entry);
                    499:        cvs_ent_close(entlist, ENT_SYNC);
1.1       jfb       500:
1.9       joris     501:        xfree(entry);
1.1       jfb       502: }
                    503:
1.9       joris     504: void
                    505: cvs_client_updated(char *data)
                    506: {
                    507:        BUF *bp;
                    508:        int l, fd;
                    509:        time_t now;
                    510:        mode_t fmode;
                    511:        size_t flen;
                    512:        CVSENTRIES *ent;
                    513:        struct cvs_ent *e;
                    514:        const char *errstr;
                    515:        struct timeval tv[2];
                    516:        char timebuf[32], *repo, *rpath, *entry, *mode;
                    517:        char revbuf[32], *len, *fpath, *wdir;
                    518:
1.10      joris     519:        client_check_directory(data);
1.9       joris     520:
                    521:        rpath = cvs_remote_input();
                    522:        entry = cvs_remote_input();
                    523:        mode = cvs_remote_input();
                    524:        len = cvs_remote_input();
                    525:
                    526:        repo = xmalloc(MAXPATHLEN);
                    527:        cvs_get_repository_path(".", repo, MAXPATHLEN);
                    528:
                    529:        if (strlen(repo) + 1 > strlen(rpath))
                    530:                fatal("received a repository path that is too short");
                    531:
                    532:        fpath = rpath + strlen(repo) + 1;
                    533:        if ((wdir = dirname(fpath)) == NULL)
                    534:                fatal("cvs_client_updated: dirname: %s", strerror(errno));
                    535:        xfree(repo);
                    536:
                    537:        flen = strtonum(len, 0, INT_MAX, &errstr);
                    538:        if (errstr != NULL)
                    539:                fatal("cvs_client_updated: %s: %s", len, errstr);
                    540:        xfree(len);
                    541:
                    542:        cvs_strtomode(mode, &fmode);
                    543:        xfree(mode);
                    544:
                    545:        time(&now);
                    546:        now = cvs_hack_time(now, 0);
                    547:        ctime_r(&now, timebuf);
                    548:        if (timebuf[strlen(timebuf) - 1] == '\n')
                    549:                timebuf[strlen(timebuf) - 1] = '\0';
                    550:
                    551:        e = cvs_ent_parse(entry);
                    552:        xfree(entry);
                    553:        rcsnum_tostr(e->ce_rev, revbuf, sizeof(revbuf));
                    554:        entry = xmalloc(CVS_ENT_MAXLINELEN);
                    555:        l = snprintf(entry, CVS_ENT_MAXLINELEN, "/%s/%s/%s//", e->ce_name,
                    556:            revbuf, timebuf);
                    557:        if (l == -1 || l >= CVS_ENT_MAXLINELEN)
                    558:                fatal("cvs_client_updated: overflow");
                    559:
                    560:        cvs_ent_free(e);
                    561:        ent = cvs_ent_open(wdir);
                    562:        cvs_ent_add(ent, entry);
                    563:        cvs_ent_close(ent, ENT_SYNC);
                    564:        xfree(entry);
                    565:
                    566:        bp = cvs_remote_receive_file(flen);
                    567:        if ((fd = open(fpath, O_CREAT | O_WRONLY | O_TRUNC)) == -1)
                    568:                fatal("cvs_client_updated: open: %s: %s",
                    569:                    fpath, strerror(errno));
1.1       jfb       570:
1.9       joris     571:        if (cvs_buf_write_fd(bp, fd) == -1)
                    572:                fatal("cvs_client_updated: cvs_buf_write_fd failed for %s",
                    573:                    fpath);
1.1       jfb       574:
1.9       joris     575:        cvs_buf_free(bp);
1.1       jfb       576:
1.9       joris     577:        now = cvs_hack_time(now, 0);
                    578:        tv[0].tv_sec = now;
                    579:        tv[0].tv_usec = 0;
                    580:        tv[1] = tv[0];
1.1       jfb       581:
1.9       joris     582:        if (futimes(fd, tv) == -1)
                    583:                fatal("cvs_client_updated: futimes: %s", strerror(errno));
1.1       jfb       584:
1.9       joris     585:        if (fchmod(fd, fmode) == -1)
                    586:                fatal("cvs_client_updated: fchmod: %s", strerror(errno));
1.1       jfb       587:
1.9       joris     588:        (void)close(fd);
1.1       jfb       589:
1.9       joris     590:        xfree(rpath);
1.1       jfb       591: }
                    592:
1.9       joris     593: void
                    594: cvs_client_merged(char *data)
                    595: {
                    596: }
1.1       jfb       597:
1.9       joris     598: void
                    599: cvs_client_removed(char *data)
                    600: {
1.13      joris     601:        char *dir;
                    602:
                    603:        dir = cvs_remote_input();
                    604:        xfree(dir);
1.9       joris     605: }
1.1       jfb       606:
1.9       joris     607: void
                    608: cvs_client_remove_entry(char *data)
1.1       jfb       609: {
1.9       joris     610:        char *dir;
1.1       jfb       611:
1.9       joris     612:        dir = cvs_remote_input();
                    613:        xfree(dir);
1.1       jfb       614: }