00001 /* 00002 * libcsync -- a library to sync a directory with another 00003 * 00004 * Copyright (c) 2006-2008 by Andreas Schneider <mail@cynapses.org> 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * vim: ts=2 sw=2 et cindent 00021 */ 00022 00023 /** 00024 * @file csync.h 00025 * 00026 * @brief Application developer interface for csync. 00027 * 00028 * @defgroup csyncPublicAPI csync public API 00029 * 00030 * @{ 00031 */ 00032 00033 #ifndef _CSYNC_H 00034 #define _CSYNC_H 00035 00036 #ifdef __cplusplus 00037 extern "C" { 00038 #endif 00039 00040 #define CSYNC_STRINGIFY(s) CSYNC_TOSTRING(s) 00041 #define CSYNC_TOSTRING(s) #s 00042 00043 /* csync version macros */ 00044 #define CSYNC_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c)) 00045 #define CSYNC_VERSION_DOT(a, b, c) a ##.## b ##.## c 00046 #define CSYNC_VERSION(a, b, c) CSYNC_VERSION_DOT(a, b, c) 00047 00048 /* csync version */ 00049 #define LIBCSYNC_VERSION_MAJOR 0 00050 #define LIBCSYNC_VERSION_MINOR 42 00051 #define LIBCSYNC_VERSION_MICRO 0 00052 00053 #define LIBCSYNC_VERSION_INT CSYNC_VERSION_INT(LIBCSYNC_VERSION_MAJOR, \ 00054 LIBCSYNC_VERSION_MINOR, \ 00055 LIBCSYNC_VERSION_MICRO) 00056 #define LIBCSYNC_VERSION CSYNC_VERSION(LIBCSYNC_VERSION_MAJOR, \ 00057 LIBCSYNC_VERSION_MINOR, \ 00058 LIBCSYNC_VERSION_MICRO) 00059 00060 /* 00061 * csync file declarations 00062 */ 00063 #define CSYNC_CONF_DIR ".csync" 00064 #define CSYNC_CONF_FILE "csync.conf" 00065 #define CSYNC_LOG_FILE "csync_log.conf" 00066 #define CSYNC_EXCLUDE_FILE "csync_exclude.conf" 00067 #define CSYNC_LOCK_FILE "lock" 00068 00069 typedef int (*csync_auth_callback) (const char *prompt, char *buf, size_t len, 00070 int echo, int verify, void *userdata); 00071 00072 /** 00073 * csync handle 00074 */ 00075 typedef struct csync_s CSYNC; 00076 00077 /** 00078 * @brief Allocate a csync context. 00079 * 00080 * @param csync The context variable to allocate. 00081 * 00082 * @return 0 on success, less than 0 if an error occured. 00083 */ 00084 int csync_create(CSYNC **csync, const char *local, const char *remote); 00085 00086 /** 00087 * @brief Initialize the file synchronizer. 00088 * 00089 * This function loads the configuration, the statedb and locks the client. 00090 * 00091 * @param ctx The context to initialize. 00092 * 00093 * @return 0 on success, less than 0 if an error occured. 00094 */ 00095 int csync_init(CSYNC *ctx); 00096 00097 /** 00098 * @brief Update detection 00099 * 00100 * @param ctx The context to run the update detection on. 00101 * 00102 * @return 0 on success, less than 0 if an error occured. 00103 */ 00104 int csync_update(CSYNC *ctx); 00105 00106 /** 00107 * @brief Reconciliation 00108 * 00109 * @param ctx The context to run the reconciliation on. 00110 * 00111 * @return 0 on success, less than 0 if an error occured. 00112 */ 00113 int csync_reconcile(CSYNC *ctx); 00114 00115 /** 00116 * @brief Propagation 00117 * 00118 * @param ctx The context to run the propagation on. 00119 * 00120 * @return 0 on success, less than 0 if an error occured. 00121 */ 00122 int csync_propagate(CSYNC *ctx); 00123 00124 /** 00125 * @brief Destroy the csync context 00126 * 00127 * Writes the statedb, unlocks csync and frees the memory. 00128 * 00129 * @param ctx The context to destroy. 00130 * 00131 * @return 0 on success, less than 0 if an error occured. 00132 */ 00133 int csync_destroy(CSYNC *ctx); 00134 00135 /** 00136 * @brief Check if csync is the required version or get the version 00137 * string. 00138 * 00139 * @param req_version The version required. 00140 * 00141 * @return If the version of csync is newer than the version 00142 * required it will return a version string. 00143 * NULL if the version is older. 00144 * 00145 * Example: 00146 * 00147 * @code 00148 * if (csync_version(CSYNC_VERSION_INT(0,42,1)) == NULL) { 00149 * fprintf(stderr, "libcsync version is too old!\n"); 00150 * exit(1); 00151 * } 00152 * 00153 * if (debug) { 00154 * printf("csync %s\n", csync_version(0)); 00155 * } 00156 * @endcode 00157 */ 00158 const char *csync_version(int req_version); 00159 00160 /** 00161 * @brief Add an additional exclude list. 00162 * 00163 * @param ctx The context to add the exclude list. 00164 * 00165 * @param path The path pointing to the file. 00166 * 00167 * @return 0 on success, less than 0 if an error occured. 00168 */ 00169 int csync_add_exclude_list(CSYNC *ctx, const char *path); 00170 00171 /** 00172 * @brief Get the config directory. 00173 * 00174 * @param ctx The csync context. 00175 * 00176 * @return The path of the config directory or NULL on error. 00177 */ 00178 const char *csync_get_config_dir(CSYNC *ctx); 00179 00180 /** 00181 * @brief Change the config directory. 00182 * 00183 * @param ctx The csync context. 00184 * 00185 * @param path The path to the new config directory. 00186 * 00187 * @return 0 on success, less than 0 if an error occured. 00188 */ 00189 int csync_set_config_dir(CSYNC *ctx, const char *path); 00190 00191 /** 00192 * @brief Remove the complete config directory. 00193 * 00194 * @param ctx The csync context. 00195 * 00196 * @return 0 on success, less than 0 if an error occured. 00197 */ 00198 int csync_remove_config_dir(CSYNC *ctx); 00199 00200 /** 00201 * @brief Enable the usage of the statedb. It is enabled by default. 00202 * 00203 * @param ctx The csync context. 00204 * 00205 * @return 0 on success, less than 0 if an error occured. 00206 */ 00207 int csync_enable_statedb(CSYNC *ctx); 00208 00209 /** 00210 * @brief Disable the usage of the statedb. It is enabled by default. 00211 * 00212 * @param ctx The csync context. 00213 * 00214 * @return 0 on success, less than 0 if an error occured. 00215 */ 00216 int csync_disable_statedb(CSYNC *ctx); 00217 00218 /** 00219 * @brief Check if the statedb usage is enabled. 00220 * 00221 * @param ctx The csync context. 00222 * 00223 * @return 1 if it is enabled, 0 if it is disabled. 00224 */ 00225 int csync_is_statedb_disabled(CSYNC *ctx); 00226 00227 /** 00228 * @brief Get the userdata saved in the context. 00229 * 00230 * @param ctx The csync context. 00231 * 00232 * @return The userdata saved in the context, NULL if an error 00233 * occured. 00234 */ 00235 void *csync_get_userdata(CSYNC *ctx); 00236 00237 /** 00238 * @brief Save userdata to the context which is passed to the auth 00239 * callback function. 00240 * 00241 * @param ctx The csync context. 00242 * 00243 * @param userdata The userdata to be stored in the context. 00244 * 00245 * @return 0 on success, less than 0 if an error occured. 00246 */ 00247 int csync_set_userdata(CSYNC *ctx, void *userdata); 00248 00249 /** 00250 * @brief Get the authentication callback set. 00251 * 00252 * @param ctx The csync context. 00253 * 00254 * @return The authentication callback set or NULL if an error 00255 * occured. 00256 */ 00257 csync_auth_callback csync_get_auth_callback(CSYNC *ctx); 00258 00259 /** 00260 * @brief Set the authentication callback. 00261 * 00262 * @param ctx The csync context. 00263 * 00264 * @param cb The authentication callback. 00265 * 00266 * @return 0 on success, less than 0 if an error occured. 00267 */ 00268 int csync_set_auth_callback(CSYNC *ctx, csync_auth_callback cb); 00269 00270 /** 00271 * @brief Get the path of the statedb file used. 00272 * 00273 * @param ctx The csync context. 00274 * 00275 * @return The path to the statedb file, NULL if an error occured. 00276 */ 00277 const char *csync_get_statedb_file(CSYNC *ctx); 00278 00279 /* Used for special modes or debugging */ 00280 int csync_get_status(CSYNC *ctx); 00281 00282 /* Used for special modes or debugging */ 00283 int csync_set_status(CSYNC *ctx, int status); 00284 00285 #ifdef __cplusplus 00286 } 00287 #endif 00288 00289 /** 00290 * }@ 00291 */ 00292 #endif /* _CSYNC_H */ 00293