libidav/resource.c

changeset 589
2514559a6367
parent 587
3c917df041b8
child 605
bbc66c72661a
equal deleted inserted replaced
588:0cfe006fcad2 589:2514559a6367
1339 } 1339 }
1340 return ret; 1340 return ret;
1341 } 1341 }
1342 1342
1343 UcxMap* parse_crypto_prop(DavSession *sn, DavXmlNode *node) { 1343 UcxMap* parse_crypto_prop(DavSession *sn, DavXmlNode *node) {
1344 1344 if(!node || node->type != DAV_XML_TEXT || node->contentlength == 0) {
1345 } 1345 return NULL;
1346 }
1347
1348 size_t len = 0;
1349 char *dec_str = aes_decrypt(node->content, &len, sn->key);
1350
1351 xmlDoc *doc = xmlReadMemory(dec_str, len, NULL, NULL, 0);
1352 free(dec_str);
1353 if(!doc) {
1354 return NULL;
1355 }
1356
1357 int err = 0;
1358 xmlNode *xml_root = xmlDocGetRootElement(doc);
1359 if(xml_root) {
1360 if(
1361 !xml_root->ns ||
1362 !xstreq(xml_root->name, "prop") ||
1363 !xstreq(xml_root->ns->href, "DAV:"))
1364 {
1365 err = 1;
1366 }
1367 } else {
1368 err = 1;
1369 }
1370
1371 if(err) {
1372 xmlFreeDoc(doc);
1373 return NULL;
1374 }
1375
1376 // ready to get the properties
1377 UcxMap *map = ucx_map_new(32);
1378 xmlNode *n = xml_root->children;
1379 while(n) {
1380 if(n->type == XML_ELEMENT_NODE && n->ns && n->ns->href) {
1381 DavProperty *property = dav_session_malloc(sn, sizeof(DavProperty));
1382 property->name = dav_session_strdup(sn, (const char*)n->name);
1383 property->ns = dav_session_malloc(sn, sizeof(DavNamespace));
1384 property->ns->name = dav_session_strdup(sn, (const char*)n->ns->href);
1385 property->ns->prefix = n->ns->prefix ?
1386 dav_session_strdup(sn, (const char*)n->ns->prefix) : NULL;
1387 property->value = n->children ? dav_convert_xml(sn, n->children) : NULL;
1388
1389 sstr_t key = dav_property_key(property->ns->name, property->name);
1390 ucx_map_sstr_put(map, key, property);
1391 free(key.ptr);
1392 }
1393 n = n->next;
1394 }
1395
1396 xmlFreeDoc(doc);
1397 if(map->count == 0) {
1398 ucx_map_free(map);
1399 return NULL;
1400 }
1401 return map;
1402 }

mercurial