libidav/webdav.c

Thu, 23 May 2024 23:23:36 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 23 May 2024 23:23:36 +0200
changeset 818
bc782cca0759
parent 816
839fefbdedc7
child 829
122ddf40e24f
permissions
-rw-r--r--

merge branch ucx-3.1

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"
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
38 #include <cx/buffer.h>
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
39 #include <cx/utils.h>
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
40 #include <cx/linked_list.h>
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
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: 645
diff changeset
42 #include <cx/compare.h>
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
43 #include "davqlparser.h"
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
44 #include "davqlexec.h"
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
587
3c917df041b8 add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
47 DavContext* dav_context_new(void) {
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
48 // initialize
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
49 DavContext *context = calloc(1, sizeof(DavContext));
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 if(!context) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 return NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
53 context->sessions = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_intptr, CX_STORE_POINTERS);
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 805
diff changeset
54 cxDefineDestructor(context->sessions, dav_session_destructor);
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
55 context->http_proxy = calloc(1, sizeof(DavProxy));
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
56 if(!context->http_proxy) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
57 dav_context_destroy(context);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
58 return NULL;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
59 }
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
60 context->https_proxy = calloc(1, sizeof(DavProxy));
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
61 if(!context->https_proxy) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
62 dav_context_destroy(context);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
63 return NULL;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
64 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
65 context->namespaces = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 if(!context->namespaces) {
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
67 dav_context_destroy(context);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 return NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
70 context->namespaceinfo = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16);
645
ad61c1654dce fix missing namespaceinfo map initializataion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
71 if(!context->namespaceinfo) {
ad61c1654dce fix missing namespaceinfo map initializataion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
72 dav_context_destroy(context);
ad61c1654dce fix missing namespaceinfo map initializataion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
73 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
74 context->keys = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16);
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
75 if(!context->keys) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
76 dav_context_destroy(context);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 return NULL;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
80 // add DAV: namespace
607
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
81 if(dav_add_namespace(context, "D", "DAV:")) {
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
82 dav_context_destroy(context);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
83 return NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
84 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
85
607
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
86
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
87 // add idav namespace
607
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
88 if(dav_add_namespace(context, "idav", DAV_NS)) {
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
89 dav_context_destroy(context);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
90 return NULL;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
91 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
92
607
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
93 // add idavprops namespace
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
94 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
95 dav_context_destroy(context);
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
96 return NULL;
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
97 }
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
98
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 return context;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 void dav_context_destroy(DavContext *ctx) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 // destroy all sessions assoziated with this context
790
7110b37f2a6b fix dav_context_destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 788
diff changeset
104 // ctx->sessions destructor must be dav_session_destructor
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
105 cxListDestroy(ctx->sessions);
790
7110b37f2a6b fix dav_context_destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 788
diff changeset
106
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
107 if(ctx->http_proxy) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
108 free(ctx->http_proxy);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
109 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
110 if(ctx->https_proxy) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
111 free(ctx->https_proxy);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
112 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
114 if(ctx->namespaces) {
790
7110b37f2a6b fix dav_context_destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 788
diff changeset
115 CxIterator i = cxMapIteratorValues(ctx->namespaces);
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
116 cx_foreach(DavNamespace*, ns, i) {
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
117 if(!ns) continue;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
118 if(ns->prefix) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
119 free(ns->prefix);
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 if(ns->name) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
122 free(ns->name);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
123 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
124 free(ns);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
125 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
126 cxMapDestroy(ctx->namespaces);
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
127 }
645
ad61c1654dce fix missing namespaceinfo map initializataion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
128 if(ctx->namespaceinfo) {
ad61c1654dce fix missing namespaceinfo map initializataion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
129 // TODO: implement
ad61c1654dce fix missing namespaceinfo map initializataion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
130 }
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
131 if(ctx->keys) {
790
7110b37f2a6b fix dav_context_destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 788
diff changeset
132 CxIterator i = cxMapIteratorValues(ctx->keys);
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
133 cx_foreach(DavKey*, key, i) {
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
134 if(!key) continue;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
135 if(key->name) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
136 free(key->name);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
137 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
138 if(key->data) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
139 free(key->data);
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 free(key);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
142 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
143 cxMapDestroy(ctx->keys);
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
144 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
145
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 free(ctx);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
149 #ifndef _WIN32
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
150
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
151 void dav_context_set_mtsafe(DavContext *ctx, DavBool enable) {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
152 if (enable) {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
153 pthread_mutex_init(&ctx->mutex, NULL);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
154 } else {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
155 pthread_mutex_destroy(&ctx->mutex);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
156 }
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
157 ctx->mtsafe = enable;
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
158 }
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
159
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
160 void dav_context_lock(DavContext *ctx) {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
161 if (ctx->mtsafe) {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
162 pthread_mutex_lock(&ctx->mutex);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
163 }
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
164 }
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
165
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
166 void dav_context_unlock(DavContext *ctx) {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
167 if (ctx->mtsafe) {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
168 pthread_mutex_unlock(&ctx->mutex);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
169 }
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
170 }
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
171
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
172 #else
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
173
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
174 void dav_context_set_mtsafe(DavContext *ctx, DavBool enable) {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
175 if (enable) {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
176 ctx->mutex = CreateMutex(NULL, FALSE, NULL);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
177 } else {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
178 CloseHandle(ctx->mutex);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
179 }
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
180 ctx->mtsafe = enable;
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
181 }
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
182
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
183 void dav_context_lock(DavContext *ctx) {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
184 if (ctx->mtsafe) {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
185 WaitForSingleObject(ctx->mutex, INFINITE);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
186 }
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
187 }
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
188
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
189 void dav_context_unlock(DavContext *ctx) {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
190 if (ctx->mtsafe) {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
191 ReleaseMutex(ctx->mutex);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
192 }
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
193 }
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
194
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
195 #endif
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
196
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
197 void dav_context_add_key(DavContext *context, DavKey *key) {
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
198 dav_context_lock(context);
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
199 cxMapPut(context->keys, cx_hash_key_str(key->name), key);
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
200 dav_context_unlock(context);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
201 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
202
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
203 DavKey* dav_context_get_key(DavContext *context, const char *name) {
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
204 DavKey *key = NULL;
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
205 dav_context_lock(context);
229
df158262f802 fixed dav_context_get_key
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
206 if(name) {
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
207 key = cxMapGet(context->keys, cx_hash_key_str(name));
229
df158262f802 fixed dav_context_get_key
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
208 }
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
209 dav_context_unlock(context);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
210 return key;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
211 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
212
317
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
213 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
214 DavNamespace *namespace = malloc(sizeof(DavNamespace));
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 if(!namespace) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 return 1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 }
607
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
218
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
219 char *p = strdup(prefix);
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
220 if (!p) {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
221 free(namespace);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
222 return 1;
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
223 }
607
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
224 char *n = strdup(name);
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
225 if (!n) {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
226 free(namespace);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
227 free(p);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
228 return 1;
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
229 }
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
230
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
231 dav_context_lock(context);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
232
607
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
233 int err = 0;
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
234 if(p && n) {
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
235 namespace->prefix = p;
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
236 namespace->name = n;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
237 err = cxMapPut(context->namespaces, cx_hash_key_str(prefix), namespace);
607
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
238 }
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
239
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
240 if(err) {
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
241 free(namespace);
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
242 if(p) free(p);
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
243 if(n) free(n);
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
244 }
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
245
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
246 dav_context_unlock(context);
607
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
247
5dc7fe41e8f8 move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 587
diff changeset
248 return err;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250
317
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
251 DavNamespace* dav_get_namespace(DavContext *context, const char *prefix) {
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
252 dav_context_lock(context);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
253 DavNamespace *ns = cxMapGet(context->namespaces, cx_hash_key_str(prefix));
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
254 dav_context_unlock(context);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
255 return ns;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
258 DavNamespace* dav_get_namespace_s(DavContext *context, cxstring prefix) {
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
259 dav_context_lock(context);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
260 DavNamespace *ns = cxMapGet(context->namespaces, cx_hash_key(prefix.ptr, prefix.length));
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
261 dav_context_unlock(context);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
262 return ns;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
265 int dav_enable_namespace_encryption(DavContext *context, const char *ns, DavBool encrypt) {
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
266 dav_context_lock(context);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
267
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
268 CxHashKey hkey = cx_hash_key_str(ns);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
269 DavNSInfo *info = cxMapGet(context->namespaceinfo, hkey);
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
270 if(!info) {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
271 info = calloc(1, sizeof(DavNSInfo));
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
272 info->encrypt = encrypt;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
273 cxMapPut(context->namespaceinfo, hkey, info);
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
274 } else {
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
275 info->encrypt = encrypt;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
276 }
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
277
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
278 dav_context_unlock(context);
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
279 return 0;
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
280 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
281
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
282 int dav_namespace_is_encrypted(DavContext *context, const char *ns) {
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
283 int ret = 0;
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
284 dav_context_lock(context);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
285
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
286 DavNSInfo *info = cxMapGet(context->namespaceinfo, cx_hash_key_str(ns));
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
287 if(info) {
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
288 ret = info->encrypt;
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
289 }
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
290 dav_context_unlock(context);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
291 return ret;
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
292 }
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
293
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
294 void dav_get_property_namespace_str(
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 DavContext *ctx,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 char *prefixed_name,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 char **ns,
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 char **name)
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 {
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
300 // TODO: rewrite using dav_get_property_ns
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
301
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 char *pname = strchr(prefixed_name, ':');
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303 char *pns = "DAV:";
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 if(pname) {
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 805
diff changeset
305 DavNamespace *davns = dav_get_namespace_s(
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 ctx,
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
307 cx_strn(prefixed_name, pname-prefixed_name));
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 805
diff changeset
308 if(davns) {
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 805
diff changeset
309 pns = davns->name;
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
310 pname++;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
311 } else {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
312 pns = NULL;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
313 pname = NULL;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
314 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315 } else {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
316 pname = prefixed_name;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
317 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
318 *ns = pns;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319 *name = pname;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
321
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
322 DavNamespace* dav_get_property_namespace(
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
323 DavContext *ctx,
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
324 char *prefixed_name,
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
325 char **name)
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
326 {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
327 char *pname = strchr(prefixed_name, ':');
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
328 if(pname) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
329 DavNamespace *ns = dav_get_namespace_s(
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
330 ctx,
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
331 cx_strn(prefixed_name, pname-prefixed_name));
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
332 if(ns) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
333 *name = pname +1;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
334 return ns;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
335 } else {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
336 *name = NULL;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
337 return NULL;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
338 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
339 } else {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
340 *name = prefixed_name;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
341 return dav_get_namespace_s(ctx, cx_str("D"));
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
342 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
343 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
344
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
345 int dav_context_add_session(DavContext *context, DavSession *sn) {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
346 dav_context_lock(context);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
347 int ret = cxListAdd(context->sessions, sn);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
348 dav_context_unlock(context);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
349 return ret;
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
350 }
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
351
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
352 int dav_context_remove_session(DavContext *context, DavSession *sn) {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
353 int ret = 0;
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
354 dav_context_lock(context);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
355 CxList *sessions = context->sessions;
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
356 ssize_t i = cxListFind(sessions, sn);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
357 if(i >= 0) {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
358 cxListRemove(sessions, i);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
359 } else {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
360 ret = 1;
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
361 }
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
362 dav_context_unlock(context);
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
363 return ret;
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
364 }
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
365
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
366
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
367 // 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
368
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
369 void dav_set_effective_href(DavSession *sn, DavResource *resource) {
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
370 char *eff_url;
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
371 curl_easy_getinfo(sn->handle, CURLINFO_EFFECTIVE_URL, &eff_url);
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
372 if(eff_url) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
373 const char *href = util_url_path(eff_url);
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
374 if(strcmp(href, resource->href)) {
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
375 dav_session_free(sn, resource->href);
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
376 resource->href = dav_session_strdup(sn, href);
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
377 }
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
378 }
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
379 }
39
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
380
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
381 DavResource* dav_get(DavSession *sn, char *path, const char *properties) {
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
382 CURL *handle = sn->handle;
48
08d5544c92fb fixed etag handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
383 DavResource *resource = dav_resource_new(sn, path);
08d5544c92fb fixed etag handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
384 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
385
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
386 CxList *proplist = NULL;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
387 if(properties) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
388 proplist = parse_properties_string(sn->context, cx_str(properties));
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
389 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
390 CxBuffer *rqbuf = create_propfind_request(sn, proplist, "propfind", 0);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
391 CxBuffer *rpbuf = cxBufferCreate(NULL, 4096, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
392
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
393 //fwrite(rqbuf->space, 1, rqbuf->size, stdout);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
394 //printf("\n");
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
395
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
396 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
397 long status = 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
398 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
399 if(ret == CURLE_OK && status == 207) {
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
400 dav_set_effective_href(sn, resource);
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
401
48
08d5544c92fb fixed etag handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
402 //printf("response\n%s\n", rpbuf->space);
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
403 // TODO: use PropfindParser
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
404 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
405 resource->exists = 1;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
406 sn->error = DAV_OK;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
407 } else {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
408 dav_session_set_error(sn, ret, status);
48
08d5544c92fb fixed etag handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
409 dav_resource_free(resource);
66
f8c1f685e08e some bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
410 resource = NULL;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
411 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
412
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
413 cxBufferFree(rqbuf);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
414 cxBufferFree(rpbuf);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
415
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
416 if(proplist) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
417 CxIterator i = cxListIterator(proplist);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
418 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: 645
diff changeset
419 free(p->name);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
420 }
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
421 cxListDestroy(proplist);
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
422 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
423
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
424 return resource;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
425 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
426
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
427
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
428 int dav_propfind(DavSession *sn, DavResource *root, CxBuffer *rqbuf) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
429 // clean resource properties
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
430 DavResourceData *data = root->data;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
431 cxMapClear(data->properties); // TODO: free existing content
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
432
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
433 CURL *handle = sn->handle;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
434 util_set_url(sn, dav_resource_get_href(root));
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
435
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
436 CxBuffer *rpbuf = cxBufferCreate(NULL, 4096, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
437 DavResource *resource = root;
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
438 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
439 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
440 long error = 0;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
441 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
442 if(ret == CURLE_OK && status == 207) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
443 //printf("response\n%s\n", rpbuf->space);
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
444 dav_set_effective_href(sn, resource);
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 607
diff changeset
445 // TODO: use PropfindParser
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
446 resource = parse_propfind_response(sn, resource, rpbuf);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
447 sn->error = DAV_OK;
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
448 root->exists = 1;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
449 } else {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
450 dav_session_set_error(sn, ret, status);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
451 error = 1;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
452 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
453 cxBufferFree(rpbuf);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
454 return error;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
455 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
456
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
457 CxList* parse_properties_string(DavContext *context, cxstring str) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
458 CxList *proplist = cxLinkedListCreateSimple(sizeof(DavProperty));
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
459
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
460 CxStrtokCtx tok = cx_strtok(str, cx_str(","), INT_MAX);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
461 cxstring s;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
462 while(cx_strtok_next(&tok, &s)) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
463 cxstring nsname = cx_strchr(s, ':');
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
464 if(nsname.length > 0) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
465 cxstring nspre = cx_strsubsl(s, 0, nsname.ptr - s.ptr);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
466 nsname.ptr++;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
467 nsname.length--;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
468
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
469 DavProperty dp;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
470 cxstring pre = cx_strtrim(nspre);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
471 dp.ns = dav_get_namespace_s(context, pre);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
472 dp.name = cx_strdup(nsname).ptr;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
473 dp.value = NULL;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
474 if(dp.ns && dp.name) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
475 cxListAdd(proplist, &dp);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
476 } else {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
477 free(dp.name);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
478 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
479 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
480 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
481
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
482 return proplist;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
483 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
484
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
485 DavResource* dav_query(DavSession *sn, char *query, ...) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 645
diff changeset
486 DavQLStatement *stmt = dav_parse_statement(cx_str(query));
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
487 if(!stmt) {
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
488 sn->error = DAV_ERROR;
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
489 return NULL;
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
490 }
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
491 if(stmt->errorcode != 0) {
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
492 sn->error = DAV_QL_ERROR;
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
493 dav_free_statement(stmt);
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
494 return NULL;
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
495 }
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
496
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
497 va_list ap;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
498 va_start(ap, query);
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
499 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
500 va_end(ap);
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
501
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
502 dav_free_statement(stmt);
786
f9d6e4cbcb62 return NULL when a davql query fails
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
503
f9d6e4cbcb62 return NULL when a davql query fails
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
504 if(result.status == -1) {
f9d6e4cbcb62 return NULL when a davql query fails
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
505 if(result.result) {
f9d6e4cbcb62 return NULL when a davql query fails
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
506 dav_resource_free(result.result);
f9d6e4cbcb62 return NULL when a davql query fails
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
507 result.result = NULL;
f9d6e4cbcb62 return NULL when a davql query fails
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
508 }
f9d6e4cbcb62 return NULL when a davql query fails
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
509 }
f9d6e4cbcb62 return NULL when a davql query fails
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
510
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
511 return result.result;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
512 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
513
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
514
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
515
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
516
788
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 786
diff changeset
517 void dav_verbose_log(
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 786
diff changeset
518 DavSession *sn,
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 786
diff changeset
519 const char *method,
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 786
diff changeset
520 const char *url,
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 786
diff changeset
521 const char *request_body,
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 786
diff changeset
522 size_t request_bodylen,
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 786
diff changeset
523 int status,
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 786
diff changeset
524 const char *response_body,
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 786
diff changeset
525 size_t response_bodylen)
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 786
diff changeset
526 {
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 786
diff changeset
527 fprintf(stderr, "# method: %s url: %s status: %d\n", method, url, status);
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 786
diff changeset
528 fprintf(stderr, "# request len: %d\n%.*s\n", (int)request_bodylen, (int)request_bodylen, request_body);
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 786
diff changeset
529 fprintf(stderr, "# response len: %d\n%.*s\n", (int)response_bodylen, (int)response_bodylen, response_body);
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 786
diff changeset
530 }

mercurial