Annotation of src/usr.bin/cvs/cvs.h, Revision 1.9
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"
216:
217:
1.7 jfb 218: struct cvs_file;
219: struct cvs_dir;
220:
221:
1.1 jfb 222: struct cvs_op {
223: u_int co_op;
224: uid_t co_uid; /* user performing the operation */
225: char *co_path; /* target path of the operation */
226: char *co_tag; /* tag or branch, NULL if HEAD */
227: };
228:
229:
230:
231: struct cvsroot {
232: u_int cr_method;
233: char *cr_buf;
234: char *cr_user;
235: char *cr_pass;
236: char *cr_host;
237: char *cr_dir;
238: u_int cr_port;
239: };
240:
241:
1.7 jfb 242: #define CF_STAT 0x01 /* allocate space for file stats */
243: #define CF_IGNORE 0x02 /* apply regular ignore rules */
244: #define CF_RECURSE 0x04 /* recurse on directory operations */
245: #define CF_SORT 0x08 /* all files are sorted alphabetically */
1.8 jfb 246: #define CF_KNOWN 0x10 /* only recurse in directories known to CVS */
1.7 jfb 247:
248:
249: /*
250: * The cvs_file structure is used to represent any file or directory within
251: * the CVS tree's hierarchy. The <cf_path> field is a path relative to the
252: * directory in which the cvs command was executed. The <cf_parent> field
253: * points back to the parent node in the directory tree structure (it is
254: * NULL if the directory is at the wd of the command).
255: *
1.8 jfb 256: * The <cf_cvstat> field gives the file's status with regards to the CVS
257: * repository. The file can be in any one of the CVS_FST_* states.
1.7 jfb 258: * If the file's type is DT_DIR, then the <cf_ddat> pointer will point to
259: * a cvs_dir structure containing data specific to the directory (such as
260: * the contents of the directory's CVS/Entries, CVS/Root, etc.).
261: */
262:
1.8 jfb 263: #define CVS_FST_UNKNOWN 0
264: #define CVS_FST_UPTODATE 1
265: #define CVS_FST_MODIFIED 2
266: #define CVS_FST_ADDED 3
267: #define CVS_FST_REMOVED 4
268: #define CVS_FST_CONFLICT 5
269:
1.9 ! jfb 270: typedef struct cvs_file {
1.7 jfb 271: char *cf_path;
272: struct cvs_file *cf_parent; /* parent directory (NULL if none) */
273: char *cf_name;
1.8 jfb 274: u_int16_t cf_cvstat; /* cvs status of the file */
275: u_int16_t cf_type; /* uses values from dirent.h */
276: struct stat *cf_stat; /* only available with CF_STAT flag */
277: struct cvs_dir *cf_ddat; /* only for directories */
1.7 jfb 278:
279: LIST_ENTRY(cvs_file) cf_list;
1.9 ! jfb 280: } CVSFILE;
1.7 jfb 281:
282:
283: struct cvs_dir {
284: struct cvsroot *cd_root;
285: char *cd_repo;
286: LIST_HEAD(cvs_flist, cvs_file) cd_files;
287: };
288:
1.1 jfb 289: #define CVS_HIST_ADDED 'A'
290: #define CVS_HIST_EXPORT 'E'
291: #define CVS_HIST_RELEASE 'F'
292: #define CVS_HIST_MODIFIED 'M'
293: #define CVS_HIST_CHECKOUT 'O'
294: #define CVS_HIST_COMMIT 'R'
295: #define CVS_HIST_TAG 'T'
296:
297:
298: #define CVS_ENT_NONE 0
299: #define CVS_ENT_FILE 1
300: #define CVS_ENT_DIR 2
301:
302:
303: struct cvs_ent {
304: char *ce_line;
305: char *ce_buf;
306: u_int ce_type;
307: char *ce_name;
308: RCSNUM *ce_rev;
309: char *ce_timestamp;
310: char *ce_opts;
311: char *ce_tag;
1.4 jfb 312: TAILQ_ENTRY(cvs_ent) ce_list;
1.1 jfb 313: };
314:
315: typedef struct cvs_entries {
316: char *cef_path;
1.3 jfb 317: FILE *cef_file;
1.1 jfb 318:
1.4 jfb 319: TAILQ_HEAD(, cvs_ent) cef_ent;
320: struct cvs_ent *cef_cur;
1.1 jfb 321: } CVSENTRIES;
322:
323:
324:
325: struct cvs_hent {
326: char ch_event;
327: time_t ch_date;
328: uid_t ch_uid;
329: char *ch_user;
330: char *ch_curdir;
331: char *ch_repo;
332: RCSNUM *ch_rev;
333: char *ch_arg;
334: };
335:
336:
337: typedef struct cvs_histfile {
338: int chf_fd;
339: char *chf_buf; /* read buffer */
340: size_t chf_blen; /* buffer size */
341: size_t chf_bused; /* bytes used in buffer */
342:
343: off_t chf_off; /* next read */
344: u_int chf_sindex; /* history entry index of first in array */
345: u_int chf_cindex; /* current index (for getnext()) */
346: u_int chf_nbhent; /* number of valid entries in the array */
347:
348: struct cvs_hent chf_hent[CVS_HIST_CACHE];
349:
350: } CVSHIST;
351:
352:
353:
354: /* client command handlers */
355: int cvs_add (int, char **);
1.9 ! jfb 356: int cvs_checkout (int, char **);
1.1 jfb 357: int cvs_commit (int, char **);
358: int cvs_diff (int, char **);
359: int cvs_getlog (int, char **);
360: int cvs_history (int, char **);
361: int cvs_init (int, char **);
362: int cvs_server (int, char **);
363: int cvs_update (int, char **);
364: int cvs_version (int, char **);
365:
366:
367: /* proto.c */
368: int cvs_req_handle (char *);
369: const char* cvs_req_getbyid (int);
370: int cvs_req_getbyname (const char *);
371: char* cvs_req_getvalid (void);
372:
1.2 jfb 373:
1.1 jfb 374: int cvs_resp_handle (char *);
375: const char* cvs_resp_getbyid (int);
376: int cvs_resp_getbyname (const char *);
377: char* cvs_resp_getvalid (void);
378:
379: int cvs_sendfile (const char *);
380: int cvs_recvfile (const char *);
381:
382:
383: /* from client.c */
384: int cvs_client_connect (void);
385: void cvs_client_disconnect (void);
386: int cvs_client_sendreq (u_int, const char *, int);
387: int cvs_client_sendarg (const char *, int);
388: int cvs_client_sendln (const char *);
389: int cvs_client_sendraw (const void *, size_t);
390: ssize_t cvs_client_recvraw (void *, size_t);
391: int cvs_client_getln (char *, size_t);
392: int cvs_client_senddir (const char *);
393:
394:
395: /* from root.c */
396: struct cvsroot* cvsroot_parse (const char *);
397: void cvsroot_free (struct cvsroot *);
398: struct cvsroot* cvsroot_get (const char *);
1.2 jfb 399:
400:
1.7 jfb 401: /* from file.c */
1.9 ! jfb 402: int cvs_file_init (void);
! 403: int cvs_file_ignore (const char *);
! 404: int cvs_file_chkign (const char *);
! 405: char** cvs_file_getv (const char *, int *, int);
! 406: CVSFILE* cvs_file_get (const char *, int);
! 407: void cvs_file_free (struct cvs_file *);
! 408: int cvs_file_examine (CVSFILE *, int (*)(CVSFILE *, void *), void *);
1.1 jfb 409:
410:
411: /* Entries API */
1.3 jfb 412: CVSENTRIES* cvs_ent_open (const char *, int);
1.1 jfb 413: struct cvs_ent* cvs_ent_get (CVSENTRIES *, const char *);
414: struct cvs_ent* cvs_ent_next (CVSENTRIES *);
415: int cvs_ent_add (CVSENTRIES *, struct cvs_ent *);
1.5 jfb 416: int cvs_ent_addln (CVSENTRIES *, const char *);
1.1 jfb 417: int cvs_ent_remove (CVSENTRIES *, const char *);
418: struct cvs_ent* cvs_ent_parse (const char *);
419: void cvs_ent_close (CVSENTRIES *);
1.8 jfb 420: void cvs_ent_free (struct cvs_ent *);
421: struct cvs_ent* cvs_ent_getent (const char *);
1.1 jfb 422:
423: /* history API */
424: CVSHIST* cvs_hist_open (const char *);
425: void cvs_hist_close (CVSHIST *);
426: int cvs_hist_parse (CVSHIST *);
427: struct cvs_hent* cvs_hist_getnext (CVSHIST *);
428: int cvs_hist_append (CVSHIST *, struct cvs_hent *);
429:
430:
431: /* from util.c */
432: int cvs_readrepo (const char *, char *, size_t);
433: int cvs_splitpath (const char *, char *, size_t, char *, size_t);
434: int cvs_modetostr (mode_t, char *, size_t);
435: int cvs_strtomode (const char *, mode_t *);
436: int cvs_cksum (const char *, char *, size_t);
437: int cvs_exec (int, char **, int []);
1.6 jfb 438: int cvs_getargv (const char *, char **, int);
439: void cvs_freeargv (char **, int);
1.1 jfb 440:
441:
442: #endif /* CVS_H */