Annotation of src/usr.bin/cvs/server.c, Revision 1.10
1.10 ! xsa 1: /* $OpenBSD: server.c,v 1.9 2005/04/01 09:52:39 joris 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"
1.5 jfb 39: #include "proto.h"
1.1 jfb 40:
41:
42: /* argument vector built by the `Argument' and `Argumentx' requests */
43: char **cvs_args;
1.6 tedu 44: u_int cvs_nbarg = 0;
1.1 jfb 45: u_int cvs_utf8ok = 0;
46: u_int cvs_case = 0;
1.8 joris 47:
48: struct cvs_cmd_info cmd_server = {
49: NULL, NULL, NULL, NULL, NULL, 0, 0, 0 };
1.1 jfb 50:
51: /*
52: * cvs_server()
53: *
54: * Implement the `cvs server' command. As opposed to the general method of
55: * CVS client/server implementation, the cvs program merely acts as a
56: * redirector to the cvs daemon for most of the tasks.
57: *
58: * The `cvs server' command is only used on the server side of a remote
59: * cvs command. With this command, the cvs program starts listening on
60: * standard input for CVS protocol requests.
61: */
62: int
63: cvs_server(int argc, char **argv)
64: {
1.5 jfb 65: size_t len;
1.9 joris 66: char reqbuf[512];
1.1 jfb 67:
68: if (argc != 1) {
69: return (EX_USAGE);
70: }
71:
1.5 jfb 72: /* make sure standard in and standard out are line-buffered */
73: (void)setvbuf(stdin, NULL, _IOLBF, 0);
74: (void)setvbuf(stdout, NULL, _IOLBF, 0);
75:
1.1 jfb 76: for (;;) {
1.5 jfb 77: if (fgets(reqbuf, sizeof(reqbuf), stdin) == NULL) {
78: if (feof(stdin))
79: break;
80: else if (ferror(stdin))
1.10 ! xsa 81: return (-1);
1.1 jfb 82: }
83:
1.5 jfb 84: len = strlen(reqbuf);
85: if (len == 0)
86: continue;
87: else if (reqbuf[len - 1] != '\n') {
88: cvs_log(LP_ERR, "truncated request");
1.10 ! xsa 89: return (-1);
1.5 jfb 90: }
91: reqbuf[--len] = '\0';
1.1 jfb 92:
1.5 jfb 93: cvs_req_handle(reqbuf);
1.1 jfb 94:
95:
96: }
97:
98: return (0);
99: }