libidav/methods.c

Mon, 26 Aug 2013 14:44:21 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 26 Aug 2013 14:44:21 +0200
changeset 34
1b87b3b1921e
parent 33
0bbbb0341606
child 38
b855f76e965b
permissions
-rw-r--r--

removed debug code

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 *
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2013 Olaf Wintermann. All rights reserved.
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"
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "davql.h"
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #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
38
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 /* ----------------------------- PROPFIND ----------------------------- */
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 CURLcode do_propfind_request(
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 CURL *handle,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 UcxBuffer *request,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 UcxBuffer *response)
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPFIND");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 struct curl_slist *headers = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 headers = curl_slist_append(headers, "Content-Type: text/xml");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 headers = curl_slist_append(headers, "Depth: 1");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 curl_easy_setopt(handle, CURLOPT_READDATA, request);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 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
61 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 ucx_buffer_seek(request, 0, SEEK_SET);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 return curl_easy_perform(handle);
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
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 UcxBuffer* create_allprop_propfind_request() {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 UcxBuffer *buf = ucx_buffer_new(NULL, 512, 0);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 sstr_t s;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 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
72 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
73
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 s = S("<D:propfind xmlns:D=\"DAV:\">\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 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
76
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 s = S("<D:allprop/></D:propfind>\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 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
79
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 return buf;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 UcxBuffer* create_propfind_request(UcxList *properties) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 UcxBuffer *buf = ucx_buffer_new(NULL, 512, 0);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 sstr_t s;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 UcxMap *namespaces = ucx_map_new(8);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 UCX_FOREACH(elm, properties) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 DavProperty *p = elm->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 if(strcmp(p->ns->name, "DAV:")) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 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
92 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 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
96 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
97
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 // write root element and namespaces
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 s = S("<D:propfind xmlns:D=\"DAV:\"");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 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
101 UcxMapIterator mapi = ucx_map_iterator(namespaces);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 UcxKey key;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 DavNamespace *ns;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 UCX_MAP_FOREACH(key, ns, mapi) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 s = S(" xmlns:");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 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
107 s = sstr(ns->prefix);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 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
109 s = S("=\"");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 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
111 s = sstr(ns->name);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 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
113 s = S("\"");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 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
115 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 s = S(">\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 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
118
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 // default properties
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 s = S("<D:prop>\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 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
122
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 s = S("<D:creationdate />\n<D:getlastmodified />\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 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
125
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 s = S("<D:getcontentlength />\n<D:getcontenttype />\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:resourcetype />\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 // extra properties
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 UCX_FOREACH(elm, properties) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 DavProperty *prop = elm->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 s = S("<");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 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
137 s = sstr(prop->ns->prefix);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 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
139 s = S(":");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 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
141 s = sstr(prop->name);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 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
143 s = S(" />\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 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
145 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 // end
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 s = S("</D:prop>\n</D:propfind>\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 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
150
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 return buf;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 DavResource* parse_propfind_response(DavSession *sn, DavResource *root, UcxBuffer *response, DavQOp *cond, size_t len) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 char *url = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 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
157 if(!root) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 root = dav_resource_new_href(sn, util_url_path(url));
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 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
162 if(!doc) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 // TODO: free stuff
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 sn->error = DAV_ERROR;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 return NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 xmlNode *xml_root = xmlDocGetRootElement(doc);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 xmlNode *node = xml_root->children;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 while(node) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 if(node->type == XML_ELEMENT_NODE) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 if(xstreq(node->name, "response")) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 parse_response_tag(root, node, cond, len);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 node = node->next;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 return root;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 int parse_response_tag(DavResource *resource, xmlNode *node, DavQOp *cond, size_t clen) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 DavResource *res = resource;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 node = node->children;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 while(node) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 if(node->type == XML_ELEMENT_NODE) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 if(xstreq(node->name, "href")) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 xmlNode *href_node = node->children;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 if(href_node->type != XML_TEXT_NODE) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 // error
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 resource->session->error = DAV_ERROR;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 return 1;
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 char *href = (char*)href_node->content;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 href = util_url_path(href);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 if(xstreq(resource->href, href)) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 res = resource;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 } else {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 res = dav_resource_new_href(resource->session, href);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 res->parent = resource;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 } else if(xstreq(node->name, "propstat")) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 xmlNode *n = node->children;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 xmlNode *prop_node = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 int ok = 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 // get the status code
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 while(n) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 if(n->type == XML_ELEMENT_NODE) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 if(xstreq(n->name, "prop")) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 prop_node = n;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 } else if(xstreq(n->name, "status")) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 xmlNode *status_node = n->children;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 if(status_node->type != XML_TEXT_NODE) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 resource->session->error = DAV_ERROR;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 return 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 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
219 if(status_str.length < 13) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 resource->session->error = DAV_ERROR;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 return 1;
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 status_str = sstrsubsl(status_str, 9, 3);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 if(!sstrcmp(status_str, S("200"))) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 ok = 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 n = n->next;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 // if status is ok, get all properties
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 if(ok) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 n = prop_node->children;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 while(n) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 if(n->type == XML_ELEMENT_NODE) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 if(xstreq(n->name, "resourcetype")) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 xmlNode *rsnode = n->children;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 if(rsnode && rsnode->type == XML_ELEMENT_NODE) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 // TODO: this is a ugly lazy hack
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 resource_add_property(res, "DAV:", (char*)n->name, "collection");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 res->iscollection = 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 } else {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 xmlNode *content = n->children;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 if(content) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 resource_add_property(
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 res,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 (char*)n->ns->href,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 (char*)n->name,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 (char*)content->content);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 n = n->next;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 node = node->next;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 set_davprops(res);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 if(res != resource) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 if(clen > 0) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 if(!condition_eval(res, cond, clen)) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 // skip resource
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 return 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 resource_add_child(resource, res);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274 return 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 void set_davprops(DavResource *res) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278 char *cl = dav_get_property_ns(res, "DAV:", "getcontentlength");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 char *ct = dav_get_property_ns(res, "DAV:", "getcontenttype");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280 char *cd = dav_get_property_ns(res, "DAV:", "creationdate");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281 char *lm = dav_get_property_ns(res, "DAV:", "getlastmodified");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 res->contenttype = ct;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 if(cl) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 char *end = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 res->contentlength = strtoull(cl, &end, 0);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 res->creationdate = util_parse_creationdate(cd);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289 res->lastmodified = util_parse_lastmodified(lm);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 /* ----------------------------- PROPPATCH ----------------------------- */
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 CURLcode do_proppatch_request(
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 CURL *handle,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 UcxBuffer *request,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 UcxBuffer *response)
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPPATCH");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 struct curl_slist *headers = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303 headers = curl_slist_append(headers, "Content-Type: text/xml");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309 curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310 curl_easy_setopt(handle, CURLOPT_READDATA, request);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
312
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 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
314 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
316 ucx_buffer_seek(request, 0, SEEK_SET);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
317 return curl_easy_perform(handle);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
318 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320 UcxBuffer* create_proppatch_request(DavResourceData *data) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
321 UcxBuffer *buf = ucx_buffer_new(NULL, 512, 0);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
322 sstr_t s;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
324 UcxMap *namespaces = ucx_map_new(8);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
325 char prefix[8];
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 int pfxnum = 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327 UCX_FOREACH(elm, data->set) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328 DavProperty *p = elm->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329 if(strcmp(p->ns->name, "DAV:")) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330 snprintf(prefix, 8, "x%d\0", pfxnum++);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331 ucx_map_cstr_put(namespaces, p->ns->name, prefix);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
332 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
333 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 UCX_FOREACH(elm, data->remove) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 DavProperty *p = elm->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336 if(strcmp(p->ns->name, "DAV:")) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337 snprintf(prefix, 8, "x%d\0", pfxnum++);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338 ucx_map_cstr_put(namespaces, p->ns->name, prefix);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 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
343 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
344
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345 // write root element and namespaces
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346 s = S("<D:propertyupdate xmlns:D=\"DAV:\"");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
347 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
348 UcxMapIterator mapi = ucx_map_iterator(namespaces);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
349 UcxKey key;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
350 char *pfxval;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
351 UCX_MAP_FOREACH(key, pfxval, mapi) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
352 s = S(" xmlns:");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
353 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
354 s = sstr(pfxval);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
355 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
356 s = S("=\"");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
357 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
358 s = sstrn(key.data, key.len);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
359 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
360 s = S("\"");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
361 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
362 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
363 s = S(">\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
364 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
365
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
366 if(data->set) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367 s = S("<D:set>\n<D:prop>\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
368 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
369 UCX_FOREACH(elm, data->set) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
370 DavProperty *property = elm->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
371 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
372
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
373 s = S("<");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
374 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
375 s = sstr(prefix);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
376 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
377 s = S(":");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
378 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
379 s = sstr(property->name);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
380 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
381 s = S(">");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
382 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
383 s = sstr(property->value);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
384 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
385 s = S("</");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
386 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
387 s = sstr(prefix);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
388 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
389 s = S(":");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
390 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
391 s = sstr(property->name);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
392 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
393 s = S(">\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
394 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
395 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
396 s = S("</D:prop>\n</D:set>\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
397 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
398 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
399 if(data->remove) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
400 s = S("<D:set>\n<D:prop>\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
401 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
402 UCX_FOREACH(elm, data->set) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
403 DavProperty *property = elm->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
404 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
405
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
406 s = S("<");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
407 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
408 s = sstr(prefix);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
409 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
410 s = S(":");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
411 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
412 s = sstr(property->name);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
413 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
414 s = S(">");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
415 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
416 s = sstr(property->value);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
417 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
418 s = S("</");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
419 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
420 s = sstr(prefix);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
421 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
422 s = S(":");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
423 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
424 s = sstr(property->name);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
425 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
426 s = S(">\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
427 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
428 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
429 s = S("</D:prop>\n</D:set>\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
430 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
431 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
432
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
433 s = S("</D:propertyupdate>\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
434 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
435
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
436 return buf;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
437 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
438
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
439 /* ----------------------------- PUT ----------------------------- */
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
440
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
441 static size_t dummy_write(void *buf, size_t s, size_t n, void *data) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
442 fwrite(buf, s, n, stdout);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
443 return s*n;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
444 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
445
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
446 CURLcode do_put_request(CURL *handle, void *data, dav_read_func read_func, size_t length) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
447 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
448 curl_easy_setopt(handle, CURLOPT_PUT, 1L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
449 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
450 curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
451
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
452 UcxBuffer *buf = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
453 if(!read_func) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
454 buf = ucx_buffer_new(data, length, 0);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
455 buf->size = length;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
456 data = buf;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
457 read_func = (dav_read_func)ucx_buffer_read;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
458 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
459 } else if(length == 0) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
460 struct curl_slist *headers = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
461 headers = curl_slist_append(headers, "Transfer-Encoding: chunked");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
462 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
463 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
464 } else {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
465 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
466 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
467
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
468 curl_easy_setopt(handle, CURLOPT_READFUNCTION, read_func);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
469 curl_easy_setopt(handle, CURLOPT_READDATA, data);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
470
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
471 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
472 curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
473
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
474 CURLcode ret = curl_easy_perform(handle);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
475 if(buf) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
476 ucx_buffer_free(buf);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
477 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
478 return ret;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
479 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
480
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
481 CURLcode do_delete_request(CURL *handle, UcxBuffer *response) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
482 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "DELETE");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
483 curl_easy_setopt(handle, CURLOPT_PUT, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
484 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
485 curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
486
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
487 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
488 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
489
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
490 CURLcode ret = curl_easy_perform(handle);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
491 return ret;
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 CURLcode do_mkcol_request(CURL *handle) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
495 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "MKCOL");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
496 curl_easy_setopt(handle, CURLOPT_PUT, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
497 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
498 curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
499
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
500 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
501 curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
502
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
503 CURLcode ret = curl_easy_perform(handle);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
504 return ret;
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
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 CURLcode do_head_request(CURL *handle) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
509 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "HEAD");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
510 curl_easy_setopt(handle, CURLOPT_PUT, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
511 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
512 curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
513 curl_easy_setopt(handle, CURLOPT_NOBODY, 1L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
514
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
515 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
516 curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
517
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
518 CURLcode ret = curl_easy_perform(handle);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
519 curl_easy_setopt(handle, CURLOPT_NOBODY, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
520 return ret;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
521 }

mercurial