dav/config.c

Wed, 30 May 2018 16:25:57 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 30 May 2018 16:25:57 +0200
changeset 391
10305c5b0a16
parent 364
3769ba002fd1
child 398
26fdeed98cd7
permissions
-rw-r--r--

introduces tag filter string parser (currently supporting a simple tag list)

5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
364
3769ba002fd1 updates copyright date
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
4 * Copyright 2018 Olaf Wintermann. All rights reserved.
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
88625853ae74 new webdav api + repository and key configuration + aes encryption
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
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
8
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
32 #include <sys/types.h>
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <ucx/map.h>
8
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
34 #include <errno.h>
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include <libxml/tree.h>
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include "config.h"
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: 247
diff changeset
38 #include "main.h"
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 32
diff changeset
39 #include <libidav/utils.h>
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b)
73
41e88442ad4e ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
42 #define xstrEQ(a,b) !xmlStrcasecmp(BAD_CAST a, BAD_CAST b)
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
254
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
44 #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: 247
diff changeset
45 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: 252
diff changeset
46 fprintf(stderr, "Error (config.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: 252
diff changeset
47 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: 247
diff changeset
48 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: 247
diff changeset
49 } 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: 252
diff changeset
50 #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: 252
diff changeset
51 do {\
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
52 fprintf(stderr, "Warning (config.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: 252
diff changeset
53 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: 252
diff changeset
54 } 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: 247
diff changeset
55
32
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
56 #ifdef _WIN32
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
57 #define ENV_HOME getenv("USERPROFILE")
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
58 #else
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
59 #define ENV_HOME getenv("HOME")
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
60 #endif /* _WIN32 */
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
61
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 static UcxMap *repos;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 static UcxMap *keys;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64
215
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
65 int check_config_dir(void) {
32
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
66 char *file = util_concat_path(ENV_HOME, ".dav");
8
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
67 int ret = 0;
32
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
68 if(util_mkdir(file, S_IRWXU)) {
8
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
69 if(errno != EEXIST) {
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
70 ret = 1;
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
71 }
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
72 }
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
73 free(file);
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
74 return ret;
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
75 }
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
76
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
77 static DavContext *context;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
78
142
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
79 void create_default_config(char *file) {
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
80 xmlDoc *doc = xmlNewDoc(BAD_CAST "1.0");
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
81 xmlNode *root = xmlNewNode(NULL, BAD_CAST "configuration");
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
82 xmlDocSetRootElement(doc, root);
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
83 xmlSaveFormatFileEnc(file, doc, "UTF-8", 1);
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
84 xmlFreeDoc(doc);
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
85 }
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
86
296
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
87 char* config_file_path(char *name) {
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
88 char *davd = util_concat_path(ENV_HOME, ".dav");
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
89 if(!davd) {
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
90 return NULL;
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
91 }
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
92 char *path = util_concat_path(davd, name);
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
93 free(davd);
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
94 return path;
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
95 }
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
96
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: 247
diff changeset
97 int load_config(DavContext *ctx) {
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
98 context = ctx;
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
99 // TODO: free the config somewhere
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 repos = ucx_map_new(16);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 keys = ucx_map_new(16);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102
32
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
103 char *file = util_concat_path(ENV_HOME, ".dav/config.xml");
142
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
104
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
105 struct stat s;
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
106 if(stat(file, &s)) {
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
107 switch(errno) {
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
108 case ENOENT: {
294
dd5c0ebdf54f fixes dav startup without .dav dir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
109 return 0;
142
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
110 }
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
111 default: {
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
112 perror("Cannot load config.xml");
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
113 }
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
114 }
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: 247
diff changeset
115 return 1;
6
9c64d2a3d101 creates an empty configuration file if needed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
116 }
142
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
117
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
118 xmlDoc *doc = xmlReadFile(file, NULL, 0);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 free(file);
142
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
120 if(!doc) {
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
121 fprintf(stderr, "Cannot load config.xml\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: 247
diff changeset
122 return 1;
142
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
123 }
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 xmlNode *xml_root = xmlDocGetRootElement(doc);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 xmlNode *node = xml_root->children;
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: 247
diff changeset
127 int ret = 0;
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: 247
diff changeset
128 while(node && !ret) {
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 if(node->type == XML_ELEMENT_NODE) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 if(xstreq(node->name, "repository")) {
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: 247
diff changeset
131 ret = load_repository(node);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 } else if(xstreq(node->name, "key")) {
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: 247
diff changeset
133 ret = load_key(node);
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
134 } else if (xstreq(node->name, "http-proxy")) {
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: 247
diff changeset
135 ret = load_proxy(ctx->http_proxy, node, HTTP_PROXY);
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
136 } else if (xstreq(node->name, "https-proxy")) {
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: 247
diff changeset
137 ret = load_proxy(ctx->https_proxy, node, HTTPS_PROXY);
317
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
138 } else if (xstreq(node->name, "namespace")) {
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
139 ret = load_namespace(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: 247
diff changeset
140 } else {
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: 247
diff changeset
141 fprintf(stderr, "Unknown config element: %s\n", 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: 247
diff changeset
142 ret = 1;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 node = node->next;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147
9
6aec77cfa95b fixed build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
148 xmlFreeDoc(doc);
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: 247
diff changeset
149 return ret;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151
215
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
152 void free_config(void) {
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: 247
diff changeset
153 if(repos) {
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: 247
diff changeset
154 UcxMapIterator i = ucx_map_iterator(repos);
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: 247
diff changeset
155 UcxKey k;
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: 247
diff changeset
156 Repository *repo;
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: 247
diff changeset
157 UCX_MAP_FOREACH(k, repo, 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: 247
diff changeset
158 if(repo->default_key) {
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: 247
diff changeset
159 free(repo->default_key);
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: 247
diff changeset
160 }
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: 247
diff changeset
161 if(repo->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: 247
diff changeset
162 free(repo->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: 247
diff changeset
163 }
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: 247
diff changeset
164 if(repo->password) {
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: 247
diff changeset
165 free(repo->password);
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: 247
diff changeset
166 }
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: 247
diff changeset
167 if(repo->url) {
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: 247
diff changeset
168 free(repo->url);
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: 247
diff changeset
169 }
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: 247
diff changeset
170 if(repo->user) {
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: 247
diff changeset
171 free(repo->user);
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: 247
diff changeset
172 }
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: 247
diff changeset
173 if(repo->cert) {
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: 247
diff changeset
174 free(repo->cert);
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: 247
diff changeset
175 }
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: 247
diff changeset
176 free(repo);
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
177 }
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: 247
diff changeset
178 ucx_map_free(repos);
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
179 }
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: 247
diff changeset
180 if(keys) {
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: 247
diff changeset
181 ucx_map_free(keys);
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: 247
diff changeset
182 }
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
183 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
184
215
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
185 Repository* repository_new(void) {
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 Repository *repo = calloc(1, sizeof(Repository));
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
187 repo->encrypt_name = false;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
188 repo->encrypt_content = false;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
189 repo->decrypt_name = false;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
190 repo->decrypt_content = true;
199
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
191 repo->verification = true;
73
41e88442ad4e ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
192 repo->ssl_version = CURL_SSLVERSION_DEFAULT;
154
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
193 repo->authmethods = CURLAUTH_BASIC;
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
194 return repo;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
195 }
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
196
254
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
197 static int repo_add_config(Repository *repo, const xmlNode* node) {
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
198 unsigned short lineno = 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: 252
diff changeset
199 char *key = (char*)node->name;
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
200 char *value = util_xml_get_text(node);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201
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: 247
diff changeset
202 /* every key needs a value */
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: 247
diff changeset
203 if(!value) {
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: 247
diff changeset
204 /* 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: 247
diff changeset
205 * 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: 247
diff changeset
206 */
254
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
207 print_error(lineno, "missing value for config element: %s\n", key);
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: 247
diff changeset
208 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: 247
diff changeset
209 }
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: 247
diff changeset
210
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
211 if(xstreq(key, "name")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
212 repo->name = strdup(value);
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
213 } else if(xstreq(key, "url")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
214 repo->url = strdup(value);
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
215 } else if(xstreq(key, "user")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
216 repo->user = strdup(value);
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
217 } else if(xstreq(key, "password")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
218 repo->password = util_base64decode(value);
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
219 } else if(xstreq(key, "default-key")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
220 repo->default_key = strdup(value);
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
221 } else if(xstreq(key, "full-encryption")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
222 if(util_getboolean(value)) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
223 repo->encrypt_name = true;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
224 repo->encrypt_content = true;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
225 repo->decrypt_name = true;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
226 repo->decrypt_content = true;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
227 }
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
228 } else if(xstreq(key, "content-encryption")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
229 if(util_getboolean(value)) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
230 repo->encrypt_content = true;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
231 repo->decrypt_content = true;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
232 } else {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
233 repo->encrypt_content = false;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
234 }
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
235 } else if(xstreq(key, "decrypt-content")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
236 repo->decrypt_content = util_getboolean(value);
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
237 } else if(xstreq(key, "decrypt-name")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
238 repo->decrypt_name = util_getboolean(value);
199
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
239 } else if(xstreq(key, "cert")) {
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
240 char *configdir = util_concat_path(ENV_HOME, ".dav");
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
241 char *certfile = util_concat_path(configdir, value);
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
242 repo->cert = certfile;
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
243 free(configdir);
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
244 } else if(xstreq(key, "verification")) {
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
245 repo->verification = util_getboolean(value);
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
246 } else if(xstreq(key, "ssl-version")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
247 if(xstrEQ(value, "TLSv1")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
248 repo->ssl_version = CURL_SSLVERSION_TLSv1;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
249 } else if(xstrEQ(value, "SSLv2")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
250 repo->ssl_version = CURL_SSLVERSION_SSLv2;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
251 } else if(xstrEQ(value, "SSLv3")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
252 repo->ssl_version = CURL_SSLVERSION_SSLv3;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
253 }
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
254 #if LIBCURL_VERSION_MAJOR >= 7
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
255 #if LIBCURL_VERSION_MINOR >= 34
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
256 else if(xstrEQ(value, "TLSv1.0")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
257 repo->ssl_version = CURL_SSLVERSION_TLSv1_0;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
258 } else if(xstrEQ(value, "TLSv1.1")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
259 repo->ssl_version = CURL_SSLVERSION_TLSv1_1;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
260 } else if(xstrEQ(value, "TLSv1.2")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
261 repo->ssl_version = CURL_SSLVERSION_TLSv1_2;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
262 }
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
263 #endif
295
8ac7b8d56115 adds TLSv1.3 config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
264 #if LIBCURL_VERSION_MINOR >= 52
8ac7b8d56115 adds TLSv1.3 config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
265 else if(xstrEQ(value, "TLSv1.3")) {
8ac7b8d56115 adds TLSv1.3 config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
266 repo->ssl_version = CURL_SSLVERSION_TLSv1_3;
8ac7b8d56115 adds TLSv1.3 config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
267 }
8ac7b8d56115 adds TLSv1.3 config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
268 #endif
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
269 #endif
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
270 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: 252
diff changeset
271 print_warning(lineno, "unknown ssl version: %s\n", value);
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
272 }
154
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
273 } else if(xstreq(key, "authmethods")) {
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
274 repo->authmethods = CURLAUTH_NONE;
347
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
275 const char *delims = " \t\r\n";
154
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
276 char *meths = strdup(value);
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
277 char *meth = strtok(meths, delims);
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
278 while (meth) {
347
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
279 if(xstrEQ(meth, "basic")) {
154
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
280 repo->authmethods |= CURLAUTH_BASIC;
347
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
281 } else if(xstrEQ(meth, "digest")) {
154
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
282 repo->authmethods |= CURLAUTH_DIGEST;
347
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
283 } else if(xstrEQ(meth, "negotiate")) {
154
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
284 repo->authmethods |= CURLAUTH_GSSNEGOTIATE;
347
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
285 } else if(xstrEQ(meth, "ntlm")) {
154
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
286 repo->authmethods |= CURLAUTH_NTLM;
347
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
287 } else if(xstrEQ(meth, "any")) {
154
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
288 repo->authmethods = CURLAUTH_ANY;
347
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
289 } else if(xstrEQ(meth, "none")) {
154
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
290 /* skip */
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
291 } 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: 252
diff changeset
292 print_warning(lineno,
347
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
293 "unknown authentication method: %s\n", meth);
154
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
294 }
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
295 meth = strtok(NULL, delims);
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
296 }
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
297 free(meths);
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
298 } 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: 252
diff changeset
299 print_error(lineno, "unkown repository config element: %s\n", key);
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: 247
diff changeset
300 return 1;
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
301 }
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
302 return 0;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
303 }
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
304
254
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
305 int load_repository(const xmlNode *reponode) {
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
306 Repository *repo = repository_new();
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
307 {
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
308 xmlNode *node = reponode->children;
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
309 int ret = 0;
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
310 while(node && !ret) {
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
311 if(node->type == XML_ELEMENT_NODE) {
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
312 ret = repo_add_config(repo, node);
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
313 }
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
314 node = node->next;
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
315 }
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
316 if(ret) {
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
317 free(repo);
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
318 return 1;
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
319 }
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
320 }
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
321
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
322 if(!repo->name) {
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
323 print_error(reponode->line, "missing name for repository.\n");
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
324 return 1;
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
325 }
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
326 if(!repo->url) {
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
327 print_error(reponode->line,
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
328 "missing url for repository '%s'.\n", repo->name);
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
329 return 1;
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
330 }
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
331
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
332 ucx_map_cstr_put(repos, repo->name, repo);
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
333 return 0;
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
334 }
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
335
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
336 int load_proxy(DavProxy *proxy, const xmlNode *proxynode, int type) {
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
337 const char *stype;
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: 247
diff changeset
338 if(type == HTTPS_PROXY) {
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
339 stype = "https";
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: 247
diff changeset
340 } else if(type == HTTP_PROXY) {
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
341 stype = "http";
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
342 }
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
343
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: 247
diff changeset
344 if(!proxy) {
254
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
345 // no xml error - so report this directly via fprintf
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
346 fprintf(stderr, "no memory reserved for %s proxy.\n", stype);
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: 247
diff changeset
347 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: 247
diff changeset
348 }
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: 247
diff changeset
349
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
350 xmlNode *node = proxynode->children;
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: 247
diff changeset
351 int ret = 0;
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: 247
diff changeset
352 while(node && !ret) {
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
353 if(node->type == XML_ELEMENT_NODE) {
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
354 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: 247
diff changeset
355 int reportmissingvalue = 0;
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: 247
diff changeset
356 if(xstreq(node->name, "url")) {
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: 247
diff changeset
357 if(!(reportmissingvalue = !value)) {
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: 247
diff changeset
358 proxy->url = strdup(value);
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: 247
diff changeset
359 }
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
360 } else if(xstreq(node->name, "user")) {
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: 247
diff changeset
361 if(!(reportmissingvalue = !value)) {
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: 247
diff changeset
362 proxy->username = strdup(value);
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: 247
diff changeset
363 }
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
364 } else if(xstreq(node->name, "password")) {
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: 247
diff changeset
365 if(!(reportmissingvalue = !value)) {
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: 247
diff changeset
366 proxy->password = util_base64decode(value);
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: 247
diff changeset
367 }
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
368 } else if(xstreq(node->name, "no")) {
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: 247
diff changeset
369 if(!(reportmissingvalue = !value)) {
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: 247
diff changeset
370 proxy->no_proxy = strdup(value);
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: 247
diff changeset
371 }
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: 247
diff changeset
372 } 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: 252
diff changeset
373 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: 252
diff changeset
374 "invalid element for proxy config: %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: 247
diff changeset
375 ret = 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: 247
diff changeset
376 }
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: 247
diff changeset
377 if (reportmissingvalue) {
254
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
378 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: 252
diff changeset
379 "missing value for proxy configuration element: %s\n",
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
380 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: 247
diff changeset
381 ret = 1;
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
382 }
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
383 }
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
384 node = node->next;
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
385 }
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
386
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 247
diff changeset
387 if(!ret && !proxy->url) {
254
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
388 print_error(proxynode->line, "missing url for %s proxy.\n", stype);
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: 247
diff changeset
389 return 1;
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
390 }
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: 247
diff changeset
391
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: 247
diff changeset
392 return ret;
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
393 }
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
394
254
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
395 int load_key(const xmlNode *keynode) {
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
396 xmlNode *node = keynode->children;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
397 Key *key = calloc(1, sizeof(Key));
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
398 key->type = KEY_AES256;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
399
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
400 int error = 0;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
401 while(node) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
402 if(node->type == XML_ELEMENT_NODE) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
403 char *value = util_xml_get_text(node);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
404 if(!value) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
405 // next
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
406 } else if(xstreq(node->name, "name")) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
407 key->name = strdup(value);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
408 } else if(xstreq(node->name, "file")) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
409 // load key file
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
410 sstr_t key_data = load_key_file(value);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
411 if(key_data.length > 0) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
412 key->data = key_data.ptr;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
413 key->length = key_data.length;
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
414 } 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: 252
diff changeset
415 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: 252
diff changeset
416 "cannot get key from file: %s\n", value);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
417 error = 1;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
418 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
419 } else if(xstreq(node->name, "type")) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
420 if(!strcmp(value, "aes128")) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
421 key->type = KEY_AES128;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
422 } else if(!strcmp(value, "aes256")) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
423 key->type = KEY_AES256;
228
c0175372c35d removed password keys
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
424 } 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: 252
diff changeset
425 print_error(node->line, "unknown key type %s\n", value);
228
c0175372c35d removed password keys
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 224
diff changeset
426 error = 1;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
427 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
428 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
429
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
430 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
431 node = node->next;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
432 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
433
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
434 if(!error && key->name) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
435 error = 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: 247
diff changeset
436 size_t expected_length = 0;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
437 if(key->type == KEY_AES128) {
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: 247
diff changeset
438 expected_length = 16;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
439 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
440 if(key->type == KEY_AES256) {
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: 247
diff changeset
441 expected_length = 32;
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: 247
diff changeset
442 }
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: 247
diff changeset
443 if(key->length < expected_length) {
254
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
444 print_error(keynode->line, "key %s is too small (%zu < %zu)\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: 247
diff changeset
445 key->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: 247
diff changeset
446 key->length,
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: 247
diff changeset
447 expected_length);
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: 247
diff changeset
448 error = 1;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
449 }
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
450
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
451 // add key to context
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
452 if(!error) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
453 ucx_map_cstr_put(keys, key->name, key);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
454 dav_context_add_key(context, key);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
455 }
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
456 }
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
457
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
458 // cleanup
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
459 if(error) {
147
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
460 if(key->data) {
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
461 free(key->data);
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
462 }
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
463 free(key);
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: 247
diff changeset
464 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: 247
diff changeset
465 } else {
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: 247
diff changeset
466 return 0;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
467 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
468 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
469
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
470 sstr_t load_key_file(char *filename) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
471 sstr_t k;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
472 k.ptr = NULL;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
473 k.length = 0;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
474
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
475 FILE *file = NULL;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
476 if(filename[0] == '/') {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
477 file = fopen(filename, "r");
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
478 } else {
32
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
479 char *path = util_concat_path(ENV_HOME, ".dav/");
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
480 char *p2 = util_concat_path(path, filename);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
481 file = fopen(p2, "r");
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
482 free(path);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
483 free(p2);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
484 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
485
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
486 if(!file) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
487 return k;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
488 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
489
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
490 char *data = malloc(256);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
491 size_t r = fread(data, 1, 256, file);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
492 k.ptr = data;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
493 k.length = r;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
494
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
495 fclose(file);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
496 return k;
317
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
497 }
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
498
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
499 static char* get_attr_content(xmlNode *node) {
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
500 // TODO: remove code duplication (util_xml_get_text)
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
501 while(node) {
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
502 if(node->type == XML_TEXT_NODE) {
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
503 return (char*)node->content;
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
504 }
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
505 node = node->next;
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
506 }
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
507 return NULL;
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
508 }
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
509
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
510 int load_namespace(const xmlNode *node) {
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
511 const char *prefix = NULL;
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
512 const char *uri = NULL;
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
513
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
514 xmlAttr *attr = node->properties;
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
515 while(attr) {
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
516 if(attr->type == XML_ATTRIBUTE_NODE) {
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
517 char *value = get_attr_content(attr->children);
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
518 if(!value) {
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
519 print_error(
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
520 node->line,
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
521 "missing value for attribute %s\n", (char*)attr->name);
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
522 return 1;
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
523 }
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
524 if(xstreq(attr->name, "prefix")) {
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
525 prefix = value;
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
526 } else if(xstreq(attr->name, "uri")) {
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
527 uri = value;
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
528 } else {
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
529 print_error(
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
530 node->line,
321
eb8885a87866 adds namespace config element to XSD + fixes error message for duplicate namespace prefixes
Mike Becker <universe@uap-core.de>
parents: 319
diff changeset
531 "unexpected attribute %s\n", (char*)attr->name);
317
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
532 return 1;
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
533 }
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
534 }
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
535 attr = attr->next;
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
536 }
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
537
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
538 if(!prefix) {
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
539 print_error(node->line, "missing prefix attribute\n");
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
540 return 1;
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
541 }
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
542 if(!uri) {
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
543 print_error(node->line, "missing uri attribute\n");
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
544 return 1;
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
545 }
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
546
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
547 if(dav_get_namespace(context, prefix)) {
321
eb8885a87866 adds namespace config element to XSD + fixes error message for duplicate namespace prefixes
Mike Becker <universe@uap-core.de>
parents: 319
diff changeset
548 print_error(node->line, "namespace prefix '%s' already used\n", prefix);
317
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
549 return 1;
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
550 }
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
551
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
552 return dav_add_namespace(context, prefix, uri);
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
553 }
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
554
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
555 Repository* get_repository(sstr_t name) {
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
556 if(!name.ptr) {
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
557 return NULL;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
558 }
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
559 return ucx_map_sstr_get(repos, name);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
560 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
561
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
562 int get_repository_flags(Repository *repo) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
563 int flags = 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
564 if(repo->decrypt_content) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
565 flags |= DAV_SESSION_DECRYPT_CONTENT;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
566 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
567 if(repo->decrypt_name) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
568 flags |= DAV_SESSION_DECRYPT_NAME;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
569 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
570 if(repo->encrypt_content) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
571 flags |= DAV_SESSION_ENCRYPT_CONTENT;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
572 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
573 if(repo->encrypt_name) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
574 flags |= DAV_SESSION_ENCRYPT_NAME;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
575 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
576 return flags;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
577 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
578
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
579
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
580 Key* get_key(char *name) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
581 if(!name) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
582 return NULL;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
583 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
584 return ucx_map_cstr_get(keys, name);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
585 }
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
586
194
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
587 int add_repository(Repository *repo) {
319
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
588 if(check_config_dir()) {
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
589 fprintf(stderr, "Cannot create .dav directory\n");
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
590 return 1;
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
591 }
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
592
194
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
593 char *file = util_concat_path(ENV_HOME, ".dav/config.xml");
319
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
594 struct stat s;
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
595 if(stat(file, &s)) {
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
596 switch(errno) {
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
597 case ENOENT: {
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
598 create_default_config(file);
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
599 break;
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
600 }
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
601 default: {
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
602 perror("Cannot load config.xml");
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
603 free(file);
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
604 return 1;
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
605 }
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
606 }
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
607 }
2433b5969d44 disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
608
194
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
609 xmlDoc *doc = xmlReadFile(file, NULL, 0);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
610 if(!doc) {
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
611 free(file);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
612 fprintf(stderr, "Cannot load config.xml\n");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
613 return 1;
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
614 }
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
615
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
616 xmlNode *root = xmlDocGetRootElement(doc);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
617
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
618 xmlNode *repoNode = xmlNewNode(NULL, BAD_CAST "repository");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
619 xmlNodeAddContent(repoNode, BAD_CAST "\n\t\t");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
620 xmlNewTextChild(repoNode, NULL, BAD_CAST "name", BAD_CAST repo->name);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
621 xmlNodeAddContent(repoNode, BAD_CAST "\n\t\t");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
622 xmlNewTextChild(repoNode, NULL, BAD_CAST "url", BAD_CAST repo->url);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
623 xmlNodeAddContent(repoNode, BAD_CAST "\n");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
624 if(repo->user) {
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
625 xmlNodeAddContent(repoNode, BAD_CAST "\t\t");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
626 xmlNewChild(repoNode, NULL, BAD_CAST "user", BAD_CAST repo->user);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
627 xmlNodeAddContent(repoNode, BAD_CAST "\n");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
628 if(repo->password) {
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
629 char *pwenc = util_base64encode(
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
630 repo->password,
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
631 strlen(repo->password));
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
632 xmlNodeAddContent(repoNode, BAD_CAST "\t\t");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
633 xmlNewTextChild(repoNode, NULL, BAD_CAST "password", BAD_CAST pwenc);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
634 free(pwenc);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
635 xmlNodeAddContent(repoNode, BAD_CAST "\n");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
636 }
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
637 }
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
638 xmlNodeAddContent(repoNode, BAD_CAST "\t");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
639
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
640 xmlNodeAddContent(root, BAD_CAST "\n\t");
194
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
641 xmlAddChild(root, repoNode);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
642 xmlNodeAddContent(root, BAD_CAST "\n");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
643
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
644 int ret = 0;
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
645 if(xmlSaveFormatFileEnc(file, doc, "UTF-8", 1) == -1) {
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
646 ret = 1;
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
647 }
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
648 xmlFreeDoc(doc);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
649 free(file);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
650
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
651 return ret;
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
652 }
198
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
653
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
654 int list_repositories() {
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
655 UcxMapIterator i = ucx_map_iterator(repos);
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
656 Repository *repo;
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
657 UCX_MAP_FOREACH(key, repo, i) {
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
658 printf("%s\n", repo->name);
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
659 }
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
660 return 0;
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
661 }
215
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
662
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
663 UcxList* get_repositories(void) {
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
664 UcxList *list = NULL;
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
665 UcxMapIterator i = ucx_map_iterator(repos);
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
666 Repository *repo;
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
667 UCX_MAP_FOREACH(key, repo, i) {
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
668 list = ucx_list_append(list, repo);
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
669 }
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
670 return list;
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
671 }

mercurial