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

1.6     ! tedu        1: /*     $OpenBSD: server.c,v 1.5 2004/08/02 17:35:37 jfb Exp $  */
1.1       jfb         2: /*
                      3:  * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
1.6     ! tedu        4:  * All rights reserved.
1.1       jfb         5:  *
1.6     ! tedu        6:  * Redistribution and use in source and binary forms, with or without
        !             7:  * modification, are permitted provided that the following conditions
        !             8:  * are met:
1.1       jfb         9:  *
1.6     ! tedu       10:  * 1. Redistributions of source code must retain the above copyright
        !            11:  *    notice, this list of conditions and the following disclaimer.
1.1       jfb        12:  * 2. The name of the author may not be used to endorse or promote products
1.6     ! tedu       13:  *    derived from this software without specific prior written permission.
1.1       jfb        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
1.6     ! tedu       24:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.1       jfb        25:  */
                     26:
                     27: #include <sys/types.h>
                     28:
                     29: #include <stdlib.h>
                     30: #include <stdio.h>
                     31: #include <unistd.h>
                     32: #include <errno.h>
                     33: #include <string.h>
                     34: #include <paths.h>
                     35: #include <sysexits.h>
                     36:
                     37: #include "cvs.h"
                     38: #include "log.h"
                     39: #include "sock.h"
1.5       jfb        40: #include "proto.h"
1.1       jfb        41:
                     42:
                     43: /* argument vector built by the `Argument' and `Argumentx' requests */
                     44: char   **cvs_args;
1.6     ! tedu       45: u_int   cvs_nbarg = 0;
1.1       jfb        46: u_int   cvs_utf8ok = 0;
                     47: u_int   cvs_case   = 0;
                     48:
                     49: /*
                     50:  * cvs_server()
                     51:  *
                     52:  * Implement the `cvs server' command.  As opposed to the general method of
                     53:  * CVS client/server implementation, the cvs program merely acts as a
                     54:  * redirector to the cvs daemon for most of the tasks.
                     55:  *
                     56:  * The `cvs server' command is only used on the server side of a remote
                     57:  * cvs command.  With this command, the cvs program starts listening on
                     58:  * standard input for CVS protocol requests.
                     59:  */
                     60: int
                     61: cvs_server(int argc, char **argv)
                     62: {
1.5       jfb        63:        size_t len;
1.1       jfb        64:        char reqbuf[128];
                     65:
                     66:        if (argc != 1) {
                     67:                return (EX_USAGE);
                     68:        }
                     69:
1.5       jfb        70:        /* make sure standard in and standard out are line-buffered */
                     71:        (void)setvbuf(stdin, NULL, _IOLBF, 0);
                     72:        (void)setvbuf(stdout, NULL, _IOLBF, 0);
                     73:
                     74:        if (cvs_sock_connect(CVSD_SOCK_PATH) < 0) {
                     75:                cvs_log(LP_ERR, "failed to connect to CVS server socket");
                     76:                return (-1);
                     77:        }
                     78:
                     79:
1.1       jfb        80:        for (;;) {
1.5       jfb        81:                if (fgets(reqbuf, sizeof(reqbuf), stdin) == NULL) {
                     82:                        if (feof(stdin))
                     83:                                break;
                     84:                        else if (ferror(stdin))
                     85:                                return (EX_DATAERR);
1.1       jfb        86:                }
                     87:
1.5       jfb        88:                len = strlen(reqbuf);
                     89:                if (len == 0)
                     90:                        continue;
                     91:                else if (reqbuf[len - 1] != '\n') {
                     92:                        cvs_log(LP_ERR, "truncated request");
                     93:                        return (EX_DATAERR);
                     94:                }
                     95:                reqbuf[--len] = '\0';
1.1       jfb        96:
1.5       jfb        97:                cvs_req_handle(reqbuf);
1.1       jfb        98:
                     99:
                    100:        }
                    101:
                    102:        cvs_sock_disconnect();
                    103:
                    104:        return (0);
                    105: }