Annotation of src/usr.bin/cvs/cvs.h, Revision 1.12
1.1 jfb 1: /* $OpenBSD$ */
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 <sys/param.h>
1.8 jfb 31: #include <stdio.h>
1.9 jfb 32: #include <dirent.h>
33:
1.1 jfb 34: #include "rcs.h"
35:
36: #define CVS_VERSION "OpenCVS 0.1"
37:
38:
39: #define CVS_HIST_CACHE 128
40: #define CVS_HIST_NBFLD 6
41:
42:
43: #define CVS_REQ_TIMEOUT 300
44:
45:
46:
47: #define CVS_CKSUM_LEN 33 /* length of a CVS checksum string */
48:
49:
50: /* operations */
1.8 jfb 51: #define CVS_OP_ANY 0 /* all operations */
1.1 jfb 52: #define CVS_OP_ADD 1
53: #define CVS_OP_ANNOTATE 2
54: #define CVS_OP_COMMIT 3
55: #define CVS_OP_DIFF 4
56: #define CVS_OP_TAG 5
57: #define CVS_OP_UPDATE 6
58:
59:
60:
61:
62: /* methods */
63: #define CVS_METHOD_NONE 0
64: #define CVS_METHOD_LOCAL 1 /* local access */
65: #define CVS_METHOD_SERVER 2 /* tunnel through CVS_RSH */
66: #define CVS_METHOD_PSERVER 3 /* cvs pserver */
67: #define CVS_METHOD_KSERVER 4 /* kerberos */
68: #define CVS_METHOD_GSERVER 5 /* gssapi server */
69: #define CVS_METHOD_EXT 6
70: #define CVS_METHOD_FORK 7 /* local but fork */
71:
72: /* client/server protocol requests */
73: #define CVS_REQ_NONE 0
74: #define CVS_REQ_ROOT 1
75: #define CVS_REQ_VALIDREQ 2
76: #define CVS_REQ_VALIDRESP 3
77: #define CVS_REQ_DIRECTORY 4
78: #define CVS_REQ_MAXDOTDOT 5
79: #define CVS_REQ_STATICDIR 6
80: #define CVS_REQ_STICKY 7
81: #define CVS_REQ_ENTRY 8
82: #define CVS_REQ_ENTRYEXTRA 9
83: #define CVS_REQ_CHECKINTIME 10
84: #define CVS_REQ_MODIFIED 11
85: #define CVS_REQ_ISMODIFIED 12
86: #define CVS_REQ_UNCHANGED 13
87: #define CVS_REQ_USEUNCHANGED 14
88: #define CVS_REQ_NOTIFY 15
89: #define CVS_REQ_NOTIFYUSER 16
90: #define CVS_REQ_QUESTIONABLE 17
91: #define CVS_REQ_CASE 18
92: #define CVS_REQ_UTF8 19
93: #define CVS_REQ_ARGUMENT 20
94: #define CVS_REQ_ARGUMENTX 21
95: #define CVS_REQ_GLOBALOPT 22
96: #define CVS_REQ_GZIPSTREAM 23
97: #define CVS_REQ_KERBENCRYPT 24
98: #define CVS_REQ_GSSENCRYPT 25
99: #define CVS_REQ_PROTOENCRYPT 26
100: #define CVS_REQ_GSSAUTH 27
101: #define CVS_REQ_PROTOAUTH 28
102: #define CVS_REQ_READCVSRC2 29
103: #define CVS_REQ_READWRAP 30
104: #define CVS_REQ_ERRIFREADER 31
105: #define CVS_REQ_VALIDRCSOPT 32
106: #define CVS_REQ_READIGNORE 33
107: #define CVS_REQ_SET 34
108: #define CVS_REQ_XPANDMOD 35
109: #define CVS_REQ_CI 36
110: #define CVS_REQ_CHOWN 37
111: #define CVS_REQ_SETOWN 38
112: #define CVS_REQ_SETPERM 39
113: #define CVS_REQ_CHACL 40
114: #define CVS_REQ_LISTPERM 41
115: #define CVS_REQ_LISTACL 42
116: #define CVS_REQ_SETPASS 43
117: #define CVS_REQ_PASSWD 44
118: #define CVS_REQ_DIFF 45
119: #define CVS_REQ_STATUS 46
120: #define CVS_REQ_LS 47
121: #define CVS_REQ_TAG 48
122: #define CVS_REQ_IMPORT 49
123: #define CVS_REQ_ADMIN 50
124: #define CVS_REQ_HISTORY 51
125: #define CVS_REQ_WATCHERS 52
126: #define CVS_REQ_EDITORS 53
127: #define CVS_REQ_ANNOTATE 54
128: #define CVS_REQ_LOG 55
129: #define CVS_REQ_CO 56
130: #define CVS_REQ_EXPORT 57
131: #define CVS_REQ_RANNOTATE 58
132: #define CVS_REQ_INIT 59
133: #define CVS_REQ_UPDATE 60
134: #define CVS_REQ_ADD 62
135: #define CVS_REQ_REMOVE 63
136: #define CVS_REQ_NOOP 64
137: #define CVS_REQ_RTAG 65
138: #define CVS_REQ_RELEASE 66
139: #define CVS_REQ_RLOG 67
140: #define CVS_REQ_RDIFF 68
141: #define CVS_REQ_VERSION 69
142:
143: #define CVS_REQ_MAX 69
144:
145:
146: /* responses */
147: #define CVS_RESP_OK 1
148: #define CVS_RESP_ERROR 2
149: #define CVS_RESP_VALIDREQ 3
150: #define CVS_RESP_CHECKEDIN 4
151: #define CVS_RESP_NEWENTRY 5
152: #define CVS_RESP_CKSUM 6
153: #define CVS_RESP_COPYFILE 7
154: #define CVS_RESP_UPDATED 8
155: #define CVS_RESP_CREATED 9
156: #define CVS_RESP_UPDEXIST 10
157: #define CVS_RESP_MERGED 11
158: #define CVS_RESP_PATCHED 12
159: #define CVS_RESP_RCSDIFF 13
160: #define CVS_RESP_MODE 14
161: #define CVS_RESP_MODTIME 15
162: #define CVS_RESP_REMOVED 16
163: #define CVS_RESP_RMENTRY 17
164: #define CVS_RESP_SETSTATDIR 18
165: #define CVS_RESP_CLRSTATDIR 19
166: #define CVS_RESP_SETSTICKY 20
167: #define CVS_RESP_CLRSTICKY 21
168: #define CVS_RESP_TEMPLATE 22
169: #define CVS_RESP_SETCIPROG 23
170: #define CVS_RESP_SETUPDPROG 24
171: #define CVS_RESP_NOTIFIED 25
172: #define CVS_RESP_MODXPAND 26
173: #define CVS_RESP_WRAPRCSOPT 27
174: #define CVS_RESP_M 28
175: #define CVS_RESP_MBINARY 29
176: #define CVS_RESP_E 30
177: #define CVS_RESP_F 31
178: #define CVS_RESP_MT 32
179:
180:
181:
182:
183: #define CVS_CMD_MAXNAMELEN 16
184: #define CVS_CMD_MAXALIAS 2
185: #define CVS_CMD_MAXDESCRLEN 64
186:
187:
188: /* defaults */
189: #define CVS_RSH_DEFAULT "ssh"
190: #define CVS_EDITOR_DEFAULT "vi"
191:
192:
193: /* server-side paths */
194: #define CVS_PATH_ROOT "CVSROOT"
195: #define CVS_PATH_COMMITINFO CVS_PATH_ROOT "/commitinfo"
196: #define CVS_PATH_CONFIG CVS_PATH_ROOT "/config"
197: #define CVS_PATH_CVSIGNORE CVS_PATH_ROOT "/cvsignore"
198: #define CVS_PATH_CVSWRAPPERS CVS_PATH_ROOT "/cvswrappers"
199: #define CVS_PATH_EDITINFO CVS_PATH_ROOT "/editinfo"
200: #define CVS_PATH_HISTORY CVS_PATH_ROOT "/history"
201: #define CVS_PATH_LOGINFO CVS_PATH_ROOT "/loginfo"
202: #define CVS_PATH_MODULES CVS_PATH_ROOT "/modules"
203: #define CVS_PATH_NOTIFY CVS_PATH_ROOT "/notify"
204: #define CVS_PATH_RCSINFO CVS_PATH_ROOT "/rcsinfo"
205: #define CVS_PATH_TAGINFO CVS_PATH_ROOT "/taginfo"
206: #define CVS_PATH_VERIFYMSG CVS_PATH_ROOT "/verifymsg"
207:
208:
209: /* client-side paths */
210: #define CVS_PATH_RC ".cvsrc"
211: #define CVS_PATH_CVSDIR "CVS"
212: #define CVS_PATH_ENTRIES CVS_PATH_CVSDIR "/Entries"
213: #define CVS_PATH_STATICENTRIES CVS_PATH_CVSDIR "/Entries.Static"
214: #define CVS_PATH_LOGENTRIES CVS_PATH_CVSDIR "/Entries.Log"
215: #define CVS_PATH_ROOTSPEC CVS_PATH_CVSDIR "/Root"
1.10 jfb 216: #define CVS_PATH_REPOSITORY CVS_PATH_CVSDIR "/Repository"
1.1 jfb 217:
218:
1.7 jfb 219: struct cvs_file;
220: struct cvs_dir;
221:
222:
1.1 jfb 223: struct cvs_op {
224: u_int co_op;
225: uid_t co_uid; /* user performing the operation */
226: char *co_path; /* target path of the operation */
227: char *co_tag; /* tag or branch, NULL if HEAD */
228: };
229:
230:
231:
232: struct cvsroot {
1.11 jfb 233: char *cr_str;
1.1 jfb 234: u_int cr_method;
235: char *cr_buf;
236: char *cr_user;
237: char *cr_pass;
238: char *cr_host;
239: char *cr_dir;
240: u_int cr_port;
1.11 jfb 241: u_int cr_ref;
242:
243: /* connection data */
244: FILE *cr_srvin;
245: FILE *cr_srvout;
1.1 jfb 246: };
247:
248:
1.7 jfb 249: #define CF_STAT 0x01 /* allocate space for file stats */
250: #define CF_IGNORE 0x02 /* apply regular ignore rules */
251: #define CF_RECURSE 0x04 /* recurse on directory operations */
252: #define CF_SORT 0x08 /* all files are sorted alphabetically */
1.8 jfb 253: #define CF_KNOWN 0x10 /* only recurse in directories known to CVS */
1.10 jfb 254: #define CF_CREATE 0x20 /* create if file does not exist */
1.7 jfb 255:
256:
257: /*
258: * The cvs_file structure is used to represent any file or directory within
259: * the CVS tree's hierarchy. The <cf_path> field is a path relative to the
260: * directory in which the cvs command was executed. The <cf_parent> field
261: * points back to the parent node in the directory tree structure (it is
262: * NULL if the directory is at the wd of the command).
263: *
1.8 jfb 264: * The <cf_cvstat> field gives the file's status with regards to the CVS
265: * repository. The file can be in any one of the CVS_FST_* states.
1.7 jfb 266: * If the file's type is DT_DIR, then the <cf_ddat> pointer will point to
267: * a cvs_dir structure containing data specific to the directory (such as
268: * the contents of the directory's CVS/Entries, CVS/Root, etc.).
269: */
270:
1.8 jfb 271: #define CVS_FST_UNKNOWN 0
272: #define CVS_FST_UPTODATE 1
273: #define CVS_FST_MODIFIED 2
274: #define CVS_FST_ADDED 3
275: #define CVS_FST_REMOVED 4
276: #define CVS_FST_CONFLICT 5
1.12 ! jfb 277: #define CVS_FST_PATCHED 6
1.8 jfb 278:
1.9 jfb 279: typedef struct cvs_file {
1.7 jfb 280: char *cf_path;
281: struct cvs_file *cf_parent; /* parent directory (NULL if none) */
282: char *cf_name;
1.8 jfb 283: u_int16_t cf_cvstat; /* cvs status of the file */
284: u_int16_t cf_type; /* uses values from dirent.h */
285: struct stat *cf_stat; /* only available with CF_STAT flag */
286: struct cvs_dir *cf_ddat; /* only for directories */
1.7 jfb 287:
288: LIST_ENTRY(cvs_file) cf_list;
1.9 jfb 289: } CVSFILE;
1.7 jfb 290:
291:
292: struct cvs_dir {
293: struct cvsroot *cd_root;
294: char *cd_repo;
295: LIST_HEAD(cvs_flist, cvs_file) cd_files;
296: };
297:
1.1 jfb 298: #define CVS_HIST_ADDED 'A'
299: #define CVS_HIST_EXPORT 'E'
300: #define CVS_HIST_RELEASE 'F'
301: #define CVS_HIST_MODIFIED 'M'
302: #define CVS_HIST_CHECKOUT 'O'
303: #define CVS_HIST_COMMIT 'R'
304: #define CVS_HIST_TAG 'T'
305:
306:
307: #define CVS_ENT_NONE 0
308: #define CVS_ENT_FILE 1
309: #define CVS_ENT_DIR 2
310:
311:
312: struct cvs_ent {
313: char *ce_line;
314: char *ce_buf;
315: u_int ce_type;
316: char *ce_name;
317: RCSNUM *ce_rev;
318: char *ce_timestamp;
319: char *ce_opts;
320: char *ce_tag;
1.4 jfb 321: TAILQ_ENTRY(cvs_ent) ce_list;
1.1 jfb 322: };
323:
324: typedef struct cvs_entries {
325: char *cef_path;
1.3 jfb 326: FILE *cef_file;
1.1 jfb 327:
1.4 jfb 328: TAILQ_HEAD(, cvs_ent) cef_ent;
329: struct cvs_ent *cef_cur;
1.1 jfb 330: } CVSENTRIES;
331:
332:
333:
334: struct cvs_hent {
335: char ch_event;
336: time_t ch_date;
337: uid_t ch_uid;
338: char *ch_user;
339: char *ch_curdir;
340: char *ch_repo;
341: RCSNUM *ch_rev;
342: char *ch_arg;
343: };
344:
345:
346: typedef struct cvs_histfile {
347: int chf_fd;
348: char *chf_buf; /* read buffer */
349: size_t chf_blen; /* buffer size */
350: size_t chf_bused; /* bytes used in buffer */
351:
352: off_t chf_off; /* next read */
353: u_int chf_sindex; /* history entry index of first in array */
354: u_int chf_cindex; /* current index (for getnext()) */
355: u_int chf_nbhent; /* number of valid entries in the array */
356:
357: struct cvs_hent chf_hent[CVS_HIST_CACHE];
358:
359: } CVSHIST;
360:
361:
362:
363: /* client command handlers */
364: int cvs_add (int, char **);
1.9 jfb 365: int cvs_checkout (int, char **);
1.1 jfb 366: int cvs_commit (int, char **);
367: int cvs_diff (int, char **);
368: int cvs_getlog (int, char **);
369: int cvs_history (int, char **);
370: int cvs_init (int, char **);
371: int cvs_server (int, char **);
372: int cvs_update (int, char **);
373: int cvs_version (int, char **);
374:
375:
376: /* proto.c */
377: int cvs_req_handle (char *);
378: const char* cvs_req_getbyid (int);
379: int cvs_req_getbyname (const char *);
380: char* cvs_req_getvalid (void);
381:
1.2 jfb 382:
1.1 jfb 383: int cvs_resp_handle (char *);
384: const char* cvs_resp_getbyid (int);
385: int cvs_resp_getbyname (const char *);
386: char* cvs_resp_getvalid (void);
387:
388: int cvs_sendfile (const char *);
389: int cvs_recvfile (const char *);
390:
391:
392: /* from client.c */
1.11 jfb 393: int cvs_client_connect (struct cvsroot *);
394: void cvs_client_disconnect (struct cvsroot *);
1.1 jfb 395: int cvs_client_sendreq (u_int, const char *, int);
396: int cvs_client_sendarg (const char *, int);
397: int cvs_client_sendln (const char *);
398: int cvs_client_sendraw (const void *, size_t);
399: ssize_t cvs_client_recvraw (void *, size_t);
400: int cvs_client_getln (char *, size_t);
401: int cvs_client_senddir (const char *);
402:
403:
404: /* from root.c */
405: struct cvsroot* cvsroot_parse (const char *);
406: void cvsroot_free (struct cvsroot *);
407: struct cvsroot* cvsroot_get (const char *);
1.2 jfb 408:
409:
1.7 jfb 410: /* from file.c */
1.9 jfb 411: int cvs_file_init (void);
412: int cvs_file_ignore (const char *);
413: int cvs_file_chkign (const char *);
1.10 jfb 414: CVSFILE* cvs_file_create (const char *, u_int, mode_t);
1.9 jfb 415: CVSFILE* cvs_file_get (const char *, int);
1.12 ! jfb 416: CVSFILE* cvs_file_getspec (char **, int, int);
1.9 jfb 417: void cvs_file_free (struct cvs_file *);
418: int cvs_file_examine (CVSFILE *, int (*)(CVSFILE *, void *), void *);
1.1 jfb 419:
420:
421: /* Entries API */
1.3 jfb 422: CVSENTRIES* cvs_ent_open (const char *, int);
1.1 jfb 423: struct cvs_ent* cvs_ent_get (CVSENTRIES *, const char *);
424: struct cvs_ent* cvs_ent_next (CVSENTRIES *);
425: int cvs_ent_add (CVSENTRIES *, struct cvs_ent *);
1.5 jfb 426: int cvs_ent_addln (CVSENTRIES *, const char *);
1.1 jfb 427: int cvs_ent_remove (CVSENTRIES *, const char *);
428: struct cvs_ent* cvs_ent_parse (const char *);
429: void cvs_ent_close (CVSENTRIES *);
1.8 jfb 430: void cvs_ent_free (struct cvs_ent *);
431: struct cvs_ent* cvs_ent_getent (const char *);
1.1 jfb 432:
433: /* history API */
434: CVSHIST* cvs_hist_open (const char *);
435: void cvs_hist_close (CVSHIST *);
436: int cvs_hist_parse (CVSHIST *);
437: struct cvs_hent* cvs_hist_getnext (CVSHIST *);
438: int cvs_hist_append (CVSHIST *, struct cvs_hent *);
439:
440:
441: /* from util.c */
442: int cvs_readrepo (const char *, char *, size_t);
443: int cvs_splitpath (const char *, char *, size_t, char *, size_t);
444: int cvs_modetostr (mode_t, char *, size_t);
445: int cvs_strtomode (const char *, mode_t *);
1.10 jfb 446: int cvs_mkadmin (struct cvs_file *, mode_t);
1.1 jfb 447: int cvs_cksum (const char *, char *, size_t);
448: int cvs_exec (int, char **, int []);
1.6 jfb 449: int cvs_getargv (const char *, char **, int);
450: void cvs_freeargv (char **, int);
1.1 jfb 451:
452:
453: #endif /* CVS_H */