libidav/resource.c

Thu, 21 Sep 2017 12:53:29 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 21 Sep 2017 12:53:29 +0200
branch
v1.0
changeset 312
bebe0b436c84
parent 280
6d8784bee427
child 298
755b8198b071
permissions
-rw-r--r--

dav 1.0.1 update

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 *
185
cd42cccee550 updated copyright notice
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
4 * Copyright 2016 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>
182
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
32 #include <stdbool.h>
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <libxml/tree.h>
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "utils.h"
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
36 #include "session.h"
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include "methods.h"
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
38 #include "crypto.h"
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 #include "ucx/buffer.h"
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #include "ucx/utils.h"
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 #include "resource.h"
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
43 #include "davqlexec.h"
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 #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
46
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 DavResource* dav_resource_new(DavSession *sn, char *path) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
48 //char *href = util_url_path(url);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
49 //DavResource *res = dav_resource_new_href(sn, href);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
50 char *parent = util_parent_path(path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
51 char *name = util_resource_name(path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
52 char *href = dav_session_create_plain_href(sn, path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
53
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
54 DavResource *res = dav_resource_new_full(sn, parent, name, href);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
55 free(parent);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 return res;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58
42
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
59 DavResource* dav_resource_new_child(DavSession *sn, DavResource *parent, char *name) {
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
60 char *path = util_concat_path(parent->path, name);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
61 char *href = dav_session_create_plain_href(sn, path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
62 DavResource *res = dav_resource_new_full(sn, parent->path, name, href);
42
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
63 free(path);
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
64 return res;
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
65 }
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
66
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
68 DavResource* dav_resource_new_href(DavSession *sn, char *href) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
69 DavResource *res = ucx_mempool_calloc(sn->mp, 1, sizeof(DavResource));
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 res->session = sn;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 // set name, path and href
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 resource_set_info(res, href);
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 // initialize resource data
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 res->data = resource_data_new(sn);
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 return res;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
81 DavResource* dav_resource_new_full(DavSession *sn, char *parent_path, char *name, char *href) {
268
2610eecfc5e5 adds resource name validation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
82 sstr_t n = sstr(name);
2610eecfc5e5 adds resource name validation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
83 // the name must not contain path separators
280
6d8784bee427 fixes dav_resource_new_full
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
84 if(n.length > 0) {
6d8784bee427 fixes dav_resource_new_full
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
85 for(int i=0;i<n.length-1;i++) {
6d8784bee427 fixes dav_resource_new_full
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
86 char c = n.ptr[i];
6d8784bee427 fixes dav_resource_new_full
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
87 if(c == '/' || c == '\\') {
6d8784bee427 fixes dav_resource_new_full
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
88 n = sstr(util_resource_name(href));
6d8784bee427 fixes dav_resource_new_full
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
89 break;
6d8784bee427 fixes dav_resource_new_full
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
90 }
268
2610eecfc5e5 adds resource name validation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
91 }
2610eecfc5e5 adds resource name validation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
92 }
2610eecfc5e5 adds resource name validation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
93 // remove trailing '/'
2610eecfc5e5 adds resource name validation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
94 if(n.length > 0 && n.ptr[n.length-1] == '/') {
2610eecfc5e5 adds resource name validation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
95 n.length--;
2610eecfc5e5 adds resource name validation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
96 }
2610eecfc5e5 adds resource name validation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
97
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
98 DavResource *res = ucx_mempool_calloc(sn->mp, 1, sizeof(DavResource));
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
99 res->session = sn;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
100
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
101 // set name, path and href
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
102 res->name = sstrdup_a(sn->mp->allocator, n).ptr;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
103
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
104 char *path = util_concat_path(parent_path, name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
105 res->path = dav_session_strdup(sn, path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
106
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
107 res->href = href;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
108
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
109 // initialize resource data
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
110 res->data = resource_data_new(sn);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
111
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
112 // cache href/path
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
113 if(href) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
114 dav_session_cache_path(sn, sstr(path), sstr(href));
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
115 }
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
116 free(path);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
117
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
118 return res;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
119 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
120
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
121 void resource_free_properties(DavSession *sn, UcxMap *properties) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
122 UcxMapIterator i = ucx_map_iterator(properties);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
123 char *property;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
124 UCX_MAP_FOREACH(key, property, i) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
125 dav_session_free(sn, property);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
126 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
127 ucx_map_free(properties);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
128 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
129
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
130 void dav_resource_free(DavResource *res) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
131 DavSession *sn = res->session;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
132
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
133 dav_session_free(sn, res->name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
134 dav_session_free(sn, res->path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
135 if(res->href) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
136 dav_session_free(sn, res->href);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
137 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
138
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
139 DavResourceData *data = res->data;
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
140 resource_free_properties(sn, data->properties);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
141
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
142 UCX_FOREACH(elm, data->set) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
143 DavProperty *p = elm->data;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
144 dav_session_free(sn, p->ns->name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
145 if(p->ns->prefix) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
146 dav_session_free(sn, p->ns->prefix);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
147 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
148 dav_session_free(sn, p->ns);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
149
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
150 dav_session_free(sn, p->name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
151 dav_session_free(sn, p->value);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
152 dav_session_free(sn, p);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
153 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
154
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
155 UCX_FOREACH(elm, data->remove) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
156 DavProperty *p = elm->data;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
157 dav_session_free(sn, p->ns->name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
158 if(p->ns->prefix) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
159 dav_session_free(sn, p->ns->prefix);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
160 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
161 dav_session_free(sn, p->ns);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
162
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
163 dav_session_free(sn, p->name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
164 dav_session_free(sn, p);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
165 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
166
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
167 if(!data->read && data->content) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
168 dav_session_free(sn, data->content);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
169 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
170 dav_session_free(sn, data);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
171
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
172 dav_session_free(sn, res);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
173 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
174
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
175 void dav_resource_free_all(DavResource *res) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
176 DavResource *child = res->children;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
177 dav_resource_free(res);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
178 while(child) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
179 DavResource *next = child->next;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
180 dav_resource_free_all(child);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
181 child = next;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
182 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
183 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
184
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
185 void resource_set_href(DavResource *res, sstr_t href) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
186 res->href = sstrdup_a(res->session->mp->allocator, href).ptr;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
187 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
188
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 void resource_set_info(DavResource *res, char *href_str) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 char *url_str = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 curl_easy_getinfo(res->session->handle, CURLINFO_EFFECTIVE_URL, &url_str);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 sstr_t name = sstr(util_resource_name(href_str));
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 sstr_t href = sstr(href_str);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 sstr_t base_href = sstr(util_url_path(res->session->base_url));
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 sstr_t path = sstrsubs(href, base_href.length - 1);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
198 UcxAllocator *a = res->session->mp->allocator;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
199 CURL *handle = res->session->handle;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
200
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
201 int nlen = 0;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
202 char *uname = curl_easy_unescape(handle, name.ptr, name.length , &nlen);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
203 int plen = 0;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
204 char *upath = curl_easy_unescape(handle, path.ptr, path.length, &plen);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
205
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
206 res->name = sstrdup_a(a, sstrn(uname, nlen)).ptr;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 res->href = sstrdup_a(a, href).ptr;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
208 res->path = sstrdup_a(a, sstrn(upath, plen)).ptr;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
209
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
210 curl_free(uname);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
211 curl_free(upath);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 DavResourceData* resource_data_new(DavSession *sn) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 DavResourceData *data = ucx_mempool_malloc(
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 sn->mp,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 sizeof(DavResourceData));
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 if(!data) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 return NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 }
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
221 data->properties = ucx_map_new_a(sn->mp->allocator, 32);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 data->set = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 data->remove = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 data->content = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 data->read = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 data->length = 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 return data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
230 char* dav_resource_get_href(DavResource *resource) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
231 if(!resource->href) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
232 resource->href = dav_session_get_href(
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
233 resource->session,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
234 resource->path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
235 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
236 return resource->href;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
237 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
238
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 void resource_add_property(DavResource *res, char *ns, char *name, char *val) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 if(!val) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 return;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 UcxKey key = dav_property_key(ns, name);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
245 sstr_t v = sstrdup_a(res->session->mp->allocator, sstr(val));
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 ucx_map_put(((DavResourceData*)res->data)->properties, key, v.ptr);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 free(key.data);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 char* resource_get_property(DavResource *res, char *ns, char *name) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 UcxKey key = dav_property_key(ns, name);
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
252 char *property = resource_get_property_k(res, key);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 free(key.data);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 return property;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
257 char* resource_get_property_k(DavResource *res, UcxKey key) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
258 DavResourceData *data = (DavResourceData*)res->data;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
259 return ucx_map_get(data->properties, key);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
260 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
261
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 UcxKey dav_property_key(char *ns, char *name) {
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
263 return dav_property_key_a(ucx_default_allocator(), ns, name);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
264 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
265
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
266 UcxKey dav_property_key_a(UcxAllocator *a, char *ns, char *name) {
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 sstr_t ns_str = sstr(ns);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 sstr_t name_str = sstr(name);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 sstr_t key;
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
271 key = sstrcat_a(a, 4, ns_str, S("\0"), name_str, S("\0"));
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 return ucx_key(key.ptr, key.length);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 void resource_add_child(DavResource *parent, DavResource *child) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280 child->next = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281 if(parent->children) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 DavResource *last = parent->children;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 while(last->next) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 last = last->next;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 last->next = child;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 child->prev = last;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 } else {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289 child->prev = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 parent->children = child;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 child->parent = parent;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
295 static int resource_cmp(DavResource *res1, DavResource *res2, DavOrderCriterion *cr) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
296 if(!(res1 && res2)) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
297 return 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
298 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
299
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
300 int ret;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
301 if(cr->type == 0) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
302 switch(cr->column.resprop) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
303 case DAVQL_RES_NAME: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
304 ret = strcmp(res1->name, res2->name);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
305 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
306 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
307 case DAVQL_RES_PATH: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
308 ret = strcmp(res1->path, res2->path);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
309 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
310 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
311 case DAVQL_RES_HREF: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
312 ret = strcmp(res1->href, res2->href);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
313 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
314 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
315 case DAVQL_RES_CONTENTLENGTH: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
316 int c = res1->contentlength == res2->contentlength;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
317 ret = c ? 0 : (res1->contentlength < res2->contentlength?-1:1);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
318 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
319 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
320 case DAVQL_RES_CONTENTTYPE: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
321 ret = strcmp(res1->contenttype, res2->contenttype);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
322 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
323 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
324 case DAVQL_RES_CREATIONDATE: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
325 int c = res1->creationdate == res2->creationdate;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
326 ret = c ? 0 : (res1->creationdate < res2->creationdate?-1:1);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
327 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
328 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
329 case DAVQL_RES_LASTMODIFIED: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
330 int c = res1->lastmodified == res2->lastmodified;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
331 ret = c ? 0 : (res1->lastmodified < res2->lastmodified?-1:1);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
332 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
333 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
334 case DAVQL_RES_ISCOLLECTION: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
335 int c = res1->iscollection == res2->iscollection;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
336 ret = c ? 0 : (res1->iscollection < res2->iscollection?-1:1);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
337 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
338 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
339 default: ret = 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
340 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
341 } else if(cr->type == 1) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
342 char *value1 = resource_get_property_k(res1, cr->column.property);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
343 char *value2 = resource_get_property_k(res2, cr->column.property);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
344 if(!value1) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
345 ret = value2 ? -1 : 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
346 } else if(!value2) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
347 ret = value1 ? 1 : 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
348 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
349 ret = strcmp(value1, value2);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
350 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
351 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
352 return 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
353 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
354
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
355 return cr->descending ? -ret : ret;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
356 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
357
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
358 void resource_add_ordered_child(DavResource *parent, DavResource *child, UcxList *ordercr) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
359 if(!ordercr) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
360 resource_add_child(parent, child);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
361 return;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
362 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
363
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
364 child->parent = parent;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
365
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
366 if(!parent->children) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
367 child->next = NULL;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
368 child->prev = NULL;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
369 parent->children = child;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
370 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
371 DavResource *resource = parent->children;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
372 while(resource) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
373 int r = 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
374 UCX_FOREACH(elm, ordercr) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
375 DavOrderCriterion *cr = elm->data;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
376 r = resource_cmp(child, resource, cr);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
377 if(r != 0) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
378 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
379 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
380 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
381
140
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
382 if(r < 0) {
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
383 // insert child before resource
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
384 child->prev = resource->prev;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
385 child->next = resource;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
386 if(resource->prev) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
387 resource->prev->next = child;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
388 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
389 parent->children = child;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
390 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
391 resource->prev = child;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
392 break;
140
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
393 } if(!resource->next) {
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
394 // append child
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
395 child->prev = resource;
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
396 child->next = NULL;
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
397 resource->next = child;
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
398 break;
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
399 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
400 resource = resource->next;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
401 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
402 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
403 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
404 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
405
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
406 char* dav_get_property(DavResource *res, char *name) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
407 char *pns;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
408 char *pname;
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
409 dav_get_property_namespace_str(res->session->context, name, &pns, &pname);
269
c89633916e36 fixes crash when using invalid namespace prefix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
410 if(!pns || !pname) {
c89633916e36 fixes crash when using invalid namespace prefix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
411 return NULL;
c89633916e36 fixes crash when using invalid namespace prefix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
412 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
413 return dav_get_property_ns(res, pns, pname);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
414 }
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 char* dav_get_property_ns(DavResource *res, char *ns, char *name) {
269
c89633916e36 fixes crash when using invalid namespace prefix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
417 if(!ns || !name) {
c89633916e36 fixes crash when using invalid namespace prefix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
418 return NULL;
c89633916e36 fixes crash when using invalid namespace prefix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
419 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
420 char *property = resource_get_property(res, ns, name);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
421 DavResourceData *data = res->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
422 // resource_get_property only returns persistent properties
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
423 // check the remove and set list
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
424 if(property) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
425 // if the property is in the remove list, we return NULL
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
426 UCX_FOREACH(elm, data->remove) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
427 DavProperty *p = elm->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
428 if(!strcmp(p->name, name) && !strcmp(p->ns->name, ns)) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
429 return NULL;
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 // the set list contains property updates
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
434 // we return an updated property if possible
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
435 UCX_FOREACH(elm, data->set) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
436 DavProperty *p = elm->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
437 if(!strcmp(p->name, name) && !strcmp(p->ns->name, ns)) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
438 return p->value;
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 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
441 // no property update
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
442 return property;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
443 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
444
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
445 void dav_set_property(DavResource *res, char *name, char *value) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
446 char *pns;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
447 char *pname;
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
448 dav_get_property_namespace_str(res->session->context, name, &pns, &pname);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
449 dav_set_property_ns(res, pns, pname, value);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
450 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
451
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
452 void dav_set_property_ns(DavResource *res, char *ns, char *name, char *value) {
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
453 UcxAllocator *a = res->session->mp->allocator;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
454 DavResourceData *data = res->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
455
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
456 DavProperty *property = dav_session_malloc(
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
457 res->session,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
458 sizeof(DavProperty));
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
459 property->name = dav_session_strdup(res->session, name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
460 property->value = dav_session_strdup(res->session, value);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
461
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
462 DavNamespace *namespace = dav_session_malloc(
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
463 res->session,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
464 sizeof(DavNamespace));
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
465 namespace->prefix = NULL;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
466 namespace->name = dav_session_strdup(res->session, ns);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
467 property->ns = namespace;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
468
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
469 data->set = ucx_list_append_a(a, data->set, property);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
470 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
471
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
472 void dav_remove_property(DavResource *res, char *name) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
473 char *pns;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
474 char *pname;
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
475 dav_get_property_namespace_str(res->session->context, name, &pns, &pname);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
476 dav_remove_property_ns(res, pns, pname);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
477 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
478
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
479 void dav_remove_property_ns(DavResource *res, char *ns, char *name) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
480 DavResourceData *data = res->data;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
481 UcxAllocator *a = res->session->mp->allocator;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
482
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
483 DavProperty *property = dav_session_malloc(
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
484 res->session,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
485 sizeof(DavProperty));
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
486 property->name = sstrdup_a(a, sstr(name)).ptr;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
487 property->value = NULL;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
488
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
489 DavNamespace *namespace = dav_session_malloc(
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
490 res->session,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
491 sizeof(DavNamespace));
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
492 namespace->prefix = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
493 namespace->name = sstrdup_a(a, sstr(ns)).ptr;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
494 property->ns = namespace;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
495
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
496 data->remove = ucx_list_append_a(a, data->remove, property);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
497 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
498
84
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
499 static int compare_propname(const void *a, const void *b) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
500 const DavPropName *p1 = a;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
501 const DavPropName *p2 = b;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
502
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
503 int result = strcmp(p1->ns, p2->ns);
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
504 if(result) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
505 return result;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
506 } else {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
507 return strcmp(p1->name, p2->name);
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
508 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
509 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
510
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
511 DavPropName* dav_get_property_names(DavResource *res, size_t *count) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
512 DavResourceData *data = res->data;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
513
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
514 *count = data->properties->count;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
515 DavPropName *names = dav_session_calloc(
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
516 res->session,
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
517 *count,
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
518 sizeof(DavPropName));
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
519
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
520
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
521 UcxMapIterator i = ucx_map_iterator(data->properties);
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
522 void *value;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
523 int j = 0;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
524 UCX_MAP_FOREACH(key, value, i) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
525 DavPropName *name = &names[j];
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
526 // the map key is namespace + '\0' + name
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
527 name->ns = key.data;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
528 for(int k=0;j<key.len;k++) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
529 if(((char*)key.data)[k] == '\0') {
146
e48048334602 hidden password input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
530 name->name = (char*)key.data + k + 1;
84
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
531 break;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
532 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
533 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
534 j++;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
535 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
536
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
537 qsort(names, *count, sizeof(DavPropName), compare_propname);
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
538
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
539 return names;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
540 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
541
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
542
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
543 void dav_set_content(DavResource *res, void *stream, dav_read_func read_func) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
544 DavResourceData *data = res->data;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
545 data->content = stream;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
546 data->read = read_func;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
547 data->length = 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
548 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
549
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
550 void dav_set_content_data(DavResource *res, char *content, size_t length) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
551 DavSession *sn = res->session;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
552 DavResourceData *data = res->data;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
553 data->content = dav_session_malloc(sn, length);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
554 memcpy(data->content, content, length);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
555 data->read = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
556 data->length = length;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
557 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
558
178
e137883e620f using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
559 void dav_set_content_length(DavResource *res, size_t length) {
e137883e620f using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
560 DavResourceData *data = res->data;
e137883e620f using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
561 data->length = length;
e137883e620f using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
562 }
e137883e620f using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
563
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
564
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
565 int dav_load(DavResource *res) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
566 UcxBuffer *rqbuf = create_allprop_propfind_request();
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
567 int ret = dav_propfind(res->session, res, rqbuf);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
568 ucx_buffer_free(rqbuf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
569 return ret;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
570 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
571
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
572 int dav_store(DavResource *res) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
573 DavSession *sn = res->session;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
574 DavResourceData *data = res->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
575
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
576 util_set_url(sn, dav_resource_get_href(res));
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
577
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
578 DavLock *lock = dav_get_lock(sn, res->path);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
579 char *locktoken = lock ? lock->token : NULL;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
580
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
581 // store content
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
582 if(data->content) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
583 int encryption = DAV_ENCRYPT_CONTENT(sn) && sn->key;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
584 CURLcode ret;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
585 if(encryption) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
586 AESEncrypter *enc = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
587 UcxBuffer *buf = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
588 if(data->read) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
589 enc = aes_encrypter_new(sn->key, data->content, data->read);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
590 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
591 buf = ucx_buffer_new(data->content, data->length, 0);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
592 buf->size = data->length;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
593 enc = aes_encrypter_new(
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
594 sn->key,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
595 buf,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
596 (dav_read_func)ucx_buffer_read);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
597 }
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
598
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
599 // put resource
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
600 ret = do_put_request(
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
601 sn->handle,
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
602 locktoken,
227
bf485439222a fixed locking in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
603 TRUE,
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
604 enc,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
605 (dav_read_func)aes_read,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
606 0);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
607
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
608 // get sha256 hash
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
609 unsigned char sha[SHA256_DIGEST_LENGTH];
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
610 dav_get_hash(&enc->sha256, sha);
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
611 char *enc_hash = aes_encrypt((char*)sha, SHA256_DIGEST_LENGTH, sn->key);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
612
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
613 aes_encrypter_close(enc);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
614 if(buf) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
615 ucx_buffer_free(buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
616 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
617
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
618 // add crypto properties
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
619 // TODO: store the properties later
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
620 if(resource_add_crypto_info(sn, res->href, res->name, enc_hash)) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
621 free(enc_hash);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
622 return 1;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
623 }
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
624 resource_add_property(res, DAV_NS, "crypto-hash", enc_hash);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
625 free(enc_hash);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
626 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
627 ret = do_put_request(
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
628 sn->handle,
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
629 locktoken,
227
bf485439222a fixed locking in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
630 TRUE,
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
631 data->content,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
632 data->read,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
633 data->length);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
634 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
635
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
636 long status = 0;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
637 curl_easy_getinfo(sn->handle, CURLINFO_RESPONSE_CODE, &status);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
638 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
639 res->session->error = 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
640 // cleanup node data
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
641 if(!data->read) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
642 ucx_mempool_free(sn->mp, data->content);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
643 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
644 data->content = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
645 data->read = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
646 data->length = 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
647 } else {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
648 dav_session_set_error(sn, ret, status);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
649 return 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
650 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
651 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
652
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
653 // store properties
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
654 int r = 0;
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
655 sn->error = DAV_OK;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
656 if(data->set || data->remove) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
657 UcxBuffer *request = create_proppatch_request(data);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
658 UcxBuffer *response = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND);
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
659 //printf("request:\n%.*s\n\n", request->pos, request->space);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
660
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
661 CURLcode ret = do_proppatch_request(sn->handle, locktoken, request, response);
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
662 long status = 0;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
663 curl_easy_getinfo (sn->handle, CURLINFO_RESPONSE_CODE, &status);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
664 if(ret == CURLE_OK && status == 207) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
665 //printf("%s\n", response->space);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
666 // TODO: parse response
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
667 // TODO: cleanup node data correctly
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
668 data->set = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
669 data->remove = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
670 } else {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
671 dav_session_set_error(sn, ret, status);
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
672 r = -1;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
673 }
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
674
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
675 ucx_buffer_free(request);
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
676 ucx_buffer_free(response);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
677 }
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
678
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
679 return r;
33
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 int dav_get_content(DavResource *res, void *stream, dav_write_func write_fnc) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
683 DavSession *sn = res->session;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
684 CURL *handle = sn->handle;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
685 util_set_url(res->session, dav_resource_get_href(res));
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
686
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
687 // check encryption
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
688 AESDecrypter *dec = NULL;
151
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
689 DavKey *key = NULL;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
690 if(DAV_DECRYPT_CONTENT(sn)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
691 char *keyname = dav_get_property_ns(res, DAV_NS, "crypto-key");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
692 if(keyname) {
151
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
693 key = dav_context_get_key(sn->context, keyname);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
694 if(key) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
695 dec = aes_decrypter_new(key, stream, write_fnc);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
696 stream = dec;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
697 write_fnc = (dav_write_func)aes_write;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
698 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
699 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
700 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
701
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
702 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
703 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
704 curl_easy_setopt(handle, CURLOPT_PUT, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
705 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
706
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
707 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_fnc);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
708 curl_easy_setopt(handle, CURLOPT_WRITEDATA, stream);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
709
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
710 CURLcode ret = curl_easy_perform(handle);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
711
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
712 char *hash = NULL;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
713 if(dec) {
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
714 aes_decrypter_shutdown(dec); // get final bytes
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
715
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
716 // get hash
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
717 unsigned char sha[SHA256_DIGEST_LENGTH];
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
718 dav_get_hash(&dec->sha256, sha);
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
719 hash = util_hexstr(sha, 32);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
720
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
721 aes_decrypter_close(dec);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
722 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
723
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
724 long status = 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
725 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
726 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
727 int verify_failed = 0;
151
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
728 if(DAV_DECRYPT_CONTENT(sn) && key) {
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
729 // try to verify the content
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
730 char *res_hash = dav_get_property_ns(res, DAV_NS, "crypto-hash");
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
731
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
732 if(res_hash) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
733 size_t len = 0;
151
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
734 char *dec_hash = aes_decrypt(res_hash, &len, key);
155
b85248a8aee2 fixed some cases of incompatible types in crypto functions
Mike Becker <universe@uap-core.de>
parents: 151
diff changeset
735 char *hex_hash = util_hexstr((unsigned char*)dec_hash, 32);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
736 if(strcmp(hash, hex_hash)) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
737 verify_failed = 1;
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
738 }
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
739 free(dec_hash);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
740 free(hex_hash);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
741 }
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
742 }
151
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
743 if(hash) {
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
744 free(hash);
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
745 }
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
746
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
747 if(verify_failed) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
748 res->session->error = DAV_CONTENT_VERIFICATION_ERROR;
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
749 return 1;
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
750 }
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
751
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
752 res->session->error = DAV_OK;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
753 return 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
754 } else {
151
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
755 if(hash) {
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
756 free(hash);
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
757 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
758 dav_session_set_error(res->session, ret, status);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
759 return 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
760 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
761 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
762
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
763 DavResource* dav_create_child(DavResource *parent, char *name) {
42
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
764 DavResource *res = dav_resource_new_child(parent->session, parent, name);
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
765 if(dav_create(res)) {
225
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
766 dav_resource_free(res);
42
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
767 return NULL;
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
768 } else {
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
769 return res;
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
770 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
771 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
772
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
773 int dav_delete(DavResource *res) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
774 CURL *handle = res->session->handle;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
775 util_set_url(res->session, dav_resource_get_href(res));
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
776
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
777 DavLock *lock = dav_get_lock(res->session, res->path);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
778 char *locktoken = lock ? lock->token : NULL;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
779
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
780 UcxBuffer *response = ucx_buffer_new(NULL, 4096, UCX_BUFFER_AUTOEXTEND);
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
781 CURLcode ret = do_delete_request(handle, locktoken, response);
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
782 long status = 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
783 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
784 int r = 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
785 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
786 res->session->error = DAV_OK;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
787
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
788 // TODO: parse response
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
789 // TODO: free res
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
790 } else {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
791 dav_session_set_error(res->session, ret, status);
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
792 r = 1;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
793 }
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
794
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
795 ucx_buffer_free(response);
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
796 return r;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
797 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
798
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
799 static int create_ancestors(DavSession *sn, char *href, char *path) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
800 CURL *handle = sn->handle;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
801 CURLcode code;
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
802
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
803 DavLock *lock = dav_get_lock(sn, path);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
804 char *locktoken = lock ? lock->token : NULL;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
805
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
806 long status = 0;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
807 int ret = 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
808
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
809 if(strlen(path) <= 1) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
810 return 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
811 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
812
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
813 char *p = util_parent_path(path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
814 char *h = util_parent_path(href);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
815
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
816 for(int i=0;i<2;i++) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
817 util_set_url(sn, h);
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
818 code = do_mkcol_request(handle, locktoken);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
819 curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &status);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
820 if(status == 201) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
821 // resource successfully created
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
822 char *name = util_resource_name(p);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
823 int len = strlen(name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
824 if(name[len - 1] == '/') {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
825 name[len - 1] = '\0';
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
826 }
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
827 if(resource_add_crypto_info(sn, h, name, NULL)) {
225
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
828 sn->error = DAV_ERROR;
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
829 dav_session_set_errstr(sn, "Cannot set crypto properties for ancestor");
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
830 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
831 break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
832 } else if(status == 405) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
833 // parent already exists
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
834 break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
835 } else if(status == 409) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
836 // parent doesn't exist
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
837 if(create_ancestors(sn, h, p)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
838 ret = 1;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
839 break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
840 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
841 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
842 dav_session_set_error(sn, code, status);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
843 ret = 1;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
844 break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
845 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
846 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
847
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
848 free(p);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
849 free(h);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
850 return ret;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
851 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
852
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
853 static int create_resource(DavResource *res, int *status) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
854 DavSession *sn = res->session;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
855 CURL *handle = sn->handle;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
856 util_set_url(sn, dav_resource_get_href(res));
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
857
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
858 DavLock *lock = dav_get_lock(res->session, res->path);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
859 char *locktoken = lock ? lock->token : NULL;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
860
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
861 CURLcode code;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
862 if(res->iscollection) {
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
863 code = do_mkcol_request(handle, locktoken);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
864 } else {
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
865 code = do_put_request(handle, locktoken, TRUE, "", NULL, 0);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
866 }
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
867 long s = 0;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
868 curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &s);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
869 *status = s;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
870 if(code == CURLE_OK && (s >= 200 && s < 300)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
871 sn->error = DAV_OK;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
872 // if the session has encrypted file names, add crypto infos
225
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
873 if(!resource_add_crypto_info(sn, res->href, res->name, NULL)) {
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
874 // do a minimal propfind request
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
875 UcxBuffer *rqbuf = create_propfind_request(sn, NULL);
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
876 int ret = dav_propfind(sn, res, rqbuf);
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
877 ucx_buffer_free(rqbuf);
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
878 return ret;
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
879 } else {
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
880 return 1;
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
881 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
882 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
883 dav_session_set_error(sn, code, s);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
884 return 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
885 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
886 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
887
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
888 int dav_create(DavResource *res) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
889 int status;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
890 if(!create_resource(res, &status)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
891 // resource successfully created
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
892 return 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
893 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
894
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
895 if(status == 403 || status == 409) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
896 // create intermediate collections
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
897 if(create_ancestors(res->session, res->href, res->path)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
898 return 1;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
899 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
900 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
901
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
902 return create_resource(res, &status);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
903 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
904
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
905 int dav_exists(DavResource *res) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
906 DavSession *sn = res->session;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
907 CURL *handle = sn->handle;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
908 util_set_url(sn, dav_resource_get_href(res));
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
909
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
910 CURLcode ret = do_head_request(handle);
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
911 long status = 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
912 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
913 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
914 return 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
915 } else {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
916 dav_session_set_error(sn, ret, status);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
917 return 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
918 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
919 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
920
186
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
921 static int dav_cp_mv_url(DavResource *res, char *desturl, _Bool copy, _Bool override) {
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
922 DavSession *sn = res->session;
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
923 CURL *handle = sn->handle;
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
924 util_set_url(sn, dav_resource_get_href(res));
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
925
236
6b4ce32d0c4e copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
926 DavLock *lock = dav_get_lock(sn, res->path);
6b4ce32d0c4e copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
927 char *locktoken = lock ? lock->token : NULL;
6b4ce32d0c4e copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
928
6b4ce32d0c4e copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
929 CURLcode ret = do_copy_move_request(handle, desturl, locktoken, copy, override);
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
930
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
931 long status = 0;
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
932 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
933 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
934 return 0;
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
935 } else {
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
936 dav_session_set_error(sn, ret, status);
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
937 return 1;
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
938 }
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
939 }
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
940
186
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
941 static int dav_cp_mv(DavResource *res, char *newpath, _Bool copy, _Bool override) {
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
942 char *dest = dav_session_get_href(res->session, newpath);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
943 char *desturl = util_get_url(res->session, dest);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
944 dav_session_free(res->session, dest);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
945
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
946 int ret = dav_cp_mv_url(res, desturl, copy, override);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
947 free(desturl);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
948 return ret;
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
949 }
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
950
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
951 int dav_copy(DavResource *res, char *newpath) {
182
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
952 return dav_cp_mv(res, newpath, true, false);
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
953 }
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
954
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
955 int dav_move(DavResource *res, char *newpath) {
182
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
956 return dav_cp_mv(res, newpath, false, false);
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
957 }
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
958
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
959 int dav_copy_o(DavResource *res, char *newpath, DavBool override) {
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
960 return dav_cp_mv(res, newpath, true, override);
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
961 }
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
962
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
963 int dav_move_o(DavResource *res, char *newpath, DavBool override) {
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
964 return dav_cp_mv(res, newpath, false, override);
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
965 }
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
966
186
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
967 int dav_copyto(DavResource *res, char *url, DavBool override) {
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
968 return dav_cp_mv_url(res, url, true, override);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
969 }
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
970
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
971 int dav_moveto(DavResource *res, char *url, DavBool override) {
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
972 return dav_cp_mv_url(res, url, false, override);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
973 }
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
974
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
975 int dav_lock(DavResource *res) {
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
976 DavSession *sn = res->session;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
977 CURL *handle = sn->handle;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
978 util_set_url(sn, dav_resource_get_href(res));
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
979
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
980 UcxBuffer *request = create_lock_request();
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
981 UcxBuffer *response = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND);
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
982 CURLcode ret = do_lock_request(handle, request, response);
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
983
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
984 //printf("\nlock\n");
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
985 //printf("%.*s\n\n", request->size, request->space);
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
986 //printf("%.*s\n\n", response->size, response->space);
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
987
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
988 ucx_buffer_free(request);
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
989
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
990 long status = 0;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
991 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
992 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
993 LockDiscovery lock;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
994 if(parse_lock_response(sn, response, &lock)) {
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
995 sn->error = DAV_ERROR;
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
996 ucx_buffer_free(response);
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
997 return -1;
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
998 }
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
999 ucx_buffer_free(response);
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1000
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1001 DavLock *l = dav_create_lock(sn, lock.locktoken, lock.timeout);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1002 free(lock.locktoken);
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1003 free(lock.timeout);
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1004
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1005 int r = 0;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1006 if(res->iscollection) {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1007 r = dav_add_collection_lock(sn, res->path, l);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1008 } else {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1009 r = dav_add_resource_lock(sn, res->path, l);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1010 }
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1011
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1012 if(r == 0) {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1013 return 0;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1014 } else {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1015 (void)dav_unlock(res);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1016 sn->error = DAV_ERROR;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1017 dav_destroy_lock(sn, l);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1018 return -1;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1019 }
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1020 } else {
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1021 dav_session_set_error(sn, ret, status);
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
1022 ucx_buffer_free(response);
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1023 return -1;
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1024 }
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1025 }
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1026
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1027 int dav_unlock(DavResource *res) {
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1028 DavSession *sn = res->session;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1029 CURL *handle = sn->handle;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1030 util_set_url(sn, dav_resource_get_href(res));
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1031
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1032 DavLock *lock = dav_get_lock(res->session, res->path);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1033 if(!lock) {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1034 sn->error = DAV_ERROR;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1035 return -1;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1036 }
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1037
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1038 CURLcode ret = do_unlock_request(handle, lock->token);
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1039 long status = 0;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1040 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1041 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1042 dav_remove_lock(sn, res->path, lock);
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1043 } else {
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1044 dav_session_set_error(sn, ret, status);
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1045 return 1;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1046 }
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1047
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1048 return 0;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1049 }
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1050
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1051
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1052 int resource_add_crypto_info(DavSession *sn, char *href, char *name, char *hash) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1053 if(!DAV_IS_ENCRYPTED(sn)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1054 return 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1055 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1056
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1057 UcxBuffer *request = create_crypto_proppatch_request(sn, sn->key, name, hash);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1058 UcxBuffer *response = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1059
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1060 util_set_url(sn, href);
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1061 // TODO: lock
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1062 CURLcode ret = do_proppatch_request(sn->handle, NULL, request, response);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1063 ucx_buffer_free(request);
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
1064 long status = 0;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1065 curl_easy_getinfo (sn->handle, CURLINFO_RESPONSE_CODE, &status);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1066 if(ret == CURLE_OK && status == 207) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1067 // TODO: parse response
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1068 sn->error = DAV_OK;
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1069 ucx_buffer_free(response);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1070 return 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1071 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1072 dav_session_set_error(sn, ret, status);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1073 ucx_buffer_free(response);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1074 return 1;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1075 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1076 }

mercurial