libidav/methods.c

branch
dav-2
changeset 891
4d58cbcc9efa
parent 886
da79af4baec8
equal deleted inserted replaced
890:e77ccf1c4bb3 891:4d58cbcc9efa
72 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); 72 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size);
73 73
74 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, cxBufferWrite); 74 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, cxBufferWrite);
75 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); 75 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
76 CxMap *respheaders = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 32); 76 CxMap *respheaders = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 32);
77 cxDefineDestructor(respheaders, free); 77 cxSetDestructor(respheaders, free);
78 util_capture_header(handle, respheaders); 78 util_capture_header(handle, respheaders);
79 79
80 for(int i=0;i<maxretry;i++) { 80 for(int i=0;i<maxretry;i++) {
81 if (depth == 1) { 81 if (depth == 1) {
82 headers = curl_slist_append(headers, "Depth: 1"); 82 headers = curl_slist_append(headers, "Depth: 1");
120 120
121 return ret; 121 return ret;
122 } 122 }
123 123
124 CxBuffer* create_allprop_propfind_request(void) { 124 CxBuffer* create_allprop_propfind_request(void) {
125 CxBuffer *buf = cxBufferCreate(NULL, 512, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); 125 CxBuffer *buf = cxBufferCreate(cxDefaultAllocator, NULL, 512, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
126 cxstring s; 126 cxstring s;
127 127
128 s = CX_STR("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); 128 s = cx_str("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
129 cxBufferWrite(s.ptr, 1, s.length, buf); 129 cxBufferWrite(s.ptr, 1, s.length, buf);
130 130
131 s = CX_STR("<D:propfind xmlns:D=\"DAV:\">\n"); 131 s = cx_str("<D:propfind xmlns:D=\"DAV:\">\n");
132 cxBufferWrite(s.ptr, 1, s.length, buf); 132 cxBufferWrite(s.ptr, 1, s.length, buf);
133 133
134 s = CX_STR("<D:allprop/></D:propfind>\n"); 134 s = cx_str("<D:allprop/></D:propfind>\n");
135 cxBufferWrite(s.ptr, 1, s.length, buf); 135 cxBufferWrite(s.ptr, 1, s.length, buf);
136 136
137 return buf; 137 return buf;
138 } 138 }
139 139
140 CxBuffer* create_cryptoprop_propfind_request(void) { 140 CxBuffer* create_cryptoprop_propfind_request(void) {
141 CxBuffer *buf = cxBufferCreate(NULL, 256, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); 141 CxBuffer *buf = cxBufferCreate(cxDefaultAllocator, NULL, 256, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
142 cxstring s; 142 cxstring s;
143 143
144 s = CX_STR("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); 144 s = cx_str("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
145 cxBufferWrite(s.ptr, 1, s.length, buf); 145 cxBufferWrite(s.ptr, 1, s.length, buf);
146 146
147 s = CX_STR("<D:propfind xmlns:D=\"DAV:\" xmlns:idav=\"" DAV_NS "\">\n"); 147 s = cx_str("<D:propfind xmlns:D=\"DAV:\" xmlns:idav=\"" DAV_NS "\">\n");
148 cxBufferWrite(s.ptr, 1, s.length, buf); 148 cxBufferWrite(s.ptr, 1, s.length, buf);
149 149
150 s = CX_STR("<D:prop><idav:crypto-prop/></D:prop></D:propfind>\n"); 150 s = cx_str("<D:prop><idav:crypto-prop/></D:prop></D:propfind>\n");
151 cxBufferWrite(s.ptr, 1, s.length, buf); 151 cxBufferWrite(s.ptr, 1, s.length, buf);
152 152
153 return buf; 153 return buf;
154 } 154 }
155 155
156 CxBuffer* create_propfind_request(DavSession *sn, CxList *properties, char *rootelm, DavBool nocrypt) { 156 CxBuffer* create_propfind_request(DavSession *sn, CxList *properties, char *rootelm, DavBool nocrypt) {
157 CxBuffer *buf = cxBufferCreate(NULL, 512, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); 157 CxBuffer *buf = cxBufferCreate(cxDefaultAllocator, NULL, 512, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
158 cxstring s; 158 cxstring s;
159 159
160 int add_crypto_name = 1; 160 int add_crypto_name = 1;
161 int add_crypto_key = 1; 161 int add_crypto_key = 1;
162 int add_crypto_hash = 1; 162 int add_crypto_hash = 1;
191 idav_ns.prefix = "idav"; 191 idav_ns.prefix = "idav";
192 idav_ns.name = DAV_NS; 192 idav_ns.name = DAV_NS;
193 cxMapPut(namespaces, cx_hash_key_str("idav"), &idav_ns); 193 cxMapPut(namespaces, cx_hash_key_str("idav"), &idav_ns);
194 } 194 }
195 195
196 s = CX_STR("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); 196 s = cx_str("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
197 cxBufferWrite(s.ptr, 1, s.length, buf); 197 cxBufferWrite(s.ptr, 1, s.length, buf);
198 198
199 // write root element and namespaces 199 // write root element and namespaces
200 cx_bprintf(buf, "<D:%s xmlns:D=\"DAV:\"", rootelm); 200 cx_bprintf(buf, "<D:%s xmlns:D=\"DAV:\"", rootelm);
201 201
202 CxMapIterator mapi = cxMapIteratorValues(namespaces); 202 CxMapIterator mapi = cxMapIteratorValues(namespaces);
203 cx_foreach(DavNamespace*, ns, mapi) { 203 cx_foreach(DavNamespace*, ns, mapi) {
204 s = CX_STR(" xmlns:"); 204 s = cx_str(" xmlns:");
205 cxBufferWrite(s.ptr, 1, s.length, buf); 205 cxBufferWrite(s.ptr, 1, s.length, buf);
206 s = cx_str(ns->prefix); 206 s = cx_str(ns->prefix);
207 cxBufferWrite(s.ptr, 1, s.length, buf); 207 cxBufferWrite(s.ptr, 1, s.length, buf);
208 s = CX_STR("=\""); 208 s = cx_str("=\"");
209 cxBufferWrite(s.ptr, 1, s.length, buf); 209 cxBufferWrite(s.ptr, 1, s.length, buf);
210 s = cx_str(ns->name); 210 s = cx_str(ns->name);
211 cxBufferWrite(s.ptr, 1, s.length, buf); 211 cxBufferWrite(s.ptr, 1, s.length, buf);
212 s = CX_STR("\""); 212 s = cx_str("\"");
213 cxBufferWrite(s.ptr, 1, s.length, buf); 213 cxBufferWrite(s.ptr, 1, s.length, buf);
214 } 214 }
215 s = CX_STR(">\n"); 215 s = cx_str(">\n");
216 cxBufferWrite(s.ptr, 1, s.length, buf); 216 cxBufferWrite(s.ptr, 1, s.length, buf);
217 217
218 // default properties 218 // default properties
219 s = CX_STR("<D:prop>\n"); 219 s = cx_str("<D:prop>\n");
220 cxBufferWrite(s.ptr, 1, s.length, buf); 220 cxBufferWrite(s.ptr, 1, s.length, buf);
221 221
222 s = CX_STR("<D:creationdate />\n<D:getlastmodified />\n"); 222 s = cx_str("<D:creationdate />\n<D:getlastmodified />\n");
223 cxBufferWrite(s.ptr, 1, s.length, buf); 223 cxBufferWrite(s.ptr, 1, s.length, buf);
224 224
225 s = CX_STR("<D:getcontentlength />\n<D:getcontenttype />\n"); 225 s = cx_str("<D:getcontentlength />\n<D:getcontenttype />\n");
226 cxBufferWrite(s.ptr, 1, s.length, buf); 226 cxBufferWrite(s.ptr, 1, s.length, buf);
227 227
228 s = CX_STR("<D:resourcetype />\n"); 228 s = cx_str("<D:resourcetype />\n");
229 cxBufferWrite(s.ptr, 1, s.length, buf); 229 cxBufferWrite(s.ptr, 1, s.length, buf);
230 230
231 // crypto properties 231 // crypto properties
232 if(DAV_CRYPTO(sn) && !nocrypt) { 232 if(DAV_CRYPTO(sn) && !nocrypt) {
233 if(add_crypto_name) { 233 if(add_crypto_name) {
234 cxBufferPut(buf, '<'); 234 cxBufferPut(buf, '<');
235 cxBufferPutString(buf, crypto_ns); 235 cxBufferPutString(buf, crypto_ns);
236 s = CX_STR(":crypto-name />\n"); 236 s = cx_str(":crypto-name />\n");
237 cxBufferWrite(s.ptr, 1, s.length, buf); 237 cxBufferWrite(s.ptr, 1, s.length, buf);
238 } 238 }
239 if(add_crypto_key) { 239 if(add_crypto_key) {
240 cxBufferPut(buf, '<'); 240 cxBufferPut(buf, '<');
241 cxBufferPutString(buf, crypto_ns); 241 cxBufferPutString(buf, crypto_ns);
242 s = CX_STR(":crypto-key />\n"); 242 s = cx_str(":crypto-key />\n");
243 cxBufferWrite(s.ptr, 1, s.length, buf); 243 cxBufferWrite(s.ptr, 1, s.length, buf);
244 } 244 }
245 if(add_crypto_hash) { 245 if(add_crypto_hash) {
246 cxBufferPut(buf, '<'); 246 cxBufferPut(buf, '<');
247 cxBufferPutString(buf, crypto_ns); 247 cxBufferPutString(buf, crypto_ns);
248 s = CX_STR(":crypto-hash />\n"); 248 s = cx_str(":crypto-hash />\n");
249 cxBufferWrite(s.ptr, 1, s.length, buf); 249 cxBufferWrite(s.ptr, 1, s.length, buf);
250 } 250 }
251 } 251 }
252 252
253 // extra properties 253 // extra properties
254 if(properties) { 254 if(properties) {
255 CxIterator i = cxListIterator(properties); 255 CxIterator i = cxListIterator(properties);
256 cx_foreach(DavProperty*, prop, i) { 256 cx_foreach(DavProperty*, prop, i) {
257 s = CX_STR("<"); 257 s = cx_str("<");
258 cxBufferWrite(s.ptr, 1, s.length, buf); 258 cxBufferWrite(s.ptr, 1, s.length, buf);
259 s = cx_str(prop->ns->prefix); 259 s = cx_str(prop->ns->prefix);
260 cxBufferWrite(s.ptr, 1, s.length, buf); 260 cxBufferWrite(s.ptr, 1, s.length, buf);
261 s = CX_STR(":"); 261 s = cx_str(":");
262 cxBufferWrite(s.ptr, 1, s.length, buf); 262 cxBufferWrite(s.ptr, 1, s.length, buf);
263 s = cx_str(prop->name); 263 s = cx_str(prop->name);
264 cxBufferWrite(s.ptr, 1, s.length, buf); 264 cxBufferWrite(s.ptr, 1, s.length, buf);
265 s = CX_STR(" />\n"); 265 s = cx_str(" />\n");
266 cxBufferWrite(s.ptr, 1, s.length, buf); 266 cxBufferWrite(s.ptr, 1, s.length, buf);
267 } 267 }
268 } 268 }
269 269
270 // end 270 // end
273 cxMapFree(namespaces); 273 cxMapFree(namespaces);
274 return buf; 274 return buf;
275 } 275 }
276 276
277 CxBuffer* create_basic_propfind_request(void) { 277 CxBuffer* create_basic_propfind_request(void) {
278 CxBuffer *buf = cxBufferCreate(NULL, 512, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); 278 CxBuffer *buf = cxBufferCreate(cxDefaultAllocator, NULL, 512, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
279 cxstring s; 279 cxstring s;
280 280
281 s = CX_STR("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); 281 s = cx_str("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
282 cxBufferWrite(s.ptr, 1, s.length, buf); 282 cxBufferWrite(s.ptr, 1, s.length, buf);
283 283
284 s = CX_STR("<D:propfind xmlns:D=\"DAV:\" xmlns:i=\""); 284 s = cx_str("<D:propfind xmlns:D=\"DAV:\" xmlns:i=\"");
285 cxBufferWrite(s.ptr, 1, s.length, buf); 285 cxBufferWrite(s.ptr, 1, s.length, buf);
286 s = CX_STR(DAV_NS); 286 s = cx_str(DAV_NS);
287 cxBufferWrite(s.ptr, 1, s.length, buf); 287 cxBufferWrite(s.ptr, 1, s.length, buf);
288 s = CX_STR("\" >\n"); 288 s = cx_str("\" >\n");
289 cxBufferWrite(s.ptr, 1, s.length, buf); 289 cxBufferWrite(s.ptr, 1, s.length, buf);
290 290
291 // properties 291 // properties
292 s = CX_STR("<D:prop>\n"); 292 s = cx_str("<D:prop>\n");
293 cxBufferWrite(s.ptr, 1, s.length, buf); 293 cxBufferWrite(s.ptr, 1, s.length, buf);
294 s = CX_STR("<D:resourcetype />\n"); 294 s = cx_str("<D:resourcetype />\n");
295 cxBufferWrite(s.ptr, 1, s.length, buf); 295 cxBufferWrite(s.ptr, 1, s.length, buf);
296 s = CX_STR("<i:crypto-key />\n"); 296 s = cx_str("<i:crypto-key />\n");
297 cxBufferWrite(s.ptr, 1, s.length, buf); 297 cxBufferWrite(s.ptr, 1, s.length, buf);
298 s = CX_STR("<i:crypto-name />\n"); 298 s = cx_str("<i:crypto-name />\n");
299 cxBufferWrite(s.ptr, 1, s.length, buf); 299 cxBufferWrite(s.ptr, 1, s.length, buf);
300 s = CX_STR("<i:crypto-hash />\n"); 300 s = cx_str("<i:crypto-hash />\n");
301 cxBufferWrite(s.ptr, 1, s.length, buf); 301 cxBufferWrite(s.ptr, 1, s.length, buf);
302 s = CX_STR("</D:prop>\n"); 302 s = cx_str("</D:prop>\n");
303 cxBufferWrite(s.ptr, 1, s.length, buf); 303 cxBufferWrite(s.ptr, 1, s.length, buf);
304 304
305 // end 305 // end
306 s = CX_STR("</D:propfind>\n"); 306 s = cx_str("</D:propfind>\n");
307 cxBufferWrite(s.ptr, 1, s.length, buf); 307 cxBufferWrite(s.ptr, 1, s.length, buf);
308 308
309 return buf; 309 return buf;
310 } 310 }
311 311
354 char *href = NULL; 354 char *href = NULL;
355 int iscollection = 0; 355 int iscollection = 0;
356 char *crypto_name = NULL; // name set by crypto-name property 356 char *crypto_name = NULL; // name set by crypto-name property
357 char *crypto_key = NULL; 357 char *crypto_key = NULL;
358 358
359 result->properties = cxLinkedListCreateSimple(CX_STORE_POINTERS); // xmlNode list 359 result->properties = cxLinkedListCreate(NULL, CX_STORE_POINTERS); // xmlNode list
360 360
361 xmlNode *node = parser->current->children; 361 xmlNode *node = parser->current->children;
362 while(node) { 362 while(node) {
363 if(node->type == XML_ELEMENT_NODE) { 363 if(node->type == XML_ELEMENT_NODE) {
364 if(xstreq(node->name, "href")) { 364 if(xstreq(node->name, "href")) {
387 if(status_str.length < 13) { 387 if(status_str.length < 13) {
388 // error 388 // error
389 return -1; 389 return -1;
390 } 390 }
391 status_str = cx_strsubsl(status_str, 9, 3); 391 status_str = cx_strsubsl(status_str, 9, 3);
392 if(!cx_strcmp(status_str, CX_STR("200"))) { 392 if(!cx_strcmp(status_str, cx_str("200"))) {
393 ok = 1; 393 ok = 1;
394 } 394 }
395 } 395 }
396 } 396 }
397 n = n->next; 397 n = n->next;
588 DavSession *sn = resource->session; 588 DavSession *sn = resource->session;
589 589
590 //DavResource *res = resource; 590 //DavResource *res = resource;
591 DavResource *res = NULL; 591 DavResource *res = NULL;
592 const char *href = NULL; 592 const char *href = NULL;
593 CxList *properties = cxLinkedListCreateSimple(CX_STORE_POINTERS); // xmlNode list 593 CxList *properties = cxLinkedListCreate(NULL, CX_STORE_POINTERS); // xmlNode list
594 char *crypto_name = NULL; // name set by crypto-name property 594 char *crypto_name = NULL; // name set by crypto-name property
595 char *crypto_key = NULL; 595 char *crypto_key = NULL;
596 596
597 int iscollection = 0; // TODO: remove 597 int iscollection = 0; // TODO: remove
598 598
637 if(status_str.length < 13) { 637 if(status_str.length < 13) {
638 sn->error = DAV_ERROR; 638 sn->error = DAV_ERROR;
639 return 1; 639 return 1;
640 } 640 }
641 status_str = cx_strsubsl(status_str, 9, 3); 641 status_str = cx_strsubsl(status_str, 9, 3);
642 if(!cx_strcmp(status_str, CX_STR("200"))) { 642 if(!cx_strcmp(status_str, cx_str("200"))) {
643 ok = 1; 643 ok = 1;
644 } 644 }
645 } 645 }
646 } 646 }
647 n = n->next; 647 n = n->next;
820 820
821 return ret; 821 return ret;
822 } 822 }
823 823
824 CxBuffer* create_proppatch_request(DavResourceData *data) { 824 CxBuffer* create_proppatch_request(DavResourceData *data) {
825 CxBuffer *buf = cxBufferCreate(NULL, 512, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); 825 CxBuffer *buf = cxBufferCreate(cxDefaultAllocator, NULL, 512, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
826 cxstring s; 826 cxstring s;
827 827
828 CxMap *namespaces = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 8); 828 CxMap *namespaces = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 8);
829 cxDefineDestructor(namespaces, free); 829 cxSetDestructor(namespaces, free);
830 830
831 { 831 {
832 char prefix[8]; 832 char prefix[8];
833 int pfxnum = 0; 833 int pfxnum = 0;
834 if (data->set && cxListSize(data->set) > 0) { 834 if (data->set && cxListSize(data->set) > 0) {
849 } 849 }
850 } 850 }
851 } 851 }
852 } 852 }
853 853
854 s = CX_STR("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); 854 s = cx_str("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
855 cxBufferWrite(s.ptr, 1, s.length, buf); 855 cxBufferWrite(s.ptr, 1, s.length, buf);
856 856
857 // write root element and namespaces 857 // write root element and namespaces
858 s = CX_STR("<D:propertyupdate xmlns:D=\"DAV:\""); 858 s = cx_str("<D:propertyupdate xmlns:D=\"DAV:\"");
859 cxBufferWrite(s.ptr, 1, s.length, buf); 859 cxBufferWrite(s.ptr, 1, s.length, buf);
860 CxMapIterator mapi = cxMapIterator(namespaces); 860 CxMapIterator mapi = cxMapIterator(namespaces);
861 cx_foreach(CxMapEntry*, entry, mapi) { 861 cx_foreach(CxMapEntry*, entry, mapi) {
862 s = CX_STR(" xmlns:"); 862 s = cx_str(" xmlns:");
863 cxBufferWrite(s.ptr, 1, s.length, buf); 863 cxBufferWrite(s.ptr, 1, s.length, buf);
864 s = cx_str(entry->value); 864 s = cx_str(entry->value);
865 cxBufferWrite(s.ptr, 1, s.length, buf); 865 cxBufferWrite(s.ptr, 1, s.length, buf);
866 s = CX_STR("=\""); 866 s = cx_str("=\"");
867 cxBufferWrite(s.ptr, 1, s.length, buf); 867 cxBufferWrite(s.ptr, 1, s.length, buf);
868 s = cx_strn(entry->key->data, entry->key->len); 868 s = cx_strn(entry->key->data, entry->key->len);
869 cxBufferWrite(s.ptr, 1, s.length, buf); 869 cxBufferWrite(s.ptr, 1, s.length, buf);
870 s = CX_STR("\""); 870 s = cx_str("\"");
871 cxBufferWrite(s.ptr, 1, s.length, buf); 871 cxBufferWrite(s.ptr, 1, s.length, buf);
872 } 872 }
873 s = CX_STR(">\n"); 873 s = cx_str(">\n");
874 cxBufferWrite(s.ptr, 1, s.length, buf); 874 cxBufferWrite(s.ptr, 1, s.length, buf);
875 875
876 if(data->set) { 876 if(data->set) {
877 s = CX_STR("<D:set>\n<D:prop>\n"); 877 s = cx_str("<D:set>\n<D:prop>\n");
878 cxBufferWrite(s.ptr, 1, s.length, buf); 878 cxBufferWrite(s.ptr, 1, s.length, buf);
879 CxIterator i = cxListIterator(data->set); 879 CxIterator i = cxListIterator(data->set);
880 cx_foreach(DavProperty*, property, i) { 880 cx_foreach(DavProperty*, property, i) {
881 char *prefix = cxMapGet(namespaces, cx_hash_key_str(property->ns->name)); 881 char *prefix = cxMapGet(namespaces, cx_hash_key_str(property->ns->name));
882 if(!prefix) { 882 if(!prefix) {
883 prefix = "D"; 883 prefix = "D";
884 } 884 }
885 885
886 // begin tag 886 // begin tag
887 s = CX_STR("<"); 887 s = cx_str("<");
888 cxBufferWrite(s.ptr, 1, s.length, buf); 888 cxBufferWrite(s.ptr, 1, s.length, buf);
889 s = cx_str(prefix); 889 s = cx_str(prefix);
890 cxBufferWrite(s.ptr, 1, s.length, buf); 890 cxBufferWrite(s.ptr, 1, s.length, buf);
891 s = CX_STR(":"); 891 s = cx_str(":");
892 cxBufferWrite(s.ptr, 1, s.length, buf); 892 cxBufferWrite(s.ptr, 1, s.length, buf);
893 s = cx_str(property->name); 893 s = cx_str(property->name);
894 cxBufferWrite(s.ptr, 1, s.length, buf); 894 cxBufferWrite(s.ptr, 1, s.length, buf);
895 s = CX_STR(">"); 895 s = cx_str(">");
896 cxBufferWrite(s.ptr, 1, s.length, buf); 896 cxBufferWrite(s.ptr, 1, s.length, buf);
897 897
898 // content 898 // content
899 DavXmlNode *content = property->value; 899 DavXmlNode *content = property->value;
900 if(content->type == DAV_XML_TEXT && !content->next) { 900 if(content->type == DAV_XML_TEXT && !content->next) {
902 } else { 902 } else {
903 dav_print_node(buf, (cx_write_func)cxBufferWrite, namespaces, content); 903 dav_print_node(buf, (cx_write_func)cxBufferWrite, namespaces, content);
904 } 904 }
905 905
906 // end tag 906 // end tag
907 s = CX_STR("</"); 907 s = cx_str("</");
908 cxBufferWrite(s.ptr, 1, s.length, buf); 908 cxBufferWrite(s.ptr, 1, s.length, buf);
909 s = cx_str(prefix); 909 s = cx_str(prefix);
910 cxBufferWrite(s.ptr, 1, s.length, buf); 910 cxBufferWrite(s.ptr, 1, s.length, buf);
911 s = CX_STR(":"); 911 s = cx_str(":");
912 cxBufferWrite(s.ptr, 1, s.length, buf); 912 cxBufferWrite(s.ptr, 1, s.length, buf);
913 s = cx_str(property->name); 913 s = cx_str(property->name);
914 cxBufferWrite(s.ptr, 1, s.length, buf); 914 cxBufferWrite(s.ptr, 1, s.length, buf);
915 s = CX_STR(">\n"); 915 s = cx_str(">\n");
916 cxBufferWrite(s.ptr, 1, s.length, buf); 916 cxBufferWrite(s.ptr, 1, s.length, buf);
917 } 917 }
918 s = CX_STR("</D:prop>\n</D:set>\n"); 918 s = cx_str("</D:prop>\n</D:set>\n");
919 cxBufferWrite(s.ptr, 1, s.length, buf); 919 cxBufferWrite(s.ptr, 1, s.length, buf);
920 } 920 }
921 if(data->remove) { 921 if(data->remove) {
922 s = CX_STR("<D:remove>\n<D:prop>\n"); 922 s = cx_str("<D:remove>\n<D:prop>\n");
923 cxBufferWrite(s.ptr, 1, s.length, buf); 923 cxBufferWrite(s.ptr, 1, s.length, buf);
924 CxIterator i = cxListIterator(data->remove); 924 CxIterator i = cxListIterator(data->remove);
925 cx_foreach(DavProperty*, property, i) { 925 cx_foreach(DavProperty*, property, i) {
926 char *prefix = cxMapGet(namespaces, cx_hash_key_str(property->ns->name)); 926 char *prefix = cxMapGet(namespaces, cx_hash_key_str(property->ns->name));
927 927
928 s = CX_STR("<"); 928 s = cx_str("<");
929 cxBufferWrite(s.ptr, 1, s.length, buf); 929 cxBufferWrite(s.ptr, 1, s.length, buf);
930 s = cx_str(prefix); 930 s = cx_str(prefix);
931 cxBufferWrite(s.ptr, 1, s.length, buf); 931 cxBufferWrite(s.ptr, 1, s.length, buf);
932 s = CX_STR(":"); 932 s = cx_str(":");
933 cxBufferWrite(s.ptr, 1, s.length, buf); 933 cxBufferWrite(s.ptr, 1, s.length, buf);
934 s = cx_str(property->name); 934 s = cx_str(property->name);
935 cxBufferWrite(s.ptr, 1, s.length, buf); 935 cxBufferWrite(s.ptr, 1, s.length, buf);
936 s = CX_STR(" />\n"); 936 s = cx_str(" />\n");
937 cxBufferWrite(s.ptr, 1, s.length, buf); 937 cxBufferWrite(s.ptr, 1, s.length, buf);
938 } 938 }
939 s = CX_STR("</D:prop>\n</D:remove>\n"); 939 s = cx_str("</D:prop>\n</D:remove>\n");
940 cxBufferWrite(s.ptr, 1, s.length, buf); 940 cxBufferWrite(s.ptr, 1, s.length, buf);
941 } 941 }
942 942
943 s = CX_STR("</D:propertyupdate>\n"); 943 s = cx_str("</D:propertyupdate>\n");
944 cxBufferWrite(s.ptr, 1, s.length, buf); 944 cxBufferWrite(s.ptr, 1, s.length, buf);
945 945
946 // cleanup namespace map 946 // cleanup namespace map
947 cxMapFree(namespaces); 947 cxMapFree(namespaces);
948 948
949 return buf; 949 return buf;
950 } 950 }
951 951
952 CxBuffer* create_crypto_proppatch_request(DavSession *sn, DavKey *key, const char *name, const char *hash) { 952 CxBuffer* create_crypto_proppatch_request(DavSession *sn, DavKey *key, const char *name, const char *hash) {
953 CxBuffer *buf = cxBufferCreate(NULL, 512, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); 953 CxBuffer *buf = cxBufferCreate(cxDefaultAllocator, NULL, 512, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
954 cxstring s; 954 cxstring s;
955 955
956 s = CX_STR("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); 956 s = cx_str("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
957 cxBufferWrite(s.ptr, 1, s.length, buf); 957 cxBufferWrite(s.ptr, 1, s.length, buf);
958 958
959 s = CX_STR("<D:propertyupdate xmlns:D=\"DAV:\" xmlns:idav=\"" DAV_NS "\">\n"); 959 s = cx_str("<D:propertyupdate xmlns:D=\"DAV:\" xmlns:idav=\"" DAV_NS "\">\n");
960 cxBufferWrite(s.ptr, 1, s.length, buf); 960 cxBufferWrite(s.ptr, 1, s.length, buf);
961 961
962 s = CX_STR("<D:set>\n<D:prop>\n"); 962 s = cx_str("<D:set>\n<D:prop>\n");
963 cxBufferWrite(s.ptr, 1, s.length, buf); 963 cxBufferWrite(s.ptr, 1, s.length, buf);
964 964
965 if(DAV_ENCRYPT_NAME(sn)) { 965 if(DAV_ENCRYPT_NAME(sn)) {
966 s = CX_STR("<idav:crypto-name>"); 966 s = cx_str("<idav:crypto-name>");
967 cxBufferWrite(s.ptr, 1, s.length, buf); 967 cxBufferWrite(s.ptr, 1, s.length, buf);
968 char *crname = aes_encrypt(name, strlen(name), key); 968 char *crname = aes_encrypt(name, strlen(name), key);
969 cxBufferPutString(buf, crname); 969 cxBufferPutString(buf, crname);
970 free(crname); 970 free(crname);
971 s = CX_STR("</idav:crypto-name>\n"); 971 s = cx_str("</idav:crypto-name>\n");
972 cxBufferWrite(s.ptr, 1, s.length, buf); 972 cxBufferWrite(s.ptr, 1, s.length, buf);
973 } 973 }
974 974
975 s = CX_STR("<idav:crypto-key>"); 975 s = cx_str("<idav:crypto-key>");
976 cxBufferWrite(s.ptr, 1, s.length, buf); 976 cxBufferWrite(s.ptr, 1, s.length, buf);
977 cxBufferPutString(buf, key->name); 977 cxBufferPutString(buf, key->name);
978 s = CX_STR("</idav:crypto-key>\n"); 978 s = cx_str("</idav:crypto-key>\n");
979 cxBufferWrite(s.ptr, 1, s.length, buf); 979 cxBufferWrite(s.ptr, 1, s.length, buf);
980 980
981 if(hash) { 981 if(hash) {
982 s = CX_STR("<idav:crypto-hash>"); 982 s = cx_str("<idav:crypto-hash>");
983 cxBufferWrite(s.ptr, 1, s.length, buf); 983 cxBufferWrite(s.ptr, 1, s.length, buf);
984 cxBufferPutString(buf, hash); 984 cxBufferPutString(buf, hash);
985 s = CX_STR("</idav:crypto-hash>\n"); 985 s = cx_str("</idav:crypto-hash>\n");
986 cxBufferWrite(s.ptr, 1, s.length, buf); 986 cxBufferWrite(s.ptr, 1, s.length, buf);
987 } 987 }
988 988
989 s = CX_STR("</D:prop>\n</D:set>\n</D:propertyupdate>\n"); 989 s = cx_str("</D:prop>\n</D:set>\n</D:propertyupdate>\n");
990 cxBufferWrite(s.ptr, 1, s.length, buf); 990 cxBufferWrite(s.ptr, 1, s.length, buf);
991 991
992 return buf; 992 return buf;
993 } 993 }
994 994
1023 } 1023 }
1024 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); 1024 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
1025 1025
1026 CxBuffer *buf = NULL; 1026 CxBuffer *buf = NULL;
1027 if(!read_func) { 1027 if(!read_func) {
1028 buf = cxBufferCreate(data, length, cxDefaultAllocator, 0); 1028 buf = cxBufferCreate(cxDefaultAllocator, data, length, 0);
1029 buf->size = length; 1029 buf->size = length;
1030 data = buf; 1030 data = buf;
1031 read_func = (dav_read_func)cxBufferRead; 1031 read_func = (dav_read_func)cxBufferRead;
1032 curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)length); 1032 curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)length);
1033 } else if(length == 0) { 1033 } else if(length == 0) {
1146 char *ltheader = cx_asprintf("If: <%s> (<%s>)", url, lock).ptr; 1146 char *ltheader = cx_asprintf("If: <%s> (<%s>)", url, lock).ptr;
1147 headers = curl_slist_append(headers, ltheader); 1147 headers = curl_slist_append(headers, ltheader);
1148 free(ltheader); 1148 free(ltheader);
1149 } 1149 }
1150 //cxstring deststr = ucx_sprintf("Destination: %s", dest); 1150 //cxstring deststr = ucx_sprintf("Destination: %s", dest);
1151 cxmutstr deststr = cx_strcat(2, CX_STR("Destination: "), cx_str(dest)); 1151 cxmutstr deststr = cx_strcat(2, cx_str("Destination: "), cx_str(dest));
1152 headers = curl_slist_append(headers, deststr.ptr); 1152 headers = curl_slist_append(headers, deststr.ptr);
1153 if(override) { 1153 if(override) {
1154 headers = curl_slist_append(headers, "Overwrite: T"); 1154 headers = curl_slist_append(headers, "Overwrite: T");
1155 } else { 1155 } else {
1156 headers = curl_slist_append(headers, "Overwrite: F"); 1156 headers = curl_slist_append(headers, "Overwrite: F");
1165 return ret; 1165 return ret;
1166 } 1166 }
1167 1167
1168 1168
1169 CxBuffer* create_lock_request(void) { 1169 CxBuffer* create_lock_request(void) {
1170 CxBuffer *buf = cxBufferCreate(NULL, 512, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); 1170 CxBuffer *buf = cxBufferCreate(cxDefaultAllocator, NULL, 512, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
1171 cxstring s; 1171 cxstring s;
1172 1172
1173 s = CX_STR("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); 1173 s = cx_str("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
1174 cxBufferWrite(s.ptr, 1, s.length, buf); 1174 cxBufferWrite(s.ptr, 1, s.length, buf);
1175 1175
1176 s = CX_STR("<D:lockinfo xmlns:D=\"DAV:\">\n" 1176 s = cx_str("<D:lockinfo xmlns:D=\"DAV:\">\n"
1177 "<D:lockscope><D:exclusive/></D:lockscope>\n" 1177 "<D:lockscope><D:exclusive/></D:lockscope>\n"
1178 "<D:locktype><D:write/></D:locktype>\n" 1178 "<D:locktype><D:write/></D:locktype>\n"
1179 "<D:owner><D:href>http://davutils.org/libidav/</D:href></D:owner>\n"); 1179 "<D:owner><D:href>http://davutils.org/libidav/</D:href></D:owner>\n");
1180 cxBufferWrite(s.ptr, 1, s.length, buf); 1180 cxBufferWrite(s.ptr, 1, s.length, buf);
1181 1181
1182 s = CX_STR("</D:lockinfo>\n"); 1182 s = cx_str("</D:lockinfo>\n");
1183 cxBufferWrite(s.ptr, 1, s.length, buf); 1183 cxBufferWrite(s.ptr, 1, s.length, buf);
1184 1184
1185 return buf; 1185 return buf;
1186 } 1186 }
1187 1187

mercurial