libidav/resource.c

changeset 505
481802342fdf
parent 493
75a259ec8dea
child 518
cca3e7aa30ed
--- a/libidav/resource.c	Mon Feb 04 14:11:57 2019 +0100
+++ b/libidav/resource.c	Mon Feb 04 17:17:48 2019 +0100
@@ -239,15 +239,15 @@
     return resource->href;
 }
 
-void resource_add_property(DavResource *res, char *ns, char *name, xmlNode *val) {
+void resource_add_property(DavResource *res, const char *ns, const char *name, xmlNode *val) {
     if(!val) {
         return;
     }
     
-    UcxKey key = dav_property_key(ns, name);
+    sstr_t key = dav_property_key(ns, name);
     DavXmlNode *v = dav_convert_xml(res->session, val);
-    ucx_map_put(((DavResourceData*)res->data)->properties, key, v);
-    free(key.data);
+    ucx_map_sstr_put(((DavResourceData*)res->data)->properties, key, v);
+    free(key.ptr);
 }
 
 void resource_add_string_property(DavResource *res, char *ns, char *name, char *val) {
@@ -255,16 +255,17 @@
         return;
     }
     
-    UcxKey key = dav_property_key(ns, name);
+    sstr_t key = dav_property_key(ns, name);
     DavXmlNode *v = dav_text_node(res->session, val);
-    ucx_map_put(((DavResourceData*)res->data)->properties, key, v);
-    free(key.data);
+    ucx_map_sstr_put(((DavResourceData*)res->data)->properties, key, v);
+    free(key.ptr);
 }
 
-DavXmlNode* resource_get_property(DavResource *res, char *ns, char *name) {
-    UcxKey key = dav_property_key(ns, name);
+DavXmlNode* resource_get_property(DavResource *res, const char *ns, const char *name) {
+    sstr_t keystr = dav_property_key(ns, name);
+    UcxKey key = ucx_key(keystr.ptr, keystr.length);
     DavXmlNode *property = resource_get_property_k(res, key);
-    free(key.data);
+    free(keystr.ptr);
     return property;
 }
 
@@ -273,18 +274,15 @@
     return ucx_map_get(data->properties, key);
 }
 
-UcxKey dav_property_key(char *ns, char *name) {
+sstr_t dav_property_key(const char *ns, const char *name) {
     return dav_property_key_a(ucx_default_allocator(), ns, name);
 }
 
-UcxKey dav_property_key_a(UcxAllocator *a, char *ns, char *name) {
-    sstr_t ns_str = sstr(ns);
-    sstr_t name_str = sstr(name);
+sstr_t dav_property_key_a(UcxAllocator *a, const char *ns, const char *name) {
+    scstr_t ns_str = scstr(ns);
+    scstr_t name_str = scstr(name);
     
-    sstr_t key;
-    key = sstrcat_a(a, 4, ns_str, S("\0"), name_str, S("\0"));
-    
-    return ucx_key(key.ptr, key.length);
+    return sstrcat_a(a, 4, ns_str, S("\0"), name_str, S("\0"));
 }
 
 
@@ -447,7 +445,7 @@
     return dav_get_property_ns(res, pns, pname);
 }
 
-DavXmlNode* dav_get_property_ns(DavResource *res, char *ns, char *name) {
+DavXmlNode* dav_get_property_ns(DavResource *res, const char *ns, const char *name) {
     if(!ns || !name) {
         return NULL;
     }
@@ -585,7 +583,7 @@
     UCX_MAP_FOREACH(key, value, i) {
         DavPropName *name = &names[j];
         // the map key is namespace + '\0' + name
-        name->ns = key.data;
+        name->ns = (char*)key.data;
         for(int k=0;j<key.len;k++) {
             if(((char*)key.data)[k] == '\0') {
                 name->name = (char*)key.data + k + 1;
@@ -1180,7 +1178,7 @@
 }
 
 
-int resource_add_crypto_info(DavSession *sn, char *href, char *name, char *hash) {
+int resource_add_crypto_info(DavSession *sn, const char *href, const char *name, const char *hash) {
     if(!DAV_IS_ENCRYPTED(sn)) {
         return 0;
     }

mercurial