Fri, 17 Apr 2015 16:26:53 +0200
fixed static variable fail
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" |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include "davql.h" |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
36 | #include "crypto.h" |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
37 | #include "session.h" |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #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
|
40 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | /* ----------------------------- PROPFIND ----------------------------- */ |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | CURLcode do_propfind_request( |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | CURL *handle, |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | UcxBuffer *request, |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | UcxBuffer *response) |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPFIND"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | struct curl_slist *headers = NULL; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | 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
|
52 | headers = curl_slist_append(headers, "Depth: 1"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | 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
|
59 | curl_easy_setopt(handle, CURLOPT_READDATA, request); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | 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
|
63 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | ucx_buffer_seek(request, 0, SEEK_SET); |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
66 | CURLcode ret = curl_easy_perform(handle); |
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
67 | curl_slist_free_all(headers); |
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
68 | return ret; |
33
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 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | UcxBuffer* create_allprop_propfind_request() { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | UcxBuffer *buf = ucx_buffer_new(NULL, 512, 0); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | sstr_t s; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | 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
|
76 | 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
|
77 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | s = S("<D:propfind xmlns:D=\"DAV:\">\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | 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
|
80 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | s = S("<D:allprop/></D:propfind>\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | 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
|
83 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | return buf; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
87 | UcxBuffer* create_propfind_request(DavSession *sn, UcxList *properties) { |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | UcxBuffer *buf = ucx_buffer_new(NULL, 512, 0); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | sstr_t s; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
91 | int add_crypto_name = 1; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
92 | int add_crypto_key = 1; |
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; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
110 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
111 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
112 | } |
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 | DavNamespace idav_ns; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
115 | 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
|
116 | idav_ns.prefix = "idav"; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
117 | idav_ns.name = DAV_NS; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
118 | 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
|
119 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | s = S("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | // write root element and namespaces |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | s = S("<D:propfind xmlns:D=\"DAV:\""); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | 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
|
127 | UcxMapIterator mapi = ucx_map_iterator(namespaces); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | UcxKey key; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | DavNamespace *ns; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | UCX_MAP_FOREACH(key, ns, mapi) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | s = S(" xmlns:"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | 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
|
133 | s = sstr(ns->prefix); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | 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
|
135 | s = S("=\""); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | s = sstr(ns->name); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | s = S("\""); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | s = S(">\n"); |
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 | // default properties |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | s = S("<D:prop>\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | 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
|
148 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | s = S("<D:creationdate />\n<D:getlastmodified />\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:getcontentlength />\n<D:getcontenttype />\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:resourcetype />\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 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
158 | // crypto properties |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
159 | if(DAV_CRYPTO(sn)) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
160 | if(add_crypto_name) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
161 | ucx_buffer_putc(buf, '<'); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
162 | ucx_buffer_puts(buf, crypto_ns); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
163 | s = S(":crypto-name />\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
164 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
165 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
166 | if(add_crypto_key) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
167 | ucx_buffer_putc(buf, '<'); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
168 | ucx_buffer_puts(buf, crypto_ns); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
169 | s = S(":crypto-key />\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
170 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
171 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
172 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
173 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | // extra properties |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | UCX_FOREACH(elm, properties) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | DavProperty *prop = elm->data; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | s = S("<"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | 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
|
179 | s = sstr(prop->ns->prefix); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | 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
|
181 | s = S(":"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | 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
|
183 | s = sstr(prop->name); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | 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
|
185 | s = S(" />\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | 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
|
187 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | // end |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | s = S("</D:prop>\n</D:propfind>\n"); |
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 | |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
193 | ucx_map_free(namespaces); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | return buf; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
197 | UcxBuffer* create_basic_propfind_request() { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
198 | UcxBuffer *buf = ucx_buffer_new(NULL, 512, 0); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
199 | sstr_t s; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
200 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
201 | 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
|
202 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
203 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
204 | s = S("<D:propfind xmlns:D=\"DAV:\" xmlns:i=\""); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
205 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
206 | s = S(DAV_NS); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
207 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
208 | s = S("\" >\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
209 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
210 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
211 | // properties |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
212 | s = S("<D:prop>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
213 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
214 | s = S("<D:resourcetype />\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
215 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
216 | s = S("<i:crypto-key />\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
217 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
218 | s = S("<i:crypto-name />\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
219 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
220 | s = S("</D:prop>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
221 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
222 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
223 | // end |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
224 | s = S("</D:propfind>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
225 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
226 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
227 | return buf; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
228 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
229 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | DavResource* parse_propfind_response(DavSession *sn, DavResource *root, UcxBuffer *response, DavQOp *cond, size_t len) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | char *url = NULL; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | 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
|
233 | if(!root) { |
44
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
234 | printf("method.c: TODO: remove\n"); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
235 | 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
|
236 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237 | |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
238 | //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
|
239 | 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
|
240 | if(!doc) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | // TODO: free stuff |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | sn->error = DAV_ERROR; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | return NULL; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | xmlNode *xml_root = xmlDocGetRootElement(doc); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | xmlNode *node = xml_root->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | while(node) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | if(node->type == XML_ELEMENT_NODE) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | if(xstreq(node->name, "response")) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | parse_response_tag(root, node, cond, len); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | node = node->next; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255 | } |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
256 | xmlFreeDoc(doc); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258 | return root; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | int parse_response_tag(DavResource *resource, xmlNode *node, DavQOp *cond, size_t clen) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
262 | DavSession *sn = resource->session; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
263 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
264 | //DavResource *res = resource; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
265 | DavResource *res = NULL; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
266 | char *href = NULL; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
267 | UcxList *properties = NULL; // xmlNode list |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
268 | 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
|
269 | char *crypto_key = NULL; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
270 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
271 | int iscollection = 0; // TODO: remove |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
272 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | node = node->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | while(node) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | if(node->type == XML_ELEMENT_NODE) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
276 | if(xstreq(node->name, "href")) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
277 | xmlNode *href_node = node->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | if(href_node->type != XML_TEXT_NODE) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | // error |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
280 | sn->error = DAV_ERROR; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281 | return 1; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
283 | //char *href = (char*)href_node->content; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
284 | 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
|
285 | |
66 | 286 | sstr_t href_s = sstr(util_url_decode(resource->session, href)); |
287 | 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
|
288 | if(!sstrcmp(href_s, href_r)) { |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289 | res = resource; |
60
cdca2eef48ee
fixed propfind response parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
290 | } 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
|
291 | if(href_s.ptr[href_s.length-1] == '/') { |
cdca2eef48ee
fixed propfind response parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
292 | href_s.length--; |
cdca2eef48ee
fixed propfind response parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
293 | if(!sstrcmp(href_s, href_r)) { |
cdca2eef48ee
fixed propfind response parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
294 | res = resource; |
cdca2eef48ee
fixed propfind response parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
295 | } |
cdca2eef48ee
fixed propfind response parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
296 | } |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
297 | } |
66 | 298 | |
299 | free(href_s.ptr); | |
300 | free(href_r.ptr); | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
301 | } else if(xstreq(node->name, "propstat")) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
302 | xmlNode *n = node->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
303 | xmlNode *prop_node = NULL; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
304 | int ok = 0; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
305 | // get the status code |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
306 | while(n) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
307 | if(n->type == XML_ELEMENT_NODE) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
308 | if(xstreq(n->name, "prop")) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
309 | prop_node = n; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
310 | } else if(xstreq(n->name, "status")) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
311 | xmlNode *status_node = n->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
312 | if(status_node->type != XML_TEXT_NODE) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
313 | sn->error = DAV_ERROR; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
314 | return 1; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
315 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
316 | 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
|
317 | if(status_str.length < 13) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
318 | sn->error = DAV_ERROR; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
319 | return 1; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
320 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
321 | status_str = sstrsubsl(status_str, 9, 3); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
322 | if(!sstrcmp(status_str, S("200"))) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
323 | ok = 1; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
324 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
325 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
326 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
327 | n = n->next; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
328 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
329 | // if status is ok, get all properties |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
330 | if(ok) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
331 | n = prop_node->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
332 | while(n) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
333 | if(n->type == XML_ELEMENT_NODE) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
334 | properties = ucx_list_append(properties, n); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
335 | if(xstreq(n->name, "resourcetype")) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
336 | xmlNode *rsnode = n->children; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
337 | if(rsnode && rsnode->type == XML_ELEMENT_NODE) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
338 | // TODO: this is a ugly lazy hack |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
339 | //resource_add_property(res, "DAV:", (char*)n->name, "collection"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
340 | iscollection = 1; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
341 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
342 | } else if(xstreq(n->ns->href, DAV_NS)) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
343 | if(xstreq(n->name, "crypto-name")) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
344 | crypto_name = util_xml_get_text(n); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
345 | } else if(xstreq(n->name, "crypto-key")) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
346 | crypto_key = util_xml_get_text(n); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
347 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
348 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
349 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
350 | n = n->next; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
351 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
352 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
353 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
354 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
355 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
356 | node = node->next; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
357 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
358 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
359 | if(!res) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
360 | // create new resource object |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
361 | char *name = NULL; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
362 | if(DAV_DECRYPT_NAME(sn) && crypto_name) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
363 | if(!crypto_key) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
364 | // TODO: error |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
365 | fprintf(stderr, "encrypted resource without key\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
366 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
367 | name = util_decrypt_str(sn, crypto_name, crypto_key); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
368 | if(!name) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
369 | // TODO: error |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
370 | fprintf(stderr, "decrypted name is null\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
371 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
372 | } else { |
44
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
373 | sstr_t resname = sstr(util_resource_name(href)); |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
374 | int nlen = 0; |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
375 | char *uname = curl_easy_unescape( |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
376 | sn->handle, |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
377 | resname.ptr, |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
378 | resname.length, |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
379 | &nlen); |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
380 | name = dav_session_strdup(sn, uname); |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
381 | curl_free(uname); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
382 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
383 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
384 | href = dav_session_strdup(sn, href); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
385 | 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
|
386 | |
e4e23a88d4de
added missing url decode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
387 | dav_session_free(sn, name); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
388 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
389 | res->iscollection = iscollection; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
390 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
391 | // add properties |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
392 | UCX_FOREACH(elm, properties) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
393 | xmlNode *prop = elm->data; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
394 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
395 | // TODO: add xml data instead of a string |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
396 | char *text = util_xml_get_text(prop); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
397 | if(text) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
398 | 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
|
399 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
400 | } |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
401 | ucx_list_free(properties); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
402 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
403 | set_davprops(res); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
404 | if(res != resource) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
405 | if(clen > 0) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
406 | if(!condition_eval(res, cond, clen)) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
407 | // skip resource |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
408 | return 0; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
409 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
410 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
411 | resource_add_child(resource, res); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
412 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
413 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
414 | return 0; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
415 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
416 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
417 | void set_davprops(DavResource *res) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
418 | 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
|
419 | 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
|
420 | 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
|
421 | 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
|
422 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
423 | res->contenttype = ct; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
424 | if(cl) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
425 | char *end = NULL; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
426 | res->contentlength = strtoull(cl, &end, 0); |
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 | res->creationdate = util_parse_creationdate(cd); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
429 | res->lastmodified = util_parse_lastmodified(lm); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
430 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
431 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
432 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
433 | /* ----------------------------- PROPPATCH ----------------------------- */ |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
434 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
435 | CURLcode do_proppatch_request( |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
436 | CURL *handle, |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
437 | UcxBuffer *request, |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
438 | UcxBuffer *response) |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
439 | { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
440 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPPATCH"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
441 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
442 | struct curl_slist *headers = NULL; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
443 | 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
|
444 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
445 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
446 | curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
447 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
448 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
449 | 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
|
450 | curl_easy_setopt(handle, CURLOPT_READDATA, request); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
451 | curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
452 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
453 | 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
|
454 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
455 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
456 | ucx_buffer_seek(request, 0, SEEK_SET); |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
457 | CURLcode ret = curl_easy_perform(handle); |
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
458 | curl_slist_free_all(headers); |
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
459 | return ret; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
460 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
461 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
462 | UcxBuffer* create_proppatch_request(DavResourceData *data) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
463 | UcxBuffer *buf = ucx_buffer_new(NULL, 512, 0); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
464 | sstr_t s; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
465 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
466 | UcxMap *namespaces = ucx_map_new(8); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
467 | char prefix[8]; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
468 | int pfxnum = 0; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
469 | UCX_FOREACH(elm, data->set) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
470 | DavProperty *p = elm->data; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
471 | if(strcmp(p->ns->name, "DAV:")) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
472 | snprintf(prefix, 8, "x%d\0", pfxnum++); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
473 | 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
|
474 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
475 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
476 | UCX_FOREACH(elm, data->remove) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
477 | DavProperty *p = elm->data; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
478 | if(strcmp(p->ns->name, "DAV:")) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
479 | snprintf(prefix, 8, "x%d\0", pfxnum++); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
480 | 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
|
481 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
482 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
483 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
484 | 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
|
485 | 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
|
486 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
487 | // write root element and namespaces |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
488 | s = S("<D:propertyupdate xmlns:D=\"DAV:\""); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
489 | 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
|
490 | UcxMapIterator mapi = ucx_map_iterator(namespaces); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
491 | UcxKey key; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
492 | char *pfxval; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
493 | UCX_MAP_FOREACH(key, pfxval, mapi) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
494 | s = S(" xmlns:"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
495 | 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
|
496 | s = sstr(pfxval); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
497 | 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
|
498 | s = S("=\""); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
499 | 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
|
500 | s = sstrn(key.data, key.len); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
501 | 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
|
502 | s = S("\""); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
503 | 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
|
504 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
505 | s = S(">\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
506 | 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
|
507 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
508 | if(data->set) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
509 | s = S("<D:set>\n<D:prop>\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
510 | 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
|
511 | UCX_FOREACH(elm, data->set) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
512 | DavProperty *property = elm->data; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
513 | 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
|
514 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
515 | s = S("<"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
516 | 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
|
517 | s = sstr(prefix); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
518 | 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
|
519 | s = S(":"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
520 | 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
|
521 | s = sstr(property->name); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
522 | 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
|
523 | s = S(">"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
524 | 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
|
525 | s = sstr(property->value); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
526 | 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
|
527 | s = S("</"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
528 | 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
|
529 | s = sstr(prefix); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
530 | 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
|
531 | s = S(":"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
532 | 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
|
533 | s = sstr(property->name); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
534 | 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
|
535 | s = S(">\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
536 | 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
|
537 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
538 | s = S("</D:prop>\n</D:set>\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
539 | 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
|
540 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
541 | if(data->remove) { |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
542 | 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
|
543 | 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
|
544 | UCX_FOREACH(elm, data->remove) { |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
545 | DavProperty *property = elm->data; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
546 | 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
|
547 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
548 | s = S("<"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
549 | 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
|
550 | s = sstr(prefix); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
551 | 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
|
552 | s = S(":"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
553 | 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
|
554 | s = sstr(property->name); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
555 | 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
|
556 | s = S(" />\n"); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
557 | 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
|
558 | } |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
559 | 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
|
560 | 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
|
561 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
562 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
563 | s = S("</D:propertyupdate>\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
564 | 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
|
565 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
566 | return buf; |
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 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
569 | UcxBuffer* create_crypto_proppatch_request(DavSession *sn, DavKey *key, char *name) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
570 | UcxBuffer *buf = ucx_buffer_new(NULL, 512, 0); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
571 | sstr_t s; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
572 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
573 | 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
|
574 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
575 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
576 | 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
|
577 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
578 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
579 | s = S("<D:set>\n<D:prop>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
580 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
581 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
582 | if(DAV_ENCRYPT_NAME(sn)) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
583 | s = S("<idav:crypto-name>"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
584 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
585 | char *crname = aes_encrypt(name, key); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
586 | ucx_buffer_puts(buf, crname); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
587 | free(crname); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
588 | s = S("</idav:crypto-name>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
589 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
590 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
591 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
592 | s = S("<idav:crypto-key>"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
593 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
594 | ucx_buffer_puts(buf, key->name); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
595 | s = S("</idav:crypto-key>\n"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
596 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
597 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
598 | 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
|
599 | ucx_buffer_write(s.ptr, 1, s.length, buf); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
600 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
601 | return buf; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
602 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
603 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
604 | /* ----------------------------- PUT ----------------------------- */ |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
605 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
606 | 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
|
607 | return s*n; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
608 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
609 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
610 | 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
|
611 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
612 | curl_easy_setopt(handle, CURLOPT_PUT, 1L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
613 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
614 | curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
615 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
616 | // clear headers |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
617 | struct curl_slist *headers = NULL; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
618 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
619 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
620 | UcxBuffer *buf = NULL; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
621 | if(!read_func) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
622 | buf = ucx_buffer_new(data, length, 0); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
623 | buf->size = length; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
624 | data = buf; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
625 | read_func = (dav_read_func)ucx_buffer_read; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
626 | 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
|
627 | } else if(length == 0) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
628 | headers = curl_slist_append(headers, "Transfer-Encoding: chunked"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
629 | 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
|
630 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
631 | } else { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
632 | 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
|
633 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
634 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
635 | curl_easy_setopt(handle, CURLOPT_READFUNCTION, read_func); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
636 | curl_easy_setopt(handle, CURLOPT_READDATA, data); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
637 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
638 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
639 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
640 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
641 | CURLcode ret = curl_easy_perform(handle); |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
642 | curl_slist_free_all(headers); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
643 | if(buf) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
644 | ucx_buffer_free(buf); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
645 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
646 | return ret; |
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 | CURLcode do_delete_request(CURL *handle, UcxBuffer *response) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
650 | struct curl_slist *headers = NULL; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
651 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
652 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
653 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "DELETE"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
654 | curl_easy_setopt(handle, CURLOPT_PUT, 0L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
655 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
656 | curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); |
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 | 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
|
659 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
660 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
661 | CURLcode ret = curl_easy_perform(handle); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
662 | return ret; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
663 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
664 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
665 | CURLcode do_mkcol_request(CURL *handle) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
666 | struct curl_slist *headers = NULL; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
667 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
668 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
669 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "MKCOL"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
670 | curl_easy_setopt(handle, CURLOPT_PUT, 0L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
671 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
672 | curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
673 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
674 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
675 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); |
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 | CURLcode ret = curl_easy_perform(handle); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
678 | return ret; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
679 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
680 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
681 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
682 | CURLcode do_head_request(CURL *handle) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
683 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "HEAD"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
684 | curl_easy_setopt(handle, CURLOPT_PUT, 0L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
685 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
686 | curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
687 | curl_easy_setopt(handle, CURLOPT_NOBODY, 1L); |
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 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
690 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
691 | |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
692 | CURLcode ret = curl_easy_perform(handle); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
693 | curl_easy_setopt(handle, CURLOPT_NOBODY, 0L); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
694 | return ret; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
695 | } |