414:99a34860c105 | 415:d938228c382e |
---|---|
28 | 28 |
29 #include <stdio.h> | 29 #include <stdio.h> |
30 #include <stdlib.h> | 30 #include <stdlib.h> |
31 #include <string.h> | 31 #include <string.h> |
32 | 32 |
33 #include <ucx/string.h> | 33 #include <cx/string.h> |
34 #include <ucx/utils.h> | 34 #include <cx/utils.h> |
35 #include <ucx/map.h> | 35 #include <cx/map.h> |
36 #include <cx/hash_map.h> | |
36 | 37 |
37 #include "requestparser.h" | 38 #include "requestparser.h" |
38 #include "webdav.h" | 39 #include "webdav.h" |
40 | |
41 #include "../util/pool.h" | |
39 | 42 |
40 #define xstreq(a, b) !strcmp((const char*)a, (const char*)b) | 43 #define xstreq(a, b) !strcmp((const char*)a, (const char*)b) |
41 | 44 |
42 void proplist_free(pool_handle_t *pool, WebdavPList *list) { | 45 void proplist_free(pool_handle_t *pool, WebdavPList *list) { |
43 while(list) { | 46 while(list) { |
61 } | 64 } |
62 | 65 |
63 static int parse_prop( | 66 static int parse_prop( |
64 Session *sn, | 67 Session *sn, |
65 xmlNode *node, | 68 xmlNode *node, |
66 UcxMap *propmap, | 69 CxMap *propmap, |
67 WebdavPList **plist_begin, | 70 WebdavPList **plist_begin, |
68 WebdavPList **plist_end, | 71 WebdavPList **plist_end, |
69 size_t *propcount, | 72 size_t *propcount, |
70 int proppatch, | 73 int proppatch, |
71 int *error) | 74 int *error) |
78 | 81 |
79 const char* ns = (const char*)pnode->ns->href; | 82 const char* ns = (const char*)pnode->ns->href; |
80 const char* name = (const char*)pnode->name; | 83 const char* name = (const char*)pnode->name; |
81 | 84 |
82 // check for prop duplicates | 85 // check for prop duplicates |
83 UcxKey k = webdav_property_key((const char*)ns, (const char*)name); | 86 CxHashKey k = webdav_property_key((const char*)ns, (const char*)name); |
84 if(!k.data) { | 87 if(!k.data.bytes) { |
85 *error = proppatch ? PROPPATCH_PARSER_OOM : PROPFIND_PARSER_OOM; | 88 *error = proppatch ? PROPPATCH_PARSER_OOM : PROPFIND_PARSER_OOM; |
86 return 1; | 89 return 1; |
87 } | 90 } |
88 void *c = ucx_map_get(propmap, k); | 91 void *c = cxMapGet(propmap, k); |
89 if(!c) { | 92 if(!c) { |
90 if(ucx_map_put(propmap, k, (void*)1)) { | 93 if(cxMapPut(propmap, k, (void*)1)) { |
91 *error = proppatch ? PROPPATCH_PARSER_OOM : PROPFIND_PARSER_OOM; | 94 *error = proppatch ? PROPPATCH_PARSER_OOM : PROPFIND_PARSER_OOM; |
92 } | 95 } |
93 | 96 |
94 // no duplicate | 97 // no duplicate |
95 // create property elment and add it to the list | 98 // create property elment and add it to the list |
109 } | 112 } |
110 } else if(proppatch) { | 113 } else if(proppatch) { |
111 *error = PROPPATCH_PARSER_DUPLICATE; | 114 *error = PROPPATCH_PARSER_DUPLICATE; |
112 } | 115 } |
113 | 116 |
114 free((void*)k.data); | 117 free((void*)k.data.str); |
115 if(*error) { | 118 if(*error) { |
116 return 1; | 119 return 1; |
117 } | 120 } |
118 } | 121 } |
119 return 0; | 122 return 0; |
154 *error = PROPFIND_PARSER_NO_PROPFIND; | 157 *error = PROPFIND_PARSER_NO_PROPFIND; |
155 xmlFreeDoc(doc); | 158 xmlFreeDoc(doc); |
156 return NULL; | 159 return NULL; |
157 } | 160 } |
158 | 161 |
159 UcxMap *propmap = ucx_map_new(32); | 162 CxAllocator *a = pool_allocator(sn->pool); |
163 CxMap *propmap = cxHashMapCreate(a, 32); // value: intptr_t | |
160 if(!propmap) { | 164 if(!propmap) { |
161 *error = PROPFIND_PARSER_OOM; | 165 *error = PROPFIND_PARSER_OOM; |
162 xmlFreeDoc(doc); | 166 xmlFreeDoc(doc); |
163 return NULL; | 167 return NULL; |
164 } | 168 } |
188 } | 192 } |
189 } | 193 } |
190 node = node->next; | 194 node = node->next; |
191 } | 195 } |
192 | 196 |
193 ucx_map_free(propmap); // no allocated content must be freed | 197 cxMapDestroy(propmap); // no allocated content must be freed |
194 | 198 |
195 if(ret) { | 199 if(ret) { |
196 // parse_prop failed | 200 // parse_prop failed |
197 // in this case, error is already set | 201 // in this case, error is already set |
198 xmlFreeDoc(doc); | 202 xmlFreeDoc(doc); |
293 } | 297 } |
294 | 298 |
295 // ret vars | 299 // ret vars |
296 *error = 0; | 300 *error = 0; |
297 | 301 |
298 UcxMap *propmap = ucx_map_new(32); // map for duplicate checking | 302 CxAllocator *a = pool_allocator(sn->pool); |
303 // map for duplicate checking | |
304 // value type: intptr_t | |
305 CxMap *propmap = cxHashMapCreate(a, 32); | |
299 if(!propmap) { | 306 if(!propmap) { |
300 *error = PROPPATCH_PARSER_OOM; | 307 *error = PROPPATCH_PARSER_OOM; |
301 xmlFreeDoc(doc); | 308 xmlFreeDoc(doc); |
302 return NULL; | 309 return NULL; |
303 } | 310 } |
348 } | 355 } |
349 } | 356 } |
350 node = node->next; | 357 node = node->next; |
351 } | 358 } |
352 | 359 |
353 ucx_map_free(propmap); // allocated content must not be freed | 360 cxMapDestroy(propmap); // allocated content must not be freed |
354 | 361 |
355 if(set_count + remove_count == 0) { | 362 if(set_count + remove_count == 0) { |
356 *error = PROPPATCH_PARSER_NO_PROPERTIES; | 363 *error = PROPPATCH_PARSER_NO_PROPERTIES; |
357 ret = 1; | 364 ret = 1; |
358 } | 365 } |