doc
csync.h
Go to the documentation of this file.
1 /*
2  * libcsync -- a library to sync a directory with another
3  *
4  * Copyright (c) 2006-2008 by Andreas Schneider <mail@cynapses.org>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 /**
22  * @file csync.h
23  *
24  * @brief Application developer interface for csync.
25  *
26  * @defgroup csyncPublicAPI csync public API
27  *
28  * @{
29  */
30 
31 #ifndef _CSYNC_H
32 #define _CSYNC_H
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #define CSYNC_STRINGIFY(s) CSYNC_TOSTRING(s)
39 #define CSYNC_TOSTRING(s) #s
40 
41 /* csync version macros */
42 #define CSYNC_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c))
43 #define CSYNC_VERSION_DOT(a, b, c) a ##.## b ##.## c
44 #define CSYNC_VERSION(a, b, c) CSYNC_VERSION_DOT(a, b, c)
45 
46 /* csync version */
47 #define LIBCSYNC_VERSION_MAJOR 0
48 #define LIBCSYNC_VERSION_MINOR 44
49 #define LIBCSYNC_VERSION_MICRO 0
50 
51 #define LIBCSYNC_VERSION_INT CSYNC_VERSION_INT(LIBCSYNC_VERSION_MAJOR, \
52  LIBCSYNC_VERSION_MINOR, \
53  LIBCSYNC_VERSION_MICRO)
54 #define LIBCSYNC_VERSION CSYNC_VERSION(LIBCSYNC_VERSION_MAJOR, \
55  LIBCSYNC_VERSION_MINOR, \
56  LIBCSYNC_VERSION_MICRO)
57 
58 /*
59  * csync file declarations
60  */
61 #define CSYNC_CONF_DIR ".csync"
62 #define CSYNC_CONF_FILE "csync.conf"
63 #define CSYNC_LOG_FILE "csync_log.conf"
64 #define CSYNC_EXCLUDE_FILE "csync_exclude.conf"
65 #define CSYNC_LOCK_FILE "lock"
66 
67 typedef int (*csync_auth_callback) (const char *prompt, char *buf, size_t len,
68  int echo, int verify, void *userdata);
69 
70 /**
71  * csync handle
72  */
73 typedef struct csync_s CSYNC;
74 
75 /**
76  * @brief Allocate a csync context.
77  *
78  * @param csync The context variable to allocate.
79  *
80  * @return 0 on success, less than 0 if an error occured.
81  */
82 int csync_create(CSYNC **csync, const char *local, const char *remote);
83 
84 /**
85  * @brief Initialize the file synchronizer.
86  *
87  * This function loads the configuration, the statedb and locks the client.
88  *
89  * @param ctx The context to initialize.
90  *
91  * @return 0 on success, less than 0 if an error occured.
92  */
93 int csync_init(CSYNC *ctx);
94 
95 /**
96  * @brief Update detection
97  *
98  * @param ctx The context to run the update detection on.
99  *
100  * @return 0 on success, less than 0 if an error occured.
101  */
102 int csync_update(CSYNC *ctx);
103 
104 /**
105  * @brief Reconciliation
106  *
107  * @param ctx The context to run the reconciliation on.
108  *
109  * @return 0 on success, less than 0 if an error occured.
110  */
111 int csync_reconcile(CSYNC *ctx);
112 
113 /**
114  * @brief Propagation
115  *
116  * @param ctx The context to run the propagation on.
117  *
118  * @return 0 on success, less than 0 if an error occured.
119  */
120 int csync_propagate(CSYNC *ctx);
121 
122 /**
123  * @brief Destroy the csync context
124  *
125  * Writes the statedb, unlocks csync and frees the memory.
126  *
127  * @param ctx The context to destroy.
128  *
129  * @return 0 on success, less than 0 if an error occured.
130  */
131 int csync_destroy(CSYNC *ctx);
132 
133 /**
134  * @brief Check if csync is the required version or get the version
135  * string.
136  *
137  * @param req_version The version required.
138  *
139  * @return If the version of csync is newer than the version
140  * required it will return a version string.
141  * NULL if the version is older.
142  *
143  * Example:
144  *
145  * @code
146  * if (csync_version(CSYNC_VERSION_INT(0,42,1)) == NULL) {
147  * fprintf(stderr, "libcsync version is too old!\n");
148  * exit(1);
149  * }
150  *
151  * if (debug) {
152  * printf("csync %s\n", csync_version(0));
153  * }
154  * @endcode
155  */
156 const char *csync_version(int req_version);
157 
158 /**
159  * @brief Add an additional exclude list.
160  *
161  * @param ctx The context to add the exclude list.
162  *
163  * @param path The path pointing to the file.
164  *
165  * @return 0 on success, less than 0 if an error occured.
166  */
167 int csync_add_exclude_list(CSYNC *ctx, const char *path);
168 
169 /**
170  * @brief Get the config directory.
171  *
172  * @param ctx The csync context.
173  *
174  * @return The path of the config directory or NULL on error.
175  */
176 const char *csync_get_config_dir(CSYNC *ctx);
177 
178 /**
179  * @brief Change the config directory.
180  *
181  * @param ctx The csync context.
182  *
183  * @param path The path to the new config directory.
184  *
185  * @return 0 on success, less than 0 if an error occured.
186  */
187 int csync_set_config_dir(CSYNC *ctx, const char *path);
188 
189 /**
190  * @brief Remove the complete config directory.
191  *
192  * @param ctx The csync context.
193  *
194  * @return 0 on success, less than 0 if an error occured.
195  */
197 
198 /**
199  * @brief Enable the usage of the statedb. It is enabled by default.
200  *
201  * @param ctx The csync context.
202  *
203  * @return 0 on success, less than 0 if an error occured.
204  */
205 int csync_enable_statedb(CSYNC *ctx);
206 
207 /**
208  * @brief Disable the usage of the statedb. It is enabled by default.
209  *
210  * @param ctx The csync context.
211  *
212  * @return 0 on success, less than 0 if an error occured.
213  */
214 int csync_disable_statedb(CSYNC *ctx);
215 
216 /**
217  * @brief Check if the statedb usage is enabled.
218  *
219  * @param ctx The csync context.
220  *
221  * @return 1 if it is enabled, 0 if it is disabled.
222  */
224 
225 /**
226  * @brief Get the userdata saved in the context.
227  *
228  * @param ctx The csync context.
229  *
230  * @return The userdata saved in the context, NULL if an error
231  * occured.
232  */
233 void *csync_get_userdata(CSYNC *ctx);
234 
235 /**
236  * @brief Save userdata to the context which is passed to the auth
237  * callback function.
238  *
239  * @param ctx The csync context.
240  *
241  * @param userdata The userdata to be stored in the context.
242  *
243  * @return 0 on success, less than 0 if an error occured.
244  */
245 int csync_set_userdata(CSYNC *ctx, void *userdata);
246 
247 /**
248  * @brief Get the authentication callback set.
249  *
250  * @param ctx The csync context.
251  *
252  * @return The authentication callback set or NULL if an error
253  * occured.
254  */
256 
257 /**
258  * @brief Set the authentication callback.
259  *
260  * @param ctx The csync context.
261  *
262  * @param cb The authentication callback.
263  *
264  * @return 0 on success, less than 0 if an error occured.
265  */
267 
268 /**
269  * @brief Get the path of the statedb file used.
270  *
271  * @param ctx The csync context.
272  *
273  * @return The path to the statedb file, NULL if an error occured.
274  */
275 const char *csync_get_statedb_file(CSYNC *ctx);
276 
277 /* Used for special modes or debugging */
278 int csync_get_status(CSYNC *ctx);
279 
280 /* Used for special modes or debugging */
281 int csync_set_status(CSYNC *ctx, int status);
282 
283 #ifdef __cplusplus
284 }
285 #endif
286 
287 /**
288  * }@
289  */
290 #endif /* _CSYNC_H */
291 /* vim: set ft=c.doxygen ts=8 sw=2 et cindent: */