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

Annotation of src/usr.bin/cvs/resp.c, Revision 1.10

1.10    ! jfb         1: /*     $OpenBSD: resp.c,v 1.9 2004/12/03 21:08:40 jfb Exp $    */
1.1       jfb         2: /*
                      3:  * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
                      4:  * All rights reserved.
                      5:  *
                      6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
                      9:  *
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. The name of the author may not be used to endorse or promote products
                     13:  *    derived from this software without specific prior written permission.
                     14:  *
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
                     16:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
                     17:  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
                     18:  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
                     19:  * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
                     20:  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
                     21:  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
                     22:  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
                     23:  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
                     24:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     25:  */
                     26:
                     27:
                     28: #include <sys/types.h>
                     29: #include <sys/stat.h>
1.2       jfb        30: #include <sys/time.h>
1.1       jfb        31:
                     32: #include <fcntl.h>
                     33: #include <stdio.h>
                     34: #include <errno.h>
                     35: #include <dirent.h>
                     36: #include <stdlib.h>
                     37: #include <unistd.h>
                     38: #include <string.h>
                     39: #include <sysexits.h>
                     40:
                     41: #include "buf.h"
                     42: #include "cvs.h"
                     43: #include "log.h"
                     44: #include "file.h"
                     45: #include "proto.h"
                     46:
                     47:
                     48: #define CVS_MTSTK_MAXDEPTH   16
                     49:
                     50:
1.4       jfb        51: #define STRIP_SLASH(p)                                         \
                     52:        do {                                                    \
                     53:                size_t len;                                     \
                     54:                len = strlen(p);                                \
                     55:                while ((len > 0) && (p[len - 1] == '/'))        \
                     56:                        p[--len] = '\0';                        \
                     57:        } while (0)
                     58:
                     59:
                     60:
1.1       jfb        61: static int  cvs_resp_validreq  (struct cvsroot *, int, char *);
                     62: static int  cvs_resp_cksum     (struct cvsroot *, int, char *);
                     63: static int  cvs_resp_modtime   (struct cvsroot *, int, char *);
                     64: static int  cvs_resp_m         (struct cvsroot *, int, char *);
                     65: static int  cvs_resp_ok        (struct cvsroot *, int, char *);
                     66: static int  cvs_resp_error     (struct cvsroot *, int, char *);
                     67: static int  cvs_resp_statdir   (struct cvsroot *, int, char *);
                     68: static int  cvs_resp_sticky    (struct cvsroot *, int, char *);
                     69: static int  cvs_resp_newentry  (struct cvsroot *, int, char *);
                     70: static int  cvs_resp_updated   (struct cvsroot *, int, char *);
                     71: static int  cvs_resp_removed   (struct cvsroot *, int, char *);
                     72: static int  cvs_resp_mode      (struct cvsroot *, int, char *);
                     73: static int  cvs_resp_modxpand  (struct cvsroot *, int, char *);
                     74: static int  cvs_resp_rcsdiff   (struct cvsroot *, int, char *);
                     75: static int  cvs_resp_template  (struct cvsroot *, int, char *);
                     76:
                     77:
                     78: struct cvs_resphdlr {
                     79:        int (*hdlr)(struct cvsroot *, int, char *);
                     80: } cvs_resp_swtab[CVS_RESP_MAX + 1] = {
                     81:        { NULL              },
                     82:        { cvs_resp_ok       },
                     83:        { cvs_resp_error    },
                     84:        { cvs_resp_validreq },
                     85:        { cvs_resp_newentry },
                     86:        { cvs_resp_newentry },
                     87:        { cvs_resp_cksum    },
                     88:        { NULL              },
                     89:        { cvs_resp_updated  },
                     90:        { cvs_resp_updated  },
                     91:        { cvs_resp_updated  },  /* 10 */
                     92:        { cvs_resp_updated  },
                     93:        { cvs_resp_updated  },
                     94:        { cvs_resp_rcsdiff  },
                     95:        { cvs_resp_mode     },
                     96:        { cvs_resp_modtime  },
                     97:        { cvs_resp_removed  },
                     98:        { cvs_resp_removed  },
                     99:        { cvs_resp_statdir  },
                    100:        { cvs_resp_statdir  },
                    101:        { cvs_resp_sticky   },  /* 20 */
                    102:        { cvs_resp_sticky   },
                    103:        { cvs_resp_template },
                    104:        { NULL              },
                    105:        { NULL              },
                    106:        { NULL              },
                    107:        { cvs_resp_modxpand },
                    108:        { NULL              },
                    109:        { cvs_resp_m        },
                    110:        { cvs_resp_m        },
                    111:        { cvs_resp_m        },  /* 30 */
                    112:        { cvs_resp_m        },
                    113:        { cvs_resp_m        },
                    114: };
                    115:
                    116:
                    117:
                    118: /*
                    119:  * The MT command uses scoping to tag the data.  Whenever we encouter a '+',
                    120:  * we push the name of the tag on the stack, and we pop it when we encounter
                    121:  * a '-' with the same name.
                    122:  */
                    123:
                    124: static char *cvs_mt_stack[CVS_MTSTK_MAXDEPTH];
                    125: static u_int cvs_mtstk_depth = 0;
                    126:
                    127: static time_t cvs_modtime = 0;
                    128:
                    129:
                    130: /* last checksum received */
                    131: char *cvs_fcksum = NULL;
                    132:
                    133: mode_t  cvs_lastmode = 0;
                    134:
                    135: /* hack to receive the remote version without outputting it */
                    136: extern u_int cvs_version_sent;
                    137:
                    138:
                    139: /*
                    140:  * cvs_resp_handle()
                    141:  *
                    142:  * Generic response handler dispatcher.  The handler expects the first line
                    143:  * of the command as single argument.
                    144:  * Returns the return value of the command on success, or -1 on failure.
                    145:  */
                    146:
                    147: int
                    148: cvs_resp_handle(struct cvsroot *root, char *line)
                    149: {
                    150:        char *cp, *cmd;
                    151:        struct cvs_resp *resp;
                    152:
                    153:        cmd = line;
                    154:
                    155:        cp = strchr(cmd, ' ');
                    156:        if (cp != NULL)
                    157:                *(cp++) = '\0';
                    158:
                    159:        resp = cvs_resp_getbyname(cmd);
                    160:        if (resp == NULL) {
                    161:                return (-1);
                    162:        }
                    163:        else if (cvs_resp_swtab[resp->resp_id].hdlr == NULL) {
                    164:                cvs_log(LP_ERRNO, "handler for `%s' not implemented", cmd);
                    165:                return (-1);
                    166:        }
                    167:
                    168:        return (*cvs_resp_swtab[resp->resp_id].hdlr)(root, resp->resp_id, cp);
                    169: }
                    170:
                    171:
                    172: /*
                    173:  * cvs_resp_validreq()
                    174:  *
                    175:  * Handler for the `Valid-requests' response.  The list of valid requests is
                    176:  * split on spaces and each request's entry in the valid request array is set
                    177:  * to 1 to indicate the validity.
                    178:  * Returns 0 on success, or -1 on failure.
                    179:  */
                    180:
                    181: static int
                    182: cvs_resp_validreq(struct cvsroot *root, int type, char *line)
                    183: {
                    184:        char *sp, *ep;
                    185:        struct cvs_req *req;
                    186:
                    187:        /* parse the requests */
                    188:        sp = line;
                    189:        do {
                    190:                ep = strchr(sp, ' ');
                    191:                if (ep != NULL)
                    192:                        *ep = '\0';
                    193:
                    194:                req = cvs_req_getbyname(sp);
                    195:                if (req != NULL)
                    196:                        CVS_SETVR(root, req->req_id);
                    197:
                    198:                if (ep != NULL)
                    199:                        sp = ep + 1;
                    200:        } while (ep != NULL);
                    201:
                    202:        return (0);
                    203: }
                    204:
                    205:
                    206: /*
                    207:  * cvs_resp_m()
                    208:  *
                    209:  * Handler for the `M', 'MT', `F' and `E' responses.
                    210:  */
                    211:
                    212: static int
                    213: cvs_resp_m(struct cvsroot *root, int type, char *line)
                    214: {
                    215:        char *cp;
                    216:        FILE *stream;
                    217:
                    218:        stream = NULL;
                    219:
                    220:        switch (type) {
                    221:        case CVS_RESP_F:
                    222:                fflush(stderr);
                    223:                return (0);
                    224:        case CVS_RESP_M:
                    225:                if (cvs_version_sent) {
                    226:                        /*
                    227:                         * Instead of outputting the line, we save it as the
                    228:                         * remote server's version string.
                    229:                         */
                    230:                        cvs_version_sent = 0;
                    231:                        root->cr_version = strdup(line);
                    232:                        return (0);
                    233:                }
                    234:                stream = stdout;
                    235:                break;
                    236:        case CVS_RESP_E:
                    237:                stream = stderr;
                    238:                break;
                    239:        case CVS_RESP_MT:
                    240:                if (*line == '+') {
                    241:                        if (cvs_mtstk_depth == CVS_MTSTK_MAXDEPTH) {
                    242:                                cvs_log(LP_ERR,
                    243:                                    "MT scope stack has reached max depth");
                    244:                                return (-1);
                    245:                        }
                    246:                        cvs_mt_stack[cvs_mtstk_depth] = strdup(line + 1);
                    247:                        if (cvs_mt_stack[cvs_mtstk_depth] == NULL)
                    248:                                return (-1);
                    249:                        cvs_mtstk_depth++;
                    250:                }
                    251:                else if (*line == '-') {
                    252:                        if (cvs_mtstk_depth == 0) {
                    253:                                cvs_log(LP_ERR, "MT scope stack underflow");
                    254:                                return (-1);
                    255:                        }
                    256:                        else if (strcmp(line + 1,
                    257:                            cvs_mt_stack[cvs_mtstk_depth - 1]) != 0) {
                    258:                                cvs_log(LP_ERR, "mismatch in MT scope stack");
                    259:                                return (-1);
                    260:                        }
                    261:                        free(cvs_mt_stack[cvs_mtstk_depth--]);
                    262:                }
                    263:                else {
                    264:                        if (strcmp(line, "newline") == 0)
                    265:                                putc('\n', stdout);
                    266:                        else if (strncmp(line, "fname ", 6) == 0)
                    267:                                printf("%s", line + 6);
                    268:                        else {
                    269:                                /* assume text */
                    270:                                cp = strchr(line, ' ');
                    271:                                if (cp != NULL)
                    272:                                        printf("%s", cp + 1);
                    273:                        }
                    274:                }
                    275:
                    276:                return (0);
                    277:        case CVS_RESP_MBINARY:
                    278:                cvs_log(LP_WARN, "Mbinary not supported in client yet");
                    279:                break;
                    280:        }
                    281:
                    282:        fputs(line, stream);
                    283:        fputc('\n', stream);
                    284:
                    285:        return (0);
                    286: }
                    287:
                    288:
                    289: /*
                    290:  * cvs_resp_ok()
                    291:  *
                    292:  * Handler for the `ok' response.  This handler's job is to
                    293:  */
                    294:
                    295: static int
                    296: cvs_resp_ok(struct cvsroot *root, int type, char *line)
                    297: {
                    298:        return (1);
                    299: }
                    300:
                    301:
                    302: /*
                    303:  * cvs_resp_error()
                    304:  *
                    305:  * Handler for the `error' response.  This handler's job is to
                    306:  */
                    307:
                    308: static int
                    309: cvs_resp_error(struct cvsroot *root, int type, char *line)
                    310: {
1.7       jfb       311:        fprintf(stderr, "%s\n", line);
1.1       jfb       312:        return (1);
                    313: }
                    314:
                    315:
                    316: /*
                    317:  * cvs_resp_statdir()
                    318:  *
                    319:  * Handler for the `Clear-static-directory' and `Set-static-directory'
                    320:  * responses.
                    321:  */
                    322:
                    323: static int
                    324: cvs_resp_statdir(struct cvsroot *root, int type, char *line)
                    325: {
                    326:        int fd;
                    327:        char rpath[MAXPATHLEN], statpath[MAXPATHLEN];
                    328:
1.3       jfb       329:        /* remote directory line */
                    330:        if (cvs_getln(root, rpath, sizeof(rpath)) < 0)
                    331:                return (-1);
1.1       jfb       332:
                    333:        snprintf(statpath, sizeof(statpath), "%s/%s", line,
                    334:            CVS_PATH_STATICENTRIES);
                    335:
                    336:        if ((type == CVS_RESP_CLRSTATDIR) &&
                    337:            (unlink(statpath) == -1) && (errno != ENOENT)) {
                    338:                cvs_log(LP_ERRNO, "failed to unlink %s file",
                    339:                    CVS_PATH_STATICENTRIES);
                    340:                return (-1);
                    341:        }
                    342:        else if (type == CVS_RESP_SETSTATDIR) {
                    343:                fd = open(statpath, O_CREAT|O_TRUNC|O_WRONLY, 0400);
                    344:                if (fd == -1) {
1.3       jfb       345:                        cvs_log(LP_ERRNO,
                    346:                            "failed to set static directory on %s", line);
1.1       jfb       347:                        return (-1);
                    348:                }
                    349:                (void)close(fd);
                    350:
                    351:        }
                    352:
                    353:        return (0);
                    354: }
                    355:
                    356: /*
                    357:  * cvs_resp_sticky()
                    358:  *
1.4       jfb       359:  * Handler for the `Clear-sticky' and `Set-sticky' responses.  If the
                    360:  * specified directory doesn't exist, we create it and attach it to the
                    361:  * global file structure.
1.1       jfb       362:  */
                    363:
                    364: static int
                    365: cvs_resp_sticky(struct cvsroot *root, int type, char *line)
                    366: {
1.5       jfb       367:        char buf[MAXPATHLEN], subdir[MAXPATHLEN], *file;
                    368:        struct cvs_ent *ent;
1.4       jfb       369:        CVSFILE *cf, *sdir;
                    370:
                    371:        /* get the remote path */
1.5       jfb       372:        if (cvs_getln(root, buf, sizeof(buf)) < 0)
1.4       jfb       373:                return (-1);
1.1       jfb       374:
1.4       jfb       375:        STRIP_SLASH(line);
1.1       jfb       376:
1.4       jfb       377:        cvs_splitpath(line, subdir, sizeof(subdir), &file);
                    378:        sdir = cvs_file_find(cvs_files, subdir);
                    379:        if (sdir == NULL) {
                    380:                cvs_log(LP_ERR, "failed to find %s", subdir);
                    381:                return (-1);
                    382:        }
1.1       jfb       383:
1.4       jfb       384:        cf = cvs_file_find(sdir, file);
                    385:        if (cf == NULL) {
1.1       jfb       386:                /* attempt to create it */
1.8       jfb       387:                cf = cvs_file_create(sdir, line, DT_DIR, 0755);
1.4       jfb       388:                if (cf == NULL)
                    389:                        return (-1);
                    390:                cf->cf_ddat->cd_repo = strdup(line);
                    391:                cf->cf_ddat->cd_root = root;
                    392:                root->cr_ref++;
1.1       jfb       393:
1.4       jfb       394:                cvs_file_attach(sdir, cf);
1.5       jfb       395:
                    396:                /* add a directory entry to the parent */
                    397:                if (CVS_DIR_ENTRIES(sdir) != NULL) {
1.8       jfb       398:                        snprintf(buf, sizeof(buf), "D/%s////",
                    399:                            CVS_FILE_NAME(cf));
1.5       jfb       400:                        ent = cvs_ent_parse(buf);
                    401:                        if (ent == NULL)
                    402:                                cvs_log(LP_ERR,
                    403:                                    "failed to create directory entry");
                    404:                        else
                    405:                                cvs_ent_add(CVS_DIR_ENTRIES(sdir), ent);
                    406:                }
1.1       jfb       407:        }
                    408:
1.4       jfb       409:        if (type == CVS_RESP_CLRSTICKY)
                    410:                cf->cf_ddat->cd_flags &= ~CVS_DIRF_STICKY;
                    411:        else if (type == CVS_RESP_SETSTICKY)
                    412:                cf->cf_ddat->cd_flags |= CVS_DIRF_STICKY;
1.1       jfb       413:
                    414:        return (0);
                    415: }
                    416:
                    417:
                    418: /*
                    419:  * cvs_resp_newentry()
                    420:  *
                    421:  * Handler for the `New-entry' response and `Checked-in' responses.
1.9       jfb       422:  * In the case of `New-entry', we expect the entry line
1.1       jfb       423:  */
                    424:
                    425: static int
                    426: cvs_resp_newentry(struct cvsroot *root, int type, char *line)
                    427: {
                    428:        char entbuf[128];
1.9       jfb       429:        struct cvs_ent *ent;
1.1       jfb       430:        CVSENTRIES *entfile;
                    431:
                    432:        /* get the remote path */
                    433:        cvs_getln(root, entbuf, sizeof(entbuf));
                    434:
                    435:        /* get the new Entries line */
                    436:        if (cvs_getln(root, entbuf, sizeof(entbuf)) < 0)
                    437:                return (-1);
                    438:
                    439:        entfile = cvs_ent_open(line, O_WRONLY);
                    440:        if (entfile == NULL)
                    441:                return (-1);
1.9       jfb       442:        if (type == CVS_RESP_NEWENTRY) {
                    443:                cvs_ent_addln(entfile, entbuf);
                    444:        }
                    445:        else if (type == CVS_RESP_CHECKEDIN) {
                    446:                ent = cvs_ent_parse(entbuf);
                    447:                if (ent == NULL) {
                    448:                        cvs_log(LP_ERR, "failed to parse entry");
                    449:                        cvs_ent_close(entfile);
                    450:                        return (-1);
                    451:                }
                    452:
                    453:                /* timestamp it to now */
                    454:                ent->ce_mtime = time(&(ent->ce_mtime));
                    455:
                    456:                /* replace the current entry with the one we just received */
                    457:                if (cvs_ent_remove(entfile, ent->ce_name) < 0)
                    458:                        cvs_log(LP_WARN, "failed to remove `%s' entry",
                    459:                            ent->ce_name);
                    460:
                    461:                cvs_ent_add(entfile, ent);
                    462:        }
1.1       jfb       463:        cvs_ent_close(entfile);
                    464:
                    465:        return (0);
                    466: }
                    467:
                    468:
                    469: /*
                    470:  * cvs_resp_cksum()
                    471:  *
                    472:  * Handler for the `Checksum' response.  We store the checksum received for
                    473:  * the next file in a dynamically-allocated buffer pointed to by <cvs_fcksum>.
                    474:  * Upon next file reception, the handler checks to see if there is a stored
                    475:  * checksum.
                    476:  * The file handler must make sure that the checksums match and free the
                    477:  * checksum buffer once it's done to indicate there is no further checksum.
                    478:  */
                    479:
                    480: static int
                    481: cvs_resp_cksum(struct cvsroot *root, int type, char *line)
                    482: {
                    483:        if (cvs_fcksum != NULL) {
                    484:                cvs_log(LP_WARN, "unused checksum");
                    485:                free(cvs_fcksum);
                    486:        }
                    487:
                    488:        cvs_fcksum = strdup(line);
                    489:        if (cvs_fcksum == NULL) {
                    490:                cvs_log(LP_ERRNO, "failed to copy checksum string");
                    491:                return (-1);
                    492:        }
                    493:
                    494:        return (0);
                    495: }
                    496:
                    497:
                    498: /*
                    499:  * cvs_resp_modtime()
                    500:  *
                    501:  * Handler for the `Mod-time' file update modifying response.  The timestamp
                    502:  * given is used to set the last modification time on the next file that
                    503:  * will be received.
                    504:  */
                    505:
                    506: static int
                    507: cvs_resp_modtime(struct cvsroot *root, int type, char *line)
                    508: {
1.4       jfb       509:        cvs_modtime = cvs_datesec(line, CVS_DATE_RFC822, 1);
1.1       jfb       510:        return (0);
                    511: }
                    512:
                    513:
                    514: /*
                    515:  * cvs_resp_updated()
                    516:  *
1.4       jfb       517:  * Handler for the `Updated', `Update-existing', `Created', `Merged' and
                    518:  * `Patched' responses, which all have a very similar format.
1.1       jfb       519:  */
                    520:
                    521: static int
                    522: cvs_resp_updated(struct cvsroot *root, int type, char *line)
                    523: {
                    524:        mode_t fmode;
1.4       jfb       525:        char path[MAXPATHLEN], cksum_buf[CVS_CKSUM_LEN];
1.1       jfb       526:        BUF *fbuf;
1.4       jfb       527:        CVSFILE *cf;
1.1       jfb       528:        struct cvs_ent *ep;
1.2       jfb       529:        struct timeval tv[2];
1.1       jfb       530:
1.4       jfb       531:        STRIP_SLASH(line);
                    532:
                    533:        /* find parent directory of file */
                    534:        cf = cvs_file_find(cvs_files, line);
                    535:        if (cf == NULL) {
                    536:                cvs_log(LP_ERR, "failed to find directory %s", line);
                    537:                return (-1);
                    538:        }
1.1       jfb       539:
                    540:        /* read the remote path of the file */
1.4       jfb       541:        if (cvs_getln(root, path, sizeof(path)) < 0)
                    542:                return (-1);
1.1       jfb       543:
                    544:        /* read the new entry */
1.4       jfb       545:        if (cvs_getln(root, path, sizeof(path)) < 0)
1.1       jfb       546:                return (-1);
1.4       jfb       547:
                    548:        if ((ep = cvs_ent_parse(path)) == NULL)
                    549:                return (-1);
                    550:        snprintf(path, sizeof(path), "%s/%s", line, ep->ce_name);
1.1       jfb       551:
                    552:        if (type == CVS_RESP_CREATED) {
                    553:                /* set the timestamp as the last one received from Mod-time */
1.4       jfb       554:                ep->ce_mtime = cvs_modtime;
                    555:                cvs_ent_add(cf->cf_ddat->cd_ent, ep);
1.1       jfb       556:        }
                    557:        else if (type == CVS_RESP_UPDEXIST) {
                    558:        }
                    559:        else if (type == CVS_RESP_UPDATED) {
                    560:        }
                    561:
                    562:        fbuf = cvs_recvfile(root, &fmode);
                    563:        if (fbuf == NULL)
                    564:                return (-1);
                    565:
                    566:        cvs_buf_write(fbuf, path, fmode);
1.2       jfb       567:
                    568:        tv[0].tv_sec = (long)cvs_modtime;
                    569:        tv[0].tv_usec = 0;
                    570:        tv[1].tv_sec = (long)cvs_modtime;
                    571:        tv[1].tv_usec = 0;
                    572:        if (utimes(path, tv) == -1)
                    573:                cvs_log(LP_ERRNO, "failed to set file timestamps");
1.1       jfb       574:
                    575:        /* now see if there is a checksum */
                    576:        if (cvs_fcksum != NULL) {
                    577:                if (cvs_cksum(path, cksum_buf, sizeof(cksum_buf)) < 0) {
                    578:                }
                    579:
                    580:                if (strcmp(cksum_buf, cvs_fcksum) != 0) {
                    581:                        cvs_log(LP_ERR, "checksum error on received file");
                    582:                        (void)unlink(line);
                    583:                }
                    584:
                    585:                free(cvs_fcksum);
                    586:                cvs_fcksum = NULL;
                    587:        }
                    588:
                    589:        return (0);
                    590: }
                    591:
                    592:
                    593: /*
                    594:  * cvs_resp_removed()
                    595:  *
1.10    ! jfb       596:  * Handler for the `Removed' and `Remove-entry' responses.  The `Removed'
        !           597:  * response is received when both a file and its entry need to be removed from
        !           598:  * the local copy.  The `Remove-entry' is received in cases where the file is
        !           599:  * already gone but there is still an entry to remove in the Entries file.
1.1       jfb       600:  */
                    601:
                    602: static int
                    603: cvs_resp_removed(struct cvsroot *root, int type, char *line)
                    604: {
1.3       jfb       605:        char base[MAXPATHLEN], *file;
1.1       jfb       606:        CVSENTRIES *ef;
                    607:
1.3       jfb       608:        cvs_splitpath(line, base, sizeof(base), &file);
1.1       jfb       609:        ef = cvs_ent_open(base, O_RDWR);
1.10    ! jfb       610:        if (ef == NULL) {
        !           611:                cvs_log(LP_ERR, "error handling `Removed' response");
        !           612:                if (type == CVS_RESP_RMENTRY)
        !           613:                        return (-1);
        !           614:        } else {
        !           615:                (void)cvs_ent_remove(ef, file);
        !           616:                cvs_ent_close(ef);
        !           617:        }
        !           618:
        !           619:        if ((type == CVS_RESP_REMOVED) && (unlink(line) == -1)) {
        !           620:                cvs_log(LP_ERRNO, "failed to unlink `%s'", line);
1.1       jfb       621:                return (-1);
1.10    ! jfb       622:        }
1.1       jfb       623:
                    624:        return (0);
                    625: }
                    626:
                    627:
                    628: /*
                    629:  * cvs_resp_mode()
                    630:  *
                    631:  * Handler for the `Mode' response.
                    632:  */
                    633:
                    634: static int
                    635: cvs_resp_mode(struct cvsroot *root, int type, char *line)
                    636: {
                    637:        if (cvs_strtomode(line, &cvs_lastmode) < 0) {
                    638:                return (-1);
                    639:        }
                    640:        return (0);
                    641: }
                    642:
                    643:
                    644: /*
                    645:  * cvs_resp_modxpand()
                    646:  *
                    647:  * Handler for the `Module-expansion' response.
                    648:  */
                    649:
                    650: static int
                    651: cvs_resp_modxpand(struct cvsroot *root, int type, char *line)
                    652: {
                    653:        return (0);
                    654: }
                    655:
                    656: /*
                    657:  * cvs_resp_rcsdiff()
                    658:  *
                    659:  * Handler for the `Rcs-diff' response.
                    660:  */
                    661:
                    662: static int
                    663: cvs_resp_rcsdiff(struct cvsroot *root, int type, char *line)
                    664: {
                    665:        char file[MAXPATHLEN], buf[MAXPATHLEN], cksum_buf[CVS_CKSUM_LEN];
                    666:        char *fname, *orig, *patch;
                    667:        mode_t fmode;
                    668:        BUF *res, *fcont, *patchbuf;
                    669:        CVSENTRIES *entf;
                    670:        struct cvs_ent *ent;
                    671:
                    672:        /* get remote path and build local path of file to be patched */
                    673:        cvs_getln(root, buf, sizeof(buf));
                    674:        fname = strrchr(buf, '/');
                    675:        if (fname == NULL)
                    676:                fname = buf;
                    677:        snprintf(file, sizeof(file), "%s%s", line, fname);
                    678:
                    679:        /* get updated entry fields */
                    680:        cvs_getln(root, buf, sizeof(buf));
                    681:        ent = cvs_ent_parse(buf);
                    682:        if (ent == NULL) {
                    683:                return (-1);
                    684:        }
                    685:
                    686:        patchbuf = cvs_recvfile(root, &fmode);
                    687:        fcont = cvs_buf_load(file, BUF_AUTOEXT);
                    688:        if (fcont == NULL)
                    689:                return (-1);
                    690:
                    691:        cvs_buf_putc(patchbuf, '\0');
                    692:        cvs_buf_putc(fcont, '\0');
                    693:        orig = cvs_buf_release(fcont);
                    694:        patch = cvs_buf_release(patchbuf);
                    695:
                    696:        res = rcs_patch(orig, patch);
                    697:        if (res == NULL)
                    698:                return (-1);
                    699:
                    700:        cvs_buf_write(res, file, fmode);
                    701:
                    702:        /* now see if there is a checksum */
                    703:        if (cvs_fcksum != NULL) {
                    704:                if (cvs_cksum(file, cksum_buf, sizeof(cksum_buf)) < 0) {
                    705:                }
                    706:
                    707:                if (strcmp(cksum_buf, cvs_fcksum) != 0) {
                    708:                        cvs_log(LP_ERR, "checksum error on received file");
                    709:                        (void)unlink(file);
                    710:                }
                    711:
                    712:                free(cvs_fcksum);
                    713:                cvs_fcksum = NULL;
                    714:        }
                    715:
                    716:        /* update revision in entries */
                    717:        entf = cvs_ent_open(line, O_WRONLY);
                    718:        if (entf == NULL)
                    719:                return (-1);
                    720:
                    721:        cvs_ent_close(entf);
                    722:
                    723:        return (0);
                    724: }
                    725:
                    726:
                    727: /*
                    728:  * cvs_resp_template()
                    729:  *
                    730:  * Handler for the `Template' response.
                    731:  */
                    732:
                    733: static int
                    734: cvs_resp_template(struct cvsroot *root, int type, char *line)
                    735: {
                    736:        mode_t mode;
                    737:        BUF *tmpl;
                    738:
                    739:        tmpl = cvs_recvfile(root, &mode);
                    740:        if (tmpl == NULL)
                    741:                return (-1);
                    742:
                    743:        return (0);
                    744: }