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

1.84    ! tobias      1: /*     $OpenBSD: server.c,v 1.83 2008/02/09 20:04:00 xsa 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;
1.84    ! tobias    215:        bp = cvs_buf_alloc(512);
1.29      joris     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.83      xsa       320:        char *dir, *repo, *parent, *entry, *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, ".")) {
1.83      xsa       354:                entry = xmalloc(CVS_ENT_MAXLINELEN);
                    355:                cvs_ent_line_str(dirn, NULL, NULL, NULL, NULL, 1, 0,
                    356:                    entry, CVS_ENT_MAXLINELEN);
                    357:
1.29      joris     358:                entlist = cvs_ent_open(parent);
                    359:                cvs_ent_add(entlist, entry);
                    360:                cvs_ent_close(entlist, ENT_SYNC);
1.83      xsa       361:                xfree(entry);
1.1       jfb       362:        }
                    363:
1.29      joris     364:        if (server_currentdir != NULL)
                    365:                xfree(server_currentdir);
1.61      ray       366:        server_currentdir = p;
1.29      joris     367:
                    368:        xfree(dir);
                    369: }
                    370:
                    371: void
                    372: cvs_server_entry(char *data)
                    373: {
                    374:        CVSENTRIES *entlist;
                    375:
1.57      ray       376:        if (data == NULL)
                    377:                fatal("Missing argument for Entry");
                    378:
1.29      joris     379:        entlist = cvs_ent_open(server_currentdir);
                    380:        cvs_ent_add(entlist, data);
                    381:        cvs_ent_close(entlist, ENT_SYNC);
                    382: }
                    383:
                    384: void
                    385: cvs_server_modified(char *data)
                    386: {
1.41      xsa       387:        int fd;
1.29      joris     388:        size_t flen;
                    389:        mode_t fmode;
                    390:        const char *errstr;
1.51      otto      391:        char *mode, *len, fpath[MAXPATHLEN];
1.29      joris     392:
1.57      ray       393:        if (data == NULL)
                    394:                fatal("Missing argument for Modified");
                    395:
1.29      joris     396:        mode = cvs_remote_input();
                    397:        len = cvs_remote_input();
                    398:
                    399:        cvs_strtomode(mode, &fmode);
                    400:        xfree(mode);
                    401:
                    402:        flen = strtonum(len, 0, INT_MAX, &errstr);
                    403:        if (errstr != NULL)
                    404:                fatal("cvs_server_modified: %s", errstr);
                    405:        xfree(len);
                    406:
1.54      xsa       407:        (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", server_currentdir, data);
1.29      joris     408:
                    409:        if ((fd = open(fpath, O_WRONLY | O_CREAT | O_TRUNC)) == -1)
                    410:                fatal("cvs_server_modified: %s: %s", fpath, strerror(errno));
                    411:
1.48      joris     412:        cvs_remote_receive_file(fd, flen);
1.29      joris     413:
                    414:        if (fchmod(fd, 0600) == -1)
                    415:                fatal("cvs_server_modified: failed to set file mode");
                    416:
                    417:        (void)close(fd);
                    418: }
                    419:
                    420: void
                    421: cvs_server_useunchanged(char *data)
                    422: {
                    423: }
                    424:
                    425: void
                    426: cvs_server_unchanged(char *data)
                    427: {
1.51      otto      428:        char fpath[MAXPATHLEN];
1.29      joris     429:        CVSENTRIES *entlist;
                    430:        struct cvs_ent *ent;
1.71      joris     431:        char sticky[CVS_ENT_MAXLINELEN];
                    432:        char rev[CVS_REV_BUFSZ], entry[CVS_ENT_MAXLINELEN];
1.29      joris     433:
1.57      ray       434:        if (data == NULL)
                    435:                fatal("Missing argument for Unchanged");
                    436:
1.54      xsa       437:        (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", server_currentdir, data);
1.29      joris     438:
                    439:        entlist = cvs_ent_open(server_currentdir);
                    440:        ent = cvs_ent_get(entlist, data);
                    441:        if (ent == NULL)
                    442:                fatal("received Unchanged request for non-existing file");
                    443:
1.71      joris     444:        sticky[0] = '\0';
                    445:        if (ent->ce_tag != NULL)
                    446:                (void)xsnprintf(sticky, sizeof(sticky), "T%s", ent->ce_tag);
                    447:
                    448:        rcsnum_tostr(ent->ce_rev, rev, sizeof(rev));
                    449:        (void)xsnprintf(entry, sizeof(entry), "/%s/%s/%s/%s/%s",
                    450:            ent->ce_name, rev, CVS_SERVER_UNCHANGED, ent->ce_opts ?
                    451:            ent->ce_opts : "", sticky);
1.29      joris     452:
                    453:        cvs_ent_free(ent);
1.71      joris     454:        cvs_ent_add(entlist, entry);
                    455:        cvs_ent_close(entlist, ENT_SYNC);
1.29      joris     456: }
                    457:
                    458: void
                    459: cvs_server_questionable(char *data)
                    460: {
                    461: }
                    462:
                    463: void
                    464: cvs_server_argument(char *data)
                    465: {
1.60      ray       466:        if (server_argc >= CVS_CMD_MAXARG)
1.29      joris     467:                fatal("cvs_server_argument: too many arguments sent");
1.57      ray       468:
                    469:        if (data == NULL)
                    470:                fatal("Missing argument for Argument");
1.29      joris     471:
                    472:        server_argv[server_argc++] = xstrdup(data);
1.37      xsa       473: }
                    474:
                    475: void
                    476: cvs_server_argumentx(char *data)
                    477: {
1.66      joris     478:        int idx;
                    479:        size_t len;
                    480:
                    481:        if (server_argc < 0)
                    482:                fatal("Protocol Error: ArgumentX without previous argument");
                    483:
                    484:        idx = server_argc - 1;
                    485:
                    486:        len = strlen(server_argv[idx]) + strlen(data) + 2;
                    487:        server_argv[idx] = xrealloc(server_argv[idx], len, sizeof(char));
                    488:        strlcat(server_argv[idx], "\n", len);
                    489:        strlcat(server_argv[idx], data, len);
1.44      xsa       490: }
                    491:
                    492: void
                    493: cvs_server_update_patches(char *data)
                    494: {
                    495:        /*
                    496:         * This does not actually do anything.
                    497:         * It is used to tell that the server is able to
                    498:         * generate patches when given an `update' request.
                    499:         * The client must issue the -u argument to `update'
                    500:         * to receive patches.
                    501:         */
1.29      joris     502: }
                    503:
                    504: void
1.31      xsa       505: cvs_server_add(char *data)
                    506: {
                    507:        if (chdir(server_currentdir) == -1)
                    508:                fatal("cvs_server_add: %s", strerror(errno));
                    509:
                    510:        cvs_cmdop = CVS_OP_ADD;
1.78      tobias    511:        cmdp->cmd_flags = cvs_cmd_add.cmd_flags;
1.31      xsa       512:        cvs_add(server_argc, server_argv);
1.50      joris     513:        cvs_server_send_response("ok");
                    514: }
                    515:
                    516: void
                    517: cvs_server_import(char *data)
                    518: {
                    519:        if (chdir(server_currentdir) == -1)
                    520:                fatal("cvs_server_import: %s", strerror(errno));
                    521:
                    522:        cvs_cmdop = CVS_OP_IMPORT;
1.78      tobias    523:        cmdp->cmd_flags = cvs_cmd_import.cmd_flags;
1.50      joris     524:        cvs_import(server_argc, server_argv);
1.31      xsa       525:        cvs_server_send_response("ok");
                    526: }
1.35      xsa       527:
                    528: void
                    529: cvs_server_admin(char *data)
                    530: {
                    531:        if (chdir(server_currentdir) == -1)
                    532:                fatal("cvs_server_admin: %s", strerror(errno));
                    533:
                    534:        cvs_cmdop = CVS_OP_ADMIN;
1.78      tobias    535:        cmdp->cmd_flags = cvs_cmd_admin.cmd_flags;
1.35      xsa       536:        cvs_admin(server_argc, server_argv);
                    537:        cvs_server_send_response("ok");
                    538: }
                    539:
1.40      xsa       540: void
                    541: cvs_server_annotate(char *data)
                    542: {
                    543:        if (chdir(server_currentdir) == -1)
                    544:                fatal("cvs_server_annotate: %s", strerror(errno));
                    545:
                    546:        cvs_cmdop = CVS_OP_ANNOTATE;
1.78      tobias    547:        cmdp->cmd_flags = cvs_cmd_annotate.cmd_flags;
1.80      tobias    548:        cvs_annotate(server_argc, server_argv);
                    549:        cvs_server_send_response("ok");
                    550: }
                    551:
                    552: void
                    553: cvs_server_rannotate(char *data)
                    554: {
                    555:        if (chdir(server_currentdir) == -1)
                    556:                fatal("cvs_server_rannotate: %s", strerror(errno));
                    557:
                    558:        cvs_cmdop = CVS_OP_RANNOTATE;
                    559:        cmdp->cmd_flags = cvs_cmd_rannotate.cmd_flags;
1.40      xsa       560:        cvs_annotate(server_argc, server_argv);
                    561:        cvs_server_send_response("ok");
                    562: }
1.31      xsa       563:
                    564: void
1.29      joris     565: cvs_server_commit(char *data)
                    566: {
                    567:        if (chdir(server_currentdir) == -1)
                    568:                fatal("cvs_server_commit: %s", strerror(errno));
                    569:
                    570:        cvs_cmdop = CVS_OP_COMMIT;
1.78      tobias    571:        cmdp->cmd_flags = cvs_cmd_commit.cmd_flags;
1.29      joris     572:        cvs_commit(server_argc, server_argv);
1.49      joris     573:        cvs_server_send_response("ok");
                    574: }
                    575:
                    576: void
                    577: cvs_server_checkout(char *data)
1.77      tobias    578: {
                    579:        if (chdir(server_currentdir) == -1)
1.49      joris     580:                fatal("cvs_server_checkout: %s", strerror(errno));
                    581:
                    582:        cvs_cmdop = CVS_OP_CHECKOUT;
1.78      tobias    583:        cmdp->cmd_flags = cvs_cmd_checkout.cmd_flags;
1.49      joris     584:        cvs_checkout(server_argc, server_argv);
1.29      joris     585:        cvs_server_send_response("ok");
                    586: }
                    587:
                    588: void
                    589: cvs_server_diff(char *data)
                    590: {
                    591:        if (chdir(server_currentdir) == -1)
                    592:                fatal("cvs_server_diff: %s", strerror(errno));
                    593:
                    594:        cvs_cmdop = CVS_OP_DIFF;
1.78      tobias    595:        cmdp->cmd_flags = cvs_cmd_diff.cmd_flags;
1.82      tobias    596:        cvs_diff(server_argc, server_argv);
                    597:        cvs_server_send_response("ok");
                    598: }
                    599:
                    600: void
                    601: cvs_server_rdiff(char *data)
                    602: {
                    603:        if (chdir(server_currentdir) == -1)
                    604:                fatal("cvs_server_rdiff: %s", strerror(errno));
                    605:
                    606:        cvs_cmdop = CVS_OP_RDIFF;
                    607:        cmdp->cmd_flags = cvs_cmd_rdiff.cmd_flags;
1.29      joris     608:        cvs_diff(server_argc, server_argv);
1.76      tobias    609:        cvs_server_send_response("ok");
                    610: }
                    611:
                    612: void
                    613: cvs_server_export(char *data)
1.77      tobias    614: {
                    615:        if (chdir(server_currentdir) == -1)
                    616:                fatal("cvs_server_export: %s", strerror(errno));
1.76      tobias    617:
                    618:        cvs_cmdop = CVS_OP_EXPORT;
1.78      tobias    619:        cmdp->cmd_flags = cvs_cmd_export.cmd_flags;
1.76      tobias    620:        cvs_checkout(server_argc, server_argv);
1.34      xsa       621:        cvs_server_send_response("ok");
                    622: }
                    623:
                    624: void
                    625: cvs_server_init(char *data)
                    626: {
1.69      tobias    627:        if (data == NULL)
                    628:                fatal("Missing argument for init");
                    629:
                    630:        if (current_cvsroot != NULL)
                    631:                fatal("Root in combination with init is not supported");
                    632:
                    633:        if ((current_cvsroot = cvsroot_get(data)) == NULL)
                    634:                fatal("Invalid argument for init");
1.34      xsa       635:
                    636:        cvs_cmdop = CVS_OP_INIT;
1.78      tobias    637:        cmdp->cmd_flags = cvs_cmd_init.cmd_flags;
1.34      xsa       638:        cvs_init(server_argc, server_argv);
1.64      xsa       639:        cvs_server_send_response("ok");
                    640: }
                    641:
                    642: void
                    643: cvs_server_release(char *data)
                    644: {
                    645:        if (chdir(server_currentdir) == -1)
1.67      xsa       646:                fatal("cvs_server_release: %s", strerror(errno));
1.64      xsa       647:
                    648:        cvs_cmdop = CVS_OP_RELEASE;
1.78      tobias    649:        cmdp->cmd_flags = cvs_cmd_release.cmd_flags;
1.64      xsa       650:        cvs_release(server_argc, server_argv);
1.31      xsa       651:        cvs_server_send_response("ok");
                    652: }
                    653:
                    654: void
                    655: cvs_server_remove(char *data)
                    656: {
                    657:        if (chdir(server_currentdir) == -1)
                    658:                fatal("cvs_server_remove: %s", strerror(errno));
                    659:
                    660:        cvs_cmdop = CVS_OP_REMOVE;
1.78      tobias    661:        cmdp->cmd_flags = cvs_cmd_remove.cmd_flags;
1.31      xsa       662:        cvs_remove(server_argc, server_argv);
1.29      joris     663:        cvs_server_send_response("ok");
                    664: }
                    665:
                    666: void
                    667: cvs_server_status(char *data)
                    668: {
                    669:        if (chdir(server_currentdir) == -1)
                    670:                fatal("cvs_server_status: %s", strerror(errno));
                    671:
                    672:        cvs_cmdop = CVS_OP_STATUS;
1.78      tobias    673:        cmdp->cmd_flags = cvs_cmd_status.cmd_flags;
1.29      joris     674:        cvs_status(server_argc, server_argv);
                    675:        cvs_server_send_response("ok");
                    676: }
                    677:
                    678: void
                    679: cvs_server_log(char *data)
                    680: {
                    681:        if (chdir(server_currentdir) == -1)
                    682:                fatal("cvs_server_log: %s", strerror(errno));
                    683:
                    684:        cvs_cmdop = CVS_OP_LOG;
1.78      tobias    685:        cmdp->cmd_flags = cvs_cmd_log.cmd_flags;
1.62      niallo    686:        cvs_getlog(server_argc, server_argv);
                    687:        cvs_server_send_response("ok");
                    688: }
1.79      xsa       689:
1.62      niallo    690: void
                    691: cvs_server_rlog(char *data)
                    692: {
1.74      tobias    693:        if (chdir(current_cvsroot->cr_dir) == -1)
1.67      xsa       694:                fatal("cvs_server_rlog: %s", strerror(errno));
1.62      niallo    695:
                    696:        cvs_cmdop = CVS_OP_RLOG;
1.78      tobias    697:        cmdp->cmd_flags = cvs_cmd_rlog.cmd_flags;
1.32      xsa       698:        cvs_getlog(server_argc, server_argv);
                    699:        cvs_server_send_response("ok");
                    700: }
                    701:
                    702: void
                    703: cvs_server_tag(char *data)
                    704: {
                    705:        if (chdir(server_currentdir) == -1)
                    706:                fatal("cvs_server_tag: %s", strerror(errno));
                    707:
                    708:        cvs_cmdop = CVS_OP_TAG;
1.78      tobias    709:        cmdp->cmd_flags = cvs_cmd_tag.cmd_flags;
1.75      tobias    710:        cvs_tag(server_argc, server_argv);
                    711:        cvs_server_send_response("ok");
                    712: }
                    713:
                    714: void
                    715: cvs_server_rtag(char *data)
                    716: {
                    717:        if (chdir(current_cvsroot->cr_dir) == -1)
1.77      tobias    718:                fatal("cvs_server_rtag: %s", strerror(errno));
1.75      tobias    719:
                    720:        cvs_cmdop = CVS_OP_RTAG;
1.78      tobias    721:        cmdp->cmd_flags = cvs_cmd_rtag.cmd_flags;
1.33      xsa       722:        cvs_tag(server_argc, server_argv);
1.29      joris     723:        cvs_server_send_response("ok");
                    724: }
                    725:
                    726: void
                    727: cvs_server_update(char *data)
                    728: {
                    729:        if (chdir(server_currentdir) == -1)
                    730:                fatal("cvs_server_update: %s", strerror(errno));
1.14      joris     731:
1.29      joris     732:        cvs_cmdop = CVS_OP_UPDATE;
1.78      tobias    733:        cmdp->cmd_flags = cvs_cmd_update.cmd_flags;
1.29      joris     734:        cvs_update(server_argc, server_argv);
1.36      xsa       735:        cvs_server_send_response("ok");
                    736: }
                    737:
                    738: void
                    739: cvs_server_version(char *data)
                    740: {
                    741:        cvs_cmdop = CVS_OP_VERSION;
1.78      tobias    742:        cmdp->cmd_flags = cvs_cmd_version.cmd_flags;
1.36      xsa       743:        cvs_version(server_argc, server_argv);
1.29      joris     744:        cvs_server_send_response("ok");
1.47      joris     745: }
                    746:
                    747: void
                    748: cvs_server_update_entry(const char *resp, struct cvs_file *cf)
                    749: {
1.58      ray       750:        char *p;
1.65      joris     751:        char repo[MAXPATHLEN], fpath[MAXPATHLEN];
1.47      joris     752:
                    753:        if ((p = strrchr(cf->file_rpath, ',')) != NULL)
                    754:                *p = '\0';
                    755:
1.65      joris     756:        cvs_get_repository_path(cf->file_wd, repo, MAXPATHLEN);
                    757:        (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", repo, cf->file_name);
                    758:
1.58      ray       759:        cvs_server_send_response("%s %s/", resp, cf->file_wd);
1.65      joris     760:        cvs_remote_output(fpath);
1.47      joris     761:
                    762:        if (p != NULL)
                    763:                *p = ',';
1.65      joris     764: }
                    765:
                    766: void
                    767: cvs_server_set_sticky(char *dir, char *tag)
                    768: {
1.72      joris     769:        char fpath[MAXPATHLEN];
1.65      joris     770:
1.81      joris     771:        if (module_repo_root != NULL) {
                    772:                (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s/%s",
                    773:                    current_cvsroot->cr_dir, module_repo_root, dir);
                    774:        } else {
                    775:                (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s",
                    776:                    current_cvsroot->cr_dir, dir);
                    777:        }
1.65      joris     778:
                    779:        cvs_server_send_response("Set-sticky %s", dir);
                    780:        cvs_remote_output(fpath);
1.72      joris     781:        cvs_remote_output(tag);
1.65      joris     782: }
                    783:
                    784: void
                    785: cvs_server_clear_sticky(char *dir)
                    786: {
                    787:        char fpath[MAXPATHLEN];
                    788:
1.81      joris     789:        if (module_repo_root != NULL) {
                    790:                (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s/%s",
                    791:                    current_cvsroot->cr_dir, module_repo_root, dir);
                    792:        } else {
                    793:                (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s",
                    794:                    current_cvsroot->cr_dir, dir);
                    795:        }
1.65      joris     796:
                    797:        cvs_server_send_response("Clear-sticky %s", dir);
                    798:        cvs_remote_output(fpath);
1.1       jfb       799: }