libidav/resource.c

Sun, 24 Jun 2018 12:44:05 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 24 Jun 2018 12:44:05 +0200
changeset 430
b7e415d8bcdd
parent 361
b6f2462ee055
child 441
99c26b1b7327
permissions
-rw-r--r--

Added tag v1.2.0 for changeset 1607450065ba

33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
4 * Copyright 2018 Olaf Wintermann. All rights reserved.
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
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"
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
43 #include "xml.h"
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
44 #include "davqlexec.h"
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 #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
47
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 DavResource* dav_resource_new(DavSession *sn, char *path) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
49 //char *href = util_url_path(url);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
50 //DavResource *res = dav_resource_new_href(sn, href);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
51 char *parent = util_parent_path(path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
52 char *name = util_resource_name(path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
53 char *href = dav_session_create_plain_href(sn, path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
54
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
55 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
56 free(parent);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 return res;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
42
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
60 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
61 char *path = util_concat_path(parent->path, name);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
62 char *href = dav_session_create_plain_href(sn, path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
63 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
64 free(path);
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
65 return res;
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
66 }
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
67
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
69 DavResource* dav_resource_new_href(DavSession *sn, char *href) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
70 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
71 res->session = sn;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 // set name, path and href
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 resource_set_info(res, href);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 // initialize resource data
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 res->data = resource_data_new(sn);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 return res;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
82 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
83 sstr_t n = sstr(name);
2610eecfc5e5 adds resource name validation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
84 // the name must not contain path separators
280
6d8784bee427 fixes dav_resource_new_full
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
85 if(n.length > 0) {
6d8784bee427 fixes dav_resource_new_full
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
86 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
87 char c = n.ptr[i];
6d8784bee427 fixes dav_resource_new_full
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
88 if(c == '/' || c == '\\') {
6d8784bee427 fixes dav_resource_new_full
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
89 n = sstr(util_resource_name(href));
6d8784bee427 fixes dav_resource_new_full
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
90 break;
6d8784bee427 fixes dav_resource_new_full
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
91 }
268
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 }
2610eecfc5e5 adds resource name validation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
94 // remove trailing '/'
2610eecfc5e5 adds resource name validation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
95 if(n.length > 0 && n.ptr[n.length-1] == '/') {
2610eecfc5e5 adds resource name validation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
96 n.length--;
2610eecfc5e5 adds resource name validation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
97 }
2610eecfc5e5 adds resource name validation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
98
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
99 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
100 res->session = sn;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
101
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
102 // set name, path and href
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
103 res->name = sstrdup_a(sn->mp->allocator, n).ptr;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
104
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
105 char *path = util_concat_path(parent_path, name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
106 res->path = dav_session_strdup(sn, path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
107
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
108 res->href = href;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
109
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
110 // initialize resource data
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
111 res->data = resource_data_new(sn);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
112
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
113 // cache href/path
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
114 if(href) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
115 dav_session_cache_path(sn, sstr(path), sstr(href));
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
116 }
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
117 free(path);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
118
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
119 return res;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
120 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
121
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
122 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
123 UcxMapIterator i = ucx_map_iterator(properties);
348
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
124 DavXmlNode *node;
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
125 UCX_MAP_FOREACH(key, node, i) {
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
126 // TODO: free everything
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
127 dav_session_free(sn, node);
134
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 ucx_map_free(properties);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
130 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
131
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
132 void dav_resource_free(DavResource *res) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
133 DavSession *sn = res->session;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
134
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
135 dav_session_free(sn, res->name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
136 dav_session_free(sn, res->path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
137 if(res->href) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
138 dav_session_free(sn, res->href);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
139 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
140
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
141 DavResourceData *data = res->data;
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
142 resource_free_properties(sn, data->properties);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
143
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
144 UCX_FOREACH(elm, data->set) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
145 DavProperty *p = elm->data;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
146 dav_session_free(sn, p->ns->name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
147 if(p->ns->prefix) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
148 dav_session_free(sn, p->ns->prefix);
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->ns);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
151
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
152 dav_session_free(sn, p->name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
153 dav_session_free(sn, p->value);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
154 dav_session_free(sn, p);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
155 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
156
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
157 UCX_FOREACH(elm, data->remove) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
158 DavProperty *p = elm->data;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
159 dav_session_free(sn, p->ns->name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
160 if(p->ns->prefix) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
161 dav_session_free(sn, p->ns->prefix);
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->ns);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
164
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
165 dav_session_free(sn, p->name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
166 dav_session_free(sn, p);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
167 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
168
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
169 if(!data->read && data->content) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
170 dav_session_free(sn, data->content);
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, data);
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 dav_session_free(sn, res);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
175 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
176
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
177 void dav_resource_free_all(DavResource *res) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
178 DavResource *child = res->children;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
179 dav_resource_free(res);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
180 while(child) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
181 DavResource *next = child->next;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
182 dav_resource_free_all(child);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
183 child = next;
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 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
186
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
187 void resource_set_href(DavResource *res, sstr_t href) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
188 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
189 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
190
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 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
192 char *url_str = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 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
194 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
195 sstr_t href = sstr(href_str);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 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
198 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
199
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
200 UcxAllocator *a = res->session->mp->allocator;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
201 CURL *handle = res->session->handle;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
202
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
203 int nlen = 0;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
204 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
205 int plen = 0;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
206 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
207
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
208 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
209 res->href = sstrdup_a(a, href).ptr;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
210 res->path = sstrdup_a(a, sstrn(upath, plen)).ptr;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
211
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
212 curl_free(uname);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
213 curl_free(upath);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 DavResourceData* resource_data_new(DavSession *sn) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 DavResourceData *data = ucx_mempool_malloc(
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 sn->mp,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 sizeof(DavResourceData));
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 if(!data) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 return NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 }
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
223 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
224 data->set = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 data->remove = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 data->content = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 data->read = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 data->length = 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 return data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
232 char* dav_resource_get_href(DavResource *resource) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
233 if(!resource->href) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
234 resource->href = dav_session_get_href(
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
235 resource->session,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
236 resource->path);
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 return resource->href;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
239 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
240
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
241 void resource_add_property(DavResource *res, char *ns, char *name, xmlNode *val) {
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 if(!val) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 return;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 UcxKey key = dav_property_key(ns, name);
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
247 DavXmlNode *v = dav_convert_xml(res->session, val);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
248 ucx_map_put(((DavResourceData*)res->data)->properties, key, v);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 free(key.data);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
252 void resource_add_string_property(DavResource *res, char *ns, char *name, char *val) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
253 if(!val) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
254 return;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
255 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
256
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 UcxKey key = dav_property_key(ns, name);
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
258 DavXmlNode *v = dav_text_node(res->session, val);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
259 ucx_map_put(((DavResourceData*)res->data)->properties, key, v);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
260 free(key.data);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
261 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
262
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
263 DavXmlNode* resource_get_property(DavResource *res, char *ns, char *name) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
264 UcxKey key = dav_property_key(ns, name);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
265 DavXmlNode *property = resource_get_property_k(res, key);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 free(key.data);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 return property;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
270 DavXmlNode* resource_get_property_k(DavResource *res, UcxKey key) {
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
271 DavResourceData *data = (DavResourceData*)res->data;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
272 return ucx_map_get(data->properties, key);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
273 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
274
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 UcxKey dav_property_key(char *ns, char *name) {
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
276 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
277 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
278
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
279 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
280 sstr_t ns_str = sstr(ns);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281 sstr_t name_str = sstr(name);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 sstr_t key;
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
284 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
285
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 return ucx_key(key.ptr, key.length);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 void resource_add_child(DavResource *parent, DavResource *child) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 child->next = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294 if(parent->children) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 DavResource *last = parent->children;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 while(last->next) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 last = last->next;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 last->next = child;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 child->prev = last;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 } else {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 child->prev = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303 parent->children = child;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305 child->parent = parent;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
308 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
309 if(!(res1 && res2)) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
310 return 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
311 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
312
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
313 int ret;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
314 if(cr->type == 0) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
315 switch(cr->column.resprop) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
316 case DAVQL_RES_NAME: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
317 ret = strcmp(res1->name, res2->name);
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_PATH: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
321 ret = strcmp(res1->path, res2->path);
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_HREF: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
325 ret = strcmp(res1->href, res2->href);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
326 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
327 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
328 case DAVQL_RES_CONTENTLENGTH: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
329 int c = res1->contentlength == res2->contentlength;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
330 ret = c ? 0 : (res1->contentlength < res2->contentlength?-1:1);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
331 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
332 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
333 case DAVQL_RES_CONTENTTYPE: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
334 ret = strcmp(res1->contenttype, res2->contenttype);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
335 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
336 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
337 case DAVQL_RES_CREATIONDATE: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
338 int c = res1->creationdate == res2->creationdate;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
339 ret = c ? 0 : (res1->creationdate < res2->creationdate?-1:1);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
340 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
341 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
342 case DAVQL_RES_LASTMODIFIED: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
343 int c = res1->lastmodified == res2->lastmodified;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
344 ret = c ? 0 : (res1->lastmodified < res2->lastmodified?-1:1);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
345 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
346 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
347 case DAVQL_RES_ISCOLLECTION: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
348 int c = res1->iscollection == res2->iscollection;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
349 ret = c ? 0 : (res1->iscollection < res2->iscollection?-1:1);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
350 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
351 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
352 default: ret = 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 } else if(cr->type == 1) {
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
355 DavXmlNode *xvalue1 = resource_get_property_k(res1, cr->column.property);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
356 DavXmlNode *xvalue2 = resource_get_property_k(res2, cr->column.property);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
357 char *value1 = dav_xml_getstring(xvalue1);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
358 char *value2 = dav_xml_getstring(xvalue2);
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
359 if(!value1) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
360 ret = value2 ? -1 : 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
361 } else if(!value2) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
362 ret = value1 ? 1 : 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
363 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
364 ret = strcmp(value1, value2);
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 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
367 return 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
368 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
369
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
370 return cr->descending ? -ret : ret;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
371 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
372
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
373 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
374 if(!ordercr) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
375 resource_add_child(parent, child);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
376 return;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
377 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
378
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
379 child->parent = parent;
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 if(!parent->children) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
382 child->next = NULL;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
383 child->prev = NULL;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
384 parent->children = child;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
385 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
386 DavResource *resource = parent->children;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
387 while(resource) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
388 int r = 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
389 UCX_FOREACH(elm, ordercr) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
390 DavOrderCriterion *cr = elm->data;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
391 r = resource_cmp(child, resource, cr);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
392 if(r != 0) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
393 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
394 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
395 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
396
140
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
397 if(r < 0) {
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
398 // insert child before resource
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
399 child->prev = resource->prev;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
400 child->next = resource;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
401 if(resource->prev) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
402 resource->prev->next = child;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
403 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
404 parent->children = child;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
405 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
406 resource->prev = child;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
407 break;
140
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
408 } if(!resource->next) {
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
409 // append child
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
410 child->prev = resource;
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
411 child->next = NULL;
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
412 resource->next = child;
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
413 break;
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
414 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
415 resource = resource->next;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
416 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
417 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
418 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
419 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
420
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
421 char* dav_get_string_property(DavResource *res, char *name) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
422 char *pns;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
423 char *pname;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
424 dav_get_property_namespace_str(res->session->context, name, &pns, &pname);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
425 if(!pns || !pname) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
426 return NULL;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
427 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
428 return dav_get_string_property_ns(res, pns, pname);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
429 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
430
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
431 char* dav_get_string_property_ns(DavResource *res, char *ns, char *name) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
432 DavXmlNode *prop = dav_get_property_ns(res, ns, name);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
433 if(!prop) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
434 return NULL;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
435 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
436 return dav_xml_getstring(prop);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
437 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
438
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
439 DavXmlNode* dav_get_property(DavResource *res, char *name) {
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
440 char *pns;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
441 char *pname;
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
442 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
443 if(!pns || !pname) {
c89633916e36 fixes crash when using invalid namespace prefix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
444 return NULL;
c89633916e36 fixes crash when using invalid namespace prefix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
445 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
446 return dav_get_property_ns(res, pns, pname);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
447 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
448
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
449 DavXmlNode* 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
450 if(!ns || !name) {
c89633916e36 fixes crash when using invalid namespace prefix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
451 return NULL;
c89633916e36 fixes crash when using invalid namespace prefix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
452 }
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
453 DavXmlNode *property = resource_get_property(res, ns, name);
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 // resource_get_property only returns persistent properties
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
456 // check the remove and set list
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
457 if(property) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
458 // 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
459 UCX_FOREACH(elm, data->remove) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
460 DavProperty *p = elm->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
461 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
462 return NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
463 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
464 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
465 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
466 // the set list contains property updates
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
467 // we return an updated property if possible
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
468 UCX_FOREACH(elm, data->set) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
469 DavProperty *p = elm->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
470 if(!strcmp(p->name, name) && !strcmp(p->ns->name, ns)) {
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
471 return p->value; // TODO: fix
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
472 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
473 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
474 // no property update
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
475 return property;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
476 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
477
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
478 void dav_set_string_property(DavResource *res, char *name, char *value) {
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
479 char *pns;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
480 char *pname;
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
481 dav_get_property_namespace_str(res->session->context, name, &pns, &pname);
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
482 dav_set_string_property_ns(res, pns, pname, value);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
483 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
484
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
485 void dav_set_string_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
486 UcxAllocator *a = res->session->mp->allocator;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
487 DavResourceData *data = res->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
488
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
489 DavProperty *property = 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(DavProperty));
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
492 property->name = dav_session_strdup(res->session, name);
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
493 property->value = dav_text_node(res->session, value);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
494
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
495 DavNamespace *namespace = dav_session_malloc(
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
496 res->session,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
497 sizeof(DavNamespace));
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
498 namespace->prefix = NULL;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
499 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
500 property->ns = namespace;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
501
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
502 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
503 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
504
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
505 void dav_set_property(DavResource *res, char *name, DavXmlNode *value) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
506 char *pns;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
507 char *pname;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
508 dav_get_property_namespace_str(res->session->context, name, &pns, &pname);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
509 dav_set_property_ns(res, pns, pname, value);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
510 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
511
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
512 void dav_set_property_ns(DavResource *res, char *ns, char *name, DavXmlNode *value) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
513 UcxAllocator *a = res->session->mp->allocator;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
514 DavResourceData *data = res->data;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
515
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
516 DavProperty *property = dav_session_malloc(
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
517 res->session,
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
518 sizeof(DavProperty));
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
519 property->name = dav_session_strdup(res->session, name);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
520 property->value = value; // TODO: copy node?
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
521
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
522 DavNamespace *namespace = dav_session_malloc(
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
523 res->session,
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
524 sizeof(DavNamespace));
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
525 namespace->prefix = NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
526 namespace->name = dav_session_strdup(res->session, ns);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
527 property->ns = namespace;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
528
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
529 data->set = ucx_list_append_a(a, data->set, property);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
530 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
531
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
532 void dav_remove_property(DavResource *res, char *name) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
533 char *pns;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
534 char *pname;
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
535 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
536 dav_remove_property_ns(res, pns, pname);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
537 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
538
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
539 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
540 DavResourceData *data = res->data;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
541 UcxAllocator *a = res->session->mp->allocator;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
542
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
543 DavProperty *property = dav_session_malloc(
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
544 res->session,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
545 sizeof(DavProperty));
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
546 property->name = sstrdup_a(a, sstr(name)).ptr;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
547 property->value = NULL;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
548
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
549 DavNamespace *namespace = dav_session_malloc(
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
550 res->session,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
551 sizeof(DavNamespace));
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
552 namespace->prefix = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
553 namespace->name = sstrdup_a(a, sstr(ns)).ptr;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
554 property->ns = namespace;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
555
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
556 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
557 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
558
84
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
559 static int compare_propname(const void *a, const void *b) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
560 const DavPropName *p1 = a;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
561 const DavPropName *p2 = b;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
562
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
563 int result = strcmp(p1->ns, p2->ns);
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
564 if(result) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
565 return result;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
566 } else {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
567 return strcmp(p1->name, p2->name);
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
568 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
569 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
570
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
571 DavPropName* dav_get_property_names(DavResource *res, size_t *count) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
572 DavResourceData *data = res->data;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
573
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
574 *count = data->properties->count;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
575 DavPropName *names = dav_session_calloc(
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
576 res->session,
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
577 *count,
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
578 sizeof(DavPropName));
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
579
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
580
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
581 UcxMapIterator i = ucx_map_iterator(data->properties);
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
582 void *value;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
583 int j = 0;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
584 UCX_MAP_FOREACH(key, value, i) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
585 DavPropName *name = &names[j];
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
586 // the map key is namespace + '\0' + name
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
587 name->ns = key.data;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
588 for(int k=0;j<key.len;k++) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
589 if(((char*)key.data)[k] == '\0') {
146
e48048334602 hidden password input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
590 name->name = (char*)key.data + k + 1;
84
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
591 break;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
592 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
593 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
594 j++;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
595 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
596
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
597 qsort(names, *count, sizeof(DavPropName), compare_propname);
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
598
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
599 return names;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
600 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
601
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
602
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
603 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
604 DavResourceData *data = res->data;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
605 data->content = stream;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
606 data->read = read_func;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
607 data->length = 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
608 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
609
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
610 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
611 DavSession *sn = res->session;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
612 DavResourceData *data = res->data;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
613 data->content = dav_session_malloc(sn, length);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
614 memcpy(data->content, content, length);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
615 data->read = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
616 data->length = length;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
617 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
618
178
e137883e620f using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
619 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
620 DavResourceData *data = res->data;
e137883e620f using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
621 data->length = length;
e137883e620f using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
622 }
e137883e620f using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
623
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
624
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
625 int dav_load(DavResource *res) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
626 UcxBuffer *rqbuf = create_allprop_propfind_request();
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
627 int ret = dav_propfind(res->session, res, rqbuf);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
628 ucx_buffer_free(rqbuf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
629 return ret;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
630 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
631
298
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
632 int dav_load_prop(DavResource *res, DavPropName *properties, size_t numprop) {
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
633 UcxMempool *mp = ucx_mempool_new(64);
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
634
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
635 UcxList *proplist = NULL;
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
636 for(size_t i=0;i<numprop;i++) {
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
637 DavProperty *p = ucx_mempool_malloc(mp, sizeof(DavProperty));
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
638 p->name = properties[i].name;
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
639 p->ns = ucx_mempool_malloc(mp, sizeof(DavNamespace));
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
640 p->ns->name = properties[i].ns;
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
641 if(!strcmp(properties[i].ns, "DAV:")) {
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
642 p->ns->prefix = "D";
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
643 } else {
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
644 p->ns->prefix = ucx_asprintf(mp->allocator, "x%d", i).ptr;
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
645 }
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
646 p->value = NULL;
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
647 proplist = ucx_list_append_a(mp->allocator, proplist, p);
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
648 }
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
649
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
650 UcxBuffer *rqbuf = create_propfind_request(res->session, proplist);
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
651 int ret = dav_propfind(res->session, res, rqbuf);
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
652 ucx_buffer_free(rqbuf);
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
653 ucx_mempool_destroy(mp);
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
654 return ret;
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
655 }
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
656
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
657 int dav_store(DavResource *res) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
658 DavSession *sn = res->session;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
659 DavResourceData *data = res->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
660
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
661 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
662
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
663 DavLock *lock = dav_get_lock(sn, res->path);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
664 char *locktoken = lock ? lock->token : NULL;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
665
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
666 // store content
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
667 if(data->content) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
668 int encryption = DAV_ENCRYPT_CONTENT(sn) && sn->key;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
669 CURLcode ret;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
670 if(encryption) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
671 AESEncrypter *enc = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
672 UcxBuffer *buf = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
673 if(data->read) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
674 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
675 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
676 buf = ucx_buffer_new(data->content, data->length, 0);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
677 buf->size = data->length;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
678 enc = aes_encrypter_new(
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
679 sn->key,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
680 buf,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
681 (dav_read_func)ucx_buffer_read);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
682 }
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
683
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
684 // put resource
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
685 ret = do_put_request(
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
686 sn,
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
687 locktoken,
227
bf485439222a fixed locking in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
688 TRUE,
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
689 enc,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
690 (dav_read_func)aes_read,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
691 0);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
692
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
693 // get sha256 hash
349
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
694 unsigned char sha[DAV_SHA256_DIGEST_LENGTH];
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
695 dav_get_hash(&enc->sha256, sha);
349
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
696 char *enc_hash = aes_encrypt((char*)sha, DAV_SHA256_DIGEST_LENGTH, sn->key);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
697
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
698 aes_encrypter_close(enc);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
699 if(buf) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
700 ucx_buffer_free(buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
701 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
702
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
703 // add crypto properties
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
704 // TODO: store the properties later
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
705 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
706 free(enc_hash);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
707 return 1;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
708 }
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
709 resource_add_string_property(res, DAV_NS, "crypto-hash", enc_hash);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
710 free(enc_hash);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
711 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
712 ret = do_put_request(
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
713 sn,
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
714 locktoken,
227
bf485439222a fixed locking in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
715 TRUE,
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
716 data->content,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
717 data->read,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
718 data->length);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
719 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
720
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
721 long status = 0;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
722 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
723 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
724 res->session->error = 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
725 // cleanup node data
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
726 if(!data->read) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
727 ucx_mempool_free(sn->mp, data->content);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
728 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
729 data->content = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
730 data->read = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
731 data->length = 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
732 } else {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
733 dav_session_set_error(sn, ret, status);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
734 return 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
735 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
736 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
737
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
738 // store properties
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
739 int r = 0;
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
740 sn->error = DAV_OK;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
741 if(data->set || data->remove) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
742 UcxBuffer *request = create_proppatch_request(data);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
743 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
744 //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
745
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
746 CURLcode ret = do_proppatch_request(sn, 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
747 long status = 0;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
748 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
749 if(ret == CURLE_OK && status == 207) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
750 //printf("%s\n", response->space);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
751 // TODO: parse response
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
752 // TODO: cleanup node data correctly
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
753 data->set = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
754 data->remove = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
755 } else {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
756 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
757 r = -1;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
758 }
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
759
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
760 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
761 ucx_buffer_free(response);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
762 }
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
763
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
764 return r;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
765 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
766
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
767 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
768 DavSession *sn = res->session;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
769 CURL *handle = sn->handle;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
770 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
771
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
772 // check encryption
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
773 AESDecrypter *dec = NULL;
151
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
774 DavKey *key = NULL;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
775 if(DAV_DECRYPT_CONTENT(sn)) {
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
776 char *keyname = dav_get_string_property_ns(res, DAV_NS, "crypto-key");
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
777 if(keyname) {
151
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
778 key = dav_context_get_key(sn->context, keyname);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
779 if(key) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
780 dec = aes_decrypter_new(key, stream, write_fnc);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
781 stream = dec;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
782 write_fnc = (dav_write_func)aes_write;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
783 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
784 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
785 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
786
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
787 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
788 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
789 curl_easy_setopt(handle, CURLOPT_PUT, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
790 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
791
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
792 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_fnc);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
793 curl_easy_setopt(handle, CURLOPT_WRITEDATA, stream);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
794
355
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
795 if(sn->get_progress) {
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
796 curl_easy_setopt(handle, CURLOPT_XFERINFOFUNCTION, dav_session_get_progress);
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
797 curl_easy_setopt(handle, CURLOPT_XFERINFODATA, res);
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
798 curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 0L);
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
799 }
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
800
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
801 long status = 0;
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
802 CURLcode ret = dav_session_curl_perform(sn, &status);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
803
355
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
804 if(sn->get_progress) {
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
805 curl_easy_setopt(handle, CURLOPT_XFERINFOFUNCTION, NULL);
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
806 curl_easy_setopt(handle, CURLOPT_XFERINFODATA, NULL);
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
807 curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 1L);
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
808 }
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
809
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
810 char *hash = NULL;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
811 if(dec) {
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
812 aes_decrypter_shutdown(dec); // get final bytes
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
813
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
814 // get hash
349
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
815 unsigned char sha[DAV_SHA256_DIGEST_LENGTH];
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
816 dav_get_hash(&dec->sha256, sha);
349
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
817 hash = util_hexstr(sha, DAV_SHA256_DIGEST_LENGTH);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
818
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
819 aes_decrypter_close(dec);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
820 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
821
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
822 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
823 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
824 if(DAV_DECRYPT_CONTENT(sn) && key) {
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
825 // try to verify the content
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
826 char *res_hash = dav_get_string_property_ns(res, DAV_NS, "crypto-hash");
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
827
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
828 if(res_hash) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
829 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
830 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
831 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
832 if(strcmp(hash, hex_hash)) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
833 verify_failed = 1;
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
834 }
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
835 free(dec_hash);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
836 free(hex_hash);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
837 }
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
838 }
151
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
839 if(hash) {
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
840 free(hash);
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
841 }
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
842
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
843 if(verify_failed) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
844 res->session->error = DAV_CONTENT_VERIFICATION_ERROR;
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
845 return 1;
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
846 }
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
847
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
848 res->session->error = DAV_OK;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
849 return 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
850 } else {
151
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
851 if(hash) {
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
852 free(hash);
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
853 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
854 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
855 return 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
856 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
857 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
858
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
859 DavResource* dav_create_child(DavResource *parent, char *name) {
42
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
860 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
861 if(dav_create(res)) {
225
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
862 dav_resource_free(res);
42
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
863 return NULL;
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
864 } else {
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
865 return res;
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
866 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
867 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
868
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
869 int dav_delete(DavResource *res) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
870 CURL *handle = res->session->handle;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
871 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
872
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
873 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
874 char *locktoken = lock ? lock->token : NULL;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
875
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
876 UcxBuffer *response = ucx_buffer_new(NULL, 4096, UCX_BUFFER_AUTOEXTEND);
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
877 CURLcode ret = do_delete_request(res->session, locktoken, response);
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
878 long status = 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
879 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
880 int r = 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
881 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
882 res->session->error = DAV_OK;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
883
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
884 // TODO: parse response
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
885 // TODO: free res
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
886 } else {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
887 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
888 r = 1;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
889 }
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
890
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
891 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
892 return r;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
893 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
894
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
895 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
896 CURL *handle = sn->handle;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
897 CURLcode code;
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
898
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
899 DavLock *lock = dav_get_lock(sn, path);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
900 char *locktoken = lock ? lock->token : NULL;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
901
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
902 long status = 0;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
903 int ret = 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
904
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
905 if(strlen(path) <= 1) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
906 return 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
907 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
908
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
909 char *p = util_parent_path(path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
910 char *h = util_parent_path(href);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
911
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
912 for(int i=0;i<2;i++) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
913 util_set_url(sn, h);
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
914 code = do_mkcol_request(sn, locktoken);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
915 curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &status);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
916 if(status == 201) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
917 // resource successfully created
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
918 char *name = util_resource_name(p);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
919 int len = strlen(name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
920 if(name[len - 1] == '/') {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
921 name[len - 1] = '\0';
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
922 }
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
923 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
924 sn->error = DAV_ERROR;
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
925 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
926 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
927 break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
928 } else if(status == 405) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
929 // parent already exists
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
930 break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
931 } else if(status == 409) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
932 // parent doesn't exist
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
933 if(create_ancestors(sn, h, p)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
934 ret = 1;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
935 break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
936 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
937 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
938 dav_session_set_error(sn, code, status);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
939 ret = 1;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
940 break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
941 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
942 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
943
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
944 free(p);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
945 free(h);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
946 return ret;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
947 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
948
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
949 static int create_resource(DavResource *res, int *status) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
950 DavSession *sn = res->session;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
951 CURL *handle = sn->handle;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
952 util_set_url(sn, dav_resource_get_href(res));
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
953
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
954 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
955 char *locktoken = lock ? lock->token : NULL;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
956
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
957 CURLcode code;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
958 if(res->iscollection) {
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
959 code = do_mkcol_request(sn, locktoken);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
960 } else {
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
961 code = do_put_request(sn, locktoken, TRUE, "", NULL, 0);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
962 }
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
963 long s = 0;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
964 curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &s);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
965 *status = s;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
966 if(code == CURLE_OK && (s >= 200 && s < 300)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
967 sn->error = DAV_OK;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
968 // 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
969 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
970 // do a minimal propfind request
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
971 UcxBuffer *rqbuf = create_propfind_request(sn, NULL);
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
972 int ret = dav_propfind(sn, res, rqbuf);
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
973 ucx_buffer_free(rqbuf);
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
974 return ret;
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
975 } else {
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
976 return 1;
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
977 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
978 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
979 dav_session_set_error(sn, code, s);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
980 return 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
981 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
982 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
983
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
984 int dav_create(DavResource *res) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
985 int status;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
986 if(!create_resource(res, &status)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
987 // resource successfully created
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
988 return 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
989 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
990
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
991 if(status == 403 || status == 409) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
992 // create intermediate collections
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
993 if(create_ancestors(res->session, res->href, res->path)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
994 return 1;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
995 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
996 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
997
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
998 return create_resource(res, &status);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
999 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1000
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1001 int dav_exists(DavResource *res) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1002 DavSession *sn = res->session;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1003 CURL *handle = sn->handle;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1004 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
1005
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
1006 CURLcode ret = do_head_request(sn);
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
1007 long status = 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1008 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1009 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1010 return 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1011 } else {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1012 dav_session_set_error(sn, ret, status);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1013 return 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1014 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1015 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1016
186
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1017 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
1018 DavSession *sn = res->session;
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1019 CURL *handle = sn->handle;
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1020 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
1021
236
6b4ce32d0c4e copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1022 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
1023 char *locktoken = lock ? lock->token : NULL;
6b4ce32d0c4e copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1024
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
1025 CURLcode ret = do_copy_move_request(sn, desturl, locktoken, copy, override);
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1026
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
1027 long status = 0;
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1028 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
1029 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
1030 return 0;
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1031 } else {
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1032 dav_session_set_error(sn, ret, status);
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1033 return 1;
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1034 }
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1035 }
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1036
186
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1037 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
1038 char *dest = dav_session_get_href(res->session, newpath);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1039 char *desturl = util_get_url(res->session, dest);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1040 dav_session_free(res->session, dest);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1041
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1042 int ret = dav_cp_mv_url(res, desturl, copy, override);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1043 free(desturl);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1044 return ret;
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1045 }
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1046
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1047 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
1048 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
1049 }
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1050
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1051 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
1052 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
1053 }
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
1054
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
1055 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
1056 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
1057 }
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
1058
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
1059 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
1060 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
1061 }
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1062
186
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1063 int dav_copyto(DavResource *res, char *url, DavBool override) {
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1064 return dav_cp_mv_url(res, url, true, override);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1065 }
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1066
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1067 int dav_moveto(DavResource *res, char *url, DavBool override) {
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1068 return dav_cp_mv_url(res, url, false, override);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1069 }
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1070
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1071 int dav_lock(DavResource *res) {
315
7db4dbf4e6f9 adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1072 return dav_lock_t(res, 0);
7db4dbf4e6f9 adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1073 }
7db4dbf4e6f9 adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1074
7db4dbf4e6f9 adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1075 int dav_lock_t(DavResource *res, time_t timeout) {
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1076 DavSession *sn = res->session;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1077 CURL *handle = sn->handle;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1078 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
1079
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1080 UcxBuffer *request = create_lock_request();
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1081 UcxBuffer *response = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND);
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
1082 CURLcode ret = do_lock_request(sn, request, response, timeout);
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1083
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1084 //printf("\nlock\n");
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1085 //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
1086 //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
1087
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
1088 ucx_buffer_free(request);
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
1089
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1090 long status = 0;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1091 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
1092 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
1093 LockDiscovery lock;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1094 if(parse_lock_response(sn, response, &lock)) {
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1095 sn->error = DAV_ERROR;
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
1096 ucx_buffer_free(response);
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1097 return -1;
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1098 }
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
1099 ucx_buffer_free(response);
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1100
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1101 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
1102 free(lock.locktoken);
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1103 free(lock.timeout);
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1104
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1105 int r = 0;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1106 if(res->iscollection) {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1107 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
1108 } else {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1109 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
1110 }
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1111
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1112 if(r == 0) {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1113 return 0;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1114 } else {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1115 (void)dav_unlock(res);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1116 sn->error = DAV_ERROR;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1117 dav_destroy_lock(sn, l);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1118 return -1;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1119 }
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1120 } else {
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1121 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
1122 ucx_buffer_free(response);
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1123 return -1;
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1124 }
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1125 }
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1126
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1127 int dav_unlock(DavResource *res) {
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1128 DavSession *sn = res->session;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1129 CURL *handle = sn->handle;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1130 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
1131
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1132 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
1133 if(!lock) {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1134 sn->error = DAV_ERROR;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1135 return -1;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1136 }
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1137
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
1138 CURLcode ret = do_unlock_request(sn, lock->token);
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1139 long status = 0;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1140 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
1141 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
1142 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
1143 } else {
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1144 dav_session_set_error(sn, ret, status);
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1145 return 1;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1146 }
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1147
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1148 return 0;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1149 }
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1150
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1151
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1152 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
1153 if(!DAV_IS_ENCRYPTED(sn)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1154 return 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1155 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1156
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1157 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
1158 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
1159
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1160 util_set_url(sn, href);
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1161 // TODO: lock
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
1162 CURLcode ret = do_proppatch_request(sn, NULL, request, response);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1163 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
1164 long status = 0;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1165 curl_easy_getinfo (sn->handle, CURLINFO_RESPONSE_CODE, &status);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1166 if(ret == CURLE_OK && status == 207) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1167 // TODO: parse response
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1168 sn->error = DAV_OK;
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1169 ucx_buffer_free(response);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1170 return 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1171 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1172 dav_session_set_error(sn, ret, status);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1173 ucx_buffer_free(response);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1174 return 1;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1175 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1176 }

mercurial