| 493 } |
493 } |
| 494 } |
494 } |
| 495 } |
495 } |
| 496 } |
496 } |
| 497 |
497 |
| 498 char* dav_get_string_property(DavResource *res, char *name) { |
498 const char* dav_get_string_property(DavResource *res, const char *name) { |
| 499 char *pns; |
499 const char *pns; |
| 500 char *pname; |
500 const char *pname; |
| 501 dav_get_property_namespace_str(res->session->context, name, &pns, &pname); |
501 dav_get_property_namespace_str(res->session->context, name, &pns, &pname); |
| 502 if(!pns || !pname) { |
502 if(!pns || !pname) { |
| 503 return NULL; |
503 return NULL; |
| 504 } |
504 } |
| 505 return dav_get_string_property_ns(res, pns, pname); |
505 return dav_get_string_property_ns(res, pns, pname); |
| 506 } |
506 } |
| 507 |
507 |
| 508 char* dav_get_string_property_ns(DavResource *res, char *ns, char *name) { |
508 const char* dav_get_string_property_ns(DavResource *res, const char *ns, const char *name) { |
| 509 DavXmlNode *prop = dav_get_property_ns(res, ns, name); |
509 DavXmlNode *prop = dav_get_property_ns(res, ns, name); |
| 510 if(!prop) { |
510 if(!prop) { |
| 511 return NULL; |
511 return NULL; |
| 512 } |
512 } |
| 513 return dav_xml_getstring(prop); |
513 return dav_xml_getstring(prop); |
| 514 } |
514 } |
| 515 |
515 |
| 516 DavXmlNode* dav_get_property(DavResource *res, char *name) { |
516 DavXmlNode* dav_get_property(DavResource *res, char *name) { |
| 517 char *pns; |
517 const char *pns; |
| 518 char *pname; |
518 const char *pname; |
| 519 dav_get_property_namespace_str(res->session->context, name, &pns, &pname); |
519 dav_get_property_namespace_str(res->session->context, name, &pns, &pname); |
| 520 if(!pns || !pname) { |
520 if(!pns || !pname) { |
| 521 return NULL; |
521 return NULL; |
| 522 } |
522 } |
| 523 return dav_get_property_ns(res, pns, pname); |
523 return dav_get_property_ns(res, pns, pname); |
| 603 property->ns = namespace; |
603 property->ns = namespace; |
| 604 |
604 |
| 605 return property; |
605 return property; |
| 606 } |
606 } |
| 607 |
607 |
| 608 int dav_set_string_property(DavResource *res, char *name, char *value) { |
608 int dav_set_string_property(DavResource *res, const char *name, const char *value) { |
| 609 char *pns; |
609 const char *pns; |
| 610 char *pname; |
610 const char *pname; |
| 611 dav_get_property_namespace_str(res->session->context, name, &pns, &pname); |
611 dav_get_property_namespace_str(res->session->context, name, &pns, &pname); |
| 612 if(!pns) { |
612 if(!pns) { |
| 613 res->session->errorstr = "Property namespace not found"; |
613 res->session->errorstr = "Property namespace not found"; |
| 614 return 1; |
614 return 1; |
| 615 } |
615 } |
| 627 } |
627 } |
| 628 cxListAdd(*list, property); |
628 cxListAdd(*list, property); |
| 629 return 0; |
629 return 0; |
| 630 } |
630 } |
| 631 |
631 |
| 632 void dav_set_string_property_ns(DavResource *res, char *ns, char *name, char *value) { |
632 void dav_set_string_property_ns(DavResource *res, const char *ns, const char *name, const char *value) { |
| 633 DavSession *sn = res->session; |
633 DavSession *sn = res->session; |
| 634 const CxAllocator *a = res->session->mp->allocator; |
634 const CxAllocator *a = res->session->mp->allocator; |
| 635 DavResourceData *data = res->data; |
635 DavResourceData *data = res->data; |
| 636 |
636 |
| 637 DavProperty *property = createprop(res->session, ns, name); |
637 DavProperty *property = createprop(res->session, ns, name); |
| 642 } else { |
642 } else { |
| 643 add2propertylist(a, &data->set, property); |
643 add2propertylist(a, &data->set, property); |
| 644 } |
644 } |
| 645 } |
645 } |
| 646 |
646 |
| 647 void dav_set_property(DavResource *res, char *name, DavXmlNode *value) { |
647 void dav_set_property(DavResource *res, const char *name, DavXmlNode *value) { |
| 648 char *pns; |
648 const char *pns; |
| 649 char *pname; |
649 const char *pname; |
| 650 dav_get_property_namespace_str(res->session->context, name, &pns, &pname); |
650 dav_get_property_namespace_str(res->session->context, name, &pns, &pname); |
| 651 dav_set_property_ns(res, pns, pname, value); |
651 dav_set_property_ns(res, pns, pname, value); |
| 652 } |
652 } |
| 653 |
653 |
| 654 void dav_set_property_ns(DavResource *res, char *ns, char *name, DavXmlNode *value) { |
654 void dav_set_property_ns(DavResource *res, const char *ns, const char *name, DavXmlNode *value) { |
| 655 DavSession *sn = res->session; |
655 DavSession *sn = res->session; |
| 656 const CxAllocator *a = sn->mp->allocator; |
656 const CxAllocator *a = sn->mp->allocator; |
| 657 DavResourceData *data = res->data; |
657 DavResourceData *data = res->data; |
| 658 |
658 |
| 659 DavProperty *property = createprop(sn, ns, name); |
659 DavProperty *property = createprop(sn, ns, name); |
| 666 } else { |
666 } else { |
| 667 add2propertylist(a, &data->set, property); |
667 add2propertylist(a, &data->set, property); |
| 668 } |
668 } |
| 669 } |
669 } |
| 670 |
670 |
| 671 void dav_remove_property(DavResource *res, char *name) { |
671 void dav_remove_property(DavResource *res, const char *name) { |
| 672 char *pns; |
672 const char *pns; |
| 673 char *pname; |
673 const char *pname; |
| 674 dav_get_property_namespace_str(res->session->context, name, &pns, &pname); |
674 dav_get_property_namespace_str(res->session->context, name, &pns, &pname); |
| 675 dav_remove_property_ns(res, pns, pname); |
675 dav_remove_property_ns(res, pns, pname); |
| 676 } |
676 } |
| 677 |
677 |
| 678 void dav_remove_property_ns(DavResource *res, char *ns, char *name) { |
678 void dav_remove_property_ns(DavResource *res, const char *ns, const char *name) { |
| 679 DavSession *sn = res->session; |
679 DavSession *sn = res->session; |
| 680 DavResourceData *data = res->data; |
680 DavResourceData *data = res->data; |
| 681 const CxAllocator *a = res->session->mp->allocator; |
681 const CxAllocator *a = res->session->mp->allocator; |
| 682 |
682 |
| 683 DavProperty *property = createprop(res->session, ns, name); |
683 DavProperty *property = createprop(res->session, ns, name); |
| 1099 |
1099 |
| 1100 // check encryption |
1100 // check encryption |
| 1101 AESDecrypter *dec = NULL; |
1101 AESDecrypter *dec = NULL; |
| 1102 DavKey *key = NULL; |
1102 DavKey *key = NULL; |
| 1103 if(DAV_DECRYPT_CONTENT(sn)) { |
1103 if(DAV_DECRYPT_CONTENT(sn)) { |
| 1104 char *keyname = dav_get_string_property_ns(res, DAV_NS, "crypto-key"); |
1104 const char *keyname = dav_get_string_property_ns(res, DAV_NS, "crypto-key"); |
| 1105 if(keyname) { |
1105 if(keyname) { |
| 1106 key = dav_context_get_key(sn->context, keyname); |
1106 key = dav_context_get_key(sn->context, keyname); |
| 1107 if(key) { |
1107 if(key) { |
| 1108 dec = aes_decrypter_new(key, stream, write_fnc); |
1108 dec = aes_decrypter_new(key, stream, write_fnc); |
| 1109 stream = dec; |
1109 stream = dec; |
| 1144 |
1144 |
| 1145 if(ret == CURLE_OK && (status >= 200 && status < 300)) { |
1145 if(ret == CURLE_OK && (status >= 200 && status < 300)) { |
| 1146 int verify_failed = 0; |
1146 int verify_failed = 0; |
| 1147 if(DAV_DECRYPT_CONTENT(sn) && key) { |
1147 if(DAV_DECRYPT_CONTENT(sn) && key) { |
| 1148 // try to verify the content |
1148 // try to verify the content |
| 1149 char *res_hash = dav_get_string_property_ns(res, DAV_NS, "crypto-hash"); |
1149 const char *res_hash = dav_get_string_property_ns(res, DAV_NS, "crypto-hash"); |
| 1150 |
1150 |
| 1151 if(res_hash) { |
1151 if(res_hash) { |
| 1152 size_t len = 0; |
1152 size_t len = 0; |
| 1153 char *dec_hash = aes_decrypt(res_hash, &len, key); |
1153 char *dec_hash = aes_decrypt(res_hash, &len, key); |
| 1154 char *hex_hash = util_hexstr((unsigned char*)dec_hash, len); |
1154 char *hex_hash = util_hexstr((unsigned char*)dec_hash, len); |