libidav/resource.c

changeset 505
481802342fdf
parent 493
75a259ec8dea
child 518
cca3e7aa30ed
equal deleted inserted replaced
504:bf3695fee719 505:481802342fdf
237 resource->path); 237 resource->path);
238 } 238 }
239 return resource->href; 239 return resource->href;
240 } 240 }
241 241
242 void resource_add_property(DavResource *res, char *ns, char *name, xmlNode *val) { 242 void resource_add_property(DavResource *res, const char *ns, const char *name, xmlNode *val) {
243 if(!val) { 243 if(!val) {
244 return; 244 return;
245 } 245 }
246 246
247 UcxKey key = dav_property_key(ns, name); 247 sstr_t key = dav_property_key(ns, name);
248 DavXmlNode *v = dav_convert_xml(res->session, val); 248 DavXmlNode *v = dav_convert_xml(res->session, val);
249 ucx_map_put(((DavResourceData*)res->data)->properties, key, v); 249 ucx_map_sstr_put(((DavResourceData*)res->data)->properties, key, v);
250 free(key.data); 250 free(key.ptr);
251 } 251 }
252 252
253 void resource_add_string_property(DavResource *res, char *ns, char *name, char *val) { 253 void resource_add_string_property(DavResource *res, char *ns, char *name, char *val) {
254 if(!val) { 254 if(!val) {
255 return; 255 return;
256 } 256 }
257 257
258 UcxKey key = dav_property_key(ns, name); 258 sstr_t key = dav_property_key(ns, name);
259 DavXmlNode *v = dav_text_node(res->session, val); 259 DavXmlNode *v = dav_text_node(res->session, val);
260 ucx_map_put(((DavResourceData*)res->data)->properties, key, v); 260 ucx_map_sstr_put(((DavResourceData*)res->data)->properties, key, v);
261 free(key.data); 261 free(key.ptr);
262 } 262 }
263 263
264 DavXmlNode* resource_get_property(DavResource *res, char *ns, char *name) { 264 DavXmlNode* resource_get_property(DavResource *res, const char *ns, const char *name) {
265 UcxKey key = dav_property_key(ns, name); 265 sstr_t keystr = dav_property_key(ns, name);
266 UcxKey key = ucx_key(keystr.ptr, keystr.length);
266 DavXmlNode *property = resource_get_property_k(res, key); 267 DavXmlNode *property = resource_get_property_k(res, key);
267 free(key.data); 268 free(keystr.ptr);
268 return property; 269 return property;
269 } 270 }
270 271
271 DavXmlNode* resource_get_property_k(DavResource *res, UcxKey key) { 272 DavXmlNode* resource_get_property_k(DavResource *res, UcxKey key) {
272 DavResourceData *data = (DavResourceData*)res->data; 273 DavResourceData *data = (DavResourceData*)res->data;
273 return ucx_map_get(data->properties, key); 274 return ucx_map_get(data->properties, key);
274 } 275 }
275 276
276 UcxKey dav_property_key(char *ns, char *name) { 277 sstr_t dav_property_key(const char *ns, const char *name) {
277 return dav_property_key_a(ucx_default_allocator(), ns, name); 278 return dav_property_key_a(ucx_default_allocator(), ns, name);
278 } 279 }
279 280
280 UcxKey dav_property_key_a(UcxAllocator *a, char *ns, char *name) { 281 sstr_t dav_property_key_a(UcxAllocator *a, const char *ns, const char *name) {
281 sstr_t ns_str = sstr(ns); 282 scstr_t ns_str = scstr(ns);
282 sstr_t name_str = sstr(name); 283 scstr_t name_str = scstr(name);
283 284
284 sstr_t key; 285 return sstrcat_a(a, 4, ns_str, S("\0"), name_str, S("\0"));
285 key = sstrcat_a(a, 4, ns_str, S("\0"), name_str, S("\0"));
286
287 return ucx_key(key.ptr, key.length);
288 } 286 }
289 287
290 288
291 289
292 290
445 return NULL; 443 return NULL;
446 } 444 }
447 return dav_get_property_ns(res, pns, pname); 445 return dav_get_property_ns(res, pns, pname);
448 } 446 }
449 447
450 DavXmlNode* dav_get_property_ns(DavResource *res, char *ns, char *name) { 448 DavXmlNode* dav_get_property_ns(DavResource *res, const char *ns, const char *name) {
451 if(!ns || !name) { 449 if(!ns || !name) {
452 return NULL; 450 return NULL;
453 } 451 }
454 DavXmlNode *property = resource_get_property(res, ns, name); 452 DavXmlNode *property = resource_get_property(res, ns, name);
455 DavResourceData *data = res->data; 453 DavResourceData *data = res->data;
583 void *value; 581 void *value;
584 int j = 0; 582 int j = 0;
585 UCX_MAP_FOREACH(key, value, i) { 583 UCX_MAP_FOREACH(key, value, i) {
586 DavPropName *name = &names[j]; 584 DavPropName *name = &names[j];
587 // the map key is namespace + '\0' + name 585 // the map key is namespace + '\0' + name
588 name->ns = key.data; 586 name->ns = (char*)key.data;
589 for(int k=0;j<key.len;k++) { 587 for(int k=0;j<key.len;k++) {
590 if(((char*)key.data)[k] == '\0') { 588 if(((char*)key.data)[k] == '\0') {
591 name->name = (char*)key.data + k + 1; 589 name->name = (char*)key.data + k + 1;
592 break; 590 break;
593 } 591 }
1178 1176
1179 return 0; 1177 return 0;
1180 } 1178 }
1181 1179
1182 1180
1183 int resource_add_crypto_info(DavSession *sn, char *href, char *name, char *hash) { 1181 int resource_add_crypto_info(DavSession *sn, const char *href, const char *name, const char *hash) {
1184 if(!DAV_IS_ENCRYPTED(sn)) { 1182 if(!DAV_IS_ENCRYPTED(sn)) {
1185 return 0; 1183 return 0;
1186 } 1184 }
1187 1185
1188 UcxBuffer *request = create_crypto_proppatch_request(sn, sn->key, name, hash); 1186 UcxBuffer *request = create_crypto_proppatch_request(sn, sn->key, name, hash);

mercurial