Sun, 16 Jun 2019 13:14:24 +0200
add new session flags for properties encryption
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 | * |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
4 | * Copyright 2018 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" |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
37 | #include "xml.h" |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | |
156 | 39 | #include <ucx/utils.h> |
40 | ||
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | #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
|
42 | |
478
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
43 | |
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
44 | int dav_buffer_seek(UcxBuffer *b, curl_off_t offset, int origin) { |
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
45 | return ucx_buffer_seek(b, offset, origin) == 0 ? 0:CURL_SEEKFUNC_CANTSEEK; |
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
46 | } |
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
47 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | /* ----------------------------- PROPFIND ----------------------------- */ |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | CURLcode do_propfind_request( |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
51 | DavSession *sn, |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | UcxBuffer *request, |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | UcxBuffer *response) |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | { |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
55 | CURL *handle = sn->handle; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPFIND"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | |
170
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
58 | // 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
|
59 | int depth = 1; |
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
60 | |
171
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
61 | int maxretry = 2; |
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
62 | |
163
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
63 | struct curl_slist *headers = NULL; |
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
64 | CURLcode ret = 0; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); |
478
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
68 | curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, dav_buffer_seek); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | curl_easy_setopt(handle, CURLOPT_READDATA, request); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | 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
|
73 | 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
|
74 | 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
|
75 | util_capture_header(handle, respheaders); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | |
171
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
77 | for(int i=0;i<maxretry;i++) { |
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
78 | if (depth == 1) { |
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
79 | headers = curl_slist_append(headers, "Depth: 1"); |
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
80 | } else if (depth == -1) { |
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
81 | headers = curl_slist_append(headers, "Depth: infinity"); |
163
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
82 | } else { |
171
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
83 | headers = curl_slist_append(headers, "Depth: 0"); |
163
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
84 | } |
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
85 | 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
|
86 | 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
|
87 | |
8911170d5e78
fixed incorrect response buffer reset in manual redirection handling in do_propfind_request
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
88 | // 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
|
89 | 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
|
90 | response->size = response->pos = 0; |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
91 | ret = dav_session_curl_perform_buf(sn, request, response, NULL); |
163
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
92 | curl_slist_free_all(headers); |
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
93 | headers = NULL; |
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
94 | |
170
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
95 | /* |
171
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
96 | * Handle two cases: |
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
97 | * 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
|
98 | * => 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
|
99 | * 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
|
100 | * => 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
|
101 | */ |
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
102 | char *msdavexterror; |
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
103 | 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
|
104 | 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
|
105 | 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
|
106 | |
171
254326cbc1bc
simplified do_propfind_request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
107 | if(iishack) { |
170
cf054cded046
added depth header workaround for Microsoft IIS (tested with sharepoint)
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
108 | depth = 0; |
163
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
109 | } else { |
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
110 | break; |
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
111 | } |
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
112 | } |
c6d05f646b59
reimplemented redirects for propfind requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
113 | |
176
747f3796eddd
improved util_capture_header when deactivating the capturing
Mike Becker <universe@uap-core.de>
parents:
172
diff
changeset
|
114 | // 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
|
115 | 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
|
116 | 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
|
117 | ucx_map_free(respheaders); |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
118 | |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
119 | return ret; |
33
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 | |
315
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
122 | UcxBuffer* create_allprop_propfind_request(void) { |
148
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
123 | 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
|
124 | sstr_t s; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | 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
|
127 | 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
|
128 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | s = S("<D:propfind xmlns:D=\"DAV:\">\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | 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
|
131 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | s = S("<D:allprop/></D:propfind>\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | 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
|
134 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | return buf; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | |
475
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
138 | UcxBuffer* create_propfind_request(DavSession *sn, UcxList *properties, char *rootelm, DavBool nocrypt) { |
148
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
139 | 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
|
140 | sstr_t s; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
142 | int add_crypto_name = 1; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
143 | int add_crypto_key = 1; |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
144 | int add_crypto_hash = 1; |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
145 | char *crypto_ns = "idav"; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | UcxMap *namespaces = ucx_map_new(8); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | UCX_FOREACH(elm, properties) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | DavProperty *p = elm->data; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | if(strcmp(p->ns->name, "DAV:")) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | 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
|
151 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
152 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
153 | // 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
|
154 | // and crypto-key, mark them as existent |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
155 | if(!strcmp(p->ns->name, DAV_NS)) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
156 | if(!strcmp(p->name, "crypto-name")) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
157 | add_crypto_name = 0; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
158 | crypto_ns = p->ns->prefix; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
159 | } else if(!strcmp(p->name, "crypto-key")) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
160 | add_crypto_key = 0; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
161 | crypto_ns = p->ns->prefix; |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
162 | } else if(!strcmp(p->name, "crypto-hash")) { |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
163 | add_crypto_hash = 0; |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
164 | crypto_ns = p->ns->prefix; |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
165 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
166 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
167 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
168 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
169 | DavNamespace idav_ns; |
475
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
170 | if(add_crypto_name && add_crypto_key && DAV_CRYPTO(sn) && !nocrypt) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
171 | idav_ns.prefix = "idav"; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
172 | idav_ns.name = DAV_NS; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
173 | 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
|
174 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | 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
|
177 | 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
|
178 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | // write root element and namespaces |
475
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
180 | ucx_bprintf(buf, "<D:%s xmlns:D=\"DAV:\"", rootelm); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
181 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | UcxMapIterator mapi = ucx_map_iterator(namespaces); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | UcxKey key; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | DavNamespace *ns; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | UCX_MAP_FOREACH(key, ns, mapi) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | s = S(" xmlns:"); |
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 | s = sstr(ns->prefix); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | 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
|
190 | s = S("=\""); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | 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
|
192 | s = sstr(ns->name); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | 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
|
194 | s = S("\""); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | 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
|
196 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | s = S(">\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | 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
|
199 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | // default properties |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | s = S("<D:prop>\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | 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
|
203 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | s = S("<D:creationdate />\n<D:getlastmodified />\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | 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
|
206 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | s = S("<D:getcontentlength />\n<D:getcontenttype />\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | 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
|
209 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | s = S("<D:resourcetype />\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | 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
|
212 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
213 | // crypto properties |
475
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
214 | if(DAV_CRYPTO(sn) && !nocrypt) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
215 | if(add_crypto_name) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
216 | ucx_buffer_putc(buf, '<'); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
217 | ucx_buffer_puts(buf, crypto_ns); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
218 | s = S(":crypto-name />\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
219 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
220 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
221 | if(add_crypto_key) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
222 | ucx_buffer_putc(buf, '<'); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
223 | ucx_buffer_puts(buf, crypto_ns); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
224 | s = S(":crypto-key />\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
225 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
226 | } |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
227 | if(add_crypto_hash) { |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
228 | ucx_buffer_putc(buf, '<'); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
229 | ucx_buffer_puts(buf, crypto_ns); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
230 | s = S(":crypto-hash />\n"); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
231 | 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
|
232 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
233 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
234 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | // extra properties |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | UCX_FOREACH(elm, properties) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237 | DavProperty *prop = elm->data; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | s = S("<"); |
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 | s = sstr(prop->ns->prefix); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | 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
|
242 | s = S(":"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | 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
|
244 | s = sstr(prop->name); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | 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
|
246 | s = S(" />\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | 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
|
248 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | // end |
475
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
251 | ucx_bprintf(buf, "</D:prop>\n</D:%s>\n", rootelm); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
253 | ucx_map_free(namespaces); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | return buf; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | |
315
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
257 | UcxBuffer* create_basic_propfind_request(void) { |
148
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
258 | 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
|
259 | sstr_t s; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
260 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
261 | 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
|
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 | s = S("<D:propfind xmlns:D=\"DAV:\" xmlns:i=\""); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
265 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
266 | s = S(DAV_NS); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
267 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
268 | s = S("\" >\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
269 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
270 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
271 | // properties |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
272 | s = S("<D:prop>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
273 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
274 | s = S("<D:resourcetype />\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
275 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
276 | s = S("<i:crypto-key />\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
277 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
278 | s = S("<i:crypto-name />\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
279 | 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
|
280 | s = S("<i:crypto-hash />\n"); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
281 | 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
|
282 | s = S("</D:prop>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
283 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
284 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
285 | // end |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
286 | s = S("</D:propfind>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
287 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
288 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
289 | return buf; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
290 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
291 | |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
292 | 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
|
293 | 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
|
294 | if(!parser) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
295 | return NULL; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
296 | } |
137
01cb9aabff05
fixed horrible bugs, davql hopefully just works now (without order by yet)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
297 | 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
|
298 | parser->current = NULL; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
299 | if(parser->document) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
300 | 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
|
301 | if(xml_root) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
302 | 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
|
303 | while(node) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
304 | // find first response tag |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
305 | 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
|
306 | 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
|
307 | parser->current = node; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
308 | break; |
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 | node = node->next; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
312 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
313 | return parser; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
314 | } else { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
315 | xmlFreeDoc(parser->document); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
316 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
317 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
318 | free(parser); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
319 | return NULL; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
320 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
321 | |
148
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
322 | void destroy_propfind_parser(PropfindParser *parser) { |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
323 | if(parser->document) { |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
324 | xmlFreeDoc(parser->document); |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
325 | } |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
326 | free(parser); |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
327 | } |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
328 | |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
329 | 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
|
330 | if(parser->current == NULL) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
331 | return 0; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
332 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
333 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
334 | char *href = NULL; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
335 | int iscollection = 0; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
336 | 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
|
337 | 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
|
338 | char *crypto_key = NULL; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
339 | |
148
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
340 | result->properties = NULL; |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
341 | |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
342 | 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
|
343 | while(node) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
344 | 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
|
345 | 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
|
346 | 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
|
347 | 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
|
348 | // error |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
349 | return -1; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
350 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
351 | 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
|
352 | } 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
|
353 | xmlNode *n = node->children; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
354 | xmlNode *prop_node = NULL; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
355 | int ok = 0; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
356 | // get the status code |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
357 | while(n) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
358 | 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
|
359 | 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
|
360 | prop_node = n; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
361 | } 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
|
362 | 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
|
363 | 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
|
364 | // error |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
365 | return -1; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
366 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
367 | 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
|
368 | 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
|
369 | // error |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
370 | return -1; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
371 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
372 | 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
|
373 | 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
|
374 | ok = 1; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
375 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
376 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
377 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
378 | n = n->next; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
379 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
380 | // 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
|
381 | if(ok) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
382 | n = prop_node->children; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
383 | while(n) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
384 | 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
|
385 | 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
|
386 | if(xstreq(n->name, "resourcetype")) { |
231
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
387 | if(parse_resource_type(n)) { |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
388 | iscollection = TRUE; |
128
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 | } 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
|
391 | 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
|
392 | 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
|
393 | } 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
|
394 | 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
|
395 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
396 | } |
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 | n = n->next; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
399 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
400 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
401 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
402 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
403 | node = node->next; |
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 | |
156 | 406 | 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
|
407 | result->iscollection = iscollection; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
408 | result->properties = properties; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
409 | 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
|
410 | 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
|
411 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
412 | // find next response tag |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
413 | 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
|
414 | while(next) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
415 | 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
|
416 | 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
|
417 | break; |
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 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
420 | next = next->next; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
421 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
422 | parser->current = next; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
423 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
424 | return 1; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
425 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
426 | |
148
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
427 | void cleanup_response(ResponseTag *result) { |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
428 | if(result) { |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
429 | ucx_list_free(result->properties); |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
430 | } |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
431 | } |
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
432 | |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
433 | 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
|
434 | 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
|
435 | 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
|
436 | int ret = 0; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
437 | 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
|
438 | ret = 1; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
439 | } 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
|
440 | 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
|
441 | href_s.length--; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
442 | 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
|
443 | ret = 1; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
444 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
445 | } |
141
b0c44be83276
fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
137
diff
changeset
|
446 | } else if(href_r.length == href_s.length + 1) { |
b0c44be83276
fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
137
diff
changeset
|
447 | if(href_r.ptr[href_r.length-1] == '/') { |
b0c44be83276
fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
137
diff
changeset
|
448 | href_r.length--; |
b0c44be83276
fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
137
diff
changeset
|
449 | if(!sstrcmp(href_s, href_r)) { |
b0c44be83276
fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
137
diff
changeset
|
450 | ret = 1; |
b0c44be83276
fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
137
diff
changeset
|
451 | } |
b0c44be83276
fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
137
diff
changeset
|
452 | } |
b0c44be83276
fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
137
diff
changeset
|
453 | } |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
454 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
455 | free(href_s.ptr); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
456 | free(href_r.ptr); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
457 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
458 | return ret; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
459 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
460 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
461 | |
135
664aeaec8d25
replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
462 | 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
|
463 | char *url = NULL; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
464 | 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
|
465 | if(!root) { |
225
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
466 | printf("methods.c: TODO: remove\n"); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
467 | 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
|
468 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
469 | |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
470 | //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
|
471 | 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
|
472 | if(!doc) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
473 | // TODO: free stuff |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
474 | sn->error = DAV_ERROR; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
475 | return NULL; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
476 | } |
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 | xmlNode *xml_root = xmlDocGetRootElement(doc); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
479 | xmlNode *node = xml_root->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
480 | while(node) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
481 | if(node->type == XML_ELEMENT_NODE) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
482 | if(xstreq(node->name, "response")) { |
135
664aeaec8d25
replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
483 | parse_response_tag(root, node); |
33
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 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
486 | node = node->next; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
487 | } |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
488 | xmlFreeDoc(doc); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
489 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
490 | return root; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
491 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
492 | |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
493 | 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
|
494 | // create resource |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
495 | 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
|
496 | 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
|
497 | 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
|
498 | if(!response->crypto_key) { |
225
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
499 | sn->error = DAV_ERROR; |
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
500 | 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
|
501 | return NULL; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
502 | } |
147
458a8dc68048
added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
503 | 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
|
504 | if(!name) { |
225
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
505 | sn->error = DAV_ERROR; |
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
506 | 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
|
507 | return NULL; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
508 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
509 | } else { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
510 | 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
|
511 | int nlen = 0; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
512 | 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
|
513 | sn->handle, |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
514 | resname.ptr, |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
515 | resname.length, |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
516 | &nlen); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
517 | 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
|
518 | curl_free(uname); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
519 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
520 | |
137
01cb9aabff05
fixed horrible bugs, davql hopefully just works now (without order by yet)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
521 | 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
|
522 | DavResource *res = NULL; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
523 | if(parent_path) { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
524 | 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
|
525 | } else { |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
526 | 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
|
527 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
528 | 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
|
529 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
530 | add_properties(res, response); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
531 | return res; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
532 | } |
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 | 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
|
535 | res->iscollection = response->iscollection; |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
536 | |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
537 | // add properties |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
538 | 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
|
539 | xmlNode *prop = elm->data; |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
540 | resource_add_property(res, (char*)prop->ns->href, (char*)prop->name, prop->children); |
128
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
541 | } |
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 | set_davprops(res); |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
544 | } |
649eb328674a
implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
545 | |
135
664aeaec8d25
replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
546 | int parse_response_tag(DavResource *resource, xmlNode *node) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
547 | DavSession *sn = resource->session; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
548 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
549 | //DavResource *res = resource; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
550 | DavResource *res = NULL; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
551 | char *href = NULL; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
552 | UcxList *properties = NULL; // xmlNode list |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
553 | 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
|
554 | char *crypto_key = NULL; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
555 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
556 | int iscollection = 0; // TODO: remove |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
557 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
558 | node = node->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
559 | while(node) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
560 | if(node->type == XML_ELEMENT_NODE) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
561 | if(xstreq(node->name, "href")) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
562 | xmlNode *href_node = node->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
563 | if(href_node->type != XML_TEXT_NODE) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
564 | // error |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
565 | sn->error = DAV_ERROR; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
566 | return 1; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
567 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
568 | //char *href = (char*)href_node->content; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
569 | 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
|
570 | |
164
4c204e40ef52
fixed href comparison in parse_response_tag
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
571 | 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
|
572 | 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
|
573 | |
4c204e40ef52
fixed href comparison in parse_response_tag
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
574 | if(hrefeq(sn, href_s, href_r)) { |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
575 | res = resource; |
164
4c204e40ef52
fixed href comparison in parse_response_tag
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
576 | } |
66 | 577 | |
164
4c204e40ef52
fixed href comparison in parse_response_tag
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
578 | free(href_s); |
4c204e40ef52
fixed href comparison in parse_response_tag
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
579 | free(href_r); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
580 | } else if(xstreq(node->name, "propstat")) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
581 | xmlNode *n = node->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
582 | xmlNode *prop_node = NULL; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
583 | int ok = 0; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
584 | // get the status code |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
585 | while(n) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
586 | if(n->type == XML_ELEMENT_NODE) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
587 | if(xstreq(n->name, "prop")) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
588 | prop_node = n; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
589 | } else if(xstreq(n->name, "status")) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
590 | xmlNode *status_node = n->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
591 | if(status_node->type != XML_TEXT_NODE) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
592 | sn->error = DAV_ERROR; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
593 | return 1; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
594 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
595 | 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
|
596 | if(status_str.length < 13) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
597 | sn->error = DAV_ERROR; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
598 | return 1; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
599 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
600 | status_str = sstrsubsl(status_str, 9, 3); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
601 | if(!sstrcmp(status_str, S("200"))) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
602 | ok = 1; |
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 | } |
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 | n = n->next; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
607 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
608 | // if status is ok, get all properties |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
609 | if(ok) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
610 | n = prop_node->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
611 | while(n) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
612 | if(n->type == XML_ELEMENT_NODE) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
613 | properties = ucx_list_append(properties, n); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
614 | if(xstreq(n->name, "resourcetype")) { |
231
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
615 | if(parse_resource_type(n)) { |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
616 | iscollection = TRUE; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
617 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
618 | } else if(xstreq(n->ns->href, DAV_NS)) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
619 | if(xstreq(n->name, "crypto-name")) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
620 | crypto_name = util_xml_get_text(n); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
621 | } else if(xstreq(n->name, "crypto-key")) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
622 | crypto_key = util_xml_get_text(n); |
33
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 | } |
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 | n = n->next; |
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 | } |
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 | node = node->next; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
633 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
634 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
635 | if(!res) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
636 | // create new resource object |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
637 | char *name = NULL; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
638 | if(DAV_DECRYPT_NAME(sn) && crypto_name) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
639 | if(!crypto_key) { |
225
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
640 | sn->error = DAV_ERROR; |
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
641 | 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
|
642 | return -1; |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
643 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
644 | name = util_decrypt_str(sn, crypto_name, crypto_key); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
645 | if(!name) { |
225
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
646 | sn->error = DAV_ERROR; |
a297c2e28fa1
improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
647 | 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
|
648 | return -1; |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
649 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
650 | } else { |
44
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
651 | sstr_t resname = sstr(util_resource_name(href)); |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
652 | int nlen = 0; |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
653 | char *uname = curl_easy_unescape( |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
654 | sn->handle, |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
655 | resname.ptr, |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
656 | resname.length, |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
657 | &nlen); |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
658 | name = dav_session_strdup(sn, uname); |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
659 | curl_free(uname); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
660 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
661 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
662 | href = dav_session_strdup(sn, href); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
663 | 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
|
664 | |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
665 | dav_session_free(sn, name); |
43
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 | res->iscollection = iscollection; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
668 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
669 | // add properties |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
670 | UCX_FOREACH(elm, properties) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
671 | xmlNode *prop = elm->data; |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
672 | resource_add_property(res, (char*)prop->ns->href, (char*)prop->name, prop->children); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
673 | } |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
674 | ucx_list_free(properties); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
675 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
676 | set_davprops(res); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
677 | if(res != resource) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
678 | resource_add_child(resource, res); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
679 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
680 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
681 | return 0; |
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 | void set_davprops(DavResource *res) { |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
685 | char *cl = dav_get_string_property_ns(res, "DAV:", "getcontentlength"); |
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
686 | char *ct = dav_get_string_property_ns(res, "DAV:", "getcontenttype"); |
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
687 | char *cd = dav_get_string_property_ns(res, "DAV:", "creationdate"); |
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
688 | char *lm = dav_get_string_property_ns(res, "DAV:", "getlastmodified"); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
689 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
690 | res->contenttype = ct; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
691 | if(cl) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
692 | char *end = NULL; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
693 | res->contentlength = strtoull(cl, &end, 0); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
694 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
695 | res->creationdate = util_parse_creationdate(cd); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
696 | res->lastmodified = util_parse_lastmodified(lm); |
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 | |
231
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
699 | int parse_resource_type(xmlNode *node) { |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
700 | int collection = FALSE; |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
701 | xmlNode *c = node->children; |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
702 | while(c) { |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
703 | if(c->type == XML_ELEMENT_NODE) { |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
704 | 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
|
705 | collection = TRUE; |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
706 | break; |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
707 | } |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
708 | } |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
709 | c = c->next; |
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 | return collection; |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
712 | } |
f3119e749549
fixed lazy propfind parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
227
diff
changeset
|
713 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
714 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
715 | /* ----------------------------- PROPPATCH ----------------------------- */ |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
716 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
717 | CURLcode do_proppatch_request( |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
718 | DavSession *sn, |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
719 | char *lock, |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
720 | UcxBuffer *request, |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
721 | UcxBuffer *response) |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
722 | { |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
723 | CURL *handle = sn->handle; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
724 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPPATCH"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
725 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
726 | struct curl_slist *headers = NULL; |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
727 | 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
|
728 | if(lock) { |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
729 | char *url = NULL; |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
730 | curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
731 | 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
|
732 | headers = curl_slist_append(headers, ltheader); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
733 | free(ltheader); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
734 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
735 | } |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
736 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
737 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
738 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
739 | curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); |
478
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
740 | curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, dav_buffer_seek); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
741 | curl_easy_setopt(handle, CURLOPT_READDATA, request); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
742 | curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
743 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
744 | 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
|
745 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
746 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
747 | ucx_buffer_seek(request, 0, SEEK_SET); |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
748 | CURLcode ret = dav_session_curl_perform_buf(sn, request, response, NULL); |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
749 | curl_slist_free_all(headers); |
371
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
750 | |
373
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
751 | //printf("proppatch: \n%.*s\n", request->size, request->space); |
371
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
752 | |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
753 | return ret; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
754 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
755 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
756 | UcxBuffer* create_proppatch_request(DavResourceData *data) { |
148
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
757 | UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND); |
505 | 758 | scstr_t s; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
759 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
760 | UcxMap *namespaces = ucx_map_new(8); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
761 | char prefix[8]; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
762 | int pfxnum = 0; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
763 | UCX_FOREACH(elm, data->set) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
764 | DavProperty *p = elm->data; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
765 | if(strcmp(p->ns->name, "DAV:")) { |
104
6fb4d24d9df9
added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
766 | snprintf(prefix, 8, "x%d", pfxnum++); |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
767 | 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
|
768 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
769 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
770 | UCX_FOREACH(elm, data->remove) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
771 | DavProperty *p = elm->data; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
772 | if(strcmp(p->ns->name, "DAV:")) { |
104
6fb4d24d9df9
added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
773 | snprintf(prefix, 8, "x%d", pfxnum++); |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
774 | 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
|
775 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
776 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
777 | |
505 | 778 | s = SC("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
779 | 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
|
780 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
781 | // write root element and namespaces |
505 | 782 | s = SC("<D:propertyupdate xmlns:D=\"DAV:\""); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
783 | 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
|
784 | UcxMapIterator mapi = ucx_map_iterator(namespaces); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
785 | UcxKey key; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
786 | char *pfxval; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
787 | UCX_MAP_FOREACH(key, pfxval, mapi) { |
505 | 788 | s = SC(" xmlns:"); |
33
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); |
505 | 790 | s = scstr(pfxval); |
33
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); |
505 | 792 | s = SC("=\""); |
33
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); |
505 | 794 | s = scstrn(key.data, key.len); |
33
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); |
505 | 796 | s = SC("\""); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
797 | 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
|
798 | } |
505 | 799 | s = SC(">\n"); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
800 | 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
|
801 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
802 | if(data->set) { |
505 | 803 | s = SC("<D:set>\n<D:prop>\n"); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
804 | 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
|
805 | UCX_FOREACH(elm, data->set) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
806 | DavProperty *property = elm->data; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
807 | 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
|
808 | if(!prefix) { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
809 | prefix = "D"; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
810 | } |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
811 | |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
812 | // begin tag |
505 | 813 | s = SC("<"); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
814 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
505 | 815 | s = scstr(prefix); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
816 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
505 | 817 | s = SC(":"); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
818 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
505 | 819 | s = scstr(property->name); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
820 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
505 | 821 | s = SC(">"); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
822 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
823 | |
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
824 | // content |
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
825 | DavXmlNode *content = property->value; |
371
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
826 | if(content->type == DAV_XML_TEXT && !content->next) { |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
827 | ucx_buffer_write(content->content, 1, content->contentlength, buf); |
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
828 | } else { |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
829 | dav_print_node(buf, (write_func)ucx_buffer_write, namespaces, content); |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
830 | } |
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
831 | |
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
832 | // end tag |
505 | 833 | s = SC("</"); |
33
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); |
505 | 835 | s = scstr(prefix); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
836 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
505 | 837 | s = SC(":"); |
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); |
505 | 839 | s = scstr(property->name); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
840 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
505 | 841 | s = SC(">\n"); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
842 | 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
|
843 | } |
505 | 844 | s = SC("</D:prop>\n</D:set>\n"); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
845 | 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
|
846 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
847 | if(data->remove) { |
505 | 848 | s = SC("<D:remove>\n<D:prop>\n"); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
849 | 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
|
850 | UCX_FOREACH(elm, data->remove) { |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
851 | DavProperty *property = elm->data; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
852 | 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
|
853 | |
505 | 854 | s = SC("<"); |
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); |
505 | 856 | s = scstr(prefix); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
857 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
505 | 858 | s = SC(":"); |
33
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); |
505 | 860 | s = scstr(property->name); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
861 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
505 | 862 | s = SC(" />\n"); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
863 | 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
|
864 | } |
505 | 865 | s = SC("</D:prop>\n</D:remove>\n"); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
866 | 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
|
867 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
868 | |
505 | 869 | s = SC("</D:propertyupdate>\n"); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
870 | 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
|
871 | |
223
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
872 | // cleanup namespace map |
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
873 | 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
|
874 | ucx_map_free(namespaces); |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
875 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
876 | return buf; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
877 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
878 | |
505 | 879 | UcxBuffer* create_crypto_proppatch_request(DavSession *sn, DavKey *key, const char *name, const char *hash) { |
148
f21ee22170bf
fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
880 | 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
|
881 | sstr_t s; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
882 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
883 | 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
|
884 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
885 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
886 | 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
|
887 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
888 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
889 | s = S("<D:set>\n<D:prop>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
890 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
891 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
892 | if(DAV_ENCRYPT_NAME(sn)) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
893 | s = S("<idav:crypto-name>"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
894 | 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
|
895 | char *crname = aes_encrypt(name, strlen(name), key); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
896 | ucx_buffer_puts(buf, crname); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
897 | free(crname); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
898 | s = S("</idav:crypto-name>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
899 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
900 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
901 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
902 | s = S("<idav:crypto-key>"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
903 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
904 | ucx_buffer_puts(buf, key->name); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
905 | s = S("</idav:crypto-key>\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 | |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
908 | if(hash) { |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
909 | s = S("<idav:crypto-hash>"); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
910 | 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
|
911 | ucx_buffer_puts(buf, hash); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
912 | s = S("</idav:crypto-hash>\n"); |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
913 | 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
|
914 | } |
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
148
diff
changeset
|
915 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
916 | 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
|
917 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
918 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
919 | return buf; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
920 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
921 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
922 | /* ----------------------------- PUT ----------------------------- */ |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
923 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
924 | 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
|
925 | //fwrite(buf, s, n, stdout); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
926 | return s*n; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
927 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
928 | |
478
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
929 | CURLcode do_put_request(DavSession *sn, char *lock, DavBool create, void *data, dav_read_func read_func, dav_seek_func seek_func, size_t length) { |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
930 | CURL *handle = sn->handle; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
931 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
932 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
933 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
934 | // clear headers |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
935 | struct curl_slist *headers = NULL; |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
936 | if(lock) { |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
937 | char *url = NULL; |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
938 | 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
|
939 | char *ltheader = NULL; |
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
940 | if(create) { |
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
941 | 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
|
942 | 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
|
943 | free(url); |
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
944 | } else { |
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
945 | 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
|
946 | } |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
947 | headers = curl_slist_append(headers, ltheader); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
948 | free(ltheader); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
949 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
950 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
951 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
952 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
953 | UcxBuffer *buf = NULL; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
954 | if(!read_func) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
955 | buf = ucx_buffer_new(data, length, 0); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
956 | buf->size = length; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
957 | data = buf; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
958 | read_func = (dav_read_func)ucx_buffer_read; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
959 | 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
|
960 | } else if(length == 0) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
961 | headers = curl_slist_append(headers, "Transfer-Encoding: chunked"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
962 | 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
|
963 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
964 | } else { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
965 | 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
|
966 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
967 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
968 | curl_easy_setopt(handle, CURLOPT_READFUNCTION, read_func); |
478
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
969 | curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, seek_func); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
970 | curl_easy_setopt(handle, CURLOPT_READDATA, data); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
971 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
972 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
973 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
974 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
975 | CURLcode ret = dav_session_curl_perform(sn, NULL); |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
976 | curl_slist_free_all(headers); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
977 | if(buf) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
978 | ucx_buffer_free(buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
979 | } |
223
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
980 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
981 | return ret; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
982 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
983 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
984 | CURLcode do_delete_request(DavSession *sn, char *lock, UcxBuffer *response) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
985 | CURL *handle = sn->handle; |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
986 | struct curl_slist *headers = NULL; |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
987 | if(lock) { |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
988 | char *url = NULL; |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
989 | curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
990 | 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
|
991 | headers = curl_slist_append(headers, ltheader); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
992 | free(ltheader); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
993 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
994 | } else { |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
995 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
996 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
997 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
998 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "DELETE"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
999 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1000 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1001 | 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
|
1002 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1003 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
1004 | CURLcode ret = dav_session_curl_perform(sn, NULL); |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1005 | curl_slist_free_all(headers); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1006 | return ret; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1007 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1008 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
1009 | CURLcode do_mkcol_request(DavSession *sn, char *lock) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
1010 | CURL *handle = sn->handle; |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
1011 | struct curl_slist *headers = NULL; |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1012 | if(lock) { |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1013 | char *url = NULL; |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1014 | 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
|
1015 | url = util_parent_path(url); |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1016 | 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
|
1017 | free(url); |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1018 | headers = curl_slist_append(headers, ltheader); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1019 | free(ltheader); |
227
bf485439222a
fixed locking in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
1020 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1021 | } else { |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1022 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1023 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
1024 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1025 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "MKCOL"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1026 | curl_easy_setopt(handle, CURLOPT_PUT, 0L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1027 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1028 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1029 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1030 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1031 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
1032 | CURLcode ret = dav_session_curl_perform(sn, NULL); |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1033 | curl_slist_free_all(headers); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1034 | return ret; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1035 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1036 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1037 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
1038 | CURLcode do_head_request(DavSession *sn) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
1039 | CURL *handle = sn->handle; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1040 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "HEAD"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1041 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1042 | curl_easy_setopt(handle, CURLOPT_NOBODY, 1L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1043 | |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1044 | // clear headers |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1045 | struct curl_slist *headers = NULL; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1046 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1047 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1048 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1049 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1050 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
1051 | CURLcode ret = dav_session_curl_perform(sn, NULL); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1052 | curl_easy_setopt(handle, CURLOPT_NOBODY, 0L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1053 | return ret; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1054 | } |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1055 | |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1056 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
1057 | CURLcode do_copy_move_request(DavSession *sn, char *dest, char *lock, DavBool copy, DavBool override) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
1058 | CURL *handle = sn->handle; |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1059 | if(copy) { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1060 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "COPY"); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1061 | } else { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1062 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "MOVE"); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1063 | } |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1064 | curl_easy_setopt(handle, CURLOPT_PUT, 0L); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1065 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1066 | |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1067 | 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
|
1068 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1069 | |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1070 | struct curl_slist *headers = NULL; |
236
6b4ce32d0c4e
copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
231
diff
changeset
|
1071 | if(lock) { |
6b4ce32d0c4e
copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
231
diff
changeset
|
1072 | char *url = NULL; |
6b4ce32d0c4e
copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
231
diff
changeset
|
1073 | 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
|
1074 | 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
|
1075 | headers = curl_slist_append(headers, ltheader); |
6b4ce32d0c4e
copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
231
diff
changeset
|
1076 | free(ltheader); |
6b4ce32d0c4e
copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
231
diff
changeset
|
1077 | } |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1078 | //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
|
1079 | 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
|
1080 | headers = curl_slist_append(headers, deststr.ptr); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1081 | if(override) { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1082 | headers = curl_slist_append(headers, "Overwrite: T"); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1083 | } else { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1084 | headers = curl_slist_append(headers, "Overwrite: F"); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1085 | } |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1086 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1087 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
1088 | CURLcode ret = dav_session_curl_perform(sn, NULL); |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1089 | free(deststr.ptr); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1090 | curl_slist_free_all(headers); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1091 | headers = NULL; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1092 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1093 | return ret; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1094 | } |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
176
diff
changeset
|
1095 | |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1096 | |
315
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1097 | UcxBuffer* create_lock_request(void) { |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1098 | 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
|
1099 | sstr_t s; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1100 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1101 | 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
|
1102 | 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
|
1103 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1104 | 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
|
1105 | "<D:lockscope><D:exclusive/></D:lockscope>\n" |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1106 | "<D:locktype><D:write/></D:locktype>\n" |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1107 | "<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
|
1108 | 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
|
1109 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1110 | s = S("</D:lockinfo>\n"); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1111 | 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
|
1112 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1113 | return buf; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1114 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1115 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1116 | 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
|
1117 | lock->locktoken = NULL; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1118 | lock->timeout = NULL; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1119 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1120 | 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
|
1121 | if(!doc) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1122 | sn->error = DAV_ERROR; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1123 | return -1; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1124 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1125 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1126 | char *timeout = NULL; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1127 | char *locktoken = NULL; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1128 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1129 | int ret = -1; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1130 | xmlNode *xml_root = xmlDocGetRootElement(doc); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1131 | DavBool lockdiscovery = 0; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1132 | if(xml_root) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1133 | xmlNode *node = xml_root->children; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1134 | while(node) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1135 | if(node->type == XML_ELEMENT_NODE) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1136 | if(xstreq(node->name, "lockdiscovery")) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1137 | node = node->children; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1138 | lockdiscovery = 1; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1139 | continue; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1140 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1141 | |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1142 | if(xstreq(node->name, "activelock")) { |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1143 | node = node->children; |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1144 | continue; |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1145 | } |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1146 | |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1147 | if(lockdiscovery) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1148 | if(xstreq(node->name, "timeout")) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1149 | timeout = util_xml_get_text(node); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1150 | } else if(xstreq(node->name, "locktoken")) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1151 | xmlNode *n = node->children; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1152 | while(n) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1153 | if(xstreq(n->name, "href")) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1154 | locktoken = util_xml_get_text(n); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1155 | break; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1156 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1157 | n = n->next; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1158 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1159 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1160 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1161 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1162 | node = node->next; |
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 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1165 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1166 | if(timeout && locktoken) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1167 | lock->timeout = strdup(timeout); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1168 | lock->locktoken = strdup(locktoken); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1169 | ret = 0; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1170 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1171 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1172 | xmlFreeDoc(doc); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1173 | return ret; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1174 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1175 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
1176 | CURLcode do_lock_request(DavSession *sn, UcxBuffer *request, UcxBuffer *response, time_t timeout) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
1177 | CURL *handle = sn->handle; |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1178 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "LOCK"); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1179 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1180 | request->pos = 0; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1181 | |
315
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1182 | // clear headers |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1183 | struct curl_slist *headers = NULL; |
315
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1184 | |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1185 | if(timeout != 0) { |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1186 | sstr_t thdr; |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1187 | if(timeout < 0) { |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1188 | thdr = ucx_sprintf("%s", "Timeout: Infinite"); |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1189 | } else { |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1190 | thdr = ucx_sprintf("Timeout: Second-%u", (unsigned int)timeout); |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1191 | } |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1192 | headers = curl_slist_append(headers, thdr.ptr); |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1193 | free(thdr.ptr); |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1194 | } |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1195 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
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 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1198 | curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); |
478
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
1199 | curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, dav_buffer_seek); |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1200 | curl_easy_setopt(handle, CURLOPT_READDATA, request); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1201 | 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
|
1202 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1203 | 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
|
1204 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1205 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
1206 | CURLcode ret = dav_session_curl_perform_buf(sn, request, response, NULL); |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1207 | |
315
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1208 | if(headers) { |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1209 | curl_slist_free_all(headers); |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1210 | } |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1211 | |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1212 | return ret; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1213 | } |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1214 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
1215 | CURLcode do_unlock_request(DavSession *sn, char *locktoken) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
1216 | CURL *handle = sn->handle; |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1217 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "UNLOCK"); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1218 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1219 | |
208
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1220 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1221 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); |
1fb26aca5093
added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1222 | |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1223 | // set lock-token header |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1224 | 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
|
1225 | 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
|
1226 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1227 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
1228 | CURLcode ret = dav_session_curl_perform(sn, NULL); |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1229 | curl_slist_free_all(headers); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1230 | free(ltheader.ptr); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1231 | |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1232 | return ret; |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1233 | } |
475
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1234 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1235 | CURLcode do_simple_request(DavSession *sn, char *method, char *locktoken) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1236 | CURL *handle = sn->handle; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1237 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, method); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1238 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1239 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1240 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1241 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1242 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1243 | // set lock-token header |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1244 | sstr_t ltheader; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1245 | struct curl_slist *headers = NULL; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1246 | if(locktoken) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1247 | ltheader = ucx_sprintf("Lock-Token: <%s>", locktoken); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1248 | headers = curl_slist_append(NULL, ltheader.ptr); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1249 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1250 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1251 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1252 | CURLcode ret = dav_session_curl_perform(sn, NULL); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1253 | if(locktoken) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1254 | curl_slist_free_all(headers); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1255 | free(ltheader.ptr); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1256 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1257 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1258 | return ret; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1259 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1260 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1261 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1262 | CURLcode do_report_request(DavSession *sn, UcxBuffer *request, UcxBuffer *response) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1263 | CURL *handle = sn->handle; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1264 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "REPORT"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1265 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1266 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1267 | curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); |
478
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
1268 | curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, dav_buffer_seek); |
475
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1269 | curl_easy_setopt(handle, CURLOPT_READDATA, request); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1270 | curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1271 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1272 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1273 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1274 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1275 | struct curl_slist *headers = NULL; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1276 | headers = curl_slist_append(headers, "Content-Type: text/xml"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1277 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1278 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1279 | request->pos = 0; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1280 | response->size = response->pos = 0; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1281 | CURLcode ret = dav_session_curl_perform_buf(sn, request, response, NULL); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1282 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1283 | curl_slist_free_all(headers); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1284 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1285 | return ret; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
1286 | } |