| 278 resource->path); |
278 resource->path); |
| 279 } |
279 } |
| 280 return resource->href; |
280 return resource->href; |
| 281 } |
281 } |
| 282 |
282 |
| 283 CxHashKey dav_resource_path_key(DavResource *res) { |
|
| 284 CxHashKey key = { NULL, 0, 0 }; |
|
| 285 if(res && res->path) { |
|
| 286 cxstring res_path = cx_str(res->path); |
|
| 287 if(res_path.length > 0 && res_path.ptr[res_path.length-1] == '/') { |
|
| 288 res_path.length--; |
|
| 289 } |
|
| 290 key = cx_hash_key(res_path.ptr, res_path.length); |
|
| 291 } |
|
| 292 return key; |
|
| 293 } |
|
| 294 |
|
| 295 CxTreeIterator dav_resource_iterator(DavResource *res) { |
|
| 296 return cx_tree_iterator(res, FALSE, offsetof(DavResource, children), offsetof(DavResource, next)); |
|
| 297 } |
|
| 298 |
|
| 299 CxTreeVisitor dav_resource_visitor(DavResource *res) { |
|
| 300 return cx_tree_visitor(res, offsetof(DavResource, children), offsetof(DavResource, next)); |
|
| 301 } |
|
| 302 |
|
| 303 CxMap* dav_resource_map(DavResource *res) { |
|
| 304 CxMap *map = cxHashMapCreate(res->session->mp->allocator, CX_STORE_POINTERS, 16); |
|
| 305 if(!map) { |
|
| 306 return NULL; |
|
| 307 } |
|
| 308 CxTreeIterator i = dav_resource_iterator(res); |
|
| 309 int error = 0; |
|
| 310 cx_foreach(DavResource *, res, i) { |
|
| 311 if(cxMapPut(map, res->path, res)) { |
|
| 312 error = 1; |
|
| 313 } |
|
| 314 } |
|
| 315 if(!error) { |
|
| 316 cxMapRehash(map); |
|
| 317 return map; |
|
| 318 } else { |
|
| 319 cxMapFree(map); |
|
| 320 return NULL; |
|
| 321 } |
|
| 322 } |
|
| 323 |
|
| 324 void resource_add_prop(DavResource *res, const char *ns, const char *name, DavXmlNode *val) { |
283 void resource_add_prop(DavResource *res, const char *ns, const char *name, DavXmlNode *val) { |
| 325 DavSession *sn = res->session; |
284 DavSession *sn = res->session; |
| 326 |
285 |
| 327 DavNamespace *namespace = dav_session_malloc(sn, sizeof(DavNamespace)); |
286 DavNamespace *namespace = dav_session_malloc(sn, sizeof(DavNamespace)); |
| 328 namespace->prefix = NULL; |
287 namespace->prefix = NULL; |
| 1637 property->ns->prefix = n->ns->prefix ? |
1596 property->ns->prefix = n->ns->prefix ? |
| 1638 dav_session_strdup(sn, (const char*)n->ns->prefix) : NULL; |
1597 dav_session_strdup(sn, (const char*)n->ns->prefix) : NULL; |
| 1639 property->value = n->children ? dav_convert_xml(sn, n->children) : NULL; |
1598 property->value = n->children ? dav_convert_xml(sn, n->children) : NULL; |
| 1640 |
1599 |
| 1641 cxmutstr propkey = dav_property_key(property->ns->name, property->name); |
1600 cxmutstr propkey = dav_property_key(property->ns->name, property->name); |
| 1642 cxMapPut(map, cx_hash_key_cxstr(propkey), property); |
1601 cxMapPut(map, propkey, property); |
| 1643 cx_strfree(&propkey); |
1602 cx_strfree(&propkey); |
| 1644 } |
1603 } |
| 1645 n = n->next; |
1604 n = n->next; |
| 1646 } |
1605 } |
| 1647 |
1606 |