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