705 |
705 |
706 /* ----------------------------- PROPPATCH ----------------------------- */ |
706 /* ----------------------------- PROPPATCH ----------------------------- */ |
707 |
707 |
708 CURLcode do_proppatch_request( |
708 CURLcode do_proppatch_request( |
709 CURL *handle, |
709 CURL *handle, |
|
710 char *lock, |
710 UcxBuffer *request, |
711 UcxBuffer *request, |
711 UcxBuffer *response) |
712 UcxBuffer *response) |
712 { |
713 { |
713 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPPATCH"); |
714 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPPATCH"); |
714 |
715 |
715 struct curl_slist *headers = NULL; |
716 struct curl_slist *headers = NULL; |
716 headers = curl_slist_append(headers, "Content-Type: text/xml"); |
717 headers = curl_slist_append(headers, "Content-Type: text/xml"); |
|
718 if(lock) { |
|
719 char *url = NULL; |
|
720 curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); |
|
721 char *ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; |
|
722 headers = curl_slist_append(headers, ltheader); |
|
723 free(ltheader); |
|
724 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
|
725 } |
717 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
726 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
718 |
727 |
719 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); |
728 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); |
720 curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); |
729 curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); |
721 curl_easy_setopt(handle, CURLOPT_READDATA, request); |
730 curl_easy_setopt(handle, CURLOPT_READDATA, request); |
889 |
898 |
890 static size_t dummy_write(void *buf, size_t s, size_t n, void *data) { |
899 static size_t dummy_write(void *buf, size_t s, size_t n, void *data) { |
891 return s*n; |
900 return s*n; |
892 } |
901 } |
893 |
902 |
894 CURLcode do_put_request(CURL *handle, void *data, dav_read_func read_func, size_t length) { |
903 CURLcode do_put_request(CURL *handle, char *lock, void *data, dav_read_func read_func, size_t length) { |
895 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL); |
904 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL); |
896 curl_easy_setopt(handle, CURLOPT_PUT, 1L); |
|
897 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L); |
905 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L); |
898 |
906 |
899 // clear headers |
907 // clear headers |
900 struct curl_slist *headers = NULL; |
908 struct curl_slist *headers = NULL; |
|
909 if(lock) { |
|
910 char *url = NULL; |
|
911 curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); |
|
912 char *ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; |
|
913 headers = curl_slist_append(headers, ltheader); |
|
914 free(ltheader); |
|
915 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
|
916 } |
901 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
917 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
902 |
918 |
903 UcxBuffer *buf = NULL; |
919 UcxBuffer *buf = NULL; |
904 if(!read_func) { |
920 if(!read_func) { |
905 buf = ucx_buffer_new(data, length, 0); |
921 buf = ucx_buffer_new(data, length, 0); |
927 ucx_buffer_free(buf); |
943 ucx_buffer_free(buf); |
928 } |
944 } |
929 return ret; |
945 return ret; |
930 } |
946 } |
931 |
947 |
932 CURLcode do_delete_request(CURL *handle, UcxBuffer *response) { |
948 CURLcode do_delete_request(CURL *handle, char *lock, UcxBuffer *response) { |
933 struct curl_slist *headers = NULL; |
949 struct curl_slist *headers = NULL; |
934 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
950 if(lock) { |
|
951 char *url = NULL; |
|
952 curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); |
|
953 char *ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; |
|
954 headers = curl_slist_append(headers, ltheader); |
|
955 free(ltheader); |
|
956 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
|
957 } else { |
|
958 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL); |
|
959 } |
935 |
960 |
936 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "DELETE"); |
961 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "DELETE"); |
937 curl_easy_setopt(handle, CURLOPT_PUT, 0L); |
|
938 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
962 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
939 |
963 |
940 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); |
964 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); |
941 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); |
965 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); |
942 |
966 |
943 CURLcode ret = curl_easy_perform(handle); |
967 CURLcode ret = curl_easy_perform(handle); |
|
968 curl_slist_free_all(headers); |
944 return ret; |
969 return ret; |
945 } |
970 } |
946 |
971 |
947 CURLcode do_mkcol_request(CURL *handle) { |
972 CURLcode do_mkcol_request(CURL *handle, char *lock) { |
948 struct curl_slist *headers = NULL; |
973 struct curl_slist *headers = NULL; |
949 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
974 if(lock) { |
|
975 char *url = NULL; |
|
976 curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); |
|
977 char *ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; |
|
978 headers = curl_slist_append(headers, ltheader); |
|
979 free(ltheader); |
|
980 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL); |
|
981 } else { |
|
982 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL); |
|
983 } |
950 |
984 |
951 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "MKCOL"); |
985 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "MKCOL"); |
952 curl_easy_setopt(handle, CURLOPT_PUT, 0L); |
986 curl_easy_setopt(handle, CURLOPT_PUT, 0L); |
953 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
987 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
954 |
988 |
955 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); |
989 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); |
956 curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); |
990 curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); |
957 |
991 |
958 CURLcode ret = curl_easy_perform(handle); |
992 CURLcode ret = curl_easy_perform(handle); |
|
993 curl_slist_free_all(headers); |
959 return ret; |
994 return ret; |
960 } |
995 } |
961 |
996 |
962 |
997 |
963 CURLcode do_head_request(CURL *handle) { |
998 CURLcode do_head_request(CURL *handle) { |
976 curl_easy_setopt(handle, CURLOPT_NOBODY, 0L); |
1011 curl_easy_setopt(handle, CURLOPT_NOBODY, 0L); |
977 return ret; |
1012 return ret; |
978 } |
1013 } |
979 |
1014 |
980 |
1015 |
981 CURLcode do_copy_move_request(CURL *handle, char *dest, _Bool copy, _Bool override) { |
1016 CURLcode do_copy_move_request(CURL *handle, char *dest, _Bool copy, _Bool override) { |
982 if(copy) { |
1017 if(copy) { |
983 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "COPY"); |
1018 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "COPY"); |
984 } else { |
1019 } else { |
985 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "MOVE"); |
1020 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "MOVE"); |
986 } |
1021 } |
1104 CURLcode ret = curl_easy_perform(handle); |
1144 CURLcode ret = curl_easy_perform(handle); |
1105 |
1145 |
1106 return ret; |
1146 return ret; |
1107 } |
1147 } |
1108 |
1148 |
1109 CURLcode do_unlock_request(CURL *handle, char *locktoken) { |
1149 CURLcode do_unlock_request(CURL *handle, char *locktoken) { |
1110 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "UNLOCK"); |
1150 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "UNLOCK"); |
1111 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
1151 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
|
1152 |
|
1153 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); |
|
1154 curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); |
1112 |
1155 |
1113 // set lock-token header |
1156 // set lock-token header |
1114 sstr_t ltheader = ucx_sprintf("Lock-Token: <%s>", locktoken); |
1157 sstr_t ltheader = ucx_sprintf("Lock-Token: <%s>", locktoken); |
1115 struct curl_slist *headers = curl_slist_append(NULL, ltheader.ptr); |
1158 struct curl_slist *headers = curl_slist_append(NULL, ltheader.ptr); |
1116 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
1159 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |