Mon, 11 Sep 2017 14:17:26 +0200
adds dav remove-property command
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
185
cd42cccee550
updated copyright notice
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
181
diff
changeset
|
4 | * Copyright 2016 Olaf Wintermann. All rights reserved. |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include <stdio.h> |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #include <stdlib.h> |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include <string.h> |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include "utils.h" |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include "methods.h" |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
35 | #include "crypto.h" |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
36 | #include "session.h" |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
156 | 38 | #include <ucx/utils.h> |
39 | ||
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b) |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | /* ----------------------------- PROPFIND ----------------------------- */ |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | CURLcode do_propfind_request( |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | CURL *handle, |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | UcxBuffer *request, |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | UcxBuffer *response) |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPFIND"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | |
170
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
51 | // always try to get information about possible children |
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
52 | int depth = 1; |
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
53 | |
171
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
54 | int maxretry = 2; |
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
55 | |
163
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
56 | struct curl_slist *headers = NULL; |
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
57 | CURLcode ret = 0; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | curl_easy_setopt(handle, CURLOPT_READDATA, request); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); |
170
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
66 | UcxMap *respheaders = ucx_map_new(32); |
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
67 | util_capture_header(handle, respheaders); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | |
171
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
69 | for(int i=0;i<maxretry;i++) { |
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
70 | if (depth == 1) { |
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
71 | headers = curl_slist_append(headers, "Depth: 1"); |
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
72 | } else if (depth == -1) { |
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
73 | headers = curl_slist_append(headers, "Depth: infinity"); |
163
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
74 | } else { |
171
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
75 | headers = curl_slist_append(headers, "Depth: 0"); |
163
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
76 | } |
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
77 | headers = curl_slist_append(headers, "Content-Type: text/xml"); |
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
78 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
166
8911170d5e78
fixed incorrect response buffer reset in manual redirection handling in do_propfind_request
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
79 | |
8911170d5e78
fixed incorrect response buffer reset in manual redirection handling in do_propfind_request
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
80 | // reset buffers and perform request |
8911170d5e78
fixed incorrect response buffer reset in manual redirection handling in do_propfind_request
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
81 | request->pos = 0; |
8911170d5e78
fixed incorrect response buffer reset in manual redirection handling in do_propfind_request
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
82 | response->size = response->pos = 0; |
163
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
83 | ret = curl_easy_perform(handle); |
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
84 | curl_slist_free_all(headers); |
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
85 | headers = NULL; |
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
86 | |
170
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
87 | /* |
171
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
88 | * Handle two cases: |
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
89 | * 1. We communicate with IIS and get a X-MSDAVEXT_Error: 589831 |
170
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
90 | * => try with depth 0 next time, it's not a collection |
171
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
91 | * 2. Other cases |
170
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
92 | * => the server handled our request and we can stop requesting |
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
93 | */ |
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
94 | char *msdavexterror; |
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
95 | msdavexterror = ucx_map_cstr_get(respheaders, "x-msdavext_error"); |
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
96 | int iishack = depth == 1 && |
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
97 | msdavexterror && !strncmp(msdavexterror, "589831;", 7); |
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
98 | |
171
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
99 | if(iishack) { |
170
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
100 | depth = 0; |
163
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
101 | } else { |
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
102 | break; |
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
103 | } |
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
104 | } |
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
105 | |
176
747f3796eddd
improved util_capture_header when deactivating the capturing
Mike Becker <universe@uap-core.de>
parents:
172
diff
changeset
|
106 | // deactivate header capturing and free captured map |
747f3796eddd
improved util_capture_header when deactivating the capturing
Mike Becker <universe@uap-core.de>
parents:
172
diff
changeset
|
107 | util_capture_header(handle, NULL); |
170
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
108 | ucx_map_free_content(respheaders, free); |
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
109 | ucx_map_free(respheaders); |
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
110 | |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
111 | return ret; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | UcxBuffer* create_allprop_propfind_request() { |
148
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
115 | UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOFREE); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | sstr_t s; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | s = S("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | s = S("<D:propfind xmlns:D=\"DAV:\">\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | s = S("<D:allprop/></D:propfind>\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | return buf; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
130 | UcxBuffer* create_propfind_request(DavSession *sn, UcxList *properties) { |
148
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
131 | UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | sstr_t s; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
134 | int add_crypto_name = 1; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
135 | int add_crypto_key = 1; |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
136 | int add_crypto_hash = 1; |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
137 | char *crypto_ns = "idav"; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | UcxMap *namespaces = ucx_map_new(8); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | UCX_FOREACH(elm, properties) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | DavProperty *p = elm->data; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | if(strcmp(p->ns->name, "DAV:")) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | ucx_map_cstr_put(namespaces, p->ns->prefix, p->ns); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
144 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
145 | // if the properties list contains the idav properties crypto-name |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
146 | // and crypto-key, mark them as existent |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
147 | if(!strcmp(p->ns->name, DAV_NS)) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
148 | if(!strcmp(p->name, "crypto-name")) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
149 | add_crypto_name = 0; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
150 | crypto_ns = p->ns->prefix; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
151 | } else if(!strcmp(p->name, "crypto-key")) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
152 | add_crypto_key = 0; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
153 | crypto_ns = p->ns->prefix; |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
154 | } else if(!strcmp(p->name, "crypto-hash")) { |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
155 | add_crypto_hash = 0; |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
156 | crypto_ns = p->ns->prefix; |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
157 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
158 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
159 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
160 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
161 | DavNamespace idav_ns; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
162 | if(add_crypto_name && add_crypto_key && DAV_CRYPTO(sn)) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
163 | idav_ns.prefix = "idav"; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
164 | idav_ns.name = DAV_NS; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
165 | ucx_map_cstr_put(namespaces, "idav", &idav_ns); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | s = S("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | // write root element and namespaces |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | s = S("<D:propfind xmlns:D=\"DAV:\""); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | UcxMapIterator mapi = ucx_map_iterator(namespaces); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | UcxKey key; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | DavNamespace *ns; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | UCX_MAP_FOREACH(key, ns, mapi) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | s = S(" xmlns:"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | s = sstr(ns->prefix); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | s = S("=\""); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | s = sstr(ns->name); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | s = S("\""); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | s = S(">\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | // default properties |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | s = S("<D:prop>\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | s = S("<D:creationdate />\n<D:getlastmodified />\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | s = S("<D:getcontentlength />\n<D:getcontenttype />\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | s = S("<D:resourcetype />\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
205 | // crypto properties |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
206 | if(DAV_CRYPTO(sn)) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
207 | if(add_crypto_name) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
208 | ucx_buffer_putc(buf, '<'); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
209 | ucx_buffer_puts(buf, crypto_ns); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
210 | s = S(":crypto-name />\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
211 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
212 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
213 | if(add_crypto_key) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
214 | ucx_buffer_putc(buf, '<'); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
215 | ucx_buffer_puts(buf, crypto_ns); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
216 | s = S(":crypto-key />\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
217 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
218 | } |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
219 | if(add_crypto_hash) { |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
220 | ucx_buffer_putc(buf, '<'); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
221 | ucx_buffer_puts(buf, crypto_ns); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
222 | s = S(":crypto-hash />\n"); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
223 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
224 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
225 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
226 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | // extra properties |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | UCX_FOREACH(elm, properties) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | DavProperty *prop = elm->data; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | s = S("<"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | s = sstr(prop->ns->prefix); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | s = S(":"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | s = sstr(prop->name); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | s = S(" />\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | // end |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | s = S("</D:prop>\n</D:propfind>\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
246 | ucx_map_free(namespaces); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | return buf; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
250 | UcxBuffer* create_basic_propfind_request() { |
148
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
251 | UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
252 | sstr_t s; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
253 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
254 | s = S("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
255 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
256 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
257 | s = S("<D:propfind xmlns:D=\"DAV:\" xmlns:i=\""); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
258 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
259 | s = S(DAV_NS); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
260 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
261 | s = S("\" >\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
262 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
263 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
264 | // properties |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
265 | s = S("<D:prop>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
266 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
267 | s = S("<D:resourcetype />\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
268 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
269 | s = S("<i:crypto-key />\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
270 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
271 | s = S("<i:crypto-name />\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
272 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
273 | s = S("<i:crypto-hash />\n"); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
274 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
275 | s = S("</D:prop>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
276 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
277 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
278 | // end |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
279 | s = S("</D:propfind>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
280 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
281 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
282 | return buf; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
283 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
284 | |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
285 | PropfindParser* create_propfind_parser(UcxBuffer *response, char *url) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
286 | PropfindParser *parser = malloc(sizeof(PropfindParser)); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
287 | if(!parser) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
288 | return NULL; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
289 | } |
137
01cb9aabff05
fixed horrible bugs, davql hopefully just works now (without order by yet)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
290 | parser->document = xmlReadMemory(response->space, response->pos, url, NULL, 0); |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
291 | parser->current = NULL; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
292 | if(parser->document) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
293 | xmlNode *xml_root = xmlDocGetRootElement(parser->document); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
294 | if(xml_root) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
295 | xmlNode *node = xml_root->children; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
296 | while(node) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
297 | // find first response tag |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
298 | if(node->type == XML_ELEMENT_NODE) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
299 | if(xstreq(node->name, "response")) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
300 | parser->current = node; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
301 | break; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
302 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
303 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
304 | node = node->next; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
305 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
306 | return parser; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
307 | } else { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
308 | xmlFreeDoc(parser->document); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
309 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
310 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
311 | free(parser); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
312 | return NULL; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
313 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
314 | |
148
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
315 | void destroy_propfind_parser(PropfindParser *parser) { |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
316 | if(parser->document) { |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
317 | xmlFreeDoc(parser->document); |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
318 | } |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
319 | free(parser); |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
320 | } |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
321 | |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
322 | int get_propfind_response(PropfindParser *parser, ResponseTag *result) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
323 | if(parser->current == NULL) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
324 | return 0; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
325 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
326 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
327 | char *href = NULL; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
328 | int iscollection = 0; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
329 | UcxList *properties = NULL; // xmlNode list |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
330 | char *crypto_name = NULL; // name set by crypto-name property |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
331 | char *crypto_key = NULL; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
332 | |
148
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
333 | result->properties = NULL; |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
334 | |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
335 | xmlNode *node = parser->current->children; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
336 | while(node) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
337 | if(node->type == XML_ELEMENT_NODE) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
338 | if(xstreq(node->name, "href")) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
339 | xmlNode *href_node = node->children; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
340 | if(href_node->type != XML_TEXT_NODE) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
341 | // error |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
342 | return -1; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
343 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
344 | href = (char*)href_node->content; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
345 | } else if(xstreq(node->name, "propstat")) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
346 | xmlNode *n = node->children; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
347 | xmlNode *prop_node = NULL; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
348 | int ok = 0; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
349 | // get the status code |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
350 | while(n) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
351 | if(n->type == XML_ELEMENT_NODE) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
352 | if(xstreq(n->name, "prop")) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
353 | prop_node = n; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
354 | } else if(xstreq(n->name, "status")) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
355 | xmlNode *status_node = n->children; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
356 | if(status_node->type != XML_TEXT_NODE) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
357 | // error |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
358 | return -1; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
359 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
360 | sstr_t status_str = sstr((char*)status_node->content); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
361 | if(status_str.length < 13) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
362 | // error |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
363 | return -1; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
364 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
365 | status_str = sstrsubsl(status_str, 9, 3); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
366 | if(!sstrcmp(status_str, S("200"))) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
367 | ok = 1; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
368 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
369 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
370 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
371 | n = n->next; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
372 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
373 | // if status is ok, get all properties |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
374 | if(ok) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
375 | n = prop_node->children; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
376 | while(n) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
377 | if(n->type == XML_ELEMENT_NODE) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
378 | properties = ucx_list_append(properties, n); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
379 | if(xstreq(n->name, "resourcetype")) { |
231
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
380 | if(parse_resource_type(n)) { |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
381 | iscollection = TRUE; |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
382 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
383 | } else if(xstreq(n->ns->href, DAV_NS)) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
384 | if(xstreq(n->name, "crypto-name")) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
385 | crypto_name = util_xml_get_text(n); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
386 | } else if(xstreq(n->name, "crypto-key")) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
387 | crypto_key = util_xml_get_text(n); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
388 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
389 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
390 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
391 | n = n->next; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
392 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
393 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
394 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
395 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
396 | node = node->next; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
397 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
398 | |
156 | 399 | result->href = util_url_path(href); |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
400 | result->iscollection = iscollection; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
401 | result->properties = properties; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
402 | result->crypto_name = crypto_name; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
403 | result->crypto_key = crypto_key; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
404 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
405 | // find next response tag |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
406 | xmlNode *next = parser->current->next; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
407 | while(next) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
408 | if(next->type == XML_ELEMENT_NODE) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
409 | if(xstreq(next->name, "response")) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
410 | break; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
411 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
412 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
413 | next = next->next; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
414 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
415 | parser->current = next; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
416 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
417 | return 1; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
418 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
419 | |
148
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
420 | void cleanup_response(ResponseTag *result) { |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
421 | if(result) { |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
422 | ucx_list_free(result->properties); |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
423 | } |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
424 | } |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
425 | |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
426 | int hrefeq(DavSession *sn, char *href1, char *href2) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
427 | sstr_t href_s = sstr(util_url_decode(sn, href1)); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
428 | sstr_t href_r = sstr(util_url_decode(sn, href2)); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
429 | int ret = 0; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
430 | if(!sstrcmp(href_s, href_r)) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
431 | ret = 1; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
432 | } else if(href_s.length == href_r.length + 1) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
433 | if(href_s.ptr[href_s.length-1] == '/') { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
434 | href_s.length--; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
435 | if(!sstrcmp(href_s, href_r)) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
436 | ret = 1; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
437 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
438 | } |
141
b0c44be83276
fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
137
diff
changeset
|
439 | } else if(href_r.length == href_s.length + 1) { |
b0c44be83276
fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
137
diff
changeset
|
440 | if(href_r.ptr[href_r.length-1] == '/') { |
b0c44be83276
fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
137
diff
changeset
|
441 | href_r.length--; |
b0c44be83276
fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
137
diff
changeset
|
442 | if(!sstrcmp(href_s, href_r)) { |
b0c44be83276
fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
137
diff
changeset
|
443 | ret = 1; |
b0c44be83276
fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
137
diff
changeset
|
444 | } |
b0c44be83276
fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
137
diff
changeset
|
445 | } |
b0c44be83276
fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
137
diff
changeset
|
446 | } |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
447 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
448 | free(href_s.ptr); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
449 | free(href_r.ptr); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
450 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
451 | return ret; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
452 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
453 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
454 | |
135
664aeaec8d25
replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
455 | DavResource* parse_propfind_response(DavSession *sn, DavResource *root, UcxBuffer *response) { |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
456 | char *url = NULL; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
457 | curl_easy_getinfo(sn->handle, CURLINFO_EFFECTIVE_URL, &url); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
458 | if(!root) { |
225
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
459 | printf("methods.c: TODO: remove\n"); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
460 | root = dav_resource_new_href(sn, util_url_path(url)); // TODO: remove |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
461 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
462 | |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
463 | //printf("%.*s\n\n", response->size, response->space); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
464 | xmlDoc *doc = xmlReadMemory(response->space, response->size, url, NULL, 0); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
465 | if(!doc) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
466 | // TODO: free stuff |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
467 | sn->error = DAV_ERROR; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
468 | return NULL; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
469 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
470 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
471 | xmlNode *xml_root = xmlDocGetRootElement(doc); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
472 | xmlNode *node = xml_root->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
473 | while(node) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
474 | if(node->type == XML_ELEMENT_NODE) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
475 | if(xstreq(node->name, "response")) { |
135
664aeaec8d25
replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
476 | parse_response_tag(root, node); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
477 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
478 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
479 | node = node->next; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
480 | } |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
481 | xmlFreeDoc(doc); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
482 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
483 | return root; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
484 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
485 | |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
486 | DavResource* response2resource(DavSession *sn, ResponseTag *response, char *parent_path) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
487 | // create resource |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
488 | char *name = NULL; |
147
458a8dc68048
added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
489 | DavKey *key = NULL; |
458a8dc68048
added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
490 | if(DAV_DECRYPT_NAME(sn) && response->crypto_name && (key = dav_context_get_key(sn->context, response->crypto_key))) { |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
491 | if(!response->crypto_key) { |
225
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
492 | sn->error = DAV_ERROR; |
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
493 | dav_session_set_errstr(sn, "Missing crypto-key property"); |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
494 | return NULL; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
495 | } |
147
458a8dc68048
added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
496 | name = util_decrypt_str_k(sn, response->crypto_name, key); |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
497 | if(!name) { |
225
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
498 | sn->error = DAV_ERROR; |
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
499 | dav_session_set_errstr(sn, "Cannot decrypt resource name"); |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
500 | return NULL; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
501 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
502 | } else { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
503 | sstr_t resname = sstr(util_resource_name(response->href)); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
504 | int nlen = 0; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
505 | char *uname = curl_easy_unescape( |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
506 | sn->handle, |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
507 | resname.ptr, |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
508 | resname.length, |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
509 | &nlen); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
510 | name = dav_session_strdup(sn, uname); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
511 | curl_free(uname); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
512 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
513 | |
137
01cb9aabff05
fixed horrible bugs, davql hopefully just works now (without order by yet)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
514 | char *href = dav_session_strdup(sn, response->href); |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
515 | DavResource *res = NULL; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
516 | if(parent_path) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
517 | res = dav_resource_new_full(sn, parent_path, name, href); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
518 | } else { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
519 | res = dav_resource_new_href(sn, href); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
520 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
521 | dav_session_free(sn, name); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
522 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
523 | add_properties(res, response); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
524 | return res; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
525 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
526 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
527 | void add_properties(DavResource *res, ResponseTag *response) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
528 | res->iscollection = response->iscollection; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
529 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
530 | // add properties |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
531 | UCX_FOREACH(elm, response->properties) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
532 | xmlNode *prop = elm->data; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
533 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
534 | // TODO: add xml data instead of a string |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
535 | char *text = util_xml_get_text(prop); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
536 | if(text) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
537 | resource_add_property(res, (char*)prop->ns->href, (char*)prop->name, text); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
538 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
539 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
540 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
541 | set_davprops(res); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
542 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
543 | |
135
664aeaec8d25
replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
544 | int parse_response_tag(DavResource *resource, xmlNode *node) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
545 | DavSession *sn = resource->session; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
546 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
547 | //DavResource *res = resource; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
548 | DavResource *res = NULL; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
549 | char *href = NULL; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
550 | UcxList *properties = NULL; // xmlNode list |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
551 | char *crypto_name = NULL; // name set by crypto-name property |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
552 | char *crypto_key = NULL; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
553 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
554 | int iscollection = 0; // TODO: remove |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
555 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
556 | node = node->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
557 | while(node) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
558 | if(node->type == XML_ELEMENT_NODE) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
559 | if(xstreq(node->name, "href")) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
560 | xmlNode *href_node = node->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
561 | if(href_node->type != XML_TEXT_NODE) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
562 | // error |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
563 | sn->error = DAV_ERROR; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
564 | return 1; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
565 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
566 | //char *href = (char*)href_node->content; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
567 | href = util_url_path((char*)href_node->content); |
60
cdca2eef48ee
fixed propfind response parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
568 | |
164
4c204e40ef52
fixed href comparison in parse_response_tag
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
569 | char *href_s = util_url_decode(resource->session, href); |
4c204e40ef52
fixed href comparison in parse_response_tag
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
570 | char *href_r = util_url_decode(resource->session, resource->href); |
4c204e40ef52
fixed href comparison in parse_response_tag
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
571 | |
4c204e40ef52
fixed href comparison in parse_response_tag
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
572 | if(hrefeq(sn, href_s, href_r)) { |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
573 | res = resource; |
164
4c204e40ef52
fixed href comparison in parse_response_tag
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
574 | } |
66 | 575 | |
164
4c204e40ef52
fixed href comparison in parse_response_tag
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
576 | free(href_s); |
4c204e40ef52
fixed href comparison in parse_response_tag
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
577 | free(href_r); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
578 | } else if(xstreq(node->name, "propstat")) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
579 | xmlNode *n = node->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
580 | xmlNode *prop_node = NULL; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
581 | int ok = 0; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
582 | // get the status code |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
583 | while(n) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
584 | if(n->type == XML_ELEMENT_NODE) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
585 | if(xstreq(n->name, "prop")) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
586 | prop_node = n; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
587 | } else if(xstreq(n->name, "status")) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
588 | xmlNode *status_node = n->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
589 | if(status_node->type != XML_TEXT_NODE) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
590 | sn->error = DAV_ERROR; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
591 | return 1; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
592 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
593 | sstr_t status_str = sstr((char*)status_node->content); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
594 | if(status_str.length < 13) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
595 | sn->error = DAV_ERROR; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
596 | return 1; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
597 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
598 | status_str = sstrsubsl(status_str, 9, 3); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
599 | if(!sstrcmp(status_str, S("200"))) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
600 | ok = 1; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
601 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
602 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
603 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
604 | n = n->next; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
605 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
606 | // if status is ok, get all properties |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
607 | if(ok) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
608 | n = prop_node->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
609 | while(n) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
610 | if(n->type == XML_ELEMENT_NODE) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
611 | properties = ucx_list_append(properties, n); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
612 | if(xstreq(n->name, "resourcetype")) { |
231
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
613 | if(parse_resource_type(n)) { |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
614 | iscollection = TRUE; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
615 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
616 | } else if(xstreq(n->ns->href, DAV_NS)) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
617 | if(xstreq(n->name, "crypto-name")) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
618 | crypto_name = util_xml_get_text(n); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
619 | } else if(xstreq(n->name, "crypto-key")) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
620 | crypto_key = util_xml_get_text(n); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
621 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
622 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
623 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
624 | n = n->next; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
625 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
626 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
627 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
628 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
629 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
630 | node = node->next; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
631 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
632 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
633 | if(!res) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
634 | // create new resource object |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
635 | char *name = NULL; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
636 | if(DAV_DECRYPT_NAME(sn) && crypto_name) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
637 | if(!crypto_key) { |
225
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
638 | sn->error = DAV_ERROR; |
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
639 | dav_session_set_errstr(sn, "Missing crypto-key property"); |
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
640 | return -1; |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
641 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
642 | name = util_decrypt_str(sn, crypto_name, crypto_key); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
643 | if(!name) { |
225
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
644 | sn->error = DAV_ERROR; |
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
645 | dav_session_set_errstr(sn, "Cannot decrypt resource name"); |
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
646 | return -1; |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
647 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
648 | } else { |
44
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
649 | sstr_t resname = sstr(util_resource_name(href)); |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
650 | int nlen = 0; |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
651 | char *uname = curl_easy_unescape( |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
652 | sn->handle, |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
653 | resname.ptr, |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
654 | resname.length, |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
655 | &nlen); |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
656 | name = dav_session_strdup(sn, uname); |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
657 | curl_free(uname); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
658 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
659 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
660 | href = dav_session_strdup(sn, href); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
661 | res = dav_resource_new_full(sn, resource->path, name, href); |
44
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
662 | |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
663 | dav_session_free(sn, name); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
664 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
665 | res->iscollection = iscollection; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
666 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
667 | // add properties |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
668 | UCX_FOREACH(elm, properties) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
669 | xmlNode *prop = elm->data; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
670 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
671 | // TODO: add xml data instead of a string |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
672 | char *text = util_xml_get_text(prop); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
673 | if(text) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
674 | resource_add_property(res, (char*)prop->ns->href, (char*)prop->name, text); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
675 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
676 | } |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
677 | ucx_list_free(properties); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
678 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
679 | set_davprops(res); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
680 | if(res != resource) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
681 | resource_add_child(resource, res); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
682 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
683 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
684 | return 0; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
685 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
686 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
687 | void set_davprops(DavResource *res) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
688 | char *cl = dav_get_property_ns(res, "DAV:", "getcontentlength"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
689 | char *ct = dav_get_property_ns(res, "DAV:", "getcontenttype"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
690 | char *cd = dav_get_property_ns(res, "DAV:", "creationdate"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
691 | char *lm = dav_get_property_ns(res, "DAV:", "getlastmodified"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
692 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
693 | res->contenttype = ct; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
694 | if(cl) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
695 | char *end = NULL; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
696 | res->contentlength = strtoull(cl, &end, 0); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
697 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
698 | res->creationdate = util_parse_creationdate(cd); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
699 | res->lastmodified = util_parse_lastmodified(lm); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
700 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
701 | |
231
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
702 | int parse_resource_type(xmlNode *node) { |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
703 | int collection = FALSE; |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
704 | xmlNode *c = node->children; |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
705 | while(c) { |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
706 | if(c->type == XML_ELEMENT_NODE) { |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
707 | if(xstreq(c->ns->href, "DAV:") && xstreq(c->name, "collection")) { |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
708 | collection = TRUE; |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
709 | break; |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
710 | } |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
711 | } |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
712 | c = c->next; |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
713 | } |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
714 | return collection; |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
715 | } |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
716 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
717 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
718 | /* ----------------------------- PROPPATCH ----------------------------- */ |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
719 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
720 | CURLcode do_proppatch_request( |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
721 | CURL *handle, |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
722 | char *lock, |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
723 | UcxBuffer *request, |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
724 | UcxBuffer *response) |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
725 | { |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
726 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPPATCH"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
727 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
728 | struct curl_slist *headers = NULL; |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
729 | headers = curl_slist_append(headers, "Content-Type: text/xml"); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
730 | if(lock) { |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
731 | char *url = NULL; |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
732 | curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
733 | char *ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
734 | headers = curl_slist_append(headers, ltheader); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
735 | free(ltheader); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
736 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
737 | } |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
738 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
739 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
740 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
741 | curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
742 | curl_easy_setopt(handle, CURLOPT_READDATA, request); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
743 | curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
744 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
745 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
746 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
747 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
748 | ucx_buffer_seek(request, 0, SEEK_SET); |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
749 | CURLcode ret = curl_easy_perform(handle); |
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
750 | curl_slist_free_all(headers); |
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
751 | return ret; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
752 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
753 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
754 | UcxBuffer* create_proppatch_request(DavResourceData *data) { |
148
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
755 | UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
756 | sstr_t s; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
757 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
758 | UcxMap *namespaces = ucx_map_new(8); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
759 | char prefix[8]; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
760 | int pfxnum = 0; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
761 | UCX_FOREACH(elm, data->set) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
762 | DavProperty *p = elm->data; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
763 | if(strcmp(p->ns->name, "DAV:")) { |
104
6fb4d24d9df9
added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
764 | snprintf(prefix, 8, "x%d", pfxnum++); |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
765 | ucx_map_cstr_put(namespaces, p->ns->name, strdup(prefix)); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
766 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
767 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
768 | UCX_FOREACH(elm, data->remove) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
769 | DavProperty *p = elm->data; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
770 | if(strcmp(p->ns->name, "DAV:")) { |
104
6fb4d24d9df9
added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
771 | snprintf(prefix, 8, "x%d", pfxnum++); |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
772 | ucx_map_cstr_put(namespaces, p->ns->name, strdup(prefix)); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
773 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
774 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
775 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
776 | s = S("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
777 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
778 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
779 | // write root element and namespaces |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
780 | s = S("<D:propertyupdate xmlns:D=\"DAV:\""); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
781 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
782 | UcxMapIterator mapi = ucx_map_iterator(namespaces); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
783 | UcxKey key; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
784 | char *pfxval; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
785 | UCX_MAP_FOREACH(key, pfxval, mapi) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
786 | s = S(" xmlns:"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
787 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
788 | s = sstr(pfxval); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
789 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
790 | s = S("=\""); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
791 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
792 | s = sstrn(key.data, key.len); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
793 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
794 | s = S("\""); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
795 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
796 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
797 | s = S(">\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
798 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
799 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
800 | if(data->set) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
801 | s = S("<D:set>\n<D:prop>\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
802 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
803 | UCX_FOREACH(elm, data->set) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
804 | DavProperty *property = elm->data; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
805 | char *prefix = ucx_map_cstr_get(namespaces, property->ns->name); |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
806 | if(!prefix) { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
807 | prefix = "D"; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
808 | } |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
809 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
810 | s = S("<"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
811 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
812 | s = sstr(prefix); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
813 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
814 | s = S(":"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
815 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
816 | s = sstr(property->name); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
817 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
818 | s = S(">"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
819 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
820 | s = sstr(property->value); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
821 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
822 | s = S("</"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
823 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
824 | s = sstr(prefix); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
825 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
826 | s = S(":"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
827 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
828 | s = sstr(property->name); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
829 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
830 | s = S(">\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
831 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
832 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
833 | s = S("</D:prop>\n</D:set>\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
834 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
835 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
836 | if(data->remove) { |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
837 | s = S("<D:remove>\n<D:prop>\n"); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
838 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
839 | UCX_FOREACH(elm, data->remove) { |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
840 | DavProperty *property = elm->data; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
841 | char *prefix = ucx_map_cstr_get(namespaces, property->ns->name); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
842 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
843 | s = S("<"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
844 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
845 | s = sstr(prefix); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
846 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
847 | s = S(":"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
848 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
849 | s = sstr(property->name); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
850 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
851 | s = S(" />\n"); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
852 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
853 | } |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
854 | s = S("</D:prop>\n</D:remove>\n"); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
855 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
856 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
857 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
858 | s = S("</D:propertyupdate>\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
859 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
860 | |
223
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
861 | // cleanup namespace map |
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
862 | ucx_map_free_content(namespaces, free); |
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
863 | ucx_map_free(namespaces); |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
864 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
865 | return buf; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
866 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
867 | |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
868 | UcxBuffer* create_crypto_proppatch_request(DavSession *sn, DavKey *key, char *name, char *hash) { |
148
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
869 | UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
870 | sstr_t s; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
871 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
872 | s = S("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
873 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
874 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
875 | s = S("<D:propertyupdate xmlns:D=\"DAV:\" xmlns:idav=\"" DAV_NS "\">\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
876 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
877 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
878 | s = S("<D:set>\n<D:prop>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
879 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
880 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
881 | if(DAV_ENCRYPT_NAME(sn)) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
882 | s = S("<idav:crypto-name>"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
883 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
884 | char *crname = aes_encrypt(name, strlen(name), key); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
885 | ucx_buffer_puts(buf, crname); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
886 | free(crname); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
887 | s = S("</idav:crypto-name>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
888 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
889 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
890 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
891 | s = S("<idav:crypto-key>"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
892 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
893 | ucx_buffer_puts(buf, key->name); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
894 | s = S("</idav:crypto-key>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
895 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
896 | |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
897 | if(hash) { |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
898 | s = S("<idav:crypto-hash>"); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
899 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
900 | ucx_buffer_puts(buf, hash); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
901 | s = S("</idav:crypto-hash>\n"); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
902 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
903 | } |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
904 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
905 | s = S("</D:prop>\n</D:set>\n</D:propertyupdate>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
906 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
907 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
908 | return buf; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
909 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
910 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
911 | /* ----------------------------- PUT ----------------------------- */ |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
912 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
913 | static size_t dummy_write(void *buf, size_t s, size_t n, void *data) { |
227
bf485439222a
fixed locking in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
914 | //fwrite(buf, s, n, stdout); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
915 | return s*n; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
916 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
917 | |
223
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
918 | CURLcode do_put_request(CURL *handle, char *lock, DavBool create, void *data, dav_read_func read_func, size_t length) { |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
919 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
920 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
921 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
922 | // clear headers |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
923 | struct curl_slist *headers = NULL; |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
924 | if(lock) { |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
925 | char *url = NULL; |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
926 | curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); |
223
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
927 | char *ltheader = NULL; |
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
928 | if(create) { |
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
929 | url = util_parent_path(url); |
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
930 | ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; |
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
931 | free(url); |
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
932 | } else { |
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
933 | ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; |
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
934 | } |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
935 | headers = curl_slist_append(headers, ltheader); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
936 | free(ltheader); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
937 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
938 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
939 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
940 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
941 | UcxBuffer *buf = NULL; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
942 | if(!read_func) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
943 | buf = ucx_buffer_new(data, length, 0); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
944 | buf->size = length; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
945 | data = buf; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
946 | read_func = (dav_read_func)ucx_buffer_read; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
947 | curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)length); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
948 | } else if(length == 0) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
949 | headers = curl_slist_append(headers, "Transfer-Encoding: chunked"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
950 | curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)1); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
951 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
952 | } else { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
953 | curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)length); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
954 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
955 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
956 | curl_easy_setopt(handle, CURLOPT_READFUNCTION, read_func); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
957 | curl_easy_setopt(handle, CURLOPT_READDATA, data); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
958 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
959 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
960 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
961 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
962 | CURLcode ret = curl_easy_perform(handle); |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
963 | curl_slist_free_all(headers); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
964 | if(buf) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
965 | ucx_buffer_free(buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
966 | } |
223
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
967 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
968 | return ret; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
969 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
970 | |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
971 | CURLcode do_delete_request(CURL *handle, char *lock, UcxBuffer *response) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
972 | struct curl_slist *headers = NULL; |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
973 | if(lock) { |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
974 | char *url = NULL; |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
975 | curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
976 | char *ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
977 | headers = curl_slist_append(headers, ltheader); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
978 | free(ltheader); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
979 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
980 | } else { |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
981 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
982 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
983 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
984 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "DELETE"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
985 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
986 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
987 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
988 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
989 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
990 | CURLcode ret = curl_easy_perform(handle); |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
991 | curl_slist_free_all(headers); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
992 | return ret; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
993 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
994 | |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
995 | CURLcode do_mkcol_request(CURL *handle, char *lock) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
996 | struct curl_slist *headers = NULL; |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
997 | if(lock) { |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
998 | char *url = NULL; |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
999 | curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); |
223
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
1000 | url = util_parent_path(url); |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1001 | char *ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; |
223
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
1002 | free(url); |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1003 | headers = curl_slist_append(headers, ltheader); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1004 | free(ltheader); |
227
bf485439222a
fixed locking in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
1005 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1006 | } else { |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1007 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1008 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
1009 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1010 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "MKCOL"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1011 | curl_easy_setopt(handle, CURLOPT_PUT, 0L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1012 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1013 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1014 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1015 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1016 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1017 | CURLcode ret = curl_easy_perform(handle); |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1018 | curl_slist_free_all(headers); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1019 | return ret; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1020 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1021 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1022 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1023 | CURLcode do_head_request(CURL *handle) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1024 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "HEAD"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1025 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1026 | curl_easy_setopt(handle, CURLOPT_NOBODY, 1L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1027 | |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1028 | // clear headers |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1029 | struct curl_slist *headers = NULL; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1030 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1031 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1032 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1033 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1034 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1035 | CURLcode ret = curl_easy_perform(handle); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1036 | curl_easy_setopt(handle, CURLOPT_NOBODY, 0L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1037 | return ret; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1038 | } |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1039 | |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1040 | |
236
6b4ce32d0c4e
copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
231
diff
changeset
|
1041 | CURLcode do_copy_move_request(CURL *handle, char *dest, char *lock, DavBool copy, DavBool override) { |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1042 | if(copy) { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1043 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "COPY"); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1044 | } else { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1045 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "MOVE"); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1046 | } |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1047 | curl_easy_setopt(handle, CURLOPT_PUT, 0L); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1048 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1049 | |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1050 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1051 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1052 | |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1053 | struct curl_slist *headers = NULL; |
236
6b4ce32d0c4e
copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
231
diff
changeset
|
1054 | if(lock) { |
6b4ce32d0c4e
copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
231
diff
changeset
|
1055 | char *url = NULL; |
6b4ce32d0c4e
copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
231
diff
changeset
|
1056 | curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); |
6b4ce32d0c4e
copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
231
diff
changeset
|
1057 | char *ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; |
6b4ce32d0c4e
copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
231
diff
changeset
|
1058 | headers = curl_slist_append(headers, ltheader); |
6b4ce32d0c4e
copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
231
diff
changeset
|
1059 | free(ltheader); |
6b4ce32d0c4e
copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
231
diff
changeset
|
1060 | } |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1061 | //sstr_t deststr = ucx_sprintf("Destination: %s", dest); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1062 | sstr_t deststr = sstrcat(2, S("Destination: "), sstr(dest)); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1063 | headers = curl_slist_append(headers, deststr.ptr); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1064 | if(override) { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1065 | headers = curl_slist_append(headers, "Overwrite: T"); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1066 | } else { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1067 | headers = curl_slist_append(headers, "Overwrite: F"); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1068 | } |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1069 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1070 | |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1071 | CURLcode ret = curl_easy_perform(handle); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1072 | free(deststr.ptr); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1073 | curl_slist_free_all(headers); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1074 | headers = NULL; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1075 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1076 | return ret; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1077 | } |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1078 | |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1079 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1080 | UcxBuffer* create_lock_request() { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1081 | UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1082 | sstr_t s; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1083 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1084 | s = S("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1085 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1086 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1087 | s = S("<D:lockinfo xmlns:D=\"DAV:\">\n" |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1088 | "<D:lockscope><D:exclusive/></D:lockscope>\n" |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1089 | "<D:locktype><D:write/></D:locktype>\n" |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1090 | "<D:owner><D:href>http://davutils.org/libidav/</D:href></D:owner>\n"); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1091 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1092 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1093 | s = S("</D:lockinfo>\n"); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1094 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1095 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1096 | return buf; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1097 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1098 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1099 | int parse_lock_response(DavSession *sn, UcxBuffer *response, LockDiscovery *lock) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1100 | lock->locktoken = NULL; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1101 | lock->timeout = NULL; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1102 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1103 | xmlDoc *doc = xmlReadMemory(response->space, response->size, NULL, NULL, 0); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1104 | if(!doc) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1105 | sn->error = DAV_ERROR; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1106 | return -1; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1107 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1108 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1109 | char *timeout = NULL; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1110 | char *locktoken = NULL; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1111 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1112 | int ret = -1; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1113 | xmlNode *xml_root = xmlDocGetRootElement(doc); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1114 | DavBool lockdiscovery = 0; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1115 | if(xml_root) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1116 | xmlNode *node = xml_root->children; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1117 | while(node) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1118 | if(node->type == XML_ELEMENT_NODE) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1119 | if(xstreq(node->name, "lockdiscovery")) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1120 | node = node->children; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1121 | lockdiscovery = 1; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1122 | continue; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1123 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1124 | |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1125 | if(xstreq(node->name, "activelock")) { |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1126 | node = node->children; |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1127 | continue; |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1128 | } |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1129 | |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1130 | if(lockdiscovery) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1131 | if(xstreq(node->name, "timeout")) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1132 | timeout = util_xml_get_text(node); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1133 | } else if(xstreq(node->name, "locktoken")) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1134 | xmlNode *n = node->children; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1135 | while(n) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1136 | if(xstreq(n->name, "href")) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1137 | locktoken = util_xml_get_text(n); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1138 | break; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1139 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1140 | n = n->next; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1141 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1142 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1143 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1144 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1145 | node = node->next; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1146 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1147 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1148 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1149 | if(timeout && locktoken) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1150 | lock->timeout = strdup(timeout); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1151 | lock->locktoken = strdup(locktoken); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1152 | ret = 0; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1153 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1154 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1155 | xmlFreeDoc(doc); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1156 | return ret; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1157 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1158 | |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1159 | CURLcode do_lock_request(CURL *handle, UcxBuffer *request, UcxBuffer *response) { |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1160 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "LOCK"); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1161 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1162 | request->pos = 0; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1163 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1164 | // clear headers |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1165 | struct curl_slist *headers = NULL; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1166 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1167 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1168 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1169 | curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1170 | curl_easy_setopt(handle, CURLOPT_READDATA, request); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1171 | curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1172 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1173 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1174 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1175 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1176 | CURLcode ret = curl_easy_perform(handle); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1177 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1178 | return ret; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1179 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1180 | |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1181 | CURLcode do_unlock_request(CURL *handle, char *locktoken) { |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1182 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "UNLOCK"); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1183 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1184 | |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1185 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1186 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1187 | |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1188 | // set lock-token header |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1189 | sstr_t ltheader = ucx_sprintf("Lock-Token: <%s>", locktoken); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1190 | struct curl_slist *headers = curl_slist_append(NULL, ltheader.ptr); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1191 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1192 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1193 | CURLcode ret = curl_easy_perform(handle); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1194 | curl_slist_free_all(headers); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1195 | free(ltheader.ptr); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1196 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1197 | return ret; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1198 | } |