libidav/methods.c

Tue, 13 Oct 2015 16:10:58 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 13 Oct 2015 16:10:58 +0200
changeset 161
97a52ce52b1a
parent 156
4b3aecafd6be
child 162
25374afa5616
permissions
-rw-r--r--

don't allow signs for date strings (always expect full years)

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 *
75
56962faf2b42 copyright update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 74
diff changeset
4 * Copyright 2015 Olaf Wintermann. All rights reserved.
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "utils.h"
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "methods.h"
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
35 #include "crypto.h"
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
36 #include "session.h"
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
156
4b3aecafd6be fixed href bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
38 #include <ucx/utils.h>
4b3aecafd6be fixed href bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
39
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b)
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 /* ----------------------------- PROPFIND ----------------------------- */
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 CURLcode do_propfind_request(
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 CURL *handle,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 UcxBuffer *request,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 UcxBuffer *response)
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPFIND");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 struct curl_slist *headers = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 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
53 headers = curl_slist_append(headers, "Depth: 1");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 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
58 curl_easy_setopt(handle, CURLOPT_READDATA, request);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 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
62 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 ucx_buffer_seek(request, 0, SEEK_SET);
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
65 CURLcode ret = curl_easy_perform(handle);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
66 curl_slist_free_all(headers);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
67 return ret;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 UcxBuffer* create_allprop_propfind_request() {
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
71 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
72 sstr_t s;
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("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\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:propfind xmlns:D=\"DAV:\">\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 s = S("<D:allprop/></D:propfind>\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 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
82
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 return buf;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
86 UcxBuffer* create_propfind_request(DavSession *sn, UcxList *properties) {
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
87 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
88 sstr_t s;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
90 int add_crypto_name = 1;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
91 int add_crypto_key = 1;
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
92 int add_crypto_hash = 1;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
93 char *crypto_ns = "idav";
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 UcxMap *namespaces = ucx_map_new(8);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 UCX_FOREACH(elm, properties) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 DavProperty *p = elm->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 if(strcmp(p->ns->name, "DAV:")) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 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
99 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
100
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
101 // 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
102 // and crypto-key, mark them as existent
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
103 if(!strcmp(p->ns->name, DAV_NS)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
104 if(!strcmp(p->name, "crypto-name")) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
105 add_crypto_name = 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
106 crypto_ns = p->ns->prefix;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
107 } else if(!strcmp(p->name, "crypto-key")) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
108 add_crypto_key = 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
109 crypto_ns = p->ns->prefix;
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
110 } else if(!strcmp(p->name, "crypto-hash")) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
111 add_crypto_hash = 0;
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
112 crypto_ns = p->ns->prefix;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
113 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
114 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
115 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
116
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
117 DavNamespace idav_ns;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
118 if(add_crypto_name && add_crypto_key && DAV_CRYPTO(sn)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
119 idav_ns.prefix = "idav";
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
120 idav_ns.name = DAV_NS;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
121 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
122 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 s = S("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 ucx_buffer_write(s.ptr, 1, s.length, buf);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 // write root element and namespaces
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 s = S("<D:propfind xmlns:D=\"DAV:\"");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 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
130 UcxMapIterator mapi = ucx_map_iterator(namespaces);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 UcxKey key;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 DavNamespace *ns;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 UCX_MAP_FOREACH(key, ns, mapi) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 s = S(" xmlns:");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 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
136 s = sstr(ns->prefix);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 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
138 s = S("=\"");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 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
140 s = sstr(ns->name);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 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
142 s = S("\"");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 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
144 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 s = S(">\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 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
147
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 // default properties
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 s = S("<D:prop>\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 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
151
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 s = S("<D:creationdate />\n<D:getlastmodified />\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 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
154
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 s = S("<D:getcontentlength />\n<D:getcontenttype />\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 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
157
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 s = S("<D:resourcetype />\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 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
160
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
161 // crypto properties
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
162 if(DAV_CRYPTO(sn)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
163 if(add_crypto_name) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
164 ucx_buffer_putc(buf, '<');
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
165 ucx_buffer_puts(buf, crypto_ns);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
166 s = S(":crypto-name />\n");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
167 ucx_buffer_write(s.ptr, 1, s.length, buf);
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(add_crypto_key) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
170 ucx_buffer_putc(buf, '<');
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
171 ucx_buffer_puts(buf, crypto_ns);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
172 s = S(":crypto-key />\n");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
173 ucx_buffer_write(s.ptr, 1, s.length, buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
174 }
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
175 if(add_crypto_hash) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
176 ucx_buffer_putc(buf, '<');
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
177 ucx_buffer_puts(buf, crypto_ns);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
178 s = S(":crypto-hash />\n");
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
179 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
180 }
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
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 // extra properties
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 UCX_FOREACH(elm, properties) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 DavProperty *prop = elm->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 s = S("<");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 ucx_buffer_write(s.ptr, 1, s.length, buf);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 s = sstr(prop->ns->prefix);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 ucx_buffer_write(s.ptr, 1, s.length, buf);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 s = S(":");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 ucx_buffer_write(s.ptr, 1, s.length, buf);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 s = sstr(prop->name);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 ucx_buffer_write(s.ptr, 1, s.length, buf);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 s = S(" />\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 ucx_buffer_write(s.ptr, 1, s.length, buf);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 // end
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 s = S("</D:prop>\n</D:propfind>\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 ucx_buffer_write(s.ptr, 1, s.length, buf);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
202 ucx_map_free(namespaces);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 return buf;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
206 UcxBuffer* create_basic_propfind_request() {
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
207 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
208 sstr_t s;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
209
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
210 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
211 ucx_buffer_write(s.ptr, 1, s.length, buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
212
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
213 s = S("<D:propfind xmlns:D=\"DAV:\" xmlns:i=\"");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
214 ucx_buffer_write(s.ptr, 1, s.length, buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
215 s = S(DAV_NS);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
216 ucx_buffer_write(s.ptr, 1, s.length, buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
217 s = S("\" >\n");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
218 ucx_buffer_write(s.ptr, 1, s.length, buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
219
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
220 // properties
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
221 s = S("<D:prop>\n");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
222 ucx_buffer_write(s.ptr, 1, s.length, buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
223 s = S("<D:resourcetype />\n");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
224 ucx_buffer_write(s.ptr, 1, s.length, buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
225 s = S("<i:crypto-key />\n");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
226 ucx_buffer_write(s.ptr, 1, s.length, buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
227 s = S("<i:crypto-name />\n");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
228 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
229 s = S("<i:crypto-hash />\n");
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
230 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
231 s = S("</D:prop>\n");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
232 ucx_buffer_write(s.ptr, 1, s.length, buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
233
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
234 // end
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
235 s = S("</D:propfind>\n");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
236 ucx_buffer_write(s.ptr, 1, s.length, buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
237
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
238 return buf;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
239 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
240
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
241 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
242 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
243 if(!parser) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
244 return NULL;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
245 }
137
01cb9aabff05 fixed horrible bugs, davql hopefully just works now (without order by yet)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
246 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
247 parser->current = NULL;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
248 if(parser->document) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
249 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
250 if(xml_root) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
251 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
252 while(node) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
253 // find first response tag
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
254 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
255 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
256 parser->current = node;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
257 break;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
258 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
259 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
260 node = node->next;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
261 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
262 return parser;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
263 } else {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
264 xmlFreeDoc(parser->document);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
265 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
266 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
267 free(parser);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
268 return NULL;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
269 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
270
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
271 void destroy_propfind_parser(PropfindParser *parser) {
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
272 if(parser->document) {
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
273 xmlFreeDoc(parser->document);
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
274 }
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
275 free(parser);
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
276 }
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
277
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
278 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
279 if(parser->current == NULL) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
280 return 0;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
281 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
282
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
283 char *href = NULL;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
284 int iscollection = 0;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
285 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
286 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
287 char *crypto_key = NULL;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
288
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
289 result->properties = NULL;
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
290
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
291 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
292 while(node) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
293 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
294 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
295 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
296 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
297 // error
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
298 return -1;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
299 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
300 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
301 } 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
302 xmlNode *n = node->children;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
303 xmlNode *prop_node = NULL;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
304 int ok = 0;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
305 // get the status code
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
306 while(n) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
307 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
308 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
309 prop_node = n;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
310 } 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
311 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
312 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
313 // error
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
314 return -1;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
315 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
316 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
317 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
318 // error
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
319 return -1;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
320 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
321 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
322 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
323 ok = 1;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
324 }
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 n = n->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 // 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
330 if(ok) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
331 n = prop_node->children;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
332 while(n) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
333 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
334 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
335 if(xstreq(n->name, "resourcetype")) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
336 xmlNode *rsnode = n->children;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
337 if(rsnode && rsnode->type == XML_ELEMENT_NODE) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
338 // TODO: check content
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
339 iscollection = 1;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
340 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
341 } 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
342 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
343 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
344 } 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
345 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
346 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
347 }
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 n = n->next;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
350 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
351 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
352 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
353 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
354 node = node->next;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
355 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
356
156
4b3aecafd6be fixed href bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
357 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
358 result->iscollection = iscollection;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
359 result->properties = properties;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
360 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
361 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
362
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
363 // find next response tag
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
364 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
365 while(next) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
366 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
367 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
368 break;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
369 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
370 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
371 next = next->next;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
372 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
373 parser->current = next;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
374
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
375 return 1;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
376 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
377
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
378 void cleanup_response(ResponseTag *result) {
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
379 if(result) {
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
380 ucx_list_free(result->properties);
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
381 }
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
382 }
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
383
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
384 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
385 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
386 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
387 int ret = 0;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
388 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
389 ret = 1;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
390 } 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
391 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
392 href_s.length--;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
393 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
394 ret = 1;
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 }
141
b0c44be83276 fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
397 } else if(href_r.length == href_s.length + 1) {
b0c44be83276 fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
398 if(href_r.ptr[href_r.length-1] == '/') {
b0c44be83276 fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
399 href_r.length--;
b0c44be83276 fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
400 if(!sstrcmp(href_s, href_r)) {
b0c44be83276 fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
401 ret = 1;
b0c44be83276 fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
402 }
b0c44be83276 fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
403 }
b0c44be83276 fixed href comparison bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
404 }
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 free(href_s.ptr);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
407 free(href_r.ptr);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
408
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
409 return ret;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
410 }
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
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
413 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
414 char *url = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
415 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
416 if(!root) {
44
e4e23a88d4de added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
417 printf("method.c: TODO: remove\n");
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
418 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
419 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
420
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
421 //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
422 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
423 if(!doc) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
424 // TODO: free stuff
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
425 sn->error = DAV_ERROR;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
426 return NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
427 }
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 xmlNode *xml_root = xmlDocGetRootElement(doc);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
430 xmlNode *node = xml_root->children;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
431 while(node) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
432 if(node->type == XML_ELEMENT_NODE) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
433 if(xstreq(node->name, "response")) {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
434 parse_response_tag(root, node);
33
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 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
437 node = node->next;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
438 }
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
439 xmlFreeDoc(doc);
33
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 return root;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
442 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
443
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
444 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
445 // create resource
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
446 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
447 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
448 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
449 if(!response->crypto_key) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
450 // TODO: error
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
451 fprintf(stderr, "encrypted resource without key\n");
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
452 return NULL;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
453 }
147
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
454 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
455 if(!name) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
456 // TODO: error
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
457 fprintf(stderr, "decrypted name is null\n");
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
458 return NULL;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
459 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
460 } else {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
461 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
462 int nlen = 0;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
463 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
464 sn->handle,
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
465 resname.ptr,
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
466 resname.length,
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
467 &nlen);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
468 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
469 curl_free(uname);
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
137
01cb9aabff05 fixed horrible bugs, davql hopefully just works now (without order by yet)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
472 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
473 DavResource *res = NULL;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
474 if(parent_path) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
475 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
476 } else {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
477 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
478 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
479 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
480
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
481 add_properties(res, response);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
482 return res;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
483 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
484
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
485 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
486 res->iscollection = response->iscollection;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
487
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
488 // add properties
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
489 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
490 xmlNode *prop = elm->data;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
491
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
492 // TODO: add xml data instead of a string
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
493 char *text = util_xml_get_text(prop);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
494 if(text) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
495 resource_add_property(res, (char*)prop->ns->href, (char*)prop->name, text);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
496 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
497 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
498
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
499 set_davprops(res);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
500 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
501
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
502 int parse_response_tag(DavResource *resource, xmlNode *node) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
503 DavSession *sn = resource->session;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
504
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
505 //DavResource *res = resource;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
506 DavResource *res = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
507 char *href = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
508 UcxList *properties = NULL; // xmlNode list
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
509 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
510 char *crypto_key = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
511
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
512 int iscollection = 0; // TODO: remove
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
513
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
514 node = node->children;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
515 while(node) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
516 if(node->type == XML_ELEMENT_NODE) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
517 if(xstreq(node->name, "href")) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
518 xmlNode *href_node = node->children;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
519 if(href_node->type != XML_TEXT_NODE) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
520 // error
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
521 sn->error = DAV_ERROR;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
522 return 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
523 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
524 //char *href = (char*)href_node->content;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
525 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
526
66
f8c1f685e08e some bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
527 sstr_t href_s = sstr(util_url_decode(resource->session, href));
f8c1f685e08e some bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
528 sstr_t href_r = sstr(util_url_decode(resource->session, resource->href));
60
cdca2eef48ee fixed propfind response parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
529 if(!sstrcmp(href_s, href_r)) {
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
530 res = resource;
60
cdca2eef48ee fixed propfind response parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
531 } else if(href_s.length == href_r.length + 1) {
cdca2eef48ee fixed propfind response parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
532 if(href_s.ptr[href_s.length-1] == '/') {
cdca2eef48ee fixed propfind response parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
533 href_s.length--;
cdca2eef48ee fixed propfind response parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
534 if(!sstrcmp(href_s, href_r)) {
cdca2eef48ee fixed propfind response parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
535 res = resource;
cdca2eef48ee fixed propfind response parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
536 }
cdca2eef48ee fixed propfind response parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
537 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
538 }
66
f8c1f685e08e some bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
539
f8c1f685e08e some bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
540 free(href_s.ptr);
f8c1f685e08e some bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
541 free(href_r.ptr);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
542 } else if(xstreq(node->name, "propstat")) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
543 xmlNode *n = node->children;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
544 xmlNode *prop_node = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
545 int ok = 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
546 // get the status code
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
547 while(n) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
548 if(n->type == XML_ELEMENT_NODE) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
549 if(xstreq(n->name, "prop")) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
550 prop_node = n;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
551 } else if(xstreq(n->name, "status")) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
552 xmlNode *status_node = n->children;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
553 if(status_node->type != XML_TEXT_NODE) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
554 sn->error = DAV_ERROR;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
555 return 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
556 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
557 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
558 if(status_str.length < 13) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
559 sn->error = DAV_ERROR;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
560 return 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
561 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
562 status_str = sstrsubsl(status_str, 9, 3);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
563 if(!sstrcmp(status_str, S("200"))) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
564 ok = 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
565 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
566 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
567 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
568 n = n->next;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
569 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
570 // if status is ok, get all properties
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
571 if(ok) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
572 n = prop_node->children;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
573 while(n) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
574 if(n->type == XML_ELEMENT_NODE) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
575 properties = ucx_list_append(properties, n);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
576 if(xstreq(n->name, "resourcetype")) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
577 xmlNode *rsnode = n->children;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
578 if(rsnode && rsnode->type == XML_ELEMENT_NODE) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
579 // TODO: this is a ugly lazy hack
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
580 //resource_add_property(res, "DAV:", (char*)n->name, "collection");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
581 iscollection = 1;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
582 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
583 } else if(xstreq(n->ns->href, DAV_NS)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
584 if(xstreq(n->name, "crypto-name")) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
585 crypto_name = util_xml_get_text(n);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
586 } else if(xstreq(n->name, "crypto-key")) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
587 crypto_key = util_xml_get_text(n);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
588 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
589 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
590 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
591 n = n->next;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
592 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
593 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
594 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
595 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
596
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
597 node = node->next;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
598 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
599
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
600 if(!res) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
601 // create new resource object
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
602 char *name = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
603 if(DAV_DECRYPT_NAME(sn) && crypto_name) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
604 if(!crypto_key) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
605 // TODO: error
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
606 fprintf(stderr, "encrypted resource without key\n");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
607 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
608 name = util_decrypt_str(sn, crypto_name, crypto_key);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
609 if(!name) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
610 // TODO: error
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
611 fprintf(stderr, "decrypted name is null\n");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
612 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
613 } else {
44
e4e23a88d4de added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
614 sstr_t resname = sstr(util_resource_name(href));
e4e23a88d4de added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
615 int nlen = 0;
e4e23a88d4de added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
616 char *uname = curl_easy_unescape(
e4e23a88d4de added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
617 sn->handle,
e4e23a88d4de added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
618 resname.ptr,
e4e23a88d4de added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
619 resname.length,
e4e23a88d4de added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
620 &nlen);
e4e23a88d4de added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
621 name = dav_session_strdup(sn, uname);
e4e23a88d4de added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
622 curl_free(uname);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
623 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
624
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
625 href = dav_session_strdup(sn, href);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
626 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
627
e4e23a88d4de added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
628 dav_session_free(sn, name);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
629 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
630 res->iscollection = iscollection;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
631
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
632 // add properties
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
633 UCX_FOREACH(elm, properties) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
634 xmlNode *prop = elm->data;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
635
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
636 // TODO: add xml data instead of a string
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
637 char *text = util_xml_get_text(prop);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
638 if(text) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
639 resource_add_property(res, (char*)prop->ns->href, (char*)prop->name, text);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
640 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
641 }
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
642 ucx_list_free(properties);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
643
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
644 set_davprops(res);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
645 if(res != resource) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
646 resource_add_child(resource, res);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
647 }
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 return 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
650 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
651
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
652 void set_davprops(DavResource *res) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
653 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
654 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
655 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
656 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
657
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
658 res->contenttype = ct;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
659 if(cl) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
660 char *end = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
661 res->contentlength = strtoull(cl, &end, 0);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
662 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
663 res->creationdate = util_parse_creationdate(cd);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
664 res->lastmodified = util_parse_lastmodified(lm);
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
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
668 /* ----------------------------- PROPPATCH ----------------------------- */
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 CURLcode do_proppatch_request(
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
671 CURL *handle,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
672 UcxBuffer *request,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
673 UcxBuffer *response)
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 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPPATCH");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
676
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
677 struct curl_slist *headers = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
678 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
679 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
680
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
681 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
682 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
683 curl_easy_setopt(handle, CURLOPT_READDATA, request);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
684 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
685
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
686 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
687 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
688
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
689 ucx_buffer_seek(request, 0, SEEK_SET);
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
690 CURLcode ret = curl_easy_perform(handle);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
691 curl_slist_free_all(headers);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
692 return ret;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
693 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
694
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
695 UcxBuffer* create_proppatch_request(DavResourceData *data) {
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
696 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
697 sstr_t s;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
698
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
699 UcxMap *namespaces = ucx_map_new(8);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
700 char prefix[8];
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
701 int pfxnum = 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
702 UCX_FOREACH(elm, data->set) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
703 DavProperty *p = elm->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
704 if(strcmp(p->ns->name, "DAV:")) {
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
705 snprintf(prefix, 8, "x%d", pfxnum++);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
706 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
707 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
708 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
709 UCX_FOREACH(elm, data->remove) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
710 DavProperty *p = elm->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
711 if(strcmp(p->ns->name, "DAV:")) {
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
712 snprintf(prefix, 8, "x%d", pfxnum++);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
713 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
714 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
715 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
716
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
717 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
718 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
719
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
720 // write root element and namespaces
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
721 s = S("<D:propertyupdate xmlns:D=\"DAV:\"");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
722 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
723 UcxMapIterator mapi = ucx_map_iterator(namespaces);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
724 UcxKey key;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
725 char *pfxval;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
726 UCX_MAP_FOREACH(key, pfxval, mapi) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
727 s = S(" xmlns:");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
728 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
729 s = sstr(pfxval);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
730 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
731 s = S("=\"");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
732 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
733 s = sstrn(key.data, key.len);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
734 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
735 s = S("\"");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
736 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
737 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
738 s = S(">\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
739 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
740
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
741 if(data->set) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
742 s = S("<D:set>\n<D:prop>\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
743 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
744 UCX_FOREACH(elm, data->set) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
745 DavProperty *property = elm->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
746 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
747
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
748 s = S("<");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
749 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
750 s = sstr(prefix);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
751 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
752 s = S(":");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
753 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
754 s = sstr(property->name);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
755 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
756 s = S(">");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
757 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
758 s = sstr(property->value);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
759 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
760 s = S("</");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
761 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
762 s = sstr(prefix);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
763 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
764 s = S(":");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
765 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
766 s = sstr(property->name);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
767 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
768 s = S(">\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
769 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
770 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
771 s = S("</D:prop>\n</D:set>\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
772 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
773 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
774 if(data->remove) {
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
775 s = S("<D:remove>\n<D:prop>\n");
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
776 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
777 UCX_FOREACH(elm, data->remove) {
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
778 DavProperty *property = elm->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
779 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
780
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
781 s = S("<");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
782 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
783 s = sstr(prefix);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
784 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
785 s = S(":");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
786 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
787 s = sstr(property->name);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
788 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
789 s = S(" />\n");
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
790 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
791 }
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
792 s = S("</D:prop>\n</D:remove>\n");
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
793 ucx_buffer_write(s.ptr, 1, s.length, buf);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
794 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
795
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
796 s = S("</D:propertyupdate>\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
797 ucx_buffer_write(s.ptr, 1, s.length, buf);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
798
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
799 return buf;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
800 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
801
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
802 UcxBuffer* create_crypto_proppatch_request(DavSession *sn, DavKey *key, char *name, char *hash) {
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
803 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
804 sstr_t s;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
805
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
806 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
807 ucx_buffer_write(s.ptr, 1, s.length, buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
808
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
809 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
810 ucx_buffer_write(s.ptr, 1, s.length, buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
811
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
812 s = S("<D:set>\n<D:prop>\n");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
813 ucx_buffer_write(s.ptr, 1, s.length, buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
814
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
815 if(DAV_ENCRYPT_NAME(sn)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
816 s = S("<idav:crypto-name>");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
817 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
818 char *crname = aes_encrypt(name, strlen(name), key);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
819 ucx_buffer_puts(buf, crname);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
820 free(crname);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
821 s = S("</idav:crypto-name>\n");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
822 ucx_buffer_write(s.ptr, 1, s.length, buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
823 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
824
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
825 s = S("<idav:crypto-key>");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
826 ucx_buffer_write(s.ptr, 1, s.length, buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
827 ucx_buffer_puts(buf, key->name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
828 s = S("</idav:crypto-key>\n");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
829 ucx_buffer_write(s.ptr, 1, s.length, buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
830
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
831 if(hash) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
832 s = S("<idav:crypto-hash>");
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
833 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
834 ucx_buffer_puts(buf, hash);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
835 s = S("</idav:crypto-hash>\n");
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
836 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
837 }
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
838
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
839 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
840 ucx_buffer_write(s.ptr, 1, s.length, buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
841
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
842 return buf;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
843 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
844
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
845 /* ----------------------------- PUT ----------------------------- */
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
846
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
847 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
848 return s*n;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
849 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
850
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
851 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
852 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
853 curl_easy_setopt(handle, CURLOPT_PUT, 1L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
854 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
855
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
856 // clear headers
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
857 struct curl_slist *headers = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
858 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
859
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
860 UcxBuffer *buf = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
861 if(!read_func) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
862 buf = ucx_buffer_new(data, length, 0);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
863 buf->size = length;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
864 data = buf;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
865 read_func = (dav_read_func)ucx_buffer_read;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
866 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
867 } else if(length == 0) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
868 headers = curl_slist_append(headers, "Transfer-Encoding: chunked");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
869 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
870 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
871 } else {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
872 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
873 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
874
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
875 curl_easy_setopt(handle, CURLOPT_READFUNCTION, read_func);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
876 curl_easy_setopt(handle, CURLOPT_READDATA, data);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
877
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
878 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
879 curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
880
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
881 CURLcode ret = curl_easy_perform(handle);
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
882 curl_slist_free_all(headers);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
883 if(buf) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
884 ucx_buffer_free(buf);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
885 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
886 return ret;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
887 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
888
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
889 CURLcode do_delete_request(CURL *handle, UcxBuffer *response) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
890 struct curl_slist *headers = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
891 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
892
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
893 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "DELETE");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
894 curl_easy_setopt(handle, CURLOPT_PUT, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
895 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
896
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
897 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
898 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
899
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
900 CURLcode ret = curl_easy_perform(handle);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
901 return ret;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
902 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
903
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
904 CURLcode do_mkcol_request(CURL *handle) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
905 struct curl_slist *headers = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
906 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
907
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
908 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "MKCOL");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
909 curl_easy_setopt(handle, CURLOPT_PUT, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
910 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
911
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
912 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
913 curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
914
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
915 CURLcode ret = curl_easy_perform(handle);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
916 return ret;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
917 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
918
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
919
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
920 CURLcode do_head_request(CURL *handle) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
921 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "HEAD");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
922 curl_easy_setopt(handle, CURLOPT_PUT, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
923 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
924 curl_easy_setopt(handle, CURLOPT_NOBODY, 1L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
925
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
926 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
927 curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
928
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
929 CURLcode ret = curl_easy_perform(handle);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
930 curl_easy_setopt(handle, CURLOPT_NOBODY, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
931 return ret;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
932 }

mercurial