libidav/methods.c

changeset 331
9ca1e4706acc
parent 315
7db4dbf4e6f9
child 354
067ea2315a8a
equal deleted inserted replaced
330:54819e984a19 331:9ca1e4706acc
32 32
33 #include "utils.h" 33 #include "utils.h"
34 #include "methods.h" 34 #include "methods.h"
35 #include "crypto.h" 35 #include "crypto.h"
36 #include "session.h" 36 #include "session.h"
37 #include "xml.h"
37 38
38 #include <ucx/utils.h> 39 #include <ucx/utils.h>
39 40
40 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b) 41 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b)
41 42
105 106
106 // deactivate header capturing and free captured map 107 // deactivate header capturing and free captured map
107 util_capture_header(handle, NULL); 108 util_capture_header(handle, NULL);
108 ucx_map_free_content(respheaders, free); 109 ucx_map_free_content(respheaders, free);
109 ucx_map_free(respheaders); 110 ucx_map_free(respheaders);
110 111
111 return ret; 112 return ret;
112 } 113 }
113 114
114 UcxBuffer* create_allprop_propfind_request(void) { 115 UcxBuffer* create_allprop_propfind_request(void) {
115 UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOFREE); 116 UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOFREE);
528 res->iscollection = response->iscollection; 529 res->iscollection = response->iscollection;
529 530
530 // add properties 531 // add properties
531 UCX_FOREACH(elm, response->properties) { 532 UCX_FOREACH(elm, response->properties) {
532 xmlNode *prop = elm->data; 533 xmlNode *prop = elm->data;
533 534 resource_add_property(res, (char*)prop->ns->href, (char*)prop->name, prop->children);
534 // TODO: add xml data instead of a string
535 char *text = util_xml_get_text(prop);
536 if(text) {
537 resource_add_property(res, (char*)prop->ns->href, (char*)prop->name, text);
538 }
539 } 535 }
540 536
541 set_davprops(res); 537 set_davprops(res);
542 } 538 }
543 539
665 res->iscollection = iscollection; 661 res->iscollection = iscollection;
666 662
667 // add properties 663 // add properties
668 UCX_FOREACH(elm, properties) { 664 UCX_FOREACH(elm, properties) {
669 xmlNode *prop = elm->data; 665 xmlNode *prop = elm->data;
670 666 resource_add_property(res, (char*)prop->ns->href, (char*)prop->name, prop->children);
671 // TODO: add xml data instead of a string
672 char *text = util_xml_get_text(prop);
673 if(text) {
674 resource_add_property(res, (char*)prop->ns->href, (char*)prop->name, text);
675 }
676 } 667 }
677 ucx_list_free(properties); 668 ucx_list_free(properties);
678 669
679 set_davprops(res); 670 set_davprops(res);
680 if(res != resource) { 671 if(res != resource) {
683 674
684 return 0; 675 return 0;
685 } 676 }
686 677
687 void set_davprops(DavResource *res) { 678 void set_davprops(DavResource *res) {
688 char *cl = dav_get_property_ns(res, "DAV:", "getcontentlength"); 679 char *cl = dav_get_string_property_ns(res, "DAV:", "getcontentlength");
689 char *ct = dav_get_property_ns(res, "DAV:", "getcontenttype"); 680 char *ct = dav_get_string_property_ns(res, "DAV:", "getcontenttype");
690 char *cd = dav_get_property_ns(res, "DAV:", "creationdate"); 681 char *cd = dav_get_string_property_ns(res, "DAV:", "creationdate");
691 char *lm = dav_get_property_ns(res, "DAV:", "getlastmodified"); 682 char *lm = dav_get_string_property_ns(res, "DAV:", "getlastmodified");
692 683
693 res->contenttype = ct; 684 res->contenttype = ct;
694 if(cl) { 685 if(cl) {
695 char *end = NULL; 686 char *end = NULL;
696 res->contentlength = strtoull(cl, &end, 0); 687 res->contentlength = strtoull(cl, &end, 0);
805 char *prefix = ucx_map_cstr_get(namespaces, property->ns->name); 796 char *prefix = ucx_map_cstr_get(namespaces, property->ns->name);
806 if(!prefix) { 797 if(!prefix) {
807 prefix = "D"; 798 prefix = "D";
808 } 799 }
809 800
801 // begin tag
810 s = S("<"); 802 s = S("<");
811 ucx_buffer_write(s.ptr, 1, s.length, buf); 803 ucx_buffer_write(s.ptr, 1, s.length, buf);
812 s = sstr(prefix); 804 s = sstr(prefix);
813 ucx_buffer_write(s.ptr, 1, s.length, buf); 805 ucx_buffer_write(s.ptr, 1, s.length, buf);
814 s = S(":"); 806 s = S(":");
815 ucx_buffer_write(s.ptr, 1, s.length, buf); 807 ucx_buffer_write(s.ptr, 1, s.length, buf);
816 s = sstr(property->name); 808 s = sstr(property->name);
817 ucx_buffer_write(s.ptr, 1, s.length, buf); 809 ucx_buffer_write(s.ptr, 1, s.length, buf);
818 s = S(">"); 810 s = S(">");
819 ucx_buffer_write(s.ptr, 1, s.length, buf); 811 ucx_buffer_write(s.ptr, 1, s.length, buf);
820 s = sstr(property->value); 812
821 ucx_buffer_write(s.ptr, 1, s.length, buf); 813 // content
814 DavXmlNode *content = property->value;
815 if(content->type == DAV_XML_TEXT) {
816 ucx_buffer_write(content->content, 1, content->contentlength, buf);
817 } else {
818 // TODO: implement
819 }
820
821 // end tag
822 s = S("</"); 822 s = S("</");
823 ucx_buffer_write(s.ptr, 1, s.length, buf); 823 ucx_buffer_write(s.ptr, 1, s.length, buf);
824 s = sstr(prefix); 824 s = sstr(prefix);
825 ucx_buffer_write(s.ptr, 1, s.length, buf); 825 ucx_buffer_write(s.ptr, 1, s.length, buf);
826 s = S(":"); 826 s = S(":");

mercurial