Tue, 09 Apr 2019 18:23:23 +0200
fixes missing return in copy_file()
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
364
3769ba002fd1
updates copyright date
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
363
diff
changeset
|
4 | * Copyright 2018 Olaf Wintermann. All rights reserved. |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include <stdio.h> |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #include <stdlib.h> |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include <string.h> |
65
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
32 | #include <errno.h> |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include <libidav/utils.h> |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include <ucx/map.h> |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
35 | #include <ucx/utils.h> |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #include "scfg.h" |
319
2433b5969d44
disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
316
diff
changeset
|
38 | #include "config.h" |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b) |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
42 | |
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
43 | #define print_error(lineno, ...) \ |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
44 | do {\ |
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
45 | fprintf(stderr, "Error (sync.xml line %u): ", lineno); \ |
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
46 | fprintf(stderr, __VA_ARGS__); \ |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
47 | fprintf(stderr, "Abort.\n"); \ |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
48 | } while(0); |
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
49 | #define print_warning(lineno, ...) \ |
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
50 | do {\ |
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
51 | fprintf(stderr, "Warning (sync.xml line %u): ", lineno); \ |
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
52 | fprintf(stderr, __VA_ARGS__); \ |
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
53 | } while(0); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
54 | |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | #ifdef _WIN32 |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | #define ENV_HOME getenv("USERPROFILE") |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | #else |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | #define ENV_HOME getenv("HOME") |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | #endif /* _WIN32 */ |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | static UcxMap *directories; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
63 | UcxMapIterator scfg_directory_iterator() { |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
64 | return ucx_map_iterator(directories); |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
65 | } |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
66 | |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
67 | static int create_default_sync_config(char *file) { |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
68 | FILE *out = fopen(file, "w"); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
69 | if(!out) { |
253
1d2be1b31e70
There has never been deliberately fucked up error handling for missing sync.xml.
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
70 | perror("Cannot create config file"); |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
71 | return -1; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
72 | } |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
73 | |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
74 | fputs("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n", out); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
75 | fputs("<configuration>\n", out); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
76 | fputs("</configuration>\n", out); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
77 | fclose(out); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
78 | |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
79 | return 0; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
80 | } |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
81 | |
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
82 | static UcxList* add_regex_pattern(UcxList *list, char *value, |
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
83 | unsigned short xmlline) { |
58
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
84 | regex_t *regex = malloc(sizeof(regex_t)); |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
85 | if (regcomp(regex, value, REG_EXTENDED|REG_NOSUB)) { |
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
86 | print_warning(xmlline, |
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
87 | "Invalid regular expression (%s) ... skipped\n", value); |
288
cd3846cc8b25
fixes memory leaks detected by cppcheck (or annotates them at least)
Mike Becker <universe@uap-core.de>
parents:
256
diff
changeset
|
88 | free(regex); |
58
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
89 | return list; |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
90 | } else { |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
91 | return ucx_list_append(list, regex); |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
92 | } |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
93 | } |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
94 | |
401
3bb3210f3e6e
adds syncdir config element for tag filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
95 | static int scfg_load_filter( |
3bb3210f3e6e
adds syncdir config element for tag filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
96 | xmlNode *node, |
3bb3210f3e6e
adds syncdir config element for tag filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
97 | UcxList **include, |
3bb3210f3e6e
adds syncdir config element for tag filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
98 | UcxList **exclude, |
417
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
99 | UcxList **tags) |
401
3bb3210f3e6e
adds syncdir config element for tag filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
100 | { |
244
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
101 | node = node->children; |
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
102 | |
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
103 | while(node) { |
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
104 | if(node->type == XML_ELEMENT_NODE) { |
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
105 | char *value = util_xml_get_text(node); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
106 | if(xstreq(node->name, "include")) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
107 | if(value) { |
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
108 | *include = add_regex_pattern(*include, value, node->line); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
109 | } |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
110 | } else if(xstreq(node->name, "exclude")) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
111 | if(value) { |
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
112 | *exclude = add_regex_pattern(*exclude, value, node->line); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
113 | } |
401
3bb3210f3e6e
adds syncdir config element for tag filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
114 | } else if(xstreq(node->name, "tags")) { |
3bb3210f3e6e
adds syncdir config element for tag filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
115 | if(value) { |
417
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
116 | SyncTagFilter *tagfilter = parse_tagfilter_string( |
414
ea50585ec9d9
adds tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
117 | value, DAV_SYNC_TAGFILTER_SCOPE_RESOURCE); |
417
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
118 | if(!tagfilter) { |
401
3bb3210f3e6e
adds syncdir config element for tag filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
119 | print_error( |
3bb3210f3e6e
adds syncdir config element for tag filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
120 | node->line, |
3bb3210f3e6e
adds syncdir config element for tag filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
121 | "malformed tag filter: %s\n", |
3bb3210f3e6e
adds syncdir config element for tag filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
122 | value); |
3bb3210f3e6e
adds syncdir config element for tag filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
123 | return 1; |
416
d7a086201a6e
adds attribute for tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
124 | } else { |
d7a086201a6e
adds attribute for tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
125 | // get scope |
425
ae4d89c3477c
fixes dav list return value
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
126 | xmlChar *scope = xmlGetNoNsProp(node, BAD_CAST "scope"); |
416
d7a086201a6e
adds attribute for tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
127 | if(scope) { |
d7a086201a6e
adds attribute for tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
128 | if(xstreq(scope, "resource")) |
d7a086201a6e
adds attribute for tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
129 | { |
417
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
130 | tagfilter->scope = |
416
d7a086201a6e
adds attribute for tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
131 | DAV_SYNC_TAGFILTER_SCOPE_RESOURCE; |
d7a086201a6e
adds attribute for tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
132 | } else if(xstreq(scope, "collection")) { |
417
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
133 | tagfilter->scope = |
416
d7a086201a6e
adds attribute for tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
134 | DAV_SYNC_TAGFILTER_SCOPE_COLLECTION; |
d7a086201a6e
adds attribute for tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
135 | } else if(xstreq(scope, "all")) { |
417
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
136 | tagfilter->scope = |
416
d7a086201a6e
adds attribute for tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
137 | DAV_SYNC_TAGFILTER_SCOPE_RESOURCE |
d7a086201a6e
adds attribute for tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
138 | | DAV_SYNC_TAGFILTER_SCOPE_COLLECTION; |
417
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
139 | } else { |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
140 | tagfilter->scope = |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
141 | DAV_SYNC_TAGFILTER_SCOPE_RESOURCE; |
416
d7a086201a6e
adds attribute for tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
142 | } |
d7a086201a6e
adds attribute for tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
143 | } |
d7a086201a6e
adds attribute for tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
144 | xmlFree(scope); |
417
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
145 | |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
146 | *tags = ucx_list_append(*tags, tagfilter); |
401
3bb3210f3e6e
adds syncdir config element for tag filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
147 | } |
3bb3210f3e6e
adds syncdir config element for tag filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
148 | } |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
149 | } else { |
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
150 | print_error(node->line, |
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
151 | "unknown filter config element: %s\n", node->name); |
244
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
152 | return 1; |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
153 | } |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
154 | if(!value) { |
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
155 | print_error(node->line, |
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
156 | "missing value for filter: %s\n", node->name); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
157 | return 1; |
244
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
158 | } |
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
159 | } |
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
160 | |
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
161 | node = node->next; |
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
162 | } |
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
163 | |
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
164 | return 0; |
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
165 | } |
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
166 | |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
167 | static TagFormat str2tagformat(const char *str) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
168 | if(!strcmp(str, "text")) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
169 | return TAG_FORMAT_TEXT; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
170 | } else if(!strcmp(str, "csv")) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
171 | return TAG_FORMAT_CSV; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
172 | } else if(!strcmp(str, "xml")) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
173 | return TAG_FORMAT_XML; |
363
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
174 | } else if(!strcmp(str, "macos")) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
175 | return TAG_FORMAT_MACOS; |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
176 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
177 | return TAG_FORMAT_UNKNOWN; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
178 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
179 | |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
180 | #define CHECK_VALUE(element, value) if(!(value)) \ |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
181 | print_error(element->line, "missing value element: %s\n", element->name); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
182 | |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
183 | static TagConfig* parse_tagconfig(xmlNode *node) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
184 | TagConfig conf; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
185 | conf.store = TAG_STORE_XATTR; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
186 | conf.local_format = TAG_FORMAT_TEXT; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
187 | conf.server_format = TAG_FORMAT_XML; |
368
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
188 | conf.xattr_name = NULL; |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
189 | conf.detect_changes = false; |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
190 | conf.conflict = TAG_NO_CONFLICT; |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
191 | xmlNode *c = node->children; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
192 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
193 | // TODO: error handling |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
194 | while(c) { |
367
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
195 | if(c->type == XML_ELEMENT_NODE) { |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
196 | char *value = util_xml_get_text(c); |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
197 | if(xstreq(c->name, "local-store")) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
198 | CHECK_VALUE(c, value); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
199 | if(xstreq(value, "xattr")) { |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
200 | conf.store = TAG_STORE_XATTR; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
201 | } else { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
202 | return NULL; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
203 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
204 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
205 | xmlAttr *attr = c->properties; |
425
ae4d89c3477c
fixes dav list return value
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
206 | xmlChar *format = xmlGetNoNsProp(node, BAD_CAST "format"); |
416
d7a086201a6e
adds attribute for tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
207 | if(format) { |
425
ae4d89c3477c
fixes dav list return value
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
208 | conf.local_format = str2tagformat((char*)format); |
416
d7a086201a6e
adds attribute for tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
209 | xmlFree(format); |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
210 | } |
368
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
211 | } else if(xstreq(c->name, "detect-changes")) { |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
212 | CHECK_VALUE(c, value); |
368
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
213 | conf.detect_changes = util_getboolean(value); |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
214 | } else if(xstreq(c->name, "xattr-name")) { |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
215 | if(!value) { |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
216 | return NULL; |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
217 | } |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
218 | conf.xattr_name = strdup(value); |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
219 | } else if(xstreq(c->name, "on-conflict")) { |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
220 | CHECK_VALUE(c, value); |
368
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
221 | if(xstreq(value, "no_conflict")) { |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
222 | conf.conflict = TAG_NO_CONFLICT; |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
223 | } else if(xstreq(value, "keep_local")) { |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
224 | conf.conflict = TAG_KEEP_LOCAL; |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
225 | } else if(xstreq(value, "keep_remote")) { |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
226 | conf.conflict = TAG_KEEP_REMOTE; |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
227 | } else if(xstreq(value, "merge")) { |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
228 | conf.conflict = TAG_MERGE; |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
229 | } else { |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
230 | fprintf(stderr, "on-conflict: unknown value: %s\n", value); |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
231 | return NULL; |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
232 | } |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
233 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
234 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
235 | c = c->next; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
236 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
237 | |
368
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
238 | if(conf.store == TAG_STORE_XATTR && !conf.xattr_name) { |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
239 | switch(conf.local_format) { |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
240 | default: |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
241 | case TAG_FORMAT_TEXT: |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
242 | case TAG_FORMAT_CSV: |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
243 | case TAG_FORMAT_XML: conf.xattr_name = strdup(DEFAULT_TAG_XATTR); break; |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
244 | case TAG_FORMAT_MACOS: conf.xattr_name = strdup(MACOS_TAG_XATTR); break; |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
245 | } |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
246 | } |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
247 | |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
248 | TagConfig *tagconfig = malloc(sizeof(TagConfig)); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
249 | *tagconfig = conf; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
250 | return tagconfig; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
251 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
252 | |
534
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
253 | static SplitConfig* parse_split(xmlNode *node) { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
254 | char *pattern = NULL; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
255 | char *minsize = NULL; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
256 | char *blocksize = NULL; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
257 | |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
258 | xmlNode *c = node->children; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
259 | while(c) { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
260 | char *value = util_xml_get_text(c); |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
261 | if(xstreq(c->name, "pattern")) { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
262 | pattern = value; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
263 | } else if(xstreq(c->name, "minsize")) { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
264 | minsize = value; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
265 | } else if(xstreq(c->name, "blocksize")) { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
266 | blocksize = value; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
267 | } |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
268 | c = c->next; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
269 | } |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
270 | |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
271 | uint64_t sz = 0; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
272 | if(!blocksize) { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
273 | fprintf(stderr, "splitconfig: no blocksize specified\n"); |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
274 | return NULL; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
275 | } |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
276 | size_t bsz_len = strlen(blocksize); |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
277 | if(bsz_len < 2) { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
278 | fprintf(stderr, "splitconfig: blocksize too small\n"); |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
279 | return NULL; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
280 | } |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
281 | |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
282 | if(!util_szstrtouint(blocksize, &sz)) { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
283 | fprintf(stderr, "splitconfig: blocksize is not a number\n"); |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
284 | return NULL; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
285 | } |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
286 | |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
287 | if(!pattern && !minsize) { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
288 | fprintf(stderr, "splitconfig: pattern or minsize must be specified\n"); |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
289 | return NULL; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
290 | } |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
291 | |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
292 | int64_t minsz = -1; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
293 | if(minsize) { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
294 | uint64_t m; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
295 | if(!util_szstrtouint(minsize, &m)) { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
296 | fprintf(stderr, "splitconfig: minsize is not a number\n"); |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
297 | return NULL; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
298 | } |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
299 | minsz = (int64_t)m; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
300 | } |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
301 | |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
302 | SplitConfig *sc = calloc(1, sizeof(SplitConfig)); |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
534
diff
changeset
|
303 | if(pattern) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
534
diff
changeset
|
304 | regex_t *regex = malloc(sizeof(regex_t)); |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
534
diff
changeset
|
305 | if (regcomp(regex, pattern, REG_EXTENDED|REG_NOSUB)) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
534
diff
changeset
|
306 | fprintf(stderr, "Invalid regular expression (%s)\n", pattern); |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
534
diff
changeset
|
307 | } else { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
534
diff
changeset
|
308 | sc->pattern = regex; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
534
diff
changeset
|
309 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
534
diff
changeset
|
310 | } |
534
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
311 | sc->minsize = minsz; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
312 | sc->blocksize = (size_t)sz; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
313 | return sc; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
314 | } |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
315 | |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
316 | static UcxList* parse_splitconfig(xmlNode *node, int *error) { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
317 | UcxList *splitconfig = NULL; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
318 | int err = 0; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
319 | xmlNode *c = node->children; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
320 | while(c) { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
321 | if(c->type == XML_ELEMENT_NODE && xstreq(c->name, "split")) { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
322 | SplitConfig *sc = parse_split(c); |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
323 | if(sc) { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
324 | splitconfig = ucx_list_append(splitconfig, sc); |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
325 | } else { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
326 | err = 1; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
327 | break; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
328 | } |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
329 | } |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
330 | c = c->next; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
331 | } |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
332 | |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
333 | if(error) { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
334 | *error = err; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
335 | } |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
336 | return splitconfig; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
337 | } |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
338 | |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
339 | static Versioning* parse_versioning_config(xmlNode *node) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
340 | Versioning v; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
341 | v.always = FALSE; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
342 | v.type = VERSIONING_SIMPLE; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
343 | v.collection = "/.dav-version-history"; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
344 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
345 | xmlNode *c = node->children; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
346 | while(c) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
347 | if(c->type == XML_ELEMENT_NODE) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
348 | char *value = util_xml_get_text(c); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
349 | if(xstreq(c->name, "type")) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
350 | CHECK_VALUE(c, value); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
351 | if(!strcmp(value, "simple")) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
352 | v.type = VERSIONING_SIMPLE; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
353 | } else if(!strcmp(value, "deltav")) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
354 | v.type = VERSIONING_DELTAV; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
355 | } else { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
356 | return NULL; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
357 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
358 | } else if(xstreq(c->name, "collection")) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
359 | CHECK_VALUE(c, value); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
360 | v.collection = value; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
361 | } else if(xstreq(c->name, "always")) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
362 | CHECK_VALUE(c, value); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
363 | v.always = util_getboolean(value); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
364 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
365 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
366 | c = c->next; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
367 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
368 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
369 | v.collection = strdup(v.collection); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
370 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
371 | Versioning *versioning = malloc(sizeof(Versioning)); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
372 | *versioning = v; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
373 | return versioning; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
374 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
375 | |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
376 | static int scfg_load_directory(xmlNode *node) { |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
377 | char *name = NULL; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
378 | char *path = NULL; |
65
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
379 | char *trash = NULL; |
56
99f7816fcf01
added collection config for sync directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
380 | char *collection = NULL; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
381 | char *repository = NULL; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
382 | char *database = NULL; |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
383 | TagConfig *tagconfig = NULL; |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
384 | Versioning *versioning = NULL; |
58
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
385 | UcxList *include = NULL; |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
386 | UcxList *exclude = NULL; |
417
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
387 | UcxList *tagfilter = NULL; |
534
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
388 | UcxList *splitconfig = NULL; |
244
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
389 | int max_retry = 0; |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
426
diff
changeset
|
390 | int allow_cmd = SYNC_CMD_PULL | SYNC_CMD_PUSH |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
426
diff
changeset
|
391 | | SYNC_CMD_ARCHIVE | SYNC_CMD_RESTORE; |
145
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
392 | bool backuppull = false; |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
393 | bool lockpull = false; |
232
df3fa8637a58
disabled locking in dav-sync by default
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
226
diff
changeset
|
394 | bool lockpush = false; |
549
af91d3c96994
add hashing config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
395 | bool hashing = false; |
af91d3c96994
add hashing config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
396 | bool detect_copy = false; |
316
9d0505d80044
adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
288
diff
changeset
|
397 | time_t lock_timeout = 0; |
522
46f96dcd6eab
adds metadata config element for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
521
diff
changeset
|
398 | uint32_t metadata = 0; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
399 | |
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
400 | unsigned short parentlineno = node->line; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
401 | node = node->children; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
402 | while(node) { |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
403 | if(node->type == XML_ELEMENT_NODE) { |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
404 | char *value = util_xml_get_text(node); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
405 | /* every key needs a value */ |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
406 | if(!value) { |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
407 | /* TODO: maybe this should only be reported, if the key is valid |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
408 | * But this makes the code very ugly. |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
409 | */ |
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
410 | print_error(node->line, |
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
411 | "missing value for directory element: %s\n", |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
412 | node->name); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
413 | return 1; |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
414 | } |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
415 | if(xstreq(node->name, "name")) { |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
416 | name = value; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
417 | } else if(xstreq(node->name, "path")) { |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
418 | path = value; |
65
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
419 | } else if(xstreq(node->name, "trash")) { |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
420 | trash = value; |
56
99f7816fcf01
added collection config for sync directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
421 | } else if(xstreq(node->name, "collection")) { |
99f7816fcf01
added collection config for sync directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
422 | collection = value; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
423 | } else if(xstreq(node->name, "repository")) { |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
424 | repository = value; |
244
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
425 | } else if(xstreq(node->name, "filter")) { |
401
3bb3210f3e6e
adds syncdir config element for tag filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
426 | if(scfg_load_filter(node, &include, &exclude, &tagfilter)) { |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
427 | return 1; |
244
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
428 | } |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
429 | } else if(xstreq(node->name, "database")) { |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
430 | database = value; |
426
9cec06cfeade
renames <tags> element to <tagconfig>
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
431 | } else if(xstreq(node->name, "tagconfig")) { |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
432 | tagconfig = parse_tagconfig(node); |
534
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
433 | } else if(xstreq(node->name, "splitconfig")) { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
434 | int err = 0; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
435 | splitconfig = parse_splitconfig(node, &err); |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
436 | if(err) { |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
437 | return 1; |
9a4857d6444e
adds dav-sync splitconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
438 | } |
522
46f96dcd6eab
adds metadata config element for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
521
diff
changeset
|
439 | } else if(xstreq(node->name, "metadata")) { |
46f96dcd6eab
adds metadata config element for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
521
diff
changeset
|
440 | char *error = NULL; |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
523
diff
changeset
|
441 | metadata = parse_finfo_settings(value, &error); |
522
46f96dcd6eab
adds metadata config element for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
521
diff
changeset
|
442 | if(error) { |
46f96dcd6eab
adds metadata config element for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
521
diff
changeset
|
443 | print_error(node->line, "unknown metadata: %s\n", error); |
46f96dcd6eab
adds metadata config element for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
521
diff
changeset
|
444 | free(error); |
46f96dcd6eab
adds metadata config element for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
521
diff
changeset
|
445 | } |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
446 | } else if(xstreq(node->name, "versioning")) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
447 | versioning = parse_versioning_config(node); |
145
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
448 | } else if(xstreq(node->name, "max-retry")) { |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
449 | int64_t i; |
244
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
450 | if(util_strtoint(value, &i) && i >= 0) { |
145
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
451 | max_retry = (int)i; |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
452 | } else { |
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
453 | print_warning(node->line, "unsigned integer value " |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
454 | "expected in <max-retry> element\n"); |
145
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
455 | } |
347
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
456 | } else if(xstreq(node->name, "allow-cmd")) { |
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
457 | int cmds = 0; |
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
458 | const char *delims = " ,\r\n"; |
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
459 | char *cmdstr = strdup(value); |
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
460 | char *cmd = strtok(cmdstr, delims); |
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
461 | while(cmd) { |
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
462 | if(!strcmp(cmd, "pull")) { |
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
463 | cmds |= SYNC_CMD_PULL; |
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
464 | } else if(!strcmp(cmd, "push")) { |
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
465 | cmds |= SYNC_CMD_PUSH; |
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
466 | } else if(!strcmp(cmd, "archive")) { |
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
467 | cmds |= SYNC_CMD_ARCHIVE; |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
426
diff
changeset
|
468 | } else if(!strcmp(cmd, "restore")) { |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
426
diff
changeset
|
469 | cmds |= SYNC_CMD_RESTORE; |
347
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
470 | } |
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
471 | cmd = strtok(NULL, delims); |
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
472 | } |
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
473 | free(cmdstr); |
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
474 | allow_cmd = cmds; |
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
475 | |
145
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
476 | } else if(xstreq(node->name, "backup-on-pull")) { |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
477 | backuppull = util_getboolean(value); |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
478 | } else if(xstreq(node->name, "lock-pull")) { |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
479 | lockpull = util_getboolean(value); |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
480 | } else if(xstreq(node->name, "lock-push")) { |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
481 | lockpush = util_getboolean(value); |
316
9d0505d80044
adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
288
diff
changeset
|
482 | } else if(xstreq(node->name, "lock-timeout")) { |
9d0505d80044
adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
288
diff
changeset
|
483 | int64_t t = 0; |
9d0505d80044
adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
288
diff
changeset
|
484 | if(util_strtoint(value, &t)) { |
9d0505d80044
adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
288
diff
changeset
|
485 | lock_timeout = (time_t)t; |
9d0505d80044
adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
288
diff
changeset
|
486 | } else { |
9d0505d80044
adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
288
diff
changeset
|
487 | print_warning(node->line, "integer value " |
9d0505d80044
adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
288
diff
changeset
|
488 | "expected in <lock-timeout> element\n"); |
9d0505d80044
adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
288
diff
changeset
|
489 | } |
549
af91d3c96994
add hashing config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
490 | } else if(xstreq(node->name, "hashing")) { |
af91d3c96994
add hashing config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
491 | hashing = util_getboolean(value); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
492 | } else { |
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
493 | print_error(node->line, |
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
494 | "unknown directory config element: %s\n", node->name); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
495 | return 1; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
496 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
497 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
498 | node = node->next; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
499 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
500 | |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
501 | if(!name) { |
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
502 | print_error(parentlineno, "missing name element for directory\n"); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
503 | return 1; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
504 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
505 | if(!path) { |
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
506 | print_error(parentlineno, |
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
507 | "missing path element for directory %s\n", name); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
508 | return 1; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
509 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
510 | if(!repository) { |
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
511 | print_error(parentlineno, |
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
512 | "missing repository element for directory %s\n", name); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
513 | return 1; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
514 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
515 | if(!database) { |
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
516 | print_error(parentlineno, |
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
253
diff
changeset
|
517 | "missing database element for directory %s\n", name); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
518 | return 1; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
519 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
520 | |
521
c5bbae4b3cca
extends sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
491
diff
changeset
|
521 | SyncDirectory *dir = calloc(1, sizeof(SyncDirectory)); |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
522 | dir->name = strdup(name); |
226
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
523 | dir->path = scfg_create_path(path); |
56
99f7816fcf01
added collection config for sync directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
524 | dir->collection = collection ? strdup(collection) : NULL; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
525 | dir->repository = strdup(repository); |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
526 | dir->database = strdup(database); |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
527 | dir->tagconfig = tagconfig; |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
528 | dir->versioning = versioning; |
145
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
529 | dir->max_retry = max_retry; |
347
b6ff6be7aa91
adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
319
diff
changeset
|
530 | dir->allow_cmd = allow_cmd; |
145
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
531 | dir->backuppull = backuppull; |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
532 | dir->lockpull = lockpull; |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
533 | dir->lockpush = lockpush; |
549
af91d3c96994
add hashing config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
534 | dir->hashing = hashing; |
316
9d0505d80044
adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
288
diff
changeset
|
535 | dir->lock_timeout = lock_timeout; |
522
46f96dcd6eab
adds metadata config element for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
521
diff
changeset
|
536 | dir->metadata = metadata; |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
534
diff
changeset
|
537 | dir->splitconfig = splitconfig; |
539
8deb52292c99
fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
536
diff
changeset
|
538 | if((metadata & FINFO_MODE) == FINFO_MODE) { |
522
46f96dcd6eab
adds metadata config element for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
521
diff
changeset
|
539 | dir->db_settings = DB_STORE_MODE; |
46f96dcd6eab
adds metadata config element for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
521
diff
changeset
|
540 | } |
539
8deb52292c99
fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
536
diff
changeset
|
541 | if((metadata & FINFO_OWNER) == FINFO_OWNER) { |
522
46f96dcd6eab
adds metadata config element for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
521
diff
changeset
|
542 | dir->db_settings |= DB_STORE_OWNER; |
46f96dcd6eab
adds metadata config element for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
521
diff
changeset
|
543 | } |
46f96dcd6eab
adds metadata config element for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
521
diff
changeset
|
544 | |
58
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
545 | if (include) { |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
546 | dir->include = include; |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
547 | } else { |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
548 | regex_t *matchall = malloc(sizeof(regex_t)); |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
549 | regcomp(matchall, ".*", REG_NOSUB); |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
550 | dir->include = ucx_list_append(NULL, matchall); |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
551 | } |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
552 | if (exclude) { |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
553 | dir->exclude = exclude; |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
554 | } else { |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
555 | regex_t *matchnothing = malloc(sizeof(regex_t)); |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
556 | regcomp(matchnothing, "///", REG_NOSUB); |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
557 | dir->exclude = ucx_list_append(NULL, matchnothing); |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
558 | } |
402
babdf40dd22c
dav-sync pull applies config tag filter now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
559 | dir->tagfilter = tagfilter; |
66 | 560 | |
561 | if (trash && sstrtrim(sstr(trash)).length > 0) { | |
226
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
562 | if (trash[0] == '/' || trash[0] == '$') { |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
563 | dir->trash = scfg_create_path(trash); |
65
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
564 | } else { |
226
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
565 | char *t = util_concat_path(dir->path, trash); |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
566 | dir->trash = util_concat_path(t, "/"); |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
567 | free(t); |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
568 | } |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
569 | |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
570 | if(dir->trash[strlen(dir->trash)-1] != '/') { |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
571 | char *t = dir->trash; |
65
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
572 | dir->trash = util_concat_path(t, "/"); |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
573 | free(t); |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
574 | } |
66 | 575 | } else { |
576 | dir->trash = NULL; | |
65
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
577 | } |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
578 | |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
579 | ucx_map_cstr_put(directories, name, dir); |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
580 | |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
581 | return 0; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
582 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
583 | |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
584 | int load_sync_config() { |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
585 | directories = ucx_map_new(8); |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
586 | |
319
2433b5969d44
disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
316
diff
changeset
|
587 | if(check_config_dir()) { |
2433b5969d44
disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
316
diff
changeset
|
588 | fprintf(stderr, "Cannot create .dav directory\n"); |
2433b5969d44
disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
316
diff
changeset
|
589 | return 1; |
2433b5969d44
disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
316
diff
changeset
|
590 | } |
2433b5969d44
disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
316
diff
changeset
|
591 | |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
592 | char *file = util_concat_path(ENV_HOME, ".dav/sync.xml"); |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
593 | |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
594 | struct stat s; |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
595 | if(stat(file, &s)) { |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
596 | switch(errno) { |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
597 | case ENOENT: { |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
598 | if(create_default_sync_config(file)) { |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
599 | return 1; |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
600 | } |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
601 | break; |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
602 | } |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
603 | default: { |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
604 | perror("Cannot load sync.xml"); |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
605 | } |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
606 | } |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
607 | free(file); |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
608 | return 0; |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
609 | } |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
610 | |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
611 | xmlDoc *doc = xmlReadFile(file, NULL, 0); |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
612 | if(!doc) { |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
613 | fprintf(stderr, "Cannot load sync.xml\n"); |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
614 | free(file); |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
615 | return -1; |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
616 | } |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
617 | |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
618 | int ret = 0; |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
619 | xmlNode *node = xmlDocGetRootElement(doc)->children; |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
620 | while(node && !ret) { |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
621 | if(node->type == XML_ELEMENT_NODE) { |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
622 | if(xstreq(node->name, "directory")) { |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
623 | ret = scfg_load_directory(node); |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
624 | } else { |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
625 | print_error(node->line, |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
626 | "unknown config element: %s\n", node->name); |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
627 | ret = 1; |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
628 | } |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
629 | } |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
630 | node = node->next; |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
631 | } |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
632 | |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
633 | xmlFreeDoc(doc); |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
634 | free(file); |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
635 | return ret; |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
636 | } |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
637 | |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
638 | SyncDirectory* scfg_get_dir(char *name) { |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
639 | return ucx_map_cstr_get(directories, name); |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
640 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
641 | |
233
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
642 | int scfg_check_dir(SyncDirectory *dir) { |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
643 | struct stat s; |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
644 | if(stat(dir->path, &s)) { |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
645 | int err = errno; |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
646 | if(err == ENOENT) { |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
647 | fprintf(stderr, "directory %s does not exist.\n", dir->path); |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
648 | } else { |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
649 | fprintf(stderr, "Cannot stat directory %s.\n", dir->path); |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
650 | perror(NULL); |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
651 | } |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
652 | fprintf(stderr, "Abort.\n"); |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
653 | return -1; |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
654 | } |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
655 | |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
656 | if(dir->trash) { |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
657 | // create trash directory |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
658 | mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
659 | if (util_mkdir(dir->trash, mode)) { |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
660 | if (errno != EEXIST) { |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
661 | fprintf(stderr, "Cannot create trash directory: %s\nAbort.\n", dir->trash); |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
662 | return -1; |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
663 | } |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
664 | } |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
665 | } |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
666 | |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
667 | return 0; |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
668 | } |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
232
diff
changeset
|
669 | |
226
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
670 | char* scfg_create_path(char *cfg) { |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
671 | if(!cfg) { |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
672 | return NULL; |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
673 | } |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
674 | if(cfg[0] != '$') { |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
675 | return strdup(cfg); |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
676 | } |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
677 | |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
678 | sstr_t s = sstr(cfg); |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
679 | sstr_t path = sstrchr(sstr(cfg), '/'); |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
680 | char *localpath = NULL; |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
681 | if(path.length > 0) { |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
682 | // path = $var/path/ |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
683 | |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
684 | sstr_t var = sstrsubsl(s, 1, path.ptr - s.ptr - 1); |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
685 | if(var.length > 0) { |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
686 | char *env = sstrdup(var).ptr; |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
687 | char *envval = getenv(env); |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
688 | free(env); |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
689 | if(envval) { |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
690 | localpath = util_concat_path(envval, path.ptr); |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
691 | } else { |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
692 | fprintf( |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
693 | stderr, |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
694 | "Environment variable %.*s not set.\nAbort.\n", |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
695 | (int)var.length, |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
696 | var.ptr); |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
697 | exit(-1); |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
698 | } |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
699 | } else { |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
700 | localpath = sstrdup(path).ptr; |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
701 | } |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
702 | } else { |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
703 | // path = $var |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
704 | char *envval = getenv(cfg + 1); |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
705 | if(envval) { |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
706 | localpath = strdup(envval); |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
707 | } else { |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
708 | fprintf( |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
709 | stderr, |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
710 | "Environment variable %s not set.\nAbort.\n", |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
711 | cfg); |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
712 | exit(-1); |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
713 | } |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
714 | } |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
715 | return localpath; |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
716 | } |
acc997e0d0f9
added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
717 | |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
718 | |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
719 | int add_directory(SyncDirectory *dir) { |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
720 | char *file = util_concat_path(ENV_HOME, ".dav/sync.xml"); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
721 | xmlDoc *doc = xmlReadFile(file, NULL, 0); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
722 | if(!doc) { |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
723 | free(file); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
724 | fprintf(stderr, "Cannot load config.xml\n"); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
725 | return 1; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
726 | } |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
727 | |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
728 | xmlNode *root = xmlDocGetRootElement(doc); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
729 | |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
730 | xmlNode *dirNode = xmlNewNode(NULL, BAD_CAST "directory"); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
731 | xmlNodeAddContent(dirNode, BAD_CAST "\n\t\t"); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
732 | |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
733 | xmlNewTextChild(dirNode, NULL, BAD_CAST "name", BAD_CAST dir->name); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
734 | xmlNodeAddContent(dirNode, BAD_CAST "\n\t\t"); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
735 | |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
736 | xmlNewTextChild(dirNode, NULL, BAD_CAST "path", BAD_CAST dir->path); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
737 | xmlNodeAddContent(dirNode, BAD_CAST "\n\t\t"); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
738 | |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
739 | xmlNewTextChild(dirNode, NULL, BAD_CAST "repository", BAD_CAST dir->repository); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
740 | xmlNodeAddContent(dirNode, BAD_CAST "\n\t\t"); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
741 | |
203
9a93ebd71984
fixed add-directory command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
202
diff
changeset
|
742 | xmlNewTextChild(dirNode, NULL, BAD_CAST "collection", BAD_CAST dir->collection); |
9a93ebd71984
fixed add-directory command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
202
diff
changeset
|
743 | xmlNodeAddContent(dirNode, BAD_CAST "\n\t\t"); |
9a93ebd71984
fixed add-directory command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
202
diff
changeset
|
744 | |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
745 | if(dir->trash) { |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
746 | xmlNewTextChild(dirNode, NULL, BAD_CAST "trash", BAD_CAST dir->trash); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
747 | xmlNodeAddContent(dirNode, BAD_CAST "\n\t\t"); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
748 | } |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
749 | xmlNewTextChild(dirNode, NULL, BAD_CAST "database", BAD_CAST dir->database); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
750 | xmlNodeAddContent(dirNode, BAD_CAST "\n\t"); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
751 | |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
752 | xmlNodeAddContent(root, BAD_CAST "\n\t"); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
753 | xmlAddChild(root, dirNode); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
754 | xmlNodeAddContent(root, BAD_CAST "\n"); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
755 | |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
756 | int ret = 0; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
757 | if(xmlSaveFormatFileEnc(file, doc, "UTF-8", 1) == -1) { |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
758 | ret = 1; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
759 | } |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
760 | xmlFreeDoc(doc); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
761 | free(file); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
762 | |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
763 | return ret; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
764 | } |
198
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
765 | |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
766 | char* generate_db_name(char *basename) { |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
767 | char *dbname = NULL; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
768 | int count = -1; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
769 | while(!dbname) { |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
770 | sstr_t name = count < 0 ? |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
771 | ucx_sprintf("%s-db.xml", basename) : |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
772 | ucx_sprintf("%s%d-db.xml", basename, count); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
773 | count++; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
774 | |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
775 | UcxMapIterator i = ucx_map_iterator(directories); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
776 | SyncDirectory *dir; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
777 | bool unique = true; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
778 | UCX_MAP_FOREACH(key, dir, i) { |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
779 | if(!sstrcmp(name, sstr(dir->database))) { |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
780 | unique = false; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
781 | break; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
782 | } |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
783 | } |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
784 | if(unique) { |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
785 | dbname = name.ptr; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
786 | break; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
787 | } |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
788 | } |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
789 | return dbname; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
790 | } |
224
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
222
diff
changeset
|
791 | |
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
222
diff
changeset
|
792 | |
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
222
diff
changeset
|
793 | void free_sync_config() { |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
794 | if(directories) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
795 | UcxMapIterator i = ucx_map_iterator(directories); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
796 | SyncDirectory *dir; |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
797 | UCX_MAP_FOREACH(elm, dir, i) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
798 | free(dir->name); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
799 | free(dir->path); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
800 | free(dir->repository); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
801 | free(dir->database); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
802 | |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
803 | if(dir->collection) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
804 | free(dir->collection); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
805 | } |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
806 | if(dir->trash) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
807 | free(dir->trash); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
808 | } |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
809 | |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
810 | UCX_FOREACH(elm, dir->include) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
811 | regfree(elm->data); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
812 | free(elm->data); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
813 | } |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
814 | ucx_list_free(dir->include); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
815 | UCX_FOREACH(elm, dir->exclude) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
816 | regfree(elm->data); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
817 | free(elm->data); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
818 | } |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
819 | ucx_list_free(dir->exclude); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
820 | |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
821 | free(dir); |
224
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
222
diff
changeset
|
822 | } |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
823 | |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
246
diff
changeset
|
824 | ucx_map_free(directories); |
224
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
222
diff
changeset
|
825 | } |
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
222
diff
changeset
|
826 | } |