1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #ifndef SYNC_H
30 #define SYNC_H
31
32 #include <curl/curl.h>
33 #include <libidav/webdav.h>
34 #include <cx/list.h>
35 #include <cx/hash_map.h>
36
37 #include "scfg.h"
38 #include "config.h"
39 #include "sopt.h"
40 #include "system.h"
41
42 #include "version.h"
43
44 #ifdef _WIN32
45
46 #else
47 #include <pthread.h>
48 #endif
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54 #define STDIN_BUF_SIZE 2048
55
56 #define VERSION_PATH_PROPERTY "version-collection"
57
58 typedef struct SyncFile {
59 SyncDirectory *dir;
60 char *path;
61 } SyncFile;
62
63 typedef struct MetadataHashes {
64 char *tags;
65 char *tags_remote;
66 char *xattr;
67 DavBool update_tags;
68 DavBool update_tags_remote;
69 DavBool update_xattr;
70 } MetadataHashes;
71
72 typedef struct MovedFile {
73 DavResource *resource;
74 LocalResource *content;
75 DavBool copy;
76 } MovedFile;
77
78 enum RemoteChangeType {
79 REMOTE_NO_CHANGE =
0,
80 REMOTE_CHANGE_MODIFIED,
81 REMOTE_CHANGE_NEW,
82 REMOTE_CHANGE_DELETED,
83 REMOTE_CHANGE_CONFLICT_LOCAL_MODIFIED,
84 REMOTE_CHANGE_METADATA,
85 REMOTE_CHANGE_MKDIR,
86 REMOTE_CHANGE_LINK
87 };
88 typedef enum RemoteChangeType RemoteChangeType;
89
90 typedef struct RemoteChange {
91 DavResource *resource;
92 RemoteChangeType type;
93 } RemoteChange;
94
95 void print_usage(
char *cmd);
96
97 #ifndef _WIN32
98 pthread_t start_sighandler(
pthread_mutex_t *mutex) ;
99 void stop_sighandler(
pthread_mutex_t *mutex,
pthread_t tid);
100 #else
101
102 int start_sighandler(
int* mutex);
103 int stop_sighandler(
int* mutex,
int tid);
104 #endif
105
106 void res2map(DavResource *root, CxMap *map);
107
108 int cmd_pull(CmdArgs *args, DavBool incoming);
109 int cmd_push(CmdArgs *args, DavBool outgoing, DavBool archive);
110 int cmd_restore(CmdArgs *args);
111
112 void log_printf(
const char *fmt, ...);
113
114 void print_outgoing(
115 CmdArgs *args,
116 CxList *ls_new,
117 CxList *ls_modified,
118 CxList *ls_conflict,
119 CxList *ls_update,
120 CxList *ls_delete,
121 CxList *ls_move,
122 CxList *ls_copy,
123 CxList *ls_mkcol);
124
125 RemoteChangeType resource_get_remote_change(
126 CmdArgs *a,
127 DavResource *res,
128 SyncDirectory *dir,
129 SyncDatabase *db);
130
131 void sync_set_metadata_from_stat(LocalResource *local,
SYS_STAT *s);
132 int sync_move_resource(
133 CmdArgs *a,
134 SyncDirectory *dir,
135 DavResource *res,
136 LocalResource *content,
137 DavBool copy,
138 SyncDatabase *db,
139 int *counter);
140 int sync_get_resource(
141 CmdArgs *a,
142 SyncDirectory *dir,
143 const char *path,
144 DavResource *res,
145 SyncDatabase *db,
146 DavBool update_local,
147 int *counter);
148 int sync_get_collection(
149 CmdArgs *a,
150 SyncDirectory *dir,
151 DavResource *res,
152 SyncDatabase *db);
153 int sync_remove_local_resource(SyncDirectory *dir, LocalResource *res);
154 int sync_remove_local_directory(SyncDirectory *dir, LocalResource *res);
155 void rename_conflict_file(SyncDirectory *dir, SyncDatabase *db,
char *path, DavBool copy);
156 char* create_tmp_download_path(
char *path);
157 void move_to_trash(SyncDirectory *dir,
char *path);
158
159 CxList* local_scan(SyncDirectory *dir, SyncDatabase *db);
160 CxList* read_changes(SyncDirectory *dir, SyncDatabase *db);
161 LocalResource* local_resource_new(SyncDirectory *dir, SyncDatabase *db,
char *path);
162 char* local_resource_path(LocalResource *res);
163 int local_resource_is_changed(
164 SyncDirectory *dir,
165 SyncDatabase *db,
166 LocalResource *res,
167 CxMap *svrres,
168 DavBool restore_deleted,
169 DavBool restore_modified);
170 int remote_resource_is_changed(
171 DavSession *sn,
172 SyncDirectory *dir,
173 SyncDatabase *db,
174 DavResource *remote,
175 LocalResource *res,
176 DavBool *equal);
177 int local_resource_load_metadata(SyncDirectory *dir, LocalResource *res);
178
179 void local_resource_set_etag(LocalResource *local,
const char *etag);
180
181 char* resource_local_path(DavResource *res);
182
183 size_t resource_get_blocksize(SyncDirectory *dir, LocalResource *local, DavResource *res,
off_t filesize);
184
185 int resource_pathlen_cmp(LocalResource *res1, LocalResource *res2,
void *n);
186 int resource_path_cmp(LocalResource *res1, LocalResource *res2,
void *n);
187
188 DavResource *versioning_simple_find(DavResource *res,
const char *version);
189 DavResource *versioning_deltav_find(DavResource *res,
const char *version);
190
191 int sync_set_status(DavResource *res,
char *status);
192 int sync_remove_status(DavResource *res);
193 CxBuffer* sync_get_file_tag_data(SyncDirectory *dir, LocalResource *res);
194 CxList* sync_get_file_tags(SyncDirectory *dir, LocalResource *res, DavBool *changed,
char **newhash);
195 int sync_tags_equal(CxList *tags1, CxList *tags2);
196 int sync_store_metadata(SyncDirectory *dir,
const char *path, LocalResource *local, DavResource *res);
197 int sync_store_xattr(SyncDirectory *dir,
const char *path, XAttributes *xattr);
198 int sync_store_tags(SyncDirectory *dir,
const char *path, LocalResource *local, DavResource *res);
199 int sync_store_tags_local(SyncDirectory *dir, LocalResource *local,
const char *path, CxList *tags);
200 int sync_put_resource(
201 SyncDirectory *dir,
202 DavResource *res,
203 LocalResource *local,
204 int *counter);
205 int sync_mkdir(SyncDirectory *dir, DavResource *res, LocalResource *local);
206 int sync_move_remote_resource(
207 SyncDirectory *dir,
208 SyncDatabase *db,
209 DavResource *origin,
210 LocalResource *local,
211 DavBool copy,
212 int *counter);
213 int sync_delete_remote_resource(SyncDirectory *dir, DavSession *sn, LocalResource *res,
int *counter, CxList *cols);
214 MetadataHashes sync_set_metadata_properties(
215 SyncDirectory *dir,
216 DavSession *sn,
217 DavResource *res,
218 LocalResource *local,
219 DavBool force);
220 int sync_update_metadata(
221 SyncDirectory *dir,
222 DavSession *sn,
223 DavResource *res,
224 LocalResource *local);
225
226 void update_parts(LocalResource *local, CxList *updates,
uint64_t numparts);
227
228 void remove_deleted_conflicts(SyncDirectory *dir, SyncDatabase *db);
229
230 int cmd_list_conflicts(CmdArgs *args);
231 int cmd_resolve_conflicts(CmdArgs *args);
232 int cmd_delete_conflicts(CmdArgs *args);
233
234 int cmd_list_versions(CmdArgs *args);
235
236 int cmd_trash_info(CmdArgs *args);
237 int cmd_empty_trash(CmdArgs *args);
238
239 int cmd_add_tag(CmdArgs *args);
240 int cmd_remove_tag(CmdArgs *args);
241 int cmd_set_tags(CmdArgs *args);
242 int cmd_list_tags(CmdArgs *args);
243 int cmd_tagop(CmdArgs *args,
int cmd);
244
245
246
247
248
249
250
251
252
253
254
255
256 int sync_get_file(CmdArgs *args,
const char *path, SyncFile *f, DavBool dostat);
257 void sync_print_get_file_err(
const char *path,
int err);
258
259 int isfileindir(SyncDirectory *dir,
const char *path, SyncFile *f);
260
261 int cmd_add_directory(CmdArgs *args);
262 int cmd_list_dirs();
263 int cmd_check_repositories(CmdArgs *args);
264
265 char* create_locktoken_file(
const char *syncdirname,
const char *locktoken);
266
267
268
269
270
271 char* sync_get_content_hash(DavResource *res);
272
273
274
275
276
277
278
279 void sync_set_content_hash(DavResource *res,
const unsigned char *hashdata);
280
281 #ifdef __cplusplus
282 }
283 #endif
284
285 #endif
286
287