Fri, 11 Nov 2016 15:03:19 +0100
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
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 | * |
185
cd42cccee550
updated copyright notice
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
4 | * Copyright 2016 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 | |
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
|
44 | #define print_error(...) \ |
6b8e287269fc
improves config 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 {\ |
6b8e287269fc
improves config 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
|
46 | fprintf(stderr, "Error (config.xml): " __VA_ARGS__); \ |
6b8e287269fc
improves config 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
|
47 | fprintf(stderr, "Abort.\n"); \ |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
247
diff
changeset
|
48 | } while(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
|
49 | #define print_warning(...) \ |
6b8e287269fc
improves config 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
|
50 | fprintf(stderr, "Warning (config.xml): " __VA_ARGS__); |
6b8e287269fc
improves config 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
|
51 | |
32 | 52 | #ifdef _WIN32 |
53 | #define ENV_HOME getenv("USERPROFILE") | |
54 | #else | |
55 | #define ENV_HOME getenv("HOME") | |
56 | #endif /* _WIN32 */ | |
57 | ||
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | static UcxMap *repos; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | static UcxMap *keys; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | |
215
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
61 | int check_config_dir(void) { |
32 | 62 | 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
|
63 | int ret = 0; |
32 | 64 | 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
|
65 | if(errno != EEXIST) { |
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
66 | ret = 1; |
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
67 | } |
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
68 | } |
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
69 | free(file); |
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
70 | return ret; |
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 | |
40
a95ee94b9204
supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
73 | static DavContext *context; |
a95ee94b9204
supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
74 | |
142
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
75 | 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
|
76 | 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
|
77 | 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
|
78 | xmlDocSetRootElement(doc, root); |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
79 | 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
|
80 | xmlFreeDoc(doc); |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
81 | } |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
82 | |
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
|
83 | int load_config(DavContext *ctx) { |
40
a95ee94b9204
supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
84 | context = ctx; |
36 | 85 | // 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
|
86 | repos = ucx_map_new(16); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | keys = ucx_map_new(16); |
8
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
88 | if(check_config_dir()) { |
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
|
89 | return 1; |
8
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
90 | } |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | |
32 | 92 | 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
|
93 | |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
94 | struct stat s; |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
95 | if(stat(file, &s)) { |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
96 | switch(errno) { |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
97 | case ENOENT: { |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
98 | create_default_config(file); |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
99 | break; |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
100 | } |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
101 | default: { |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
102 | perror("Cannot load config.xml"); |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
103 | } |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
104 | } |
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
|
105 | return 1; |
6
9c64d2a3d101
creates an empty configuration file if needed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
106 | } |
142
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
107 | |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
108 | 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
|
109 | free(file); |
142
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
110 | if(!doc) { |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
111 | 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
|
112 | return 1; |
142
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
113 | } |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | xmlNode *xml_root = xmlDocGetRootElement(doc); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | 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
|
117 | 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
|
118 | while(node && !ret) { |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | 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
|
120 | 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
|
121 | ret = load_repository(node); |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | } 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
|
123 | ret = load_key(node); |
36 | 124 | } 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
|
125 | ret = load_proxy(ctx->http_proxy, node, HTTP_PROXY); |
36 | 126 | } 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
|
127 | ret = load_proxy(ctx->https_proxy, node, HTTPS_PROXY); |
6b8e287269fc
improves config 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 | } 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
|
129 | 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
|
130 | ret = 1; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | node = node->next; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | |
9 | 136 | 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
|
137 | return ret; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | |
215
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
140 | 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
|
141 | 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
|
142 | 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
|
143 | 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
|
144 | 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
|
145 | 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
|
146 | 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
|
147 | 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
|
148 | } |
6b8e287269fc
improves config 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 | 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
|
150 | 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
|
151 | } |
6b8e287269fc
improves config 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
|
152 | 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
|
153 | 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
|
154 | } |
6b8e287269fc
improves config 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 | 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
|
156 | 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
|
157 | } |
6b8e287269fc
improves config 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->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
|
159 | 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
|
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->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
|
162 | 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
|
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 | free(repo); |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
165 | } |
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
|
166 | ucx_map_free(repos); |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
167 | } |
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
|
168 | 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
|
169 | 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
|
170 | } |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
171 | } |
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
172 | |
215
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
173 | Repository* repository_new(void) { |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | Repository *repo = calloc(1, sizeof(Repository)); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
175 | repo->encrypt_name = false; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
176 | repo->encrypt_content = false; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
177 | repo->decrypt_name = false; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
178 | repo->decrypt_content = true; |
199
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
179 | repo->verification = true; |
73
41e88442ad4e
ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
180 | 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
|
181 | repo->authmethods = CURLAUTH_BASIC; |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
182 | return repo; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
183 | } |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
184 | |
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
|
185 | int load_repository(xmlNode *reponode) { |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
186 | Repository *repo = repository_new(); |
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
|
187 | { |
6b8e287269fc
improves config 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
|
188 | xmlNode *node = reponode->children; |
6b8e287269fc
improves config 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
|
189 | 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
|
190 | while(node && !ret) { |
6b8e287269fc
improves config 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
|
191 | if(node->type == XML_ELEMENT_NODE) { |
6b8e287269fc
improves config 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
|
192 | char *name = (char*)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
|
193 | char *value = util_xml_get_text(node); |
6b8e287269fc
improves config 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
|
194 | ret = repo_add_config(repo, name, value); |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | } |
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
|
196 | node = node->next; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | } |
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
|
198 | if(ret) { |
6b8e287269fc
improves config 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
|
199 | free(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
|
200 | 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
|
201 | } |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | |
21 | 204 | if(!repo->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
|
205 | print_error("missing name for repository.\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
|
206 | return 1; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | } |
21 | 208 | if(!repo->url) { |
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
|
209 | print_error("missing url for repository '%s'.\n", 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
|
210 | return 1; |
21 | 211 | } |
212 | ||
213 | ucx_map_cstr_put(repos, repo->name, repo); | |
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
|
214 | return 0; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | |
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
|
217 | int repo_add_config(Repository *repo, char *key, char *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
|
218 | /* 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
|
219 | 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
|
220 | /* 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
|
221 | * 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
|
222 | */ |
6b8e287269fc
improves config 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
|
223 | print_error("missing value for config element: %s\n", 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
|
224 | 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
|
225 | } |
6b8e287269fc
improves config 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
|
226 | |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
227 | if(xstreq(key, "name")) { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
228 | repo->name = strdup(value); |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
229 | } else if(xstreq(key, "url")) { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
230 | repo->url = strdup(value); |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
231 | } else if(xstreq(key, "user")) { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
232 | repo->user = strdup(value); |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
233 | } else if(xstreq(key, "password")) { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
234 | repo->password = util_base64decode(value); |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
235 | } else if(xstreq(key, "default-key")) { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
236 | repo->default_key = strdup(value); |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
237 | } else if(xstreq(key, "full-encryption")) { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
238 | if(util_getboolean(value)) { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
239 | repo->encrypt_name = true; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
240 | repo->encrypt_content = true; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
241 | repo->decrypt_name = true; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
242 | repo->decrypt_content = true; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
243 | } |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
244 | } else if(xstreq(key, "content-encryption")) { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
245 | if(util_getboolean(value)) { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
246 | repo->encrypt_content = true; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
247 | repo->decrypt_content = true; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
248 | } else { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
249 | repo->encrypt_content = false; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
250 | } |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
251 | } else if(xstreq(key, "decrypt-content")) { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
252 | repo->decrypt_content = util_getboolean(value); |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
253 | } else if(xstreq(key, "decrypt-name")) { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
254 | repo->decrypt_name = util_getboolean(value); |
199
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
255 | } else if(xstreq(key, "cert")) { |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
256 | char *configdir = util_concat_path(ENV_HOME, ".dav"); |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
257 | char *certfile = util_concat_path(configdir, value); |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
258 | repo->cert = certfile; |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
259 | free(configdir); |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
260 | } else if(xstreq(key, "verification")) { |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
261 | repo->verification = util_getboolean(value); |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
262 | } else if(xstreq(key, "ssl-version")) { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
263 | if(xstrEQ(value, "TLSv1")) { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
264 | repo->ssl_version = CURL_SSLVERSION_TLSv1; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
265 | } else if(xstrEQ(value, "SSLv2")) { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
266 | repo->ssl_version = CURL_SSLVERSION_SSLv2; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
267 | } else if(xstrEQ(value, "SSLv3")) { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
268 | repo->ssl_version = CURL_SSLVERSION_SSLv3; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
269 | } |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
270 | #if LIBCURL_VERSION_MAJOR >= 7 |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
271 | #if LIBCURL_VERSION_MINOR >= 34 |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
272 | else if(xstrEQ(value, "TLSv1.0")) { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
273 | repo->ssl_version = CURL_SSLVERSION_TLSv1_0; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
274 | } else if(xstrEQ(value, "TLSv1.1")) { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
275 | repo->ssl_version = CURL_SSLVERSION_TLSv1_1; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
276 | } else if(xstrEQ(value, "TLSv1.2")) { |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
277 | repo->ssl_version = CURL_SSLVERSION_TLSv1_2; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
278 | } |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
279 | #endif |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
280 | #endif |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
281 | else { |
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
|
282 | print_warning("unknown ssl version: %s\n", value); |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
283 | } |
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 | } 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
|
285 | repo->authmethods = CURLAUTH_NONE; |
247
3020d1b5e7bd
adds XSD for dav config XML and removes comma as authmethod delimiter
Mike Becker <universe@uap-core.de>
parents:
228
diff
changeset
|
286 | const char *delims = " \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
|
287 | 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
|
288 | 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
|
289 | while (meth) { |
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 | if(xstrEQ(value, "basic")) { |
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 | repo->authmethods |= CURLAUTH_BASIC; |
3cfb4670d9e6
added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents:
150
diff
changeset
|
292 | } else if(xstrEQ(value, "digest")) { |
3cfb4670d9e6
added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents:
150
diff
changeset
|
293 | repo->authmethods |= CURLAUTH_DIGEST; |
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 | } else if(xstrEQ(value, "negotiate")) { |
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 | repo->authmethods |= CURLAUTH_GSSNEGOTIATE; |
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 | } else if(xstrEQ(value, "ntlm")) { |
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 | repo->authmethods |= CURLAUTH_NTLM; |
3cfb4670d9e6
added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents:
150
diff
changeset
|
298 | } else if(xstrEQ(value, "any")) { |
3cfb4670d9e6
added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents:
150
diff
changeset
|
299 | repo->authmethods = CURLAUTH_ANY; |
3cfb4670d9e6
added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents:
150
diff
changeset
|
300 | } else if(xstrEQ(value, "none")) { |
3cfb4670d9e6
added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents:
150
diff
changeset
|
301 | /* 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
|
302 | } else { |
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
|
303 | print_warning("unknown authentication method: %s\n", value); |
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
|
304 | } |
3cfb4670d9e6
added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents:
150
diff
changeset
|
305 | 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
|
306 | } |
3cfb4670d9e6
added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents:
150
diff
changeset
|
307 | free(meths); |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
308 | } else { |
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
|
309 | print_error("unkown repository config element: %s\n", 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
|
310 | return 1; |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
311 | } |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
312 | return 0; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
313 | } |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
314 | |
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
|
315 | int load_proxy(DavProxy *proxy, xmlNode *proxynode, int type) { |
36 | 316 | 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
|
317 | if(type == HTTPS_PROXY) { |
36 | 318 | 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
|
319 | } else if(type == HTTP_PROXY) { |
36 | 320 | stype = "http"; |
321 | } | |
322 | ||
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
|
323 | if(!proxy) { |
6b8e287269fc
improves config 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
|
324 | print_error("no memory reserved for %s proxy.\n", stype); |
6b8e287269fc
improves config 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
|
325 | 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
|
326 | } |
6b8e287269fc
improves config 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
|
327 | |
36 | 328 | 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
|
329 | 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
|
330 | while(node && !ret) { |
36 | 331 | if(node->type == XML_ELEMENT_NODE) { |
332 | 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
|
333 | 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
|
334 | 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
|
335 | 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
|
336 | 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
|
337 | } |
36 | 338 | } 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
|
339 | 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
|
340 | 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
|
341 | } |
36 | 342 | } 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
|
343 | 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
|
344 | 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
|
345 | } |
36 | 346 | } 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
|
347 | 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
|
348 | 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
|
349 | } |
6b8e287269fc
improves config 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
|
350 | } 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
|
351 | print_error("invalid element for proxy config: %s\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
|
352 | 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
|
353 | 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
|
354 | } |
6b8e287269fc
improves config 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 | if (reportmissingvalue) { |
6b8e287269fc
improves config 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 | print_error("missing value for proxy configuration " |
6b8e287269fc
improves config 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 | "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
|
358 | ret = 1; |
36 | 359 | } |
360 | } | |
361 | node = node->next; | |
362 | } | |
363 | ||
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
|
364 | if(!ret && !proxy->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
|
365 | print_error("missing url for %s proxy.\n", stype); |
6b8e287269fc
improves config 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 | return 1; |
36 | 367 | } |
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
|
368 | |
6b8e287269fc
improves config 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 | return ret; |
36 | 370 | } |
371 | ||
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
|
372 | int load_key(xmlNode *keynode) { |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
373 | xmlNode *node = keynode->children; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
374 | 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
|
375 | key->type = KEY_AES256; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
376 | |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
377 | int error = 0; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
378 | while(node) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
379 | 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
|
380 | 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
|
381 | if(!value) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
382 | // next |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
383 | } 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
|
384 | key->name = strdup(value); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
385 | } 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
|
386 | // load key file |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
387 | 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
|
388 | if(key_data.length > 0) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
389 | key->data = key_data.ptr; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
390 | key->length = key_data.length; |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
391 | } else { |
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
|
392 | print_error("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
|
393 | error = 1; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
394 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
395 | } 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
|
396 | if(!strcmp(value, "aes128")) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
397 | key->type = KEY_AES128; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
398 | } else if(!strcmp(value, "aes256")) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
399 | key->type = KEY_AES256; |
228
c0175372c35d
removed password keys
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
224
diff
changeset
|
400 | } else { |
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
|
401 | print_error("unknown key type %s\n", value); |
228
c0175372c35d
removed password keys
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
224
diff
changeset
|
402 | error = 1; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
403 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
404 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
405 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
406 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
407 | node = node->next; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
408 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
409 | |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
410 | if(!error && key->name) { |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
411 | 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
|
412 | 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
|
413 | 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
|
414 | expected_length = 16; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
415 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
416 | 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
|
417 | 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
|
418 | } |
6b8e287269fc
improves config 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
|
419 | if(key->length < 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
|
420 | print_error("key %s is too small (%zu < %zu)\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
|
421 | 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
|
422 | 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
|
423 | 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
|
424 | error = 1; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
425 | } |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
426 | |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
427 | // add key to context |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
428 | if(!error) { |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
429 | ucx_map_cstr_put(keys, key->name, key); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
430 | dav_context_add_key(context, key); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
431 | } |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
432 | } |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
433 | |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
434 | // cleanup |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
435 | 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
|
436 | 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
|
437 | 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
|
438 | } |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
439 | 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
|
440 | 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
|
441 | } 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
|
442 | return 0; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
443 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
444 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
445 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
446 | 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
|
447 | sstr_t k; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
448 | k.ptr = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
449 | k.length = 0; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
450 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
451 | FILE *file = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
452 | if(filename[0] == '/') { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
453 | file = fopen(filename, "r"); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
454 | } else { |
32 | 455 | 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
|
456 | 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
|
457 | file = fopen(p2, "r"); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
458 | free(path); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
459 | free(p2); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
460 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
461 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
462 | if(!file) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
463 | return k; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
464 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
465 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
466 | char *data = malloc(256); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
467 | 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
|
468 | k.ptr = data; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
469 | k.length = r; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
470 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
471 | fclose(file); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
472 | return k; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
473 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
474 | |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
475 | Repository* get_repository(sstr_t name) { |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
476 | if(!name.ptr) { |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
477 | return NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
478 | } |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
479 | 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
|
480 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
481 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
482 | int get_repository_flags(Repository *repo) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
483 | int flags = 0; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
484 | if(repo->decrypt_content) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
485 | flags |= DAV_SESSION_DECRYPT_CONTENT; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
486 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
487 | if(repo->decrypt_name) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
488 | flags |= DAV_SESSION_DECRYPT_NAME; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
489 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
490 | if(repo->encrypt_content) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
491 | flags |= DAV_SESSION_ENCRYPT_CONTENT; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
492 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
493 | if(repo->encrypt_name) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
494 | flags |= DAV_SESSION_ENCRYPT_NAME; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
495 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
496 | return flags; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
497 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
498 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
499 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
500 | Key* get_key(char *name) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
501 | if(!name) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
502 | return NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
503 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
504 | 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
|
505 | } |
36 | 506 | |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
507 | int add_repository(Repository *repo) { |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
508 | char *file = util_concat_path(ENV_HOME, ".dav/config.xml"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
509 | xmlDoc *doc = xmlReadFile(file, NULL, 0); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
510 | if(!doc) { |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
511 | free(file); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
512 | fprintf(stderr, "Cannot load config.xml\n"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
513 | return 1; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
514 | } |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
515 | |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
516 | xmlNode *root = xmlDocGetRootElement(doc); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
517 | |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
518 | xmlNode *repoNode = xmlNewNode(NULL, BAD_CAST "repository"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
519 | xmlNodeAddContent(repoNode, BAD_CAST "\n\t\t"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
520 | 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
|
521 | xmlNodeAddContent(repoNode, BAD_CAST "\n\t\t"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
522 | 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
|
523 | xmlNodeAddContent(repoNode, BAD_CAST "\n"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
524 | if(repo->user) { |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
525 | xmlNodeAddContent(repoNode, BAD_CAST "\t\t"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
526 | 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
|
527 | xmlNodeAddContent(repoNode, BAD_CAST "\n"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
528 | if(repo->password) { |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
529 | char *pwenc = util_base64encode( |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
530 | repo->password, |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
531 | strlen(repo->password)); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
532 | xmlNodeAddContent(repoNode, BAD_CAST "\t\t"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
533 | 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
|
534 | free(pwenc); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
535 | xmlNodeAddContent(repoNode, BAD_CAST "\n"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
536 | } |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
537 | } |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
538 | xmlNodeAddContent(repoNode, BAD_CAST "\t"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
539 | |
205
bf756f6c3581
fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
540 | xmlNodeAddContent(root, BAD_CAST "\n\t"); |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
541 | xmlAddChild(root, repoNode); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
542 | xmlNodeAddContent(root, BAD_CAST "\n"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
543 | |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
544 | int ret = 0; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
545 | 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
|
546 | ret = 1; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
547 | } |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
548 | xmlFreeDoc(doc); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
549 | free(file); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
550 | |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
551 | return ret; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
552 | } |
198
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
194
diff
changeset
|
553 | |
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
194
diff
changeset
|
554 | int list_repositories() { |
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
194
diff
changeset
|
555 | UcxMapIterator i = ucx_map_iterator(repos); |
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
194
diff
changeset
|
556 | Repository *repo; |
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
194
diff
changeset
|
557 | UCX_MAP_FOREACH(key, repo, i) { |
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
194
diff
changeset
|
558 | printf("%s\n", repo->name); |
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
194
diff
changeset
|
559 | } |
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
194
diff
changeset
|
560 | return 0; |
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
194
diff
changeset
|
561 | } |
215
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
562 | |
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
563 | UcxList* get_repositories(void) { |
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
564 | UcxList *list = NULL; |
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
565 | 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
|
566 | Repository *repo; |
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
567 | 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
|
568 | 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
|
569 | } |
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
570 | return list; |
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
571 | } |