libidav/methods.c

changeset 747
efbd59642577
parent 743
716f6bf04c30
child 753
8776125fd49c
equal deleted inserted replaced
746:a569148841ff 747:efbd59642577
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 #include "xml.h"
38 38
39 #include <ucx/utils.h> 39 #include <cx/utils.h>
40 #include <cx/printf.h>
41 #include <cx/hash_map.h>
40 42
41 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b) 43 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b)
42 44
43 45
44 int dav_buffer_seek(UcxBuffer *b, curl_off_t offset, int origin) { 46 int dav_buffer_seek(CxBuffer *b, curl_off_t offset, int origin) {
45 return ucx_buffer_seek(b, offset, origin) == 0 ? 0:CURL_SEEKFUNC_CANTSEEK; 47 return cxBufferSeek(b, offset, origin) == 0 ? 0:CURL_SEEKFUNC_CANTSEEK;
46 } 48 }
47 49
48 /* ----------------------------- PROPFIND ----------------------------- */ 50 /* ----------------------------- PROPFIND ----------------------------- */
49 51
50 CURLcode do_propfind_request( 52 CURLcode do_propfind_request(
51 DavSession *sn, 53 DavSession *sn,
52 UcxBuffer *request, 54 CxBuffer *request,
53 UcxBuffer *response) 55 CxBuffer *response)
54 { 56 {
55 CURL *handle = sn->handle; 57 CURL *handle = sn->handle;
56 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPFIND"); 58 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPFIND");
57 59
58 // always try to get information about possible children 60 // always try to get information about possible children
62 64
63 struct curl_slist *headers = NULL; 65 struct curl_slist *headers = NULL;
64 CURLcode ret = 0; 66 CURLcode ret = 0;
65 67
66 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); 68 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1);
67 curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); 69 curl_easy_setopt(handle, CURLOPT_READFUNCTION, cxBufferRead);
68 curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, dav_buffer_seek); 70 curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, cxBufferSeek);
69 curl_easy_setopt(handle, CURLOPT_READDATA, request); 71 curl_easy_setopt(handle, CURLOPT_READDATA, request);
70 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); 72 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size);
71 73
72 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); 74 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, cxBufferWrite);
73 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); 75 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
74 UcxMap *respheaders = ucx_map_new(32); 76 CxMap *respheaders = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 32);
77 respheaders->simple_destructor = free;
75 util_capture_header(handle, respheaders); 78 util_capture_header(handle, respheaders);
76 79
77 for(int i=0;i<maxretry;i++) { 80 for(int i=0;i<maxretry;i++) {
78 if (depth == 1) { 81 if (depth == 1) {
79 headers = curl_slist_append(headers, "Depth: 1"); 82 headers = curl_slist_append(headers, "Depth: 1");
98 * => try with depth 0 next time, it's not a collection 101 * => try with depth 0 next time, it's not a collection
99 * 2. Other cases 102 * 2. Other cases
100 * => the server handled our request and we can stop requesting 103 * => the server handled our request and we can stop requesting
101 */ 104 */
102 char *msdavexterror; 105 char *msdavexterror;
103 msdavexterror = ucx_map_cstr_get(respheaders, "x-msdavext_error"); 106 msdavexterror = cxMapGet(respheaders, cx_hash_key_str("x-msdavext_error"));
104 int iishack = depth == 1 && 107 int iishack = depth == 1 &&
105 msdavexterror && !strncmp(msdavexterror, "589831;", 7); 108 msdavexterror && !strncmp(msdavexterror, "589831;", 7);
106 109
107 if(iishack) { 110 if(iishack) {
108 depth = 0; 111 depth = 0;
111 } 114 }
112 } 115 }
113 116
114 // deactivate header capturing and free captured map 117 // deactivate header capturing and free captured map
115 util_capture_header(handle, NULL); 118 util_capture_header(handle, NULL);
116 ucx_map_free_content(respheaders, free); 119 cxMapDestroy(respheaders);
117 ucx_map_free(respheaders);
118 120
119 return ret; 121 return ret;
120 } 122 }
121 123
122 UcxBuffer* create_allprop_propfind_request(void) { 124 CxBuffer* create_allprop_propfind_request(void) {
123 UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOFREE); 125 CxBuffer *buf = cxBufferCreate(NULL, 512, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
124 sstr_t s; 126 cxstring s;
125 127
126 s = S("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); 128 s = CX_STR("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
127 ucx_buffer_write(s.ptr, 1, s.length, buf); 129 cxBufferWrite(s.ptr, 1, s.length, buf);
128 130
129 s = S("<D:propfind xmlns:D=\"DAV:\">\n"); 131 s = CX_STR("<D:propfind xmlns:D=\"DAV:\">\n");
130 ucx_buffer_write(s.ptr, 1, s.length, buf); 132 cxBufferWrite(s.ptr, 1, s.length, buf);
131 133
132 s = S("<D:allprop/></D:propfind>\n"); 134 s = CX_STR("<D:allprop/></D:propfind>\n");
133 ucx_buffer_write(s.ptr, 1, s.length, buf); 135 cxBufferWrite(s.ptr, 1, s.length, buf);
134 136
135 return buf; 137 return buf;
136 } 138 }
137 139
138 UcxBuffer* create_cryptoprop_propfind_request(void) { 140 CxBuffer* create_cryptoprop_propfind_request(void) {
139 UcxBuffer *buf = ucx_buffer_new(NULL, 256, UCX_BUFFER_AUTOFREE); 141 CxBuffer *buf = cxBufferCreate(NULL, 256, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
140 scstr_t s; 142 cxstring s;
141 143
142 s = SC("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); 144 s = CX_STR("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
143 ucx_buffer_write(s.ptr, 1, s.length, buf); 145 cxBufferWrite(s.ptr, 1, s.length, buf);
144 146
145 s = SC("<D:propfind xmlns:D=\"DAV:\" xmlns:idav=\"" DAV_NS "\">\n"); 147 s = CX_STR("<D:propfind xmlns:D=\"DAV:\" xmlns:idav=\"" DAV_NS "\">\n");
146 ucx_buffer_write(s.ptr, 1, s.length, buf); 148 cxBufferWrite(s.ptr, 1, s.length, buf);
147 149
148 s = SC("<D:prop><idav:crypto-prop/></D:prop></D:propfind>\n"); 150 s = CX_STR("<D:prop><idav:crypto-prop/></D:prop></D:propfind>\n");
149 ucx_buffer_write(s.ptr, 1, s.length, buf); 151 cxBufferWrite(s.ptr, 1, s.length, buf);
150 152
151 return buf; 153 return buf;
152 } 154 }
153 155
154 UcxBuffer* create_propfind_request(DavSession *sn, UcxList *properties, char *rootelm, DavBool nocrypt) { 156 CxBuffer* create_propfind_request(DavSession *sn, CxList *properties, char *rootelm, DavBool nocrypt) {
155 UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND); 157 CxBuffer *buf = cxBufferCreate(NULL, 512, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
156 sstr_t s; 158 cxstring s;
157 159
158 int add_crypto_name = 1; 160 int add_crypto_name = 1;
159 int add_crypto_key = 1; 161 int add_crypto_key = 1;
160 int add_crypto_hash = 1; 162 int add_crypto_hash = 1;
161 char *crypto_ns = "idav"; 163 char *crypto_ns = "idav";
162 UcxMap *namespaces = ucx_map_new(8); 164 CxMap *namespaces = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 8);
163 UCX_FOREACH(elm, properties) { 165 if(properties) {
164 DavProperty *p = elm->data; 166 CxIterator i = cxListIterator(properties);
165 if(strcmp(p->ns->name, "DAV:")) { 167 cx_foreach(DavProperty*, p, i) {
166 ucx_map_cstr_put(namespaces, p->ns->prefix, p->ns); 168 if(strcmp(p->ns->name, "DAV:")) {
167 } 169 cxMapPut(namespaces, cx_hash_key_str(p->ns->prefix), p->ns);
168 170 }
169 // if the properties list contains the idav properties crypto-name 171
170 // and crypto-key, mark them as existent 172 // if the properties list contains the idav properties crypto-name
171 if(!strcmp(p->ns->name, DAV_NS)) { 173 // and crypto-key, mark them as existent
172 if(!strcmp(p->name, "crypto-name")) { 174 if(!strcmp(p->ns->name, DAV_NS)) {
173 add_crypto_name = 0; 175 if(!strcmp(p->name, "crypto-name")) {
174 crypto_ns = p->ns->prefix; 176 add_crypto_name = 0;
175 } else if(!strcmp(p->name, "crypto-key")) { 177 crypto_ns = p->ns->prefix;
176 add_crypto_key = 0; 178 } else if(!strcmp(p->name, "crypto-key")) {
177 crypto_ns = p->ns->prefix; 179 add_crypto_key = 0;
178 } else if(!strcmp(p->name, "crypto-hash")) { 180 crypto_ns = p->ns->prefix;
179 add_crypto_hash = 0; 181 } else if(!strcmp(p->name, "crypto-hash")) {
180 crypto_ns = p->ns->prefix; 182 add_crypto_hash = 0;
183 crypto_ns = p->ns->prefix;
184 }
181 } 185 }
182 } 186 }
183 } 187 }
184 188
185 DavNamespace idav_ns; 189 DavNamespace idav_ns;
186 if(add_crypto_name && add_crypto_key && DAV_CRYPTO(sn) && !nocrypt) { 190 if(add_crypto_name && add_crypto_key && DAV_CRYPTO(sn) && !nocrypt) {
187 idav_ns.prefix = "idav"; 191 idav_ns.prefix = "idav";
188 idav_ns.name = DAV_NS; 192 idav_ns.name = DAV_NS;
189 ucx_map_cstr_put(namespaces, "idav", &idav_ns); 193 cxMapPut(namespaces, cx_hash_key_str("idav"), &idav_ns);
190 } 194 }
191 195
192 s = S("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); 196 s = CX_STR("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
193 ucx_buffer_write(s.ptr, 1, s.length, buf); 197 cxBufferWrite(s.ptr, 1, s.length, buf);
194 198
195 // write root element and namespaces 199 // write root element and namespaces
196 ucx_bprintf(buf, "<D:%s xmlns:D=\"DAV:\"", rootelm); 200 cx_bprintf(buf, "<D:%s xmlns:D=\"DAV:\"", rootelm);
197 201
198 UcxMapIterator mapi = ucx_map_iterator(namespaces); 202 CxIterator mapi = cxMapIteratorValues(namespaces);
199 UcxKey key; 203 cx_foreach(DavNamespace*, ns, mapi) {
200 DavNamespace *ns; 204 s = CX_STR(" xmlns:");
201 UCX_MAP_FOREACH(key, ns, mapi) { 205 cxBufferWrite(s.ptr, 1, s.length, buf);
202 s = S(" xmlns:"); 206 s = cx_str(ns->prefix);
203 ucx_buffer_write(s.ptr, 1, s.length, buf); 207 cxBufferWrite(s.ptr, 1, s.length, buf);
204 s = sstr(ns->prefix); 208 s = CX_STR("=\"");
205 ucx_buffer_write(s.ptr, 1, s.length, buf); 209 cxBufferWrite(s.ptr, 1, s.length, buf);
206 s = S("=\""); 210 s = cx_str(ns->name);
207 ucx_buffer_write(s.ptr, 1, s.length, buf); 211 cxBufferWrite(s.ptr, 1, s.length, buf);
208 s = sstr(ns->name); 212 s = CX_STR("\"");
209 ucx_buffer_write(s.ptr, 1, s.length, buf); 213 cxBufferWrite(s.ptr, 1, s.length, buf);
210 s = S("\""); 214 }
211 ucx_buffer_write(s.ptr, 1, s.length, buf); 215 s = CX_STR(">\n");
212 } 216 cxBufferWrite(s.ptr, 1, s.length, buf);
213 s = S(">\n");
214 ucx_buffer_write(s.ptr, 1, s.length, buf);
215 217
216 // default properties 218 // default properties
217 s = S("<D:prop>\n"); 219 s = CX_STR("<D:prop>\n");
218 ucx_buffer_write(s.ptr, 1, s.length, buf); 220 cxBufferWrite(s.ptr, 1, s.length, buf);
219 221
220 s = S("<D:creationdate />\n<D:getlastmodified />\n"); 222 s = CX_STR("<D:creationdate />\n<D:getlastmodified />\n");
221 ucx_buffer_write(s.ptr, 1, s.length, buf); 223 cxBufferWrite(s.ptr, 1, s.length, buf);
222 224
223 s = S("<D:getcontentlength />\n<D:getcontenttype />\n"); 225 s = CX_STR("<D:getcontentlength />\n<D:getcontenttype />\n");
224 ucx_buffer_write(s.ptr, 1, s.length, buf); 226 cxBufferWrite(s.ptr, 1, s.length, buf);
225 227
226 s = S("<D:resourcetype />\n"); 228 s = CX_STR("<D:resourcetype />\n");
227 ucx_buffer_write(s.ptr, 1, s.length, buf); 229 cxBufferWrite(s.ptr, 1, s.length, buf);
228 230
229 // crypto properties 231 // crypto properties
230 if(DAV_CRYPTO(sn) && !nocrypt) { 232 if(DAV_CRYPTO(sn) && !nocrypt) {
231 if(add_crypto_name) { 233 if(add_crypto_name) {
232 ucx_buffer_putc(buf, '<'); 234 cxBufferPut(buf, '<');
233 ucx_buffer_puts(buf, crypto_ns); 235 cxBufferPutString(buf, crypto_ns);
234 s = S(":crypto-name />\n"); 236 s = CX_STR(":crypto-name />\n");
235 ucx_buffer_write(s.ptr, 1, s.length, buf); 237 cxBufferWrite(s.ptr, 1, s.length, buf);
236 } 238 }
237 if(add_crypto_key) { 239 if(add_crypto_key) {
238 ucx_buffer_putc(buf, '<'); 240 cxBufferPut(buf, '<');
239 ucx_buffer_puts(buf, crypto_ns); 241 cxBufferPutString(buf, crypto_ns);
240 s = S(":crypto-key />\n"); 242 s = CX_STR(":crypto-key />\n");
241 ucx_buffer_write(s.ptr, 1, s.length, buf); 243 cxBufferWrite(s.ptr, 1, s.length, buf);
242 } 244 }
243 if(add_crypto_hash) { 245 if(add_crypto_hash) {
244 ucx_buffer_putc(buf, '<'); 246 cxBufferPut(buf, '<');
245 ucx_buffer_puts(buf, crypto_ns); 247 cxBufferPutString(buf, crypto_ns);
246 s = S(":crypto-hash />\n"); 248 s = CX_STR(":crypto-hash />\n");
247 ucx_buffer_write(s.ptr, 1, s.length, buf); 249 cxBufferWrite(s.ptr, 1, s.length, buf);
248 } 250 }
249 } 251 }
250 252
251 // extra properties 253 // extra properties
252 UCX_FOREACH(elm, properties) { 254 if(properties) {
253 DavProperty *prop = elm->data; 255 CxIterator i = cxListIterator(properties);
254 s = S("<"); 256 cx_foreach(DavProperty*, prop, i) {
255 ucx_buffer_write(s.ptr, 1, s.length, buf); 257 s = CX_STR("<");
256 s = sstr(prop->ns->prefix); 258 cxBufferWrite(s.ptr, 1, s.length, buf);
257 ucx_buffer_write(s.ptr, 1, s.length, buf); 259 s = cx_str(prop->ns->prefix);
258 s = S(":"); 260 cxBufferWrite(s.ptr, 1, s.length, buf);
259 ucx_buffer_write(s.ptr, 1, s.length, buf); 261 s = CX_STR(":");
260 s = sstr(prop->name); 262 cxBufferWrite(s.ptr, 1, s.length, buf);
261 ucx_buffer_write(s.ptr, 1, s.length, buf); 263 s = cx_str(prop->name);
262 s = S(" />\n"); 264 cxBufferWrite(s.ptr, 1, s.length, buf);
263 ucx_buffer_write(s.ptr, 1, s.length, buf); 265 s = CX_STR(" />\n");
266 cxBufferWrite(s.ptr, 1, s.length, buf);
267 }
264 } 268 }
265 269
266 // end 270 // end
267 ucx_bprintf(buf, "</D:prop>\n</D:%s>\n", rootelm); 271 cx_bprintf(buf, "</D:prop>\n</D:%s>\n", rootelm);
268 272
269 ucx_map_free(namespaces); 273 cxMapDestroy(namespaces);
270 return buf; 274 return buf;
271 } 275 }
272 276
273 UcxBuffer* create_basic_propfind_request(void) { 277 CxBuffer* create_basic_propfind_request(void) {
274 UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND); 278 CxBuffer *buf = cxBufferCreate(NULL, 512, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
275 sstr_t s; 279 cxstring s;
276 280
277 s = S("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); 281 s = CX_STR("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
278 ucx_buffer_write(s.ptr, 1, s.length, buf); 282 cxBufferWrite(s.ptr, 1, s.length, buf);
279 283
280 s = S("<D:propfind xmlns:D=\"DAV:\" xmlns:i=\""); 284 s = CX_STR("<D:propfind xmlns:D=\"DAV:\" xmlns:i=\"");
281 ucx_buffer_write(s.ptr, 1, s.length, buf); 285 cxBufferWrite(s.ptr, 1, s.length, buf);
282 s = S(DAV_NS); 286 s = CX_STR(DAV_NS);
283 ucx_buffer_write(s.ptr, 1, s.length, buf); 287 cxBufferWrite(s.ptr, 1, s.length, buf);
284 s = S("\" >\n"); 288 s = CX_STR("\" >\n");
285 ucx_buffer_write(s.ptr, 1, s.length, buf); 289 cxBufferWrite(s.ptr, 1, s.length, buf);
286 290
287 // properties 291 // properties
288 s = S("<D:prop>\n"); 292 s = CX_STR("<D:prop>\n");
289 ucx_buffer_write(s.ptr, 1, s.length, buf); 293 cxBufferWrite(s.ptr, 1, s.length, buf);
290 s = S("<D:resourcetype />\n"); 294 s = CX_STR("<D:resourcetype />\n");
291 ucx_buffer_write(s.ptr, 1, s.length, buf); 295 cxBufferWrite(s.ptr, 1, s.length, buf);
292 s = S("<i:crypto-key />\n"); 296 s = CX_STR("<i:crypto-key />\n");
293 ucx_buffer_write(s.ptr, 1, s.length, buf); 297 cxBufferWrite(s.ptr, 1, s.length, buf);
294 s = S("<i:crypto-name />\n"); 298 s = CX_STR("<i:crypto-name />\n");
295 ucx_buffer_write(s.ptr, 1, s.length, buf); 299 cxBufferWrite(s.ptr, 1, s.length, buf);
296 s = S("<i:crypto-hash />\n"); 300 s = CX_STR("<i:crypto-hash />\n");
297 ucx_buffer_write(s.ptr, 1, s.length, buf); 301 cxBufferWrite(s.ptr, 1, s.length, buf);
298 s = S("</D:prop>\n"); 302 s = CX_STR("</D:prop>\n");
299 ucx_buffer_write(s.ptr, 1, s.length, buf); 303 cxBufferWrite(s.ptr, 1, s.length, buf);
300 304
301 // end 305 // end
302 s = S("</D:propfind>\n"); 306 s = CX_STR("</D:propfind>\n");
303 ucx_buffer_write(s.ptr, 1, s.length, buf); 307 cxBufferWrite(s.ptr, 1, s.length, buf);
304 308
305 return buf; 309 return buf;
306 } 310 }
307 311
308 PropfindParser* create_propfind_parser(UcxBuffer *response, char *url) { 312 PropfindParser* create_propfind_parser(CxBuffer *response, char *url) {
309 PropfindParser *parser = malloc(sizeof(PropfindParser)); 313 PropfindParser *parser = malloc(sizeof(PropfindParser));
310 if(!parser) { 314 if(!parser) {
311 return NULL; 315 return NULL;
312 } 316 }
313 parser->document = xmlReadMemory(response->space, response->pos, url, NULL, 0); 317 parser->document = xmlReadMemory(response->space, response->pos, url, NULL, 0);
347 return 0; 351 return 0;
348 } 352 }
349 353
350 char *href = NULL; 354 char *href = NULL;
351 int iscollection = 0; 355 int iscollection = 0;
352 UcxList *properties = NULL; // xmlNode list
353 char *crypto_name = NULL; // name set by crypto-name property 356 char *crypto_name = NULL; // name set by crypto-name property
354 char *crypto_key = NULL; 357 char *crypto_key = NULL;
355 358
356 result->properties = NULL; 359 result->properties = cxLinkedListCreateSimple(CX_STORE_POINTERS); // xmlNode list
357 360
358 xmlNode *node = parser->current->children; 361 xmlNode *node = parser->current->children;
359 while(node) { 362 while(node) {
360 if(node->type == XML_ELEMENT_NODE) { 363 if(node->type == XML_ELEMENT_NODE) {
361 if(xstreq(node->name, "href")) { 364 if(xstreq(node->name, "href")) {
378 xmlNode *status_node = n->children; 381 xmlNode *status_node = n->children;
379 if(status_node->type != XML_TEXT_NODE) { 382 if(status_node->type != XML_TEXT_NODE) {
380 // error 383 // error
381 return -1; 384 return -1;
382 } 385 }
383 sstr_t status_str = sstr((char*)status_node->content); 386 cxstring status_str = cx_str((char*)status_node->content);
384 if(status_str.length < 13) { 387 if(status_str.length < 13) {
385 // error 388 // error
386 return -1; 389 return -1;
387 } 390 }
388 status_str = sstrsubsl(status_str, 9, 3); 391 status_str = cx_strsubsl(status_str, 9, 3);
389 if(!sstrcmp(status_str, S("200"))) { 392 if(!cx_strcmp(status_str, CX_STR("200"))) {
390 ok = 1; 393 ok = 1;
391 } 394 }
392 } 395 }
393 } 396 }
394 n = n->next; 397 n = n->next;
396 // if status is ok, get all properties 399 // if status is ok, get all properties
397 if(ok) { 400 if(ok) {
398 n = prop_node->children; 401 n = prop_node->children;
399 while(n) { 402 while(n) {
400 if(n->type == XML_ELEMENT_NODE) { 403 if(n->type == XML_ELEMENT_NODE) {
401 properties = ucx_list_append(properties, n); 404 cxListAdd(result->properties, n);
402 if(xstreq(n->name, "resourcetype")) { 405 if(xstreq(n->name, "resourcetype")) {
403 if(parse_resource_type(n)) { 406 if(parse_resource_type(n)) {
404 iscollection = TRUE; 407 iscollection = TRUE;
405 } 408 }
406 } else if(xstreq(n->ns->href, DAV_NS)) { 409 } else if(xstreq(n->ns->href, DAV_NS)) {
419 node = node->next; 422 node = node->next;
420 } 423 }
421 424
422 result->href = util_url_path(href); 425 result->href = util_url_path(href);
423 result->iscollection = iscollection; 426 result->iscollection = iscollection;
424 result->properties = properties;
425 result->crypto_name = crypto_name; 427 result->crypto_name = crypto_name;
426 result->crypto_key = crypto_key; 428 result->crypto_key = crypto_key;
427 429
428 // find next response tag 430 // find next response tag
429 xmlNode *next = parser->current->next; 431 xmlNode *next = parser->current->next;
440 return 1; 442 return 1;
441 } 443 }
442 444
443 void cleanup_response(ResponseTag *result) { 445 void cleanup_response(ResponseTag *result) {
444 if(result) { 446 if(result) {
445 ucx_list_free(result->properties); 447 cxListDestroy(result->properties);
446 } 448 }
447 } 449 }
448 450
449 int hrefeq(DavSession *sn, char *href1, char *href2) { 451 int hrefeq(DavSession *sn, const char *href1, const char *href2) {
450 sstr_t href_s = sstr(util_url_decode(sn, href1)); 452 cxmutstr href_s = cx_mutstr(util_url_decode(sn, href1));
451 sstr_t href_r = sstr(util_url_decode(sn, href2)); 453 cxmutstr href_r = cx_mutstr(util_url_decode(sn, href2));
452 int ret = 0; 454 int ret = 0;
453 if(!sstrcmp(href_s, href_r)) { 455 if(!cx_strcmp(cx_strcast(href_s), cx_strcast(href_r))) {
454 ret = 1; 456 ret = 1;
455 } else if(href_s.length == href_r.length + 1) { 457 } else if(href_s.length == href_r.length + 1) {
456 if(href_s.ptr[href_s.length-1] == '/') { 458 if(href_s.ptr[href_s.length-1] == '/') {
457 href_s.length--; 459 href_s.length--;
458 if(!sstrcmp(href_s, href_r)) { 460 if(!cx_strcmp(cx_strcast(href_s), cx_strcast(href_r))) {
459 ret = 1; 461 ret = 1;
460 } 462 }
461 } 463 }
462 } else if(href_r.length == href_s.length + 1) { 464 } else if(href_r.length == href_s.length + 1) {
463 if(href_r.ptr[href_r.length-1] == '/') { 465 if(href_r.ptr[href_r.length-1] == '/') {
464 href_r.length--; 466 href_r.length--;
465 if(!sstrcmp(href_s, href_r)) { 467 if(!cx_strcmp(cx_strcast(href_s), cx_strcast(href_r))) {
466 ret = 1; 468 ret = 1;
467 } 469 }
468 } 470 }
469 } 471 }
470 472
473 475
474 return ret; 476 return ret;
475 } 477 }
476 478
477 479
478 DavResource* parse_propfind_response(DavSession *sn, DavResource *root, UcxBuffer *response) { 480 DavResource* parse_propfind_response(DavSession *sn, DavResource *root, CxBuffer *response) {
479 char *url = NULL; 481 char *url = NULL;
480 curl_easy_getinfo(sn->handle, CURLINFO_EFFECTIVE_URL, &url); 482 curl_easy_getinfo(sn->handle, CURLINFO_EFFECTIVE_URL, &url);
481 if(!root) { 483 if(!root) {
482 printf("methods.c: TODO: remove\n"); 484 printf("methods.c: TODO: remove\n");
483 root = dav_resource_new_href(sn, util_url_path(url)); // TODO: remove 485 root = dav_resource_new_href(sn, util_url_path(url)); // TODO: remove
521 sn->error = DAV_ERROR; 523 sn->error = DAV_ERROR;
522 dav_session_set_errstr(sn, "Cannot decrypt resource name"); 524 dav_session_set_errstr(sn, "Cannot decrypt resource name");
523 return NULL; 525 return NULL;
524 } 526 }
525 } else { 527 } else {
526 sstr_t resname = sstr(util_resource_name(response->href)); 528 cxstring resname = cx_str(util_resource_name(response->href));
527 int nlen = 0; 529 int nlen = 0;
528 char *uname = curl_easy_unescape( 530 char *uname = curl_easy_unescape(
529 sn->handle, 531 sn->handle,
530 resname.ptr, 532 resname.ptr,
531 resname.length, 533 resname.length,
553 int decrypt_props = DAV_ENCRYPT_PROPERTIES(res->session); 555 int decrypt_props = DAV_ENCRYPT_PROPERTIES(res->session);
554 xmlNode *crypto_prop = NULL; 556 xmlNode *crypto_prop = NULL;
555 char *crypto_key = NULL; 557 char *crypto_key = NULL;
556 558
557 // add properties 559 // add properties
558 UCX_FOREACH(elm, response->properties) { 560 if(response->properties) {
559 xmlNode *prop = elm->data; 561 CxIterator i = cxListIterator(response->properties);
560 resource_add_property(res, (char*)prop->ns->href, (char*)prop->name, prop->children); 562 cx_foreach(xmlNode*, prop, i) {
563 resource_add_property(res, (char*)prop->ns->href, (char*)prop->name, prop->children);
561 564
562 if (decrypt_props && 565 if (decrypt_props &&
563 prop->children && 566 prop->children &&
564 prop->children->type == XML_TEXT_NODE && 567 prop->children->type == XML_TEXT_NODE &&
565 xstreq(prop->ns->href, DAV_NS)) 568 xstreq(prop->ns->href, DAV_NS))
566 { 569 {
567 if(xstreq(prop->name, "crypto-prop")) { 570 if(xstreq(prop->name, "crypto-prop")) {
568 crypto_prop = prop; 571 crypto_prop = prop;
569 } else if(xstreq(prop->name, "crypto-key")) { 572 } else if(xstreq(prop->name, "crypto-key")) {
570 crypto_key = util_xml_get_text(prop); 573 crypto_key = util_xml_get_text(prop);
574 }
571 } 575 }
572 } 576 }
573 } 577 }
574 578
575 if(crypto_prop && crypto_key) { 579 if(crypto_prop && crypto_key) {
576 char *crypto_prop_content = util_xml_get_text(crypto_prop); 580 char *crypto_prop_content = util_xml_get_text(crypto_prop);
577 DavKey *key = dav_context_get_key(res->session->context, crypto_key); 581 DavKey *key = dav_context_get_key(res->session->context, crypto_key);
578 if(crypto_prop_content) { 582 if(crypto_prop_content) {
579 UcxMap *cprops = parse_crypto_prop_str(res->session, key, crypto_prop_content); 583 CxMap *cprops = parse_crypto_prop_str(res->session, key, crypto_prop_content);
580 resource_set_crypto_properties(res, cprops); 584 resource_set_crypto_properties(res, cprops);
581 } 585 }
582 } 586 }
583 587
584 set_davprops(res); 588 set_davprops(res);
587 int parse_response_tag(DavResource *resource, xmlNode *node) { 591 int parse_response_tag(DavResource *resource, xmlNode *node) {
588 DavSession *sn = resource->session; 592 DavSession *sn = resource->session;
589 593
590 //DavResource *res = resource; 594 //DavResource *res = resource;
591 DavResource *res = NULL; 595 DavResource *res = NULL;
592 char *href = NULL; 596 const char *href = NULL;
593 UcxList *properties = NULL; // xmlNode list 597 CxList *properties = cxLinkedListCreateSimple(CX_STORE_POINTERS); // xmlNode list
594 char *crypto_name = NULL; // name set by crypto-name property 598 char *crypto_name = NULL; // name set by crypto-name property
595 char *crypto_key = NULL; 599 char *crypto_key = NULL;
596 600
597 int iscollection = 0; // TODO: remove 601 int iscollection = 0; // TODO: remove
598 602
605 // error 609 // error
606 sn->error = DAV_ERROR; 610 sn->error = DAV_ERROR;
607 return 1; 611 return 1;
608 } 612 }
609 //char *href = (char*)href_node->content; 613 //char *href = (char*)href_node->content;
610 href = util_url_path((char*)href_node->content); 614 href = util_url_path((const char*)href_node->content);
611 615
612 char *href_s = util_url_decode(resource->session, href); 616 char *href_s = util_url_decode(resource->session, href);
613 char *href_r = util_url_decode(resource->session, resource->href); 617 char *href_r = util_url_decode(resource->session, resource->href);
614 618
615 if(hrefeq(sn, href_s, href_r)) { 619 if(hrefeq(sn, href_s, href_r)) {
631 xmlNode *status_node = n->children; 635 xmlNode *status_node = n->children;
632 if(status_node->type != XML_TEXT_NODE) { 636 if(status_node->type != XML_TEXT_NODE) {
633 sn->error = DAV_ERROR; 637 sn->error = DAV_ERROR;
634 return 1; 638 return 1;
635 } 639 }
636 sstr_t status_str = sstr((char*)status_node->content); 640 cxstring status_str = cx_str((char*)status_node->content);
637 if(status_str.length < 13) { 641 if(status_str.length < 13) {
638 sn->error = DAV_ERROR; 642 sn->error = DAV_ERROR;
639 return 1; 643 return 1;
640 } 644 }
641 status_str = sstrsubsl(status_str, 9, 3); 645 status_str = cx_strsubsl(status_str, 9, 3);
642 if(!sstrcmp(status_str, S("200"))) { 646 if(!cx_strcmp(status_str, CX_STR("200"))) {
643 ok = 1; 647 ok = 1;
644 } 648 }
645 } 649 }
646 } 650 }
647 n = n->next; 651 n = n->next;
649 // if status is ok, get all properties 653 // if status is ok, get all properties
650 if(ok) { 654 if(ok) {
651 n = prop_node->children; 655 n = prop_node->children;
652 while(n) { 656 while(n) {
653 if(n->type == XML_ELEMENT_NODE) { 657 if(n->type == XML_ELEMENT_NODE) {
654 properties = ucx_list_append(properties, n); 658 cxListAdd(properties, n);
655 if(xstreq(n->name, "resourcetype")) { 659 if(xstreq(n->name, "resourcetype")) {
656 if(parse_resource_type(n)) { 660 if(parse_resource_type(n)) {
657 iscollection = TRUE; 661 iscollection = TRUE;
658 } 662 }
659 } else if(n->ns && xstreq(n->ns->href, DAV_NS)) { 663 } else if(n->ns && xstreq(n->ns->href, DAV_NS)) {
687 sn->error = DAV_ERROR; 691 sn->error = DAV_ERROR;
688 dav_session_set_errstr(sn, "Cannot decrypt resource name"); 692 dav_session_set_errstr(sn, "Cannot decrypt resource name");
689 return -1; 693 return -1;
690 } 694 }
691 } else { 695 } else {
692 sstr_t resname = sstr(util_resource_name(href)); 696 cxstring resname = cx_str(util_resource_name(href));
693 int nlen = 0; 697 int nlen = 0;
694 char *uname = curl_easy_unescape( 698 char *uname = curl_easy_unescape(
695 sn->handle, 699 sn->handle,
696 resname.ptr, 700 resname.ptr,
697 resname.length, 701 resname.length,
698 &nlen); 702 &nlen);
699 name = dav_session_strdup(sn, uname); 703 name = dav_session_strdup(sn, uname);
700 curl_free(uname); 704 curl_free(uname);
701 } 705 }
702 706
703 href = dav_session_strdup(sn, href); 707 char *href_cp = dav_session_strdup(sn, href);
704 res = dav_resource_new_full(sn, resource->path, name, href); 708 res = dav_resource_new_full(sn, resource->path, name, href_cp);
705 709
706 dav_session_free(sn, name); 710 dav_session_free(sn, name);
707 } 711 }
708 res->iscollection = iscollection; 712 res->iscollection = iscollection;
709 713
710 // add properties 714 // add properties
711 int decrypt_props = DAV_ENCRYPT_PROPERTIES(res->session); 715 int decrypt_props = DAV_ENCRYPT_PROPERTIES(res->session);
712 xmlNode *crypto_prop = NULL; 716 xmlNode *crypto_prop = NULL;
713 717
714 UCX_FOREACH(elm, properties) { 718 CxIterator i = cxListIterator(properties);
715 xmlNode *prop = elm->data; 719 cx_foreach(xmlNode*, prop, i) {
716 if(!prop->ns) { 720 if(!prop->ns) {
717 continue; 721 continue;
718 } 722 }
719 resource_add_property(res, (char*)prop->ns->href, (char*)prop->name, prop->children); 723 resource_add_property(res, (char*)prop->ns->href, (char*)prop->name, prop->children);
720 724
726 if(xstreq(prop->name, "crypto-prop")) { 730 if(xstreq(prop->name, "crypto-prop")) {
727 crypto_prop = prop; 731 crypto_prop = prop;
728 } 732 }
729 } 733 }
730 } 734 }
731 ucx_list_free(properties); 735 cxListDestroy(properties);
732 736
733 if(crypto_prop && crypto_key) { 737 if(crypto_prop && crypto_key) {
734 char *crypto_prop_content = util_xml_get_text(crypto_prop); 738 char *crypto_prop_content = util_xml_get_text(crypto_prop);
735 DavKey *key = dav_context_get_key(res->session->context, crypto_key); 739 DavKey *key = dav_context_get_key(res->session->context, crypto_key);
736 if(crypto_prop_content && key) { 740 if(crypto_prop_content && key) {
737 UcxMap *cprops = parse_crypto_prop_str(res->session, key, crypto_prop_content); 741 CxMap *cprops = parse_crypto_prop_str(res->session, key, crypto_prop_content);
738 resource_set_crypto_properties(res, cprops); 742 resource_set_crypto_properties(res, cprops);
739 } 743 }
740 } 744 }
741 745
742 746
782 /* ----------------------------- PROPPATCH ----------------------------- */ 786 /* ----------------------------- PROPPATCH ----------------------------- */
783 787
784 CURLcode do_proppatch_request( 788 CURLcode do_proppatch_request(
785 DavSession *sn, 789 DavSession *sn,
786 char *lock, 790 char *lock,
787 UcxBuffer *request, 791 CxBuffer *request,
788 UcxBuffer *response) 792 CxBuffer *response)
789 { 793 {
790 CURL *handle = sn->handle; 794 CURL *handle = sn->handle;
791 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPPATCH"); 795 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPPATCH");
792 796
793 struct curl_slist *headers = NULL; 797 struct curl_slist *headers = NULL;
794 headers = curl_slist_append(headers, "Content-Type: text/xml"); 798 headers = curl_slist_append(headers, "Content-Type: text/xml");
795 if(lock) { 799 if(lock) {
796 char *url = NULL; 800 char *url = NULL;
797 curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); 801 curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
798 char *ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; 802 char *ltheader = cx_asprintf("If: <%s> (<%s>)", url, lock).ptr;
799 headers = curl_slist_append(headers, ltheader); 803 headers = curl_slist_append(headers, ltheader);
800 free(ltheader); 804 free(ltheader);
801 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); 805 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
802 } 806 }
803 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); 807 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
804 808
805 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); 809 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1);
806 curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); 810 curl_easy_setopt(handle, CURLOPT_READFUNCTION, cxBufferRead);
807 curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, dav_buffer_seek); 811 curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, cxBufferSeek);
808 curl_easy_setopt(handle, CURLOPT_READDATA, request); 812 curl_easy_setopt(handle, CURLOPT_READDATA, request);
809 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); 813 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size);
810 814
811 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); 815 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, cxBufferWrite);
812 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); 816 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
813 817
814 ucx_buffer_seek(request, 0, SEEK_SET); 818 cxBufferSeek(request, 0, SEEK_SET);
815 CURLcode ret = dav_session_curl_perform_buf(sn, request, response, NULL); 819 CURLcode ret = dav_session_curl_perform_buf(sn, request, response, NULL);
816 curl_slist_free_all(headers); 820 curl_slist_free_all(headers);
817 821
818 //printf("proppatch: \n%.*s\n", request->size, request->space); 822 //printf("proppatch: \n%.*s\n", request->size, request->space);
819 823
820 return ret; 824 return ret;
821 } 825 }
822 826
823 UcxBuffer* create_proppatch_request(DavResourceData *data) { 827 CxBuffer* create_proppatch_request(DavResourceData *data) {
824 UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND); 828 CxBuffer *buf = cxBufferCreate(NULL, 512, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
825 scstr_t s; 829 cxstring s;
826 830
827 UcxMap *namespaces = ucx_map_new(8); 831 CxMap *namespaces = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 8);
832 namespaces->simple_destructor = free;
833
828 char prefix[8]; 834 char prefix[8];
829 int pfxnum = 0; 835 int pfxnum = 0;
830 UCX_FOREACH(elm, data->set) { 836 if(data->set) {
831 DavProperty *p = elm->data; 837 CxIterator i = cxListIterator(data->set);
832 if(strcmp(p->ns->name, "DAV:")) { 838 cx_foreach(DavProperty*, p, i) {
833 snprintf(prefix, 8, "x%d", pfxnum++); 839 if(strcmp(p->ns->name, "DAV:")) {
834 ucx_map_cstr_put(namespaces, p->ns->name, strdup(prefix)); 840 snprintf(prefix, 8, "x%d", pfxnum++);
835 } 841 cxMapPut(namespaces, cx_hash_key_str(p->ns->name), strdup(prefix));
836 } 842 }
837 UCX_FOREACH(elm, data->remove) { 843 }
838 DavProperty *p = elm->data; 844 }
839 if(strcmp(p->ns->name, "DAV:")) { 845 if(data->remove) {
840 snprintf(prefix, 8, "x%d", pfxnum++); 846 CxIterator i = cxListIterator(data->remove);
841 ucx_map_cstr_put(namespaces, p->ns->name, strdup(prefix)); 847 cx_foreach(DavProperty*, p, i) {
842 } 848 if(strcmp(p->ns->name, "DAV:")) {
843 } 849 snprintf(prefix, 8, "x%d", pfxnum++);
844 850 cxMapPut(namespaces, cx_hash_key_str(p->ns->name), strdup(prefix));
845 s = SC("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); 851 }
846 ucx_buffer_write(s.ptr, 1, s.length, buf); 852 }
853 }
854
855 s = CX_STR("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
856 cxBufferWrite(s.ptr, 1, s.length, buf);
847 857
848 // write root element and namespaces 858 // write root element and namespaces
849 s = SC("<D:propertyupdate xmlns:D=\"DAV:\""); 859 s = CX_STR("<D:propertyupdate xmlns:D=\"DAV:\"");
850 ucx_buffer_write(s.ptr, 1, s.length, buf); 860 cxBufferWrite(s.ptr, 1, s.length, buf);
851 UcxMapIterator mapi = ucx_map_iterator(namespaces); 861 CxIterator mapi = cxMapIterator(namespaces);
852 UcxKey key; 862 cx_foreach(CxMapEntry*, entry, mapi) {
853 char *pfxval; 863 s = CX_STR(" xmlns:");
854 UCX_MAP_FOREACH(key, pfxval, mapi) { 864 cxBufferWrite(s.ptr, 1, s.length, buf);
855 s = SC(" xmlns:"); 865 s = cx_str(entry->value);
856 ucx_buffer_write(s.ptr, 1, s.length, buf); 866 cxBufferWrite(s.ptr, 1, s.length, buf);
857 s = scstr(pfxval); 867 s = CX_STR("=\"");
858 ucx_buffer_write(s.ptr, 1, s.length, buf); 868 cxBufferWrite(s.ptr, 1, s.length, buf);
859 s = SC("=\""); 869 s = cx_strn(entry->key->data, entry->key->len);
860 ucx_buffer_write(s.ptr, 1, s.length, buf); 870 cxBufferWrite(s.ptr, 1, s.length, buf);
861 s = scstrn(key.data, key.len); 871 s = CX_STR("\"");
862 ucx_buffer_write(s.ptr, 1, s.length, buf); 872 cxBufferWrite(s.ptr, 1, s.length, buf);
863 s = SC("\""); 873 }
864 ucx_buffer_write(s.ptr, 1, s.length, buf); 874 s = CX_STR(">\n");
865 } 875 cxBufferWrite(s.ptr, 1, s.length, buf);
866 s = SC(">\n");
867 ucx_buffer_write(s.ptr, 1, s.length, buf);
868 876
869 if(data->set) { 877 if(data->set) {
870 s = SC("<D:set>\n<D:prop>\n"); 878 s = CX_STR("<D:set>\n<D:prop>\n");
871 ucx_buffer_write(s.ptr, 1, s.length, buf); 879 cxBufferWrite(s.ptr, 1, s.length, buf);
872 UCX_FOREACH(elm, data->set) { 880 CxIterator i = cxListIterator(data->set);
873 DavProperty *property = elm->data; 881 cx_foreach(DavProperty*, property, i) {
874 char *prefix = ucx_map_cstr_get(namespaces, property->ns->name); 882 char *prefix = cxMapGet(namespaces, cx_hash_key_str(property->ns->name));
875 if(!prefix) { 883 if(!prefix) {
876 prefix = "D"; 884 prefix = "D";
877 } 885 }
878 886
879 // begin tag 887 // begin tag
880 s = SC("<"); 888 s = CX_STR("<");
881 ucx_buffer_write(s.ptr, 1, s.length, buf); 889 cxBufferWrite(s.ptr, 1, s.length, buf);
882 s = scstr(prefix); 890 s = cx_str(prefix);
883 ucx_buffer_write(s.ptr, 1, s.length, buf); 891 cxBufferWrite(s.ptr, 1, s.length, buf);
884 s = SC(":"); 892 s = CX_STR(":");
885 ucx_buffer_write(s.ptr, 1, s.length, buf); 893 cxBufferWrite(s.ptr, 1, s.length, buf);
886 s = scstr(property->name); 894 s = cx_str(property->name);
887 ucx_buffer_write(s.ptr, 1, s.length, buf); 895 cxBufferWrite(s.ptr, 1, s.length, buf);
888 s = SC(">"); 896 s = CX_STR(">");
889 ucx_buffer_write(s.ptr, 1, s.length, buf); 897 cxBufferWrite(s.ptr, 1, s.length, buf);
890 898
891 // content 899 // content
892 DavXmlNode *content = property->value; 900 DavXmlNode *content = property->value;
893 if(content->type == DAV_XML_TEXT && !content->next) { 901 if(content->type == DAV_XML_TEXT && !content->next) {
894 ucx_buffer_write(content->content, 1, content->contentlength, buf); 902 cxBufferWrite(content->content, 1, content->contentlength, buf);
895 } else { 903 } else {
896 dav_print_node(buf, (write_func)ucx_buffer_write, namespaces, content); 904 dav_print_node(buf, (cx_write_func)cxBufferWrite, namespaces, content);
897 } 905 }
898 906
899 // end tag 907 // end tag
900 s = SC("</"); 908 s = CX_STR("</");
901 ucx_buffer_write(s.ptr, 1, s.length, buf); 909 cxBufferWrite(s.ptr, 1, s.length, buf);
902 s = scstr(prefix); 910 s = cx_str(prefix);
903 ucx_buffer_write(s.ptr, 1, s.length, buf); 911 cxBufferWrite(s.ptr, 1, s.length, buf);
904 s = SC(":"); 912 s = CX_STR(":");
905 ucx_buffer_write(s.ptr, 1, s.length, buf); 913 cxBufferWrite(s.ptr, 1, s.length, buf);
906 s = scstr(property->name); 914 s = cx_str(property->name);
907 ucx_buffer_write(s.ptr, 1, s.length, buf); 915 cxBufferWrite(s.ptr, 1, s.length, buf);
908 s = SC(">\n"); 916 s = CX_STR(">\n");
909 ucx_buffer_write(s.ptr, 1, s.length, buf); 917 cxBufferWrite(s.ptr, 1, s.length, buf);
910 } 918 }
911 s = SC("</D:prop>\n</D:set>\n"); 919 s = CX_STR("</D:prop>\n</D:set>\n");
912 ucx_buffer_write(s.ptr, 1, s.length, buf); 920 cxBufferWrite(s.ptr, 1, s.length, buf);
913 } 921 }
914 if(data->remove) { 922 if(data->remove) {
915 s = SC("<D:remove>\n<D:prop>\n"); 923 s = CX_STR("<D:remove>\n<D:prop>\n");
916 ucx_buffer_write(s.ptr, 1, s.length, buf); 924 cxBufferWrite(s.ptr, 1, s.length, buf);
917 UCX_FOREACH(elm, data->remove) { 925 CxIterator i = cxListIterator(data->remove);
918 DavProperty *property = elm->data; 926 cx_foreach(DavProperty*, property, i) {
919 char *prefix = ucx_map_cstr_get(namespaces, property->ns->name); 927 char *prefix = cxMapGet(namespaces, cx_hash_key_str(property->ns->name));
920 928
921 s = SC("<"); 929 s = CX_STR("<");
922 ucx_buffer_write(s.ptr, 1, s.length, buf); 930 cxBufferWrite(s.ptr, 1, s.length, buf);
923 s = scstr(prefix); 931 s = cx_str(prefix);
924 ucx_buffer_write(s.ptr, 1, s.length, buf); 932 cxBufferWrite(s.ptr, 1, s.length, buf);
925 s = SC(":"); 933 s = CX_STR(":");
926 ucx_buffer_write(s.ptr, 1, s.length, buf); 934 cxBufferWrite(s.ptr, 1, s.length, buf);
927 s = scstr(property->name); 935 s = cx_str(property->name);
928 ucx_buffer_write(s.ptr, 1, s.length, buf); 936 cxBufferWrite(s.ptr, 1, s.length, buf);
929 s = SC(" />\n"); 937 s = CX_STR(" />\n");
930 ucx_buffer_write(s.ptr, 1, s.length, buf); 938 cxBufferWrite(s.ptr, 1, s.length, buf);
931 } 939 }
932 s = SC("</D:prop>\n</D:remove>\n"); 940 s = CX_STR("</D:prop>\n</D:remove>\n");
933 ucx_buffer_write(s.ptr, 1, s.length, buf); 941 cxBufferWrite(s.ptr, 1, s.length, buf);
934 } 942 }
935 943
936 s = SC("</D:propertyupdate>\n"); 944 s = CX_STR("</D:propertyupdate>\n");
937 ucx_buffer_write(s.ptr, 1, s.length, buf); 945 cxBufferWrite(s.ptr, 1, s.length, buf);
938 946
939 // cleanup namespace map 947 // cleanup namespace map
940 ucx_map_free_content(namespaces, free); 948 cxMapDestroy(namespaces);
941 ucx_map_free(namespaces);
942 949
943 return buf; 950 return buf;
944 } 951 }
945 952
946 UcxBuffer* create_crypto_proppatch_request(DavSession *sn, DavKey *key, const char *name, const char *hash) { 953 CxBuffer* create_crypto_proppatch_request(DavSession *sn, DavKey *key, const char *name, const char *hash) {
947 UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND); 954 CxBuffer *buf = cxBufferCreate(NULL, 512, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
948 sstr_t s; 955 cxstring s;
949 956
950 s = S("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); 957 s = CX_STR("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
951 ucx_buffer_write(s.ptr, 1, s.length, buf); 958 cxBufferWrite(s.ptr, 1, s.length, buf);
952 959
953 s = S("<D:propertyupdate xmlns:D=\"DAV:\" xmlns:idav=\"" DAV_NS "\">\n"); 960 s = CX_STR("<D:propertyupdate xmlns:D=\"DAV:\" xmlns:idav=\"" DAV_NS "\">\n");
954 ucx_buffer_write(s.ptr, 1, s.length, buf); 961 cxBufferWrite(s.ptr, 1, s.length, buf);
955 962
956 s = S("<D:set>\n<D:prop>\n"); 963 s = CX_STR("<D:set>\n<D:prop>\n");
957 ucx_buffer_write(s.ptr, 1, s.length, buf); 964 cxBufferWrite(s.ptr, 1, s.length, buf);
958 965
959 if(DAV_ENCRYPT_NAME(sn)) { 966 if(DAV_ENCRYPT_NAME(sn)) {
960 s = S("<idav:crypto-name>"); 967 s = CX_STR("<idav:crypto-name>");
961 ucx_buffer_write(s.ptr, 1, s.length, buf); 968 cxBufferWrite(s.ptr, 1, s.length, buf);
962 char *crname = aes_encrypt(name, strlen(name), key); 969 char *crname = aes_encrypt(name, strlen(name), key);
963 ucx_buffer_puts(buf, crname); 970 cxBufferPutString(buf, crname);
964 free(crname); 971 free(crname);
965 s = S("</idav:crypto-name>\n"); 972 s = CX_STR("</idav:crypto-name>\n");
966 ucx_buffer_write(s.ptr, 1, s.length, buf); 973 cxBufferWrite(s.ptr, 1, s.length, buf);
967 } 974 }
968 975
969 s = S("<idav:crypto-key>"); 976 s = CX_STR("<idav:crypto-key>");
970 ucx_buffer_write(s.ptr, 1, s.length, buf); 977 cxBufferWrite(s.ptr, 1, s.length, buf);
971 ucx_buffer_puts(buf, key->name); 978 cxBufferPutString(buf, key->name);
972 s = S("</idav:crypto-key>\n"); 979 s = CX_STR("</idav:crypto-key>\n");
973 ucx_buffer_write(s.ptr, 1, s.length, buf); 980 cxBufferWrite(s.ptr, 1, s.length, buf);
974 981
975 if(hash) { 982 if(hash) {
976 s = S("<idav:crypto-hash>"); 983 s = CX_STR("<idav:crypto-hash>");
977 ucx_buffer_write(s.ptr, 1, s.length, buf); 984 cxBufferWrite(s.ptr, 1, s.length, buf);
978 ucx_buffer_puts(buf, hash); 985 cxBufferPutString(buf, hash);
979 s = S("</idav:crypto-hash>\n"); 986 s = CX_STR("</idav:crypto-hash>\n");
980 ucx_buffer_write(s.ptr, 1, s.length, buf); 987 cxBufferWrite(s.ptr, 1, s.length, buf);
981 } 988 }
982 989
983 s = S("</D:prop>\n</D:set>\n</D:propertyupdate>\n"); 990 s = CX_STR("</D:prop>\n</D:set>\n</D:propertyupdate>\n");
984 ucx_buffer_write(s.ptr, 1, s.length, buf); 991 cxBufferWrite(s.ptr, 1, s.length, buf);
985 992
986 return buf; 993 return buf;
987 } 994 }
988 995
989 /* ----------------------------- PUT ----------------------------- */ 996 /* ----------------------------- PUT ----------------------------- */
1004 char *url = NULL; 1011 char *url = NULL;
1005 curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); 1012 curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
1006 char *ltheader = NULL; 1013 char *ltheader = NULL;
1007 if(create) { 1014 if(create) {
1008 url = util_parent_path(url); 1015 url = util_parent_path(url);
1009 ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; 1016 ltheader = cx_asprintf("If: <%s> (<%s>)", url, lock).ptr;
1010 free(url); 1017 free(url);
1011 } else { 1018 } else {
1012 ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; 1019 ltheader = cx_asprintf("If: <%s> (<%s>)", url, lock).ptr;
1013 } 1020 }
1014 headers = curl_slist_append(headers, ltheader); 1021 headers = curl_slist_append(headers, ltheader);
1015 free(ltheader); 1022 free(ltheader);
1016 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); 1023 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
1017 } 1024 }
1018 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); 1025 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
1019 1026
1020 UcxBuffer *buf = NULL; 1027 CxBuffer *buf = NULL;
1021 if(!read_func) { 1028 if(!read_func) {
1022 buf = ucx_buffer_new(data, length, 0); 1029 buf = cxBufferCreate(data, length, cxDefaultAllocator, 0);
1023 buf->size = length; 1030 buf->size = length;
1024 data = buf; 1031 data = buf;
1025 read_func = (dav_read_func)ucx_buffer_read; 1032 read_func = (dav_read_func)cxBufferRead;
1026 curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)length); 1033 curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)length);
1027 } else if(length == 0) { 1034 } else if(length == 0) {
1028 headers = curl_slist_append(headers, "Transfer-Encoding: chunked"); 1035 headers = curl_slist_append(headers, "Transfer-Encoding: chunked");
1029 curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)1); 1036 curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)1);
1030 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); 1037 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
1040 curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); 1047 curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL);
1041 1048
1042 CURLcode ret = dav_session_curl_perform(sn, NULL); 1049 CURLcode ret = dav_session_curl_perform(sn, NULL);
1043 curl_slist_free_all(headers); 1050 curl_slist_free_all(headers);
1044 if(buf) { 1051 if(buf) {
1045 ucx_buffer_free(buf); 1052 cxBufferFree(buf);
1046 } 1053 }
1047 1054
1048 return ret; 1055 return ret;
1049 } 1056 }
1050 1057
1051 CURLcode do_delete_request(DavSession *sn, char *lock, UcxBuffer *response) { 1058 CURLcode do_delete_request(DavSession *sn, char *lock, CxBuffer *response) {
1052 CURL *handle = sn->handle; 1059 CURL *handle = sn->handle;
1053 struct curl_slist *headers = NULL; 1060 struct curl_slist *headers = NULL;
1054 if(lock) { 1061 if(lock) {
1055 char *url = NULL; 1062 char *url = NULL;
1056 curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); 1063 curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
1057 char *ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; 1064 char *ltheader = cx_asprintf("If: <%s> (<%s>)", url, lock).ptr;
1058 headers = curl_slist_append(headers, ltheader); 1065 headers = curl_slist_append(headers, ltheader);
1059 free(ltheader); 1066 free(ltheader);
1060 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); 1067 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
1061 } else { 1068 } else {
1062 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL); 1069 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL);
1063 } 1070 }
1064 1071
1065 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "DELETE"); 1072 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "DELETE");
1066 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); 1073 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
1067 1074
1068 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); 1075 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, cxBufferWrite);
1069 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); 1076 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
1070 1077
1071 CURLcode ret = dav_session_curl_perform(sn, NULL); 1078 CURLcode ret = dav_session_curl_perform(sn, NULL);
1072 curl_slist_free_all(headers); 1079 curl_slist_free_all(headers);
1073 return ret; 1080 return ret;
1078 struct curl_slist *headers = NULL; 1085 struct curl_slist *headers = NULL;
1079 if(lock) { 1086 if(lock) {
1080 char *url = NULL; 1087 char *url = NULL;
1081 curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); 1088 curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
1082 url = util_parent_path(url); 1089 url = util_parent_path(url);
1083 char *ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; 1090 char *ltheader = cx_asprintf("If: <%s> (<%s>)", url, lock).ptr;
1084 free(url); 1091 free(url);
1085 headers = curl_slist_append(headers, ltheader); 1092 headers = curl_slist_append(headers, ltheader);
1086 free(ltheader); 1093 free(ltheader);
1087 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); 1094 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
1088 } else { 1095 } else {
1136 1143
1137 struct curl_slist *headers = NULL; 1144 struct curl_slist *headers = NULL;
1138 if(lock) { 1145 if(lock) {
1139 char *url = NULL; 1146 char *url = NULL;
1140 curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); 1147 curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
1141 char *ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; 1148 char *ltheader = cx_asprintf("If: <%s> (<%s>)", url, lock).ptr;
1142 headers = curl_slist_append(headers, ltheader); 1149 headers = curl_slist_append(headers, ltheader);
1143 free(ltheader); 1150 free(ltheader);
1144 } 1151 }
1145 //sstr_t deststr = ucx_sprintf("Destination: %s", dest); 1152 //cxstring deststr = ucx_sprintf("Destination: %s", dest);
1146 sstr_t deststr = sstrcat(2, S("Destination: "), sstr(dest)); 1153 cxmutstr deststr = cx_strcat(2, CX_STR("Destination: "), cx_str(dest));
1147 headers = curl_slist_append(headers, deststr.ptr); 1154 headers = curl_slist_append(headers, deststr.ptr);
1148 if(override) { 1155 if(override) {
1149 headers = curl_slist_append(headers, "Overwrite: T"); 1156 headers = curl_slist_append(headers, "Overwrite: T");
1150 } else { 1157 } else {
1151 headers = curl_slist_append(headers, "Overwrite: F"); 1158 headers = curl_slist_append(headers, "Overwrite: F");
1159 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); 1166 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
1160 return ret; 1167 return ret;
1161 } 1168 }
1162 1169
1163 1170
1164 UcxBuffer* create_lock_request(void) { 1171 CxBuffer* create_lock_request(void) {
1165 UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND); 1172 CxBuffer *buf = cxBufferCreate(NULL, 512, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
1166 sstr_t s; 1173 cxstring s;
1167 1174
1168 s = S("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); 1175 s = CX_STR("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
1169 ucx_buffer_write(s.ptr, 1, s.length, buf); 1176 cxBufferWrite(s.ptr, 1, s.length, buf);
1170 1177
1171 s = S("<D:lockinfo xmlns:D=\"DAV:\">\n" 1178 s = CX_STR("<D:lockinfo xmlns:D=\"DAV:\">\n"
1172 "<D:lockscope><D:exclusive/></D:lockscope>\n" 1179 "<D:lockscope><D:exclusive/></D:lockscope>\n"
1173 "<D:locktype><D:write/></D:locktype>\n" 1180 "<D:locktype><D:write/></D:locktype>\n"
1174 "<D:owner><D:href>http://davutils.org/libidav/</D:href></D:owner>\n"); 1181 "<D:owner><D:href>http://davutils.org/libidav/</D:href></D:owner>\n");
1175 ucx_buffer_write(s.ptr, 1, s.length, buf); 1182 cxBufferWrite(s.ptr, 1, s.length, buf);
1176 1183
1177 s = S("</D:lockinfo>\n"); 1184 s = CX_STR("</D:lockinfo>\n");
1178 ucx_buffer_write(s.ptr, 1, s.length, buf); 1185 cxBufferWrite(s.ptr, 1, s.length, buf);
1179 1186
1180 return buf; 1187 return buf;
1181 } 1188 }
1182 1189
1183 int parse_lock_response(DavSession *sn, UcxBuffer *response, LockDiscovery *lock) { 1190 int parse_lock_response(DavSession *sn, CxBuffer *response, LockDiscovery *lock) {
1184 lock->locktoken = NULL; 1191 lock->locktoken = NULL;
1185 lock->timeout = NULL; 1192 lock->timeout = NULL;
1186 1193
1187 xmlDoc *doc = xmlReadMemory(response->space, response->size, NULL, NULL, 0); 1194 xmlDoc *doc = xmlReadMemory(response->space, response->size, NULL, NULL, 0);
1188 if(!doc) { 1195 if(!doc) {
1238 1245
1239 xmlFreeDoc(doc); 1246 xmlFreeDoc(doc);
1240 return ret; 1247 return ret;
1241 } 1248 }
1242 1249
1243 CURLcode do_lock_request(DavSession *sn, UcxBuffer *request, UcxBuffer *response, time_t timeout) { 1250 CURLcode do_lock_request(DavSession *sn, CxBuffer *request, CxBuffer *response, time_t timeout) {
1244 CURL *handle = sn->handle; 1251 CURL *handle = sn->handle;
1245 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "LOCK"); 1252 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "LOCK");
1246 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L); 1253 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L);
1247 request->pos = 0; 1254 request->pos = 0;
1248 1255
1249 // clear headers 1256 // clear headers
1250 struct curl_slist *headers = NULL; 1257 struct curl_slist *headers = NULL;
1251 1258
1252 if(timeout != 0) { 1259 if(timeout != 0) {
1253 sstr_t thdr; 1260 cxmutstr thdr;
1254 if(timeout < 0) { 1261 if(timeout < 0) {
1255 thdr = ucx_sprintf("%s", "Timeout: Infinite"); 1262 thdr = cx_asprintf("%s", "Timeout: Infinite");
1256 } else { 1263 } else {
1257 thdr = ucx_sprintf("Timeout: Second-%u", (unsigned int)timeout); 1264 thdr = cx_asprintf("Timeout: Second-%u", (unsigned int)timeout);
1258 } 1265 }
1259 headers = curl_slist_append(headers, thdr.ptr); 1266 headers = curl_slist_append(headers, thdr.ptr);
1260 free(thdr.ptr); 1267 free(thdr.ptr);
1261 } 1268 }
1262 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); 1269 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
1263 1270
1264 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); 1271 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1);
1265 curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); 1272 curl_easy_setopt(handle, CURLOPT_READFUNCTION, cxBufferRead);
1266 curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, dav_buffer_seek); 1273 curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, cxBufferSeek);
1267 curl_easy_setopt(handle, CURLOPT_READDATA, request); 1274 curl_easy_setopt(handle, CURLOPT_READDATA, request);
1268 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); 1275 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size);
1269 1276
1270 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); 1277 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, cxBufferWrite);
1271 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); 1278 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
1272 1279
1273 CURLcode ret = dav_session_curl_perform_buf(sn, request, response, NULL); 1280 CURLcode ret = dav_session_curl_perform_buf(sn, request, response, NULL);
1274 1281
1275 if(headers) { 1282 if(headers) {
1286 1293
1287 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); 1294 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write);
1288 curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); 1295 curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL);
1289 1296
1290 // set lock-token header 1297 // set lock-token header
1291 sstr_t ltheader = ucx_sprintf("Lock-Token: <%s>", locktoken); 1298 cxmutstr ltheader = cx_asprintf("Lock-Token: <%s>", locktoken);
1292 struct curl_slist *headers = curl_slist_append(NULL, ltheader.ptr); 1299 struct curl_slist *headers = curl_slist_append(NULL, ltheader.ptr);
1293 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); 1300 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
1294 1301
1295 CURLcode ret = dav_session_curl_perform(sn, NULL); 1302 CURLcode ret = dav_session_curl_perform(sn, NULL);
1296 curl_slist_free_all(headers); 1303 curl_slist_free_all(headers);
1306 1313
1307 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); 1314 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write);
1308 curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); 1315 curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL);
1309 1316
1310 // set lock-token header 1317 // set lock-token header
1311 sstr_t ltheader; 1318 cxmutstr ltheader;
1312 struct curl_slist *headers = NULL; 1319 struct curl_slist *headers = NULL;
1313 if(locktoken) { 1320 if(locktoken) {
1314 ltheader = ucx_sprintf("Lock-Token: <%s>", locktoken); 1321 ltheader = cx_asprintf("Lock-Token: <%s>", locktoken);
1315 headers = curl_slist_append(NULL, ltheader.ptr); 1322 headers = curl_slist_append(NULL, ltheader.ptr);
1316 } 1323 }
1317 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); 1324 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
1318 1325
1319 CURLcode ret = dav_session_curl_perform(sn, NULL); 1326 CURLcode ret = dav_session_curl_perform(sn, NULL);
1324 1331
1325 return ret; 1332 return ret;
1326 } 1333 }
1327 1334
1328 1335
1329 CURLcode do_report_request(DavSession *sn, UcxBuffer *request, UcxBuffer *response) { 1336 CURLcode do_report_request(DavSession *sn, CxBuffer *request, CxBuffer *response) {
1330 CURL *handle = sn->handle; 1337 CURL *handle = sn->handle;
1331 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "REPORT"); 1338 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "REPORT");
1332 1339
1333 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); 1340 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1);
1334 curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); 1341 curl_easy_setopt(handle, CURLOPT_READFUNCTION, cxBufferRead);
1335 curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, dav_buffer_seek); 1342 curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, cxBufferSeek);
1336 curl_easy_setopt(handle, CURLOPT_READDATA, request); 1343 curl_easy_setopt(handle, CURLOPT_READDATA, request);
1337 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); 1344 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size);
1338 1345
1339 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); 1346 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, cxBufferWrite);
1340 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); 1347 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
1341 1348
1342 struct curl_slist *headers = NULL; 1349 struct curl_slist *headers = NULL;
1343 headers = curl_slist_append(headers, "Content-Type: text/xml"); 1350 headers = curl_slist_append(headers, "Content-Type: text/xml");
1344 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); 1351 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);

mercurial