libidav/resource.c

branch
dav-2
changeset 891
4d58cbcc9efa
parent 889
42cdbf9bbd49
equal deleted inserted replaced
890:e77ccf1c4bb3 891:4d58cbcc9efa
358 358
359 cxmutstr dav_property_key_a(const CxAllocator *a, const char *ns, const char *name) { 359 cxmutstr dav_property_key_a(const CxAllocator *a, const char *ns, const char *name) {
360 cxstring ns_str = cx_str(ns); 360 cxstring ns_str = cx_str(ns);
361 cxstring name_str = cx_str(name); 361 cxstring name_str = cx_str(name);
362 362
363 return cx_strcat_a(a, 4, ns_str, CX_STR("\0"), name_str, CX_STR("\0")); 363 return cx_strcat_a(a, 4, ns_str, cx_str("\0"), name_str, cx_str("\0"));
364 } 364 }
365 365
366 366
367 367
368 368
617 return 0; 617 return 0;
618 } 618 }
619 619
620 static int add2propertylist(const CxAllocator *a, CxList **list, DavProperty *property) { 620 static int add2propertylist(const CxAllocator *a, CxList **list, DavProperty *property) {
621 if(!*list) { 621 if(!*list) {
622 CxList *newlist = cxLinkedListCreate(a, NULL, CX_STORE_POINTERS); 622 CxList *newlist = cxLinkedListCreate(a, CX_STORE_POINTERS);
623 if(!newlist) { 623 if(!newlist) {
624 return 1; 624 return 1;
625 } 625 }
626 *list = newlist; 626 *list = newlist;
627 } 627 }
786 786
787 int dav_load_prop(DavResource *res, DavPropName *properties, size_t numprop) { 787 int dav_load_prop(DavResource *res, DavPropName *properties, size_t numprop) {
788 CxMempool *mp = cxMempoolCreateSimple(64); 788 CxMempool *mp = cxMempoolCreateSimple(64);
789 const CxAllocator *a = mp->allocator; 789 const CxAllocator *a = mp->allocator;
790 790
791 CxList *proplist = cxArrayListCreate(a, NULL, sizeof(DavProperty), numprop); 791 CxList *proplist = cxArrayListCreate(a, sizeof(DavProperty), numprop);
792 for(size_t i=0;i<numprop;i++) { 792 for(size_t i=0;i<numprop;i++) {
793 DavProperty p; 793 DavProperty p;
794 p.name = properties[i].name; 794 p.name = properties[i].name;
795 p.ns = cxMalloc(a, sizeof(DavNamespace)); 795 p.ns = cxMalloc(a, sizeof(DavNamespace));
796 p.ns->name = properties[i].ns; 796 p.ns->name = properties[i].ns;
868 sn->key, 868 sn->key,
869 data->content, 869 data->content,
870 data->read, 870 data->read,
871 data->seek); 871 data->seek);
872 } else { 872 } else {
873 buf = cxBufferCreate(data->content, data->length, cxDefaultAllocator, 0); 873 buf = cxBufferCreate(cxDefaultAllocator, data->content, data->length, 0);
874 buf->size = data->length; 874 buf->size = data->length;
875 enc = aes_encrypter_new( 875 enc = aes_encrypter_new(
876 sn->key, 876 sn->key,
877 buf, 877 buf,
878 (dav_read_func)cxBufferRead, 878 (dav_read_func)cxBufferRead,
910 free(enc_hash); 910 free(enc_hash);
911 } else if((sn->flags & DAV_SESSION_STORE_HASH) == DAV_SESSION_STORE_HASH) { 911 } else if((sn->flags & DAV_SESSION_STORE_HASH) == DAV_SESSION_STORE_HASH) {
912 HashStream hstr; 912 HashStream hstr;
913 CxBuffer *iobuf = NULL; 913 CxBuffer *iobuf = NULL;
914 if(!data->read) { 914 if(!data->read) {
915 iobuf = cxBufferCreate(data->content, data->length, cxDefaultAllocator, 0); 915 iobuf = cxBufferCreate(cxDefaultAllocator, data->content, data->length, 0);
916 iobuf->size = data->length; 916 iobuf->size = data->length;
917 init_hash_stream( 917 init_hash_stream(
918 &hstr, 918 &hstr,
919 iobuf, 919 iobuf,
920 (dav_read_func)cxBufferRead, 920 (dav_read_func)cxBufferRead,
1043 // store properties 1043 // store properties
1044 int r = 0; 1044 int r = 0;
1045 sn->error = DAV_OK; 1045 sn->error = DAV_OK;
1046 if(data->set || data->remove > 0) { 1046 if(data->set || data->remove > 0) {
1047 CxBuffer *request = create_proppatch_request(data); 1047 CxBuffer *request = create_proppatch_request(data);
1048 CxBuffer *response = cxBufferCreate(NULL, 1024, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); 1048 CxBuffer *response = cxBufferCreate(cxDefaultAllocator, NULL, 1024, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
1049 //printf("request:\n%.*s\n\n", request->pos, request->space); 1049 //printf("request:\n%.*s\n\n", request->pos, request->space);
1050 1050
1051 CURLcode ret = do_proppatch_request(sn, locktoken, request, response); 1051 CURLcode ret = do_proppatch_request(sn, locktoken, request, response);
1052 long status = 0; 1052 long status = 0;
1053 curl_easy_getinfo (sn->handle, CURLINFO_RESPONSE_CODE, &status); 1053 curl_easy_getinfo (sn->handle, CURLINFO_RESPONSE_CODE, &status);
1194 util_set_url(res->session, dav_resource_get_href(res)); 1194 util_set_url(res->session, dav_resource_get_href(res));
1195 1195
1196 DavLock *lock = dav_get_lock(res->session, res->path); 1196 DavLock *lock = dav_get_lock(res->session, res->path);
1197 char *locktoken = lock ? lock->token : NULL; 1197 char *locktoken = lock ? lock->token : NULL;
1198 1198
1199 CxBuffer *response = cxBufferCreate(NULL, 4096, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); 1199 CxBuffer *response = cxBufferCreate(cxDefaultAllocator, NULL, 4096, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
1200 CURLcode ret = do_delete_request(res->session, locktoken, response); 1200 CURLcode ret = do_delete_request(res->session, locktoken, response);
1201 long status = 0; 1201 long status = 0;
1202 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status); 1202 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
1203 int r = 0; 1203 int r = 0;
1204 if(ret == CURLE_OK && (status >= 200 && status < 300)) { 1204 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
1397 DavSession *sn = res->session; 1397 DavSession *sn = res->session;
1398 CURL *handle = sn->handle; 1398 CURL *handle = sn->handle;
1399 util_set_url(sn, dav_resource_get_href(res)); 1399 util_set_url(sn, dav_resource_get_href(res));
1400 1400
1401 CxBuffer *request = create_lock_request(); 1401 CxBuffer *request = create_lock_request();
1402 CxBuffer *response = cxBufferCreate(NULL, 512, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); 1402 CxBuffer *response = cxBufferCreate(cxDefaultAllocator, NULL, 512, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
1403 CURLcode ret = do_lock_request(sn, request, response, timeout); 1403 CURLcode ret = do_lock_request(sn, request, response, timeout);
1404 1404
1405 //printf("\nlock\n"); 1405 //printf("\nlock\n");
1406 //printf("%.*s\n\n", request->size, request->space); 1406 //printf("%.*s\n\n", request->size, request->space);
1407 //printf("%.*s\n\n", response->size, response->space); 1407 //printf("%.*s\n\n", response->size, response->space);
1474 if(!DAV_IS_ENCRYPTED(sn)) { 1474 if(!DAV_IS_ENCRYPTED(sn)) {
1475 return 0; 1475 return 0;
1476 } 1476 }
1477 1477
1478 CxBuffer *request = create_crypto_proppatch_request(sn, sn->key, name, hash); 1478 CxBuffer *request = create_crypto_proppatch_request(sn, sn->key, name, hash);
1479 CxBuffer *response = cxBufferCreate(NULL, 1024, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); 1479 CxBuffer *response = cxBufferCreate(cxDefaultAllocator, NULL, 1024, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
1480 1480
1481 util_set_url(sn, href); 1481 util_set_url(sn, href);
1482 // TODO: lock 1482 // TODO: lock
1483 CURLcode ret = do_proppatch_request(sn, NULL, request, response); 1483 CURLcode ret = do_proppatch_request(sn, NULL, request, response);
1484 cxBufferFree(request); 1484 cxBufferFree(request);
1501 DavXmlNode* create_crypto_prop(DavSession *sn, CxMap *properties) { 1501 DavXmlNode* create_crypto_prop(DavSession *sn, CxMap *properties) {
1502 if(!sn->key) { 1502 if(!sn->key) {
1503 return NULL; 1503 return NULL;
1504 } 1504 }
1505 1505
1506 CxBuffer *content = cxBufferCreate(NULL, 2048, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); 1506 CxBuffer *content = cxBufferCreate(cxDefaultAllocator, NULL, 2048, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
1507 1507
1508 // create an xml document containing all properties 1508 // create an xml document containing all properties
1509 CxMap *nsmap = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 8); 1509 CxMap *nsmap = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 8);
1510 cxDefineDestructor(nsmap, free); 1510 cxSetDestructor(nsmap, free);
1511 cxMapPut(nsmap, cx_hash_key_str("DAV:"), strdup("D")); 1511 cxMapPut(nsmap, cx_hash_key_str("DAV:"), strdup("D"));
1512 1512
1513 cxBufferPutString(content, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); 1513 cxBufferPutString(content, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1514 cxBufferPutString(content, "<D:prop xmlns:D=\"DAV:\">\n"); 1514 cxBufferPutString(content, "<D:prop xmlns:D=\"DAV:\">\n");
1515 1515

mercurial