dav/scfg.c

Wed, 13 Mar 2019 15:05:40 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 13 Mar 2019 15:05:40 +0100
changeset 521
c5bbae4b3cca
parent 491
fdc2fb090cc7
child 522
46f96dcd6eab
permissions
-rw-r--r--

extends sync db

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
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
253 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
254 Versioning v;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
255 v.always = FALSE;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
256 v.type = VERSIONING_SIMPLE;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
257 v.collection = "/.dav-version-history";
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
258
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
259 xmlNode *c = node->children;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
260 while(c) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
261 if(c->type == XML_ELEMENT_NODE) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
262 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
263 if(xstreq(c->name, "type")) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
264 CHECK_VALUE(c, value);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
265 if(!strcmp(value, "simple")) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
266 v.type = VERSIONING_SIMPLE;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
267 } else if(!strcmp(value, "deltav")) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
268 v.type = VERSIONING_DELTAV;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
269 } else {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
270 return NULL;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
271 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
272 } else if(xstreq(c->name, "collection")) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
273 CHECK_VALUE(c, value);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
274 v.collection = value;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
275 } else if(xstreq(c->name, "always")) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
276 CHECK_VALUE(c, value);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
277 v.always = util_getboolean(value);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
278 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
279 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
280 c = c->next;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
281 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
282
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
283 v.collection = strdup(v.collection);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
284
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
285 Versioning *versioning = malloc(sizeof(Versioning));
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
286 *versioning = v;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
287 return versioning;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
288 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
289
256
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
290 static int scfg_load_directory(xmlNode *node) {
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 char *name = NULL;
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 char *path = NULL;
65
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
293 char *trash = NULL;
56
99f7816fcf01 added collection config for sync directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
294 char *collection = NULL;
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 char *repository = NULL;
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 char *database = NULL;
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
297 TagConfig *tagconfig = NULL;
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
298 Versioning *versioning = NULL;
58
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 56
diff changeset
299 UcxList *include = NULL;
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 56
diff changeset
300 UcxList *exclude = NULL;
417
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 416
diff changeset
301 UcxList *tagfilter = NULL;
244
47791bdf1725 changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
302 int max_retry = 0;
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 426
diff changeset
303 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
304 | SYNC_CMD_ARCHIVE | SYNC_CMD_RESTORE;
145
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
305 bool backuppull = false;
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 203
diff changeset
306 bool lockpull = false;
232
df3fa8637a58 disabled locking in dav-sync by default
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
307 bool lockpush = false;
316
9d0505d80044 adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 288
diff changeset
308 time_t lock_timeout = 0;
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309
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
310 unsigned short parentlineno = node->line;
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311 node = node->children;
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
312 while(node) {
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 if(node->type == XML_ELEMENT_NODE) {
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314 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
315 /* every key needs a value */
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
316 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
317 /* 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
318 * 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
319 */
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
320 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
321 "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
322 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
323 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
324 }
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
325 if(xstreq(node->name, "name")) {
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 name = value;
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327 } else if(xstreq(node->name, "path")) {
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328 path = value;
65
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
329 } else if(xstreq(node->name, "trash")) {
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
330 trash = value;
56
99f7816fcf01 added collection config for sync directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
331 } else if(xstreq(node->name, "collection")) {
99f7816fcf01 added collection config for sync directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
332 collection = value;
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
333 } else if(xstreq(node->name, "repository")) {
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 repository = value;
244
47791bdf1725 changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
335 } 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
336 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
337 return 1;
244
47791bdf1725 changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
338 }
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339 } else if(xstreq(node->name, "database")) {
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 database = value;
426
9cec06cfeade renames <tags> element to <tagconfig>
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 425
diff changeset
341 } else if(xstreq(node->name, "tagconfig")) {
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
342 tagconfig = parse_tagconfig(node);
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
343 } else if(xstreq(node->name, "versioning")) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
344 versioning = parse_versioning_config(node);
145
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
345 } else if(xstreq(node->name, "max-retry")) {
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
346 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
347 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
348 max_retry = (int)i;
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
349 } 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
350 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
351 "expected in <max-retry> element\n");
145
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
352 }
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
353 } 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
354 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
355 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
356 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
357 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
358 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
359 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
360 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
361 } 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
362 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
363 } 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
364 cmds |= SYNC_CMD_ARCHIVE;
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 426
diff changeset
365 } else if(!strcmp(cmd, "restore")) {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 426
diff changeset
366 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
367 }
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
368 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
369 }
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
370 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
371 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
372
145
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
373 } 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
374 backuppull = util_getboolean(value);
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 203
diff changeset
375 } else if(xstreq(node->name, "lock-pull")) {
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 203
diff changeset
376 lockpull = util_getboolean(value);
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 203
diff changeset
377 } else if(xstreq(node->name, "lock-push")) {
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 203
diff changeset
378 lockpush = util_getboolean(value);
316
9d0505d80044 adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 288
diff changeset
379 } 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
380 int64_t t = 0;
9d0505d80044 adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 288
diff changeset
381 if(util_strtoint(value, &t)) {
9d0505d80044 adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 288
diff changeset
382 lock_timeout = (time_t)t;
9d0505d80044 adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 288
diff changeset
383 } else {
9d0505d80044 adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 288
diff changeset
384 print_warning(node->line, "integer value "
9d0505d80044 adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 288
diff changeset
385 "expected in <lock-timeout> element\n");
9d0505d80044 adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 288
diff changeset
386 }
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
387 } 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
388 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
389 "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
390 return 1;
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
391 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
392 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
393 node = node->next;
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
394 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
395
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
396 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
397 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
398 return 1;
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
399 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
400 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
401 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
402 "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
403 return 1;
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
404 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
405 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
406 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
407 "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
408 return 1;
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
409 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
410 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
411 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
412 "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
413 return 1;
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
414 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
415
521
c5bbae4b3cca extends sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
416 SyncDirectory *dir = calloc(1, sizeof(SyncDirectory));
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
417 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
418 dir->path = scfg_create_path(path);
56
99f7816fcf01 added collection config for sync directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
419 dir->collection = collection ? strdup(collection) : NULL;
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
420 dir->repository = strdup(repository);
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
421 dir->database = strdup(database);
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
422 dir->tagconfig = tagconfig;
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
423 dir->versioning = versioning;
145
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
424 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
425 dir->allow_cmd = allow_cmd;
145
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
426 dir->backuppull = backuppull;
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 203
diff changeset
427 dir->lockpull = lockpull;
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 203
diff changeset
428 dir->lockpush = lockpush;
316
9d0505d80044 adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 288
diff changeset
429 dir->lock_timeout = lock_timeout;
58
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 56
diff changeset
430 if (include) {
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 56
diff changeset
431 dir->include = include;
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 56
diff changeset
432 } else {
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 56
diff changeset
433 regex_t *matchall = malloc(sizeof(regex_t));
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 56
diff changeset
434 regcomp(matchall, ".*", REG_NOSUB);
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 56
diff changeset
435 dir->include = ucx_list_append(NULL, matchall);
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 56
diff changeset
436 }
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 56
diff changeset
437 if (exclude) {
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 56
diff changeset
438 dir->exclude = exclude;
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 56
diff changeset
439 } else {
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 56
diff changeset
440 regex_t *matchnothing = malloc(sizeof(regex_t));
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 56
diff changeset
441 regcomp(matchnothing, "///", REG_NOSUB);
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 56
diff changeset
442 dir->exclude = ucx_list_append(NULL, matchnothing);
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 56
diff changeset
443 }
402
babdf40dd22c dav-sync pull applies config tag filter now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
444 dir->tagfilter = tagfilter;
66
f8c1f685e08e some bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
445
f8c1f685e08e some bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
446 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
447 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
448 dir->trash = scfg_create_path(trash);
65
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
449 } else {
226
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
450 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
451 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
452 free(t);
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
453 }
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
454
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
455 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
456 char *t = dir->trash;
65
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
457 dir->trash = util_concat_path(t, "/");
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
458 free(t);
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
459 }
66
f8c1f685e08e some bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
460 } else {
f8c1f685e08e some bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
461 dir->trash = NULL;
65
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
462 }
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
463
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
464 ucx_map_cstr_put(directories, name, dir);
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
465
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
466 return 0;
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
467 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
468
256
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
469 int load_sync_config() {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
470 directories = ucx_map_new(8);
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
471
319
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 316
diff changeset
472 if(check_config_dir()) {
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 316
diff changeset
473 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
474 return 1;
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 316
diff changeset
475 }
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 316
diff changeset
476
256
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
477 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
478
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
479 struct stat s;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
480 if(stat(file, &s)) {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
481 switch(errno) {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
482 case ENOENT: {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
483 if(create_default_sync_config(file)) {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
484 return 1;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
485 }
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
486 break;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
487 }
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
488 default: {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
489 perror("Cannot load sync.xml");
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
490 }
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
491 }
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
492 free(file);
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
493 return 0;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
494 }
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
495
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
496 xmlDoc *doc = xmlReadFile(file, NULL, 0);
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
497 if(!doc) {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
498 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
499 free(file);
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
500 return -1;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
501 }
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
502
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
503 int ret = 0;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
504 xmlNode *node = xmlDocGetRootElement(doc)->children;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
505 while(node && !ret) {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
506 if(node->type == XML_ELEMENT_NODE) {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
507 if(xstreq(node->name, "directory")) {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
508 ret = scfg_load_directory(node);
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
509 } else {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
510 print_error(node->line,
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
511 "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
512 ret = 1;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
513 }
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
514 }
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
515 node = node->next;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
516 }
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
517
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
518 xmlFreeDoc(doc);
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
519 free(file);
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
520 return ret;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
521 }
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
522
200
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
523 SyncDirectory* scfg_get_dir(char *name) {
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
524 return ucx_map_cstr_get(directories, name);
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
525 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
526
233
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
527 int scfg_check_dir(SyncDirectory *dir) {
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
528 struct stat s;
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
529 if(stat(dir->path, &s)) {
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
530 int err = errno;
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
531 if(err == ENOENT) {
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
532 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
533 } else {
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
534 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
535 perror(NULL);
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
536 }
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
537 fprintf(stderr, "Abort.\n");
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
538 return -1;
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
539 }
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
540
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
541 if(dir->trash) {
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
542 // create trash directory
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
543 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
544 if (util_mkdir(dir->trash, mode)) {
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
545 if (errno != EEXIST) {
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
546 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
547 return -1;
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
548 }
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
549 }
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
550 }
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
551
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
552 return 0;
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
553 }
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
554
226
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
555 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
556 if(!cfg) {
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
557 return NULL;
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
558 }
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
559 if(cfg[0] != '$') {
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
560 return strdup(cfg);
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
561 }
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
562
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
563 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
564 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
565 char *localpath = NULL;
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
566 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
567 // path = $var/path/
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 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
570 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
571 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
572 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
573 free(env);
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
574 if(envval) {
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
575 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
576 } else {
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
577 fprintf(
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
578 stderr,
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
579 "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
580 (int)var.length,
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
581 var.ptr);
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
582 exit(-1);
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
583 }
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
584 } else {
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
585 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
586 }
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
587 } else {
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
588 // path = $var
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
589 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
590 if(envval) {
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
591 localpath = strdup(envval);
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
592 } else {
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
593 fprintf(
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
594 stderr,
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
595 "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
596 cfg);
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
597 exit(-1);
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
598 }
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
599 }
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
600 return localpath;
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
601 }
acc997e0d0f9 added support for paths with environment variables in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
602
200
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
603
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
604 int add_directory(SyncDirectory *dir) {
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
605 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
606 xmlDoc *doc = xmlReadFile(file, NULL, 0);
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
607 if(!doc) {
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
608 free(file);
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
609 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
610 return 1;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
611 }
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
612
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
613 xmlNode *root = xmlDocGetRootElement(doc);
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
614
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
615 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
616 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
617
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
618 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
619 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
620
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
621 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
622 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
623
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
624 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
625 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
626
203
9a93ebd71984 fixed add-directory command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 202
diff changeset
627 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
628 xmlNodeAddContent(dirNode, BAD_CAST "\n\t\t");
9a93ebd71984 fixed add-directory command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 202
diff changeset
629
200
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
630 if(dir->trash) {
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
631 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
632 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
633 }
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
634 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
635 xmlNodeAddContent(dirNode, BAD_CAST "\n\t");
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
636
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
637 xmlNodeAddContent(root, BAD_CAST "\n\t");
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
638 xmlAddChild(root, dirNode);
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
639 xmlNodeAddContent(root, BAD_CAST "\n");
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
640
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
641 int ret = 0;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
642 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
643 ret = 1;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
644 }
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
645 xmlFreeDoc(doc);
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
646 free(file);
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
647
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
648 return ret;
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
649 }
198
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
650
200
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
651 char* generate_db_name(char *basename) {
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
652 char *dbname = NULL;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
653 int count = -1;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
654 while(!dbname) {
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
655 sstr_t name = count < 0 ?
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
656 ucx_sprintf("%s-db.xml", basename) :
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
657 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
658 count++;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
659
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
660 UcxMapIterator i = ucx_map_iterator(directories);
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
661 SyncDirectory *dir;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
662 bool unique = true;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
663 UCX_MAP_FOREACH(key, dir, i) {
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
664 if(!sstrcmp(name, sstr(dir->database))) {
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
665 unique = false;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
666 break;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
667 }
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
668 }
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
669 if(unique) {
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
670 dbname = name.ptr;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
671 break;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
672 }
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
673 }
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
674 return dbname;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
675 }
224
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
676
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
677
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
678 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
679 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
680 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
681 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
682 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
683 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
684 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
685 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
686 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
687
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
688 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
689 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
690 }
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
691 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
692 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
693 }
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
694
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
695 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
696 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
697 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
698 }
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
699 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
700 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
701 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
702 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
703 }
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
704 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
705
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
706 free(dir);
224
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
707 }
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
708
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
709 ucx_map_free(directories);
224
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
710 }
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
711 }

mercurial