00001 /* 00002 * libcsync -- a library to sync a directory with another 00003 * 00004 * Copyright (c) 2006-2012 by Andreas Schneider <asn@cryptomilk.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 00021 /** 00022 * @file csync_private.h 00023 * 00024 * @brief Private interface of csync 00025 * 00026 * @defgroup csyncInternalAPI csync internal API 00027 * 00028 * @{ 00029 */ 00030 00031 #ifndef _CSYNC_PRIVATE_H 00032 #define _CSYNC_PRIVATE_H 00033 00034 #include <stdint.h> 00035 #include <stdbool.h> 00036 #include <sqlite3.h> 00037 00038 #include "config.h" 00039 #include "c_lib.h" 00040 #include "c_private.h" 00041 #include "csync.h" 00042 #include "csync_misc.h" 00043 00044 #ifdef WITH_ICONV 00045 #include <iconv.h> 00046 #endif 00047 00048 #include "vio/csync_vio_method.h" 00049 #include "csync_macros.h" 00050 00051 /** 00052 * How deep to scan directories. 00053 */ 00054 #define MAX_DEPTH 50 00055 00056 /** 00057 * Maximum time difference between two replicas in seconds 00058 */ 00059 #define MAX_TIME_DIFFERENCE 10 00060 00061 /** 00062 * Maximum size of a buffer for transfer 00063 */ 00064 #ifndef MAX_XFER_BUF_SIZE 00065 #define MAX_XFER_BUF_SIZE (16 * 1024) 00066 #endif 00067 00068 #define CSYNC_STATUS_INIT 1 << 0 00069 #define CSYNC_STATUS_UPDATE 1 << 1 00070 #define CSYNC_STATUS_RECONCILE 1 << 2 00071 #define CSYNC_STATUS_PROPAGATE 1 << 3 00072 00073 #define CSYNC_STATUS_DONE (CSYNC_STATUS_INIT | \ 00074 CSYNC_STATUS_UPDATE | \ 00075 CSYNC_STATUS_RECONCILE | \ 00076 CSYNC_STATUS_PROPAGATE) 00077 00078 enum csync_replica_e { 00079 LOCAL_REPLICA, 00080 REMOTE_REPLICA 00081 }; 00082 00083 typedef struct csync_file_stat_s csync_file_stat_t; 00084 00085 /** 00086 * @brief csync public structure 00087 */ 00088 struct csync_s { 00089 struct { 00090 csync_auth_callback auth_function; 00091 csync_log_callback log_function; 00092 csync_progress_callback progress_cb; 00093 void *userdata; 00094 } callbacks; 00095 c_strlist_t *excludes; 00096 00097 struct { 00098 char *file; 00099 sqlite3 *db; 00100 int exists; 00101 int disabled; 00102 } statedb; 00103 00104 struct { 00105 char *uri; 00106 c_rbtree_t *tree; 00107 c_list_t *list; 00108 enum csync_replica_e type; 00109 c_list_t *ignored_cleanup; 00110 } local; 00111 00112 struct { 00113 char *uri; 00114 c_rbtree_t *tree; 00115 c_list_t *list; 00116 enum csync_replica_e type; 00117 int read_from_db; 00118 c_list_t *ignored_cleanup; 00119 } remote; 00120 00121 struct { 00122 void *handle; 00123 csync_vio_method_t *method; 00124 csync_vio_method_finish_fn finish_fn; 00125 csync_vio_capabilities_t capabilities; 00126 } module; 00127 00128 struct { 00129 int max_depth; 00130 int max_time_difference; 00131 int sync_symbolic_links; 00132 int unix_extensions; 00133 char *config_dir; 00134 bool with_conflict_copys; 00135 bool local_only_mode; 00136 bool remote_push_atomar; 00137 int log_verbosity; 00138 int timeout; 00139 #ifdef WITH_ICONV 00140 iconv_t iconv_cd; 00141 #endif 00142 } options; 00143 00144 struct { 00145 uid_t uid; 00146 uid_t euid; 00147 } pwd; 00148 00149 csync_overall_progress_t overall_progress; 00150 00151 struct csync_progressinfo_s *progress_info; 00152 00153 /* replica we are currently walking */ 00154 enum csync_replica_e current; 00155 00156 /* replica we want to work on */ 00157 enum csync_replica_e replica; 00158 00159 /* Used in the update phase so changes in the sub directories can be notified to 00160 parent directories */ 00161 csync_file_stat_t *current_fs; 00162 00163 /* error code of the last operation */ 00164 enum csync_error_codes_e error_code; 00165 char *error_string; 00166 00167 int status; 00168 volatile int abort; 00169 void *rename_info; 00170 }; 00171 00172 00173 #ifdef _MSC_VER 00174 #pragma pack(1) 00175 #endif 00176 struct csync_file_stat_s { 00177 uint64_t phash; /* u64 */ 00178 time_t modtime; /* u64 */ 00179 int64_t size; /* u64 */ 00180 size_t pathlen; /* u64 */ 00181 uint64_t inode; /* u64 */ 00182 uid_t uid; /* u32 */ 00183 gid_t gid; /* u32 */ 00184 mode_t mode; /* u32 */ 00185 int nlink; /* u32 */ 00186 int type; /* u32 */ 00187 int child_modified;/*bool*/ 00188 int should_update_md5; /*bool */ 00189 00190 char *destpath; /* for renames */ 00191 const char *md5; 00192 const char *error_string; 00193 00194 enum csync_instructions_e instruction; /* u32 */ 00195 char path[1]; /* u8 */ 00196 } 00197 #if !defined(__SUNPRO_C) && !defined(_MSC_VER) 00198 __attribute__ ((packed)) 00199 #endif 00200 #ifdef _MSC_VER 00201 #pragma pack() 00202 #endif 00203 ; 00204 00205 void csync_file_stat_free(csync_file_stat_t *st); 00206 00207 /* 00208 * context for the treewalk function 00209 */ 00210 struct _csync_treewalk_context_s 00211 { 00212 csync_treewalk_visit_func *user_visitor; 00213 int instruction_filter; 00214 void *userdata; 00215 }; 00216 typedef struct _csync_treewalk_context_s _csync_treewalk_context; 00217 00218 /** 00219 * }@ 00220 */ 00221 #endif /* _CSYNC_PRIVATE_H */ 00222 /* vim: set ft=c.doxygen ts=8 sw=2 et cindent: */