# HG changeset patch # User Olaf Wintermann # Date 1458642254 -3600 # Node ID f3119e749549c20a4fb3aff75d77b79ff41e27d3 # Parent fdcbde1d7d65fa2b8fe0a1439e8f4f46a1c6cba6 fixed lazy propfind parser diff -r fdcbde1d7d65 -r f3119e749549 libidav/methods.c --- a/libidav/methods.c Mon Mar 21 16:37:10 2016 +0100 +++ b/libidav/methods.c Tue Mar 22 11:24:14 2016 +0100 @@ -377,10 +377,8 @@ if(n->type == XML_ELEMENT_NODE) { properties = ucx_list_append(properties, n); if(xstreq(n->name, "resourcetype")) { - xmlNode *rsnode = n->children; - if(rsnode && rsnode->type == XML_ELEMENT_NODE) { - // TODO: check content - iscollection = 1; + if(parse_resource_type(n)) { + iscollection = TRUE; } } else if(xstreq(n->ns->href, DAV_NS)) { if(xstreq(n->name, "crypto-name")) { @@ -612,11 +610,8 @@ if(n->type == XML_ELEMENT_NODE) { properties = ucx_list_append(properties, n); if(xstreq(n->name, "resourcetype")) { - xmlNode *rsnode = n->children; - if(rsnode && rsnode->type == XML_ELEMENT_NODE) { - // TODO: this is a ugly lazy hack - //resource_add_property(res, "DAV:", (char*)n->name, "collection"); - iscollection = 1; + if(parse_resource_type(n)) { + iscollection = TRUE; } } else if(xstreq(n->ns->href, DAV_NS)) { if(xstreq(n->name, "crypto-name")) { @@ -704,6 +699,21 @@ res->lastmodified = util_parse_lastmodified(lm); } +int parse_resource_type(xmlNode *node) { + int collection = FALSE; + xmlNode *c = node->children; + while(c) { + if(c->type == XML_ELEMENT_NODE) { + if(xstreq(c->ns->href, "DAV:") && xstreq(c->name, "collection")) { + collection = TRUE; + break; + } + } + c = c->next; + } + return collection; +} + /* ----------------------------- PROPPATCH ----------------------------- */ diff -r fdcbde1d7d65 -r f3119e749549 libidav/methods.h --- a/libidav/methods.h Mon Mar 21 16:37:10 2016 +0100 +++ b/libidav/methods.h Tue Mar 22 11:24:14 2016 +0100 @@ -96,6 +96,12 @@ int parse_response_tag(DavResource *resource, xmlNode *node); void set_davprops(DavResource *res); +/* + * parses the content of a resourcetype element + * returns 1 if the resourcetype is a collection, 0 otherwise + */ +int parse_resource_type(xmlNode *node); + UcxBuffer* create_proppatch_request(DavResourceData *data); UcxBuffer* create_crypto_proppatch_request(DavSession *sn, DavKey *key, char *name, char *hash);