src/server/webdav/webdav.c

Sun, 13 Nov 2022 12:58:25 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 13 Nov 2022 12:58:25 +0100
changeset 433
39fe86ae4db0
parent 415
d938228c382e
child 453
4586d534f9b5
permissions
-rw-r--r--

use non-blocking IO for pipes and socket in send_cgi

13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
4 * Copyright 2019 Olaf Wintermann. All rights reserved.
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1fdbf4170ef4 Added webdav code
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
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
33 #include <cx/buffer.h>
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
34 #include <cx/list.h>
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
35 #include <cx/linked_list.h>
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
36 #include <cx/hash_map.h>
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
37 #include <cx/printf.h>
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
38
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 #include "webdav.h"
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
41 #include "search.h"
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
42 #include "versioning.h"
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
43 #include "multistatus.h"
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
44 #include "requestparser.h"
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
45 #include "operation.h"
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
46
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
47 #include "../util/pblock.h"
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
48 #include "../util/util.h"
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
49 #include "../daemon/session.h"
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
50 #include "../daemon/http.h"
235
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
51 #include "../daemon/protocol.h"
246
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
52 #include "../daemon/vfs.h"
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
53
301
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
54 /*
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
55 * http method fptr mapping
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
56 * key: http method name (string)
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
57 * value: SAF fptr
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
58 */
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
59 static CxMap *method_handler_map;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
60
301
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
61 /*
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
62 * webdav backend types
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
63 * key: backend name (string)
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
64 * value: WebdavBackend*
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
65 */
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
66 static CxMap *webdav_type_map;
301
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
67
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
68 static WebdavBackend default_backend;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
69
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
70 static WSNamespace dav_namespace;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
71
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
72 static WebdavProperty dav_resourcetype_empty;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
73 static WebdavProperty dav_resourcetype_collection;
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
74 static WSXmlData dav_resourcetype_collection_value;
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
75
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
76 #define WEBDAV_RESOURCE_TYPE_COLLECTION "<D:collection/>"
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
77
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
78 static void init_default_backend(void) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
79 memset(&default_backend, 0, sizeof(WebdavBackend));
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
80 default_backend.propfind_init = default_propfind_init;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
81 default_backend.propfind_do = default_propfind_do;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
82 default_backend.propfind_finish = default_propfind_finish;
243
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
83 default_backend.proppatch_do = default_proppatch_do;
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
84 default_backend.proppatch_finish = default_proppatch_finish;
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
85 default_backend.opt_mkcol = NULL;
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
86 default_backend.opt_delete = NULL;
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
87 default_backend.settings = WS_WEBDAV_PROPFIND_USE_VFS;
300
0e3f275b2492 add instance field to webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 262
diff changeset
88 default_backend.instance = NULL;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
89 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
90
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
91 int webdav_register_backend(const char *name, webdav_init_func webdavInit, webdav_create_func webdavCreate) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
92 WebdavType *webdavType = malloc(sizeof(WebdavType));
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
93 webdavType->init = webdavInit;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
94 webdavType->create = webdavCreate;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
95 return cxMapPut(webdav_type_map, cx_hash_key_str(name), webdavType);
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
96 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
97
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
98 WebdavType* webdav_get_type(cxstring dav_class) {
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
99 return cxMapGet(webdav_type_map, cx_hash_key_bytes((unsigned const char *)dav_class.ptr, dav_class.length));
301
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
100 }
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
101
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
102 void* webdav_init_backend(ServerConfiguration *cfg, pool_handle_t *pool, WebdavType *dav_class, WSConfigNode *config, int *error) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
103 *error = 0;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
104 if(dav_class->init) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
105 void *initData = dav_class->init(cfg, pool, config);
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
106 if(!initData) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
107 *error = 1;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
108 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
109 return initData;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
110 } else {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
111 return NULL;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
112 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
113 }
325
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 322
diff changeset
114
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
115 WebdavBackend* webdav_create(Session *sn, Request *rq, const char *dav_class, pblock *pb, void *initData) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
116 WebdavType *webdavType = cxMapGet(webdav_type_map, cx_hash_key_str(dav_class));
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
117 if(!webdavType) {
325
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 322
diff changeset
118 log_ereport(LOG_MISCONFIG, "webdav_create: unkown dav type %s", dav_class);
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 322
diff changeset
119 return NULL;
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 322
diff changeset
120 }
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 322
diff changeset
121
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 352
diff changeset
122 return webdavType->create(sn, rq, pb, initData);
325
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 322
diff changeset
123 }
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 322
diff changeset
124
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
125 static WSBool webdav_is_initialized = FALSE;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
126
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
127 int webdav_init(pblock *pb, Session *sn, Request *rq) {
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
128 if(webdav_is_initialized) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
129 return REQ_NOACTION;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
130 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
131 webdav_is_initialized = TRUE;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
132
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
133 webdav_type_map = cxHashMapCreate(cxDefaultAllocator, 8);
301
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
134 if(!webdav_type_map) {
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
135 return REQ_ABORTED;
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
136 }
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
137
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
138 method_handler_map = cxHashMapCreate(cxDefaultAllocator, 64);
301
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
139 if(!method_handler_map) {
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
140 return REQ_ABORTED;
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
141 }
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
142
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
143 init_default_backend();
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
144 cxMapPut(webdav_type_map, cx_hash_key_str("default"), &default_backend);
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
145
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
146 cxMapPut(method_handler_map, cx_hash_key_str("OPTIONS"), webdav_options);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
147 cxMapPut(method_handler_map, cx_hash_key_str("PROPFIND"), webdav_propfind);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
148 cxMapPut(method_handler_map, cx_hash_key_str("PROPPATCH"), webdav_proppatch);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
149 cxMapPut(method_handler_map, cx_hash_key_str("MKCOL"), webdav_mkcol);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
150 cxMapPut(method_handler_map, cx_hash_key_str("POST"), webdav_post);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
151 cxMapPut(method_handler_map, cx_hash_key_str("DELETE"), webdav_delete);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
152 cxMapPut(method_handler_map, cx_hash_key_str("PUT"), webdav_put);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
153 cxMapPut(method_handler_map, cx_hash_key_str("COPY"), webdav_copy);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
154 cxMapPut(method_handler_map, cx_hash_key_str("MOVE"), webdav_move);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
155 cxMapPut(method_handler_map, cx_hash_key_str("LOCK"), webdav_lock);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
156 cxMapPut(method_handler_map, cx_hash_key_str("UNLOCK"), webdav_unlock);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
157 cxMapPut(method_handler_map, cx_hash_key_str("REPORT"), webdav_report);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
158 cxMapPut(method_handler_map, cx_hash_key_str("ACL"), webdav_acl);
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
159
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
160 cxMapPut(method_handler_map, cx_hash_key_str("SEARCH"), webdav_search);
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
161
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
162 cxMapPut(method_handler_map, cx_hash_key_str("VERSION-CONTROL"), webdav_version_control);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
163 cxMapPut(method_handler_map, cx_hash_key_str("CHECKOUT"), webdav_checkout);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
164 cxMapPut(method_handler_map, cx_hash_key_str("CHECKIN"), webdav_checkin);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
165 cxMapPut(method_handler_map, cx_hash_key_str("UNCHECKOUT"), webdav_uncheckout);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
166 cxMapPut(method_handler_map, cx_hash_key_str("MKWORKSPACE"), webdav_mkworkspace);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
167 cxMapPut(method_handler_map, cx_hash_key_str("UPDATE"), webdav_update);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
168 cxMapPut(method_handler_map, cx_hash_key_str("LABEL"), webdav_label);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
169 cxMapPut(method_handler_map, cx_hash_key_str("MERGE"), webdav_merge);
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
170
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
171 dav_namespace.href = (xmlChar*)"DAV:";
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
172 dav_namespace.prefix = (xmlChar*)"D";
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
173
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
174 dav_resourcetype_empty.namespace = &dav_namespace;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
175 dav_resourcetype_empty.name = "resourcetype";
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
176
381
7d55d60e1fe2 fix resourcetype initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 376
diff changeset
177 dav_resourcetype_collection_value.data = WEBDAV_RESOURCE_TYPE_COLLECTION;
7d55d60e1fe2 fix resourcetype initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 376
diff changeset
178 dav_resourcetype_collection_value.length = sizeof(WEBDAV_RESOURCE_TYPE_COLLECTION)-1;
7d55d60e1fe2 fix resourcetype initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 376
diff changeset
179
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
180 dav_resourcetype_collection.namespace = &dav_namespace;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
181 dav_resourcetype_collection.name = "resourcetype";
376
61d481d3c2e4 Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 373
diff changeset
182 dav_resourcetype_collection.value.data = dav_resourcetype_collection_value;
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
183 dav_resourcetype_collection.vtype = WS_VALUE_XML_DATA;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
184
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
185 return REQ_PROCEED;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
186 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
187
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
188
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
189 int webdav_service(pblock *pb, Session *sn, Request *rq) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
190 if(!method_handler_map) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
191 log_ereport(LOG_FAILURE, "WebDAV module not initialized");
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
192 protocol_status(sn, rq, 500, NULL);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
193 return REQ_ABORTED;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
194 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
195 char *method = pblock_findkeyval(pb_key_method, rq->reqpb);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
196
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
197 FuncPtr saf = (FuncPtr)cxMapGet(method_handler_map, cx_hash_key_str(method));
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
198 if(!saf) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
199 return REQ_NOACTION;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
200 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
201
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
202 return saf(pb, sn, rq);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
203 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
204
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
205 int rqbody2buffer(Session *sn, Request *rq, CxBuffer *buf) {
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
206 if(!sn->inbuf) {
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
207 //request body required, set http response code
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
208 protocol_status(sn, rq, 400, NULL);
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
209 return 1;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
210 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
211
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
212 CxAllocator *a = pool_allocator(sn->pool);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
213 if(cxBufferInit(buf, NULL, sn->inbuf->maxsize, a, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS)) {
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
214 protocol_status(sn, rq, 500, NULL);
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
215 return 1;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
216 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
217
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
218 char in[2048];
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
219 int r;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
220 while((r = netbuf_getbytes(sn->inbuf, in, 2048)) > 0) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
221 if(cxBufferWrite(in, 1, r, buf) != r) {
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
222 protocol_status(sn, rq, 500, NULL);
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
223 cxBufferDestroy(buf);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
224 return 1;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
225 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
226 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
227
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
228 return 0;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
229 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
230
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
231 int webdav_options(pblock *pb, Session *sn, Request *rq) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
232 return REQ_ABORTED;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
233 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
234
414
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
235 static const char* propfind_error2str(int error) {
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
236 switch(error) {
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
237 case PROPFIND_PARSER_OK: return "ok";
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
238 case PROPFIND_PARSER_NO_PROPFIND: return "invalid xml root element";
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
239 case PROPFIND_PARSER_NO_PROPERTIES: return "no properties specified";
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
240 case PROPFIND_PARSER_INVALID_REQUEST: return "invalid propfind request";
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
241 case PROPFIND_PARSER_OOM: return "OOM";
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
242 case PROPFIND_PARSER_ERROR: return "error";
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
243 }
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
244 return "";
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
245 }
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
246
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
247 int webdav_propfind(pblock *pb, Session *sn, Request *rq) {
235
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
248 char *expect = pblock_findkeyval(pb_key_expect, rq->headers);
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
249 if(expect) {
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
250 if(!strcasecmp(expect, "100-continue")) {
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
251 if(http_send_continue(sn)) {
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
252 return REQ_ABORTED;
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
253 }
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
254 }
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
255 }
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
256
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
257 CxBuffer reqbody;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
258 if(rqbody2buffer(sn, rq, &reqbody)) {
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
259 return REQ_ABORTED;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
260 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
261
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
262 int error = 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
263 WebdavPropfindRequest *propfind = propfind_parse(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
264 sn,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
265 rq,
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
266 reqbody.space,
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
267 reqbody.size,
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
268 &error);
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
269 cxBufferDestroy(&reqbody);
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
270 if(!propfind) {
414
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
271 log_ereport(LOG_FAILURE, "webdav-propfind: %s", propfind_error2str(error));
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
272 return REQ_ABORTED;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
273 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
274
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
275 WebdavBackend *dav = rq->davCollection ?
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
276 rq->davCollection : &default_backend;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
277
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
278
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
279 // requested uri and path
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
280 char *path = pblock_findkeyval(pb_key_path, rq->vars);
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
281 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
282
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
283 // The multistatus response object contains responses for all
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
284 // requested resources. At the end the Multistatus object will be
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
285 // serialized to xml
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
286 Multistatus *ms = multistatus_response(sn, rq);
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
287 if(!ms) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
288 return REQ_ABORTED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
289 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
290
252
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
291 int ret = webdav_propfind_do(dav, propfind, (WebdavResponse*)ms, NULL, path, uri);
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
292
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
293 // if propfind was successful, send the result to the client
414
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
294 if(ret == REQ_PROCEED) {
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
295 if(multistatus_send(ms, sn->csd)) {
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
296 ret = REQ_ABORTED;
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
297 }
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
298 } else {
414
99a34860c105 improve propfind error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
299 log_ereport(LOG_FAILURE, "webdav-propfind: operation failed");
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
300 }
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
301
252
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
302 // cleanup
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
303 if(propfind->doc) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
304 xmlFreeDoc(propfind->doc);
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
305 }
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
306
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
307 return ret;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
308 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
309
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
310 /*
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
311 * Initializes Backend Chain
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
312 *
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
313 * Calls propfind_init of each Backend and generates a list of custom
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
314 * WebdavPropfindRequest objects for each backend
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
315 */
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
316 int webdav_propfind_init(
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
317 WebdavBackend *dav,
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
318 WebdavPropfindRequest *propfind,
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
319 const char *path,
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
320 const char *uri,
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
321 WebdavPropfindRequestList **out_req)
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
322 {
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
323 pool_handle_t *pool = propfind->sn->pool;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
324 CxAllocator *a = pool_allocator(pool);
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
325
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
326 // list of individual WebdavPropfindRequest objects for each Backend
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
327 WebdavPropfindRequestList *requestObjectsBegin = NULL;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
328 WebdavPropfindRequestList *requestObjectsEnd = NULL;
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
329
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
330 // new properties after init, start with clone of original plist
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
331 WebdavPList *newProp = webdav_plist_clone(pool, propfind->properties);
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
332 size_t newPropCount = propfind->propcount;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
333
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
334 // Call propfind_init for each Backend
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
335 // propfind_init can return a new property list, which
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
336 // will be passed to the next backend
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
337
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
338 WebdavBackend *davList = dav;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
339 while(davList) {
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
340 // create WebdavPropfindRequest copy
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
341 WebdavPropfindRequest *pReq = pool_malloc(
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
342 pool,
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
343 sizeof(WebdavPropfindRequest));
220
2915b6c11aec add test for webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
344 memcpy(pReq, propfind, sizeof(WebdavPropfindRequest));
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
345 // use new plist after previous init (or orig. plist in the first run)
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
346 pReq->properties = newProp;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
347 pReq->propcount = newPropCount;
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
348 pReq->dav = davList;
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
349
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
350 // add new WebdavPropfindRequest object to list for later use
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
351 WebdavPropfindRequestList *reqListElm = pool_malloc(pool, sizeof(WebdavPropfindRequestList));
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
352 if(!reqListElm) {
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
353 return REQ_ABORTED; // OOM
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
354 }
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
355 reqListElm->propfind = pReq;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
356 reqListElm->next = NULL;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
357 cx_linked_list_add(
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
358 (void**)&requestObjectsBegin,
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
359 (void**)&requestObjectsEnd,
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
360 -1,
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
361 offsetof(WebdavPropfindRequestList, next),
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
362 reqListElm);
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
363
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
364 // create plist copy as out-plist for init
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
365 newProp = webdav_plist_clone(pool, newProp);
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
366
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
367 // run init: this can generate a new properties list (newProp)
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
368 // which will be passed to the next backend
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
369 if(davList->propfind_init(pReq, path, uri, &newProp)) {
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
370 return REQ_ABORTED;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
371 }
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
372
216
ce2866ec97f6 add webdav_plist_iterator_remove_current tests and fix some plist related bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
373 newPropCount = webdav_plist_size(newProp);
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
374
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
375 davList = davList->next;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
376 }
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
377
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
378 *out_req = requestObjectsBegin;
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
379 return REQ_PROCEED;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
380 }
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
381
252
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
382 int webdav_propfind_do(
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
383 WebdavBackend *dav,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
384 WebdavPropfindRequest *propfind,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
385 WebdavResponse *response,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
386 VFSContext *vfs,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
387 char *path,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
388 char *uri)
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
389 {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
390 Session *sn = propfind->sn;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
391 Request *rq = propfind->rq;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
392
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
393 // VFS settings are only taken from the first backend
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
394 uint32_t settings = dav->settings;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
395
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
396 // list of individual WebdavPropfindRequest objects for each Backend
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
397 WebdavPropfindRequestList *requestObjects = NULL;
252
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
398
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
399 // Initialize all Webdav Backends
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
400 if(webdav_propfind_init(dav, propfind, path, uri, &requestObjects)) {
252
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
401 return REQ_ABORTED;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
402 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
403
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
404 WebdavOperation *op = webdav_create_propfind_operation(
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
405 sn,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
406 rq,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
407 dav,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
408 propfind->properties,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
409 requestObjects,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
410 response);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
411
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
412 // some Backends can list all children by themselves, but some
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
413 // require the VFS for this
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
414 WSBool usevfs = (settings & WS_WEBDAV_PROPFIND_USE_VFS)
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
415 == WS_WEBDAV_PROPFIND_USE_VFS;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
416 struct stat s;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
417 struct stat *statptr = NULL;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
418
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
419 if(usevfs && !vfs) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
420 vfs = vfs_request_context(sn, rq);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
421 if(!vfs) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
422 return REQ_ABORTED;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
423 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
424
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
425 if(vfs_stat(vfs, path, &s)) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
426 protocol_status(sn, rq, util_errno2status(vfs->vfs_errno), NULL);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
427 return REQ_ABORTED;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
428 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
429 statptr = &s;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
430 if(!S_ISDIR(s.st_mode)) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
431 // the file is not a directory, therefore we don't need the VFS
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
432 usevfs = FALSE;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
433 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
434 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
435 if(propfind->depth == 0) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
436 usevfs = FALSE;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
437 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
438
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
439 int ret = REQ_PROCEED;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
440
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
441 // create WebdavResource object for requested resource
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
442 if(!webdav_op_propfind_begin(op, uri, NULL, statptr)) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
443 // propfind for the requested resource was successful
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
444
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
445 // usevfsdir is TRUE if
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
446 // the webdav backend has not disabled vfs usage
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
447 // the file is a directory
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
448 // depth is not 0
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
449 // in this case we need to execute propfind_do for all children
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
450 if(usevfs) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
451 if(webdav_op_propfind_children(op, vfs, uri, path)) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
452 ret = REQ_ABORTED;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
453 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
454 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
455 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
456
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
457 // finish the propfind request
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
458 // this function should cleanup all resources, therefore we execute it
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
459 // even if a previous function failed
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
460 if(webdav_op_propfind_finish(op)) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
461 // TODO: log error
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
462 ret = REQ_ABORTED;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
463 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
464
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
465 return ret;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
466 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
467
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
468
412
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
469 static const char* proppatch_error2str(int error) {
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
470 switch(error) {
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
471 case PROPPATCH_PARSER_OK: return "ok";
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
472 case PROPPATCH_PARSER_NO_PROPERTYUPDATE: return "no property update";
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
473 case PROPPATCH_PARSER_NO_PROPERTIES: return "no properties";
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
474 case PROPPATCH_PARSER_INVALID_REQUEST: return "invalid proppatch request";
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
475 case PROPPATCH_PARSER_DUPLICATE: return "proppatch property duplicate";
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
476 case PROPPATCH_PARSER_OOM: return "OOM";
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
477 case PROPPATCH_PARSER_ERROR: return "proppatch parser error";
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
478 }
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
479 return "error";
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
480 }
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
481
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
482 int webdav_proppatch(pblock *pb, Session *sn, Request *rq) {
242
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
483 char *expect = pblock_findkeyval(pb_key_expect, rq->headers);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
484 if(expect) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
485 if(!strcasecmp(expect, "100-continue")) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
486 if(http_send_continue(sn)) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
487 return REQ_ABORTED;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
488 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
489 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
490 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
491
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
492 CxBuffer reqbody;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
493 if(rqbody2buffer(sn, rq, &reqbody)) {
412
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
494 // most likely OOM
242
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
495 return REQ_ABORTED;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
496 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
497
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
498 int error = 0;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
499 WebdavProppatchRequest *proppatch = proppatch_parse(
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
500 sn,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
501 rq,
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
502 reqbody.space,
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
503 reqbody.size,
242
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
504 &error);
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
505 cxBufferDestroy(&reqbody);
242
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
506 if(!proppatch) {
412
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
507 log_ereport(LOG_FAILURE, "webdav-proppatch: %s", proppatch_error2str(error));
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
508 return REQ_ABORTED;
242
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
509 }
251
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
510
242
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
511 WebdavBackend *dav = rq->davCollection ?
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
512 rq->davCollection : &default_backend;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
513
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
514 // requested uri and path
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
515 char *path = pblock_findkeyval(pb_key_path, rq->vars);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
516 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
517
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
518 // The multistatus response object contains responses for all
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
519 // requested resources. At the end the Multistatus object will be
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
520 // serialized to xml
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
521 Multistatus *ms = multistatus_response(sn, rq);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
522 if(!ms) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
523 return REQ_ABORTED;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
524 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
525 ms->proppatch = TRUE;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
526
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
527 // WebdavResponse is the public interface used by Backends
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
528 // for adding resources to the response
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
529 WebdavResponse *response = (WebdavResponse*)ms;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
530
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
531 WebdavOperation *op = webdav_create_proppatch_operation(
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
532 sn,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
533 rq,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
534 dav,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
535 proppatch,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
536 response);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
537
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
538 int ret = REQ_PROCEED;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
539
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
540 // Execute proppatch
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
541 if(webdav_op_proppatch(op, uri, path)) {
412
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
542 log_ereport(LOG_FAILURE, "webdav-proppatch: proppatch operation failed");
242
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
543 ret = REQ_ABORTED;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
544 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
545
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
546 // send response
412
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
547 if(ret == REQ_PROCEED) {
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
548 if(multistatus_send(ms, sn->csd)) {
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
549 log_ereport(LOG_FAILURE, "webdav-proppatch: multistatus_send failed");
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
550 }
242
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
551 } else {
412
a4e2ce073c0f improve error handling in webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
552 protocol_status(sn, rq, 500, NULL);
242
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
553 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
554
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
555 // cleanup
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
556 xmlFreeDoc(proppatch->doc);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
557
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
558 return ret;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
559 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
560
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
561 int webdav_mkcol(pblock *pb, Session *sn, Request *rq) {
245
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 244
diff changeset
562 WebdavVFSOperation *op = webdav_vfs_op(sn, rq, rq->davCollection, TRUE);
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 244
diff changeset
563 if(!op) {
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
564 return REQ_ABORTED;
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
565 }
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
566
344
70a9b945206a fix webdav_mkcol response and add error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 340
diff changeset
567 int ret = REQ_ABORTED;
70a9b945206a fix webdav_mkcol response and add error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 340
diff changeset
568 if(!webdav_vfs_op_do(op, WEBDAV_VFS_MKDIR)) {
70a9b945206a fix webdav_mkcol response and add error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 340
diff changeset
569 pblock_nvinsert("content-length", "0", rq->srvhdrs);
70a9b945206a fix webdav_mkcol response and add error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 340
diff changeset
570 protocol_status(sn, rq, 201, NULL);
70a9b945206a fix webdav_mkcol response and add error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 340
diff changeset
571 protocol_start_response(sn, rq);
70a9b945206a fix webdav_mkcol response and add error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 340
diff changeset
572 ret = REQ_PROCEED;
396
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 395
diff changeset
573 } else if(rq->status_num <= 0) {
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 395
diff changeset
574 int status_code = 500;
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 395
diff changeset
575 if(op->vfs->vfs_errno == EEXIST) {
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 395
diff changeset
576 // 405 (Method Not Allowed) - MKCOL can only be executed on an unmapped URL.
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 395
diff changeset
577 status_code = 405;
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 395
diff changeset
578 } else if(op->vfs->vfs_errno == ENOENT) {
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 395
diff changeset
579 // 409 (Conflict) - A collection cannot be made at the Request-URI until
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 395
diff changeset
580 // one or more intermediate collections have been created. The server
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 395
diff changeset
581 // MUST NOT create those intermediate collections automatically.
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 395
diff changeset
582 status_code = 409;
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 395
diff changeset
583 } else {
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 395
diff changeset
584 log_ereport(LOG_VERBOSE, "webdav_mkcol: errno: %d", op->vfs->vfs_errno);
344
70a9b945206a fix webdav_mkcol response and add error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 340
diff changeset
585 }
396
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 395
diff changeset
586 protocol_status(sn, rq, status_code, NULL);
344
70a9b945206a fix webdav_mkcol response and add error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 340
diff changeset
587 }
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
588
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
589 return ret;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
590 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
591
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
592 int webdav_post(pblock *pb, Session *sn, Request *rq) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
593 return REQ_ABORTED;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
594 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
595
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
596 typedef struct DeleteFile {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
597 char *path;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
598 struct stat s;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
599 struct DeleteFile *prev;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
600 struct DeleteFile *next;
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
601 } DeleteFile;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
602
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
603 typedef struct DeleteLists {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
604 CxAllocator *a;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
605 DeleteFile *dirs_begin;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
606 DeleteFile *dirs_end;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
607 DeleteFile *files_begin;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
608 DeleteFile *files_end;
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
609 } DeleteOp;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
610
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
611 static int deletelist_add(
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
612 VFSContext *vfs,
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
613 const char *href,
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
614 const char *path,
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
615 VFSDir *parent,
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
616 struct stat *s,
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
617 void *userdata)
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
618 {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
619 DeleteOp *op = userdata;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
620
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
621 // create object for this file
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
622 DeleteFile *file = cxMalloc(op->a, sizeof(DeleteFile));
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
623 if(!file) {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
624 return 1;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
625 }
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
626 file->path = cx_strdup_a(op->a, cx_str((char*)path)).ptr;
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
627 if(!file->path) {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
628 return 1;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
629 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
630 file->s = *s;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
631 file->next = NULL;
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
632
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
633 // determine which list to use
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
634 DeleteFile **begin;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
635 DeleteFile **end;
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
636 if(S_ISDIR(s->st_mode)) {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
637 begin = &op->dirs_begin;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
638 end = &op->dirs_end;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
639 } else {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
640 begin = &op->files_begin;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
641 end = &op->files_end;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
642 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
643
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
644 // add file to list
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
645 cx_linked_list_add(
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
646 (void**)begin, (void**)end,
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
647 offsetof(DeleteFile, prev), offsetof(DeleteFile, next),
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
648 file);
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
649
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
650 return 0;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
651 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
652
246
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
653 static int webdav_delete_collection(WebdavVFSOperation *op)
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
654 {
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
655 DeleteOp del;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
656 ZERO(&del, sizeof(DeleteOp));
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
657 del.a = pool_allocator(op->sn->pool);
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
658
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
659 // get a list of all files
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
660 if(webdav_op_iterate_children(op->vfs, -1, NULL, op->path,
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
661 deletelist_add, &del))
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
662 {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
663 return 1;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
664 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
665
249
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
666 // add root to list of dir list
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
667 DeleteFile root;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
668 root.path = op->path;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
669 root.s = *op->stat;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
670 root.prev = NULL;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
671 root.next = del.dirs_begin;
249
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
672
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
673 if(del.dirs_begin) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
674 del.dirs_begin->prev = &root;
249
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
675 } else {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
676 del.dirs_end = &root;
249
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
677 }
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
678 del.dirs_begin = &root;
249
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
679
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
680 // delete files first
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
681 for(DeleteFile *file=del.files_begin;file;file=file->next) {
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
682 WebdavVFSOperation sub = webdav_vfs_sub_op(op, file->path, &file->s);
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
683 if(webdav_vfs_op_do(&sub, WEBDAV_VFS_DELETE)) {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
684 return 1;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
685 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
686 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
687
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
688 // delete directories, reverse order
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
689 for(DeleteFile *file=del.dirs_end;file;file=file->prev) {
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
690 WebdavVFSOperation sub = webdav_vfs_sub_op(op, file->path, &file->s);
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
691 if(webdav_vfs_op_do(&sub, WEBDAV_VFS_DELETE)) {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
692 return 1;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
693 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
694 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
695
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
696 return 0;
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
697 }
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
698
245
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 244
diff changeset
699 int webdav_delete(pblock *pb, Session *sn, Request *rq) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 244
diff changeset
700 WebdavVFSOperation *op = webdav_vfs_op(sn, rq, rq->davCollection, TRUE);
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 244
diff changeset
701 if(!op) {
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
702 return REQ_ABORTED;
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
703 }
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
704
246
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
705 // stat to find out if the resource is a collection
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
706 struct stat s;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
707 if(vfs_stat(op->vfs, op->path, &s)) {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
708 sys_set_error_status(op->vfs);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
709 return REQ_ABORTED;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
710 }
249
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
711 op->stat = &s;
246
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
712
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
713 int ret;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
714 if(S_ISDIR(s.st_mode)) {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
715 ret = webdav_delete_collection(op);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
716 } else {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
717 ret = webdav_vfs_op_do(op, WEBDAV_VFS_DELETE);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
718 }
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
719
327
24e740ed90b3 move http response code from webdav_vfs_op_do to webdav_delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 325
diff changeset
720 // send response
24e740ed90b3 move http response code from webdav_vfs_op_do to webdav_delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 325
diff changeset
721 if(ret == REQ_PROCEED) {
329
d2b2124801f4 add content-length header to webdav_delete and webdav_put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 328
diff changeset
722 pblock_nvinsert("content-length", "0", rq->srvhdrs);
328
1c08aa0c060e send response in webdav_put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 327
diff changeset
723 protocol_status(sn, rq, 204, NULL);
1c08aa0c060e send response in webdav_put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 327
diff changeset
724 protocol_start_response(sn, rq);
327
24e740ed90b3 move http response code from webdav_vfs_op_do to webdav_delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 325
diff changeset
725 } else {
352
d0a7ef49db0f fix webdav_delete response in case of errors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 344
diff changeset
726 protocol_status(sn, rq, 500, NULL);
327
24e740ed90b3 move http response code from webdav_vfs_op_do to webdav_delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 325
diff changeset
727 }
24e740ed90b3 move http response code from webdav_vfs_op_do to webdav_delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 325
diff changeset
728
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
729 return ret;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
730 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
731
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
732 int webdav_put(pblock *pb, Session *sn, Request *rq) {
251
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
733 char *path = pblock_findkeyval(pb_key_path, rq->vars);
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
734
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
735 VFSContext *vfs = vfs_request_context(sn, rq);
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
736 if(!vfs) {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
737 protocol_status(sn, rq, PROTOCOL_SERVER_ERROR, NULL);
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
738 return REQ_ABORTED;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
739 }
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
740
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
741 struct stat s;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
742 int create_file = 0;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
743 if(vfs_stat(vfs, path, &s)) {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
744 if(vfs->vfs_errno == ENOENT) {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
745 create_file = O_CREAT;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
746 } else {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
747 protocol_status(sn, rq, util_errno2status(vfs->vfs_errno), NULL);
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
748 return REQ_ABORTED;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
749 }
322
f26bd6e17594 fix uninitialized memory access in directory check
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
750 } else if(S_ISDIR(s.st_mode)) {
251
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
751 // PUT on collections is not allowed
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
752 protocol_status(sn, rq, PROTOCOL_METHOD_NOT_ALLOWED, NULL);
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
753 return REQ_ABORTED;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
754 }
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
755
340
03c052d9a097 add O_TRUNC to oflags in webdav_put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
756 SYS_FILE fd = vfs_open(vfs, path, O_WRONLY | O_TRUNC | create_file);
251
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
757 if(!fd) {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
758 // if it fails, vfs_open sets http status code
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
759 return REQ_ABORTED;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
760 }
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
761
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
762 // TODO: check permissions, lock, ...
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
763
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
764 // all checks done
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
765
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
766 char *expect = pblock_findkeyval(pb_key_expect, rq->headers);
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
767 if(expect) {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
768 if(!strcasecmp(expect, "100-continue")) {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
769 if(http_send_continue(sn)) {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
770 return REQ_ABORTED;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
771 }
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
772 }
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
773 }
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
774
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
775 char in[4096];
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
776 int r;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
777 while((r = netbuf_getbytes(sn->inbuf, in, 2048)) > 0) {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
778 int w = 0;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
779 while(w < r) {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
780 w += system_fwrite(fd, in, r);
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
781 }
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
782 }
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
783
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
784 system_fclose(fd);
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
785
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
786 int status = create_file ? PROTOCOL_CREATED : PROTOCOL_NO_CONTENT;
329
d2b2124801f4 add content-length header to webdav_delete and webdav_put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 328
diff changeset
787 pblock_nvinsert("content-length", "0", rq->srvhdrs);
251
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
788 protocol_status(sn, rq, status, NULL);
328
1c08aa0c060e send response in webdav_put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 327
diff changeset
789 protocol_start_response(sn, rq);
251
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
790
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
791 return REQ_PROCEED;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
792 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
793
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
794 int webdav_copy(pblock *pb, Session *sn, Request *rq) {
252
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
795 char *path = pblock_findkeyval(pb_key_path, rq->vars);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
796 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
797
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
798 char *destination = pblock_findval("destination", rq->headers);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
799 if(!destination) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
800 protocol_status(sn, rq, PROTOCOL_BAD_REQUEST, NULL);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
801 return REQ_ABORTED;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
802 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
803
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
804 VFSContext *vfs = vfs_request_context(sn, rq);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
805 if(!vfs) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
806 protocol_status(sn, rq, PROTOCOL_SERVER_ERROR, NULL);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
807 return REQ_ABORTED;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
808 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
809
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
810 struct stat src_s;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
811 if(vfs_stat(vfs, path, &src_s)) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
812 protocol_status(sn, rq, util_errno2status(vfs->vfs_errno), NULL);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
813 return REQ_ABORTED;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
814 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
815
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
816 // TODO: if src is a directory, make sure the uri has a trailing path separator
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
817
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
818
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
819 return REQ_ABORTED;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
820 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
821
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
822 int webdav_move(pblock *pb, Session *sn, Request *rq) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
823 return REQ_ABORTED;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
824 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
825
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
826 int webdav_lock(pblock *pb, Session *sn, Request *rq) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
827 return REQ_ABORTED;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
828 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
829
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
830 int webdav_unlock(pblock *pb, Session *sn, Request *rq) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
831 return REQ_ABORTED;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
832 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
833
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
834 int webdav_report(pblock *pb, Session *sn, Request *rq) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
835 return REQ_ABORTED;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
836 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
837
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
838 int webdav_acl(pblock *pb, Session *sn, Request *rq) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
839 return REQ_ABORTED;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
840 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
841
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
842
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
843
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
844 /* ------------------------ default webdav backend ------------------------ */
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
845
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
846 int default_propfind_init(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
847 WebdavPropfindRequest *rq,
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
848 const char* path,
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
849 const char *href,
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
850 WebdavPList **outplist)
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
851 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
852 DefaultWebdavData *data = pool_malloc(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
853 rq->sn->pool,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
854 sizeof(DefaultWebdavData));
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
855 if(!data) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
856 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
857 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
858 rq->userdata = data;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
859
331
ab26980faad6 implement allprop in default and postgresql webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
860 data->vfsproperties = webdav_vfs_properties(outplist, TRUE, rq->allprop, 0);
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
861
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
862 return 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
863 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
864
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
865 int default_propfind_do(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
866 WebdavPropfindRequest *request,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
867 WebdavResponse *response,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
868 VFS_DIR parent,
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
869 WebdavResource *resource,
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
870 struct stat *s)
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
871 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
872 DefaultWebdavData *data = request->userdata;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
873
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
874 // add all requested vfs properties like getcontentlength ...
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
875 if(webdav_add_vfs_properties(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
876 resource,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
877 request->sn->pool,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
878 data->vfsproperties,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
879 s))
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
880 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
881 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
882 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
883
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
884 return 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
885 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
886
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
887 int default_propfind_finish(WebdavPropfindRequest *rq) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
888 return 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
889 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
890
243
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
891 int default_proppatch_do(
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
892 WebdavProppatchRequest *request,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
893 WebdavResource *response,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
894 VFSFile *file,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
895 WebdavPList **setInOut,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
896 WebdavPList **removeInOut)
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
897 {
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
898 return 0;
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
899 }
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
900
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
901 int default_proppatch_finish(
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
902 WebdavProppatchRequest *request,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
903 WebdavResource *response,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
904 VFSFile *file,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
905 WSBool commit)
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
906 {
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
907 return 0;
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
908 }
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
909
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
910
373
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
911
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
912 /* ------------------------------ Utils ------------------------------ */
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
913
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
914 CxHashKey webdav_property_key(const char *ns, const char *name) {
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
915 CxHashKey key;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
916 cxmutstr data = cx_asprintf("%s\n%s", name, ns);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
917 key.data.str = data.ptr;
373
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
918 key.len = data.length;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
919 cx_hash_murmur(&key);
373
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
920 return key;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
921 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
922
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
923
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
924 /* ------------------------------ public API ------------------------------ */
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
925
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
926 int webdav_getdepth(Request *rq) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
927 char *depth_str = pblock_findkeyval(pb_key_depth, rq->headers);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
928 int depth = 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
929 if(depth_str) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
930 size_t dlen = strlen(depth_str);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
931 if(!memcmp(depth_str, "infinity", dlen)) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
932 depth = -1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
933 } else if(dlen == 1 && depth_str[0] == '1') {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
934 depth = 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
935 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
936 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
937 return depth;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
938 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
939
227
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
940 int webdav_plist_add(
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
941 pool_handle_t *pool,
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
942 WebdavPList **begin,
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
943 WebdavPList **end,
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
944 WebdavProperty *prop)
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
945 {
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
946 WebdavPList *elm = pool_malloc(pool, sizeof(WebdavPList));
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
947 if(!elm) {
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
948 return 1;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
949 }
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
950 elm->prev = *end;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
951 elm->next = NULL;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
952 elm->property = prop;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
953
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
954 if(!*begin) {
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
955 *begin = elm;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
956 *end = elm;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
957 return 0;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
958 }
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
959
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
960 (*end)->next = elm;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
961 *end = elm;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
962
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
963 return 0;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
964 }
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
965
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
966 WebdavPList* webdav_plist_clone(pool_handle_t *pool, WebdavPList *list) {
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
967 return webdav_plist_clone_s(pool, list, NULL);
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
968 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
969
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
970 WebdavPList* webdav_plist_clone_s(
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
971 pool_handle_t *pool,
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
972 WebdavPList *list,
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
973 size_t *newlen)
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
974 {
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
975 WebdavPList *new_list = NULL; // start of the new list
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
976 WebdavPList *new_list_end = NULL; // end of the new list
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
977
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
978 size_t len = 0;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
979
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
980 WebdavPList *elm = list;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
981 while(elm) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
982 // copy list item
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
983 WebdavPList *new_elm = pool_malloc(pool, sizeof(WebdavPList));
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
984 if(!new_elm) {
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
985 if(newlen) *newlen = 0;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
986 return NULL;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
987 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
988 new_elm->property = elm->property; // new list contains original ptr
216
ce2866ec97f6 add webdav_plist_iterator_remove_current tests and fix some plist related bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
989 new_elm->prev = new_list_end;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
990 new_elm->next = NULL;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
991
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
992 if(new_list_end) {
216
ce2866ec97f6 add webdav_plist_iterator_remove_current tests and fix some plist related bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
993 new_list_end->next = new_elm;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
994 } else {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
995 new_list = new_elm;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
996 }
216
ce2866ec97f6 add webdav_plist_iterator_remove_current tests and fix some plist related bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
997 new_list_end = new_elm;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
998
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
999 len++;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1000 elm = elm->next;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1001 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1002
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
1003 if(newlen) *newlen = len;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1004 return new_list;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1005 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1006
216
ce2866ec97f6 add webdav_plist_iterator_remove_current tests and fix some plist related bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1007 size_t webdav_plist_size(WebdavPList *list) {
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1008 size_t count = 0;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1009 WebdavPList *elm = list;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1010 while(elm) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1011 count++;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1012 elm = elm->next;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1013 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1014 return count;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1015 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1016
215
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1017 WebdavPListIterator webdav_plist_iterator(WebdavPList **list) {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1018 WebdavPListIterator i;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1019 i.list = list;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1020 i.cur = NULL;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1021 i.next = *list;
216
ce2866ec97f6 add webdav_plist_iterator_remove_current tests and fix some plist related bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1022 i.index = 0;
215
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1023 return i;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1024 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1025
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1026 int webdav_plist_iterator_next(WebdavPListIterator *i, WebdavPList **cur) {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1027 if(i->cur) {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1028 i->index++;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1029 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1030
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1031 i->cur = i->next;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1032 i->next = i->cur ? i->cur->next : NULL;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1033 *cur = i->cur;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1034
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1035 return i->cur != NULL;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1036 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1037
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1038 void webdav_plist_iterator_remove_current(WebdavPListIterator *i) {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1039 WebdavPList *cur = i->cur;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1040 if(cur->prev) {
216
ce2866ec97f6 add webdav_plist_iterator_remove_current tests and fix some plist related bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1041 cur->prev->next = cur->next;
215
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1042 if(cur->next) {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1043 cur->next->prev = cur->prev;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1044 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1045 } else {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1046 *i->list = cur->next;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1047 if(cur->next) {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1048 cur->next->prev = NULL;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1049 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1050 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1051 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1052
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1053 int webdav_nslist_add(
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1054 pool_handle_t *pool,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1055 WebdavNSList **begin,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1056 WebdavNSList **end,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1057 WSNamespace *ns)
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1058 {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1059 // same as webdav_plist_add but with different type
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1060 WebdavNSList *elm = pool_malloc(pool, sizeof(WebdavNSList));
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1061 if(!elm) {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1062 return 1;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1063 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1064 elm->prev = *end;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1065 elm->next = NULL;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1066 elm->namespace = ns;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1067
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1068 if(!*begin) {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1069 *begin = elm;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1070 *end = elm;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1071 return 0;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1072 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1073
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1074 (*end)->next = elm;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1075 *end = elm;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1076
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1077 return 0;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1078 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
1079
215
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
1080
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1081 WSNamespace* webdav_dav_namespace(void) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1082 return &dav_namespace;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1083 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1084
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
1085 WebdavProperty* webdav_resourcetype_collection(void) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
1086 return &dav_resourcetype_collection;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
1087 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
1088
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
1089 WebdavProperty* webdav_resourcetype_empty(void) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
1090 return &dav_resourcetype_empty;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
1091 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
1092
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1093 WebdavProperty* webdav_dav_property(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1094 pool_handle_t *pool,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1095 const char *name)
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1096 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1097 WebdavProperty *property = pool_malloc(pool, sizeof(WebdavProperty));
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1098 if(!property) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1099 return NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1100 }
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1101 memset(property, 0, sizeof(WebdavProperty));
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1102
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1103 property->namespace = &dav_namespace;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1104 property->name = name;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1105 return property;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1106 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1107
309
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1108 int webdav_resource_add_dav_stringproperty(
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1109 WebdavResource *res,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1110 pool_handle_t pool,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1111 const char *name,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1112 const char *str,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1113 size_t len)
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1114 {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1115 WebdavProperty *property = webdav_dav_property(pool, name);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1116 if(!property) {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1117 return 1;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1118 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1119
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1120 property->name = pool_strdup(pool, name);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1121 if(!property->name) {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1122 return 1;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1123 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1124
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1125 char *value = pool_malloc(pool, len+1);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1126 if(!value) {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1127 return 1;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1128 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1129 memcpy(value, str, len);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1130 value[len] = '\0';
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1131 property->value.text.str = value;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1132 property->value.text.length = len;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1133 property->vtype = WS_VALUE_TEXT;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1134
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1135 return res->addproperty(res, property, 200);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1136 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1137
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1138 int webdav_resource_add_stringproperty(
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1139 WebdavResource *res,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1140 pool_handle_t pool,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1141 const char *xmlns_prefix,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1142 const char *xmlns_href,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1143 const char *name,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1144 const char *str,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1145 size_t len)
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1146 {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1147 WebdavProperty *property = pool_malloc(pool, sizeof(WebdavProperty));
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1148 if(!property) {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1149 return 1;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1150 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1151 memset(property, 0, sizeof(WebdavProperty));
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1152
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1153 property->name = pool_strdup(pool, name);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1154 if(!property->name) {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1155 return 1;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1156 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1157
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1158 xmlNs *ns = pool_malloc(pool, sizeof(xmlNs));
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1159 if(!ns) {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1160 return 1;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1161 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1162 memset(ns, 0, sizeof(xmlNs));
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1163 ns->prefix = (const xmlChar*)pool_strdup(pool, xmlns_prefix);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1164 ns->href = (const xmlChar*)pool_strdup(pool, xmlns_href);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1165 if(!ns->prefix || !ns->href) {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1166 return 1;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1167 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1168
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1169 char *value = pool_malloc(pool, len+1);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1170 if(!value) {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1171 return 1;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1172 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1173 memcpy(value, str, len);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1174 value[len] = '\0';
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1175 property->value.text.str = value;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1176 property->value.text.length = len;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1177 property->vtype = WS_VALUE_TEXT;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1178
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1179 property->value.text.str = value;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1180 property->value.text.length = len;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1181 property->vtype = WS_VALUE_TEXT;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1182
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1183 return res->addproperty(res, property, 200);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1184 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1185
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1186 int webdav_property_set_value(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1187 WebdavProperty *p,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1188 pool_handle_t *pool,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1189 char *value)
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1190 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1191 WSXmlNode *node = pool_malloc(pool, sizeof(WSXmlNode));
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1192 if(!node) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1193 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1194 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1195 ZERO(node, sizeof(WSXmlNode));
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1196
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1197 node->content = (xmlChar*)value;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1198 node->type = XML_TEXT_NODE;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1199
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1200 p->value.node = node;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1201 p->vtype = WS_VALUE_XML_NODE;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1202 return 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1203 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1204
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1205 WebdavVFSProperties webdav_vfs_properties(
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1206 WebdavPList **plistInOut,
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1207 WSBool removefromlist,
331
ab26980faad6 implement allprop in default and postgresql webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
1208 WSBool allprop,
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1209 uint32_t flags)
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1210 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1211 WebdavVFSProperties ret;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1212 ZERO(&ret, sizeof(WebdavVFSProperties));
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1213
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1214 WSBool etag = 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1215 WSBool creationdate = 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1216
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1217 WebdavPListIterator i = webdav_plist_iterator(plistInOut);
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1218 WebdavPList *cur;
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1219 while(webdav_plist_iterator_next(&i, &cur)) {
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1220 WSNamespace *ns = cur->property->namespace;
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1221 if(ns && !strcmp((const char*)ns->href, "DAV:")) {
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1222 const char *name = cur->property->name;
318
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
1223 WSBool remove_prop = removefromlist;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1224 if(!strcmp(name, "getlastmodified")) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1225 ret.getlastmodified = 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1226 } else if(!strcmp(name, "getcontentlength")) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1227 ret.getcontentlength = 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1228 } else if(!strcmp(name, "resourcetype")) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1229 ret.getresourcetype = 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1230 } else if(etag && !strcmp(name, "getetag")) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1231 ret.getetag = 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1232 } else if(creationdate && !strcmp(name, "creationdate")) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1233 ret.creationdate = 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1234 } else {
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1235 remove_prop = FALSE;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1236 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1237
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1238 if(remove_prop) {
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1239 webdav_plist_iterator_remove_current(&i);
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1240 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1241 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1242 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1243
331
ab26980faad6 implement allprop in default and postgresql webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
1244 if(allprop) {
ab26980faad6 implement allprop in default and postgresql webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
1245 ret.creationdate = 1;
ab26980faad6 implement allprop in default and postgresql webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
1246 ret.getcontentlength = 1;
ab26980faad6 implement allprop in default and postgresql webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
1247 ret.getetag = 1;
ab26980faad6 implement allprop in default and postgresql webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
1248 ret.getlastmodified = 1;
ab26980faad6 implement allprop in default and postgresql webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
1249 ret.getresourcetype = 1;
ab26980faad6 implement allprop in default and postgresql webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
1250 }
ab26980faad6 implement allprop in default and postgresql webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
1251
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1252 return ret;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1253 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1254
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1255 int webdav_add_vfs_properties(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1256 WebdavResource *res,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1257 pool_handle_t *pool,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1258 WebdavVFSProperties properties,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1259 struct stat *s)
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1260 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1261 if(properties.getresourcetype) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1262 if(S_ISDIR(s->st_mode)) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1263 res->addproperty(res, &dav_resourcetype_collection, 200);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1264 } else {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1265 res->addproperty(res, &dav_resourcetype_empty, 200);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1266 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1267 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1268 if(properties.getcontentlength) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1269 char *buf = pool_malloc(pool, 64);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1270 if(!buf) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1271 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1272 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1273 uint64_t contentlength = s->st_size;
302
dfbd3a535eac fix some snprintf warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 301
diff changeset
1274 snprintf(buf, 64, "%" PRIu64, contentlength);
309
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1275 if(webdav_resource_add_dav_stringproperty(res, pool, "getcontentlength", buf, strlen(buf))) {
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1276 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1277 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1278 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1279 if(properties.getlastmodified) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1280 char *buf = pool_malloc(pool, HTTP_DATE_LEN+1);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1281 if(!buf) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1282 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1283 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1284 buf[HTTP_DATE_LEN] = 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1285
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1286 struct tm mtms;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1287 struct tm *mtm = system_gmtime(&s->st_mtim.tv_sec, &mtms);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1288
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1289 if(mtm) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1290 strftime(buf, HTTP_DATE_LEN, HTTP_DATE_FMT, mtm);
309
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1291 if(webdav_resource_add_dav_stringproperty(res, pool, "getlastmodified", buf, strlen(buf))) {
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1292 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1293 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1294 } else {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1295 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1296 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1297 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1298 if(properties.creationdate) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1299 // TODO
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1300 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1301 if(properties.getetag) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1302 char *buf = pool_malloc(pool, 96);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1303 if(!buf) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1304 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1305 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1306 snprintf(buf,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1307 96,
302
dfbd3a535eac fix some snprintf warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 301
diff changeset
1308 "\"%x-%x\"",
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1309 (int)s->st_size,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1310 (int)s->st_mtim.tv_sec);
309
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1311 if(webdav_resource_add_dav_stringproperty(res, pool, "getetag", buf, strlen(buf))) {
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1312 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1313 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1314 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1315
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1316 return 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1317 }

mercurial