| 47 // initialize |
47 // initialize |
| 48 DavContext *context = calloc(1, sizeof(DavContext)); |
48 DavContext *context = calloc(1, sizeof(DavContext)); |
| 49 if(!context) { |
49 if(!context) { |
| 50 return NULL; |
50 return NULL; |
| 51 } |
51 } |
| 52 context->sessions = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_ptr, CX_STORE_POINTERS); |
52 context->sessions = cxLinkedListCreate(cxDefaultAllocator, CX_STORE_POINTERS); |
| 53 cxDefineDestructor(context->sessions, dav_session_destructor); |
53 cxSetDestructor(context->sessions, dav_session_destructor); |
| 54 context->http_proxy = calloc(1, sizeof(DavProxy)); |
54 context->http_proxy = calloc(1, sizeof(DavProxy)); |
| 55 if(!context->http_proxy) { |
55 if(!context->http_proxy) { |
| 56 dav_context_destroy(context); |
56 dav_context_destroy(context); |
| 57 return NULL; |
57 return NULL; |
| 58 } |
58 } |
| 385 CxList *proplist = NULL; |
385 CxList *proplist = NULL; |
| 386 if(properties) { |
386 if(properties) { |
| 387 proplist = parse_properties_string(sn->context, cx_str(properties)); |
387 proplist = parse_properties_string(sn->context, cx_str(properties)); |
| 388 } |
388 } |
| 389 CxBuffer *rqbuf = create_propfind_request(sn, proplist, "propfind", 0); |
389 CxBuffer *rqbuf = create_propfind_request(sn, proplist, "propfind", 0); |
| 390 CxBuffer *rpbuf = cxBufferCreate(NULL, 4096, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
390 CxBuffer *rpbuf = cxBufferCreate(cxDefaultAllocator, NULL, 4096, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
| 391 |
391 |
| 392 //fwrite(rqbuf->space, 1, rqbuf->size, stdout); |
392 //fwrite(rqbuf->space, 1, rqbuf->size, stdout); |
| 393 //printf("\n"); |
393 //printf("\n"); |
| 394 |
394 |
| 395 CURLcode ret = do_propfind_request(sn, rqbuf, rpbuf); |
395 CURLcode ret = do_propfind_request(sn, rqbuf, rpbuf); |
| 430 cxMapClear(data->properties); // TODO: free existing content |
430 cxMapClear(data->properties); // TODO: free existing content |
| 431 |
431 |
| 432 CURL *handle = sn->handle; |
432 CURL *handle = sn->handle; |
| 433 util_set_url(sn, dav_resource_get_href(root)); |
433 util_set_url(sn, dav_resource_get_href(root)); |
| 434 |
434 |
| 435 CxBuffer *rpbuf = cxBufferCreate(NULL, 4096, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
435 CxBuffer *rpbuf = cxBufferCreate(cxDefaultAllocator, NULL, 4096, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
| 436 DavResource *resource = root; |
436 DavResource *resource = root; |
| 437 CURLcode ret = do_propfind_request(sn, rqbuf, rpbuf); |
437 CURLcode ret = do_propfind_request(sn, rqbuf, rpbuf); |
| 438 long status = 0; |
438 long status = 0; |
| 439 long error = 0; |
439 long error = 0; |
| 440 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status); |
440 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status); |
| 452 cxBufferFree(rpbuf); |
452 cxBufferFree(rpbuf); |
| 453 return error; |
453 return error; |
| 454 } |
454 } |
| 455 |
455 |
| 456 CxList* parse_properties_string(DavContext *context, cxstring str) { |
456 CxList* parse_properties_string(DavContext *context, cxstring str) { |
| 457 CxList *proplist = cxLinkedListCreateSimple(sizeof(DavProperty)); |
457 CxList *proplist = cxLinkedListCreate(NULL, sizeof(DavProperty)); |
| 458 |
458 |
| 459 CxStrtokCtx tok = cx_strtok(str, cx_str(","), INT_MAX); |
459 CxStrtokCtx tok = cx_strtok(str, cx_str(","), INT_MAX); |
| 460 cxstring s; |
460 cxstring s; |
| 461 while(cx_strtok_next(&tok, &s)) { |
461 while(cx_strtok_next(&tok, &s)) { |
| 462 cxstring nsname = cx_strchr(s, ':'); |
462 cxstring nsname = cx_strchr(s, ':'); |