src/server/webdav/webdav.c

Sun, 31 May 2020 19:35:29 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 31 May 2020 19:35:29 +0200
branch
webdav
changeset 249
3b302093945c
parent 247
1df803e06076
child 251
f727a21497bb
permissions
-rw-r--r--

add webdav_delete tests

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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
51 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
52
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
53 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
54
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
55 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
56
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
57 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
58 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
59 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
60
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
61 #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
62
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
63 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
64 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
65 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
66 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
67 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
68 default_backend.proppatch_do = default_proppatch_do;
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
69 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
70 default_backend.opt_mkcol = NULL;
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
71 default_backend.opt_delete = NULL;
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
72 default_backend.settings = WS_WEBDAV_PROPFIND_USE_VFS;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
73 }
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 int webdav_init(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
76 init_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
77
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
78 method_handler_map = ucx_map_new(64);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
79
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
80 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
81 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
82 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
83 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
84 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
85 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
86 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
87 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
88 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
89 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
90 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
91 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
92 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
93
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
94 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
95
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
96 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
97 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
98 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
99 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
100 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
101 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
102 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
103 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
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 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
106 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
107
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
108 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
109 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
110
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
111 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
112 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
113 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
114 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
115 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
116 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
117
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
118 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
119 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
120
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
121
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
122 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
123 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
124 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
125 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
126 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
127 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
128 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
129
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
130 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
131 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
132 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
133 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
134
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
135 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
136 }
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 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
139 if(!sn->inbuf) {
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
140 //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
141 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
142 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
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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
145 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
146 NULL,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
147 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
148 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
149 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
150 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
151 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
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 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
155 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
156 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
157 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
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 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
160 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
161 }
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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
164 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
165 }
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 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
168 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
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 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
172 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
173 if(expect) {
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
174 if(!strcasecmp(expect, "100-continue")) {
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
175 if(http_send_continue(sn)) {
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
176 return REQ_ABORTED;
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
177 }
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
178 }
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
179 }
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 234
diff changeset
180
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
181 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
182 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
183 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
184 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
185
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
186 UcxAllocator *a = session_get_allocator(sn);
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
187
211
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 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
189 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
190 sn,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
191 rq,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
192 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
193 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
194 &error);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
195 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
196 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
197 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
198 // 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
199 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
200 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
201 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
202
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
203 WebdavBackend *dav = rq->davCollection ?
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
204 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
205
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
206
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
207 // 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
208 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
209 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
210
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
211 // VFS settings are only taken from the first 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
212 uint32_t settings = dav->settings;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
213
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
214 // list of individual WebdavPropfindRequest objects for each Backend
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
215 UcxList *requestObjects = NULL;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
216
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
217 // Initialize all Webdav Backends
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
218 if(webdav_propfind_init(dav, propfind, path, &requestObjects)) {
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
219 return REQ_ABORTED;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
220 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
221
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
222 // The multistatus response object contains responses for all
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
223 // requested resources. At the end the Multistatus object will be
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
224 // serialized to xml
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
225 Multistatus *ms = multistatus_response(sn, rq);
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
226 if(!ms) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
227 return REQ_ABORTED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
228 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
229 // WebdavResponse is the public interface used by Backends
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
230 // for adding resources to the response
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
231 WebdavResponse *response = (WebdavResponse*)ms;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
232
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
233 WebdavOperation *op = webdav_create_propfind_operation(
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
234 sn,
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
235 rq,
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
236 dav,
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
237 propfind->properties,
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
238 requestObjects,
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
239 response);
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
240
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
241 // some Backends can list all children by themselves, but some
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
242 // require the VFS for this
240
cd74667f6c85 add proppatch interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
243 WSBool usevfs = (settings & WS_WEBDAV_PROPFIND_USE_VFS)
cd74667f6c85 add proppatch interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
244 == WS_WEBDAV_PROPFIND_USE_VFS;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
245 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
246 struct stat *statptr = NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
247
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
248 VFSContext *vfs = NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
249 if(usevfs) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
250 vfs = vfs_request_context(sn, rq);
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
251 if(!vfs) {
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
252 return REQ_ABORTED;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
253 }
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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
255 if(vfs_stat(vfs, path, &s)) {
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
256 protocol_status(sn, rq, util_errno2status(vfs->vfs_errno), 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
257 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
258 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
259 statptr = &s;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
260 if(!S_ISDIR(s.st_mode)) {
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
261 // the file is not a directory, therefore we don't need the VFS
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
262 usevfs = FALSE;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
263 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
264 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
265 if(propfind->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
266 usevfs = FALSE;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
267 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
268
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
269 int ret = REQ_PROCEED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
270
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
271 // create WebdavResource object for requested resource
236
e81d3e517b57 fix response href
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
272 if(!webdav_op_propfind_begin(op, uri, NULL, statptr)) {
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
273 // propfind for the requested resource was successful
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
274
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
275 // usevfsdir is TRUE if
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
276 // the webdav backend has not disabled vfs usage
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
277 // the file is a directory
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
278 // depth is not 0
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
279 // in this case we need to execute propfind_do for all children
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
280 if(usevfs) {
234
f30740c3aafb fix webdav_op_propfind_children return check
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
281 if(webdav_op_propfind_children(op, vfs, uri, path)) {
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
282 ret = REQ_ABORTED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
283 }
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
284 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
285 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
286
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
287 // 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
288 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
289 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
290 // 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
291 } 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
292 // 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
293 }
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
294
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
295 // finish the propfind request
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
296 // this function should cleanup all resources, therefore we execute it
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
297 // even if a previous function failed
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
298 if(webdav_op_propfind_finish(op)) {
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
299 // TODO: log error
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
300 ret = REQ_ABORTED;
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
301 }
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
302
242
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
303 // cleanup
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
304 xmlFreeDoc(propfind->doc);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
305
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
306 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
307 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
308
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
309 /*
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
310 * Initializes Backend Chain
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
311 *
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
312 * 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
313 * WebdavPropfindRequest objects for each backend
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 int webdav_propfind_init(
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
316 WebdavBackend *dav,
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
317 WebdavPropfindRequest *propfind,
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
318 const char *path,
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
319 UcxList **out_req)
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
320 {
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
321 pool_handle_t *pool = propfind->sn->pool;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
322 UcxAllocator *a = session_get_allocator(propfind->sn);
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 // 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
325 UcxList *requestObjects = NULL;
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 // 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
328 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
329 size_t newPropCount = propfind->propcount;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
330
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
331 // Call propfind_init for each Backend
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
332 // 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
333 // will be passed to the next backend
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
334
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
335 WebdavBackend *davList = dav;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
336 while(davList) {
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
337 // create WebdavPropfindRequest copy
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
338 WebdavPropfindRequest *pReq = pool_malloc(
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
339 pool,
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
340 sizeof(WebdavPropfindRequest));
220
2915b6c11aec add test for webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
341 memcpy(pReq, propfind, sizeof(WebdavPropfindRequest));
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
342 // 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
343 pReq->properties = newProp;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
344 pReq->propcount = newPropCount;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
345
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
346 // 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
347 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
348 if(!requestObjects) {
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
349 return REQ_ABORTED; // OOM
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
350 }
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
351
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
352 // 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
353 newProp = webdav_plist_clone(pool, newProp);
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
354
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
355 // 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
356 // which will be passed to the next backend
214
4d7ac67a1c14 add tests for webdav_propfind_init and fix wrong backend call
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 213
diff changeset
357 if(davList->propfind_init(pReq, path, &newProp)) {
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
358 return REQ_ABORTED;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
359 }
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
360
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
361 newPropCount = webdav_plist_size(newProp);
213
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
362
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
363 davList = davList->next;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
364 }
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
365
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
366 *out_req = requestObjects;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
367 return REQ_PROCEED;
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
368 }
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
369
4a6be4f10d5f move backend initialization to new function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
370
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
371 int webdav_proppatch(pblock *pb, Session *sn, Request *rq) {
242
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
372 char *expect = pblock_findkeyval(pb_key_expect, rq->headers);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
373 if(expect) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
374 if(!strcasecmp(expect, "100-continue")) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
375 if(http_send_continue(sn)) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
376 return REQ_ABORTED;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
377 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
378 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
379 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
380
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
381 UcxBuffer *reqbody = rqbody2buffer(sn, rq);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
382 if(!reqbody) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
383 return REQ_ABORTED;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
384 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
385
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
386 int error = 0;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
387 WebdavProppatchRequest *proppatch = proppatch_parse(
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
388 sn,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
389 rq,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
390 reqbody->space,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
391 reqbody->size,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
392 &error);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
393 ucx_buffer_free(reqbody);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
394 if(!proppatch) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
395 switch(error) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
396 // TODO: handle all errors
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
397 default: return REQ_ABORTED;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
398 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
399 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
400
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
401 WebdavBackend *dav = rq->davCollection ?
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
402 rq->davCollection : &default_backend;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
403
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
404 // requested uri and path
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
405 char *path = pblock_findkeyval(pb_key_path, rq->vars);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
406 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
407
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
408 // The multistatus response object contains responses for all
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
409 // requested resources. At the end the Multistatus object will be
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
410 // serialized to xml
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
411 Multistatus *ms = multistatus_response(sn, rq);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
412 if(!ms) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
413 return REQ_ABORTED;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
414 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
415 ms->proppatch = TRUE;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
416
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
417 // WebdavResponse is the public interface used by Backends
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
418 // for adding resources to the response
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
419 WebdavResponse *response = (WebdavResponse*)ms;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
420
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
421 WebdavOperation *op = webdav_create_proppatch_operation(
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
422 sn,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
423 rq,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
424 dav,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
425 proppatch,
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
426 response);
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 int ret = REQ_PROCEED;
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 // Execute proppatch
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
431 if(webdav_op_proppatch(op, uri, path)) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
432 ret = REQ_ABORTED;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
433 }
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 // send response
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
436 if(ret == REQ_PROCEED && multistatus_send(ms, sn->csd)) {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
437 ret = REQ_ABORTED;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
438 // TODO: log error
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
439 } else {
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
440 // TODO: error response
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
441 }
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
442
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
443 // cleanup
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
444 xmlFreeDoc(proppatch->doc);
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
445
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
446 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
447 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
448
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
449 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
450 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
451 if(!op) {
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
452 return REQ_ABORTED;
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
453 }
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
454
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
455 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
456
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
457 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
458 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
459
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
460 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
461 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
462 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
463
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
464 typedef struct DeleteFile {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
465 char *path;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
466 struct stat s;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
467 } DeleteFile;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
468
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
469 typedef struct DeleteLists {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
470 UcxAllocator *a;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
471 UcxList *dirs_begin;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
472 UcxList *dirs_end;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
473 UcxList *files_begin;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
474 UcxList *files_end;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
475 } DeleteOp;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
476
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
477 static int deletelist_add(
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
478 VFSContext *vfs,
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
479 const char *href,
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
480 const char *path,
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
481 VFSDir *parent,
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
482 struct stat *s,
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
483 void *userdata)
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
484 {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
485 DeleteOp *op = userdata;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
486
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
487 // create object for this file
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
488 DeleteFile *file = almalloc(op->a, sizeof(DeleteFile));
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
489 if(!file) {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
490 return 1;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
491 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
492 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
493 if(!file->path) {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
494 return 1;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
495 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
496 file->s = *s;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
497
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
498 // determine which list to use
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
499 UcxList **begin;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
500 UcxList **end;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
501 if(S_ISDIR(s->st_mode)) {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
502 begin = &op->dirs_begin;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
503 end = &op->dirs_end;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
504 } else {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
505 begin = &op->files_begin;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
506 end = &op->files_end;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
507 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
508
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
509 // add file to list
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
510 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
511 if(!elm) {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
512 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
513 alfree(op->a, file); // isn't really necessary
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
514 return 1;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
515 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
516 if(*begin == NULL) {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
517 *begin = elm;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
518 *end = elm;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
519 } else {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
520 ucx_list_concat(*end, elm);
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
521 *end = elm;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
522 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
523
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
524 return 0;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
525 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
526
246
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
527 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
528 {
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
529 DeleteOp del;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
530 ZERO(&del, sizeof(DeleteOp));
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
531 del.a = session_get_allocator(op->sn);
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
532
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
533 // get a list of all files
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
534 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
535 deletelist_add, &del))
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 return 1;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
538 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
539
249
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
540 // add root to list of dir list
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
541 DeleteFile root;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
542 root.path = op->path;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
543 root.s = *op->stat;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
544 UcxList root_elm;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
545 root_elm.data = &root;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
546 root_elm.prev = NULL;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
547 root_elm.next = del.dirs_begin;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
548
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
549 if(del.dirs_begin) {
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
550 del.dirs_begin->prev = &root_elm;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
551 del.dirs_begin = &root_elm;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
552 } else {
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
553 del.dirs_begin = &root_elm;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
554 del.dirs_end = &root_elm;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
555 }
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
556
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
557 // delete files first
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
558 UCX_FOREACH(elm, del.files_begin) {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
559 DeleteFile *file = elm->data;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
560 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
561 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
562 return 1;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
563 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
564 }
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 // delete directories, reverse order
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
567 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
568 DeleteFile *file = elm->data;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
569 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
570 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
571 return 1;
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
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
575 return 0;
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
576 }
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
577
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
578 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
579 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
580 if(!op) {
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
581 return REQ_ABORTED;
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
582 }
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
583
246
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
584 // 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
585 struct stat s;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
586 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
587 sys_set_error_status(op->vfs);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
588 return REQ_ABORTED;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
589 }
249
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
590 op->stat = &s;
246
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
591
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
592 int ret;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
593 if(S_ISDIR(s.st_mode)) {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
594 ret = webdav_delete_collection(op);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
595 } else {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
596 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
597 }
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
598
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
599 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
600 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
601
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
602 int webdav_put(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
603 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
604 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
605
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
606 int webdav_copy(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
607 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
608 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
609
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
610 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
611 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
612 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
613
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
614 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
615 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
616 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
617
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
618 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
619 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
620 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
621
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
622 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
623 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
624 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
625
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
626 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
627 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
628 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
629
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
630
244
e59abb210584 add minimal mkcol implementation and prepare delete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
631
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
632 /* ------------------------ 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
633
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
634 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
635 WebdavPropfindRequest *rq,
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
636 const char* path,
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
637 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
638 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
639 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
640 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
641 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
642 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
643 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
644 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
645 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
646
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
647 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
648
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
649 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
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 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
653 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
654 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
655 VFS_DIR parent,
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
656 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
657 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
658 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
659 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
660
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
661 // 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
662 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
663 resource,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
664 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
665 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
666 s))
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
667 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
668 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
669 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
670
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
671 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
672 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
673
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
674 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
675 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
676 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
677
243
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
678 int default_proppatch_do(
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
679 WebdavProppatchRequest *request,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
680 WebdavResource *response,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
681 VFSFile *file,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
682 WebdavPList **setInOut,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
683 WebdavPList **removeInOut)
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
684 {
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
685 return 0;
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
686 }
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
687
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
688 int default_proppatch_finish(
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
689 WebdavProppatchRequest *request,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
690 WebdavResource *response,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
691 VFSFile *file,
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
692 WSBool commit)
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
693 {
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
694 return 0;
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
695 }
1a29b1d8d9d8 add proppatch handler to default backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
696
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
697
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
698 /* ------------------------------ 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
699
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
700 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
701 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
702 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
703 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
704 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
705 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
706 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
707 } 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
708 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
709 }
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 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
712 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
713
227
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
714 int webdav_plist_add(
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
715 pool_handle_t *pool,
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
716 WebdavPList **begin,
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
717 WebdavPList **end,
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
718 WebdavProperty *prop)
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
719 {
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
720 WebdavPList *elm = pool_malloc(pool, sizeof(WebdavPList));
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
721 if(!elm) {
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
722 return 1;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
723 }
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
724 elm->prev = *end;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
725 elm->next = NULL;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
726 elm->property = prop;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
727
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
728 if(!*begin) {
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
729 *begin = elm;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
730 *end = elm;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
731 return 0;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
732 }
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
733
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
734 (*end)->next = elm;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
735 *end = elm;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
736
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
737 return 0;
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
738 }
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
739
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
740 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
741 return webdav_plist_clone_s(pool, list, NULL);
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
742 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
743
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
744 WebdavPList* webdav_plist_clone_s(
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
745 pool_handle_t *pool,
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
746 WebdavPList *list,
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
747 size_t *newlen)
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
748 {
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
749 WebdavPList *new_list = NULL; // start of the new list
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
750 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
751
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
752 size_t len = 0;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
753
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
754 WebdavPList *elm = list;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
755 while(elm) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
756 // copy list item
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
757 WebdavPList *new_elm = pool_malloc(pool, sizeof(WebdavPList));
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
758 if(!new_elm) {
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
759 if(newlen) *newlen = 0;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
760 return NULL;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
761 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
762 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
763 new_elm->prev = new_list_end;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
764 new_elm->next = NULL;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
765
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
766 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
767 new_list_end->next = new_elm;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
768 } else {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
769 new_list = new_elm;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
770 }
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
771 new_list_end = new_elm;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
772
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
773 len++;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
774 elm = elm->next;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
775 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
776
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
777 if(newlen) *newlen = len;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
778 return new_list;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
779 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
780
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
781 size_t webdav_plist_size(WebdavPList *list) {
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
782 size_t count = 0;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
783 WebdavPList *elm = list;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
784 while(elm) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
785 count++;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
786 elm = elm->next;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
787 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
788 return count;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
789 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
790
215
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
791 WebdavPListIterator webdav_plist_iterator(WebdavPList **list) {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
792 WebdavPListIterator i;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
793 i.list = list;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
794 i.cur = NULL;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
795 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
796 i.index = 0;
215
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
797 return i;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
798 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
799
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
800 int webdav_plist_iterator_next(WebdavPListIterator *i, WebdavPList **cur) {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
801 if(i->cur) {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
802 i->index++;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
803 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
804
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
805 i->cur = i->next;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
806 i->next = i->cur ? i->cur->next : NULL;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
807 *cur = i->cur;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
808
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
809 return i->cur != NULL;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
810 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
811
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
812 void webdav_plist_iterator_remove_current(WebdavPListIterator *i) {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
813 WebdavPList *cur = i->cur;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
814 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
815 cur->prev->next = cur->next;
215
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
816 if(cur->next) {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
817 cur->next->prev = cur->prev;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
818 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
819 } else {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
820 *i->list = cur->next;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
821 if(cur->next) {
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
822 cur->next->prev = NULL;
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
823 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
824 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
825 }
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
826
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
827 int webdav_nslist_add(
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
828 pool_handle_t *pool,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
829 WebdavNSList **begin,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
830 WebdavNSList **end,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
831 WSNamespace *ns)
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
832 {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
833 // 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
834 WebdavNSList *elm = pool_malloc(pool, sizeof(WebdavNSList));
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
835 if(!elm) {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
836 return 1;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
837 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
838 elm->prev = *end;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
839 elm->next = NULL;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
840 elm->namespace = ns;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
841
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
842 if(!*begin) {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
843 *begin = elm;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
844 *end = elm;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
845 return 0;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
846 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
847
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
848 (*end)->next = elm;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
849 *end = elm;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
850
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
851 return 0;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
852 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
853
215
68e824ba4a4f add plist iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
854
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
855 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
856 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
857 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
858
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
859 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
860 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
861 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
862 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
863 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
864 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
865 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
866 }
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
867 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
868
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
869 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
870 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
871 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
872 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
873
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
874 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
875 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
876 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
877 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
878 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
879 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
880 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
881 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
882 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
883 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
884
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
885 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
886 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
887
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
888 p->value.node = node;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
889 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
890 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
891 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
892
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
893 WebdavVFSProperties webdav_vfs_properties(
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
894 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
895 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
896 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
897 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
898 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
899 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
900
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
901 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
902 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
903
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
904 WebdavPListIterator i = webdav_plist_iterator(plistInOut);
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
905 WebdavPList *cur;
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
906 while(webdav_plist_iterator_next(&i, &cur)) {
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
907 WSNamespace *ns = cur->property->namespace;
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
908 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
909 const char *name = cur->property->name;
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
910 WSBool remove_prop = TRUE;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
911 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
912 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
913 } 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
914 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
915 } 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
916 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
917 } 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
918 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
919 } 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
920 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
921 } else {
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
922 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
923 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
924
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
925 if(remove_prop) {
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
926 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
927 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
928 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
929 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
930
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
931 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
932 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
933
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
934 static inline int w_addprop(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
935 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
936 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
937 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
938 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
939 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
940 WebdavProperty *p = webdav_dav_property(pool, name);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
941 if(!p) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
942 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
943 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
944 if(webdav_property_set_value(p, pool, value)) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
945 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
946 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
947 return res->addproperty(res, p, 200);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
948 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
949
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
950 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
951 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
952 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
953 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
954 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
955 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
956 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
957 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
958 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
959 } else {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
960 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
961 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
962 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
963 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
964 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
965 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
966 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
967 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
968 uint64_t contentlength = 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
969 snprintf(buf, 64, "%" PRIu64 "\0", contentlength);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
970 if(w_addprop(res, pool, "getcontentlength", buf)) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
971 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
972 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
973 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
974 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
975 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
976 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
977 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
978 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
979 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
980
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
981 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
982 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
983
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
984 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
985 strftime(buf, HTTP_DATE_LEN, HTTP_DATE_FMT, mtm);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
986 if(w_addprop(res, pool, "getlastmodified", buf)) {
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 1;
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 } else {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
990 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
991 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
992 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
993 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
994 // TODO
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
995 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
996 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
997 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
998 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
999 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
1000 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1001 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
1002 96,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1003 "\"%x-%x\"\0",
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1004 (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
1005 (int)s->st_mtim.tv_sec);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1006 if(w_addprop(res, pool, "getetag", buf)) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1007 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
1008 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1009 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1010
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1011 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
1012 }

mercurial