Fri, 13 Sep 2024 18:21:04 +0200
fix load_config stores wrong xml doc pointer in the config object
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2023 Olaf Wintermann. All rights reserved. |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
05647e862a17
add new config parser
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 |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include "config.h" |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include <stdio.h> |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | #include <stdlib.h> |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include <string.h> |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include <sys/types.h> |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include <cx/hash_map.h> |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #include <errno.h> |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #include <libxml/tree.h> |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | #include "utils.h" |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b) |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | #define xstrEQ(a,b) !xmlStrcasecmp(BAD_CAST a, BAD_CAST b) |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | #define print_error(lineno, ...) \ |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | do {\ |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | fprintf(stderr, "Error (config.xml line %u): ", lineno); \ |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | fprintf(stderr, __VA_ARGS__); \ |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | fprintf(stderr, "Abort.\n"); \ |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | } while(0); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | #define print_warning(lineno, ...) \ |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | do {\ |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | fprintf(stderr, "Warning (config.xml line %u): ", lineno); \ |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | fprintf(stderr, __VA_ARGS__); \ |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | } while(0); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | #ifdef _WIN32 |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | #define ENV_HOME getenv("USERPROFILE") |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | #else |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | #define ENV_HOME getenv("HOME") |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | #endif /* _WIN32 */ |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | static int load_repository( |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | DavConfig *config, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | DavCfgRepository **list_begin, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | DavCfgRepository **list_end, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | xmlNode *reponode); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | static int load_key( |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | DavConfig *config, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | DavCfgKey **list_begin, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | DavCfgKey **list_end, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | xmlNode *keynode); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | static int load_proxy( |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | DavConfig *config, DavCfgProxy *proxy, xmlNode *proxynode, int type); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | static int load_namespace( |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | DavConfig *config, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | DavCfgNamespace **list_begin, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | DavCfgNamespace **list_end, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | xmlNode *node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | static int load_secretstore(DavConfig *config, xmlNode *node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | int dav_cfg_string_set_value(DavConfig *config, CfgString *str, xmlNode *node) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | str->node = node; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | char *value = util_xml_get_text(node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | if(value) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | str->value = cx_strdup_a(config->mp->allocator, cx_str(value)); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | return 0; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | } else { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | str->value = (cxmutstr){NULL, 0}; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | return 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | void dav_cfg_bool_set_value(DavConfig *config, CfgBool *cbool, xmlNode *node) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | cbool->node = node; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | char *value = util_xml_get_text(node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | cbool->value = util_getboolean(value); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | |
827
d9928f11970f
fix load_config stores wrong xml doc pointer in the config object
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
826
diff
changeset
|
101 | DavConfig* dav_config_new(xmlDoc *doc) { |
826
b6e9fd3f1951
fix dav add-repo crash in case .dav/config.xml doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
823
diff
changeset
|
102 | CxMempool *cfg_mp = cxMempoolCreate(128, NULL); |
b6e9fd3f1951
fix dav add-repo crash in case .dav/config.xml doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
823
diff
changeset
|
103 | DavConfig *config = cxMalloc(cfg_mp->allocator, sizeof(DavConfig)); |
b6e9fd3f1951
fix dav add-repo crash in case .dav/config.xml doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
823
diff
changeset
|
104 | memset(config, 0, sizeof(DavConfig)); |
b6e9fd3f1951
fix dav add-repo crash in case .dav/config.xml doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
823
diff
changeset
|
105 | config->mp = cfg_mp; |
b6e9fd3f1951
fix dav add-repo crash in case .dav/config.xml doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
823
diff
changeset
|
106 | |
827
d9928f11970f
fix load_config stores wrong xml doc pointer in the config object
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
826
diff
changeset
|
107 | if(!doc) { |
d9928f11970f
fix load_config stores wrong xml doc pointer in the config object
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
826
diff
changeset
|
108 | doc = xmlNewDoc(BAD_CAST "1.0"); |
d9928f11970f
fix load_config stores wrong xml doc pointer in the config object
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
826
diff
changeset
|
109 | xmlNode *root = xmlNewNode(NULL, BAD_CAST "configuration"); |
d9928f11970f
fix load_config stores wrong xml doc pointer in the config object
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
826
diff
changeset
|
110 | xmlDocSetRootElement(doc, root); |
d9928f11970f
fix load_config stores wrong xml doc pointer in the config object
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
826
diff
changeset
|
111 | } |
826
b6e9fd3f1951
fix dav add-repo crash in case .dav/config.xml doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
823
diff
changeset
|
112 | config->doc = doc; |
b6e9fd3f1951
fix dav add-repo crash in case .dav/config.xml doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
823
diff
changeset
|
113 | |
b6e9fd3f1951
fix dav add-repo crash in case .dav/config.xml doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
823
diff
changeset
|
114 | return config; |
b6e9fd3f1951
fix dav add-repo crash in case .dav/config.xml doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
823
diff
changeset
|
115 | } |
b6e9fd3f1951
fix dav add-repo crash in case .dav/config.xml doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
823
diff
changeset
|
116 | |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | DavConfig* dav_config_load(cxmutstr xmlfilecontent, int *error) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | xmlDoc *doc = xmlReadMemory(xmlfilecontent.ptr, xmlfilecontent.length, NULL, NULL, 0); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | if(!doc) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | if(error) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | *error = DAV_CONFIG_ERROR_XML; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | return NULL; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | |
827
d9928f11970f
fix load_config stores wrong xml doc pointer in the config object
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
826
diff
changeset
|
126 | DavConfig *config = dav_config_new(doc); |
826
b6e9fd3f1951
fix dav add-repo crash in case .dav/config.xml doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
823
diff
changeset
|
127 | CxMempool *cfg_mp = config->mp; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | cxMempoolRegister(cfg_mp, doc, (cx_destructor_func)xmlFreeDoc); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | DavCfgRepository *repos_begin = NULL; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | DavCfgRepository *repos_end = NULL; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | DavCfgKey *keys_begin = NULL; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | DavCfgKey *keys_end = NULL; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | DavCfgNamespace *namespaces_begin = NULL; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | DavCfgNamespace *namespaces_end = NULL; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | xmlNode *xml_root = xmlDocGetRootElement(doc); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | xmlNode *node = xml_root->children; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | int ret = 0; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | while(node && !ret) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | if(node->type == XML_ELEMENT_NODE) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | if(xstreq(node->name, "repository")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | ret = load_repository(config, &repos_begin, &repos_end, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | } else if(xstreq(node->name, "key")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | ret = load_key(config, &keys_begin, &keys_end, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | } else if (xstreq(node->name, "http-proxy")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | config->http_proxy = cxCalloc(config->mp->allocator, 1, sizeof(DavCfgProxy)); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | ret = load_proxy(config, config->http_proxy, node, DAV_HTTP_PROXY); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | } else if (xstreq(node->name, "https-proxy")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | config->https_proxy = cxCalloc(config->mp->allocator, 1, sizeof(DavCfgProxy)); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | ret = load_proxy(config, config->https_proxy, node, DAV_HTTPS_PROXY); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | } else if (xstreq(node->name, "namespace")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | ret = load_namespace(config, &namespaces_begin, &namespaces_end, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | } else if (xstreq(node->name, "secretstore")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | ret = load_secretstore(config, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | } else { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | fprintf(stderr, "Unknown config element: %s\n", node->name); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | ret = 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | node = node->next; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | config->repositories = repos_begin; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | config->keys = keys_begin; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | config->namespaces = namespaces_begin; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | if(ret != 0 && error) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | *error = ret; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | cxMempoolDestroy(cfg_mp); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | return config; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | |
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
176 | void dav_config_free(DavConfig *config) { |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
177 | cxMempoolDestroy(config->mp); |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
178 | } |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
179 | |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | CxBuffer* dav_config2buf(DavConfig *config) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | xmlChar* xmlText = NULL; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | int textLen = 0; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | xmlDocDumpFormatMemory(config->doc, &xmlText, &textLen, 1); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | if(!xmlText) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | return NULL; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | CxBuffer *buf = cxBufferCreate(NULL, textLen, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | cxBufferWrite(xmlText, 1, textLen, buf); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | xmlFree(xmlText); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | return buf; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | static int repo_add_config( |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | DavConfig *config, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | DavCfgRepository *repo, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | xmlNode* node) |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | unsigned short lineno = node->line; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | char *key = (char*)node->name; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | char *value = util_xml_get_text(node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | /* every key needs a value */ |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | if(!value) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | /* TODO: maybe this should only be reported, if the key is valid |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | * But this makes the code very ugly. |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | */ |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | print_error(lineno, "missing value for config element: %s\n", key); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | return 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | if(xstreq(key, "name")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | dav_cfg_string_set_value(config, &repo->name, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | } else if(xstreq(key, "url")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | dav_cfg_string_set_value(config, &repo->url, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | } else if(xstreq(key, "user")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | dav_cfg_string_set_value(config, &repo->user, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | } else if(xstreq(key, "password")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | dav_cfg_string_set_value(config, &repo->password, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | } else if(xstreq(key, "stored-user")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | dav_cfg_string_set_value(config, &repo->stored_user, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | } else if(xstreq(key, "default-key")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | dav_cfg_string_set_value(config, &repo->default_key, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | } else if(xstreq(key, "full-encryption")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | dav_cfg_bool_set_value(config, &repo->full_encryption, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | } else if(xstreq(key, "content-encryption")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | dav_cfg_bool_set_value(config, &repo->content_encryption, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | } else if(xstreq(key, "decrypt-content")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | dav_cfg_bool_set_value(config, &repo->decrypt_content, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | } else if(xstreq(key, "decrypt-name")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | dav_cfg_bool_set_value(config, &repo->decrypt_name, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | } else if(xstreq(key, "cert")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | dav_cfg_string_set_value(config, &repo->cert, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | } else if(xstreq(key, "verification")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237 | dav_cfg_bool_set_value(config, &repo->verification, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | } else if(xstreq(key, "ssl-version")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | repo->ssl_version.node = node; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240 | if(xstrEQ(value, "TLSv1")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | repo->ssl_version.value = CURL_SSLVERSION_TLSv1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | } else if(xstrEQ(value, "SSLv2")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | repo->ssl_version.value = CURL_SSLVERSION_SSLv2; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | } else if(xstrEQ(value, "SSLv3")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | repo->ssl_version.value = CURL_SSLVERSION_SSLv3; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | #if LIBCURL_VERSION_MAJOR * 1000 + LIBCURL_VERSION_MINOR >= 7034 |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | else if(xstrEQ(value, "TLSv1.0")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | repo->ssl_version.value = CURL_SSLVERSION_TLSv1_0; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | } else if(xstrEQ(value, "TLSv1.1")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | repo->ssl_version.value = CURL_SSLVERSION_TLSv1_1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | } else if(xstrEQ(value, "TLSv1.2")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | repo->ssl_version.value = CURL_SSLVERSION_TLSv1_2; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255 | #endif |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | #if LIBCURL_VERSION_MAJOR * 1000 + LIBCURL_VERSION_MINOR >= 7052 |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | else if(xstrEQ(value, "TLSv1.3")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258 | repo->ssl_version.value = CURL_SSLVERSION_TLSv1_3; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | #endif |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | else { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | print_warning(lineno, "unknown ssl version: %s\n", value); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | repo->ssl_version.value = CURL_SSLVERSION_DEFAULT; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265 | } else if(xstreq(key, "authmethods")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
266 | repo->authmethods.node = node; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
267 | repo->authmethods.value = CURLAUTH_NONE; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
268 | const char *delims = " \t\r\n"; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
269 | char *meths = strdup(value); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270 | char *meth = strtok(meths, delims); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271 | while (meth) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272 | if(xstrEQ(meth, "basic")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | repo->authmethods.value |= CURLAUTH_BASIC; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | } else if(xstrEQ(meth, "digest")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | repo->authmethods.value |= CURLAUTH_DIGEST; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
276 | } else if(xstrEQ(meth, "negotiate")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
277 | repo->authmethods.value |= CURLAUTH_GSSNEGOTIATE; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | } else if(xstrEQ(meth, "ntlm")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | repo->authmethods.value |= CURLAUTH_NTLM; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280 | } else if(xstrEQ(meth, "any")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281 | repo->authmethods.value = CURLAUTH_ANY; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | } else if(xstrEQ(meth, "none")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283 | /* skip */ |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
284 | } else { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
285 | print_warning(lineno, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
286 | "unknown authentication method: %s\n", meth); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
287 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
288 | meth = strtok(NULL, delims); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | free(meths); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291 | } else { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
292 | print_error(lineno, "unkown repository config element: %s\n", key); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
293 | return 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
294 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295 | return 0; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
296 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
297 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
298 | static int load_repository( |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
299 | DavConfig *config, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
300 | DavCfgRepository **list_begin, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
301 | DavCfgRepository **list_end, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
302 | xmlNode *reponode) |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
303 | { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
304 | DavCfgRepository *repo = dav_repository_new(config); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
305 | repo->node = reponode; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
306 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
307 | // add repo config from child nodes |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
308 | xmlNode *node = reponode->children; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
309 | int ret = 0; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
310 | while(node && !ret) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
311 | if(node->type == XML_ELEMENT_NODE) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
312 | ret = repo_add_config(config, repo, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
313 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
314 | node = node->next; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
315 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
316 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
317 | // success: add repo to the configuration, error: free repo |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
318 | if(ret) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
319 | return 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
320 | } else { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
321 | cx_linked_list_add( |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
322 | (void**)list_begin, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
323 | (void**)list_end, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
324 | offsetof(DavCfgRepository, prev), |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
325 | offsetof(DavCfgRepository, next), |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
326 | repo); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
327 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
328 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
329 | return 0; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
330 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
331 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
332 | static xmlNode* addXmlNode(xmlNode *node, const char *name, cxmutstr content) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
333 | xmlNode *text1 = xmlNewDocText(node->doc, BAD_CAST "\t\t"); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
334 | xmlAddChild(node, text1); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
335 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
336 | cxmutstr ctn = cx_strdup(cx_strcast(content)); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
337 | xmlNode *newNode = xmlNewChild(node, NULL, BAD_CAST name, BAD_CAST ctn.ptr); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
338 | free(ctn.ptr); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
339 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
340 | xmlNode *text2 = xmlNewDocText(node->doc, BAD_CAST "\n"); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
341 | xmlAddChild(node, text2); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
342 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
343 | return newNode; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
344 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
345 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
346 | void dav_config_add_repository(DavConfig *config, DavCfgRepository *repo) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
347 | if(repo->node) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
348 | fprintf(stderr, "Error: dav_config_add_repository: node already exists\n"); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
349 | return; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
350 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
351 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
352 | xmlNode *repoNode = xmlNewNode(NULL, BAD_CAST "repository"); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
353 | xmlNode *rtext1 = xmlNewDocText(config->doc, BAD_CAST "\n"); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
354 | xmlAddChild(repoNode, rtext1); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
355 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
356 | if(repo->name.value.ptr) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
357 | repo->name.node = addXmlNode(repoNode, "name", repo->name.value); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
358 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
359 | if(repo->url.value.ptr) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
360 | repo->url.node = addXmlNode(repoNode, "url", repo->url.value); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
361 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
362 | if(repo->user.value.ptr) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
363 | repo->user.node = addXmlNode(repoNode, "user", repo->user.value); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
364 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
365 | if(repo->password.value.ptr) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
366 | repo->password.node = addXmlNode(repoNode, "password", repo->password.value); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
367 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
368 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
369 | if(repo->stored_user.value.ptr) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
370 | repo->stored_user.node = addXmlNode(repoNode, "stored-user", repo->stored_user.value); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
371 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
372 | if(repo->default_key.value.ptr) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
373 | repo->default_key.node = addXmlNode(repoNode, "default-key", repo->default_key.value); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
374 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
375 | if(repo->cert.value.ptr) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
376 | repo->cert.node = addXmlNode(repoNode, "cert", repo->cert.value); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
377 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
378 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
379 | // TODO: implement booleans |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
380 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
381 | // indent closing tag |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
382 | xmlNode *rtext2 = xmlNewDocText(config->doc, BAD_CAST "\t"); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
383 | xmlAddChild(repoNode, rtext2); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
384 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
385 | // add repository to internal list |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
386 | DavCfgRepository **list_begin = &config->repositories; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
387 | cx_linked_list_add( |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
388 | (void**)list_begin, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
389 | NULL, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
390 | offsetof(DavCfgRepository, prev), |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
391 | offsetof(DavCfgRepository, next), |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
392 | repo); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
393 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
394 | // add repository element to the xml document |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
395 | xmlNode *xml_root = xmlDocGetRootElement(config->doc); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
396 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
397 | xmlNode *text1 = xmlNewDocText(config->doc, BAD_CAST "\n\t"); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
398 | xmlAddChild(xml_root, text1); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
399 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
400 | xmlAddChild(xml_root, repoNode); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
401 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
402 | xmlNode *text2 = xmlNewDocText(config->doc, BAD_CAST "\n"); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
403 | xmlAddChild(xml_root, text2); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
404 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
405 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
406 | DavCfgRepository* dav_repository_new(DavConfig *config) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
407 | DavCfgRepository *repo = cxMalloc(config->mp->allocator, sizeof(DavCfgRepository)); |
804
1e24f187c362
fix indentation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
803
diff
changeset
|
408 | memset(repo, 0, sizeof(DavCfgRepository)); |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
409 | repo->decrypt_name.value = false; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
410 | repo->decrypt_content.value = true; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
411 | repo->decrypt_properties.value = false; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
412 | repo->verification.value = true; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
413 | repo->ssl_version.value = CURL_SSLVERSION_DEFAULT; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
414 | repo->authmethods.value = CURLAUTH_BASIC; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
415 | return repo; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
416 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
417 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
418 | void dav_repository_free(DavConfig *config, DavCfgRepository *repo) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
419 | // TODO |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
420 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
421 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
422 | void dav_repository_remove_and_free(DavConfig *config, DavCfgRepository *repo) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
423 | if(repo->prev) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
424 | repo->prev->next = repo->next; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
425 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
426 | if(repo->next) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
427 | repo->next->prev = repo->prev; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
428 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
429 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
430 | if(repo->node) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
431 | // TODO: remove newline after repo node |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
432 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
433 | xmlUnlinkNode(repo->node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
434 | xmlFreeNode(repo->node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
435 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
436 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
437 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
438 | int dav_repository_get_flags(DavCfgRepository *repo) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
439 | int flags = 0; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
440 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
441 | DavBool encrypt_content = FALSE; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
442 | DavBool encrypt_name = FALSE; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
443 | DavBool encrypt_properties = FALSE; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
444 | DavBool decrypt_content = FALSE; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
445 | DavBool decrypt_name = FALSE; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
446 | DavBool decrypt_properties = FALSE; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
447 | if(repo->full_encryption.value) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
448 | encrypt_content = TRUE; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
449 | encrypt_name = TRUE; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
450 | encrypt_properties = TRUE; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
451 | decrypt_content = TRUE; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
452 | decrypt_name = TRUE; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
453 | decrypt_properties = TRUE; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
454 | } else if(repo->content_encryption.value) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
455 | encrypt_content = TRUE; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
456 | decrypt_content = TRUE; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
457 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
458 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
459 | if(decrypt_content) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
460 | flags |= DAV_SESSION_DECRYPT_CONTENT; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
461 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
462 | if(decrypt_name) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
463 | flags |= DAV_SESSION_DECRYPT_NAME; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
464 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
465 | if(decrypt_properties) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
466 | flags |= DAV_SESSION_DECRYPT_PROPERTIES; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
467 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
468 | if(encrypt_content) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
469 | flags |= DAV_SESSION_ENCRYPT_CONTENT; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
470 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
471 | if(encrypt_name) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
472 | flags |= DAV_SESSION_ENCRYPT_NAME; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
473 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
474 | if(encrypt_properties) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
475 | flags |= DAV_SESSION_ENCRYPT_PROPERTIES; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
476 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
477 | return flags; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
478 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
479 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
480 | void dav_repository_set_url(DavConfig *config, DavCfgRepository *repo, cxstring newurl) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
481 | if(repo->url.value.ptr) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
482 | cxFree(config->mp->allocator, repo->url.value.ptr); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
483 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
484 | repo->url.value = cx_strdup_a(config->mp->allocator, newurl); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
485 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
486 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
487 | void dav_repository_set_auth(DavConfig *config, DavCfgRepository *repo, cxstring user, cxstring password) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
488 | const CxAllocator *a = config->mp->allocator; |
827
d9928f11970f
fix load_config stores wrong xml doc pointer in the config object
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
826
diff
changeset
|
489 | if(user.length > 0) { |
d9928f11970f
fix load_config stores wrong xml doc pointer in the config object
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
826
diff
changeset
|
490 | repo->user.value = cx_strdup_a(a, user); |
d9928f11970f
fix load_config stores wrong xml doc pointer in the config object
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
826
diff
changeset
|
491 | } |
d9928f11970f
fix load_config stores wrong xml doc pointer in the config object
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
826
diff
changeset
|
492 | if(password.length > 0) { |
d9928f11970f
fix load_config stores wrong xml doc pointer in the config object
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
826
diff
changeset
|
493 | char *pwenc = util_base64encode(password.ptr, password.length); |
d9928f11970f
fix load_config stores wrong xml doc pointer in the config object
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
826
diff
changeset
|
494 | repo->password.value = cx_strdup_a(a, cx_str(pwenc)); |
d9928f11970f
fix load_config stores wrong xml doc pointer in the config object
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
826
diff
changeset
|
495 | free(pwenc); |
d9928f11970f
fix load_config stores wrong xml doc pointer in the config object
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
826
diff
changeset
|
496 | } |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
497 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
498 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
499 | cxmutstr dav_repository_get_decodedpassword(DavCfgRepository *repo) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
500 | cxmutstr pw = { NULL, 0 }; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
501 | if(repo->password.value.ptr) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
502 | pw = cx_mutstr(util_base64decode(repo->password.value.ptr)); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
503 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
504 | return pw; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
505 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
506 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
507 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
508 | static int load_key( |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
509 | DavConfig *config, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
510 | DavCfgKey **list_begin, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
511 | DavCfgKey **list_end, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
512 | xmlNode *keynode) |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
513 | { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
514 | xmlNode *node = keynode->children; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
515 | DavCfgKey *key = cxMalloc(config->mp->allocator, sizeof(DavCfgKey)); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
516 | memset(key, 0, sizeof(DavCfgKey)); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
517 | key->type = DAV_KEY_TYPE_AES256; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
518 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
519 | int error = 0; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
520 | while(node) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
521 | if(node->type == XML_ELEMENT_NODE) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
522 | if(xstreq(node->name, "name")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
523 | dav_cfg_string_set_value(config, &key->name, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
524 | } else if(xstreq(node->name, "file")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
525 | dav_cfg_string_set_value(config, &key->file, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
526 | } else if(xstreq(node->name, "type")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
527 | const char *value = util_xml_get_text(node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
528 | key->type_node = node; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
529 | if(!strcmp(value, "aes128")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
530 | key->type = DAV_KEY_TYPE_AES128; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
531 | } else if(!strcmp(value, "aes256")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
532 | key->type = DAV_KEY_TYPE_AES256; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
533 | } else { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
534 | print_error(node->line, "unknown key type %s\n", value); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
535 | error = 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
536 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
537 | } else { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
538 | key->unknown_elements++; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
539 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
540 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
541 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
542 | node = node->next; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
543 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
544 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
545 | if(!key->name.value.ptr) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
546 | error = 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
547 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
548 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
549 | if(!error) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
550 | error = 0; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
551 | size_t expected_length = 0; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
552 | if(key->type == DAV_KEY_TYPE_AES128) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
553 | expected_length = 16; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
554 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
555 | if(key->type == DAV_KEY_TYPE_AES256) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
556 | expected_length = 32; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
557 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
558 | /* |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
559 | if(key->length < expected_length) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
560 | print_error(keynode->line, "key %s is too small (%zu < %zu)\n", |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
561 | key->name, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
562 | key->length, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
563 | expected_length); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
564 | error = 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
565 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
566 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
567 | // add key to context |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
568 | if(!error) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
569 | cxMapPut(keys, cx_hash_key_str(key->name), key); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
570 | dav_context_add_key(context, key); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
571 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
572 | */ |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
573 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
574 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
575 | // cleanup |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
576 | if(error) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
577 | return 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
578 | } else { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
579 | // add key to the configuration |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
580 | cx_linked_list_add( |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
581 | (void**)list_begin, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
582 | (void**)list_end, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
583 | offsetof(DavCfgKey, prev), |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
584 | offsetof(DavCfgKey, next), |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
585 | key); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
586 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
587 | return 0; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
588 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
589 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
590 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
591 | static int load_proxy( |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
592 | DavConfig *config, DavCfgProxy *proxy, xmlNode *proxynode, int type) |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
593 | { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
594 | const char *stype; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
595 | if(type == DAV_HTTPS_PROXY) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
596 | stype = "https"; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
597 | } else if(type == DAV_HTTP_PROXY) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
598 | stype = "http"; |
805
bff983370565
make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
804
diff
changeset
|
599 | } else { |
bff983370565
make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
804
diff
changeset
|
600 | fprintf(stderr, "unknown proxy type\n"); |
bff983370565
make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
804
diff
changeset
|
601 | return 1; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
602 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
603 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
604 | if(!proxy) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
605 | // no xml error - so report this directly via fprintf |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
606 | fprintf(stderr, "no memory reserved for %s proxy.\n", stype); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
607 | return 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
608 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
609 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
610 | xmlNode *node = proxynode->children; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
611 | int ret = 0; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
612 | while(node && !ret) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
613 | if(node->type == XML_ELEMENT_NODE) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
614 | int reportmissingvalue = 0; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
615 | if(xstreq(node->name, "url")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
616 | reportmissingvalue = dav_cfg_string_set_value(config, &proxy->url, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
617 | } else if(xstreq(node->name, "user")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
618 | reportmissingvalue = dav_cfg_string_set_value(config, &proxy->user, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
619 | } else if(xstreq(node->name, "password")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
620 | reportmissingvalue = dav_cfg_string_set_value(config, &proxy->password, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
621 | } else if(xstreq(node->name, "no")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
622 | reportmissingvalue = dav_cfg_string_set_value(config, &proxy->noproxy, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
623 | } else { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
624 | proxy->unknown_elements++; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
625 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
626 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
627 | if (reportmissingvalue) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
628 | print_error(node->line, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
629 | "missing value for proxy configuration element: %s\n", |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
630 | node->name); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
631 | ret = 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
632 | break; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
633 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
634 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
635 | node = node->next; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
636 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
637 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
638 | if(!ret && !proxy->url.value.ptr) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
639 | print_error(proxynode->line, "missing url for %s proxy.\n", stype); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
640 | return 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
641 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
642 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
643 | return ret; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
644 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
645 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
646 | static char* get_attr_content(xmlNode *node) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
647 | // TODO: remove code duplication (util_xml_get_text) |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
648 | while(node) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
649 | if(node->type == XML_TEXT_NODE) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
650 | return (char*)node->content; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
651 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
652 | node = node->next; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
653 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
654 | return NULL; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
655 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
656 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
657 | static int load_namespace( |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
658 | DavConfig *config, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
659 | DavCfgNamespace **list_begin, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
660 | DavCfgNamespace **list_end, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
661 | xmlNode *node) |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
662 | { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
663 | const char *prefix = NULL; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
664 | const char *uri = NULL; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
665 | xmlAttr *attr = node->properties; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
666 | while(attr) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
667 | if(attr->type == XML_ATTRIBUTE_NODE) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
668 | char *value = get_attr_content(attr->children); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
669 | if(!value) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
670 | print_error( |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
671 | node->line, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
672 | "missing value for attribute %s\n", (char*)attr->name); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
673 | return 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
674 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
675 | if(xstreq(attr->name, "prefix")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
676 | prefix = value; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
677 | } else if(xstreq(attr->name, "uri")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
678 | uri = value; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
679 | } else { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
680 | print_error( |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
681 | node->line, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
682 | "unexpected attribute %s\n", (char*)attr->name); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
683 | return 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
684 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
685 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
686 | attr = attr->next; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
687 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
688 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
689 | if(!prefix) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
690 | print_error(node->line, "missing prefix attribute\n"); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
691 | return 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
692 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
693 | if(!uri) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
694 | print_error(node->line, "missing uri attribute\n"); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
695 | return 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
696 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
697 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
698 | DavCfgNamespace *ns = cxMalloc(config->mp->allocator, sizeof(DavCfgNamespace)); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
699 | memset(ns, 0, sizeof(DavCfgNamespace)); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
700 | ns->node = node; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
701 | ns->prefix = cx_strdup_a(config->mp->allocator, cx_str(prefix)); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
702 | ns->uri = cx_strdup_a(config->mp->allocator, cx_str(uri)); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
703 | cx_linked_list_add( |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
704 | (void**)list_begin, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
705 | (void**)list_end, |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
706 | offsetof(DavCfgNamespace, prev), |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
707 | offsetof(DavCfgNamespace, next), |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
708 | ns); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
709 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
710 | return 0; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
711 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
712 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
713 | static int load_secretstore(DavConfig *config, xmlNode *node) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
714 | // currently only one secretstore is supported |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
715 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
716 | if(config->secretstore) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
717 | return 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
718 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
719 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
720 | config->secretstore = cxCalloc(config->mp->allocator, 1, sizeof(DavCfgSecretStore)); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
721 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
722 | node = node->children; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
723 | int error = 0; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
724 | while(node) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
725 | if(node->type == XML_ELEMENT_NODE) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
726 | if(xstreq(node->name, "unlock-command")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
727 | dav_cfg_string_set_value(config, &config->secretstore->unlock_cmd, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
728 | } else if(xstreq(node->name, "lock-command")) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
729 | dav_cfg_string_set_value(config, &config->secretstore->lock_cmd, node); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
730 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
731 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
732 | node = node->next; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
733 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
734 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
735 | return error; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
736 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
737 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
738 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
739 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
740 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
741 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
742 | DavCfgRepository* dav_config_get_repository(DavConfig *config, cxstring name) { |
826
b6e9fd3f1951
fix dav add-repo crash in case .dav/config.xml doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
823
diff
changeset
|
743 | if(!config) { |
b6e9fd3f1951
fix dav add-repo crash in case .dav/config.xml doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
823
diff
changeset
|
744 | return NULL; |
b6e9fd3f1951
fix dav add-repo crash in case .dav/config.xml doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
823
diff
changeset
|
745 | } |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
746 | DavCfgRepository *repo = config->repositories; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
747 | while(repo) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
748 | if(!cx_strcmp(cx_strcast(repo->name.value), name)) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
749 | return repo; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
750 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
751 | repo = repo->next; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
752 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
753 | return NULL; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
754 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
755 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
756 | DavCfgRepository* dav_config_url2repo(DavConfig *config, const char *url, char **path) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
757 | cxmutstr p; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
758 | DavCfgRepository *repo = dav_config_url2repo_s(config, cx_str(url), &p); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
759 | *path = p.ptr; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
760 | return repo; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
761 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
762 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
763 | DavCfgRepository* dav_config_url2repo_s(DavConfig *config, cxstring url, cxmutstr *path) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
764 | path->ptr = NULL; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
765 | path->length = 0; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
766 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
767 | int s; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
768 | if(cx_strprefix(url, CX_STR("http://"))) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
769 | s = 7; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
770 | } else if(cx_strprefix(url, CX_STR("https://"))) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
771 | s = 8; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
772 | } else { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
773 | s = 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
774 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
775 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
776 | // split URL into repository and path |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
777 | cxstring r = cx_strsubs(url, s); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
778 | cxstring p = cx_strchr(r, '/'); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
779 | r = cx_strsubsl(url, 0, url.length-p.length); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
780 | if(p.length == 0) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
781 | p = cx_strn("/", 1); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
782 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
783 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
784 | DavCfgRepository *repo = dav_config_get_repository(config, r); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
785 | if(repo) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
786 | *path = cx_strdup(p); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
787 | } else { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
788 | // TODO: who is responsible for freeing this repository? |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
789 | // how can the callee know, if he has to call free()? |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
790 | repo = dav_repository_new(config); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
791 | repo->name.value = cx_strdup_a(config->mp->allocator, CX_STR("")); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
792 | if(url.ptr[url.length-1] == '/') { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
793 | repo->url.value = cx_strdup_a(config->mp->allocator, url); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
794 | *path = cx_strdup(CX_STR("/")); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
795 | } else if (cx_strchr(url, '/').length > 0) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
796 | // TODO: fix the following workaround after |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
797 | // fixing the inconsistent behavior of util_url_*() |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
798 | cxstring repo_url = util_url_base_s(url); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
799 | repo->url.value = cx_strdup_a(config->mp->allocator, repo_url); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
800 | *path = cx_strdup(util_url_path_s(url)); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
801 | } else { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
802 | repo->url.value = cx_strdup(url); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
803 | *path = cx_strdup(CX_STR("/")); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
804 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
805 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
806 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
807 | return repo; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
808 | } |
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
809 | |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
810 | int dav_config_keytype(DavCfgKeyType type) { |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
811 | switch(type) { |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
812 | default: break; |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
813 | case DAV_KEY_TYPE_AES256: return DAV_KEY_AES256; |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
814 | case DAV_KEY_TYPE_AES128: return DAV_KEY_AES128; |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
815 | } |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
816 | return 0; |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
817 | } |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
818 | |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
819 | int dav_config_register_keys(DavConfig *config, DavContext *ctx, dav_loadkeyfile_func loadkey) { |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
820 | for(DavCfgKey *key=config->keys;key;key=key->next) { |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
821 | char *file = cx_strdup_m(key->file.value).ptr; |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
822 | cxmutstr keycontent = loadkey(file); |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
823 | free(file); |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
824 | |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
825 | // TODO: check key length |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
826 | |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
827 | if(!keycontent.ptr) { |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
828 | return 1; |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
829 | } |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
830 | |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
831 | DavKey *davkey = calloc(1, sizeof(DavKey)); |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
832 | davkey->name = cx_strdup_m(key->name.value).ptr; |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
833 | davkey->type = dav_config_keytype(key->type); |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
834 | davkey->data = keycontent.ptr; |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
835 | davkey->length = keycontent.length; |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
836 | |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
837 | dav_context_add_key(ctx, davkey); |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
838 | } |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
839 | return 0; |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
840 | } |
823
04c60a353331
add configured namespaces to the dav context
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
805
diff
changeset
|
841 | |
04c60a353331
add configured namespaces to the dav context
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
805
diff
changeset
|
842 | int dav_config_register_namespaces(DavConfig *config, DavContext *ctx) { |
04c60a353331
add configured namespaces to the dav context
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
805
diff
changeset
|
843 | DavCfgNamespace *ns = config->namespaces; |
04c60a353331
add configured namespaces to the dav context
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
805
diff
changeset
|
844 | while(ns) { |
04c60a353331
add configured namespaces to the dav context
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
805
diff
changeset
|
845 | dav_add_namespace(ctx, ns->prefix.ptr, ns->uri.ptr); |
04c60a353331
add configured namespaces to the dav context
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
805
diff
changeset
|
846 | ns = ns->next; |
04c60a353331
add configured namespaces to the dav context
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
805
diff
changeset
|
847 | } |
04c60a353331
add configured namespaces to the dav context
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
805
diff
changeset
|
848 | return 0; |
04c60a353331
add configured namespaces to the dav context
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
805
diff
changeset
|
849 | } |