libidav/webdav.c

Wed, 04 Sep 2019 19:28:10 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 04 Sep 2019 19:28:10 +0200
changeset 637
20241338740c
parent 609
dc3d70848c7c
child 645
ad61c1654dce
permissions
-rw-r--r--

add first dav-sync hashing test

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 *
404
5c08b8e14df8 updates copyright notice
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
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>
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <libxml/tree.h>
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "utils.h"
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "webdav.h"
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
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"
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #include "ucx/buffer.h"
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 #include "ucx/utils.h"
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
40 #include "davqlparser.h"
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
41 #include "davqlexec.h"
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
587
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
44 DavContext* dav_context_new(void) {
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
45 // initialize
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
46 DavContext *context = calloc(1, sizeof(DavContext));
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 if(!context) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 return NULL;
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 context->sessions = NULL;
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
51 context->http_proxy = calloc(1, sizeof(DavProxy));
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
52 if(!context->http_proxy) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
53 dav_context_destroy(context);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
54 return NULL;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
55 }
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
56 context->https_proxy = calloc(1, sizeof(DavProxy));
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
57 if(!context->https_proxy) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
58 dav_context_destroy(context);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
59 return NULL;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
60 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 context->namespaces = ucx_map_new(16);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 if(!context->namespaces) {
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
63 dav_context_destroy(context);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 return NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 }
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
66 context->keys = ucx_map_new(16);
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
67 if(!context->keys) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
68 dav_context_destroy(context);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 return NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
72 // add DAV: namespace
607
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
73 if(dav_add_namespace(context, "D", "DAV:")) {
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
74 dav_context_destroy(context);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
75 return NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
76 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
77
607
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
78
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
79 // add idav namespace
607
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
80 if(dav_add_namespace(context, "idav", DAV_NS)) {
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
81 dav_context_destroy(context);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
82 return NULL;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
83 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
84
607
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
85 // add idavprops namespace
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
86 if(dav_add_namespace(context, "idavprops", DAV_PROPS_NS)) {
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
87 dav_context_destroy(context);
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
88 return NULL;
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
89 }
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
90
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 return context;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 void dav_context_destroy(DavContext *ctx) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 // destroy all sessions assoziated with this context
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
96 UcxList *elm = ctx->sessions;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
97 while(elm) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
98 DavSession *sn = elm->data;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
99 elm = elm->next;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
100 dav_session_destroy(sn);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 }
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
102 if(ctx->http_proxy) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
103 free(ctx->http_proxy);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
104 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
105 if(ctx->https_proxy) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
106 free(ctx->https_proxy);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
107 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
109 if(ctx->namespaces) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
110 UcxMapIterator i = ucx_map_iterator(ctx->namespaces);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
111 UcxKey k;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
112 DavNamespace *ns;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
113 UCX_MAP_FOREACH(k, ns, i) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
114 if(!ns) continue;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
115 if(ns->prefix) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
116 free(ns->prefix);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
117 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
118 if(ns->name) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
119 free(ns->name);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
120 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
121 free(ns);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
122 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
123 ucx_map_free(ctx->namespaces);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
124 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
125 if(ctx->keys) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
126 UcxMapIterator i = ucx_map_iterator(ctx->keys);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
127 UcxKey k;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
128 DavKey *key;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
129 UCX_MAP_FOREACH(k, key, i) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
130 if(!key) continue;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
131 if(key->name) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
132 free(key->name);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
133 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
134 if(key->data) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
135 free(key->data);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
136 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
137 free(key);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
138 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
139 ucx_map_free(ctx->keys);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
140 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
141
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 free(ctx);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
145 void dav_context_add_key(DavContext *context, DavKey *key) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
146 ucx_map_cstr_put(context->keys, key->name, key);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
147 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
148
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
149 DavKey* dav_context_get_key(DavContext *context, char *name) {
229
df158262f802 fixed dav_context_get_key
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
150 if(name) {
df158262f802 fixed dav_context_get_key
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
151 return ucx_map_cstr_get(context->keys, name);
df158262f802 fixed dav_context_get_key
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
152 }
242
a39be87d34d4 fixed install target and a missing return statement in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
153 return NULL;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
154 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
155
317
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
156 int dav_add_namespace(DavContext *context, const char *prefix, const char *name) {
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 DavNamespace *namespace = malloc(sizeof(DavNamespace));
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 if(!namespace) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 return 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 }
607
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
161
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
162 char *p = strdup(prefix);
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
163 char *n = strdup(name);
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
164
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
165 int err = 0;
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
166 if(p && n) {
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
167 namespace->prefix = p;
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
168 namespace->name = n;
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
169 err = ucx_map_cstr_put(context->namespaces, prefix, namespace);
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
170 }
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
171
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
172 if(err) {
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
173 free(namespace);
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
174 if(p) free(p);
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
175 if(n) free(n);
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
176 }
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
177
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
178 return err;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180
317
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
181 DavNamespace* dav_get_namespace(DavContext *context, const char *prefix) {
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 return ucx_map_cstr_get(context->namespaces, prefix);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 DavNamespace* dav_get_namespace_s(DavContext *context, sstr_t prefix) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 return ucx_map_sstr_get(context->namespaces, prefix);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
189 int dav_enable_namespace_encryption(DavContext *context, const char *ns, DavBool encrypt) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
190 DavNSInfo *info = ucx_map_cstr_get(context->namespaceinfo, ns);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
191 if(!info) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
192 info = calloc(1, sizeof(DavNSInfo));
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
193 info->encrypt = encrypt;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
194 ucx_map_cstr_put(context->namespaceinfo, ns, info);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
195 } else {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
196 info->encrypt = encrypt;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
197 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
198 return 0;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
199 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
200
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
201 int dav_namespace_is_encrypted(DavContext *context, const char *ns) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
202 DavNSInfo *info = ucx_map_cstr_get(context->namespaceinfo, ns);
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
203 if(info) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
204 return info->encrypt;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
205 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
206 return 0;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
207 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
208
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
209 void dav_get_property_namespace_str(
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 DavContext *ctx,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 char *prefixed_name,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 char **ns,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 char **name)
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 {
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
215 // TODO: rewrite using dav_get_property_ns
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
216
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 char *pname = strchr(prefixed_name, ':');
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 char *pns = "DAV:";
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 if(pname) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 DavNamespace *ns = dav_get_namespace_s(
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 ctx,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 sstrn(prefixed_name, pname-prefixed_name));
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
223 if(ns) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
224 pns = ns->name;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
225 pname++;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
226 } else {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
227 pns = NULL;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
228 pname = NULL;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
229 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 } else {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 pname = prefixed_name;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 *ns = pns;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 *name = pname;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
237 DavNamespace* dav_get_property_namespace(
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
238 DavContext *ctx,
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
239 char *prefixed_name,
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
240 char **name)
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
241 {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
242 char *pname = strchr(prefixed_name, ':');
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
243 if(pname) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
244 DavNamespace *ns = dav_get_namespace_s(
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
245 ctx,
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
246 sstrn(prefixed_name, pname-prefixed_name));
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
247 if(ns) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
248 *name = pname +1;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
249 return ns;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
250 } else {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
251 *name = NULL;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
252 return NULL;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
253 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
254 } else {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
255 *name = prefixed_name;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
256 return dav_get_namespace_s(ctx, S("D"));
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
257 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
258 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
259
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
260 // TODO: add sstr_t version of dav_get_property_ns
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
261
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
262 void dav_set_effective_href(DavSession *sn, DavResource *resource) {
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
263 char *eff_url;
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
264 curl_easy_getinfo(sn->handle, CURLINFO_EFFECTIVE_URL, &eff_url);
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
265 if(eff_url) {
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
266 char *href = util_url_path(eff_url);
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
267 if(strcmp(href, resource->href)) {
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
268 dav_session_free(sn, resource->href);
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
269 resource->href = dav_session_strdup(sn, href);
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
270 }
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
271 }
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
272 }
39
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
273
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
274 DavResource* dav_get(DavSession *sn, char *path, char *properties) {
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 CURL *handle = sn->handle;
48
08d5544c92fb fixed etag handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
276 DavResource *resource = dav_resource_new(sn, path);
08d5544c92fb fixed etag handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
277 util_set_url(sn, dav_resource_get_href(resource));
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 UcxList *proplist = NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280 if(properties) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281 proplist = parse_properties_string(sn->context, sstr(properties));
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 }
475
52e4171d42ce adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
283 UcxBuffer *rqbuf = create_propfind_request(sn, proplist, "propfind", 0);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 UcxBuffer *rpbuf = ucx_buffer_new(NULL, 4096, UCX_BUFFER_AUTOEXTEND);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 //fwrite(rqbuf->space, 1, rqbuf->size, stdout);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 //printf("\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
289 CURLcode ret = do_propfind_request(sn, rqbuf, rpbuf);
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
290 long status = 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 if(ret == CURLE_OK && status == 207) {
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
293 dav_set_effective_href(sn, resource);
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
294
48
08d5544c92fb fixed etag handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
295 //printf("response\n%s\n", rpbuf->space);
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
296 // TODO: use PropfindParser
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
297 resource = parse_propfind_response(sn, resource, rpbuf);
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
298 resource->exists = 1;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 sn->error = DAV_OK;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 } else {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
301 dav_session_set_error(sn, ret, status);
48
08d5544c92fb fixed etag handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
302 dav_resource_free(resource);
66
f8c1f685e08e some bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
303 resource = NULL;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
305
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
306 ucx_buffer_free(rqbuf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
307 ucx_buffer_free(rpbuf);
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
308 while(proplist) {
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
309 DavProperty *p = proplist->data;
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
310 free(p->name);
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
311 free(p);
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
312 UcxList *next = proplist->next;
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
313 free(proplist);
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
314 proplist = next;
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
315 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
316
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
317 return resource;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
318 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
320
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
321 int dav_propfind(DavSession *sn, DavResource *root, UcxBuffer *rqbuf) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
322 // clean resource properties
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
323 DavResourceData *data = root->data;
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
324 ucx_map_clear(data->properties); // TODO: free existing content
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
325
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 CURL *handle = sn->handle;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
327 util_set_url(sn, dav_resource_get_href(root));
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
328
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329 UcxBuffer *rpbuf = ucx_buffer_new(NULL, 4096, UCX_BUFFER_AUTOEXTEND);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330 DavResource *resource = root;
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
331 CURLcode ret = do_propfind_request(sn, rqbuf, rpbuf);
292
0a47ffc8b73b fixes wrong int type that results in a crash on some platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
332 long status = 0;
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
333 long error = 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 if(ret == CURLE_OK && status == 207) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336 //printf("response\n%s\n", rpbuf->space);
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
337 dav_set_effective_href(sn, resource);
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
338 // TODO: use PropfindParser
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
339 resource = parse_propfind_response(sn, resource, rpbuf);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 sn->error = DAV_OK;
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
341 root->exists = 1;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 } else {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
343 dav_session_set_error(sn, ret, status);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
344 error = 1;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346 ucx_buffer_free(rpbuf);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
347 return error;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
348 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
349
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
350 UcxList* parse_properties_string(DavContext *context, sstr_t str) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
351 UcxList *proplist = NULL;
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
352 ssize_t nprops = 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
353 sstr_t *props = sstrsplit(str, S(","), &nprops);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
354 for(int i=0;i<nprops;i++) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
355 sstr_t s = props[i];
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
356 sstr_t nsname = sstrchr(s, ':');
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
357 if(nsname.length > 0) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
358 sstr_t nspre = sstrsubsl(s, 0, nsname.ptr - s.ptr);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
359 nsname.ptr++;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
360 nsname.length--;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
361
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
362 DavProperty *dp = malloc(sizeof(DavProperty));
45
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
363 sstr_t pre = sstrtrim(nspre);
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
364 dp->ns = dav_get_namespace_s(context, pre);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
365 dp->name = sstrdup(nsname).ptr;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
366 if(dp->ns && dp->name) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367 proplist = ucx_list_append(proplist, dp);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
368 } else {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
369 free(dp->name);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
370 free(dp);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
371 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
372 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
373 free(s.ptr);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
374 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
375 free(props);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
376 return proplist;
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
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
379 DavResource* dav_query(DavSession *sn, char *query, ...) {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
380 DavQLStatement *stmt = dav_parse_statement(sstr(query));
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
381 if(!stmt) {
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
382 sn->error = DAV_ERROR;
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
383 return NULL;
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
384 }
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
385 if(stmt->errorcode != 0) {
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
386 sn->error = DAV_QL_ERROR;
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
387 dav_free_statement(stmt);
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
388 return NULL;
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
389 }
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
390
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
391 va_list ap;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
392 va_start(ap, query);
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
393 DavResult result = dav_statement_execv(sn, stmt, ap);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
394 va_end(ap);
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
395
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
396 dav_free_statement(stmt);
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
397 return result.result;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
398 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
399
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
400
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
401
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
402

mercurial