Annotation of src/usr.bin/cvs/resp.c, Revision 1.14
1.14 ! jfb 1: /* $OpenBSD: resp.c,v 1.13 2004/12/07 17:10:56 tedu 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:
1.1 jfb 60: static int cvs_resp_validreq (struct cvsroot *, int, char *);
61: static int cvs_resp_cksum (struct cvsroot *, int, char *);
62: static int cvs_resp_modtime (struct cvsroot *, int, char *);
63: static int cvs_resp_m (struct cvsroot *, int, char *);
64: static int cvs_resp_ok (struct cvsroot *, int, char *);
65: static int cvs_resp_error (struct cvsroot *, int, char *);
66: static int cvs_resp_statdir (struct cvsroot *, int, char *);
67: static int cvs_resp_sticky (struct cvsroot *, int, char *);
68: static int cvs_resp_newentry (struct cvsroot *, int, char *);
69: static int cvs_resp_updated (struct cvsroot *, int, char *);
70: static int cvs_resp_removed (struct cvsroot *, int, char *);
71: static int cvs_resp_mode (struct cvsroot *, int, char *);
72: static int cvs_resp_modxpand (struct cvsroot *, int, char *);
73: static int cvs_resp_rcsdiff (struct cvsroot *, int, char *);
74: static int cvs_resp_template (struct cvsroot *, int, char *);
1.14 ! jfb 75: static int cvs_resp_copyfile (struct cvsroot *, int, char *);
1.1 jfb 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 },
1.14 ! jfb 88: { cvs_resp_copyfile },
1.1 jfb 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:
1.12 jfb 127: static time_t cvs_modtime = CVS_DATE_DMSEC;
1.1 jfb 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: int
147: cvs_resp_handle(struct cvsroot *root, char *line)
148: {
149: char *cp, *cmd;
150: struct cvs_resp *resp;
151:
152: cmd = line;
153:
154: cp = strchr(cmd, ' ');
155: if (cp != NULL)
156: *(cp++) = '\0';
157:
158: resp = cvs_resp_getbyname(cmd);
159: if (resp == NULL) {
160: return (-1);
1.11 deraadt 161: } else if (cvs_resp_swtab[resp->resp_id].hdlr == NULL) {
1.1 jfb 162: cvs_log(LP_ERRNO, "handler for `%s' not implemented", cmd);
163: return (-1);
164: }
165:
166: return (*cvs_resp_swtab[resp->resp_id].hdlr)(root, resp->resp_id, cp);
167: }
168:
169:
170: /*
171: * cvs_resp_validreq()
172: *
173: * Handler for the `Valid-requests' response. The list of valid requests is
174: * split on spaces and each request's entry in the valid request array is set
175: * to 1 to indicate the validity.
176: * Returns 0 on success, or -1 on failure.
177: */
178: static int
179: cvs_resp_validreq(struct cvsroot *root, int type, char *line)
180: {
181: char *sp, *ep;
182: struct cvs_req *req;
183:
184: /* parse the requests */
185: sp = line;
186: do {
187: ep = strchr(sp, ' ');
188: if (ep != NULL)
189: *ep = '\0';
190:
191: req = cvs_req_getbyname(sp);
192: if (req != NULL)
193: CVS_SETVR(root, req->req_id);
194:
195: if (ep != NULL)
196: sp = ep + 1;
197: } while (ep != NULL);
198:
199: return (0);
200: }
201:
202:
203: /*
204: * cvs_resp_m()
205: *
206: * Handler for the `M', 'MT', `F' and `E' responses.
207: */
208: static int
209: cvs_resp_m(struct cvsroot *root, int type, char *line)
210: {
211: char *cp;
212: FILE *stream;
213:
214: stream = NULL;
215:
216: switch (type) {
217: case CVS_RESP_F:
218: fflush(stderr);
219: return (0);
220: case CVS_RESP_M:
221: if (cvs_version_sent) {
222: /*
223: * Instead of outputting the line, we save it as the
224: * remote server's version string.
225: */
226: cvs_version_sent = 0;
227: root->cr_version = strdup(line);
228: return (0);
229: }
230: stream = stdout;
231: break;
232: case CVS_RESP_E:
233: stream = stderr;
234: break;
235: case CVS_RESP_MT:
236: if (*line == '+') {
237: if (cvs_mtstk_depth == CVS_MTSTK_MAXDEPTH) {
238: cvs_log(LP_ERR,
239: "MT scope stack has reached max depth");
240: return (-1);
241: }
242: cvs_mt_stack[cvs_mtstk_depth] = strdup(line + 1);
243: if (cvs_mt_stack[cvs_mtstk_depth] == NULL)
244: return (-1);
245: cvs_mtstk_depth++;
1.11 deraadt 246: } else if (*line == '-') {
1.1 jfb 247: if (cvs_mtstk_depth == 0) {
248: cvs_log(LP_ERR, "MT scope stack underflow");
249: return (-1);
1.11 deraadt 250: } else if (strcmp(line + 1,
1.1 jfb 251: cvs_mt_stack[cvs_mtstk_depth - 1]) != 0) {
252: cvs_log(LP_ERR, "mismatch in MT scope stack");
253: return (-1);
254: }
255: free(cvs_mt_stack[cvs_mtstk_depth--]);
1.11 deraadt 256: } else {
1.1 jfb 257: if (strcmp(line, "newline") == 0)
258: putc('\n', stdout);
259: else if (strncmp(line, "fname ", 6) == 0)
260: printf("%s", line + 6);
261: else {
262: /* assume text */
263: cp = strchr(line, ' ');
264: if (cp != NULL)
265: printf("%s", cp + 1);
266: }
267: }
268:
269: return (0);
270: case CVS_RESP_MBINARY:
271: cvs_log(LP_WARN, "Mbinary not supported in client yet");
272: break;
273: }
274:
275: fputs(line, stream);
276: fputc('\n', stream);
277:
278: return (0);
279: }
280:
281:
282: /*
283: * cvs_resp_ok()
284: *
1.13 tedu 285: * Handler for the `ok' response. This handler's job is to
1.1 jfb 286: */
287: static int
288: cvs_resp_ok(struct cvsroot *root, int type, char *line)
289: {
1.13 tedu 290:
1.1 jfb 291: return (1);
292: }
293:
294:
295: /*
296: * cvs_resp_error()
297: *
1.13 tedu 298: * Handler for the `error' response. This handler's job is to
1.1 jfb 299: */
300: static int
301: cvs_resp_error(struct cvsroot *root, int type, char *line)
302: {
1.13 tedu 303:
1.7 jfb 304: fprintf(stderr, "%s\n", line);
1.1 jfb 305: return (1);
306: }
307:
308:
309: /*
310: * cvs_resp_statdir()
311: *
312: * Handler for the `Clear-static-directory' and `Set-static-directory'
313: * responses.
314: */
315: static int
316: cvs_resp_statdir(struct cvsroot *root, int type, char *line)
317: {
318: int fd;
319: char rpath[MAXPATHLEN], statpath[MAXPATHLEN];
320:
1.3 jfb 321: /* remote directory line */
322: if (cvs_getln(root, rpath, sizeof(rpath)) < 0)
323: return (-1);
1.1 jfb 324:
325: snprintf(statpath, sizeof(statpath), "%s/%s", line,
326: CVS_PATH_STATICENTRIES);
327:
328: if ((type == CVS_RESP_CLRSTATDIR) &&
329: (unlink(statpath) == -1) && (errno != ENOENT)) {
330: cvs_log(LP_ERRNO, "failed to unlink %s file",
331: CVS_PATH_STATICENTRIES);
332: return (-1);
1.11 deraadt 333: } else if (type == CVS_RESP_SETSTATDIR) {
1.1 jfb 334: fd = open(statpath, O_CREAT|O_TRUNC|O_WRONLY, 0400);
335: if (fd == -1) {
1.3 jfb 336: cvs_log(LP_ERRNO,
337: "failed to set static directory on %s", line);
1.1 jfb 338: return (-1);
339: }
340: (void)close(fd);
341:
342: }
343:
344: return (0);
345: }
346:
347: /*
348: * cvs_resp_sticky()
349: *
1.4 jfb 350: * Handler for the `Clear-sticky' and `Set-sticky' responses. If the
351: * specified directory doesn't exist, we create it and attach it to the
352: * global file structure.
1.1 jfb 353: */
354: static int
355: cvs_resp_sticky(struct cvsroot *root, int type, char *line)
356: {
1.5 jfb 357: char buf[MAXPATHLEN], subdir[MAXPATHLEN], *file;
358: struct cvs_ent *ent;
1.4 jfb 359: CVSFILE *cf, *sdir;
360:
361: /* get the remote path */
1.5 jfb 362: if (cvs_getln(root, buf, sizeof(buf)) < 0)
1.4 jfb 363: return (-1);
1.1 jfb 364:
1.4 jfb 365: STRIP_SLASH(line);
1.1 jfb 366:
1.4 jfb 367: cvs_splitpath(line, subdir, sizeof(subdir), &file);
368: sdir = cvs_file_find(cvs_files, subdir);
369: if (sdir == NULL) {
370: cvs_log(LP_ERR, "failed to find %s", subdir);
371: return (-1);
372: }
1.1 jfb 373:
1.4 jfb 374: cf = cvs_file_find(sdir, file);
375: if (cf == NULL) {
1.1 jfb 376: /* attempt to create it */
1.8 jfb 377: cf = cvs_file_create(sdir, line, DT_DIR, 0755);
1.4 jfb 378: if (cf == NULL)
379: return (-1);
380: cf->cf_ddat->cd_repo = strdup(line);
381: cf->cf_ddat->cd_root = root;
382: root->cr_ref++;
1.1 jfb 383:
1.4 jfb 384: cvs_file_attach(sdir, cf);
1.5 jfb 385:
386: /* add a directory entry to the parent */
387: if (CVS_DIR_ENTRIES(sdir) != NULL) {
1.8 jfb 388: snprintf(buf, sizeof(buf), "D/%s////",
389: CVS_FILE_NAME(cf));
1.5 jfb 390: ent = cvs_ent_parse(buf);
391: if (ent == NULL)
392: cvs_log(LP_ERR,
393: "failed to create directory entry");
394: else
395: cvs_ent_add(CVS_DIR_ENTRIES(sdir), ent);
396: }
1.1 jfb 397: }
398:
1.4 jfb 399: if (type == CVS_RESP_CLRSTICKY)
400: cf->cf_ddat->cd_flags &= ~CVS_DIRF_STICKY;
401: else if (type == CVS_RESP_SETSTICKY)
402: cf->cf_ddat->cd_flags |= CVS_DIRF_STICKY;
1.1 jfb 403:
404: return (0);
405: }
406:
407:
408: /*
409: * cvs_resp_newentry()
410: *
411: * Handler for the `New-entry' response and `Checked-in' responses.
1.9 jfb 412: * In the case of `New-entry', we expect the entry line
1.1 jfb 413: */
414: static int
415: cvs_resp_newentry(struct cvsroot *root, int type, char *line)
416: {
417: char entbuf[128];
1.9 jfb 418: struct cvs_ent *ent;
1.1 jfb 419: CVSENTRIES *entfile;
420:
421: /* get the remote path */
422: cvs_getln(root, entbuf, sizeof(entbuf));
423:
424: /* get the new Entries line */
425: if (cvs_getln(root, entbuf, sizeof(entbuf)) < 0)
426: return (-1);
427:
428: entfile = cvs_ent_open(line, O_WRONLY);
429: if (entfile == NULL)
430: return (-1);
1.9 jfb 431: if (type == CVS_RESP_NEWENTRY) {
432: cvs_ent_addln(entfile, entbuf);
1.11 deraadt 433: } else if (type == CVS_RESP_CHECKEDIN) {
1.9 jfb 434: ent = cvs_ent_parse(entbuf);
435: if (ent == NULL) {
436: cvs_log(LP_ERR, "failed to parse entry");
437: cvs_ent_close(entfile);
438: return (-1);
439: }
440:
441: /* timestamp it to now */
442: ent->ce_mtime = time(&(ent->ce_mtime));
443:
444: /* replace the current entry with the one we just received */
445: if (cvs_ent_remove(entfile, ent->ce_name) < 0)
446: cvs_log(LP_WARN, "failed to remove `%s' entry",
447: ent->ce_name);
448:
449: cvs_ent_add(entfile, ent);
450: }
1.1 jfb 451: cvs_ent_close(entfile);
452:
453: return (0);
454: }
455:
456:
457: /*
458: * cvs_resp_cksum()
459: *
460: * Handler for the `Checksum' response. We store the checksum received for
461: * the next file in a dynamically-allocated buffer pointed to by <cvs_fcksum>.
462: * Upon next file reception, the handler checks to see if there is a stored
463: * checksum.
464: * The file handler must make sure that the checksums match and free the
465: * checksum buffer once it's done to indicate there is no further checksum.
466: */
467: static int
468: cvs_resp_cksum(struct cvsroot *root, int type, char *line)
469: {
470: if (cvs_fcksum != NULL) {
471: cvs_log(LP_WARN, "unused checksum");
472: free(cvs_fcksum);
473: }
474:
475: cvs_fcksum = strdup(line);
476: if (cvs_fcksum == NULL) {
477: cvs_log(LP_ERRNO, "failed to copy checksum string");
1.14 ! jfb 478: return (-1);
! 479: }
! 480:
! 481: return (0);
! 482: }
! 483:
! 484:
! 485: /*
! 486: * cvs_resp_copyfile()
! 487: *
! 488: * Handler for the `Copy-file' response, which is used to copy the contents
! 489: * of a file to another file for which the name is provided. The CVS protocol
! 490: * documentation states that this response is only used prior to a `Merged'
! 491: * response to create a backup of the file.
! 492: */
! 493: static int
! 494: cvs_resp_copyfile(struct cvsroot *root, int type, char *line)
! 495: {
! 496: char newname[MAXNAMLEN];
! 497:
! 498: /* read the new file name given by the server */
! 499: if (cvs_getln(root, newname, sizeof(newname)) < 0)
! 500: return (-1);
! 501:
! 502: if (rename(line, newname) == -1) {
! 503: cvs_log(LP_ERRNO, "failed to rename %s to %s", line, newname);
1.1 jfb 504: return (-1);
505: }
506:
507: return (0);
508: }
509:
510:
511: /*
512: * cvs_resp_modtime()
513: *
514: * Handler for the `Mod-time' file update modifying response. The timestamp
515: * given is used to set the last modification time on the next file that
516: * will be received.
517: */
518: static int
519: cvs_resp_modtime(struct cvsroot *root, int type, char *line)
520: {
1.4 jfb 521: cvs_modtime = cvs_datesec(line, CVS_DATE_RFC822, 1);
1.1 jfb 522: return (0);
523: }
524:
525:
526: /*
527: * cvs_resp_updated()
528: *
1.4 jfb 529: * Handler for the `Updated', `Update-existing', `Created', `Merged' and
530: * `Patched' responses, which all have a very similar format.
1.1 jfb 531: */
532: static int
533: cvs_resp_updated(struct cvsroot *root, int type, char *line)
534: {
535: mode_t fmode;
1.4 jfb 536: char path[MAXPATHLEN], cksum_buf[CVS_CKSUM_LEN];
1.1 jfb 537: BUF *fbuf;
1.4 jfb 538: CVSFILE *cf;
1.12 jfb 539: CVSENTRIES *entfile;
1.1 jfb 540: struct cvs_ent *ep;
1.2 jfb 541: struct timeval tv[2];
1.1 jfb 542:
1.4 jfb 543: STRIP_SLASH(line);
544:
545: /* find parent directory of file */
546: cf = cvs_file_find(cvs_files, line);
547: if (cf == NULL) {
548: cvs_log(LP_ERR, "failed to find directory %s", line);
549: return (-1);
550: }
1.1 jfb 551:
552: /* read the remote path of the file */
1.4 jfb 553: if (cvs_getln(root, path, sizeof(path)) < 0)
554: return (-1);
1.1 jfb 555:
556: /* read the new entry */
1.4 jfb 557: if (cvs_getln(root, path, sizeof(path)) < 0)
1.1 jfb 558: return (-1);
1.4 jfb 559:
560: if ((ep = cvs_ent_parse(path)) == NULL)
561: return (-1);
562: snprintf(path, sizeof(path), "%s/%s", line, ep->ce_name);
1.1 jfb 563:
1.12 jfb 564: entfile = cvs_ent_open(line, O_WRONLY);
565: if (entfile == NULL) {
566: cvs_ent_free(ep);
567: return (-1);
568: }
569:
1.1 jfb 570: if (type == CVS_RESP_CREATED) {
571: /* set the timestamp as the last one received from Mod-time */
1.4 jfb 572: ep->ce_mtime = cvs_modtime;
1.12 jfb 573: cvs_ent_add(entfile, ep);
574: } else if ((type == CVS_RESP_UPDEXIST) || (type == CVS_RESP_UPDATED)) {
575: if (cvs_ent_remove(entfile, ep->ce_name) < 0)
576: cvs_log(LP_WARN, "failed to remove entry for `%s'",
577: ep->ce_name);
578:
579: cvs_ent_add(entfile, ep);
580: } else if (type == CVS_RESP_MERGED) {
1.1 jfb 581: }
582:
583: fbuf = cvs_recvfile(root, &fmode);
584: if (fbuf == NULL)
585: return (-1);
586:
587: cvs_buf_write(fbuf, path, fmode);
1.2 jfb 588:
1.12 jfb 589: if (cvs_modtime != CVS_DATE_DMSEC) {
590: tv[0].tv_sec = (long)cvs_modtime;
591: tv[0].tv_usec = 0;
592: tv[1].tv_sec = (long)cvs_modtime;
593: tv[1].tv_usec = 0;
594: if (utimes(path, tv) == -1)
595: cvs_log(LP_ERRNO, "failed to set file timestamps");
596: }
1.1 jfb 597:
598: /* now see if there is a checksum */
599: if (cvs_fcksum != NULL) {
600: if (cvs_cksum(path, cksum_buf, sizeof(cksum_buf)) < 0) {
601: }
602:
603: if (strcmp(cksum_buf, cvs_fcksum) != 0) {
604: cvs_log(LP_ERR, "checksum error on received file");
605: (void)unlink(line);
606: }
607:
608: free(cvs_fcksum);
609: cvs_fcksum = NULL;
610: }
611:
612: return (0);
613: }
614:
615:
616: /*
617: * cvs_resp_removed()
618: *
1.10 jfb 619: * Handler for the `Removed' and `Remove-entry' responses. The `Removed'
620: * response is received when both a file and its entry need to be removed from
621: * the local copy. The `Remove-entry' is received in cases where the file is
622: * already gone but there is still an entry to remove in the Entries file.
1.1 jfb 623: */
624: static int
625: cvs_resp_removed(struct cvsroot *root, int type, char *line)
626: {
1.3 jfb 627: char base[MAXPATHLEN], *file;
1.1 jfb 628: CVSENTRIES *ef;
629:
1.3 jfb 630: cvs_splitpath(line, base, sizeof(base), &file);
1.1 jfb 631: ef = cvs_ent_open(base, O_RDWR);
1.10 jfb 632: if (ef == NULL) {
633: cvs_log(LP_ERR, "error handling `Removed' response");
634: if (type == CVS_RESP_RMENTRY)
635: return (-1);
636: } else {
637: (void)cvs_ent_remove(ef, file);
638: cvs_ent_close(ef);
639: }
640:
641: if ((type == CVS_RESP_REMOVED) && (unlink(line) == -1)) {
642: cvs_log(LP_ERRNO, "failed to unlink `%s'", line);
1.1 jfb 643: return (-1);
1.10 jfb 644: }
1.1 jfb 645:
646: return (0);
647: }
648:
649:
650: /*
651: * cvs_resp_mode()
652: *
653: * Handler for the `Mode' response.
654: */
655: static int
656: cvs_resp_mode(struct cvsroot *root, int type, char *line)
657: {
658: if (cvs_strtomode(line, &cvs_lastmode) < 0) {
1.12 jfb 659: cvs_log(LP_ERR, "error handling Mode response");
1.1 jfb 660: return (-1);
661: }
662: return (0);
663: }
664:
665:
666: /*
667: * cvs_resp_modxpand()
668: *
669: * Handler for the `Module-expansion' response.
670: */
671: static int
672: cvs_resp_modxpand(struct cvsroot *root, int type, char *line)
673: {
674: return (0);
675: }
676:
677: /*
678: * cvs_resp_rcsdiff()
679: *
680: * Handler for the `Rcs-diff' response.
681: */
682: static int
683: cvs_resp_rcsdiff(struct cvsroot *root, int type, char *line)
684: {
685: char file[MAXPATHLEN], buf[MAXPATHLEN], cksum_buf[CVS_CKSUM_LEN];
686: char *fname, *orig, *patch;
687: mode_t fmode;
688: BUF *res, *fcont, *patchbuf;
689: CVSENTRIES *entf;
690: struct cvs_ent *ent;
691:
692: /* get remote path and build local path of file to be patched */
693: cvs_getln(root, buf, sizeof(buf));
694: fname = strrchr(buf, '/');
695: if (fname == NULL)
696: fname = buf;
697: snprintf(file, sizeof(file), "%s%s", line, fname);
698:
699: /* get updated entry fields */
700: cvs_getln(root, buf, sizeof(buf));
701: ent = cvs_ent_parse(buf);
1.13 tedu 702: if (ent == NULL)
1.1 jfb 703: return (-1);
704:
705: patchbuf = cvs_recvfile(root, &fmode);
706: fcont = cvs_buf_load(file, BUF_AUTOEXT);
707: if (fcont == NULL)
708: return (-1);
709:
710: cvs_buf_putc(patchbuf, '\0');
711: cvs_buf_putc(fcont, '\0');
712: orig = cvs_buf_release(fcont);
713: patch = cvs_buf_release(patchbuf);
714:
715: res = rcs_patch(orig, patch);
716: if (res == NULL)
717: return (-1);
718:
719: cvs_buf_write(res, file, fmode);
720:
721: /* now see if there is a checksum */
722: if (cvs_fcksum != NULL) {
723: if (cvs_cksum(file, cksum_buf, sizeof(cksum_buf)) < 0) {
724: }
725:
726: if (strcmp(cksum_buf, cvs_fcksum) != 0) {
727: cvs_log(LP_ERR, "checksum error on received file");
728: (void)unlink(file);
729: }
730:
731: free(cvs_fcksum);
732: cvs_fcksum = NULL;
733: }
734:
735: /* update revision in entries */
736: entf = cvs_ent_open(line, O_WRONLY);
737: if (entf == NULL)
738: return (-1);
739:
740: cvs_ent_close(entf);
741:
742: return (0);
743: }
744:
745:
746: /*
747: * cvs_resp_template()
748: *
749: * Handler for the `Template' response.
750: */
751: static int
752: cvs_resp_template(struct cvsroot *root, int type, char *line)
753: {
754: mode_t mode;
755: BUF *tmpl;
756:
757: tmpl = cvs_recvfile(root, &mode);
758: if (tmpl == NULL)
759: return (-1);
760:
761: return (0);
762: }