src/server/webdav/webdav.c

Sun, 29 Dec 2019 15:09:58 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 29 Dec 2019 15:09:58 +0100
branch
webdav
changeset 212
d7e7ea9c6bc6
parent 211
2160585200ac
child 213
4a6be4f10d5f
permissions
-rw-r--r--

refactore webdav backend struct

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"
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
42
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
43 #include "../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
44 #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
45 #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
46 #include "../daemon/http.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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
48 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
49
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
50 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
51
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
52 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
53
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
54 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
55 static WebdavProperty dav_resourcetype_collection;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
56 static WSXmlNode dav_resourcetype_collection_value; // TODO: change type to WSXmlData
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
57
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 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
59 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
60 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
61 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
62 default_backend.propfind_finish = default_propfind_finish;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
63 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
64
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
65 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
66 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
67
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
68 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
69
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
70 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
71 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
72 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
73 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
74 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
75 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
76 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
77 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
78 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
79 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
80 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
81 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
82 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
83
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, "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
85
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, "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
87 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
88 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
89 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
90 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
91 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
92 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
93 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
94
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
95 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
96 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
97
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
98 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
99 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
100
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
101 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
102 dav_resourcetype_collection.name = "resourcetype";
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
103 dav_resourcetype_collection.value.node = &dav_resourcetype_collection_value;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
104 dav_resourcetype_collection.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
105 dav_resourcetype_collection_value.content = (xmlChar*)"<D:collection/>";
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_resourcetype_collection_value.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
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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
109 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
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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
112
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
113 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
114 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
115 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
116 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
117 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
118 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
119 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
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 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
122 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
123 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
124 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
125
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 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
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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
129 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
130 if(!sn->inbuf) {
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
131 //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
132 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
133 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
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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
136 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
137 NULL,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
138 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
139 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
140 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
141 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
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 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
146 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
147 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
148 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
149 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
150 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
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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
155 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
156 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
157
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
158 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
159 return REQ_ABORTED;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
160 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
161
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
162 int webdav_propfind(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
163 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
164 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
165 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
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
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
168 UcxAllocator *a = session_get_allocator(sn);
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
169
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
170 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
171 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
172 sn,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
173 rq,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
174 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
175 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
176 &error);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
177 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
178 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
179 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
180 // 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
181 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
182 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
183 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
184
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
185 // The multistatus response object contains responses for all
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
186 // requested resources. At the end the Multistatus object will be
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
187 // serialized to xml
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 Multistatus *ms = multistatus_response(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
189 if(!ms) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
190 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
191 }
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
192 // WebdavResponse is the public interface used by Backends
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
193 // for adding resources to the response
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
194 WebdavResponse *response = (WebdavResponse*)ms;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
195
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
196 WebdavBackend *dav =
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
197 rq->davCollection ? rq->davCollection : &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
198
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
199 // requested uri 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
200 char *path = pblock_findkeyval(pb_key_path, rq->vars);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
201
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
202 // Initialize WebDAV Backend Chain
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
203 //
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
204 // Call propfind_init of each Backend
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
205 // propfind_init can return a new property list, which
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
206 // will be passed to the next backend
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
207 //
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
208 // 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
209 uint32_t settings = dav->settings;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
210
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
211 // list of individual WebdavPropfindRequest objects for each Backend
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
212 UcxList *backendPropfind = NULL;
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 // new properties after init, start with clone of original plist
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
215 WebdavPList *newProp = webdav_plist_clone(sn->pool, propfind->properties);
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
216 size_t newPropCount = propfind->propcount;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
217
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
218 WebdavBackend *davList = dav;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
219 while(davList) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
220 // create WebdavPropfindRequest copy
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
221 WebdavPropfindRequest *pReq = pool_malloc(
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
222 sn->pool,
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
223 sizeof(WebdavPropfindRequest));
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
224 memcpy(propfind, pReq, sizeof(WebdavPropfindRequest));
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
225 // use new plist after previous init (or orig. plist in the first run)
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
226 pReq->properties = newProp;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
227 pReq->propcount = newPropCount;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
228
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
229 // add new WebdavPropfindRequest object to list for later use
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
230 backendPropfind = ucx_list_append_a(a, backendPropfind, pReq);
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
231 if(!backendPropfind) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
232 return REQ_ABORTED; // OOM
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
233 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
234
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
235 // create plist copy as out-plist for init
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
236 newProp = webdav_plist_clone(sn->pool, newProp);
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
237
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
238 // run init: this can generate a new properties list (newProp)
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
239 // which will be passed to the next backend
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
240 if(dav->propfind_init(pReq, path, &newProp)) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
241 return REQ_ABORTED;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
242 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
243
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
244 newPropCount = webdav_plist_count(newProp);
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
245
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
246 davList = davList->next;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
247 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
248
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
249 // 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
250 // require the VFS for this
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
251 WSBool usevfs = (settings & WS_PROPFIND_NO_VFS) != WS_PROPFIND_NO_VFS;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
252 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
253 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
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 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
256 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
257 vfs = vfs_request_context(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
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 if(vfs_stat(vfs, path, &s)) {
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
260 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
261 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
262 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
263 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
264 if(!S_ISDIR(s.st_mode)) {
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
265 // 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
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 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
269 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
270 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
271 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
272
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
273 int ret = REQ_ABORTED;
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
274 if(!webdav_propfind_do(dav, backendPropfind, response, NULL, path, 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
275 // 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
276
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
277 // 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
278 // 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
279 // 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
280 // 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
281 // in this case we need to execute propfind_do for all children
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
282 if(usevfs && !propfind_children(dav, backendPropfind, response, vfs, 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
283 ret = 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
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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
287 // finish the propfind request
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
288 // this function should cleanup all resources, therefore we execute it
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
289 // even if a previous function failed
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
290 if(dav->propfind_finish(propfind)) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
291 ret = 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
292 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
293
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
294 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
295 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
296
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
297 /*
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
298 * Executes propfind_do for each Backend
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
299 * The list requests must contain all WebdavPropfindRequest objects
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
300 * of all backends
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
301 */
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
302 int webdav_propfind_do(
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
303 WebdavBackend *webdav,
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
304 UcxList *requests,
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
305 WebdavResponse *response,
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
306 VFS_DIR parent,
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
307 const char *path,
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
308 struct stat *s)
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
309 {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
310 while(webdav && requests) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
311 if(webdav->propfind_do(requests->data, response, parent, path, s)) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
312 return REQ_ABORTED;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
313 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
314
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
315 webdav = webdav->next;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
316 requests = requests->next;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
317 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
318 return REQ_PROCEED;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
319 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
320
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
321 /*
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
322 * Executes propfind_finish for each Backend
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
323 */
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
324 int webdav_propfind_finish(WebdavBackend *webdav, UcxList *requests) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
325 int ret = REQ_PROCEED;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
326 while(webdav && requests) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
327 if(webdav->propfind_finish(requests->data)) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
328 ret = REQ_ABORTED;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
329 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
330
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
331 webdav = webdav->next;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
332 requests = requests->next;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
333 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
334 return ret;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
335 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
336
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
337
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
338 /*
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
339 * Uses the VFS to iterate over all children of the requsted resource
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
340 * and executes propfind for each child
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
341 */
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
342 int propfind_children(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
343 WebdavBackend *dav,
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
344 UcxList *requests,
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
345 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
346 VFSContext *vfs,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
347 char *path)
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
348 {
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
349 WebdavPropfindRequest *request = requests->data;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
350
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
351 UcxAllocator *a = session_get_allocator(request->sn);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
352 pool_handle_t *pool = 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
353 UcxList *stack = ucx_list_prepend_a(a, NULL, path);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
354 UcxList *stack_end = stack;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
355 if(!stack) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
356 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
357 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
358
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
359 // reusable buffer for full child path
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
360 char *newpath = NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
361 size_t newpathlen = 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
362
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
363 int err = 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
364 while(stack && !err) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
365 char *cur_path = stack->data;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
366 size_t parent_len = strlen(cur_path);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
367 if(parent_len > WEBDAV_PATH_MAX) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
368 log_ereport(LOG_FAILURE, "webdav: maximal path length exceeded");
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
369 err = 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
370 break;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
371 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
372 if(cur_path[parent_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
373 parent_len--;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
374 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
375 size_t max_child_len = WEBDAV_PATH_MAX - parent_len;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
376
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
377 // when newpath is initialized with the parent path
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
378 // set path_buf_init to TRUE
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
379 WSBool path_buf_init = FALSE;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
380
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
381 VFS_DIR dir = vfs_opendir(vfs, path);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
382 if(!dir) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
383 log_ereport(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
384 LOG_FAILURE,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
385 "webdav: propfind: cannot open directory %d",
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
386 vfs->vfs_errno);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
387 err = 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
388 break;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
389 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
390
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
391 VFS_ENTRY f;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
392 while(vfs_readdir_stat(dir, &f)) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
393 if(f.stat_errno != 0) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
394 continue;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
395 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
396
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
397 size_t child_len = strlen(f.name);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
398 if(child_len > max_child_len) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
399 log_ereport(LOG_FAILURE, "webdav: maximal path length exceeded");
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
400 err = 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
401 break;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
402 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
403 size_t childpathlen = parent_len + child_len + 1; // +1 '/'
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
404 if(childpathlen > newpathlen) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
405 // we're gonna need a bigger boa^H^H^Hbuffer
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
406 if(newpath) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
407 pool_free(pool, newpath);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
408 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
409 newpath = pool_malloc(pool, childpathlen + 1);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
410 if(!newpath) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
411 err = 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
412 break;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
413 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
414 newpathlen = childpathlen;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
415 path_buf_init = FALSE;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
416 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
417 // create full path string for this child
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
418 if(!path_buf_init) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
419 memcpy(newpath, cur_path, parent_len);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
420 newpath[parent_len] = '/';
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
421 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
422 memcpy(newpath+parent_len+1, f.name, child_len);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
423 newpath[childpathlen] = 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
424
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
425 // propfind for this child
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
426 if(webdav_propfind_do(dav, requests, response, dir, newpath, &f.stat)) {
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
427 err = 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
428 break;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
429 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
430
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
431 // depth of -1 means infinity
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
432 if(request->depth == -1 && S_ISDIR(f.stat.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
433 char *pathcp = pool_malloc(pool, childpathlen + 1);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
434 memcpy(pathcp, newpath, childpathlen + 1);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
435
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
436 // add the newpath copy to the stack
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
437 // stack_end is always not NULL here, because we remove
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
438 // the first stack element at the end of the loop
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
439 UcxList *newlistelm = ucx_list_append_a(a, stack_end, pathcp);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
440 if(!newlistelm) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
441 err = 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
442 break;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
443 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
444 stack_end = newlistelm;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
445 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
446 }
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 vfs_closedir(dir);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
449
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
450 if(cur_path != path) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
451 pool_free(pool, cur_path);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
452 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
453 stack = ucx_list_remove_a(a, stack, stack);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
454 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
455
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
456 // in case of an error, we have to free all remaining stack elements
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
457 UCX_FOREACH(elm, stack) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
458 char *data = elm->data;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
459 if(data != path) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
460 pool_free(pool, data);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
461 }
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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
464 return err;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
465 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
466
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
467 int webdav_proppatch(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
468 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
469 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
470
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
471 int webdav_mkcol(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
472 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
473 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
474
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
475 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
476 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
477 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
478
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
479 int webdav_delete(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
480 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
481 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
482
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
483 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
484 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
485 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
486
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
487 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
488 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
489 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
490
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
491 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
492 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
493 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
494
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
495 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
496 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
497 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
498
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
499 int webdav_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
500 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
501 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
502
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
503 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
504 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
505 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
506
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
507 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
508 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
509 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
510
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
511
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
512 /* ------------------------ 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
513
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
514 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
515 WebdavPropfindRequest *rq,
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
516 const char* path,
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
517 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
518 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
519 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
520 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
521 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
522 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
523 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
524 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
525 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
526
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
527 data->vfsproperties = webdav_vfs_properties(rq, TRUE, 0);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
528
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
529 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
530 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
531
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
532 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
533 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
534 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
535 VFS_DIR parent,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
536 const char *path,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
537 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
538 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
539 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
540
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
541 // add a resource to the response
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
542 // usually this will lead to a <response> ... </response> tag in the
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
543 // multistatus response
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
544 WebdavResource *resource = response->addresource(response, path);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
545 if(!resource) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
546 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
547 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
548
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
549 // 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
550 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
551 resource,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
552 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
553 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
554 s))
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
555 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
556 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
557 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
558
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
559 // all remaining properties are not available
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
560 WebdavPList *p = request->properties;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
561 while(p) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
562 resource->addproperty(resource, p->property, 404);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
563 p = p->next;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
564 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
565
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
566 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
567 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
568
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
569 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
570 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
571 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
572
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
573
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
574 /* ------------------------------ 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
575
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
576 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
577 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
578 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
579 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
580 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
581 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
582 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
583 } 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
584 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
585 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
586 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
587 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
588 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
589
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
590 WebdavPList* webdav_plist_clone(pool_handle_t *pool, WebdavPList *list) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
591 WebdavPList *new_list = NULL; // start of the new list
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
592 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
593
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
594 WebdavPList *elm = list;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
595 while(elm) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
596 // copy list item
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
597 WebdavPList *new_elm = pool_malloc(pool, sizeof(WebdavPList));
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
598 if(!new_elm) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
599 return NULL;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
600 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
601 new_elm->property = elm->property; // new list contains original ptr
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
602 new_elm->prev = NULL;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
603 new_elm->next = NULL;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
604
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
605 if(new_list_end) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
606 new_list_end->next = elm;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
607 elm->prev = new_list_end;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
608
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
609 new_list_end = elm;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
610 } else {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
611 new_list = new_elm;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
612 new_list_end = new_elm;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
613 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
614
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
615 elm = elm->next;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
616 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
617
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
618 return new_list;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
619 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
620
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
621 size_t webdav_plist_count(WebdavPList *list) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
622 size_t count = 0;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
623 WebdavPList *elm = list;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
624 while(elm) {
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
625 count++;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
626 elm = elm->next;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
627 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
628 return count;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
629 }
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
630
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
631 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
632 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
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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
635 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
636 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
637 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
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 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
640 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
641 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
642 }
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
643 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
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 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
646 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
647 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
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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
650 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
651 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
652 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
653 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
654 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
655 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
656 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
657 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
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 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
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 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
662 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
663
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
664 p->value.node = node;
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
665 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
666 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
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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
669 WebdavVFSProperties webdav_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
670 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
671 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
672 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
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 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
675 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
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 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
678 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
679
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
680 WebdavPList *property = rq->properties;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
681 WebdavPList *prev = NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
682 while(property) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
683 WebdavPList *next = property->next;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
684 WSNamespace *ns = property->property->namespace;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
685 if(ns && !strcmp((char*)ns->href, "DAV:")) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
686 const char *name = property->property->name;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
687 WebdavPList *removethis = property;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
688 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
689 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
690 } 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
691 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
692 } 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
693 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
694 } 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
695 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
696 } 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
697 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
698 } else {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
699 removethis = NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
700 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
701
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
702 if(removefromlist && removethis) {
212
d7e7ea9c6bc6 refactore webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
703
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
704 if(prev) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
705 prev->next = next;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
706 } else {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
707 rq->properties = next;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
708 }
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 prev = property;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
712 property = next;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
713 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
714
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
715 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
716 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
717
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
718 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
719 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
720 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
721 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
722 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
723 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
724 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
725 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
726 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
727 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
728 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
729 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
730 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
731 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
732 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
733
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
734 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
735 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
736 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
737 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
738 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
739 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
740 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
741 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
742 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
743 } else {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
744 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
745 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
746 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
747 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
748 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
749 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
750 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
751 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
752 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
753 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
754 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
755 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
756 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
757 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
758 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
759 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
760 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
761 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
762 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
763 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
764
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
765 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
766 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
767
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
768 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
769 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
770 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
771 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
772 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
773 } else {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
774 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
775 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
776 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
777 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
778 // TODO
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
779 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
780 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
781 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
782 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
783 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
784 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
785 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
786 96,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
787 "\"%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
788 (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
789 (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
790 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
791 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
792 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
793 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
794
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
795 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
796 }

mercurial