dav/scfg.c

Sat, 15 Sep 2018 11:56:36 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 15 Sep 2018 11:56:36 +0200
changeset 470
6bf798ad3aec
parent 426
9cec06cfeade
child 490
d94c4fd35c21
permissions
-rw-r--r--

adds encrypted password store

new repo config element: <stored-user>
new dav command: add-user

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

mercurial