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