739 int pfxnum = 0; |
739 int pfxnum = 0; |
740 UCX_FOREACH(elm, data->set) { |
740 UCX_FOREACH(elm, data->set) { |
741 DavProperty *p = elm->data; |
741 DavProperty *p = elm->data; |
742 if(strcmp(p->ns->name, "DAV:")) { |
742 if(strcmp(p->ns->name, "DAV:")) { |
743 snprintf(prefix, 8, "x%d", pfxnum++); |
743 snprintf(prefix, 8, "x%d", pfxnum++); |
744 ucx_map_cstr_put(namespaces, p->ns->name, prefix); |
744 ucx_map_cstr_put(namespaces, p->ns->name, strdup(prefix)); |
745 } |
745 } |
746 } |
746 } |
747 UCX_FOREACH(elm, data->remove) { |
747 UCX_FOREACH(elm, data->remove) { |
748 DavProperty *p = elm->data; |
748 DavProperty *p = elm->data; |
749 if(strcmp(p->ns->name, "DAV:")) { |
749 if(strcmp(p->ns->name, "DAV:")) { |
750 snprintf(prefix, 8, "x%d", pfxnum++); |
750 snprintf(prefix, 8, "x%d", pfxnum++); |
751 ucx_map_cstr_put(namespaces, p->ns->name, prefix); |
751 ucx_map_cstr_put(namespaces, p->ns->name, strdup(prefix)); |
752 } |
752 } |
753 } |
753 } |
754 |
754 |
755 s = S("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); |
755 s = S("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); |
756 ucx_buffer_write(s.ptr, 1, s.length, buf); |
756 ucx_buffer_write(s.ptr, 1, s.length, buf); |
780 s = S("<D:set>\n<D:prop>\n"); |
780 s = S("<D:set>\n<D:prop>\n"); |
781 ucx_buffer_write(s.ptr, 1, s.length, buf); |
781 ucx_buffer_write(s.ptr, 1, s.length, buf); |
782 UCX_FOREACH(elm, data->set) { |
782 UCX_FOREACH(elm, data->set) { |
783 DavProperty *property = elm->data; |
783 DavProperty *property = elm->data; |
784 char *prefix = ucx_map_cstr_get(namespaces, property->ns->name); |
784 char *prefix = ucx_map_cstr_get(namespaces, property->ns->name); |
|
785 if(!prefix) { |
|
786 prefix = "D"; |
|
787 } |
785 |
788 |
786 s = S("<"); |
789 s = S("<"); |
787 ucx_buffer_write(s.ptr, 1, s.length, buf); |
790 ucx_buffer_write(s.ptr, 1, s.length, buf); |
788 s = sstr(prefix); |
791 s = sstr(prefix); |
789 ucx_buffer_write(s.ptr, 1, s.length, buf); |
792 ucx_buffer_write(s.ptr, 1, s.length, buf); |
831 ucx_buffer_write(s.ptr, 1, s.length, buf); |
834 ucx_buffer_write(s.ptr, 1, s.length, buf); |
832 } |
835 } |
833 |
836 |
834 s = S("</D:propertyupdate>\n"); |
837 s = S("</D:propertyupdate>\n"); |
835 ucx_buffer_write(s.ptr, 1, s.length, buf); |
838 ucx_buffer_write(s.ptr, 1, s.length, buf); |
|
839 |
|
840 // TODO: cleanup namespace map |
836 |
841 |
837 return buf; |
842 return buf; |
838 } |
843 } |
839 |
844 |
840 UcxBuffer* create_crypto_proppatch_request(DavSession *sn, DavKey *key, char *name, char *hash) { |
845 UcxBuffer* create_crypto_proppatch_request(DavSession *sn, DavKey *key, char *name, char *hash) { |
966 |
971 |
967 CURLcode ret = curl_easy_perform(handle); |
972 CURLcode ret = curl_easy_perform(handle); |
968 curl_easy_setopt(handle, CURLOPT_NOBODY, 0L); |
973 curl_easy_setopt(handle, CURLOPT_NOBODY, 0L); |
969 return ret; |
974 return ret; |
970 } |
975 } |
|
976 |
|
977 |
|
978 CURLcode do_copy_move_request(CURL *handle, char *dest, _Bool copy, _Bool override) { |
|
979 if(copy) { |
|
980 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "COPY"); |
|
981 } else { |
|
982 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "MOVE"); |
|
983 } |
|
984 curl_easy_setopt(handle, CURLOPT_PUT, 0L); |
|
985 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
|
986 |
|
987 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); |
|
988 curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); |
|
989 |
|
990 struct curl_slist *headers = NULL; |
|
991 //sstr_t deststr = ucx_sprintf("Destination: %s", dest); |
|
992 sstr_t deststr = sstrcat(2, S("Destination: "), sstr(dest)); |
|
993 headers = curl_slist_append(headers, deststr.ptr); |
|
994 if(override) { |
|
995 headers = curl_slist_append(headers, "Overwrite: T"); |
|
996 } else { |
|
997 headers = curl_slist_append(headers, "Overwrite: F"); |
|
998 } |
|
999 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
|
1000 |
|
1001 CURLcode ret = curl_easy_perform(handle); |
|
1002 free(deststr.ptr); |
|
1003 curl_slist_free_all(headers); |
|
1004 headers = NULL; |
|
1005 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
|
1006 return ret; |
|
1007 } |
|
1008 |