src/server/webdav/webdav.c

Sun, 01 May 2022 11:07:31 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 01 May 2022 11:07:31 +0200
branch
webdav
changeset 322
f26bd6e17594
parent 318
60870dbac94f
child 325
2d14055c3543
permissions
-rw-r--r--

fix uninitialized memory access in directory check

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
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
33 #include <ucx/buffer.h>
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
34 #include <ucx/list.h>
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
35
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "webdav.h"
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
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 #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
39 #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
40 #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
41 #include "requestparser.h"
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
42 #include "operation.h"
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
43
211
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 "../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
45 #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
46 #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
47 #include "../daemon/http.h"
235
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
48 #include "../daemon/protocol.h"
246
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
49 #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
50
301
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
51 /*
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
52 * http method fptr mapping
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
53 * key: http method name (string)
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
54 * value: SAF fptr
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
55 */
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
56 static UcxMap *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
57
301
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
58 /*
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
59 * webdav backend types
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
60 * key: backend name (string)
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
61 * value: WebdavBackend*
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
62 */
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
63 static UcxMap *webdav_type_map;
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
64
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
65 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
66
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
67 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
68
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
69 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
70 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
71 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
72
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
73 #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
74
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
75 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
76 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
77 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
78 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
79 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
80 default_backend.proppatch_do = default_proppatch_do;
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
81 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
82 default_backend.opt_mkcol = NULL;
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
83 default_backend.opt_delete = NULL;
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
84 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
85 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
86 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
87
301
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
88 int webdav_register_backend(const char *name, webdav_create_func webdavCreate) {
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
89 return ucx_map_cstr_put(webdav_type_map, name, webdavCreate);
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
90 }
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
91
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
92 static WSBool webdav_is_initialized = FALSE;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
93
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
94 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
95 if(webdav_is_initialized) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
96 return REQ_NOACTION;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
97 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
98 webdav_is_initialized = TRUE;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
99
301
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
100 webdav_type_map = ucx_map_new(8);
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
101 if(!webdav_type_map) {
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
102 return REQ_ABORTED;
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
103 }
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
104
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
105 method_handler_map = ucx_map_new(64);
301
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
106 if(!method_handler_map) {
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
107 return REQ_ABORTED;
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
108 }
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
109
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
110 init_default_backend();
2bc514931612 add function for registering webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
111 ucx_map_cstr_put(webdav_type_map, "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
112
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
113 ucx_map_cstr_put(method_handler_map, "OPTIONS", webdav_options);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
114 ucx_map_cstr_put(method_handler_map, "PROPFIND", webdav_propfind);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
115 ucx_map_cstr_put(method_handler_map, "PROPPATCH", webdav_proppatch);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
116 ucx_map_cstr_put(method_handler_map, "MKCOL", webdav_mkcol);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
117 ucx_map_cstr_put(method_handler_map, "POST", webdav_post);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
118 ucx_map_cstr_put(method_handler_map, "DELETE", webdav_delete);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
119 ucx_map_cstr_put(method_handler_map, "PUT", webdav_put);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
120 ucx_map_cstr_put(method_handler_map, "COPY", webdav_copy);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
121 ucx_map_cstr_put(method_handler_map, "MOVE", webdav_move);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
122 ucx_map_cstr_put(method_handler_map, "LOCK", webdav_lock);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
123 ucx_map_cstr_put(method_handler_map, "UNLOCK", webdav_unlock);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
124 ucx_map_cstr_put(method_handler_map, "REPORT", webdav_report);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
125 ucx_map_cstr_put(method_handler_map, "ACL", webdav_acl);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
126
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
127 ucx_map_cstr_put(method_handler_map, "SEARCH", webdav_search);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
128
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
129 ucx_map_cstr_put(method_handler_map, "VERSION-CONTROL", webdav_version_control);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
130 ucx_map_cstr_put(method_handler_map, "CHECKOUT", webdav_checkout);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
131 ucx_map_cstr_put(method_handler_map, "CHECKIN", webdav_checkin);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
132 ucx_map_cstr_put(method_handler_map, "UNCHECKOUT", webdav_uncheckout);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
133 ucx_map_cstr_put(method_handler_map, "MKWORKSPACE", webdav_mkworkspace);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
134 ucx_map_cstr_put(method_handler_map, "UPDATE", webdav_update);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
135 ucx_map_cstr_put(method_handler_map, "LABEL", webdav_label);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
136 ucx_map_cstr_put(method_handler_map, "MERGE", webdav_merge);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
137
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
138 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
139 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
140
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
141 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
142 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
143
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
144 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
145 dav_resourcetype_collection.name = "resourcetype";
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
146 dav_resourcetype_collection.value.data = &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
147 dav_resourcetype_collection.vtype = WS_VALUE_XML_DATA;
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
148 dav_resourcetype_collection_value.data = WEBDAV_RESOURCE_TYPE_COLLECTION;
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
149 dav_resourcetype_collection_value.length = sizeof(WEBDAV_RESOURCE_TYPE_COLLECTION)-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
150
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
151 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
152 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
153
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
154
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
155 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
156 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
157 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
158 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
159 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
160 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
161 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
162
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
163 FuncPtr saf = (FuncPtr)ucx_map_cstr_get(method_handler_map, method);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
164 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
165 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
166 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
167
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
168 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
169 }
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 UcxBuffer* rqbody2buffer(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
172 if(!sn->inbuf) {
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
173 //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
174 protocol_status(sn, rq, 400, NULL);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
175 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
176 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
177
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
178 UcxBuffer *buf = ucx_buffer_new(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
179 NULL,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
180 sn->inbuf->maxsize,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
181 UCX_BUFFER_AUTOEXTEND);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
182 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
183 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
184 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
185 }
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 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
188 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
189 while((r = netbuf_getbytes(sn->inbuf, in, 2048)) > 0) {
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(ucx_buffer_write(in, 1, r, buf) != r) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
191 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
192 ucx_buffer_free(buf);
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 NULL;
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 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
196
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
197 return buf;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
198 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
199
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
200 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
201 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
202 }
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 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
205 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
206 if(expect) {
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
207 if(!strcasecmp(expect, "100-continue")) {
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
208 if(http_send_continue(sn)) {
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
209 return REQ_ABORTED;
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
210 }
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
211 }
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
212 }
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
213
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 UcxBuffer *reqbody = rqbody2buffer(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
215 if(!reqbody) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
216 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
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
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
219 UcxAllocator *a = session_get_allocator(sn);
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
220
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
221 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
222 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
223 sn,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
224 rq,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
225 reqbody->space,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
226 reqbody->size,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
227 &error);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
228 ucx_buffer_free(reqbody);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
229 if(!propfind) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
230 switch(error) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
231 // TODO: handle all errors
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
232 default: 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 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
235
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
236 WebdavBackend *dav = rq->davCollection ?
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
237 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
238
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
239
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
240 // 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
241 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
242 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
243
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
244 // The multistatus response object contains responses for all
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
245 // requested resources. At the end the Multistatus object will be
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
246 // serialized to xml
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
247 Multistatus *ms = multistatus_response(sn, rq);
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
248 if(!ms) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
249 return REQ_ABORTED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
250 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
251
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
252
252
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
253 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
254
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
255 // if propfind was successful, send the result to the client
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
256 if(ret == REQ_PROCEED && multistatus_send(ms, sn->csd)) {
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
257 ret = REQ_ABORTED;
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
258 // TODO: log error
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
259 } else {
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
260 // TODO: error response
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
261 }
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
262
252
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
263 // cleanup
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
264 if(propfind->doc) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
265 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
266 }
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
267
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 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
269 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
270
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
271 /*
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
272 * Initializes Backend Chain
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
273 *
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
274 * 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
275 * WebdavPropfindRequest objects for each backend
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
276 */
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
277 int webdav_propfind_init(
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
278 WebdavBackend *dav,
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
279 WebdavPropfindRequest *propfind,
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
280 const char *path,
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
281 const char *uri,
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
282 UcxList **out_req)
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
283 {
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
284 pool_handle_t *pool = propfind->sn->pool;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
285 UcxAllocator *a = session_get_allocator(propfind->sn);
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
286
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
287 // list of individual WebdavPropfindRequest objects for each Backend
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
288 UcxList *requestObjects = NULL;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
289
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
290 // 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
291 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
292 size_t newPropCount = propfind->propcount;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
293
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
294 // Call propfind_init for each Backend
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
295 // 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
296 // will be passed to the next backend
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
297
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
298 WebdavBackend *davList = dav;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
299 while(davList) {
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
300 // create WebdavPropfindRequest copy
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
301 WebdavPropfindRequest *pReq = pool_malloc(
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
302 pool,
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
303 sizeof(WebdavPropfindRequest));
220
2915b6c11aec add test for webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
304 memcpy(pReq, propfind, sizeof(WebdavPropfindRequest));
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
305 // 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
306 pReq->properties = newProp;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
307 pReq->propcount = newPropCount;
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
308 pReq->dav = davList;
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
309
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
310 // add new WebdavPropfindRequest object to list for later use
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
311 requestObjects = ucx_list_append_a(a, requestObjects, pReq);
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
312 if(!requestObjects) {
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
313 return REQ_ABORTED; // OOM
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
314 }
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 // 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
317 newProp = webdav_plist_clone(pool, newProp);
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
318
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
319 // 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
320 // 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
321 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
322 return REQ_ABORTED;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
323 }
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
324
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
325 newPropCount = webdav_plist_size(newProp);
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
326
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
327 davList = davList->next;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
328 }
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 *out_req = requestObjects;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
331 return REQ_PROCEED;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
332 }
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
333
252
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
334 int webdav_propfind_do(
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
335 WebdavBackend *dav,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
336 WebdavPropfindRequest *propfind,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
337 WebdavResponse *response,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
338 VFSContext *vfs,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
339 char *path,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
340 char *uri)
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
341 {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
342 Session *sn = propfind->sn;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
343 Request *rq = propfind->rq;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
344
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
345 // VFS settings are only taken from the first backend
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
346 uint32_t settings = dav->settings;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
347
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
348 // list of individual WebdavPropfindRequest objects for each Backend
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
349 UcxList *requestObjects = NULL;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
350
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
351 // Initialize all Webdav Backends
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
352 if(webdav_propfind_init(dav, propfind, path, uri, &requestObjects)) {
252
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
353 return REQ_ABORTED;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
354 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
355
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
356 WebdavOperation *op = webdav_create_propfind_operation(
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
357 sn,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
358 rq,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
359 dav,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
360 propfind->properties,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
361 requestObjects,
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
362 response);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
363
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
364 // some Backends can list all children by themselves, but some
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
365 // require the VFS for this
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
366 WSBool usevfs = (settings & WS_WEBDAV_PROPFIND_USE_VFS)
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
367 == WS_WEBDAV_PROPFIND_USE_VFS;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
368 struct stat s;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
369 struct stat *statptr = NULL;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
370
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
371 if(usevfs && !vfs) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
372 vfs = vfs_request_context(sn, rq);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
373 if(!vfs) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
374 return REQ_ABORTED;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
375 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
376
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
377 if(vfs_stat(vfs, path, &s)) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
378 protocol_status(sn, rq, util_errno2status(vfs->vfs_errno), NULL);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
379 return REQ_ABORTED;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
380 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
381 statptr = &s;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
382 if(!S_ISDIR(s.st_mode)) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
383 // 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
384 usevfs = FALSE;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
385 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
386 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
387 if(propfind->depth == 0) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
388 usevfs = FALSE;
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
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
391 int ret = REQ_PROCEED;
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 // create WebdavResource object for requested resource
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
394 if(!webdav_op_propfind_begin(op, uri, NULL, statptr)) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
395 // propfind for the requested resource was successful
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
396
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
397 // usevfsdir is TRUE if
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
398 // the webdav backend has not disabled vfs usage
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
399 // the file is a directory
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
400 // depth is not 0
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
401 // 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
402 if(usevfs) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
403 if(webdav_op_propfind_children(op, vfs, uri, path)) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
404 ret = REQ_ABORTED;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
405 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
406 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
407 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
408
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
409 // finish the propfind request
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
410 // this function should cleanup all resources, therefore we execute it
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
411 // even if a previous function failed
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
412 if(webdav_op_propfind_finish(op)) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
413 // TODO: log error
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
414 ret = REQ_ABORTED;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
415 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
416
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
417 return ret;
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
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
420
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
421 int webdav_proppatch(pblock *pb, Session *sn, Request *rq) {
242
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
422 char *expect = pblock_findkeyval(pb_key_expect, rq->headers);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
423 if(expect) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
424 if(!strcasecmp(expect, "100-continue")) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
425 if(http_send_continue(sn)) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
426 return REQ_ABORTED;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
427 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
428 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
429 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
430
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
431 UcxBuffer *reqbody = rqbody2buffer(sn, rq);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
432 if(!reqbody) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
433 return REQ_ABORTED;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
434 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
435
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
436 int error = 0;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
437 WebdavProppatchRequest *proppatch = proppatch_parse(
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
438 sn,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
439 rq,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
440 reqbody->space,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
441 reqbody->size,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
442 &error);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
443 ucx_buffer_free(reqbody);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
444 if(!proppatch) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
445 switch(error) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
446 // TODO: handle all errors
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
447 default: return REQ_ABORTED;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
448 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
449 }
251
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
450
242
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
451 WebdavBackend *dav = rq->davCollection ?
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
452 rq->davCollection : &default_backend;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
453
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
454 // requested uri and path
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
455 char *path = pblock_findkeyval(pb_key_path, rq->vars);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
456 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
457
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
458 // The multistatus response object contains responses for all
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
459 // requested resources. At the end the Multistatus object will be
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
460 // serialized to xml
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
461 Multistatus *ms = multistatus_response(sn, rq);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
462 if(!ms) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
463 return REQ_ABORTED;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
464 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
465 ms->proppatch = TRUE;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
466
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
467 // WebdavResponse is the public interface used by Backends
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
468 // for adding resources to the response
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
469 WebdavResponse *response = (WebdavResponse*)ms;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
470
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
471 WebdavOperation *op = webdav_create_proppatch_operation(
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
472 sn,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
473 rq,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
474 dav,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
475 proppatch,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
476 response);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
477
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
478 int ret = REQ_PROCEED;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
479
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
480 // Execute proppatch
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
481 if(webdav_op_proppatch(op, uri, path)) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
482 ret = REQ_ABORTED;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
483 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
484
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
485 // send response
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
486 if(ret == REQ_PROCEED && multistatus_send(ms, sn->csd)) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
487 ret = REQ_ABORTED;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
488 // TODO: log error
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
489 } else {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
490 // TODO: error response
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
491 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
492
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
493 // cleanup
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
494 xmlFreeDoc(proppatch->doc);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
495
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
496 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
497 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
498
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
499 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
500 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
501 if(!op) {
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
502 return REQ_ABORTED;
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
503 }
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
504
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
505 int ret = webdav_vfs_op_do(op, WEBDAV_VFS_MKDIR);
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
506
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
507 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
508 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
509
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
510 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
511 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
512 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
513
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
514 typedef struct DeleteFile {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
515 char *path;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
516 struct stat s;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
517 } DeleteFile;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
518
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
519 typedef struct DeleteLists {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
520 UcxAllocator *a;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
521 UcxList *dirs_begin;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
522 UcxList *dirs_end;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
523 UcxList *files_begin;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
524 UcxList *files_end;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
525 } DeleteOp;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
526
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
527 static int deletelist_add(
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
528 VFSContext *vfs,
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
529 const char *href,
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
530 const char *path,
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
531 VFSDir *parent,
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
532 struct stat *s,
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
533 void *userdata)
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
534 {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
535 DeleteOp *op = userdata;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
536
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
537 // create object for this file
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
538 DeleteFile *file = almalloc(op->a, sizeof(DeleteFile));
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
539 if(!file) {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
540 return 1;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
541 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
542 file->path = sstrdup_a(op->a, sstr((char*)path)).ptr;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
543 if(!file->path) {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
544 return 1;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
545 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
546 file->s = *s;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
547
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
548 // determine which list to use
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
549 UcxList **begin;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
550 UcxList **end;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
551 if(S_ISDIR(s->st_mode)) {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
552 begin = &op->dirs_begin;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
553 end = &op->dirs_end;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
554 } else {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
555 begin = &op->files_begin;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
556 end = &op->files_end;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
557 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
558
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
559 // add file to list
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
560 UcxList *elm = ucx_list_append_a(op->a, NULL, file);
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
561 if(!elm) {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
562 alfree(op->a, file->path); // at least do some cleanup, although it
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
563 alfree(op->a, file); // isn't really necessary
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
564 return 1;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
565 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
566 if(*begin == NULL) {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
567 *begin = elm;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
568 *end = elm;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
569 } else {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
570 ucx_list_concat(*end, elm);
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
571 *end = elm;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
572 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
573
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
574 return 0;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
575 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
576
246
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
577 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
578 {
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
579 DeleteOp del;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
580 ZERO(&del, sizeof(DeleteOp));
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
581 del.a = session_get_allocator(op->sn);
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
582
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
583 // get a list of all files
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
584 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
585 deletelist_add, &del))
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
586 {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
587 return 1;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
588 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
589
249
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
590 // add root to list of dir list
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
591 DeleteFile root;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
592 root.path = op->path;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
593 root.s = *op->stat;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
594 UcxList root_elm;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
595 root_elm.data = &root;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
596 root_elm.prev = NULL;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
597 root_elm.next = del.dirs_begin;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
598
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
599 if(del.dirs_begin) {
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
600 del.dirs_begin->prev = &root_elm;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
601 del.dirs_begin = &root_elm;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
602 } else {
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
603 del.dirs_begin = &root_elm;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
604 del.dirs_end = &root_elm;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
605 }
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
606
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
607 // delete files first
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
608 UCX_FOREACH(elm, del.files_begin) {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
609 DeleteFile *file = elm->data;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
610 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
611 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
612 return 1;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
613 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
614 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
615
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
616 // delete directories, reverse order
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
617 for(UcxList *elm=del.dirs_end;elm;elm=elm->prev) {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
618 DeleteFile *file = elm->data;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
619 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
620 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
621 return 1;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
622 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
623 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
624
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
625 return 0;
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
626 }
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
627
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
628 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
629 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
630 if(!op) {
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
631 return REQ_ABORTED;
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
632 }
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
633
246
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
634 // 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
635 struct stat s;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
636 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
637 sys_set_error_status(op->vfs);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
638 return REQ_ABORTED;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
639 }
249
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
640 op->stat = &s;
246
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
641
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
642 int ret;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
643 if(S_ISDIR(s.st_mode)) {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
644 ret = webdav_delete_collection(op);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
645 } else {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
646 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
647 }
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
648
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
649 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
650 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
651
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
652 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
653 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
654
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
655 VFSContext *vfs = vfs_request_context(sn, rq);
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
656 if(!vfs) {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
657 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
658 return REQ_ABORTED;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
659 }
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
660
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
661 struct stat s;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
662 int create_file = 0;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
663 if(vfs_stat(vfs, path, &s)) {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
664 if(vfs->vfs_errno == ENOENT) {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
665 create_file = O_CREAT;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
666 } else {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
667 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
668 return REQ_ABORTED;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
669 }
322
f26bd6e17594 fix uninitialized memory access in directory check
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
670 } 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
671 // PUT on collections is not allowed
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
672 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
673 return REQ_ABORTED;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
674 }
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
675
262
c459019a3ed3 open files for writing in webdav_put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 252
diff changeset
676 SYS_FILE fd = vfs_open(vfs, path, O_WRONLY | create_file);
251
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
677 if(!fd) {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
678 // 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
679 return REQ_ABORTED;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
680 }
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
681
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
682 // TODO: check permissions, lock, ...
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
683
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
684 // all checks done
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
685
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
686 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
687 if(expect) {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
688 if(!strcasecmp(expect, "100-continue")) {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
689 if(http_send_continue(sn)) {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
690 return REQ_ABORTED;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
691 }
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
692 }
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
693 }
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
694
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
695 char in[4096];
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
696 int r;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
697 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
698 int w = 0;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
699 while(w < r) {
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
700 w += system_fwrite(fd, in, r);
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
701 }
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
702 }
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
703
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
704 system_fclose(fd);
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
705
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
706 int status = create_file ? PROTOCOL_CREATED : PROTOCOL_NO_CONTENT;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
707 protocol_status(sn, rq, status, NULL);
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
708
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
709 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
710 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
711
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
712 int webdav_copy(pblock *pb, Session *sn, Request *rq) {
252
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
713 char *path = pblock_findkeyval(pb_key_path, rq->vars);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
714 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
715
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
716 char *destination = pblock_findval("destination", rq->headers);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
717 if(!destination) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
718 protocol_status(sn, rq, PROTOCOL_BAD_REQUEST, NULL);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
719 return REQ_ABORTED;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
720 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
721
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
722 VFSContext *vfs = vfs_request_context(sn, rq);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
723 if(!vfs) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
724 protocol_status(sn, rq, PROTOCOL_SERVER_ERROR, NULL);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
725 return REQ_ABORTED;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
726 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
727
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
728 struct stat src_s;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
729 if(vfs_stat(vfs, path, &src_s)) {
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
730 protocol_status(sn, rq, util_errno2status(vfs->vfs_errno), NULL);
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
731 return REQ_ABORTED;
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
732 }
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
733
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
734 // 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
735
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
736
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
737 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
738 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
739
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
740 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
741 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
742 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
743
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
744 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
745 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
746 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
747
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
748 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
749 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
750 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
751
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
752 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
753 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
754 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
755
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
756 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
757 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
758 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
759
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
760
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
761
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
762 /* ------------------------ 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
763
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
764 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
765 WebdavPropfindRequest *rq,
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
766 const char* path,
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
767 const char *href,
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
768 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
769 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
770 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
771 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
772 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
773 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
774 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
775 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
776 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
777
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
778 data->vfsproperties = webdav_vfs_properties(outplist, TRUE, 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
779
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
780 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
781 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
782
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
783 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
784 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
785 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
786 VFS_DIR parent,
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
787 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
788 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
789 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
790 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
791
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
792 // 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
793 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
794 resource,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
795 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
796 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
797 s))
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
798 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
799 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
800 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
801
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
802 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
803 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
804
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
805 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
806 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
807 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
808
243
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
809 int default_proppatch_do(
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
810 WebdavProppatchRequest *request,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
811 WebdavResource *response,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
812 VFSFile *file,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
813 WebdavPList **setInOut,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
814 WebdavPList **removeInOut)
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
815 {
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
816 return 0;
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
817 }
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
818
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
819 int default_proppatch_finish(
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
820 WebdavProppatchRequest *request,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
821 WebdavResource *response,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
822 VFSFile *file,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
823 WSBool commit)
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
824 {
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
825 return 0;
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
826 }
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
827
211
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 /* ------------------------------ 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
830
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
831 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
832 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
833 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
834 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
835 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
836 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
837 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
838 } 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
839 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
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 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
843 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
844
227
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
845 int webdav_plist_add(
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
846 pool_handle_t *pool,
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
847 WebdavPList **begin,
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
848 WebdavPList **end,
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
849 WebdavProperty *prop)
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
850 {
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
851 WebdavPList *elm = pool_malloc(pool, sizeof(WebdavPList));
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
852 if(!elm) {
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
853 return 1;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
854 }
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
855 elm->prev = *end;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
856 elm->next = NULL;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
857 elm->property = prop;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
858
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
859 if(!*begin) {
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
860 *begin = elm;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
861 *end = elm;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
862 return 0;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
863 }
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
864
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
865 (*end)->next = elm;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
866 *end = elm;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
867
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
868 return 0;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
869 }
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
870
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
871 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
872 return webdav_plist_clone_s(pool, list, NULL);
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
873 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
874
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
875 WebdavPList* webdav_plist_clone_s(
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
876 pool_handle_t *pool,
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
877 WebdavPList *list,
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
878 size_t *newlen)
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
879 {
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
880 WebdavPList *new_list = NULL; // start of the new list
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
881 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
882
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
883 size_t len = 0;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
884
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
885 WebdavPList *elm = list;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
886 while(elm) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
887 // copy list item
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
888 WebdavPList *new_elm = pool_malloc(pool, sizeof(WebdavPList));
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
889 if(!new_elm) {
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
890 if(newlen) *newlen = 0;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
891 return NULL;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
892 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
893 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
894 new_elm->prev = new_list_end;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
895 new_elm->next = NULL;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
896
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
897 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
898 new_list_end->next = new_elm;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
899 } else {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
900 new_list = new_elm;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
901 }
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
902 new_list_end = new_elm;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
903
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
904 len++;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
905 elm = elm->next;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
906 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
907
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
908 if(newlen) *newlen = len;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
909 return new_list;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
910 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
911
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
912 size_t webdav_plist_size(WebdavPList *list) {
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
913 size_t count = 0;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
914 WebdavPList *elm = list;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
915 while(elm) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
916 count++;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
917 elm = elm->next;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
918 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
919 return count;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
920 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
921
215
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
922 WebdavPListIterator webdav_plist_iterator(WebdavPList **list) {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
923 WebdavPListIterator i;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
924 i.list = list;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
925 i.cur = NULL;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
926 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
927 i.index = 0;
215
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
928 return i;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
929 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
930
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
931 int webdav_plist_iterator_next(WebdavPListIterator *i, WebdavPList **cur) {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
932 if(i->cur) {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
933 i->index++;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
934 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
935
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
936 i->cur = i->next;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
937 i->next = i->cur ? i->cur->next : NULL;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
938 *cur = i->cur;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
939
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
940 return i->cur != NULL;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
941 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
942
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
943 void webdav_plist_iterator_remove_current(WebdavPListIterator *i) {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
944 WebdavPList *cur = i->cur;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
945 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
946 cur->prev->next = cur->next;
215
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
947 if(cur->next) {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
948 cur->next->prev = cur->prev;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
949 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
950 } else {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
951 *i->list = cur->next;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
952 if(cur->next) {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
953 cur->next->prev = NULL;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
954 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
955 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
956 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
957
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
958 int webdav_nslist_add(
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
959 pool_handle_t *pool,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
960 WebdavNSList **begin,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
961 WebdavNSList **end,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
962 WSNamespace *ns)
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
963 {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
964 // 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
965 WebdavNSList *elm = pool_malloc(pool, sizeof(WebdavNSList));
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
966 if(!elm) {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
967 return 1;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
968 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
969 elm->prev = *end;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
970 elm->next = NULL;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
971 elm->namespace = ns;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
972
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
973 if(!*begin) {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
974 *begin = elm;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
975 *end = elm;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
976 return 0;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
977 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
978
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
979 (*end)->next = elm;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
980 *end = elm;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
981
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
982 return 0;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
983 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
984
215
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
985
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
986 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
987 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
988 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
989
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
990 WebdavProperty* webdav_resourcetype_collection(void) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
991 return &dav_resourcetype_collection;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
992 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
993
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
994 WebdavProperty* webdav_resourcetype_empty(void) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
995 return &dav_resourcetype_empty;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
996 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 302
diff changeset
997
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
998 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
999 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
1000 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
1001 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1002 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
1003 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
1004 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
1005 }
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1006 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
1007
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1008 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
1009 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
1010 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
1011 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1012
309
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1013 int webdav_resource_add_dav_stringproperty(
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1014 WebdavResource *res,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1015 pool_handle_t pool,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1016 const char *name,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1017 const char *str,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1018 size_t len)
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1019 {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1020 WebdavProperty *property = webdav_dav_property(pool, name);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1021 if(!property) {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1022 return 1;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1023 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1024
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1025 property->name = pool_strdup(pool, name);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1026 if(!property->name) {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1027 return 1;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1028 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1029
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1030 char *value = pool_malloc(pool, len+1);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1031 if(!value) {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1032 return 1;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1033 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1034 memcpy(value, str, len);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1035 value[len] = '\0';
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1036 property->value.text.str = value;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1037 property->value.text.length = len;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1038 property->vtype = WS_VALUE_TEXT;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1039
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1040 return res->addproperty(res, property, 200);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1041 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1042
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1043 int webdav_resource_add_stringproperty(
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1044 WebdavResource *res,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1045 pool_handle_t pool,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1046 const char *xmlns_prefix,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1047 const char *xmlns_href,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1048 const char *name,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1049 const char *str,
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1050 size_t len)
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1051 {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1052 WebdavProperty *property = pool_malloc(pool, sizeof(WebdavProperty));
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1053 if(!property) {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1054 return 1;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1055 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1056 memset(property, 0, sizeof(WebdavProperty));
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1057
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1058 property->name = pool_strdup(pool, name);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1059 if(!property->name) {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1060 return 1;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1061 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1062
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1063 xmlNs *ns = pool_malloc(pool, sizeof(xmlNs));
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1064 if(!ns) {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1065 return 1;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1066 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1067 memset(ns, 0, sizeof(xmlNs));
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1068 ns->prefix = (const xmlChar*)pool_strdup(pool, xmlns_prefix);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1069 ns->href = (const xmlChar*)pool_strdup(pool, xmlns_href);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1070 if(!ns->prefix || !ns->href) {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1071 return 1;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1072 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1073
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1074 char *value = pool_malloc(pool, len+1);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1075 if(!value) {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1076 return 1;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1077 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1078 memcpy(value, str, len);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1079 value[len] = '\0';
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1080 property->value.text.str = value;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1081 property->value.text.length = len;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1082 property->vtype = WS_VALUE_TEXT;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1083
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1084 property->value.text.str = value;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1085 property->value.text.length = len;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1086 property->vtype = WS_VALUE_TEXT;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1087
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1088 return res->addproperty(res, property, 200);
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1089 }
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1090
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1091 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
1092 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
1093 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
1094 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
1095 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1096 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
1097 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
1098 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
1099 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1100 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
1101
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1102 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
1103 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
1104
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1105 p->value.node = node;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
1106 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
1107 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
1108 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1109
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1110 WebdavVFSProperties webdav_vfs_properties(
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1111 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
1112 WSBool removefromlist,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1113 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
1114 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1115 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
1116 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
1117
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1118 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
1119 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
1120
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1121 WebdavPListIterator i = webdav_plist_iterator(plistInOut);
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1122 WebdavPList *cur;
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1123 while(webdav_plist_iterator_next(&i, &cur)) {
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1124 WSNamespace *ns = cur->property->namespace;
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1125 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
1126 const char *name = cur->property->name;
318
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
1127 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
1128 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
1129 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
1130 } 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
1131 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
1132 } 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
1133 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
1134 } 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
1135 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
1136 } 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
1137 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
1138 } else {
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1139 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
1140 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1141
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1142 if(remove_prop) {
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1143 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
1144 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1145 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1146 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1147
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1148 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
1149 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1150
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1151 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
1152 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
1153 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
1154 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
1155 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
1156 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1157 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
1158 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
1159 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
1160 } else {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1161 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
1162 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1163 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1164 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
1165 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
1166 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
1167 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
1168 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1169 uint64_t contentlength = s->st_size;
302
dfbd3a535eac fix some snprintf warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 301
diff changeset
1170 snprintf(buf, 64, "%" PRIu64, contentlength);
309
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1171 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
1172 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
1173 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1174 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1175 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
1176 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
1177 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
1178 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
1179 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1180 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
1181
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1182 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
1183 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
1184
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1185 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
1186 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
1187 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
1188 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
1189 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1190 } else {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1191 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
1192 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1193 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1194 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
1195 // TODO
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 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
1198 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
1199 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
1200 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
1201 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1202 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
1203 96,
302
dfbd3a535eac fix some snprintf warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 301
diff changeset
1204 "\"%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
1205 (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
1206 (int)s->st_mtim.tv_sec);
309
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
1207 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
1208 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
1209 }
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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1212 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
1213 }

mercurial