libidav/resource.c

Sun, 19 Mar 2023 15:12:42 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 19 Mar 2023 15:12:42 +0100
changeset 743
716f6bf04c30
parent 736
40be8db6fe45
child 747
efbd59642577
permissions
-rw-r--r--

fix crash if the server sends a response with elements without namespaces

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
518
cca3e7aa30ed fix null pointer dereferenciation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 505
diff changeset
85 if(n.length > 0 && href) {
280
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) {
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
123 if(!properties) return;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
124
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
125 UcxMapIterator i = ucx_map_iterator(properties);
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
126 DavProperty *property;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
127 UCX_MAP_FOREACH(key, property, i) {
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
128 // TODO: free everything
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
129 dav_session_free(sn, property);
134
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 ucx_map_free(properties);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
132 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
133
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
134 void dav_resource_free(DavResource *res) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
135 DavSession *sn = res->session;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
136
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
137 dav_session_free(sn, res->name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
138 dav_session_free(sn, res->path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
139 if(res->href) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
140 dav_session_free(sn, res->href);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
141 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
142
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
143 DavResourceData *data = res->data;
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
144 resource_free_properties(sn, data->properties);
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
145 resource_free_properties(sn, data->crypto_properties);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
146
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
147 UCX_FOREACH(elm, data->set) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
148 DavProperty *p = elm->data;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
149 dav_session_free(sn, p->ns->name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
150 if(p->ns->prefix) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
151 dav_session_free(sn, p->ns->prefix);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
152 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
153 dav_session_free(sn, p->ns);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
154
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
155 dav_session_free(sn, p->name);
736
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 728
diff changeset
156 dav_free_xml_node_sn(sn, p->value);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
157 dav_session_free(sn, p);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
158 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
159
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
160 UCX_FOREACH(elm, data->remove) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
161 DavProperty *p = elm->data;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
162 dav_session_free(sn, p->ns->name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
163 if(p->ns->prefix) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
164 dav_session_free(sn, p->ns->prefix);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
165 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
166 dav_session_free(sn, p->ns);
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 dav_session_free(sn, p->name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
169 dav_session_free(sn, p);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
170 }
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 if(!data->read && data->content) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
173 dav_session_free(sn, data->content);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
174 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
175 dav_session_free(sn, data);
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 dav_session_free(sn, res);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
178 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
179
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
180 void dav_resource_free_all(DavResource *res) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
181 DavResource *child = res->children;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
182 dav_resource_free(res);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
183 while(child) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
184 DavResource *next = child->next;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
185 dav_resource_free_all(child);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
186 child = next;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
187 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
188 }
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 void resource_set_href(DavResource *res, sstr_t href) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
191 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
192 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
193
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 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
195 char *url_str = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 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
197 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
198 sstr_t href = sstr(href_str);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 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
201 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
202
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
203 UcxAllocator *a = res->session->mp->allocator;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
204 CURL *handle = res->session->handle;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
205
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
206 int nlen = 0;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
207 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
208 int plen = 0;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
209 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
210
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
211 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
212 res->href = sstrdup_a(a, href).ptr;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
213 res->path = sstrdup_a(a, sstrn(upath, plen)).ptr;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
214
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
215 curl_free(uname);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
216 curl_free(upath);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 DavResourceData* resource_data_new(DavSession *sn) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 DavResourceData *data = ucx_mempool_malloc(
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 sn->mp,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 sizeof(DavResourceData));
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 if(!data) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 return NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 }
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
226 data->properties = ucx_map_new_a(sn->mp->allocator, 32);
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
227 data->crypto_properties = NULL;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 data->set = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 data->remove = NULL;
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
230 data->crypto_set = NULL;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
231 data->crypto_remove = NULL;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
232 data->read = NULL;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 data->content = NULL;
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 477
diff changeset
234 data->seek = NULL;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 data->length = 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 return data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
239 char* dav_resource_get_href(DavResource *resource) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
240 if(!resource->href) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
241 resource->href = dav_session_get_href(
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
242 resource->session,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
243 resource->path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
244 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
245 return resource->href;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
246 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
247
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
248 void resource_add_prop(DavResource *res, const char *ns, const char *name, DavXmlNode *val) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
249 DavSession *sn = res->session;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
250
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
251 DavNamespace *namespace = dav_session_malloc(sn, sizeof(DavNamespace));
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
252 namespace->prefix = NULL;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
253 namespace->name = dav_session_strdup(sn, ns);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
254
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
255 DavProperty *prop = dav_session_malloc(sn, sizeof(DavProperty));
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
256 prop->name = dav_session_strdup(sn, name);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
257 prop->ns = namespace;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
258 prop->value = val;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
259
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
260 sstr_t key = dav_property_key(ns, name);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
261 ucx_map_sstr_put(((DavResourceData*)res->data)->properties, key, prop);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
262 free(key.ptr);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
263 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
264
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 493
diff changeset
265 void resource_add_property(DavResource *res, const char *ns, const char *name, xmlNode *val) {
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 if(!val) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 return;
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
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
270 resource_add_prop(res, ns, name, dav_convert_xml(res->session, val));
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
273 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
274 if(!val) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
275 return;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
276 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
277
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
278 resource_add_prop(res, ns, name, dav_text_node(res->session, val));
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
279 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
280
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
281 void resource_set_crypto_properties(DavResource *res, UcxMap *cprops) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
282 DavResourceData *data = res->data;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
283 resource_free_properties(res->session, data->crypto_properties);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
284 data->crypto_properties = cprops;
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
285 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
286
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 493
diff changeset
287 DavXmlNode* resource_get_property(DavResource *res, const char *ns, const char *name) {
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 493
diff changeset
288 sstr_t keystr = dav_property_key(ns, name);
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 493
diff changeset
289 UcxKey key = ucx_key(keystr.ptr, keystr.length);
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
290 DavXmlNode *ret = resource_get_property_k(res, key);
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 493
diff changeset
291 free(keystr.ptr);
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
292
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
293 return ret;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
294 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
295
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
296 DavXmlNode* resource_get_encrypted_property(DavResource *res, const char *ns, const char *name) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
297 sstr_t keystr = dav_property_key(ns, name);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
298 UcxKey key = ucx_key(keystr.ptr, keystr.length);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
299 DavXmlNode *ret = resource_get_encrypted_property_k(res, key);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
300 free(keystr.ptr);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
301
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
302 return ret;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
305 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
306 DavResourceData *data = (DavResourceData*)res->data;
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
307 DavProperty *property = ucx_map_get(data->properties, key);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
308
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
309 return property ? property->value : NULL;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
310 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
311
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
312 DavXmlNode* resource_get_encrypted_property_k(DavResource *res, UcxKey key) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
313 DavResourceData *data = (DavResourceData*)res->data;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
314 DavProperty *property = ucx_map_get(data->crypto_properties, key);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
315
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
316 return property ? property->value : NULL;
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
317 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
318
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 493
diff changeset
319 sstr_t dav_property_key(const char *ns, const char *name) {
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
320 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
321 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
322
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 493
diff changeset
323 sstr_t dav_property_key_a(UcxAllocator *a, const char *ns, const char *name) {
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 493
diff changeset
324 scstr_t ns_str = scstr(ns);
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 493
diff changeset
325 scstr_t name_str = scstr(name);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 493
diff changeset
327 return 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
328 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
332
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
333 void resource_add_child(DavResource *parent, DavResource *child) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 child->next = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 if(parent->children) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336 DavResource *last = parent->children;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337 while(last->next) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338 last = last->next;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 last->next = child;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341 child->prev = last;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 } else {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343 child->prev = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344 parent->children = child;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346 child->parent = parent;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
347 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
348
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
349 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
350 if(!(res1 && res2)) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
351 return 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
352 }
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 int ret;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
355 if(cr->type == 0) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
356 switch(cr->column.resprop) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
357 case DAVQL_RES_NAME: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
358 ret = strcmp(res1->name, res2->name);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
359 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
360 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
361 case DAVQL_RES_PATH: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
362 ret = strcmp(res1->path, res2->path);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
363 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
364 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
365 case DAVQL_RES_HREF: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
366 ret = strcmp(res1->href, res2->href);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
367 break;
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 case DAVQL_RES_CONTENTLENGTH: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
370 int c = res1->contentlength == res2->contentlength;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
371 ret = c ? 0 : (res1->contentlength < res2->contentlength?-1:1);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
372 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
373 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
374 case DAVQL_RES_CONTENTTYPE: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
375 ret = strcmp(res1->contenttype, res2->contenttype);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
376 break;
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 case DAVQL_RES_CREATIONDATE: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
379 int c = res1->creationdate == res2->creationdate;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
380 ret = c ? 0 : (res1->creationdate < res2->creationdate?-1:1);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
381 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
382 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
383 case DAVQL_RES_LASTMODIFIED: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
384 int c = res1->lastmodified == res2->lastmodified;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
385 ret = c ? 0 : (res1->lastmodified < res2->lastmodified?-1:1);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
386 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
387 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
388 case DAVQL_RES_ISCOLLECTION: {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
389 int c = res1->iscollection == res2->iscollection;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
390 ret = c ? 0 : (res1->iscollection < res2->iscollection?-1:1);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
391 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
392 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
393 default: ret = 0;
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 } 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
396 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
397 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
398 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
399 char *value2 = dav_xml_getstring(xvalue2);
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
400 if(!value1) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
401 ret = value2 ? -1 : 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
402 } else if(!value2) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
403 ret = value1 ? 1 : 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
404 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
405 ret = strcmp(value1, value2);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
406 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
407 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
408 return 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
409 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
410
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
411 return cr->descending ? -ret : ret;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
412 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
413
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
414 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
415 if(!ordercr) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
416 resource_add_child(parent, child);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
417 return;
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 child->parent = parent;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
421
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
422 if(!parent->children) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
423 child->next = NULL;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
424 child->prev = NULL;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
425 parent->children = child;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
426 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
427 DavResource *resource = parent->children;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
428 while(resource) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
429 int r = 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
430 UCX_FOREACH(elm, ordercr) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
431 DavOrderCriterion *cr = elm->data;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
432 r = resource_cmp(child, resource, cr);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
433 if(r != 0) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
434 break;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
435 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
436 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
437
140
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
438 if(r < 0) {
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
439 // insert child before resource
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
440 child->prev = resource->prev;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
441 child->next = resource;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
442 if(resource->prev) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
443 resource->prev->next = child;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
444 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
445 parent->children = child;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
446 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
447 resource->prev = child;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
448 break;
140
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
449 } if(!resource->next) {
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
450 // append child
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
451 child->prev = resource;
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
452 child->next = NULL;
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
453 resource->next = child;
0a06bed068a1 fixed order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
454 break;
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
455 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
456 resource = resource->next;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
457 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
458 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
459 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
460 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
461
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
462 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
463 char *pns;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
464 char *pname;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
465 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
466 if(!pns || !pname) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
467 return NULL;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
468 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
469 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
470 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
471
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
472 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
473 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
474 if(!prop) {
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
475 return NULL;
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
476 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
477 return dav_xml_getstring(prop);
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
478 }
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
479
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
480 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
481 char *pns;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
482 char *pname;
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
483 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
484 if(!pns || !pname) {
c89633916e36 fixes crash when using invalid namespace prefix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
485 return NULL;
c89633916e36 fixes crash when using invalid namespace prefix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
486 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
487 return dav_get_property_ns(res, pns, pname);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
488 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
489
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
490 static DavXmlNode* get_property_ns(DavResource *res, DavBool encrypted, const char *ns, const char *name) {
269
c89633916e36 fixes crash when using invalid namespace prefix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
491 if(!ns || !name) {
c89633916e36 fixes crash when using invalid namespace prefix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
492 return NULL;
c89633916e36 fixes crash when using invalid namespace prefix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
493 }
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
494
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
495 DavResourceData *data = res->data;
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
496
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
497 DavXmlNode *property = NULL;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
498 UcxList *remove_list = NULL;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
499 UcxList *set_list = NULL;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
500
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
501 if(encrypted) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
502 // check if crypto_properties because it will only be created
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
503 // if the resource has encrypted properties
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
504 if(!data->crypto_properties) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
505 return NULL;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
506 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
507 property = resource_get_encrypted_property(res, ns, name);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
508 remove_list = data->crypto_remove;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
509 set_list = data->crypto_set;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
510 } else {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
511 property = resource_get_property(res, ns, name);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
512 remove_list = data->remove;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
513 set_list = data->set;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
514 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
515
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
516 // resource_get_property only returns persistent properties
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
517 // check the remove and set list
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
518 if(property) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
519 // if the property is in the remove list, we return NULL
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
520 UCX_FOREACH(elm, remove_list) {
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
521 DavProperty *p = elm->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
522 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
523 return NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
524 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
525 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
526 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
527 // the set list contains property updates
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
528 // we return an updated property if possible
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
529 UCX_FOREACH(elm, set_list) {
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
530 DavProperty *p = elm->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
531 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
532 return p->value; // TODO: fix
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
533 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
534 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
535 // no property update
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
536
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
537 return property;
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
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
540 DavXmlNode* dav_get_property_ns(DavResource *res, const char *ns, const char *name) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
541 DavXmlNode *property_value = get_property_ns(res, FALSE, ns, name);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
542
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
543 if(!property_value && DAV_DECRYPT_PROPERTIES(res->session)) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
544 property_value = get_property_ns(res, TRUE, ns, name);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
545 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
546
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
547 return property_value;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
548 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
549
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
550 DavXmlNode* dav_get_encrypted_property_ns(DavResource *res, const char *ns, const char *name) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
551 return get_property_ns(res, TRUE, ns, name);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
552 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
553
605
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
554 static DavProperty* createprop(DavSession *sn, const char *ns, const char *name) {
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
555 DavProperty *property = dav_session_malloc(sn, sizeof(DavProperty));
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
556 property->name = dav_session_strdup(sn, name);
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
557 property->value = NULL;
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
558
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
559 DavNamespace *namespace = dav_session_malloc(sn, sizeof(DavNamespace));
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
560 namespace->prefix = NULL;
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
561 namespace->name = dav_session_strdup(sn, ns);
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
562
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
563 property->ns = namespace;
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
564
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
565 return property;
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
566 }
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
567
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
568 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
569 char *pns;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
570 char *pname;
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
571 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
572 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
573 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
574
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
575 void dav_set_string_property_ns(DavResource *res, char *ns, char *name, char *value) {
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
576 DavSession *sn = res->session;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
577 UcxAllocator *a = res->session->mp->allocator;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
578 DavResourceData *data = res->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
579
605
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
580 DavProperty *property = createprop(res->session, ns, name);
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
581 property->value = dav_text_node(res->session, value);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
582
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
583 if(DAV_ENCRYPT_PROPERTIES(sn) && dav_namespace_is_encrypted(sn->context, ns)) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
584 data->crypto_set = ucx_list_append_a(a, data->crypto_set, property);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
585 } else {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
586 data->set = ucx_list_append_a(a, data->set, property);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
587 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
588 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
589
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
590 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
591 char *pns;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
592 char *pname;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
593 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
594 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
595 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
596
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
597 void dav_set_property_ns(DavResource *res, char *ns, char *name, DavXmlNode *value) {
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
598 DavSession *sn = res->session;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
599 UcxAllocator *a = sn->mp->allocator;
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
600 DavResourceData *data = res->data;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
601
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
602 DavProperty *property = createprop(sn, ns, name);
736
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 728
diff changeset
603 // TODO: this function should copy the value
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 728
diff changeset
604 // but we also need a function, that doesn't create a copy
40be8db6fe45 fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 728
diff changeset
605 property->value = value;
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
606
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
607 if(DAV_ENCRYPT_PROPERTIES(sn) && dav_namespace_is_encrypted(sn->context, ns)) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
608 data->crypto_set = ucx_list_append_a(a, data->crypto_set, property);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
609 } else {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
610 data->set = ucx_list_append_a(a, data->set, property);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
611 }
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
612 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
613
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
614 void dav_remove_property(DavResource *res, char *name) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
615 char *pns;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
616 char *pname;
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
617 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
618 dav_remove_property_ns(res, pns, pname);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
619 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
620
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
621 void dav_remove_property_ns(DavResource *res, char *ns, char *name) {
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
622 DavSession *sn = res->session;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
623 DavResourceData *data = res->data;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
624 UcxAllocator *a = res->session->mp->allocator;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
625
605
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
626 DavProperty *property = createprop(res->session, ns, name);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
627
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
628 if(DAV_ENCRYPT_PROPERTIES(sn) && dav_namespace_is_encrypted(sn->context, ns)) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
629 data->crypto_remove = ucx_list_append_a(a, data->crypto_remove, property);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
630 } else {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
631 data->remove = ucx_list_append_a(a, data->remove, property);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
632 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
633 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
634
605
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
635 void dav_set_encrypted_property_ns(DavResource *res, char *ns, char *name, DavXmlNode *value) {
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
636 UcxAllocator *a = res->session->mp->allocator;
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
637 DavResourceData *data = res->data;
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
638
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
639 DavProperty *property = createprop(res->session, ns, name);
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
640 property->value = value; // TODO: copy node?
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
641
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
642 data->crypto_set = ucx_list_append_a(a, data->crypto_set, property);
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
643 }
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
644
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
645 void dav_set_encrypted_string_property_ns(DavResource *res, char *ns, char *name, char *value) {
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
646 UcxAllocator *a = res->session->mp->allocator;
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
647 DavResourceData *data = res->data;
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
648
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
649 DavProperty *property = createprop(res->session, ns, name);
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
650 property->value = dav_text_node(res->session, value);
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
651
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
652 data->crypto_set = ucx_list_append_a(a, data->crypto_set, property);
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
653 }
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
654
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
655 void dav_remove_encrypted_property_ns(DavResource *res, char *ns, char *name) {
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
656 DavResourceData *data = res->data;
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
657 UcxAllocator *a = res->session->mp->allocator;
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
658
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
659 DavProperty *property = createprop(res->session, ns, name);
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
660
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
661 data->crypto_remove = ucx_list_append_a(a, data->crypto_remove, property);
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
662 }
bbc66c72661a add new api for encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 589
diff changeset
663
84
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
664 static int compare_propname(const void *a, const void *b) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
665 const DavPropName *p1 = a;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
666 const DavPropName *p2 = b;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
667
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
668 int result = strcmp(p1->ns, p2->ns);
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
669 if(result) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
670 return result;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
671 } else {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
672 return strcmp(p1->name, p2->name);
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
673 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
674 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
675
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
676 DavPropName* dav_get_property_names(DavResource *res, size_t *count) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
677 DavResourceData *data = res->data;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
678
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
679 *count = data->properties->count;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
680 DavPropName *names = dav_session_calloc(
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
681 res->session,
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
682 *count,
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
683 sizeof(DavPropName));
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
684
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
685
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
686 UcxMapIterator i = ucx_map_iterator(data->properties);
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
687 DavProperty *value;
84
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
688 int j = 0;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
689 UCX_MAP_FOREACH(key, value, i) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
690 DavPropName *name = &names[j];
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
691
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
692 name->ns = value->ns->name;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
693 name->name = value->name;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
694
84
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
695 j++;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
696 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
697
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
698 qsort(names, *count, sizeof(DavPropName), compare_propname);
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
699
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
700 return names;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
701 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
702
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
703
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 477
diff changeset
704 void dav_set_content(DavResource *res, void *stream, dav_read_func read_func, dav_seek_func seek_func) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
705 DavResourceData *data = res->data;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
706 data->content = stream;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
707 data->read = read_func;
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 477
diff changeset
708 data->seek = seek_func;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
709 data->length = 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
710 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
711
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
712 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
713 DavSession *sn = res->session;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
714 DavResourceData *data = res->data;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
715 data->content = dav_session_malloc(sn, length);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
716 memcpy(data->content, content, length);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
717 data->read = NULL;
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 477
diff changeset
718 data->seek = NULL;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
719 data->length = length;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
720 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
721
178
e137883e620f using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
722 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
723 DavResourceData *data = res->data;
e137883e620f using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
724 data->length = length;
e137883e620f using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
725 }
e137883e620f using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
726
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
727
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
728 int dav_load(DavResource *res) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
729 UcxBuffer *rqbuf = create_allprop_propfind_request();
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
730 int ret = dav_propfind(res->session, res, rqbuf);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
731 ucx_buffer_free(rqbuf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
732 return ret;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
733 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
734
298
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
735 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
736 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
737
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
738 UcxList *proplist = NULL;
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
739 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
740 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
741 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
742 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
743 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
744 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
745 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
746 } else {
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
747 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
748 }
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
749 p->value = NULL;
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
750 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
751 }
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
752
475
52e4171d42ce adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 441
diff changeset
753 UcxBuffer *rqbuf = create_propfind_request(res->session, proplist, "propfind", 0);
298
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
754 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
755 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
756 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
757 return ret;
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
758 }
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 280
diff changeset
759
555
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
760
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
761 static void init_hash_stream(HashStream *hstr, void *stream, dav_read_func readfn, dav_seek_func seekfn) {
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
762 hstr->sha = NULL;
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
763 hstr->stream = stream;
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
764 hstr->read = readfn;
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
765 hstr->seek = seekfn;
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
766 hstr->error = 0;
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
767 }
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
768
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
769 static size_t dav_read_h(void *buf, size_t size, size_t nelm, void *stream) {
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
770 HashStream *s = stream;
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
771 if(!s->sha) {
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
772 s->sha = dav_hash_init();
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
773 }
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
774
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
775 size_t r = s->read(buf, size, nelm, s->stream);
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
776 dav_hash_update(s->sha, buf, r);
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
777 return r;
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
778 }
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
779
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
780 static int dav_seek_h(void *stream, long offset, int whence) {
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
781 HashStream *s = stream;
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
782 if(offset == 0 && whence == SEEK_SET) {
558
1a9e6a5c1e79 fixes several signedness issues
Mike Becker <universe@uap-core.de>
parents: 555
diff changeset
783 unsigned char buf[DAV_SHA256_DIGEST_LENGTH];
555
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
784 dav_hash_final(s->sha, buf);
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
785 s->sha = NULL;
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
786 } else {
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
787 s->error = 1;
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
788 }
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
789 return s->seek(s->stream, offset, whence);
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
790 }
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
791
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
792
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
793 int dav_store(DavResource *res) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
794 DavSession *sn = res->session;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
795 DavResourceData *data = res->data;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
796
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
797 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
798
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
799 DavLock *lock = dav_get_lock(sn, res->path);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
800 char *locktoken = lock ? lock->token : NULL;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
801
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
802 // store content
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
803 if(data->content) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
804 int encryption = DAV_ENCRYPT_CONTENT(sn) && sn->key;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
805 CURLcode ret;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
806 if(encryption) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
807 AESEncrypter *enc = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
808 UcxBuffer *buf = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
809 if(data->read) {
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 477
diff changeset
810 enc = aes_encrypter_new(
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 477
diff changeset
811 sn->key,
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 477
diff changeset
812 data->content,
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 477
diff changeset
813 data->read,
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 477
diff changeset
814 data->seek);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
815 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
816 buf = ucx_buffer_new(data->content, data->length, 0);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
817 buf->size = data->length;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
818 enc = aes_encrypter_new(
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
819 sn->key,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
820 buf,
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 477
diff changeset
821 (dav_read_func)ucx_buffer_read,
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 477
diff changeset
822 (dav_seek_func)dav_buffer_seek);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
823 }
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
824
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
825 // put resource
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
826 ret = do_put_request(
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
827 sn,
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
828 locktoken,
227
bf485439222a fixed locking in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
829 TRUE,
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
830 enc,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
831 (dav_read_func)aes_read,
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 477
diff changeset
832 (dav_seek_func)aes_encrypter_reset,
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
833 0);
150
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 // get sha256 hash
555
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
836 dav_get_hash(&enc->sha256, (unsigned char*)data->hash);
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
837 char *enc_hash = aes_encrypt(data->hash, DAV_SHA256_DIGEST_LENGTH, sn->key);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
838
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
839 aes_encrypter_close(enc);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
840 if(buf) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
841 ucx_buffer_free(buf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
842 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
843
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
844 // add crypto properties
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
845 // TODO: store the properties later
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
846 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
847 free(enc_hash);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
848 return 1;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
849 }
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
850 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
851 free(enc_hash);
555
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
852 } else if((sn->flags & DAV_SESSION_STORE_HASH) == DAV_SESSION_STORE_HASH) {
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
853 HashStream hstr;
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
854 UcxBuffer *iobuf = NULL;
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
855 if(!data->read) {
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
856 iobuf = ucx_buffer_new(data->content, data->length, 0);
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
857 iobuf->size = data->length;
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
858 init_hash_stream(
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
859 &hstr,
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
860 iobuf,
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
861 (dav_read_func)ucx_buffer_read,
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
862 (dav_seek_func)ucx_buffer_seek);
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
863 } else {
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
864 init_hash_stream(
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
865 &hstr,
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
866 data->content,
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
867 data->read,
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
868 data->seek);
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
869 }
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
870
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
871 ret = do_put_request(
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
872 sn,
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
873 locktoken,
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
874 TRUE,
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
875 &hstr,
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
876 dav_read_h,
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
877 (dav_seek_func)dav_seek_h,
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
878 data->length);
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
879
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
880 if(hstr.sha) {
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
881 dav_hash_final(hstr.sha, (unsigned char*)data->hash);
558
1a9e6a5c1e79 fixes several signedness issues
Mike Becker <universe@uap-core.de>
parents: 555
diff changeset
882 char *hash = util_hexstr((unsigned char*)data->hash, 32);
555
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
883 dav_set_string_property_ns(res, DAV_NS, "content-hash", hash);
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
884 free(hash);
c9ada14ee90e add session flag for content hash creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
885 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
886 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
887 ret = do_put_request(
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
888 sn,
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
889 locktoken,
227
bf485439222a fixed locking in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
890 TRUE,
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
891 data->content,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
892 data->read,
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 477
diff changeset
893 data->seek,
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
894 data->length);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
895 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
896
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
897 long status = 0;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
898 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
899 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
900 res->session->error = 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
901 // cleanup node data
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
902 if(!data->read) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
903 ucx_mempool_free(sn->mp, data->content);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
904 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
905 data->content = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
906 data->read = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
907 data->length = 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
908 } else {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
909 dav_session_set_error(sn, ret, status);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
910 return 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
911 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
912 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
913
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
914 // generate crypto-prop content
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
915 if(DAV_ENCRYPT_PROPERTIES(sn) && sn->key && (data->crypto_set || data->crypto_remove)) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
916 DavResource *crypto_res = dav_resource_new_href(sn, res->href);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
917 int ret = 1;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
918
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
919 if(crypto_res) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
920 UcxBuffer *rqbuf = create_cryptoprop_propfind_request();
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
921 ret = dav_propfind(res->session, res, rqbuf);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
922 ucx_buffer_free(rqbuf);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
923 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
924
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
925 if(!ret) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
926 DavXmlNode *crypto_prop_node = dav_get_property_ns(crypto_res, DAV_NS, "crypto-prop");
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
927 UcxMap *crypto_props = parse_crypto_prop(sn, sn->key, crypto_prop_node);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
928 if(!crypto_props) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
929 // resource hasn't encrypted properties yet
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
930 crypto_props = ucx_map_new(32); // create new map
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
931 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
932
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
933 // remove all properties
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
934 UCX_FOREACH(elm, data->crypto_remove) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
935 if(crypto_props->count == 0) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
936 break; // map already empty, can't remove any more
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
937 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
938
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
939 DavProperty *property = elm->data;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
940 sstr_t key = dav_property_key(property->ns->name, property->name);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
941 DavProperty *existing_prop = ucx_map_sstr_remove(crypto_props, key);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
942 if(existing_prop) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
943 // TODO: free existing_prop
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
944 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
945 free(key.ptr);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
946 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
947
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
948 // set properties
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
949 UCX_FOREACH(elm, data->crypto_set) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
950 DavProperty *property = elm->data;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
951 sstr_t key = dav_property_key(property->ns->name, property->name);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
952 DavProperty *existing_prop = ucx_map_sstr_remove(crypto_props, key);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
953 ucx_map_sstr_put(crypto_props, key, property);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
954 if(existing_prop) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
955 // TODO: free existing_prop
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
956 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
957 free(key.ptr);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
958 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
959
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
960 DavXmlNode *crypto_prop_value = create_crypto_prop(sn, crypto_props);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
961 if(crypto_prop_value) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
962 DavProperty *new_crypto_prop = createprop(sn, DAV_NS, "crypto-prop");
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
963 new_crypto_prop->value = crypto_prop_value;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
964 data->set = ucx_list_prepend_a(sn->mp->allocator, data->set, new_crypto_prop);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
965 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
966
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
967 dav_resource_free(crypto_res);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
968 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
969
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
970 if(ret) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
971 return 1;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
972 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
973 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
974
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
975 // store properties
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
976 int r = 0;
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
977 sn->error = DAV_OK;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
978 if(data->set || data->remove) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
979 UcxBuffer *request = create_proppatch_request(data);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
980 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
981 //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
982
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
983 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
984 long status = 0;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
985 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
986 if(ret == CURLE_OK && status == 207) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
987 //printf("%s\n", response->space);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
988 // TODO: parse response
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
989 // TODO: cleanup node data correctly
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
990 data->set = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
991 data->remove = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
992 } else {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
993 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
994 r = -1;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
995 }
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
996
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
997 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
998 ucx_buffer_free(response);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
999 }
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
1000
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
1001 return r;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1002 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1003
477
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1004 #if LIBCURL_VERSION_MAJOR >= 7 && LIBCURL_VERSION_MINOR >= 32
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1005 static void set_progressfunc(DavResource *res) {
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1006 CURL *handle = res->session->handle;
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1007 curl_easy_setopt(handle, CURLOPT_XFERINFOFUNCTION, dav_session_get_progress);
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1008 curl_easy_setopt(handle, CURLOPT_XFERINFODATA, res);
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1009 curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 0L);
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1010 }
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1011
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1012 static void unset_progressfunc(DavResource *res) {
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1013 CURL *handle = res->session->handle;
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1014 curl_easy_setopt(handle, CURLOPT_XFERINFOFUNCTION, NULL);
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1015 curl_easy_setopt(handle, CURLOPT_XFERINFODATA, NULL);
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1016 curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 1L);
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1017 }
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1018 #else
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1019 static void set_progressfunc(DavResource *res) {
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1020
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1021 }
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1022 static void unset_progressfunc(DavResource *res) {
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1023
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1024 }
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1025 #endif
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1026
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1027 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
1028 DavSession *sn = res->session;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1029 CURL *handle = sn->handle;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1030 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
1031
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
1032 // check encryption
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1033 AESDecrypter *dec = NULL;
151
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
1034 DavKey *key = NULL;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1035 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
1036 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
1037 if(keyname) {
151
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
1038 key = dav_context_get_key(sn->context, keyname);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1039 if(key) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1040 dec = aes_decrypter_new(key, stream, write_fnc);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1041 stream = dec;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1042 write_fnc = (dav_write_func)aes_write;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1043 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1044 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1045 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1046
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
1047 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1048 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1049 curl_easy_setopt(handle, CURLOPT_PUT, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1050 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1051
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1052 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_fnc);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1053 curl_easy_setopt(handle, CURLOPT_WRITEDATA, stream);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1054
355
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
1055 if(sn->get_progress) {
477
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1056 set_progressfunc(res);
355
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
1057 }
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
1058
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
1059 long status = 0;
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
1060 CURLcode ret = dav_session_curl_perform(sn, &status);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1061
355
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
1062 if(sn->get_progress) {
477
9a406db6729b makes libidav compatible with libcurl < 7.32
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
1063 unset_progressfunc(res);
355
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
1064 }
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
1065
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1066 char *hash = NULL;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1067 if(dec) {
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1068 aes_decrypter_shutdown(dec); // get final bytes
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1069
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1070 // get hash
349
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
1071 unsigned char sha[DAV_SHA256_DIGEST_LENGTH];
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1072 dav_get_hash(&dec->sha256, sha);
349
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
1073 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
1074
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1075 aes_decrypter_close(dec);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1076 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1077
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1078 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
1079 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
1080 if(DAV_DECRYPT_CONTENT(sn) && key) {
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1081 // 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
1082 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
1083
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1084 if(res_hash) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1085 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
1086 char *dec_hash = aes_decrypt(res_hash, &len, key);
542
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1087 char *hex_hash = util_hexstr((unsigned char*)dec_hash, len);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1088 if(strcmp(hash, hex_hash)) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1089 verify_failed = 1;
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1090 }
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1091 free(dec_hash);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1092 free(hex_hash);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1093 }
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1094 }
151
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
1095 if(hash) {
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
1096 free(hash);
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
1097 }
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1098
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1099 if(verify_failed) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1100 res->session->error = DAV_CONTENT_VERIFICATION_ERROR;
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1101 return 1;
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1102 }
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1103
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1104 res->session->error = DAV_OK;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1105 return 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1106 } else {
151
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
1107 if(hash) {
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
1108 free(hash);
a316613205dc fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
1109 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1110 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
1111 return 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1112 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1113 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1114
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1115 DavResource* dav_create_child(DavResource *parent, char *name) {
42
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
1116 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
1117 if(dav_create(res)) {
225
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
1118 dav_resource_free(res);
42
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
1119 return NULL;
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
1120 } else {
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
1121 return res;
6518b035a9df added some api functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
1122 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1123 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1124
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1125 int dav_delete(DavResource *res) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1126 CURL *handle = res->session->handle;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1127 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
1128
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1129 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
1130 char *locktoken = lock ? lock->token : NULL;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1131
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1132 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
1133 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
1134 long status = 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1135 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
1136 int r = 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1137 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1138 res->session->error = DAV_OK;
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 518
diff changeset
1139 res->exists = 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1140
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1141 // TODO: parse response
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1142 // TODO: free res
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1143 } else {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1144 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
1145 r = 1;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1146 }
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
1147
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
1148 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
1149 return r;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1150 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1151
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1152 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
1153 CURL *handle = sn->handle;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1154 CURLcode code;
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1155
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1156 DavLock *lock = dav_get_lock(sn, path);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1157 char *locktoken = lock ? lock->token : NULL;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1158
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
1159 long status = 0;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1160 int ret = 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1161
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1162 if(strlen(path) <= 1) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1163 return 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1164 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1165
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1166 char *p = util_parent_path(path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1167 char *h = util_parent_path(href);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1168
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1169 for(int i=0;i<2;i++) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1170 util_set_url(sn, h);
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
1171 code = do_mkcol_request(sn, locktoken);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1172 curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &status);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1173 if(status == 201) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1174 // resource successfully created
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1175 char *name = util_resource_name(p);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1176 int len = strlen(name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1177 if(name[len - 1] == '/') {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1178 name[len - 1] = '\0';
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1179 }
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1180 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
1181 sn->error = DAV_ERROR;
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
1182 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
1183 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1184 break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1185 } else if(status == 405) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1186 // parent already exists
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1187 break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1188 } else if(status == 409) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1189 // parent doesn't exist
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1190 if(create_ancestors(sn, h, p)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1191 ret = 1;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1192 break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1193 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1194 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1195 dav_session_set_error(sn, code, status);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1196 ret = 1;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1197 break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1198 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1199 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1200
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1201 free(p);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1202 free(h);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1203 return ret;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1204 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1205
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1206 static int create_resource(DavResource *res, int *status) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1207 DavSession *sn = res->session;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1208 CURL *handle = sn->handle;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1209 util_set_url(sn, dav_resource_get_href(res));
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1210
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1211 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
1212 char *locktoken = lock ? lock->token : NULL;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1213
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1214 CURLcode code;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1215 if(res->iscollection) {
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
1216 code = do_mkcol_request(sn, locktoken);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1217 } else {
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 477
diff changeset
1218 code = do_put_request(sn, locktoken, TRUE, "", NULL, NULL, 0);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1219 }
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
1220 long s = 0;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1221 curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &s);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1222 *status = s;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1223 if(code == CURLE_OK && (s >= 200 && s < 300)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1224 sn->error = DAV_OK;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1225 // 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
1226 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
1227 // do a minimal propfind request
475
52e4171d42ce adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 441
diff changeset
1228 UcxBuffer *rqbuf = create_propfind_request(sn, NULL, "propfind", 0);
225
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
1229 int ret = dav_propfind(sn, res, rqbuf);
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
1230 ucx_buffer_free(rqbuf);
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
1231 return ret;
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
1232 } else {
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
1233 return 1;
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
1234 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1235 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1236 dav_session_set_error(sn, code, s);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1237 return 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1238 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1239 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1240
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1241 int dav_create(DavResource *res) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1242 int status;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1243 if(!create_resource(res, &status)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1244 // resource successfully created
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 518
diff changeset
1245 res->exists = 1;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1246 return 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1247 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1248
441
99c26b1b7327 improves compatibility with owncloud/nextcloud when uploading files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
1249 if(status == 403 || status == 409 || status == 404) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1250 // create intermediate collections
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1251 if(create_ancestors(res->session, res->href, res->path)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1252 return 1;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1253 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1254 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1255
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1256 return create_resource(res, &status);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1257 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1258
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1259 int dav_exists(DavResource *res) {
713
a1c36a6410f6 reimplement dav_exists by using dav_load_prop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
1260 if(!dav_load_prop(res, NULL, 0)) {
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 518
diff changeset
1261 res->exists = 1;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1262 return 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1263 } else {
713
a1c36a6410f6 reimplement dav_exists by using dav_load_prop
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
1264 if(res->session->error == DAV_NOT_FOUND) {
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 518
diff changeset
1265 res->exists = 0;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 518
diff changeset
1266 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1267 return 0;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1268 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1269 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1270
186
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1271 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
1272 DavSession *sn = res->session;
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1273 CURL *handle = sn->handle;
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1274 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
1275
236
6b4ce32d0c4e copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1276 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
1277 char *locktoken = lock ? lock->token : NULL;
6b4ce32d0c4e copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1278
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
1279 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
1280
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
1281 long status = 0;
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1282 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
1283 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
1284 return 0;
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1285 } else {
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1286 dav_session_set_error(sn, ret, status);
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1287 return 1;
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1288 }
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1289 }
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1290
186
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1291 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
1292 char *dest = dav_session_get_href(res->session, newpath);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1293 char *desturl = util_get_url(res->session, dest);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1294 dav_session_free(res->session, dest);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1295
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1296 int ret = dav_cp_mv_url(res, desturl, copy, override);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1297 free(desturl);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1298 return ret;
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1299 }
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1300
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1301 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
1302 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
1303 }
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1304
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1305 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
1306 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
1307 }
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
1308
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
1309 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
1310 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
1311 }
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
1312
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
1313 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
1314 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
1315 }
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1316
186
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1317 int dav_copyto(DavResource *res, char *url, DavBool override) {
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1318 return dav_cp_mv_url(res, url, true, override);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1319 }
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1320
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1321 int dav_moveto(DavResource *res, char *url, DavBool override) {
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1322 return dav_cp_mv_url(res, url, false, override);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1323 }
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1324
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1325 int dav_lock(DavResource *res) {
315
7db4dbf4e6f9 adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1326 return dav_lock_t(res, 0);
7db4dbf4e6f9 adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1327 }
7db4dbf4e6f9 adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1328
7db4dbf4e6f9 adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1329 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
1330 DavSession *sn = res->session;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1331 CURL *handle = sn->handle;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1332 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
1333
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1334 UcxBuffer *request = create_lock_request();
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1335 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
1336 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
1337
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1338 //printf("\nlock\n");
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1339 //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
1340 //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
1341
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
1342 ucx_buffer_free(request);
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
1343
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1344 long status = 0;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1345 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
1346 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
1347 LockDiscovery lock;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1348 if(parse_lock_response(sn, response, &lock)) {
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1349 sn->error = DAV_ERROR;
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
1350 ucx_buffer_free(response);
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1351 return -1;
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1352 }
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
1353 ucx_buffer_free(response);
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1354
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1355 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
1356 free(lock.locktoken);
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1357 free(lock.timeout);
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1358
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1359 int r = 0;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1360 if(res->iscollection) {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1361 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
1362 } else {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1363 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
1364 }
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1365
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1366 if(r == 0) {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1367 return 0;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1368 } else {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1369 (void)dav_unlock(res);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1370 sn->error = DAV_ERROR;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1371 dav_destroy_lock(sn, l);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1372 return -1;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1373 }
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1374 } else {
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1375 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
1376 ucx_buffer_free(response);
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1377 return -1;
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1378 }
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1379 }
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1380
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1381 int dav_unlock(DavResource *res) {
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1382 DavSession *sn = res->session;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1383 CURL *handle = sn->handle;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1384 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
1385
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1386 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
1387 if(!lock) {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1388 sn->error = DAV_ERROR;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1389 return -1;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1390 }
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1391
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
1392 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
1393 long status = 0;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1394 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
1395 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
1396 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
1397 } else {
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1398 dav_session_set_error(sn, ret, status);
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1399 return 1;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1400 }
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1401
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1402 return 0;
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1403 }
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1404
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1405
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 493
diff changeset
1406 int resource_add_crypto_info(DavSession *sn, const char *href, const char *name, const char *hash) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1407 if(!DAV_IS_ENCRYPTED(sn)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1408 return 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1409 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1410
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1411 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
1412 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
1413
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1414 util_set_url(sn, href);
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1415 // TODO: lock
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
1416 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
1417 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
1418 long status = 0;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1419 curl_easy_getinfo (sn->handle, CURLINFO_RESPONSE_CODE, &status);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1420 if(ret == CURLE_OK && status == 207) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1421 // TODO: parse response
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1422 sn->error = DAV_OK;
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1423 ucx_buffer_free(response);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1424 return 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1425 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1426 dav_session_set_error(sn, ret, status);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1427 ucx_buffer_free(response);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1428 return 1;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1429 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
1430 }
587
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1431
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1432 /* ----------------------------- crypto-prop ----------------------------- */
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1433
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1434 DavXmlNode* create_crypto_prop(DavSession *sn, UcxMap *properties) {
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1435 if(!sn->key) {
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1436 return NULL;
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1437 }
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1438
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1439 UcxBuffer *content = ucx_buffer_new(NULL, 2048, UCX_BUFFER_AUTOEXTEND);
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1440
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1441 // create an xml document containing all properties
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1442 UcxMap *nsmap = ucx_map_new(8);
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1443 ucx_map_cstr_put(nsmap, "DAV:", strdup("D"));
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1444
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1445 ucx_buffer_puts(content, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1446 ucx_buffer_puts(content, "<D:prop xmlns:D=\"DAV:\">\n");
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1447
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1448 UcxMapIterator i = ucx_map_iterator(properties);
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1449 DavProperty *prop;
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1450 UCX_MAP_FOREACH(key, prop, i) {
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1451 DavXmlNode pnode;
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1452 pnode.type = DAV_XML_ELEMENT;
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1453 pnode.namespace = prop->ns->name;
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1454 pnode.name = prop->name;
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1455 pnode.prev = NULL;
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1456 pnode.next = NULL;
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1457 pnode.children = prop->value;
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1458 pnode.parent = NULL;
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1459 pnode.attributes = NULL;
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1460 pnode.content = NULL;
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1461 pnode.contentlength = 0;
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1462
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1463 dav_print_node(content, (write_func)ucx_buffer_write, nsmap, &pnode);
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1464 ucx_buffer_putc(content, '\n');
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1465 }
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1466
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1467 ucx_buffer_puts(content, "</D:prop>");
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1468
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1469 ucx_map_free_content(nsmap, (ucx_destructor)free);
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1470 ucx_map_free(nsmap);
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1471
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1472 // encrypt xml document
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1473 char *crypto_prop_content = aes_encrypt(content->space, content->size, sn->key);
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1474 ucx_buffer_free(content);
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1475
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1476 DavXmlNode *ret = NULL;
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1477 if(crypto_prop_content) {
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1478 ret = dav_text_node(sn, crypto_prop_content);
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1479 free(crypto_prop_content);
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1480 }
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1481 return ret;
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1482 }
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1483
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
1484 UcxMap* parse_crypto_prop(DavSession *sn, DavKey *key, DavXmlNode *node) {
589
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1485 if(!node || node->type != DAV_XML_TEXT || node->contentlength == 0) {
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1486 return NULL;
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1487 }
587
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1488
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
1489 return parse_crypto_prop_str(sn, key, node->content);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
1490 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
1491
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
1492 UcxMap* parse_crypto_prop_str(DavSession *sn, DavKey *key, const char *content) {
589
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1493 size_t len = 0;
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 605
diff changeset
1494 char *dec_str = aes_decrypt(content, &len, key);
589
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1495
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1496 xmlDoc *doc = xmlReadMemory(dec_str, len, NULL, NULL, 0);
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1497 free(dec_str);
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1498 if(!doc) {
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1499 return NULL;
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1500 }
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1501
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1502 int err = 0;
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1503 xmlNode *xml_root = xmlDocGetRootElement(doc);
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1504 if(xml_root) {
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1505 if(
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1506 !xml_root->ns ||
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1507 !xstreq(xml_root->name, "prop") ||
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1508 !xstreq(xml_root->ns->href, "DAV:"))
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1509 {
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1510 err = 1;
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1511 }
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1512 } else {
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1513 err = 1;
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1514 }
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1515
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1516 if(err) {
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1517 xmlFreeDoc(doc);
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1518 return NULL;
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1519 }
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1520
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1521 // ready to get the properties
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1522 UcxMap *map = ucx_map_new(32);
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1523 xmlNode *n = xml_root->children;
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1524 while(n) {
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1525 if(n->type == XML_ELEMENT_NODE && n->ns && n->ns->href) {
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1526 DavProperty *property = dav_session_malloc(sn, sizeof(DavProperty));
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1527 property->name = dav_session_strdup(sn, (const char*)n->name);
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1528 property->ns = dav_session_malloc(sn, sizeof(DavNamespace));
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1529 property->ns->name = dav_session_strdup(sn, (const char*)n->ns->href);
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1530 property->ns->prefix = n->ns->prefix ?
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1531 dav_session_strdup(sn, (const char*)n->ns->prefix) : NULL;
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1532 property->value = n->children ? dav_convert_xml(sn, n->children) : NULL;
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1533
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1534 sstr_t key = dav_property_key(property->ns->name, property->name);
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1535 ucx_map_sstr_put(map, key, property);
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1536 free(key.ptr);
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1537 }
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1538 n = n->next;
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1539 }
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1540
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1541 xmlFreeDoc(doc);
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1542 if(map->count == 0) {
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1543 ucx_map_free(map);
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1544 return NULL;
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1545 }
2514559a6367 add function for decrypting and parsing crypto-prop elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
1546 return map;
587
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 558
diff changeset
1547 }
728
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1548
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1549
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1550 /* ----------------------------- streams ----------------------------- */
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1551
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1552 static size_t in_write(const char *ptr, size_t size, size_t nitems, void *in_stream) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1553 DavInputStream *in = in_stream;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1554 size_t len = size * nitems;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1555
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1556 if(in->alloc < len) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1557 char *newb = realloc(in->buffer, len);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1558 if(!newb) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1559 if(in->buffer) free(in->buffer);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1560 in->eof = 1;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1561 return 0;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1562 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1563
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1564 in->buffer = newb;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1565 in->alloc = len;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1566 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1567
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1568 memcpy(in->buffer, ptr, len);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1569
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1570 in->size = len;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1571 in->pos = 0;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1572
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1573 return nitems;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1574 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1575
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1576 DavInputStream* dav_inputstream_open(DavResource *res) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1577 DavSession *sn = res->session;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1578
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1579 DavInputStream *in = dav_session_malloc(sn, sizeof(DavInputStream));
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1580 if(!in) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1581 return NULL;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1582 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1583 memset(in, 0, sizeof(DavInputStream));
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1584
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1585 in->res = res;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1586
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1587 in->c = curl_easy_duphandle(sn->handle);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1588 char *url = util_get_url(sn, dav_resource_get_href(res));
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1589 curl_easy_setopt(in->c, CURLOPT_URL, url);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1590 free(url);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1591
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1592 in->m = curl_multi_init();
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1593
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1594 curl_easy_setopt(in->c, CURLOPT_HTTPHEADER, NULL);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1595 curl_easy_setopt(in->c, CURLOPT_CUSTOMREQUEST, NULL);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1596 curl_easy_setopt(in->c, CURLOPT_PUT, 0L);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1597 curl_easy_setopt(in->c, CURLOPT_UPLOAD, 0L);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1598
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1599 curl_multi_add_handle(in->m, in->c);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1600
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1601 dav_write_func write_fnc = (dav_write_func)in_write;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1602 void *stream = in;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1603
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1604 // check encryption
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1605 AESDecrypter *dec = NULL;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1606 DavKey *key = NULL;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1607 if(DAV_DECRYPT_CONTENT(sn)) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1608 char *keyname = dav_get_string_property_ns(res, DAV_NS, "crypto-key");
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1609 if(keyname) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1610 key = dav_context_get_key(sn->context, keyname);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1611 if(key) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1612 dec = aes_decrypter_new(key, stream, write_fnc);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1613 stream = dec;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1614 write_fnc = (dav_write_func)aes_write;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1615 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1616 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1617 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1618
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1619 curl_easy_setopt(in->c, CURLOPT_WRITEFUNCTION, write_fnc);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1620 curl_easy_setopt(in->c, CURLOPT_WRITEDATA, stream);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1621
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1622 in->dec = dec;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1623
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1624 return in;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1625 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1626
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1627 size_t dav_read(void *buf, size_t size, size_t nitems, DavInputStream *in) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1628 size_t len = in->size - in->pos;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1629 size_t rl = size * nitems;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1630 if(len > 0) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1631 len = rl > len ? len : rl;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1632 len -= len % size;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1633 memcpy(buf, in->buffer + in->pos, len);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1634 in->pos += len;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1635 return len / size;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1636 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1637 in->size = 0;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1638
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1639 if(in->eof) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1640 if(in->dec) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1641 aes_decrypter_shutdown(in->dec); // get final bytes
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1642 aes_decrypter_close(in->dec);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1643 in->dec = NULL;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1644 } else {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1645 return 0;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1646 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1647 } else {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1648 int running;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1649 while(!in->eof && in->size == 0) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1650 CURLMcode r = curl_multi_perform(in->m, &running);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1651 if(r != CURLM_OK || running == 0) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1652 in->eof = 1;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1653 break;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1654 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1655
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1656 int numfds;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1657 if(curl_multi_poll(in->m, NULL, 0, 5000, &numfds) != CURLM_OK) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1658 in->eof = 1;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1659 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1660 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1661 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1662
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1663 return in->size > 0 ? dav_read(buf, size, nitems, in) : 0;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1664 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1665
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1666 void dav_inputstream_close(DavInputStream *in) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1667 curl_multi_cleanup(in->m);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1668 curl_easy_cleanup(in->c);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1669 if(in->buffer) free(in->buffer);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1670 dav_session_free(in->res->session, in);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1671 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1672
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1673
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1674 static size_t out_read(char *ptr, size_t size, size_t nitems, void *out_stream) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1675 DavOutputStream *out = out_stream;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1676 size_t len = size * nitems;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1677 size_t available = out->size - out->pos;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1678 if(available == 0) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1679 return 0;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1680 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1681
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1682 size_t r = len > available ? available : len;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1683 r -= r % size;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1684 memcpy(ptr, out->buffer + out->pos, r);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1685
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1686 out->pos += r;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1687
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1688 return r / size;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1689 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1690
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1691 static size_t dummy_write(void *buf, size_t s, size_t n, void *data) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1692 return s*n;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1693 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1694
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1695 DavOutputStream* dav_outputstream_open(DavResource *res) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1696 DavSession *sn = res->session;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1697
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1698 DavOutputStream *out = dav_session_malloc(sn, sizeof(DavOutputStream));
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1699 if(!out) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1700 return NULL;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1701 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1702 memset(out, 0, sizeof(DavOutputStream));
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1703
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1704 out->res = res;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1705
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1706 out->c = curl_easy_duphandle(sn->handle);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1707 char *url = util_get_url(sn, dav_resource_get_href(res));
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1708 curl_easy_setopt(out->c, CURLOPT_URL, url);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1709 free(url);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1710
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1711 out->m = curl_multi_init();
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1712 curl_multi_add_handle(out->m, out->c);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1713
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1714 void *stream = out;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1715 dav_read_func read_fnc = (dav_read_func)out_read;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1716
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1717 // if encryption or hashing in enabled, we need a stream wrapper
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1718 if(DAV_ENCRYPT_CONTENT(sn) && sn->key) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1719 AESEncrypter *enc = aes_encrypter_new(sn->key, out, (dav_read_func)out_read, NULL);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1720 out->enc = enc;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1721 stream = enc;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1722 read_fnc = (dav_read_func)aes_read;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1723 } else if((sn->flags & DAV_SESSION_STORE_HASH) == DAV_SESSION_STORE_HASH) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1724 HashStream *hstr = dav_session_malloc(sn, sizeof(HashStream));
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1725 out->hstr = hstr;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1726 init_hash_stream(hstr, out, (dav_read_func)out_read, NULL);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1727 stream = hstr;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1728 read_fnc = (dav_read_func)dav_read_h;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1729 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1730
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1731 curl_easy_setopt(out->c, CURLOPT_HEADERFUNCTION, NULL);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1732 curl_easy_setopt(out->c, CURLOPT_HTTPHEADER, NULL);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1733 curl_easy_setopt(out->c, CURLOPT_CUSTOMREQUEST, NULL);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1734 curl_easy_setopt(out->c, CURLOPT_PUT, 1L);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1735 curl_easy_setopt(out->c, CURLOPT_UPLOAD, 1L);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1736 curl_easy_setopt(out->c, CURLOPT_READFUNCTION, read_fnc);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1737 curl_easy_setopt(out->c, CURLOPT_READDATA, stream);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1738 curl_easy_setopt(out->c, CURLOPT_SEEKFUNCTION, NULL);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1739 curl_easy_setopt(out->c, CURLOPT_INFILESIZE, -1);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1740 curl_easy_setopt(out->c, CURLOPT_INFILESIZE_LARGE, -1L);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1741
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1742 curl_easy_setopt(out->c, CURLOPT_WRITEFUNCTION, dummy_write);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1743 curl_easy_setopt(out->c, CURLOPT_WRITEDATA, NULL);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1744
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1745 return out;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1746 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1747
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1748 size_t dav_write(const void *buf, size_t size, size_t nitems, DavOutputStream *out) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1749 if(out->eof) return 0;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1750
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1751 out->buffer = buf;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1752 out->size = size * nitems;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1753 out->pos = 0;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1754
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1755 int running;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1756 while(!out->eof && (out->size == 0 || out->size - out->pos > 0)) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1757 CURLMcode r = curl_multi_perform(out->m, &running);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1758 if(r != CURLM_OK || running == 0) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1759 out->eof = 1;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1760 break;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1761 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1762
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1763 int numfds;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1764 if(curl_multi_poll(out->m, NULL, 0, 5000, &numfds) != CURLM_OK) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1765 out->eof = 1;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1766 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1767 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1768
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1769 return (out->size - out->pos) / size;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1770 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1771
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1772 int dav_outputstream_close(DavOutputStream *out) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1773 DavSession *sn = out->res->session;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1774 DavResource *res = out->res;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1775 DavResourceData *data = res->data;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1776
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1777 int ret = 0;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1778
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1779 dav_write(NULL, 1, 0, out);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1780
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1781 curl_multi_cleanup(out->m);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1782 curl_easy_cleanup(out->c);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1783
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1784 int store = 0;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1785 if(out->enc) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1786 // get sha256 hash
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1787 char hash[32];
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1788 dav_get_hash(&out->enc->sha256, (unsigned char*)data->hash);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1789 aes_encrypter_close(out->enc);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1790 char *enc_hash = aes_encrypt(hash, DAV_SHA256_DIGEST_LENGTH, sn->key);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1791 // add crypto properties
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1792 if(resource_add_crypto_info(sn, out->res->href, out->res->name, enc_hash)) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1793 ret = 1;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1794 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1795 free(enc_hash);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1796 } else if(out->hstr) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1797 dav_hash_final(out->hstr->sha, (unsigned char*)data->hash);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1798 char *hash = util_hexstr((unsigned char*)data->hash, 32);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1799 dav_set_string_property_ns(res, DAV_NS, "content-hash", hash);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1800 free(hash);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1801 dav_session_free(sn, out->hstr);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1802 store = 1;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1803 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1804
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1805 if(store) {
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1806 ret = dav_store(out->res);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1807 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1808
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1809 dav_session_free(out->res->session, out);
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1810
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1811 return ret;
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1812 }
35a421f441d5 add stream API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 713
diff changeset
1813

mercurial