src/server/webdav/multistatus.c

Sun, 08 May 2022 12:27:43 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 08 May 2022 12:27:43 +0200
branch
webdav
changeset 344
70a9b945206a
parent 309
fc021bd576d4
child 349
7bf652914e9b
permissions
-rw-r--r--

fix webdav_mkcol response and add error handling

211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
4 * Copyright 2020 Olaf Wintermann. All rights reserved.
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include "../daemon/session.h"
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
33 #include "../daemon/protocol.h"
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
34 #include "../util/platform.h"
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
35
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
36 #include <ucx/string.h>
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
38 #include "multistatus.h"
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
39
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
40 #include "operation.h"
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
41 #include "xml.h"
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 #define MULTISTATUS_BUFFER_LENGTH 2048
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 Multistatus* multistatus_response(Session *sn, Request *rq) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 Multistatus *ms = pool_malloc(sn->pool, sizeof(Multistatus));
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 if(!ms) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 return NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 ZERO(ms, sizeof(Multistatus));
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 ms->response.addresource = multistatus_addresource;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 ms->sn = sn;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 ms->rq = rq;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 ms->namespaces = ucx_map_new_a(session_get_allocator(ms->sn), 8);
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
55 ms->proppatch = FALSE;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 if(!ms->namespaces) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 return NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 }
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
59 if(ucx_map_cstr_put(ms->namespaces, "D", webdav_dav_namespace())) {
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 return NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 return ms;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
65 static int send_xml_root(Multistatus *ms, Writer *out) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
66 writer_puts(out, S("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
67 "<D:multistatus"));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
68
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
69 // write the namespaces definitions
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
70 // key is the namespace prefix
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
71 // the map always contains the "DAV:" namespace with the prefix "D"
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
72 UcxMapIterator i = ucx_map_iterator(ms->namespaces);
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
73 WSNamespace *ns;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
74 UCX_MAP_FOREACH(key, ns, i) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
75 writer_puts(out, S(" xmlns:"));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
76 writer_put(out, key.data, key.len);
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
77 writer_puts(out, S("=\""));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
78 writer_puts(out, sstr((char*)ns->href));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
79 writer_puts(out, S("\""));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
80 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
81
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
82 writer_puts(out, S(">\n"));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
83
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
84 return out->error;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
85 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
86
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
87 static void send_nsdef(WSNamespace *ns, Writer *out) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
88 writer_puts(out, S(" xmlns:"));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
89 writer_puts(out, sstr((char*)ns->prefix));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
90 writer_puts(out, S("=\""));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
91 writer_puts(out, sstr((char*)ns->href));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
92 writer_putc(out, '\"');
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
93 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
94
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
95 static int send_property(
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
96 Multistatus *ms,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
97 WebdavProperty *property,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
98 WebdavNSList *nsdef,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
99 WSBool writeContent,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
100 Writer *out)
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
101 {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
102 // write: "<prefix:name"
238
e820d433f405 fix multistatus response and add propfind tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
103 writer_putc(out, '<');
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
104 writer_puts(out, sstr((char*)property->namespace->prefix));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
105 writer_putc(out, ':');
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
106 writer_puts(out, sstr((char*)property->name));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
107
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
108 // check if the namespace is already defined
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
109 WSBool need_nsdef = TRUE;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
110 WSNamespace *ns = ucx_map_cstr_get(
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
111 ms->namespaces,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
112 (char*)property->namespace->prefix);
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
113 if(ns && !strcmp(
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
114 (const char*)ns->href,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
115 (const char*)property->namespace->href))
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
116 {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
117 need_nsdef = FALSE; // prefix and href are the same, no need for nsdef
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
118 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
119
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
120 // send definition for the element's namespace
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
121 if(need_nsdef) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
122 send_nsdef(property->namespace, out);
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
123 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
124
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
125 // send additional namespace definitions required for the value
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
126 WebdavNSList *def = nsdef;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
127 while(def) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
128 send_nsdef(def->namespace, out);
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
129 def = def->next;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
130 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
131
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
132 // send xml lang attribute
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
133 if(property->lang) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
134 writer_puts(out, S(" xml:lang=\""));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
135 writer_puts(out, sstr((char*)property->lang));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
136 writer_putc(out, '\"');
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
137 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
138
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
139 // end property tag and write content
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
140 if(writeContent) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
141 writer_putc(out, '>');
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
142
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
143 // content
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
144 switch(property->vtype) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
145 case WS_VALUE_NO_TYPE: break;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
146 case WS_VALUE_XML_NODE: {
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
147 wsxml_write_nodes_without_nsdef(
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
148 ms->sn->pool,
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
149 out,
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
150 property->value.node);
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
151 break;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
152 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
153 case WS_VALUE_XML_DATA: {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
154 // only write data, data->namespaces is already handled
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
155 writer_put(
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
156 out,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
157 property->value.data->data,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
158 property->value.data->length);
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
159 break;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
160 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
161 case WS_VALUE_TEXT: {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
162 // asume the text is already escaped
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
163 writer_put(
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
164 out,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
165 property->value.text.str,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
166 property->value.text.length);
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
167 break;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
168 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
169 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
170
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
171 // end tag
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
172 writer_puts(out, S("</"));
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
173 writer_puts(out, sstr((char*)property->namespace->prefix));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
174 writer_putc(out, ':');
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
175 writer_puts(out, sstr((char*)property->name));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
176 writer_putc(out, '>');
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
177 } else {
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
178 writer_puts(out, S("/>"));
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
179 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
180
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
181 return out->error;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
182 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
183
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
184 static int send_response_tag(Multistatus *ms, MSResponse *rp, Writer *out) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
185 writer_puts(out, S(" <D:response>\n"
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
186 " <D:href>"));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
187 writer_puts(out, sstr(rp->resource.href));
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
188 writer_puts(out, S("</D:href>\n"));
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
189
242
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
190 WSBool writeContent = ms->proppatch ? FALSE : TRUE;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
191
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
192 if(rp->plist_begin) {
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
193 writer_puts(out, S(" <D:propstat>\n"
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
194 " <D:prop>\n"));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
195 // send properties
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
196 PropertyOkList *p = rp->plist_begin;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
197 while(p) {
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
198 writer_puts(out, S(" "));
242
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
199 if(send_property(ms, p->property, p->nsdef, writeContent, out)) {
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
200 return out->error;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
201 }
242
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
202 writer_puts(out, S("\n"));
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
203 p = p->next;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
204 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
205
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
206 writer_puts(out, S(" </D:prop>\n"
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
207 " <D:status>HTTP/1.1 200 OK</D:status>\n"
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
208 " </D:propstat>\n"));
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
209 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
210
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
211 // send error properties
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
212 PropertyErrorList *error = rp->errors;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
213 while(error) {
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
214 writer_puts(out, S(" <D:propstat>\n"
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
215 " <D:prop>\n"));
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
216
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
217 WebdavPList *errprop = error->begin;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
218 while(errprop) {
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
219 writer_puts(out, S(" "));
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
220 if(send_property(ms, errprop->property, NULL, FALSE, out)) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
221 return out->error;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
222 }
238
e820d433f405 fix multistatus response and add propfind tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
223 writer_putc(out, '\n');
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
224 errprop = errprop->next;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
225 }
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
226
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
227 char statuscode[8];
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
228 int sclen = snprintf(statuscode, 8, "%d ", error->status);
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
229 if(sclen > 4) {
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
230 statuscode[0] = '5';
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
231 statuscode[1] = '0';
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
232 statuscode[2] = '0';
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
233 statuscode[3] = ' ';
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
234 sclen = 4;
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
235 }
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
236 writer_puts(out, S(" </D:prop>\n"
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
237 " <D:status>HTTP/1.1 "));
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
238 writer_put(out, statuscode, sclen);
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
239 const char *status_msg = protocol_status_message(error->status);
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
240 if(status_msg) {
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
241 writer_put(out, status_msg, strlen(status_msg));
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
242 } else {
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
243 writer_puts(out, S("Server Error"));
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
244 }
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
245 writer_puts(out, S("</D:status>\n"
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
246 " </D:propstat>\n"));
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
247
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
248
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
249 error = error->next;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
250 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
251
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
252 // end response tag
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
253 writer_puts(out, S(" </D:response>\n"));
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
254
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
255 return out->error;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
256 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
257
308
c3cad8f51a24 close last resource in multistatus_send
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 252
diff changeset
258 int multistatus_send(Multistatus *ms, SYS_NETFD net) {
c3cad8f51a24 close last resource in multistatus_send
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 252
diff changeset
259 // make sure every resource is closed
c3cad8f51a24 close last resource in multistatus_send
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 252
diff changeset
260 if(ms->current && !ms->current->resource.isclosed) {
309
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 308
diff changeset
261 if(msresponse_close((WebdavResource*)ms->current)) {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 308
diff changeset
262 return 1;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 308
diff changeset
263 }
308
c3cad8f51a24 close last resource in multistatus_send
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 252
diff changeset
264 }
c3cad8f51a24 close last resource in multistatus_send
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 252
diff changeset
265
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
266 // start http response
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
267 protocol_status(ms->sn, ms->rq, 207, NULL);
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
268 protocol_start_response(ms->sn, ms->rq);
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
269
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 char buffer[MULTISTATUS_BUFFER_LENGTH];
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
271 // create a writer, that flushes the buffer when it is filled
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 Writer writer;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 Writer *out = &writer;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274 writer_init(out, net, buffer, MULTISTATUS_BUFFER_LENGTH);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
276 // send the xml root element with namespace defs
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
277 if(send_xml_root(ms, out)) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
278 return 1;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
279 }
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
281 // send response tags
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
282 MSResponse *response = ms->first;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
283 while(response) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
284 if(send_response_tag(ms, response, out)) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
285 return 1;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
286 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
287 response = response->next;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
288 }
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
289
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
290 // end multistatus
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
291 writer_puts(out, S("</D:multistatus>\n"));
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
292
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
293 writer_flush(out);
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
294
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
295 return 0;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 WebdavResource * multistatus_addresource(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 WebdavResponse *response,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 const char *path)
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 Multistatus *ms = (Multistatus*)response;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303 MSResponse *res = pool_malloc(ms->sn->pool, sizeof(MSResponse));
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 if(!res) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305 return NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 ZERO(res, sizeof(MSResponse));
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
309 // set href
223
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
310 res->resource.href = pool_strdup(ms->sn->pool, path);
226
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
311 if(!res->resource.href) {
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
312 return NULL;
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
313 }
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
314
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
315 res->resource.err = 0;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
316
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
317 // add resource funcs
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
318 res->resource.addproperty = msresponse_addproperty;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
319 res->resource.close = msresponse_close;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320
226
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
321 res->properties = ucx_map_new_a(session_get_allocator(ms->sn), 32);
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
322 if(!res->properties) {
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
323 return NULL;
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
324 }
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
325
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 res->multistatus = ms;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327 res->errors = NULL;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
328 res->resource.isclosed = 0;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
329 res->closing = 0;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
331 // add new resource to the resource list
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
332 if(ms->current) {
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
333 // before adding a new resource, the current resource must be closed
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
334 if(!ms->current->resource.isclosed) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
335 msresponse_close((WebdavResource*)ms->current);
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
336 }
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337 ms->current->next = res;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338 } else {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339 ms->first = res;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341 ms->current = res;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343 return (WebdavResource*)res;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
346 static int oklist_add(
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
347 pool_handle_t *pool,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
348 PropertyOkList **begin,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
349 PropertyOkList **end,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
350 WebdavProperty *property,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
351 WebdavNSList *nsdef)
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
352 {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
353 PropertyOkList *newelm = pool_malloc(pool, sizeof(PropertyOkList));
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
354 if(!newelm) {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
355 return 1;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
356 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
357 newelm->property = property;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
358 newelm->nsdef = nsdef;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
359 newelm->next = NULL;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
360 if(*end) {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
361 (*end)->next = newelm;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
362 } else {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
363 *begin = newelm;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
364 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
365 *end = newelm;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
366 return 0;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
367 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
368
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
369 int msresponse_addproperty(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
370 WebdavResource *res,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
371 WebdavProperty *property,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
372 int status)
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
373 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
374 MSResponse *response = (MSResponse*)res;
227
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
375 Session *sn = response->multistatus->sn;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
376 if(response->resource.isclosed) {
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
377 log_ereport(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
378 LOG_WARN,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
379 "%s",
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
380 "webdav: cannot add property to closed response tag");
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
381 return 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
382 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
383
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
384 // some WebdavProperty checks to make sure nothing explodes
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
385 if(!property->namespace || !property->namespace->href) {
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
386 // error: namespace is required
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
387 log_ereport(
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
388 LOG_FAILURE,
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
389 "%s",
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
390 "webdav: property '%s' has no namespace",
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
391 property->name);
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
392 return 1;
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
393 }
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
394
226
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
395 // check if the property was already added to the resource
227
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
396 UcxAllocator *a = session_get_allocator(sn);
226
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
397 sstr_t key = sstrcat_a(
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
398 a,
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
399 3,
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
400 sstr((char*)property->namespace->href),
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
401 S("\0"),
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
402 sstr((char*)property->name));
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
403 if(ucx_map_sstr_get(response->properties, key)) {
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
404 a->free(a->pool, key.ptr);
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
405 return 0;
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
406 }
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
407 if(ucx_map_sstr_put(response->properties, key, property)) {
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
408 return 1; // OOM
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
409 }
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
410 a->free(a->pool, key.ptr);
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
411
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
412 // list of namespace definitions for this property
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
413 WebdavNSList *nsdef_begin = NULL;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
414 WebdavNSList *nsdef_end = NULL;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
415
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
416 // add namespace of this property to the namespace map
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
417 // the namespace map will be used for global namespace definitions
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
418 if(property->namespace->prefix) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
419 WSNamespace *ns = ucx_map_cstr_get(
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
420 response->multistatus->namespaces,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
421 (const char*)property->namespace->prefix);
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
422 if(!ns) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
423 // prefix is not in use -> we can add the namespace to the ns map
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
424 int err = ucx_map_cstr_put(
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
425 response->multistatus->namespaces,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
426 (const char*)property->namespace->prefix,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
427 property->namespace);
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
428 if(err) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
429 return 1; // OOM
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
430 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
431 } else if(
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
432 strcmp((const char*)property->namespace->href,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
433 (const char*)ns->href))
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
434 {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
435 // global namespace != local namespace
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
436 // therefore we need a namespace definition in this element
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
437
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
438 // ns-prefix != property-prefix -> add ns to nsdef
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
439 if(webdav_nslist_add(
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
440 sn->pool,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
441 &nsdef_begin,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
442 &nsdef_end,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
443 property->namespace))
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
444 {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
445 return 1; // OOM
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
446 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
447 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
448 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
449
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
450 if(response->multistatus->proppatch && response->errors) {
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
451 // in a proppatch request all operations must succeed
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
452 // if we have an error, the property update status code must be
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
453 // 424 Failed Dependency
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
454 status = 424;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
455 }
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
456
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
457 // error properties will be added to a separate list
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
458 if(status != 200) {
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
459 return msresponse_addproperror(response, property, status);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
460 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
461
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
462 // add all namespaces used by this property to the nsdef list
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
463 WebdavNSList *nslist = NULL;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
464 if(property->vtype == WS_VALUE_XML_NODE) {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
465 // iterate over xml tree and collect all namespaces
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
466 int err = 0;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
467 nslist = wsxml_get_required_namespaces(
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
468 response->multistatus->sn->pool,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
469 property->value.node,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
470 &err);
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
471 if(err) {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
472 return 1; // OOM
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
473 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
474 } else if(property->vtype == WS_VALUE_XML_DATA) {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
475 // xml data contains a list of all used namespaces
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
476 nslist = property->value.data->namespaces;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
477 } // other value types don't contain xml namespaces
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
478
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
479 while(nslist) {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
480 // only add the namespace to the definitions list, if it isn't a
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
481 // property namespace, because the prop ns is already added
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
482 // to the element's def list or global definitions list
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
483 if(strcmp(
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
484 (const char*)nslist->namespace->prefix,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
485 (const char*)property->namespace->prefix))
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
486 {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
487 // ns-prefix != property-prefix -> add ns to nsdef
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
488 if(webdav_nslist_add(
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
489 sn->pool,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
490 &nsdef_begin,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
491 &nsdef_end,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
492 nslist->namespace))
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
493 {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
494 return 1; // OOM
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
495 }
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
496 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
497 nslist = nslist->next;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
498 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
499
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
500 // add property to the list
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
501 if(oklist_add(
227
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
502 sn->pool,
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
503 &response->plist_begin,
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
504 &response->plist_end,
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
505 property,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
506 nsdef_begin))
227
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
507 {
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
508 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
509 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
510 return 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
511 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
512
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
513 int msresponse_addproperror(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
514 MSResponse *response,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
515 WebdavProperty *property,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
516 int statuscode)
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
517 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
518 pool_handle_t *pool = response->multistatus->sn->pool;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
519 UcxAllocator *a = session_get_allocator(response->multistatus->sn);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
520
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
521 response->resource.err++;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
522
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
523 // MSResponse contains a list of properties for each status code
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
524 // at first find the list for this status code
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
525 PropertyErrorList *errlist = NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
526 PropertyErrorList *list = response->errors;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
527 PropertyErrorList *last = NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
528 while(list) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
529 if(list->status == statuscode) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
530 errlist = list;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
531 break;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
532 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
533 last = list;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
534 list = list->next;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
535 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
536
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
537 if(!errlist) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
538 // no list available for this statuscode
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
539 PropertyErrorList *newelm = pool_malloc(pool,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
540 sizeof(PropertyErrorList));
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
541 if(!newelm) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
542 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
543 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
544 newelm->begin = NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
545 newelm->end = NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
546 newelm->next = NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
547 newelm->status = statuscode;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
548
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
549 if(last) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
550 last->next = newelm;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
551 } else {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
552 response->errors = newelm;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
553 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
554 errlist = newelm;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
555 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
556
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
557 // we have the list -> add the new element
229
73cb1c98ef7d replace UcxList with WebdavPList in the multistatus object
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 227
diff changeset
558 if(webdav_plist_add(pool, &errlist->begin, &errlist->end, property)) {
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
559 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
560 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
561 return 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
562 }
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
563
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
564 int msresponse_close(WebdavResource *res) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
565 MSResponse *response = (MSResponse*)res;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
566 if(response->closing) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
567 return 0; // close already in progress
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
568 }
252
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
569 response->closing = TRUE;
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
570 Multistatus *ms = response->multistatus;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
571
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
572 int ret = REQ_PROCEED;
252
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
573
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
574 // PROPFIND:
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
575 // response_close will execute propfind_do of all remaining backends
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
576 // after that we will have all available properties
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
577 WebdavOperation *op = ms->response.op;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
578 if(op->response_close(op, res)) {
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
579 ret = REQ_ABORTED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
580 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
581
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
582 // add missing properties with status code 404
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
583 UcxAllocator *a = session_get_allocator(ms->sn);
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
584 WebdavPList *pl = ms->response.op->reqprops;
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
585 while(pl) {
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
586 sstr_t key = sstrcat_a(
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
587 a,
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
588 3,
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
589 sstr((char*)pl->property->namespace->href),
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
590 S("\0"),
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
591 sstr((char*)pl->property->name));
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
592 if(!ucx_map_sstr_get(response->properties, key)) {
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
593 // property was not added to this response
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
594 if(ms->proppatch) {
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
595 if(msresponse_addproperror(response, pl->property, 424)) {
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
596 ret = REQ_ABORTED;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
597 break;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
598 }
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
599 } else {
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
600 if(msresponse_addproperror(response, pl->property, 404)) {
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
601 ret = REQ_ABORTED;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
602 break;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
603 }
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
604 }
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
605 }
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
606
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
607 pl = pl->next;
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
608 }
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
609
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
610 if(ms->proppatch && response->errors) {
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
611 // a proppatch response must succeed entirely
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
612 // if we have a single error prop, move all props with status 200
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
613 // to the error list
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
614 PropertyOkList *elm = response->plist_begin;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
615 PropertyOkList *nextelm;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
616 while(elm) {
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
617 if(msresponse_addproperror(response, elm->property, 424)) {
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
618 return 1;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
619 }
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
620 nextelm = elm->next;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
621 pool_free(response->multistatus->sn->pool, elm);
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
622 elm = nextelm;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
623 }
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
624 response->plist_begin = NULL;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
625 response->plist_end = NULL;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
626 }
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
627
226
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
628 // we don't need the properties anymore
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
629 ucx_map_free(response->properties);
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
630
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
631 response->resource.isclosed = TRUE;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
632 return ret;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
633 }

mercurial