libidav/resource.c

changeset 354
067ea2315a8a
parent 349
0b4ecadaf3f9
child 355
5da2cf15eb44
equal deleted inserted replaced
353:e554f3d72d9e 354:067ea2315a8a
654 (dav_read_func)ucx_buffer_read); 654 (dav_read_func)ucx_buffer_read);
655 } 655 }
656 656
657 // put resource 657 // put resource
658 ret = do_put_request( 658 ret = do_put_request(
659 sn->handle, 659 sn,
660 locktoken, 660 locktoken,
661 TRUE, 661 TRUE,
662 enc, 662 enc,
663 (dav_read_func)aes_read, 663 (dav_read_func)aes_read,
664 0); 664 0);
681 } 681 }
682 resource_add_string_property(res, DAV_NS, "crypto-hash", enc_hash); 682 resource_add_string_property(res, DAV_NS, "crypto-hash", enc_hash);
683 free(enc_hash); 683 free(enc_hash);
684 } else { 684 } else {
685 ret = do_put_request( 685 ret = do_put_request(
686 sn->handle, 686 sn,
687 locktoken, 687 locktoken,
688 TRUE, 688 TRUE,
689 data->content, 689 data->content,
690 data->read, 690 data->read,
691 data->length); 691 data->length);
714 if(data->set || data->remove) { 714 if(data->set || data->remove) {
715 UcxBuffer *request = create_proppatch_request(data); 715 UcxBuffer *request = create_proppatch_request(data);
716 UcxBuffer *response = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND); 716 UcxBuffer *response = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND);
717 //printf("request:\n%.*s\n\n", request->pos, request->space); 717 //printf("request:\n%.*s\n\n", request->pos, request->space);
718 718
719 CURLcode ret = do_proppatch_request(sn->handle, locktoken, request, response); 719 CURLcode ret = do_proppatch_request(sn, locktoken, request, response);
720 long status = 0; 720 long status = 0;
721 curl_easy_getinfo (sn->handle, CURLINFO_RESPONSE_CODE, &status); 721 curl_easy_getinfo (sn->handle, CURLINFO_RESPONSE_CODE, &status);
722 if(ret == CURLE_OK && status == 207) { 722 if(ret == CURLE_OK && status == 207) {
723 //printf("%s\n", response->space); 723 //printf("%s\n", response->space);
724 // TODO: parse response 724 // TODO: parse response
763 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); 763 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
764 764
765 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_fnc); 765 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_fnc);
766 curl_easy_setopt(handle, CURLOPT_WRITEDATA, stream); 766 curl_easy_setopt(handle, CURLOPT_WRITEDATA, stream);
767 767
768 CURLcode ret = curl_easy_perform(handle); 768 long status = 0;
769 CURLcode ret = dav_session_curl_perform(sn, &status);
769 770
770 char *hash = NULL; 771 char *hash = NULL;
771 if(dec) { 772 if(dec) {
772 aes_decrypter_shutdown(dec); // get final bytes 773 aes_decrypter_shutdown(dec); // get final bytes
773 774
777 hash = util_hexstr(sha, DAV_SHA256_DIGEST_LENGTH); 778 hash = util_hexstr(sha, DAV_SHA256_DIGEST_LENGTH);
778 779
779 aes_decrypter_close(dec); 780 aes_decrypter_close(dec);
780 } 781 }
781 782
782 long status = 0;
783 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
784 if(ret == CURLE_OK && (status >= 200 && status < 300)) { 783 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
785 int verify_failed = 0; 784 int verify_failed = 0;
786 if(DAV_DECRYPT_CONTENT(sn) && key) { 785 if(DAV_DECRYPT_CONTENT(sn) && key) {
787 // try to verify the content 786 // try to verify the content
788 char *res_hash = dav_get_string_property_ns(res, DAV_NS, "crypto-hash"); 787 char *res_hash = dav_get_string_property_ns(res, DAV_NS, "crypto-hash");
834 833
835 DavLock *lock = dav_get_lock(res->session, res->path); 834 DavLock *lock = dav_get_lock(res->session, res->path);
836 char *locktoken = lock ? lock->token : NULL; 835 char *locktoken = lock ? lock->token : NULL;
837 836
838 UcxBuffer *response = ucx_buffer_new(NULL, 4096, UCX_BUFFER_AUTOEXTEND); 837 UcxBuffer *response = ucx_buffer_new(NULL, 4096, UCX_BUFFER_AUTOEXTEND);
839 CURLcode ret = do_delete_request(handle, locktoken, response); 838 CURLcode ret = do_delete_request(res->session, locktoken, response);
840 long status = 0; 839 long status = 0;
841 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status); 840 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
842 int r = 0; 841 int r = 0;
843 if(ret == CURLE_OK && (status >= 200 && status < 300)) { 842 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
844 res->session->error = DAV_OK; 843 res->session->error = DAV_OK;
871 char *p = util_parent_path(path); 870 char *p = util_parent_path(path);
872 char *h = util_parent_path(href); 871 char *h = util_parent_path(href);
873 872
874 for(int i=0;i<2;i++) { 873 for(int i=0;i<2;i++) {
875 util_set_url(sn, h); 874 util_set_url(sn, h);
876 code = do_mkcol_request(handle, locktoken); 875 code = do_mkcol_request(sn, locktoken);
877 curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &status); 876 curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &status);
878 if(status == 201) { 877 if(status == 201) {
879 // resource successfully created 878 // resource successfully created
880 char *name = util_resource_name(p); 879 char *name = util_resource_name(p);
881 int len = strlen(name); 880 int len = strlen(name);
916 DavLock *lock = dav_get_lock(res->session, res->path); 915 DavLock *lock = dav_get_lock(res->session, res->path);
917 char *locktoken = lock ? lock->token : NULL; 916 char *locktoken = lock ? lock->token : NULL;
918 917
919 CURLcode code; 918 CURLcode code;
920 if(res->iscollection) { 919 if(res->iscollection) {
921 code = do_mkcol_request(handle, locktoken); 920 code = do_mkcol_request(sn, locktoken);
922 } else { 921 } else {
923 code = do_put_request(handle, locktoken, TRUE, "", NULL, 0); 922 code = do_put_request(sn, locktoken, TRUE, "", NULL, 0);
924 } 923 }
925 long s = 0; 924 long s = 0;
926 curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &s); 925 curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &s);
927 *status = s; 926 *status = s;
928 if(code == CURLE_OK && (s >= 200 && s < 300)) { 927 if(code == CURLE_OK && (s >= 200 && s < 300)) {
963 int dav_exists(DavResource *res) { 962 int dav_exists(DavResource *res) {
964 DavSession *sn = res->session; 963 DavSession *sn = res->session;
965 CURL *handle = sn->handle; 964 CURL *handle = sn->handle;
966 util_set_url(sn, dav_resource_get_href(res)); 965 util_set_url(sn, dav_resource_get_href(res));
967 966
968 CURLcode ret = do_head_request(handle); 967 CURLcode ret = do_head_request(sn);
969 long status = 0; 968 long status = 0;
970 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status); 969 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
971 if(ret == CURLE_OK && (status >= 200 && status < 300)) { 970 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
972 return 1; 971 return 1;
973 } else { 972 } else {
982 util_set_url(sn, dav_resource_get_href(res)); 981 util_set_url(sn, dav_resource_get_href(res));
983 982
984 DavLock *lock = dav_get_lock(sn, res->path); 983 DavLock *lock = dav_get_lock(sn, res->path);
985 char *locktoken = lock ? lock->token : NULL; 984 char *locktoken = lock ? lock->token : NULL;
986 985
987 CURLcode ret = do_copy_move_request(handle, desturl, locktoken, copy, override); 986 CURLcode ret = do_copy_move_request(sn, desturl, locktoken, copy, override);
988 987
989 long status = 0; 988 long status = 0;
990 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status); 989 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
991 if(ret == CURLE_OK && (status >= 200 && status < 300)) { 990 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
992 return 0; 991 return 0;
1039 CURL *handle = sn->handle; 1038 CURL *handle = sn->handle;
1040 util_set_url(sn, dav_resource_get_href(res)); 1039 util_set_url(sn, dav_resource_get_href(res));
1041 1040
1042 UcxBuffer *request = create_lock_request(); 1041 UcxBuffer *request = create_lock_request();
1043 UcxBuffer *response = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND); 1042 UcxBuffer *response = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND);
1044 CURLcode ret = do_lock_request(handle, request, response, timeout); 1043 CURLcode ret = do_lock_request(sn, request, response, timeout);
1045 1044
1046 //printf("\nlock\n"); 1045 //printf("\nlock\n");
1047 //printf("%.*s\n\n", request->size, request->space); 1046 //printf("%.*s\n\n", request->size, request->space);
1048 //printf("%.*s\n\n", response->size, response->space); 1047 //printf("%.*s\n\n", response->size, response->space);
1049 1048
1095 if(!lock) { 1094 if(!lock) {
1096 sn->error = DAV_ERROR; 1095 sn->error = DAV_ERROR;
1097 return -1; 1096 return -1;
1098 } 1097 }
1099 1098
1100 CURLcode ret = do_unlock_request(handle, lock->token); 1099 CURLcode ret = do_unlock_request(sn, lock->token);
1101 long status = 0; 1100 long status = 0;
1102 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status); 1101 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
1103 if(ret == CURLE_OK && (status >= 200 && status < 300)) { 1102 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
1104 dav_remove_lock(sn, res->path, lock); 1103 dav_remove_lock(sn, res->path, lock);
1105 } else { 1104 } else {
1119 UcxBuffer *request = create_crypto_proppatch_request(sn, sn->key, name, hash); 1118 UcxBuffer *request = create_crypto_proppatch_request(sn, sn->key, name, hash);
1120 UcxBuffer *response = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND); 1119 UcxBuffer *response = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND);
1121 1120
1122 util_set_url(sn, href); 1121 util_set_url(sn, href);
1123 // TODO: lock 1122 // TODO: lock
1124 CURLcode ret = do_proppatch_request(sn->handle, NULL, request, response); 1123 CURLcode ret = do_proppatch_request(sn, NULL, request, response);
1125 ucx_buffer_free(request); 1124 ucx_buffer_free(request);
1126 long status = 0; 1125 long status = 0;
1127 curl_easy_getinfo (sn->handle, CURLINFO_RESPONSE_CODE, &status); 1126 curl_easy_getinfo (sn->handle, CURLINFO_RESPONSE_CODE, &status);
1128 if(ret == CURLE_OK && status == 207) { 1127 if(ret == CURLE_OK && status == 207) {
1129 // TODO: parse response 1128 // TODO: parse response

mercurial