libidav/methods.c

Sat, 12 Oct 2019 13:42:02 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 12 Oct 2019 13:42:02 +0200
changeset 655
4d33b672c33a
parent 638
b3077bdb3d77
child 743
716f6bf04c30
permissions
-rw-r--r--

add edit-user command

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

mercurial