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

Annotation of src/usr.bin/cvs/server.c, Revision 1.82

1.82    ! tobias      1: /*     $OpenBSD: server.c,v 1.81 2008/02/03 17:20:14 joris Exp $       */
1.1       jfb         2: /*
1.29      joris       3:  * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
1.1       jfb         4:  *
1.29      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.
1.1       jfb         8:  *
1.29      joris       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.73      tobias     18: #include <sys/types.h>
1.55      otto       19: #include <sys/stat.h>
                     20:
                     21: #include <errno.h>
                     22: #include <fcntl.h>
                     23: #include <libgen.h>
1.68      tobias     24: #include <stdio.h>
1.55      otto       25: #include <stdlib.h>
                     26: #include <string.h>
                     27: #include <unistd.h>
1.1       jfb        28:
                     29: #include "cvs.h"
1.29      joris      30: #include "remote.h"
                     31:
                     32: struct cvs_resp cvs_responses[] = {
                     33:        /* this is what our server uses, the client should support it */
                     34:        { "Valid-requests",     1,      cvs_client_validreq, RESP_NEEDED },
                     35:        { "ok",                 0,      cvs_client_ok, RESP_NEEDED},
                     36:        { "error",              0,      cvs_client_error, RESP_NEEDED },
                     37:        { "E",                  0,      cvs_client_e, RESP_NEEDED },
                     38:        { "M",                  0,      cvs_client_m, RESP_NEEDED },
                     39:        { "Checked-in",         0,      cvs_client_checkedin, RESP_NEEDED },
                     40:        { "Updated",            0,      cvs_client_updated, RESP_NEEDED },
                     41:        { "Merged",             0,      cvs_client_merged, RESP_NEEDED },
                     42:        { "Removed",            0,      cvs_client_removed, RESP_NEEDED },
                     43:        { "Remove-entry",       0,      cvs_client_remove_entry, RESP_NEEDED },
1.46      xsa        44:        { "Set-static-directory",       0,      cvs_client_set_static_directory, RESP_NEEDED },
1.45      xsa        45:        { "Clear-static-directory",     0,      cvs_client_clear_static_directory, RESP_NEEDED },
                     46:        { "Set-sticky",         0,      cvs_client_set_sticky, RESP_NEEDED },
                     47:        { "Clear-sticky",       0,      cvs_client_clear_sticky, RESP_NEEDED },
1.29      joris      48:
                     49:        /* unsupported responses until told otherwise */
                     50:        { "New-entry",                  0,      NULL, 0 },
                     51:        { "Created",                    0,      NULL, 0 },
                     52:        { "Update-existing",            0,      NULL, 0 },
                     53:        { "Rcs-diff",                   0,      NULL, 0 },
                     54:        { "Patched",                    0,      NULL, 0 },
                     55:        { "Mode",                       0,      NULL, 0 },
                     56:        { "Mod-time",                   0,      NULL, 0 },
                     57:        { "Checksum",                   0,      NULL, 0 },
                     58:        { "Copy-file",                  0,      NULL, 0 },
                     59:        { "Template",                   0,      NULL, 0 },
                     60:        { "Set-checkin-prog",           0,      NULL, 0 },
                     61:        { "Set-update-prog",            0,      NULL, 0 },
                     62:        { "Notified",                   0,      NULL, 0 },
                     63:        { "Module-expansion",           0,      NULL, 0 },
                     64:        { "Wrapper-rcsOption",          0,      NULL, 0 },
                     65:        { "Mbinary",                    0,      NULL, 0 },
                     66:        { "F",                          0,      NULL, 0 },
                     67:        { "MT",                         0,      NULL, 0 },
                     68:        { "",                           -1,     NULL, 0 }
                     69: };
1.1       jfb        70:
1.29      joris      71: int    cvs_server(int, char **);
                     72: char   *cvs_server_path = NULL;
1.1       jfb        73:
1.29      joris      74: static char *server_currentdir = NULL;
                     75: static char *server_argv[CVS_CMD_MAXARG];
                     76: static int server_argc = 1;
1.8       joris      77:
1.17      jfb        78: struct cvs_cmd cvs_cmd_server = {
1.78      tobias     79:        CVS_OP_SERVER, CVS_USE_WDIR, "server", { "", "" },
1.29      joris      80:        "server mode",
1.17      jfb        81:        NULL,
1.29      joris      82:        NULL,
                     83:        NULL,
                     84:        cvs_server
1.17      jfb        85: };
1.1       jfb        86:
1.14      joris      87:
1.1       jfb        88: int
                     89: cvs_server(int argc, char **argv)
                     90: {
1.29      joris      91:        char *cmd, *data;
                     92:        struct cvs_req *req;
                     93:
1.68      tobias     94:        if (argc > 1)
                     95:                fatal("server does not take any extra arguments");
                     96:
1.70      tobias     97:        /* Be on server-side very verbose per default. */
                     98:        verbosity = 2;
                     99:
1.68      tobias    100:        setvbuf(stdin, NULL, _IOLBF, 0);
                    101:        setvbuf(stdout, NULL, _IOLBF, 0);
                    102:
                    103:        cvs_server_active = 1;
                    104:
1.29      joris     105:        server_argv[0] = xstrdup("server");
                    106:
1.58      ray       107:        (void)xasprintf(&cvs_server_path, "%s/cvs-serv%d", cvs_tmpdir,
                    108:            getpid());
1.29      joris     109:
                    110:        if (mkdir(cvs_server_path, 0700) == -1)
                    111:                fatal("failed to create temporary server directory: %s, %s",
                    112:                    cvs_server_path, strerror(errno));
                    113:
                    114:        if (chdir(cvs_server_path) == -1)
                    115:                fatal("failed to change directory to '%s'", cvs_server_path);
                    116:
                    117:        for (;;) {
                    118:                cmd = cvs_remote_input();
                    119:
                    120:                if ((data = strchr(cmd, ' ')) != NULL)
                    121:                        (*data++) = '\0';
                    122:
                    123:                req = cvs_remote_get_request_info(cmd);
                    124:                if (req == NULL)
                    125:                        fatal("request '%s' is not supported by our server",
                    126:                            cmd);
                    127:
                    128:                if (req->hdlr == NULL)
                    129:                        fatal("opencvs server does not support '%s'", cmd);
1.63      joris     130:
                    131:                if ((req->flags & REQ_NEEDDIR) && (server_currentdir == NULL))
                    132:                        fatal("`%s' needs a directory to be sent with "
                    133:                            "the `Directory` request first", cmd);
1.29      joris     134:
                    135:                (*req->hdlr)(data);
                    136:                xfree(cmd);
1.14      joris     137:        }
                    138:
1.29      joris     139:        return (0);
                    140: }
                    141:
                    142: void
                    143: cvs_server_send_response(char *fmt, ...)
                    144: {
                    145:        va_list ap;
1.59      ray       146:        char *data;
1.29      joris     147:
                    148:        va_start(ap, fmt);
1.56      ray       149:        if (vasprintf(&data, fmt, ap) == -1)
                    150:                fatal("vasprintf: %s", strerror(errno));
1.29      joris     151:        va_end(ap);
1.14      joris     152:
1.30      joris     153:        cvs_log(LP_TRACE, "%s", data);
1.29      joris     154:        cvs_remote_output(data);
                    155:        xfree(data);
                    156: }
                    157:
                    158: void
                    159: cvs_server_root(char *data)
                    160: {
1.68      tobias    161:        if (data == NULL)
                    162:                fatal("Missing argument for Root");
                    163:
                    164:        if (current_cvsroot != NULL)
                    165:                return;
                    166:
                    167:        if (data[0] != '/' || (current_cvsroot = cvsroot_get(data)) == NULL)
                    168:                fatal("Invalid Root specified!");
1.73      tobias    169:
                    170:        cvs_parse_configfile();
1.81      joris     171:        cvs_parse_modules();
1.73      tobias    172:        umask(cvs_umask);
1.29      joris     173: }
                    174:
                    175: void
                    176: cvs_server_validresp(char *data)
                    177: {
                    178:        int i;
                    179:        char *sp, *ep;
                    180:        struct cvs_resp *resp;
                    181:
1.57      ray       182:        if ((sp = data) == NULL)
                    183:                fatal("Missing argument for Valid-responses");
                    184:
1.29      joris     185:        do {
                    186:                if ((ep = strchr(sp, ' ')) != NULL)
                    187:                        *ep = '\0';
                    188:
                    189:                resp = cvs_remote_get_response_info(sp);
                    190:                if (resp != NULL)
                    191:                        resp->supported = 1;
                    192:
                    193:                if (ep != NULL)
                    194:                        sp = ep + 1;
                    195:        } while (ep != NULL);
                    196:
                    197:        for (i = 0; cvs_responses[i].supported != -1; i++) {
                    198:                resp = &cvs_responses[i];
                    199:                if ((resp->flags & RESP_NEEDED) &&
                    200:                    resp->supported != 1) {
                    201:                        fatal("client does not support required '%s'",
                    202:                            resp->name);
1.1       jfb       203:                }
1.29      joris     204:        }
                    205: }
1.1       jfb       206:
1.29      joris     207: void
                    208: cvs_server_validreq(char *data)
                    209: {
                    210:        BUF *bp;
                    211:        char *d;
                    212:        int i, first;
                    213:
                    214:        first = 0;
                    215:        bp = cvs_buf_alloc(512, BUF_AUTOEXT);
                    216:        for (i = 0; cvs_requests[i].supported != -1; i++) {
                    217:                if (cvs_requests[i].hdlr == NULL)
1.5       jfb       218:                        continue;
1.1       jfb       219:
1.29      joris     220:                if (first != 0)
                    221:                        cvs_buf_append(bp, " ", 1);
                    222:                else
                    223:                        first++;
                    224:
                    225:                cvs_buf_append(bp, cvs_requests[i].name,
                    226:                    strlen(cvs_requests[i].name));
                    227:        }
                    228:
                    229:        cvs_buf_putc(bp, '\0');
                    230:        d = cvs_buf_release(bp);
                    231:
                    232:        cvs_server_send_response("Valid-requests %s", d);
                    233:        cvs_server_send_response("ok");
                    234:        xfree(d);
1.42      xsa       235: }
                    236:
                    237: void
1.43      xsa       238: cvs_server_static_directory(char *data)
                    239: {
                    240:        FILE *fp;
1.51      otto      241:        char fpath[MAXPATHLEN];
1.43      xsa       242:
1.54      xsa       243:        (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s",
                    244:            server_currentdir, CVS_PATH_STATICENTRIES);
1.43      xsa       245:
                    246:        if ((fp = fopen(fpath, "w+")) == NULL) {
                    247:                cvs_log(LP_ERRNO, "%s", fpath);
1.51      otto      248:                return;
1.43      xsa       249:        }
                    250:        (void)fclose(fp);
                    251: }
                    252:
                    253: void
1.42      xsa       254: cvs_server_sticky(char *data)
                    255: {
                    256:        FILE *fp;
1.51      otto      257:        char tagpath[MAXPATHLEN];
1.42      xsa       258:
1.57      ray       259:        if (data == NULL)
                    260:                fatal("Missing argument for Sticky");
                    261:
1.54      xsa       262:        (void)xsnprintf(tagpath, MAXPATHLEN, "%s/%s",
                    263:            server_currentdir, CVS_PATH_TAG);
1.42      xsa       264:
1.43      xsa       265:        if ((fp = fopen(tagpath, "w+")) == NULL) {
1.42      xsa       266:                cvs_log(LP_ERRNO, "%s", tagpath);
1.51      otto      267:                return;
1.42      xsa       268:        }
                    269:
                    270:        (void)fprintf(fp, "%s\n", data);
                    271:        (void)fclose(fp);
1.29      joris     272: }
                    273:
                    274: void
                    275: cvs_server_globalopt(char *data)
                    276: {
1.57      ray       277:        if (data == NULL)
                    278:                fatal("Missing argument for Global_option");
                    279:
1.38      xsa       280:        if (!strcmp(data, "-l"))
                    281:                cvs_nolog = 1;
1.29      joris     282:
                    283:        if (!strcmp(data, "-n"))
                    284:                cvs_noexec = 1;
1.38      xsa       285:
                    286:        if (!strcmp(data, "-Q"))
                    287:                verbosity = 0;
                    288:
1.70      tobias    289:        if (!strcmp(data, "-q"))
                    290:                verbosity = 1;
                    291:
1.38      xsa       292:        if (!strcmp(data, "-r"))
                    293:                cvs_readonly = 1;
                    294:
                    295:        if (!strcmp(data, "-t"))
                    296:                cvs_trace = 1;
1.39      xsa       297: }
                    298:
                    299: void
                    300: cvs_server_set(char *data)
                    301: {
                    302:        char *ep;
                    303:
1.57      ray       304:        if (data == NULL)
                    305:                fatal("Missing argument for Set");
                    306:
1.39      xsa       307:        ep = strchr(data, '=');
                    308:        if (ep == NULL)
                    309:                fatal("no = in variable assignment");
                    310:
                    311:        *(ep++) = '\0';
                    312:        if (cvs_var_set(data, ep) < 0)
                    313:                fatal("cvs_server_set: cvs_var_set failed");
1.29      joris     314: }
1.1       jfb       315:
1.29      joris     316: void
                    317: cvs_server_directory(char *data)
                    318: {
                    319:        CVSENTRIES *entlist;
1.51      otto      320:        char *dir, *repo, *parent, entry[CVS_ENT_MAXLINELEN], *dirn, *p;
1.68      tobias    321:
                    322:        if (current_cvsroot == NULL)
                    323:                fatal("No Root specified for Directory");
1.29      joris     324:
                    325:        dir = cvs_remote_input();
1.49      joris     326:        STRIP_SLASH(dir);
                    327:
                    328:        if (strlen(dir) < strlen(current_cvsroot->cr_dir))
1.29      joris     329:                fatal("cvs_server_directory: bad Directory request");
                    330:
1.49      joris     331:        repo = dir + strlen(current_cvsroot->cr_dir);
                    332:
                    333:        /*
                    334:         * This is somewhat required for checkout, as the
                    335:         * directory request will be:
                    336:         *
                    337:         * Directory .
                    338:         * /path/to/cvs/root
                    339:         */
                    340:        if (repo[0] == '\0')
                    341:                p = xstrdup(".");
                    342:        else
                    343:                p = xstrdup(repo + 1);
                    344:
1.65      joris     345:        cvs_mkpath(p, NULL);
1.29      joris     346:
1.49      joris     347:        if ((dirn = basename(p)) == NULL)
1.29      joris     348:                fatal("cvs_server_directory: %s", strerror(errno));
                    349:
1.49      joris     350:        if ((parent = dirname(p)) == NULL)
1.29      joris     351:                fatal("cvs_server_directory: %s", strerror(errno));
                    352:
                    353:        if (strcmp(parent, ".")) {
                    354:                entlist = cvs_ent_open(parent);
1.53      xsa       355:                (void)xsnprintf(entry, CVS_ENT_MAXLINELEN, "D/%s////", dirn);
1.29      joris     356:
                    357:                cvs_ent_add(entlist, entry);
                    358:                cvs_ent_close(entlist, ENT_SYNC);
1.1       jfb       359:        }
                    360:
1.29      joris     361:        if (server_currentdir != NULL)
                    362:                xfree(server_currentdir);
1.61      ray       363:        server_currentdir = p;
1.29      joris     364:
                    365:        xfree(dir);
                    366: }
                    367:
                    368: void
                    369: cvs_server_entry(char *data)
                    370: {
                    371:        CVSENTRIES *entlist;
                    372:
1.57      ray       373:        if (data == NULL)
                    374:                fatal("Missing argument for Entry");
                    375:
1.29      joris     376:        entlist = cvs_ent_open(server_currentdir);
                    377:        cvs_ent_add(entlist, data);
                    378:        cvs_ent_close(entlist, ENT_SYNC);
                    379: }
                    380:
                    381: void
                    382: cvs_server_modified(char *data)
                    383: {
1.41      xsa       384:        int fd;
1.29      joris     385:        size_t flen;
                    386:        mode_t fmode;
                    387:        const char *errstr;
1.51      otto      388:        char *mode, *len, fpath[MAXPATHLEN];
1.29      joris     389:
1.57      ray       390:        if (data == NULL)
                    391:                fatal("Missing argument for Modified");
                    392:
1.29      joris     393:        mode = cvs_remote_input();
                    394:        len = cvs_remote_input();
                    395:
                    396:        cvs_strtomode(mode, &fmode);
                    397:        xfree(mode);
                    398:
                    399:        flen = strtonum(len, 0, INT_MAX, &errstr);
                    400:        if (errstr != NULL)
                    401:                fatal("cvs_server_modified: %s", errstr);
                    402:        xfree(len);
                    403:
1.54      xsa       404:        (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", server_currentdir, data);
1.29      joris     405:
                    406:        if ((fd = open(fpath, O_WRONLY | O_CREAT | O_TRUNC)) == -1)
                    407:                fatal("cvs_server_modified: %s: %s", fpath, strerror(errno));
                    408:
1.48      joris     409:        cvs_remote_receive_file(fd, flen);
1.29      joris     410:
                    411:        if (fchmod(fd, 0600) == -1)
                    412:                fatal("cvs_server_modified: failed to set file mode");
                    413:
                    414:        (void)close(fd);
                    415: }
                    416:
                    417: void
                    418: cvs_server_useunchanged(char *data)
                    419: {
                    420: }
                    421:
                    422: void
                    423: cvs_server_unchanged(char *data)
                    424: {
1.51      otto      425:        char fpath[MAXPATHLEN];
1.29      joris     426:        CVSENTRIES *entlist;
                    427:        struct cvs_ent *ent;
1.71      joris     428:        char sticky[CVS_ENT_MAXLINELEN];
                    429:        char rev[CVS_REV_BUFSZ], entry[CVS_ENT_MAXLINELEN];
1.29      joris     430:
1.57      ray       431:        if (data == NULL)
                    432:                fatal("Missing argument for Unchanged");
                    433:
1.54      xsa       434:        (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", server_currentdir, data);
1.29      joris     435:
                    436:        entlist = cvs_ent_open(server_currentdir);
                    437:        ent = cvs_ent_get(entlist, data);
                    438:        if (ent == NULL)
                    439:                fatal("received Unchanged request for non-existing file");
                    440:
1.71      joris     441:        sticky[0] = '\0';
                    442:        if (ent->ce_tag != NULL)
                    443:                (void)xsnprintf(sticky, sizeof(sticky), "T%s", ent->ce_tag);
                    444:
                    445:        rcsnum_tostr(ent->ce_rev, rev, sizeof(rev));
                    446:        (void)xsnprintf(entry, sizeof(entry), "/%s/%s/%s/%s/%s",
                    447:            ent->ce_name, rev, CVS_SERVER_UNCHANGED, ent->ce_opts ?
                    448:            ent->ce_opts : "", sticky);
1.29      joris     449:
                    450:        cvs_ent_free(ent);
1.71      joris     451:        cvs_ent_add(entlist, entry);
                    452:        cvs_ent_close(entlist, ENT_SYNC);
1.29      joris     453: }
                    454:
                    455: void
                    456: cvs_server_questionable(char *data)
                    457: {
                    458: }
                    459:
                    460: void
                    461: cvs_server_argument(char *data)
                    462: {
1.60      ray       463:        if (server_argc >= CVS_CMD_MAXARG)
1.29      joris     464:                fatal("cvs_server_argument: too many arguments sent");
1.57      ray       465:
                    466:        if (data == NULL)
                    467:                fatal("Missing argument for Argument");
1.29      joris     468:
                    469:        server_argv[server_argc++] = xstrdup(data);
1.37      xsa       470: }
                    471:
                    472: void
                    473: cvs_server_argumentx(char *data)
                    474: {
1.66      joris     475:        int idx;
                    476:        size_t len;
                    477:
                    478:        if (server_argc < 0)
                    479:                fatal("Protocol Error: ArgumentX without previous argument");
                    480:
                    481:        idx = server_argc - 1;
                    482:
                    483:        len = strlen(server_argv[idx]) + strlen(data) + 2;
                    484:        server_argv[idx] = xrealloc(server_argv[idx], len, sizeof(char));
                    485:        strlcat(server_argv[idx], "\n", len);
                    486:        strlcat(server_argv[idx], data, len);
1.44      xsa       487: }
                    488:
                    489: void
                    490: cvs_server_update_patches(char *data)
                    491: {
                    492:        /*
                    493:         * This does not actually do anything.
                    494:         * It is used to tell that the server is able to
                    495:         * generate patches when given an `update' request.
                    496:         * The client must issue the -u argument to `update'
                    497:         * to receive patches.
                    498:         */
1.29      joris     499: }
                    500:
                    501: void
1.31      xsa       502: cvs_server_add(char *data)
                    503: {
                    504:        if (chdir(server_currentdir) == -1)
                    505:                fatal("cvs_server_add: %s", strerror(errno));
                    506:
                    507:        cvs_cmdop = CVS_OP_ADD;
1.78      tobias    508:        cmdp->cmd_flags = cvs_cmd_add.cmd_flags;
1.31      xsa       509:        cvs_add(server_argc, server_argv);
1.50      joris     510:        cvs_server_send_response("ok");
                    511: }
                    512:
                    513: void
                    514: cvs_server_import(char *data)
                    515: {
                    516:        if (chdir(server_currentdir) == -1)
                    517:                fatal("cvs_server_import: %s", strerror(errno));
                    518:
                    519:        cvs_cmdop = CVS_OP_IMPORT;
1.78      tobias    520:        cmdp->cmd_flags = cvs_cmd_import.cmd_flags;
1.50      joris     521:        cvs_import(server_argc, server_argv);
1.31      xsa       522:        cvs_server_send_response("ok");
                    523: }
1.35      xsa       524:
                    525: void
                    526: cvs_server_admin(char *data)
                    527: {
                    528:        if (chdir(server_currentdir) == -1)
                    529:                fatal("cvs_server_admin: %s", strerror(errno));
                    530:
                    531:        cvs_cmdop = CVS_OP_ADMIN;
1.78      tobias    532:        cmdp->cmd_flags = cvs_cmd_admin.cmd_flags;
1.35      xsa       533:        cvs_admin(server_argc, server_argv);
                    534:        cvs_server_send_response("ok");
                    535: }
                    536:
1.40      xsa       537: void
                    538: cvs_server_annotate(char *data)
                    539: {
                    540:        if (chdir(server_currentdir) == -1)
                    541:                fatal("cvs_server_annotate: %s", strerror(errno));
                    542:
                    543:        cvs_cmdop = CVS_OP_ANNOTATE;
1.78      tobias    544:        cmdp->cmd_flags = cvs_cmd_annotate.cmd_flags;
1.80      tobias    545:        cvs_annotate(server_argc, server_argv);
                    546:        cvs_server_send_response("ok");
                    547: }
                    548:
                    549: void
                    550: cvs_server_rannotate(char *data)
                    551: {
                    552:        if (chdir(server_currentdir) == -1)
                    553:                fatal("cvs_server_rannotate: %s", strerror(errno));
                    554:
                    555:        cvs_cmdop = CVS_OP_RANNOTATE;
                    556:        cmdp->cmd_flags = cvs_cmd_rannotate.cmd_flags;
1.40      xsa       557:        cvs_annotate(server_argc, server_argv);
                    558:        cvs_server_send_response("ok");
                    559: }
1.31      xsa       560:
                    561: void
1.29      joris     562: cvs_server_commit(char *data)
                    563: {
                    564:        if (chdir(server_currentdir) == -1)
                    565:                fatal("cvs_server_commit: %s", strerror(errno));
                    566:
                    567:        cvs_cmdop = CVS_OP_COMMIT;
1.78      tobias    568:        cmdp->cmd_flags = cvs_cmd_commit.cmd_flags;
1.29      joris     569:        cvs_commit(server_argc, server_argv);
1.49      joris     570:        cvs_server_send_response("ok");
                    571: }
                    572:
                    573: void
                    574: cvs_server_checkout(char *data)
1.77      tobias    575: {
                    576:        if (chdir(server_currentdir) == -1)
1.49      joris     577:                fatal("cvs_server_checkout: %s", strerror(errno));
                    578:
                    579:        cvs_cmdop = CVS_OP_CHECKOUT;
1.78      tobias    580:        cmdp->cmd_flags = cvs_cmd_checkout.cmd_flags;
1.49      joris     581:        cvs_checkout(server_argc, server_argv);
1.29      joris     582:        cvs_server_send_response("ok");
                    583: }
                    584:
                    585: void
                    586: cvs_server_diff(char *data)
                    587: {
                    588:        if (chdir(server_currentdir) == -1)
                    589:                fatal("cvs_server_diff: %s", strerror(errno));
                    590:
                    591:        cvs_cmdop = CVS_OP_DIFF;
1.78      tobias    592:        cmdp->cmd_flags = cvs_cmd_diff.cmd_flags;
1.82    ! tobias    593:        cvs_diff(server_argc, server_argv);
        !           594:        cvs_server_send_response("ok");
        !           595: }
        !           596:
        !           597: void
        !           598: cvs_server_rdiff(char *data)
        !           599: {
        !           600:        if (chdir(server_currentdir) == -1)
        !           601:                fatal("cvs_server_rdiff: %s", strerror(errno));
        !           602:
        !           603:        cvs_cmdop = CVS_OP_RDIFF;
        !           604:        cmdp->cmd_flags = cvs_cmd_rdiff.cmd_flags;
1.29      joris     605:        cvs_diff(server_argc, server_argv);
1.76      tobias    606:        cvs_server_send_response("ok");
                    607: }
                    608:
                    609: void
                    610: cvs_server_export(char *data)
1.77      tobias    611: {
                    612:        if (chdir(server_currentdir) == -1)
                    613:                fatal("cvs_server_export: %s", strerror(errno));
1.76      tobias    614:
                    615:        cvs_cmdop = CVS_OP_EXPORT;
1.78      tobias    616:        cmdp->cmd_flags = cvs_cmd_export.cmd_flags;
1.76      tobias    617:        cvs_checkout(server_argc, server_argv);
1.34      xsa       618:        cvs_server_send_response("ok");
                    619: }
                    620:
                    621: void
                    622: cvs_server_init(char *data)
                    623: {
1.69      tobias    624:        if (data == NULL)
                    625:                fatal("Missing argument for init");
                    626:
                    627:        if (current_cvsroot != NULL)
                    628:                fatal("Root in combination with init is not supported");
                    629:
                    630:        if ((current_cvsroot = cvsroot_get(data)) == NULL)
                    631:                fatal("Invalid argument for init");
1.34      xsa       632:
                    633:        cvs_cmdop = CVS_OP_INIT;
1.78      tobias    634:        cmdp->cmd_flags = cvs_cmd_init.cmd_flags;
1.34      xsa       635:        cvs_init(server_argc, server_argv);
1.64      xsa       636:        cvs_server_send_response("ok");
                    637: }
                    638:
                    639: void
                    640: cvs_server_release(char *data)
                    641: {
                    642:        if (chdir(server_currentdir) == -1)
1.67      xsa       643:                fatal("cvs_server_release: %s", strerror(errno));
1.64      xsa       644:
                    645:        cvs_cmdop = CVS_OP_RELEASE;
1.78      tobias    646:        cmdp->cmd_flags = cvs_cmd_release.cmd_flags;
1.64      xsa       647:        cvs_release(server_argc, server_argv);
1.31      xsa       648:        cvs_server_send_response("ok");
                    649: }
                    650:
                    651: void
                    652: cvs_server_remove(char *data)
                    653: {
                    654:        if (chdir(server_currentdir) == -1)
                    655:                fatal("cvs_server_remove: %s", strerror(errno));
                    656:
                    657:        cvs_cmdop = CVS_OP_REMOVE;
1.78      tobias    658:        cmdp->cmd_flags = cvs_cmd_remove.cmd_flags;
1.31      xsa       659:        cvs_remove(server_argc, server_argv);
1.29      joris     660:        cvs_server_send_response("ok");
                    661: }
                    662:
                    663: void
                    664: cvs_server_status(char *data)
                    665: {
                    666:        if (chdir(server_currentdir) == -1)
                    667:                fatal("cvs_server_status: %s", strerror(errno));
                    668:
                    669:        cvs_cmdop = CVS_OP_STATUS;
1.78      tobias    670:        cmdp->cmd_flags = cvs_cmd_status.cmd_flags;
1.29      joris     671:        cvs_status(server_argc, server_argv);
                    672:        cvs_server_send_response("ok");
                    673: }
                    674:
                    675: void
                    676: cvs_server_log(char *data)
                    677: {
                    678:        if (chdir(server_currentdir) == -1)
                    679:                fatal("cvs_server_log: %s", strerror(errno));
                    680:
                    681:        cvs_cmdop = CVS_OP_LOG;
1.78      tobias    682:        cmdp->cmd_flags = cvs_cmd_log.cmd_flags;
1.62      niallo    683:        cvs_getlog(server_argc, server_argv);
                    684:        cvs_server_send_response("ok");
                    685: }
1.79      xsa       686:
1.62      niallo    687: void
                    688: cvs_server_rlog(char *data)
                    689: {
1.74      tobias    690:        if (chdir(current_cvsroot->cr_dir) == -1)
1.67      xsa       691:                fatal("cvs_server_rlog: %s", strerror(errno));
1.62      niallo    692:
                    693:        cvs_cmdop = CVS_OP_RLOG;
1.78      tobias    694:        cmdp->cmd_flags = cvs_cmd_rlog.cmd_flags;
1.32      xsa       695:        cvs_getlog(server_argc, server_argv);
                    696:        cvs_server_send_response("ok");
                    697: }
                    698:
                    699: void
                    700: cvs_server_tag(char *data)
                    701: {
                    702:        if (chdir(server_currentdir) == -1)
                    703:                fatal("cvs_server_tag: %s", strerror(errno));
                    704:
                    705:        cvs_cmdop = CVS_OP_TAG;
1.78      tobias    706:        cmdp->cmd_flags = cvs_cmd_tag.cmd_flags;
1.75      tobias    707:        cvs_tag(server_argc, server_argv);
                    708:        cvs_server_send_response("ok");
                    709: }
                    710:
                    711: void
                    712: cvs_server_rtag(char *data)
                    713: {
                    714:        if (chdir(current_cvsroot->cr_dir) == -1)
1.77      tobias    715:                fatal("cvs_server_rtag: %s", strerror(errno));
1.75      tobias    716:
                    717:        cvs_cmdop = CVS_OP_RTAG;
1.78      tobias    718:        cmdp->cmd_flags = cvs_cmd_rtag.cmd_flags;
1.33      xsa       719:        cvs_tag(server_argc, server_argv);
1.29      joris     720:        cvs_server_send_response("ok");
                    721: }
                    722:
                    723: void
                    724: cvs_server_update(char *data)
                    725: {
                    726:        if (chdir(server_currentdir) == -1)
                    727:                fatal("cvs_server_update: %s", strerror(errno));
1.14      joris     728:
1.29      joris     729:        cvs_cmdop = CVS_OP_UPDATE;
1.78      tobias    730:        cmdp->cmd_flags = cvs_cmd_update.cmd_flags;
1.29      joris     731:        cvs_update(server_argc, server_argv);
1.36      xsa       732:        cvs_server_send_response("ok");
                    733: }
                    734:
                    735: void
                    736: cvs_server_version(char *data)
                    737: {
                    738:        cvs_cmdop = CVS_OP_VERSION;
1.78      tobias    739:        cmdp->cmd_flags = cvs_cmd_version.cmd_flags;
1.36      xsa       740:        cvs_version(server_argc, server_argv);
1.29      joris     741:        cvs_server_send_response("ok");
1.47      joris     742: }
                    743:
                    744: void
                    745: cvs_server_update_entry(const char *resp, struct cvs_file *cf)
                    746: {
1.58      ray       747:        char *p;
1.65      joris     748:        char repo[MAXPATHLEN], fpath[MAXPATHLEN];
1.47      joris     749:
                    750:        if ((p = strrchr(cf->file_rpath, ',')) != NULL)
                    751:                *p = '\0';
                    752:
1.65      joris     753:        cvs_get_repository_path(cf->file_wd, repo, MAXPATHLEN);
                    754:        (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", repo, cf->file_name);
                    755:
1.58      ray       756:        cvs_server_send_response("%s %s/", resp, cf->file_wd);
1.65      joris     757:        cvs_remote_output(fpath);
1.47      joris     758:
                    759:        if (p != NULL)
                    760:                *p = ',';
1.65      joris     761: }
                    762:
                    763: void
                    764: cvs_server_set_sticky(char *dir, char *tag)
                    765: {
1.72      joris     766:        char fpath[MAXPATHLEN];
1.65      joris     767:
1.81      joris     768:        if (module_repo_root != NULL) {
                    769:                (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s/%s",
                    770:                    current_cvsroot->cr_dir, module_repo_root, dir);
                    771:        } else {
                    772:                (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s",
                    773:                    current_cvsroot->cr_dir, dir);
                    774:        }
1.65      joris     775:
                    776:        cvs_server_send_response("Set-sticky %s", dir);
                    777:        cvs_remote_output(fpath);
1.72      joris     778:        cvs_remote_output(tag);
1.65      joris     779: }
                    780:
                    781: void
                    782: cvs_server_clear_sticky(char *dir)
                    783: {
                    784:        char fpath[MAXPATHLEN];
                    785:
1.81      joris     786:        if (module_repo_root != NULL) {
                    787:                (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s/%s",
                    788:                    current_cvsroot->cr_dir, module_repo_root, dir);
                    789:        } else {
                    790:                (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s",
                    791:                    current_cvsroot->cr_dir, dir);
                    792:        }
1.65      joris     793:
                    794:        cvs_server_send_response("Clear-sticky %s", dir);
                    795:        cvs_remote_output(fpath);
1.1       jfb       796: }