libidav/resource.c

changeset 818
bc782cca0759
parent 816
839fefbdedc7
child 822
f9e40f5c6daf
equal deleted inserted replaced
817:22257f6d06a3 818:bc782cca0759
125 125
126 void resource_free_properties(DavSession *sn, CxMap *properties) { 126 void resource_free_properties(DavSession *sn, CxMap *properties) {
127 if(!properties) return; 127 if(!properties) return;
128 128
129 CxIterator i = cxMapIteratorValues(properties); 129 CxIterator i = cxMapIteratorValues(properties);
130 DavProperty *property;
131 cx_foreach(DavProperty*, property, i) { 130 cx_foreach(DavProperty*, property, i) {
132 // TODO: free everything 131 // TODO: free everything
133 dav_session_free(sn, property); 132 dav_session_free(sn, property);
134 } 133 }
135 cxMapDestroy(properties); 134 cxMapDestroy(properties);
728 } 727 }
729 728
730 DavPropName* dav_get_property_names(DavResource *res, size_t *count) { 729 DavPropName* dav_get_property_names(DavResource *res, size_t *count) {
731 DavResourceData *data = res->data; 730 DavResourceData *data = res->data;
732 731
733 *count = data->properties->size; 732 *count = cxMapSize(data->properties);
734 DavPropName *names = dav_session_calloc( 733 DavPropName *names = dav_session_calloc(
735 res->session, 734 res->session,
736 *count, 735 *count,
737 sizeof(DavPropName)); 736 sizeof(DavPropName));
738 737
739 738
740 CxIterator i = cxMapIteratorValues(data->properties); 739 CxIterator i = cxMapIteratorValues(data->properties);
741 DavProperty *value;
742 int j = 0;
743 cx_foreach(DavProperty*, value, i) { 740 cx_foreach(DavProperty*, value, i) {
744 DavPropName *name = &names[j]; 741 DavPropName *name = &names[i.index];
745
746 name->ns = value->ns->name; 742 name->ns = value->ns->name;
747 name->name = value->name; 743 name->name = value->name;
748
749 j++;
750 } 744 }
751 745
752 qsort(names, *count, sizeof(DavPropName), compare_propname); 746 qsort(names, *count, sizeof(DavPropName), compare_propname);
753 747
754 return names; 748 return names;
996 990
997 // remove all properties 991 // remove all properties
998 if(data->crypto_remove) { 992 if(data->crypto_remove) {
999 CxIterator i = cxListIterator(data->crypto_remove); 993 CxIterator i = cxListIterator(data->crypto_remove);
1000 cx_foreach(DavProperty *, property, i) { 994 cx_foreach(DavProperty *, property, i) {
1001 if(crypto_props->size == 0) { 995 if(cxMapSize(crypto_props) == 0) {
1002 break; // map already empty, can't remove any more 996 break; // map already empty, can't remove any more
1003 } 997 }
1004 998
1005 cxmutstr key = dav_property_key(property->ns->name, property->name); 999 cxmutstr key = dav_property_key(property->ns->name, property->name);
1006 DavProperty *existing_prop = cxMapGet(crypto_props, cx_hash_key(key.ptr, key.length)); 1000 DavProperty *existing_prop = cxMapGet(crypto_props, cx_hash_key(key.ptr, key.length));
1507 1501
1508 CxBuffer *content = cxBufferCreate(NULL, 2048, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); 1502 CxBuffer *content = cxBufferCreate(NULL, 2048, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
1509 1503
1510 // create an xml document containing all properties 1504 // create an xml document containing all properties
1511 CxMap *nsmap = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 8); 1505 CxMap *nsmap = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 8);
1512 nsmap->simple_destructor = free; 1506 cxDefineDestructor(nsmap, free);
1513 cxMapPut(nsmap, cx_hash_key_str("DAV:"), strdup("D")); 1507 cxMapPut(nsmap, cx_hash_key_str("DAV:"), strdup("D"));
1514 1508
1515 cxBufferPutString(content, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); 1509 cxBufferPutString(content, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1516 cxBufferPutString(content, "<D:prop xmlns:D=\"DAV:\">\n"); 1510 cxBufferPutString(content, "<D:prop xmlns:D=\"DAV:\">\n");
1517 1511
1518 CxIterator i = cxMapIteratorValues(properties); 1512 CxIterator i = cxMapIteratorValues(properties);
1519 DavProperty *prop;
1520 cx_foreach(DavProperty*, prop, i) { 1513 cx_foreach(DavProperty*, prop, i) {
1521 DavXmlNode pnode; 1514 DavXmlNode pnode;
1522 pnode.type = DAV_XML_ELEMENT; 1515 pnode.type = DAV_XML_ELEMENT;
1523 pnode.namespace = prop->ns->name; 1516 pnode.namespace = prop->ns->name;
1524 pnode.name = prop->name; 1517 pnode.name = prop->name;
1598 property->ns->name = dav_session_strdup(sn, (const char*)n->ns->href); 1591 property->ns->name = dav_session_strdup(sn, (const char*)n->ns->href);
1599 property->ns->prefix = n->ns->prefix ? 1592 property->ns->prefix = n->ns->prefix ?
1600 dav_session_strdup(sn, (const char*)n->ns->prefix) : NULL; 1593 dav_session_strdup(sn, (const char*)n->ns->prefix) : NULL;
1601 property->value = n->children ? dav_convert_xml(sn, n->children) : NULL; 1594 property->value = n->children ? dav_convert_xml(sn, n->children) : NULL;
1602 1595
1603 cxmutstr key = dav_property_key(property->ns->name, property->name); 1596 cxmutstr propkey = dav_property_key(property->ns->name, property->name);
1604 cxMapPut(map, cx_hash_key(key.ptr, key.length), property); 1597 cxMapPut(map, cx_hash_key_cxstr(propkey), property);
1605 free(key.ptr); 1598 cx_strfree(&propkey);
1606 } 1599 }
1607 n = n->next; 1600 n = n->next;
1608 } 1601 }
1609 1602
1610 xmlFreeDoc(doc); 1603 xmlFreeDoc(doc);
1611 if(map->size == 0) { 1604 if(cxMapSize(map) == 0) {
1612 cxMapDestroy(map); 1605 cxMapDestroy(map);
1613 return NULL; 1606 return NULL;
1614 } 1607 }
1615 return map; 1608 return map;
1616 } 1609 }

mercurial