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

1.10    ! joris       1: /*     $OpenBSD: client.c,v 1.9 2006/07/07 17:37:17 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 },
                     79:        { "add",                        0,      NULL, 0 },
                     80:        { "remove",                     0,      NULL, 0 },
                     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");
        !           140:
        !           141:        entry = xmalloc(CVS_ENT_MAXLINELEN);
        !           142:        l = snprintf(entry, CVS_ENT_MAXLINELEN, "D/%s////", base);
        !           143:        if (l == -1 || l >= CVS_ENT_MAXLINELEN)
        !           144:                fatal("client_check_directory: overflow");
        !           145:
        !           146:        entlist = cvs_ent_open(parent);
        !           147:        cvs_ent_add(entlist, entry);
        !           148:        cvs_ent_close(entlist, ENT_SYNC);
        !           149:
        !           150:        xfree(entry);
        !           151: }
        !           152:
1.9       joris     153: void
                    154: cvs_client_connect_to_server(void)
                    155: {
                    156:        char *cmd, *argv[9], *resp;
                    157:        int ifd[2], ofd[2], argc;
1.1       jfb       158:
1.9       joris     159:        switch (current_cvsroot->cr_method) {
                    160:        case CVS_METHOD_PSERVER:
                    161:        case CVS_METHOD_KSERVER:
                    162:        case CVS_METHOD_GSERVER:
                    163:        case CVS_METHOD_FORK:
                    164:        case CVS_METHOD_EXT:
                    165:                fatal("the specified connection method is not support");
                    166:        default:
                    167:                break;
                    168:        }
                    169:
                    170:        if (pipe(ifd) == -1)
                    171:                fatal("cvs_client_connect: %s", strerror(errno));
                    172:        if (pipe(ofd) == -1)
                    173:                fatal("cvs_client_connect: %s", strerror(errno));
                    174:
                    175:        switch (fork()) {
                    176:        case -1:
                    177:                fatal("cvs_client_connect: fork failed: %s", strerror(errno));
                    178:        case 0:
                    179:                if (dup2(ifd[0], STDIN_FILENO) == -1)
                    180:                        fatal("cvs_client_connect: %s", strerror(errno));
                    181:                if (dup2(ofd[1], STDOUT_FILENO) == -1)
                    182:                        fatal("cvs_client_connect: %s", strerror(errno));
1.1       jfb       183:
1.9       joris     184:                close(ifd[1]);
                    185:                close(ofd[0]);
1.1       jfb       186:
1.9       joris     187:                if ((cmd = getenv("CVS_SERVER")) == NULL)
                    188:                        cmd = CVS_SERVER_DEFAULT;
1.1       jfb       189:
                    190:                argc = 0;
                    191:                argv[argc++] = cvs_rsh;
                    192:
1.9       joris     193:                if (current_cvsroot->cr_user != NULL) {
1.1       jfb       194:                        argv[argc++] = "-l";
1.9       joris     195:                        argv[argc++] = current_cvsroot->cr_user;
1.1       jfb       196:                }
                    197:
1.9       joris     198:                argv[argc++] = current_cvsroot->cr_host;
                    199:                argv[argc++] = cmd;
1.1       jfb       200:                argv[argc++] = "server";
                    201:                argv[argc] = NULL;
                    202:
1.9       joris     203:                cvs_log(LP_TRACE, "connecting to server %s",
                    204:                    current_cvsroot->cr_host);
                    205:
1.1       jfb       206:                execvp(argv[0], argv);
1.9       joris     207:                fatal("cvs_client_connect: failed to execute cvs server");
                    208:        default:
                    209:                break;
1.1       jfb       210:        }
                    211:
1.9       joris     212:        close(ifd[0]);
                    213:        close(ofd[1]);
                    214:
                    215:        if ((current_cvsroot->cr_srvin = fdopen(ifd[1], "w")) == NULL)
                    216:                fatal("cvs_client_connect: %s", strerror(errno));
                    217:        if ((current_cvsroot->cr_srvout = fdopen(ofd[0], "r")) == NULL)
                    218:                fatal("cvs_client_connect: %s", strerror(errno));
1.1       jfb       219:
1.9       joris     220:        setvbuf(current_cvsroot->cr_srvin, NULL,_IOLBF, 0);
                    221:        setvbuf(current_cvsroot->cr_srvout, NULL, _IOLBF, 0);
1.1       jfb       222:
1.9       joris     223:        cvs_client_send_request("Root %s", current_cvsroot->cr_dir);
1.1       jfb       224:
1.9       joris     225:        resp = client_get_supported_responses();
                    226:        cvs_client_send_request("Valid-responses %s", resp);
                    227:        xfree(resp);
1.1       jfb       228:
1.9       joris     229:        cvs_client_send_request("valid-requests");
                    230:        cvs_client_get_responses();
1.1       jfb       231:
1.9       joris     232:        if (cvs_trace)
                    233:                cvs_client_send_request("Global_option -t");
1.1       jfb       234:
1.9       joris     235:        if (verbosity == 2)
                    236:                cvs_client_send_request("Global_option -V");
1.1       jfb       237:
1.9       joris     238:        cvs_client_send_request("UseUnchanged");
1.1       jfb       239: }
                    240:
1.9       joris     241: void
                    242: cvs_client_send_request(char *fmt, ...)
                    243: {
                    244:        va_list ap;
                    245:        char *data, *s;
                    246:        struct cvs_req *req;
                    247:
                    248:        va_start(ap, fmt);
                    249:        vasprintf(&data, fmt, ap);
                    250:        va_end(ap);
1.1       jfb       251:
1.9       joris     252:        if ((s = strchr(data, ' ')) != NULL)
                    253:                *s = '\0';
1.1       jfb       254:
1.9       joris     255:        req = cvs_remote_get_request_info(data);
                    256:        if (req == NULL)
                    257:                fatal("'%s' is an unknown request", data);
1.1       jfb       258:
1.9       joris     259:        if (req->supported != 1)
                    260:                fatal("remote cvs server does not support '%s'", data);
1.1       jfb       261:
1.9       joris     262:        if (s != NULL)
                    263:                *s = ' ';
1.1       jfb       264:
1.9       joris     265:        cvs_remote_output(data);
                    266:        xfree(data);
                    267: }
1.1       jfb       268:
1.9       joris     269: void
                    270: cvs_client_read_response(void)
1.1       jfb       271: {
1.9       joris     272:        char *cmd, *data;
                    273:        struct cvs_resp *resp;
1.1       jfb       274:
1.9       joris     275:        cmd = cvs_remote_input();
                    276:        if ((data = strchr(cmd, ' ')) != NULL)
                    277:                (*data++) = '\0';
1.1       jfb       278:
1.9       joris     279:        resp = cvs_remote_get_response_info(cmd);
                    280:        if (resp == NULL)
                    281:                fatal("response '%s' is not supported by our client", cmd);
1.1       jfb       282:
1.9       joris     283:        if (resp->hdlr == NULL)
                    284:                fatal("opencvs client does not support '%s'", cmd);
1.1       jfb       285:
1.9       joris     286:        (*resp->hdlr)(data);
                    287:        xfree(cmd);
1.1       jfb       288: }
                    289:
1.9       joris     290: void
                    291: cvs_client_get_responses(void)
                    292: {
                    293:        while (end_of_response != 1)
                    294:                cvs_client_read_response();
1.1       jfb       295:
1.9       joris     296:        end_of_response = 0;
                    297: }
1.1       jfb       298:
1.9       joris     299: void
                    300: cvs_client_senddir(const char *dir)
1.1       jfb       301: {
1.9       joris     302:        char *repo;
                    303:
                    304:        cvs_log(LP_TRACE, "cvs_client_senddir(%s)", dir);
                    305:
                    306:        if (lastdir != NULL && !strcmp(dir, lastdir))
                    307:                return;
1.1       jfb       308:
1.9       joris     309:        cvs_client_send_request("Directory %s", dir);
1.1       jfb       310:
1.9       joris     311:        repo = xmalloc(MAXPATHLEN);
                    312:        cvs_get_repository_path(dir, repo, MAXPATHLEN);
                    313:        cvs_remote_output(repo);
                    314:        xfree(repo);
1.1       jfb       315:
1.9       joris     316:        if (lastdir != NULL)
                    317:                xfree(lastdir);
                    318:        lastdir = xstrdup(dir);
                    319: }
1.1       jfb       320:
1.9       joris     321: void
                    322: cvs_client_sendfile(struct cvs_file *cf)
1.1       jfb       323: {
1.9       joris     324:        int l;
                    325:        size_t len;
                    326:        char rev[16], timebuf[64], sticky[32];
1.1       jfb       327:
1.9       joris     328:        if (cf->file_type != CVS_FILE)
                    329:                return;
1.1       jfb       330:
1.9       joris     331:        cvs_client_senddir(cf->file_wd);
1.1       jfb       332:
1.9       joris     333:        cvs_log(LP_TRACE, "cvs_client_sendfile(%s)", cf->file_path);
                    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.9       joris     375:                cvs_client_send_request("Entry /%s/%s%s/%s/%s/",
                    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:        cvs_log(LP_TRACE, "cvs_client_ok()");
                    410:        end_of_response = 1;
1.1       jfb       411: }
                    412:
1.9       joris     413: void
                    414: cvs_client_error(char *data)
                    415: {
                    416:        cvs_log(LP_TRACE, "cvs_client_error()");
                    417:        end_of_response = 1;
                    418: }
1.1       jfb       419:
1.9       joris     420: void
                    421: cvs_client_validreq(char *data)
1.1       jfb       422: {
1.9       joris     423:        int i;
                    424:        char *sp, *ep;
                    425:        struct cvs_req *req;
                    426:
                    427:        sp = data;
                    428:        do {
                    429:                if ((ep = strchr(sp, ' ')) != NULL)
                    430:                        *ep = '\0';
                    431:
                    432:                req = cvs_remote_get_request_info(sp);
                    433:                if (req != NULL)
                    434:                        req->supported = 1;
                    435:
                    436:                if (ep != NULL)
                    437:                        sp = ep + 1;
                    438:        } while (ep != NULL);
                    439:
                    440:        for (i = 0; cvs_requests[i].supported != -1; i++) {
                    441:                req = &cvs_requests[i];
                    442:                if ((req->flags & REQ_NEEDED) &&
                    443:                    req->supported != 1) {
                    444:                        fatal("server does not support required '%s'",
                    445:                            req->name);
                    446:                }
1.1       jfb       447:        }
1.9       joris     448: }
1.1       jfb       449:
1.9       joris     450: void
                    451: cvs_client_e(char *data)
                    452: {
                    453:        cvs_printf("%s\n", data);
                    454: }
1.1       jfb       455:
1.9       joris     456: void
                    457: cvs_client_m(char *data)
                    458: {
                    459:        cvs_printf("%s\n", data);
                    460: }
1.1       jfb       461:
1.9       joris     462: void
                    463: cvs_client_checkedin(char *data)
                    464: {
                    465:        int l;
                    466:        CVSENTRIES *entlist;
                    467:        struct cvs_ent *ent, *newent;
                    468:        char *dir, *entry, rev[16], timebuf[64], sticky[16];
1.1       jfb       469:
1.9       joris     470:        cvs_log(LP_TRACE, "cvs_client_checkedin(%s)", data);
1.1       jfb       471:
1.9       joris     472:        dir = cvs_remote_input();
                    473:        entry = cvs_remote_input();
                    474:        xfree(dir);
1.1       jfb       475:
1.9       joris     476:        entlist = cvs_ent_open(data);
                    477:        newent = cvs_ent_parse(entry);
                    478:        ent = cvs_ent_get(entlist, newent->ce_name);
                    479:        xfree(entry);
1.1       jfb       480:
1.9       joris     481:        entry = xmalloc(CVS_ENT_MAXLINELEN);
1.1       jfb       482:
1.9       joris     483:        rcsnum_tostr(newent->ce_rev, rev, sizeof(rev));
                    484:        ctime_r(&ent->ce_mtime, timebuf);
                    485:        if (timebuf[strlen(timebuf) - 1] == '\n')
                    486:                timebuf[strlen(timebuf) - 1] = '\0';
1.1       jfb       487:
1.9       joris     488:        sticky[0] = '\0';
                    489:        if (ent->ce_tag != NULL) {
                    490:                l = snprintf(sticky, sizeof(sticky), "T%s", ent->ce_tag);
                    491:                if (l == -1 || l >= (int)sizeof(sticky))
                    492:                        fatal("cvs_client_checkedin: overflow");
1.2       jfb       493:        }
1.1       jfb       494:
1.9       joris     495:        l = snprintf(entry, CVS_ENT_MAXLINELEN, "/%s/%s/%s//%s/",
                    496:            newent->ce_name, rev, timebuf, sticky);
                    497:        if (l == -1 || l >= CVS_ENT_MAXLINELEN)
                    498:                fatal("cvs_client_checkedin: overflow");
                    499:
                    500:        cvs_ent_free(ent);
                    501:        cvs_ent_free(newent);
                    502:        cvs_ent_add(entlist, entry);
                    503:        cvs_ent_close(entlist, ENT_SYNC);
1.1       jfb       504:
1.9       joris     505:        xfree(entry);
1.1       jfb       506: }
                    507:
1.9       joris     508: void
                    509: cvs_client_updated(char *data)
                    510: {
                    511:        BUF *bp;
                    512:        int l, fd;
                    513:        time_t now;
                    514:        mode_t fmode;
                    515:        size_t flen;
                    516:        CVSENTRIES *ent;
                    517:        struct cvs_ent *e;
                    518:        const char *errstr;
                    519:        struct timeval tv[2];
                    520:        char timebuf[32], *repo, *rpath, *entry, *mode;
                    521:        char revbuf[32], *len, *fpath, *wdir;
                    522:
                    523:        cvs_log(LP_TRACE, "cvs_client_updated(%s)", data);
1.10    ! joris     524:
        !           525:        client_check_directory(data);
1.9       joris     526:
                    527:        rpath = cvs_remote_input();
                    528:        entry = cvs_remote_input();
                    529:        mode = cvs_remote_input();
                    530:        len = cvs_remote_input();
                    531:
                    532:        repo = xmalloc(MAXPATHLEN);
                    533:        cvs_get_repository_path(".", repo, MAXPATHLEN);
                    534:
                    535:        if (strlen(repo) + 1 > strlen(rpath))
                    536:                fatal("received a repository path that is too short");
                    537:
                    538:        fpath = rpath + strlen(repo) + 1;
                    539:        if ((wdir = dirname(fpath)) == NULL)
                    540:                fatal("cvs_client_updated: dirname: %s", strerror(errno));
                    541:        xfree(repo);
                    542:
                    543:        flen = strtonum(len, 0, INT_MAX, &errstr);
                    544:        if (errstr != NULL)
                    545:                fatal("cvs_client_updated: %s: %s", len, errstr);
                    546:        xfree(len);
                    547:
                    548:        cvs_strtomode(mode, &fmode);
                    549:        xfree(mode);
                    550:
                    551:        time(&now);
                    552:        now = cvs_hack_time(now, 0);
                    553:        ctime_r(&now, timebuf);
                    554:        if (timebuf[strlen(timebuf) - 1] == '\n')
                    555:                timebuf[strlen(timebuf) - 1] = '\0';
                    556:
                    557:        e = cvs_ent_parse(entry);
                    558:        xfree(entry);
                    559:        rcsnum_tostr(e->ce_rev, revbuf, sizeof(revbuf));
                    560:        entry = xmalloc(CVS_ENT_MAXLINELEN);
                    561:        l = snprintf(entry, CVS_ENT_MAXLINELEN, "/%s/%s/%s//", e->ce_name,
                    562:            revbuf, timebuf);
                    563:        if (l == -1 || l >= CVS_ENT_MAXLINELEN)
                    564:                fatal("cvs_client_updated: overflow");
                    565:
                    566:        cvs_ent_free(e);
                    567:        ent = cvs_ent_open(wdir);
                    568:        cvs_ent_add(ent, entry);
                    569:        cvs_ent_close(ent, ENT_SYNC);
                    570:        xfree(entry);
                    571:
                    572:        bp = cvs_remote_receive_file(flen);
                    573:        if ((fd = open(fpath, O_CREAT | O_WRONLY | O_TRUNC)) == -1)
                    574:                fatal("cvs_client_updated: open: %s: %s",
                    575:                    fpath, strerror(errno));
1.1       jfb       576:
1.9       joris     577:        if (cvs_buf_write_fd(bp, fd) == -1)
                    578:                fatal("cvs_client_updated: cvs_buf_write_fd failed for %s",
                    579:                    fpath);
1.1       jfb       580:
1.9       joris     581:        cvs_buf_free(bp);
1.1       jfb       582:
1.9       joris     583:        now = cvs_hack_time(now, 0);
                    584:        tv[0].tv_sec = now;
                    585:        tv[0].tv_usec = 0;
                    586:        tv[1] = tv[0];
1.1       jfb       587:
1.9       joris     588:        if (futimes(fd, tv) == -1)
                    589:                fatal("cvs_client_updated: futimes: %s", strerror(errno));
1.1       jfb       590:
1.9       joris     591:        if (fchmod(fd, fmode) == -1)
                    592:                fatal("cvs_client_updated: fchmod: %s", strerror(errno));
1.1       jfb       593:
1.9       joris     594:        (void)close(fd);
1.1       jfb       595:
1.9       joris     596:        xfree(rpath);
1.1       jfb       597: }
                    598:
1.9       joris     599: void
                    600: cvs_client_merged(char *data)
                    601: {
                    602:        cvs_log(LP_TRACE, "cvs_client_merged(%s)", data);
                    603: }
1.1       jfb       604:
1.9       joris     605: void
                    606: cvs_client_removed(char *data)
                    607: {
                    608:        cvs_log(LP_TRACE, "cvs_client_removed(%s)", data);
                    609: }
1.1       jfb       610:
1.9       joris     611: void
                    612: cvs_client_remove_entry(char *data)
1.1       jfb       613: {
1.9       joris     614:        char *dir;
1.1       jfb       615:
1.9       joris     616:        cvs_log(LP_TRACE, "cvs_client_remove_entry(%s)", data);
1.1       jfb       617:
1.9       joris     618:        dir = cvs_remote_input();
                    619:        xfree(dir);
1.1       jfb       620: }