1 /*-
2  * Copyright (c) 2000-2005 MAEKAWA Masahide <maekawa@cvsync.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the author nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #ifndef __CVSYNC_H__
31 #define	__CVSYNC_H__
32 
33 #define	CVSYNC_MAXCMDLEN	2048
34 #define	CVSYNC_MAXADDRLEN	128
35 
36 #define	CVSYNC_DEFAULT_PORT	"7777"
37 
38 #define	CVSYNC_TMPFILE		".cvsync.XXXXXX"
39 #define	CVSYNC_TMPFILE_LEN	14	/* == strlen(CVSYNC_TMPFILE) */
40 
41 #define	CVSYNC_THREAD_FAILURE	((void *)false)
42 #define	CVSYNC_THREAD_SUCCESS	((void *)true)
43 
44 #define	CVSYNC_BSIZE		1048576 /* 1MB */
45 
46 enum {
47 	CVSYNC_NO_ERROR		= 0x00,
48 	CVSYNC_ERROR_DENIED	= 0x01,
49 	CVSYNC_ERROR_LIMITED	= 0x02,
50 	CVSYNC_ERROR_UNAVAIL	= 0x03,
51 	CVSYNC_ERROR_UNSPEC	= 0xff
52 };
53 
54 enum {
55 	CVSYNC_COMPRESS_UNSPEC,
56 	CVSYNC_COMPRESS_NO,
57 	CVSYNC_COMPRESS_ZLIB
58 };
59 
60 enum {
61 	CVSYNC_COMPRESS_LEVEL_UNSPEC	= -1,
62 	CVSYNC_COMPRESS_LEVEL_NO	= 0,
63 	CVSYNC_COMPRESS_LEVEL_SPEED	= 1,
64 	CVSYNC_COMPRESS_LEVEL_BEST	= 9
65 };
66 
67 enum {
68 	CVSYNC_ERRORMODE_UNSPEC = 0,
69 	CVSYNC_ERRORMODE_ABORT,
70 	CVSYNC_ERRORMODE_FIXUP,
71 	CVSYNC_ERRORMODE_IGNORE
72 };
73 
74 enum {
75 	CVSYNC_LIST_UNKNOWN = 0,
76 
77 	CVSYNC_LIST_ALL,
78 	CVSYNC_LIST_RCS,
79 
80 	CVSYNC_LIST_MAX
81 };
82 
83 enum {
84 	CVSYNC_RELEASE_UNKNOWN = 0,
85 
86 	CVSYNC_RELEASE_LIST,
87 	CVSYNC_RELEASE_RCS,
88 
89 	CVSYNC_RELEASE_MAX
90 };
91 
92 struct cvsync_file {
93 	int	cf_fileno;
94 	off_t	cf_size;
95 	time_t	cf_mtime;
96 	mode_t	cf_mode;
97 
98 	void	*cf_addr;
99 	size_t	cf_msize;
100 };
101 
102 bool cvsync_init(void);
103 
104 int cvsync_compress_pton(const char *);
105 const char *cvsync_compress_ntop(int);
106 int cvsync_list_pton(const char *);
107 const char *cvsync_list_ntop(int);
108 int cvsync_release_pton(const char *);
109 const char *cvsync_release_ntop(int);
110 
111 void *cvsync_memdup(void *, size_t);
112 int cvsync_cmp_pathname(const char *, size_t, const char *, size_t);
113 struct cvsync_file *cvsync_fopen(const char *);
114 bool cvsync_fclose(struct cvsync_file *);
115 bool cvsync_mmap(struct cvsync_file *, off_t, off_t);
116 bool cvsync_munmap(struct cvsync_file *);
117 void cvsync_signal(int);
118 bool cvsync_isinterrupted(void);
119 bool cvsync_isterminated(void);
120 
121 bool cvsync_rcs_append_attic(char *, size_t, size_t);
122 bool cvsync_rcs_insert_attic(char *, size_t, size_t);
123 bool cvsync_rcs_remove_attic(char *, size_t);
124 bool cvsync_rcs_filename(const char *, size_t);
125 bool cvsync_rcs_pathname(const char *, size_t);
126 
127 #endif /* __CVSYNC_H__ */
128