1*86d7f5d3SJohn Marino /* 2*86d7f5d3SJohn Marino * Copyright (C) 1986-2005 The Free Software Foundation, Inc. 3*86d7f5d3SJohn Marino * 4*86d7f5d3SJohn Marino * Portions Copyright (C) 1998-2005 Derek Price, Ximbiot <http://ximbiot.com>, 5*86d7f5d3SJohn Marino * and others. 6*86d7f5d3SJohn Marino * 7*86d7f5d3SJohn Marino * You may distribute under the terms of the GNU General Public License as 8*86d7f5d3SJohn Marino * specified in the README file that comes with the CVS kit. 9*86d7f5d3SJohn Marino * 10*86d7f5d3SJohn Marino * 11*86d7f5d3SJohn Marino * 12*86d7f5d3SJohn Marino * This file contains the interface between the server and the rest of CVS. 13*86d7f5d3SJohn Marino */ 14*86d7f5d3SJohn Marino 15*86d7f5d3SJohn Marino /* Miscellaneous stuff which isn't actually particularly server-specific. */ 16*86d7f5d3SJohn Marino #ifndef STDIN_FILENO 17*86d7f5d3SJohn Marino #define STDIN_FILENO 0 18*86d7f5d3SJohn Marino #define STDOUT_FILENO 1 19*86d7f5d3SJohn Marino #define STDERR_FILENO 2 20*86d7f5d3SJohn Marino #endif 21*86d7f5d3SJohn Marino 22*86d7f5d3SJohn Marino 23*86d7f5d3SJohn Marino /* 24*86d7f5d3SJohn Marino * Nonzero if we are using the server. Used by various places to call 25*86d7f5d3SJohn Marino * server-specific functions. 26*86d7f5d3SJohn Marino */ 27*86d7f5d3SJohn Marino extern int server_active; 28*86d7f5d3SJohn Marino 29*86d7f5d3SJohn Marino /* 30*86d7f5d3SJohn Marino * Expand to `S', ` ', or the empty string. Used in `%s-> ...' trace printfs. 31*86d7f5d3SJohn Marino */ 32*86d7f5d3SJohn Marino #ifdef SERVER_SUPPORT 33*86d7f5d3SJohn Marino # define CLIENT_SERVER_STR ((server_active) ? "S" : " ") 34*86d7f5d3SJohn Marino #else 35*86d7f5d3SJohn Marino # define CLIENT_SERVER_STR "" 36*86d7f5d3SJohn Marino #endif 37*86d7f5d3SJohn Marino 38*86d7f5d3SJohn Marino #ifdef SERVER_SUPPORT 39*86d7f5d3SJohn Marino 40*86d7f5d3SJohn Marino /* Server functions exported to the rest of CVS. */ 41*86d7f5d3SJohn Marino 42*86d7f5d3SJohn Marino /* pre-parse the server options. */ 43*86d7f5d3SJohn Marino void parseServerOptions (int argc, char **argv); 44*86d7f5d3SJohn Marino 45*86d7f5d3SJohn Marino /* Run the server. */ 46*86d7f5d3SJohn Marino int server (int argc, char **argv); 47*86d7f5d3SJohn Marino 48*86d7f5d3SJohn Marino /* kserver user authentication. */ 49*86d7f5d3SJohn Marino # ifdef HAVE_KERBEROS 50*86d7f5d3SJohn Marino void kserver_authenticate_connection (void); 51*86d7f5d3SJohn Marino # endif 52*86d7f5d3SJohn Marino 53*86d7f5d3SJohn Marino /* pserver user authentication. */ 54*86d7f5d3SJohn Marino # if defined (AUTH_SERVER_SUPPORT) || defined (HAVE_GSSAPI) 55*86d7f5d3SJohn Marino void pserver_authenticate_connection (void); 56*86d7f5d3SJohn Marino # endif 57*86d7f5d3SJohn Marino 58*86d7f5d3SJohn Marino /* See server.c for description. */ 59*86d7f5d3SJohn Marino void server_pathname_check (char *); 60*86d7f5d3SJohn Marino 61*86d7f5d3SJohn Marino /* We have a new Entries line for a file. TAG or DATE can be NULL. */ 62*86d7f5d3SJohn Marino void server_register (const char *name, const char *version, 63*86d7f5d3SJohn Marino const char *timestamp, const char *options, 64*86d7f5d3SJohn Marino const char *tag, const char *date, const char *conflict); 65*86d7f5d3SJohn Marino 66*86d7f5d3SJohn Marino /* Set the modification time of the next file sent. This must be 67*86d7f5d3SJohn Marino followed by a call to server_updated on the same file. */ 68*86d7f5d3SJohn Marino void server_modtime (struct file_info *finfo, Vers_TS *vers_ts); 69*86d7f5d3SJohn Marino 70*86d7f5d3SJohn Marino /* 71*86d7f5d3SJohn Marino * We want to nuke the Entries line for a file, and (unless 72*86d7f5d3SJohn Marino * server_scratch_entry_only is subsequently called) the file itself. 73*86d7f5d3SJohn Marino */ 74*86d7f5d3SJohn Marino void server_scratch (const char *name); 75*86d7f5d3SJohn Marino 76*86d7f5d3SJohn Marino /* 77*86d7f5d3SJohn Marino * The file which just had server_scratch called on it needs to have only 78*86d7f5d3SJohn Marino * the Entries line removed, not the file itself. 79*86d7f5d3SJohn Marino */ 80*86d7f5d3SJohn Marino void server_scratch_entry_only (void); 81*86d7f5d3SJohn Marino 82*86d7f5d3SJohn Marino /* 83*86d7f5d3SJohn Marino * We just successfully checked in FILE (which is just the bare 84*86d7f5d3SJohn Marino * filename, with no directory). REPOSITORY is the directory for the 85*86d7f5d3SJohn Marino * repository. 86*86d7f5d3SJohn Marino */ 87*86d7f5d3SJohn Marino void server_checked_in (const char *file, const char *update_dir, 88*86d7f5d3SJohn Marino const char *repository); 89*86d7f5d3SJohn Marino 90*86d7f5d3SJohn Marino void server_copy_file (const char *file, const char *update_dir, 91*86d7f5d3SJohn Marino const char *repository, const char *newfile); 92*86d7f5d3SJohn Marino 93*86d7f5d3SJohn Marino /* Send the appropriate responses for a file described by FINFO and 94*86d7f5d3SJohn Marino VERS. This is called after server_register or server_scratch. In 95*86d7f5d3SJohn Marino the latter case the file is to be removed (and VERS can be NULL). 96*86d7f5d3SJohn Marino In the former case, VERS must be non-NULL, and UPDATED indicates 97*86d7f5d3SJohn Marino whether the file is now up to date (SERVER_UPDATED, yes, 98*86d7f5d3SJohn Marino SERVER_MERGED, no, SERVER_PATCHED, yes, but file is a diff from 99*86d7f5d3SJohn Marino user version to repository version, SERVER_RCS_DIFF, yes, like 100*86d7f5d3SJohn Marino SERVER_PATCHED but with an RCS style diff). MODE is the mode the 101*86d7f5d3SJohn Marino file should get, or (mode_t) -1 if this should be obtained from the 102*86d7f5d3SJohn Marino file itself. CHECKSUM is the MD5 checksum of the file, or NULL if 103*86d7f5d3SJohn Marino this need not be sent. If FILEBUF is not NULL, it holds the 104*86d7f5d3SJohn Marino contents of the file, in which case the file itself may not exist. 105*86d7f5d3SJohn Marino If FILEBUF is not NULL, server_updated will free it. */ 106*86d7f5d3SJohn Marino enum server_updated_arg4 107*86d7f5d3SJohn Marino { 108*86d7f5d3SJohn Marino SERVER_UPDATED, 109*86d7f5d3SJohn Marino SERVER_MERGED, 110*86d7f5d3SJohn Marino SERVER_PATCHED, 111*86d7f5d3SJohn Marino SERVER_RCS_DIFF 112*86d7f5d3SJohn Marino }; 113*86d7f5d3SJohn Marino 114*86d7f5d3SJohn Marino struct buffer; 115*86d7f5d3SJohn Marino 116*86d7f5d3SJohn Marino void server_updated (struct file_info *finfo, Vers_TS *vers, 117*86d7f5d3SJohn Marino enum server_updated_arg4 updated, mode_t mode, 118*86d7f5d3SJohn Marino unsigned char *checksum, struct buffer *filebuf); 119*86d7f5d3SJohn Marino 120*86d7f5d3SJohn Marino /* Whether we should send RCS format patches. */ 121*86d7f5d3SJohn Marino int server_use_rcs_diff (void); 122*86d7f5d3SJohn Marino 123*86d7f5d3SJohn Marino /* Set the Entries.Static flag. */ 124*86d7f5d3SJohn Marino void server_set_entstat (const char *update_dir, const char *repository); 125*86d7f5d3SJohn Marino /* Clear it. */ 126*86d7f5d3SJohn Marino void server_clear_entstat (const char *update_dir, const char *repository); 127*86d7f5d3SJohn Marino 128*86d7f5d3SJohn Marino /* Set or clear a per-directory sticky tag or date. */ 129*86d7f5d3SJohn Marino void server_set_sticky (const char *update_dir, const char *repository, 130*86d7f5d3SJohn Marino const char *tag, const char *date, int nonbranch); 131*86d7f5d3SJohn Marino 132*86d7f5d3SJohn Marino /* Send Clear-template response. */ 133*86d7f5d3SJohn Marino void server_clear_template (const char *update_dir, const char *repository); 134*86d7f5d3SJohn Marino 135*86d7f5d3SJohn Marino /* Send Template response. */ 136*86d7f5d3SJohn Marino void server_template (const char *update_dir, const char *repository); 137*86d7f5d3SJohn Marino 138*86d7f5d3SJohn Marino void server_update_entries (const char *file, const char *update_dir, 139*86d7f5d3SJohn Marino const char *repository, 140*86d7f5d3SJohn Marino enum server_updated_arg4 updated); 141*86d7f5d3SJohn Marino 142*86d7f5d3SJohn Marino /* Pointer to a malloc'd string which is the directory which 143*86d7f5d3SJohn Marino the server should prepend to the pathnames which it sends 144*86d7f5d3SJohn Marino to the client. */ 145*86d7f5d3SJohn Marino extern char *server_dir; 146*86d7f5d3SJohn Marino 147*86d7f5d3SJohn Marino void server_cleanup (void); 148*86d7f5d3SJohn Marino 149*86d7f5d3SJohn Marino #ifdef SERVER_FLOWCONTROL 150*86d7f5d3SJohn Marino /* Pause if it's convenient to avoid memory blowout */ 151*86d7f5d3SJohn Marino void server_pause_check (void); 152*86d7f5d3SJohn Marino #endif /* SERVER_FLOWCONTROL */ 153*86d7f5d3SJohn Marino 154*86d7f5d3SJohn Marino #ifdef AUTH_SERVER_SUPPORT 155*86d7f5d3SJohn Marino extern char *CVS_Username; 156*86d7f5d3SJohn Marino #endif /* AUTH_SERVER_SUPPORT */ 157*86d7f5d3SJohn Marino 158*86d7f5d3SJohn Marino #endif /* SERVER_SUPPORT */ 159*86d7f5d3SJohn Marino 160*86d7f5d3SJohn Marino /* Stuff shared with the client. */ 161*86d7f5d3SJohn Marino struct request 162*86d7f5d3SJohn Marino { 163*86d7f5d3SJohn Marino /* Name of the request. */ 164*86d7f5d3SJohn Marino char *name; 165*86d7f5d3SJohn Marino 166*86d7f5d3SJohn Marino #ifdef SERVER_SUPPORT 167*86d7f5d3SJohn Marino /* 168*86d7f5d3SJohn Marino * Function to carry out the request. ARGS is the text of the command 169*86d7f5d3SJohn Marino * after name and, if present, a single space, have been stripped off. 170*86d7f5d3SJohn Marino */ 171*86d7f5d3SJohn Marino void (*func) (char *args); 172*86d7f5d3SJohn Marino #endif 173*86d7f5d3SJohn Marino 174*86d7f5d3SJohn Marino /* One or more of the RQ_* flags described below. */ 175*86d7f5d3SJohn Marino int flags; 176*86d7f5d3SJohn Marino 177*86d7f5d3SJohn Marino /* If set, failure to implement this request can imply a fatal 178*86d7f5d3SJohn Marino error. This should be set only for commands which were in the 179*86d7f5d3SJohn Marino original version of the protocol; it should not be set for new 180*86d7f5d3SJohn Marino commands. */ 181*86d7f5d3SJohn Marino #define RQ_ESSENTIAL 1 182*86d7f5d3SJohn Marino 183*86d7f5d3SJohn Marino /* Set by the client if the server we are talking to supports it. */ 184*86d7f5d3SJohn Marino #define RQ_SUPPORTED 2 185*86d7f5d3SJohn Marino 186*86d7f5d3SJohn Marino /* If set, and client and server both support the request, the 187*86d7f5d3SJohn Marino client should tell the server by making the request. */ 188*86d7f5d3SJohn Marino #define RQ_ENABLEME 4 189*86d7f5d3SJohn Marino 190*86d7f5d3SJohn Marino /* The server may accept this request before "Root". */ 191*86d7f5d3SJohn Marino #define RQ_ROOTLESS 8 192*86d7f5d3SJohn Marino }; 193*86d7f5d3SJohn Marino 194*86d7f5d3SJohn Marino /* Table of requests ending with an entry with a NULL name. */ 195*86d7f5d3SJohn Marino extern struct request requests[]; 196*86d7f5d3SJohn Marino 197*86d7f5d3SJohn Marino /* Gzip library, see zlib.c. */ 198*86d7f5d3SJohn Marino int gunzip_and_write (int, const char *, unsigned char *, size_t); 199*86d7f5d3SJohn Marino int read_and_gzip (int, const char *, unsigned char **, size_t *, size_t *, 200*86d7f5d3SJohn Marino int); 201*86d7f5d3SJohn Marino void server_edit_file (struct file_info *finfo); 202*86d7f5d3SJohn Marino 203*86d7f5d3SJohn Marino /* The TRACE macro */ 204*86d7f5d3SJohn Marino void cvs_trace (int level, const char *fmt, ...) 205*86d7f5d3SJohn Marino __attribute__ ((__format__ (__printf__, 2, 3))); 206*86d7f5d3SJohn Marino #define TRACE cvs_trace 207*86d7f5d3SJohn Marino /* Trace levels: 208*86d7f5d3SJohn Marino * 209*86d7f5d3SJohn Marino * TRACE_FUNCTION Trace function calls, often including function 210*86d7f5d3SJohn Marino * arguments. This is the trace level that, historically, 211*86d7f5d3SJohn Marino * applied to all trace calls. 212*86d7f5d3SJohn Marino * TRACE_FLOW Include the flow control functions, such as 213*86d7f5d3SJohn Marino * start_recursion, do_recursion, and walklist in the 214*86d7f5d3SJohn Marino * function traces. 215*86d7f5d3SJohn Marino * TRACE_DATA Trace important internal function data. 216*86d7f5d3SJohn Marino */ 217*86d7f5d3SJohn Marino #define TRACE_FUNCTION 1 218*86d7f5d3SJohn Marino #define TRACE_FLOW 2 219*86d7f5d3SJohn Marino #define TRACE_DATA 3 220*86d7f5d3SJohn Marino 221*86d7f5d3SJohn Marino extern cvsroot_t *referrer; 222