xref: /openbsd/usr.bin/cvs/cvs.h (revision 2f43a3f5)
1 /*	$OpenBSD: cvs.h,v 1.185 2021/01/27 07:18:17 deraadt Exp $	*/
2 /*
3  * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. The name of the author may not be used to endorse or promote products
13  *    derived from this software without specific prior written permission.
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
24  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef CVS_H
28 #define CVS_H
29 
30 #include <signal.h>
31 
32 #include "config.h"
33 #include "file.h"
34 #include "log.h"
35 #include "worklist.h"
36 #include "repository.h"
37 #include "trigger.h"
38 #include "util.h"
39 #include "xmalloc.h"
40 
41 #define CVS_VERSION	"OpenCVS 4.5"
42 
43 #define CVS_REV_BUFSZ	32
44 #define CVS_TIME_BUFSZ	64
45 
46 #define CVS_DATE_FMT	"%Y.%m.%d.%H.%M.%S"
47 
48 /* operations */
49 #define CVS_OP_UNKNOWN		0
50 #define CVS_OP_ADD		1
51 #define CVS_OP_ADMIN		2
52 #define CVS_OP_ANNOTATE		3
53 #define CVS_OP_CHECKOUT		4
54 #define CVS_OP_COMMIT		5
55 #define CVS_OP_DIFF		6
56 #define CVS_OP_EDIT		7
57 #define CVS_OP_EDITORS		8
58 #define CVS_OP_EXPORT		9
59 #define CVS_OP_HISTORY		10
60 #define CVS_OP_IMPORT		11
61 #define CVS_OP_INIT		12
62 #define CVS_OP_LOG		13
63 #define CVS_OP_RANNOTATE	14
64 #define CVS_OP_RDIFF		15
65 #define CVS_OP_RELEASE		16
66 #define CVS_OP_REMOVE		17
67 #define CVS_OP_RLOG		18
68 #define CVS_OP_RTAG		19
69 #define CVS_OP_SERVER		20
70 #define CVS_OP_STATUS		21
71 #define CVS_OP_TAG		22
72 #define CVS_OP_UNEDIT		23
73 #define CVS_OP_UPDATE		24
74 #define CVS_OP_VERSION		25
75 #define CVS_OP_WATCH		26
76 #define CVS_OP_WATCHERS		27
77 
78 /* methods */
79 #define CVS_METHOD_NONE		0
80 #define CVS_METHOD_LOCAL	1	/* local access */
81 #define CVS_METHOD_SERVER	2	/* tunnel through CVS_RSH */
82 #define CVS_METHOD_PSERVER	3	/* cvs pserver */
83 #define CVS_METHOD_KSERVER	4	/* kerberos */
84 #define CVS_METHOD_GSERVER	5	/* gssapi server */
85 #define CVS_METHOD_EXT		6
86 #define CVS_METHOD_FORK		7	/* local but fork */
87 
88 #define CVS_CMD_MAXNAMELEN	16
89 #define CVS_CMD_MAXALIAS	2
90 #define CVS_CMD_MAXDESCRLEN	64
91 
92 /* flags */
93 #define CVS_USE_WDIR		0x01
94 #define CVS_LOCK_REPO		0x02
95 
96 /* defaults */
97 #define CVS_SERVER_DEFAULT	"cvs"
98 #define CVS_RSH_DEFAULT		"ssh"
99 #define CVS_EDITOR_DEFAULT	"vi"
100 #define CVS_TMPDIR_DEFAULT	"/tmp"
101 #define CVS_UMASK_DEFAULT	002
102 
103 /* extensions */
104 #define CVS_DESCR_FILE_EXT	",t"
105 
106 /* server-side paths */
107 #define CVS_PATH_DEVNULL	"/dev/null"
108 #define CVS_PATH_ROOT		"CVSROOT"
109 #define CVS_PATH_EMPTYDIR	CVS_PATH_ROOT "/Emptydir"
110 #define CVS_PATH_CHECKOUTLIST	CVS_PATH_ROOT "/checkoutlist"
111 #define CVS_PATH_COMMITINFO	CVS_PATH_ROOT "/commitinfo"
112 #define CVS_PATH_CONFIG		CVS_PATH_ROOT "/config"
113 #define CVS_PATH_CVSIGNORE	CVS_PATH_ROOT "/cvsignore"
114 #define CVS_PATH_CVSWRAPPERS	CVS_PATH_ROOT "/cvswrappers"
115 #define CVS_PATH_EDITINFO	CVS_PATH_ROOT "/editinfo"
116 #define CVS_PATH_HISTORY	CVS_PATH_ROOT "/history"
117 #define CVS_PATH_LOGINFO	CVS_PATH_ROOT "/loginfo"
118 #define CVS_PATH_MODULES	CVS_PATH_ROOT "/modules"
119 #define CVS_PATH_NOTIFY_R	CVS_PATH_ROOT "/notify"
120 #define CVS_PATH_RCSINFO	CVS_PATH_ROOT "/rcsinfo"
121 #define CVS_PATH_TAGINFO	CVS_PATH_ROOT "/taginfo"
122 #define CVS_PATH_VALTAGS	CVS_PATH_ROOT "/val-tags"
123 #define CVS_PATH_VERIFYMSG	CVS_PATH_ROOT "/verifymsg"
124 
125 /* client-side paths */
126 #define CVS_PATH_RC		".cvsrc"
127 #define CVS_PATH_CVSDIR		"CVS"
128 #define CVS_PATH_BASEDIR	CVS_PATH_CVSDIR "/Base"
129 #define CVS_PATH_BASEREV	CVS_PATH_CVSDIR "/Baserev"
130 #define CVS_PATH_BASEREVTMP	CVS_PATH_CVSDIR "/Baserev.tmp"
131 #define CVS_PATH_CHECKINPROG	CVS_PATH_CVSDIR "/Checkin.prog"
132 #define CVS_PATH_ENTRIES	CVS_PATH_CVSDIR "/Entries"
133 #define CVS_PATH_STATICENTRIES	CVS_PATH_CVSDIR "/Entries.Static"
134 #define CVS_PATH_LOGENTRIES	CVS_PATH_CVSDIR "/Entries.Log"
135 #define CVS_PATH_BACKUPENTRIES	CVS_PATH_CVSDIR "/Entries.Backup"
136 #define CVS_PATH_NOTIFY		CVS_PATH_CVSDIR "/Notify"
137 #define CVS_PATH_NOTIFYTMP	CVS_PATH_CVSDIR "/Notify.tmp"
138 #define CVS_PATH_ROOTSPEC	CVS_PATH_CVSDIR "/Root"
139 #define CVS_PATH_REPOSITORY	CVS_PATH_CVSDIR "/Repository"
140 #define CVS_PATH_TAG		CVS_PATH_CVSDIR "/Tag"
141 #define CVS_PATH_TEMPLATE	CVS_PATH_CVSDIR "/Template"
142 #define CVS_PATH_UPDATEPROG	CVS_PATH_CVSDIR "/Update.prog"
143 #define CVS_PATH_ATTIC		"Attic"
144 
145 /* history stuff */
146 #define CVS_HISTORY_TAG			0
147 #define CVS_HISTORY_CHECKOUT		1
148 #define CVS_HISTORY_EXPORT		2
149 #define CVS_HISTORY_RELEASE		3
150 #define CVS_HISTORY_UPDATE_REMOVE	4
151 #define CVS_HISTORY_UPDATE_CO		5
152 #define CVS_HISTORY_UPDATE_MERGED	6
153 #define CVS_HISTORY_UPDATE_MERGED_ERR	7
154 #define CVS_HISTORY_COMMIT_MODIFIED	8
155 #define CVS_HISTORY_COMMIT_ADDED	9
156 #define CVS_HISTORY_COMMIT_REMOVED	10
157 
158 void	cvs_history_add(int, struct cvs_file *, const char *);
159 
160 struct cvs_cmd {
161 	u_int	 cmd_op;
162 	u_int	 cmd_flags;
163 	char	 cmd_name[CVS_CMD_MAXNAMELEN];
164 	char	 cmd_alias[CVS_CMD_MAXALIAS][CVS_CMD_MAXNAMELEN];
165 	char	 cmd_descr[CVS_CMD_MAXDESCRLEN];
166 	char	*cmd_synopsis;
167 	char	*cmd_opts;
168 	char	*cmd_defargs;
169 
170 	int	(*cmd)(int, char **);
171 };
172 
173 struct cvsroot;
174 
175 struct cvs_recursion {
176 	void	(*enterdir)(struct cvs_file *);
177 	void	(*leavedir)(struct cvs_file *);
178 	void	(*fileproc)(struct cvs_file *);
179 	int	flags;
180 };
181 
182 #define CR_RECURSE_DIRS		0x01
183 #define CR_ATTIC		0x02
184 #define CR_REPO			0x04
185 
186 struct cvs_var {
187 	char   *cv_name;
188 	char   *cv_val;
189 	TAILQ_ENTRY(cvs_var) cv_link;
190 };
191 
192 extern TAILQ_HEAD(cvs_varhead, cvs_var) cvs_variables;
193 
194 #define CVS_ROOT_CONNECTED	0x01
195 
196 struct cvsroot {
197 	char   *cr_str;
198 	u_int   cr_method;
199 	char   *cr_buf;
200 	char   *cr_user;
201 	char   *cr_pass;
202 	char   *cr_host;
203 	char   *cr_dir;
204 	u_int   cr_port;
205 
206 	/* connection data */
207 	FILE   *cr_srvin;
208 	FILE   *cr_srvout;
209 	FILE   *cr_srverr;
210 };
211 
212 #define CVS_HIST_ADDED		'A'
213 #define CVS_HIST_EXPORT		'E'
214 #define CVS_HIST_RELEASE	'F'
215 #define CVS_HIST_MODIFIED	'M'
216 #define CVS_HIST_CHECKOUT	'O'
217 #define CVS_HIST_COMMIT		'R'
218 #define CVS_HIST_TAG		'T'
219 
220 #define CVS_DATE_DUMMY	"dummy timestamp"
221 #define CVS_DATE_DMSEC	(time_t)-1
222 
223 #define CVS_ENT_NONE	0
224 #define CVS_ENT_FILE	1
225 #define CVS_ENT_DIR	2
226 
227 #define CVS_ENT_REG		0
228 #define CVS_ENT_ADDED		1
229 #define CVS_ENT_REMOVED		2
230 #define CVS_ENT_UPTODATE	3
231 #define CVS_ENT_UNKNOWN		4
232 
233 #define CVS_ENT_MAXLINELEN	1024
234 
235 #define ENT_NOSYNC	0
236 #define ENT_SYNC	1
237 
238 #define STRIP_SLASH(p)					\
239 	do {						\
240 		size_t _slen;				\
241 		_slen = strlen(p);			\
242 		while ((_slen > 0) && (p[_slen - 1] == '/'))	\
243 			p[--_slen] = '\0';		\
244 	} while (0)
245 
246 struct cvs_ent {
247 	char		*ce_buf;
248 	char		*ce_conflict;
249 	char		*ce_name;
250 	char		*ce_opts;
251 	char		*ce_tag;
252 	char		*ce_time;
253 	time_t		 ce_date;
254 	time_t		 ce_mtime;
255 	u_int16_t	 ce_type;
256 	u_int16_t	 ce_status;
257 	RCSNUM		*ce_rev;
258 };
259 
260 struct cvs_ent_line {
261 	char	*buf;
262 	TAILQ_ENTRY(cvs_ent_line) entries_list;
263 };
264 
265 typedef struct cvs_entries {
266 	char	*cef_path;
267 	char	*cef_bpath;
268 	char	*cef_lpath;
269 
270 	TAILQ_HEAD(, cvs_ent_line)	 cef_ent;
271 } CVSENTRIES;
272 
273 extern char *checkout_target_dir;
274 extern char *cvs_join_rev1;
275 extern char *cvs_join_rev2;
276 extern int   backup_local_changes;
277 
278 extern struct module_checkout *current_module;
279 extern char *module_repo_root;
280 
281 extern struct ignore_head checkout_ign_pats;
282 extern struct wklhead temp_files;
283 extern volatile sig_atomic_t sig_received;
284 extern volatile sig_atomic_t cvs_quit;
285 extern struct cvsroot *current_cvsroot;
286 extern char *cvs_tagname;
287 extern char *cvs_editor;
288 extern char *cvs_homedir;
289 extern char *cvs_rsh;
290 extern char *cvs_tmpdir;
291 extern char *import_repository;
292 extern char *cvs_server_path;
293 extern time_t cvs_specified_date;
294 extern time_t cvs_directory_date;
295 extern char *cvs_specified_tag;
296 extern char *cvs_directory_tag;
297 
298 extern int  cvs_umask;
299 extern int  verbosity;
300 extern int  cvs_trace;
301 extern int  cvs_nolog;
302 extern int  cvs_compress;
303 extern int  cvs_cmdop;
304 extern int  cvs_nocase;
305 extern int  cvs_noexec;
306 extern int  cvs_readonly;
307 extern int  cvs_readonlyfs;
308 extern int  cvs_server_active;
309 extern int  reset_option;
310 extern int  reset_tag;
311 extern int  kflag;
312 
313 extern struct cvs_cmd *cmdp;
314 extern struct cvs_cmd *cvs_cdt[];
315 
316 extern struct cvs_cmd cvs_cmd_add;
317 extern struct cvs_cmd cvs_cmd_admin;
318 extern struct cvs_cmd cvs_cmd_annotate;
319 extern struct cvs_cmd cvs_cmd_checkout;
320 extern struct cvs_cmd cvs_cmd_commit;
321 extern struct cvs_cmd cvs_cmd_diff;
322 extern struct cvs_cmd cvs_cmd_edit;
323 extern struct cvs_cmd cvs_cmd_editors;
324 extern struct cvs_cmd cvs_cmd_export;
325 extern struct cvs_cmd cvs_cmd_history;
326 extern struct cvs_cmd cvs_cmd_import;
327 extern struct cvs_cmd cvs_cmd_init;
328 extern struct cvs_cmd cvs_cmd_log;
329 extern struct cvs_cmd cvs_cmd_rannotate;
330 extern struct cvs_cmd cvs_cmd_rdiff;
331 extern struct cvs_cmd cvs_cmd_release;
332 extern struct cvs_cmd cvs_cmd_remove;
333 extern struct cvs_cmd cvs_cmd_rlog;
334 extern struct cvs_cmd cvs_cmd_rtag;
335 extern struct cvs_cmd cvs_cmd_status;
336 extern struct cvs_cmd cvs_cmd_tag;
337 extern struct cvs_cmd cvs_cmd_update;
338 extern struct cvs_cmd cvs_cmd_version;
339 extern struct cvs_cmd cvs_cmd_server;
340 extern struct cvs_cmd cvs_cmd_unedit;
341 extern struct cvs_cmd cvs_cmd_watch;
342 extern struct cvs_cmd cvs_cmd_watchers;
343 
344 /* add.c */
345 void		 cvs_add_tobranch(struct cvs_file *, char *);
346 
347 /* cmd.c */
348 struct cvs_cmd	*cvs_findcmd(const char *);
349 
350 /* cvs.c */
351 int		 cvs_build_cmd(char ***, char **, int);
352 int		 cvs_var_set(const char *, const char *);
353 int		 cvs_var_unset(const char *);
354 const char	*cvs_var_get(const char *);
355 void		 cvs_cleanup(void);
356 
357 /* date.y */
358 time_t		 date_parse(const char *);
359 
360 /* entries.c */
361 struct cvs_ent	*cvs_ent_parse(const char *);
362 struct cvs_ent	*cvs_ent_get(CVSENTRIES *, const char *);
363 CVSENTRIES	*cvs_ent_open(const char *);
364 void		cvs_ent_add(CVSENTRIES *, const char *);
365 void		cvs_ent_remove(CVSENTRIES *, const char *);
366 void		cvs_ent_close(CVSENTRIES *, int);
367 void		cvs_ent_free(struct cvs_ent *);
368 void		cvs_ent_line_str(const char *, char *, char *, char *, char *,
369 		    int, int, char *, size_t);
370 void		cvs_parse_tagfile(char *, char **, char **, int *);
371 void		cvs_write_tagfile(const char *, char *, char *);
372 
373 /* root.c */
374 struct cvsroot	*cvsroot_get(const char *);
375 int		cvsroot_is_local(void);
376 int		cvsroot_is_remote(void);
377 
378 /* logmsg.c */
379 char	*cvs_logmsg_read(const char *);
380 char	*cvs_logmsg_create(char *, struct cvs_flisthead *,
381 	     struct cvs_flisthead *, struct cvs_flisthead *);
382 int	 cvs_logmsg_verify(char *);
383 
384 /* misc stuff */
385 void	cvs_update_local(struct cvs_file *);
386 void	cvs_update_enterdir(struct cvs_file *);
387 void	cvs_update_leavedir(struct cvs_file *);
388 void	cvs_checkout_file(struct cvs_file *, RCSNUM *, char *, int);
389 void	cvs_remove_local(struct cvs_file *);
390 void	cvs_add_local(struct cvs_file *);
391 int	update_has_conflict_markers(struct cvs_file *);
392 void	cvs_backup_file(struct cvs_file *);
393 void	cvs_import_ignored(const char *);
394 
395 #define CO_MERGE	0x01
396 #define CO_SETSTICKY	0x02
397 #define CO_DUMP		0x04
398 #define CO_COMMIT	0x08
399 #define CO_REMOVE	0x10
400 
401 /* commands */
402 int	cvs_add(int, char **);
403 int	cvs_admin(int, char **);
404 int	cvs_annotate(int, char **);
405 int	cvs_checkout(int, char **);
406 int	cvs_commit(int, char **);
407 int	cvs_diff(int, char **);
408 int	cvs_edit(int, char **);
409 int	cvs_editors(int, char **);
410 int	cvs_export(int, char **);
411 int	cvs_getlog(int, char **);
412 int	cvs_history(int, char **);
413 int	cvs_import(int, char **);
414 int	cvs_init(int, char **);
415 int	cvs_release(int, char **);
416 int	cvs_remove(int, char **);
417 int	cvs_status(int, char **);
418 int	cvs_tag(int, char **);
419 int	cvs_unedit(int, char **);
420 int	cvs_update(int, char **);
421 int	cvs_version(int, char **);
422 int	cvs_watch(int, char **);
423 int	cvs_watchers(int, char **);
424 
425 
426 #endif
427