src/server/webdav/multistatus.c

Fri, 31 Oct 2025 21:31:02 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 31 Oct 2025 21:31:02 +0100
changeset 619
4e2bac64c950
parent 611
b446daba6839
child 630
aae6e06d70b8
permissions
-rw-r--r--

add srvctrl stop command

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
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
36 #include <cx/string.h>
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
37 #include <cx/hash_map.h>
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
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
39 #include "multistatus.h"
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
40
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
41 #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
42 #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
43
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 #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
45
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 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
47 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
48 if(!ms) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 return NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 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
52 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
53 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
54 ms->rq = rq;
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 484
diff changeset
55 ms->namespaces = cxHashMapCreate(pool_allocator(sn->pool), CX_STORE_POINTERS, 8);
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
56 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
57 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
58 return NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 }
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
60 if(cxMapPut(ms->namespaces, cx_hash_key_str("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
61 return NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 return ms;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
66 static int send_xml_root(Multistatus *ms, Writer *out) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
67 writer_put_lit(out, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
68 "<D:multistatus");
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
69
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
70 // write the namespaces definitions
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
71 // key is the namespace prefix
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
72 // the map always contains the "DAV:" namespace with the prefix "D"
579
e10457d74fe1 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 513
diff changeset
73 CxMapIterator i = cxMapIterator(ms->namespaces);
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
74 cx_foreach(CxMapEntry*, entry, i) {
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
75 WSNamespace *ns = entry->value;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
76 writer_put_lit(out, " xmlns:");
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 484
diff changeset
77 writer_put (out, entry->key->data, entry->key->len);
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
78 writer_put_lit(out, "=\"");
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
79 writer_put_str(out, (char*)ns->href);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
80 writer_put_lit(out, "\"");
231
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
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
83 writer_put_lit(out, ">\n");
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
84
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
85 return out->error;
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
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
88 static void send_nsdef(WSNamespace *ns, Writer *out) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
89 writer_put_lit(out, " xmlns:");
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
90 writer_put_str(out, (char*)ns->prefix);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
91 writer_put_lit(out, "=\"");
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
92 writer_put_str(out, (char*)ns->href);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
93 writer_putc (out, '\"');
231
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
509
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
96
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
97 // html escape
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
98 /*
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
99 static void send_string_escaped(Writer *out, cxmutstr str) {
349
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
100 char *begin = str.ptr;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
101 char *end = begin;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
102 char *escape = NULL;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
103 int esclen;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
104 for(size_t i=0;i<str.length;i++) {
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
105 char c = str.ptr[i];
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
106 end = str.ptr + i;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
107 switch(c) {
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
108 case '"': {
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
109 escape = "&quot;";
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
110 esclen = 6;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
111 break;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
112 }
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
113 case '&': {
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
114 escape = "&amp;";
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
115 esclen = 5;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
116 break;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
117 }
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
118 case '\'': {
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
119 escape = "&apos;";
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
120 esclen = 6;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
121 break;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
122 }
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
123 case '<': {
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
124 escape = "&lt;";
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
125 esclen = 4;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
126 break;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
127 }
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
128 case '>': {
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
129 escape = "&gt;";
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
130 esclen = 4;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
131 break;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
132 }
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
133 default: continue;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
134 }
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
135 ptrdiff_t len = end - begin;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
136 if(len > 0) {
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
137 writer_put(out, begin, len);
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
138 begin = end + 1;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
139 }
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
140 writer_put(out, escape, esclen);
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
141 }
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
142 ptrdiff_t len = end - begin;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
143 if(len > 0) {
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
144 writer_put(out, begin, len + 1);
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
145 begin = end + 1;
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
146 }
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
147 }
509
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
148 */
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
149
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
150 static const char hex_ch[] = "0123456789ABCDEF";
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
151
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
152 static void send_string_escaped(Writer *out, cxmutstr str) {
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
153 char *begin = str.ptr;
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
154 char *end = begin;
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
155
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
156 char escape[4];
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
157 escape[0] = '%';
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
158
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
159 for(size_t i=0;i<str.length;i++) {
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
160 unsigned char c = (unsigned char)str.ptr[i];
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
161 end = str.ptr + i;
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
162
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
163 // check if the character must be escaped
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
164 if( (c >= 'A' && c <= 'Z') ||
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
165 (c >= 'a' && c <= 'z') ||
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
166 (c >= '/' && c <= '9') ||
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
167 (strchr("_.\\-~", c) != NULL))
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
168 {
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
169 continue;
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
170 }
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
171
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
172 // convert char to hex number, escape[0] always contains '%'
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
173 escape[1] = hex_ch[(c >> 4) & 0x0F];
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
174 escape[2] = hex_ch[c & 0x0F];
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
175
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
176 // write previous unescaped chars, if available
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
177 ptrdiff_t len = end - begin;
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
178 if(len > 0) {
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
179 writer_put(out, begin, len);
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
180 }
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
181
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
182 // write escaped char
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
183 writer_put(out, escape, 3);
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
184
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
185 // begin next chunk
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
186 begin = end + 1;
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
187 }
510
379fe1856800 fix send_string_escaped
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 509
diff changeset
188 ptrdiff_t len = str.ptr + str.length - begin;
509
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
189 if(len > 0) {
510
379fe1856800 fix send_string_escaped
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 509
diff changeset
190 writer_put(out, begin, len);
509
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
191 begin = end + 1;
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
192 }
2e29d0c2fb3b urlencode resource href in webdav multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 508
diff changeset
193 }
349
7bf652914e9b xml escape href value in propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
194
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
195 static int send_property(
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
196 Multistatus *ms,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
197 WebdavProperty *property,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
198 WebdavNSList *nsdef,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
199 WSBool writeContent,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
200 Writer *out)
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
201 {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
202 // write: "<prefix:name"
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
203 writer_putc (out, '<');
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
204 writer_put_str(out, (char*)property->namespace->prefix);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
205 writer_putc (out, ':');
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
206 writer_put_str(out, (char*)property->name);
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
207
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
208 // send additional namespace definitions required for the value
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
209 WebdavNSList *def = nsdef;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
210 while(def) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
211 send_nsdef(def->namespace, out);
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
212 def = def->next;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
213 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
214
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
215 // send xml lang attribute
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
216 if(property->lang) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
217 writer_put_lit(out, " xml:lang=\"");
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
218 writer_put_str(out, (char*)property->lang);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
219 writer_putc (out, '\"');
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
220 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
221
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
222 // end property tag and write content
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
223 if(writeContent) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
224 writer_putc(out, '>');
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
225
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
226 // content
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
227 switch(property->vtype) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
228 case WS_VALUE_NO_TYPE: break;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
229 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
230 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
231 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
232 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
233 property->value.node);
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
234 break;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
235 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
236 case WS_VALUE_XML_DATA: {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
237 // only write data, data->namespaces is already handled
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
238 writer_put(
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
239 out,
376
61d481d3c2e4 Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
240 property->value.data.data,
61d481d3c2e4 Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
241 property->value.data.length);
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
242 break;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
243 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
244 case WS_VALUE_TEXT: {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
245 // asume the text is already escaped
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
246 writer_put(
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
247 out,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
248 property->value.text.str,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
249 property->value.text.length);
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
250 break;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
251 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
252 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
253
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
254 // end tag
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
255 writer_put_lit(out, "</");
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
256 writer_put_str(out, (char*)property->namespace->prefix);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
257 writer_putc (out, ':');
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
258 writer_put_str(out, (char*)property->name);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
259 writer_putc (out, '>');
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
260 } else {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
261 writer_put_lit(out, "/>");
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
262 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
263
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
264 return out->error;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
265 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
266
611
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
267 static void write_status_str(Writer *out, int status) {
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
268 char statuscode[8];
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
269 int sclen = snprintf(statuscode, 8, "%d ", status);
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
270 if(sclen > 4) {
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
271 statuscode[0] = '5';
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
272 statuscode[1] = '0';
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
273 statuscode[2] = '0';
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
274 statuscode[3] = ' ';
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
275 sclen = 4;
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
276 }
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
277 writer_put_lit(out, "HTTP/1.1 ");
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
278 writer_put(out, statuscode, sclen);
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
279 const char *status_msg = protocol_status_message(status);
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
280 if(status_msg) {
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
281 writer_put(out, status_msg, strlen(status_msg));
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
282 } else {
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
283 writer_put_lit(out, "Server Error");
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
284 }
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
285 }
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
286
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
287 static int send_response_tag(Multistatus *ms, MSResponse *rp, Writer *out) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
288 writer_put_lit(out, " <D:response>\n"
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
289 " <D:href>");
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
290 send_string_escaped(out, cx_mutstr(rp->resource.href));
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
291 writer_put_lit(out, "</D:href>\n");
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
292
242
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
293 WSBool writeContent = ms->proppatch ? FALSE : TRUE;
c337a7ac82a8 implement webdav_proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
294
611
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
295 if(rp->resource.status >= 300) {
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
296 writer_put_lit(out, " <D:status>");
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
297 write_status_str(out, rp->resource.status);
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
298 writer_put_lit(out, "</D:status>\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
299
611
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
300 } else {
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
301 if(rp->plist_begin) {
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
302 writer_put_lit(out, " <D:propstat>\n"
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
303 " <D:prop>\n");
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
304 // send properties
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
305 PropertyOkList *p = rp->plist_begin;
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
306 while(p) {
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
307 writer_put_lit(out, " ");
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
308 if(send_property(ms, p->property, p->nsdef, writeContent, out)) {
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
309 return out->error;
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
310 }
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
311 writer_put_lit(out, "\n");
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
312 p = p->next;
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
313 }
611
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
314
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
315 writer_put_lit(out, " </D:prop>\n"
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
316 " <D:status>HTTP/1.1 200 OK</D:status>\n"
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
317 " </D:propstat>\n");
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
318 }
611
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
319
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
320 // send error properties
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
321 PropertyErrorList *error = rp->errors;
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
322 while(error) {
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
323 writer_put_lit(out, " <D:propstat>\n"
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
324 " <D:prop>\n");
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
325
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
326 WebdavPList *errprop = error->begin;
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
327 while(errprop) {
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
328 writer_put_lit(out, " ");
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
329 if(send_property(ms, errprop->property, NULL, FALSE, out)) {
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
330 return out->error;
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
331 }
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
332 writer_putc(out, '\n');
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
333 errprop = errprop->next;
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
334 }
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
335
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
336 writer_put_lit(out, " </D:prop>\n"
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
337 " <D:status>");
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
338 write_status_str(out, error->status);
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
339 writer_put_lit(out, "</D:status>\n"
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
340 " </D:propstat>\n");
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
341
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
342
b446daba6839 change error handling in case webdav_xattr_parse_data fails: set response to 500 instead of failig the entire multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
343 error = error->next;
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
344 }
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
345 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
346
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
347 // end response tag
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
348 writer_put_lit(out, " </D:response>\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
349
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
350 return out->error;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
351 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
352
308
c3cad8f51a24 close last resource in multistatus_send
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 252
diff changeset
353 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
354 // make sure every resource is closed
c3cad8f51a24 close last resource in multistatus_send
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 252
diff changeset
355 if(ms->current && !ms->current->resource.isclosed) {
309
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 308
diff changeset
356 if(msresponse_close((WebdavResource*)ms->current)) {
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 308
diff changeset
357 return 1;
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 308
diff changeset
358 }
308
c3cad8f51a24 close last resource in multistatus_send
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 252
diff changeset
359 }
c3cad8f51a24 close last resource in multistatus_send
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 252
diff changeset
360
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
361 // 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
362 protocol_status(ms->sn, ms->rq, 207, NULL);
513
9a49c245a49c change net_write to attempt to write all bytes, improve error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 510
diff changeset
363 if(protocol_start_response(ms->sn, ms->rq)) {
9a49c245a49c change net_write to attempt to write all bytes, improve error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 510
diff changeset
364 return 1;
9a49c245a49c change net_write to attempt to write all bytes, improve error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 510
diff changeset
365 }
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
366
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367 char buffer[MULTISTATUS_BUFFER_LENGTH];
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
368 // 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
369 Writer writer;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
370 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
371 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
372
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
373 // send the xml root element with namespace defs
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
374 if(send_xml_root(ms, out)) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
375 return 1;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
376 }
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
377
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
378 // send response tags
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
379 MSResponse *response = ms->first;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
380 while(response) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
381 if(send_response_tag(ms, response, out)) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
382 return 1;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
383 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
384 response = response->next;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
385 }
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
386
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
387 // end multistatus
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
388 writer_put_lit(out, "</D:multistatus>\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
389
381
7d55d60e1fe2 fix resourcetype initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 376
diff changeset
390 //printf("\n\n");
376
61d481d3c2e4 Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
391 //fflush(stdout);
61d481d3c2e4 Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
392
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
393 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
394
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
395 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
396 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
397
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
398 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
399 WebdavResponse *response,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
400 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
401 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
402 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
403 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
404 if(!res) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
405 return NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
406 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
407 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
408
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
409 // set href
223
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
410 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
411 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
412 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
413 }
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
414
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
415 res->resource.err = 0;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
416
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
417 // 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
418 res->resource.addproperty = msresponse_addproperty;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
419 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
420
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 484
diff changeset
421 res->properties = cxHashMapCreate(pool_allocator(ms->sn->pool), CX_STORE_POINTERS, 32);
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
422 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
423 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
424 }
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
425
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
426 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
427 res->errors = NULL;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
428 res->resource.isclosed = 0;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
429 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
430
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
431 // 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
432 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
433 // 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
434 if(!ms->current->resource.isclosed) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
435 msresponse_close((WebdavResource*)ms->current);
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
436 }
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
437 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
438 } else {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
439 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
440 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
441 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
442
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
443 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
444 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
445
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
446 static int oklist_add(
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
447 pool_handle_t *pool,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
448 PropertyOkList **begin,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
449 PropertyOkList **end,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
450 WebdavProperty *property,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
451 WebdavNSList *nsdef)
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
452 {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
453 PropertyOkList *newelm = pool_malloc(pool, sizeof(PropertyOkList));
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
454 if(!newelm) {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
455 return 1;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
456 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
457 newelm->property = property;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
458 newelm->nsdef = nsdef;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
459 newelm->next = NULL;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
460 if(*end) {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
461 (*end)->next = newelm;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
462 } else {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
463 *begin = newelm;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
464 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
465 *end = newelm;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
466 return 0;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
467 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
468
403
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
469 /*
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
470 * should only be called from msresponse_addproperty
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
471 *
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
472 * Adds a property to the error list with the specified statuscode
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
473 */
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
474 static int msresponse_addproperror(
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
475 MSResponse *response,
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
476 WebdavProperty *property,
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
477 int statuscode)
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
478 {
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
479 pool_handle_t *pool = response->multistatus->sn->pool;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
480
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
481 response->resource.err++;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
482
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
483 // MSResponse contains a list of properties for each status code
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
484 // at first find the list for this status code
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
485 PropertyErrorList *errlist = NULL;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
486 PropertyErrorList *list = response->errors;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
487 PropertyErrorList *last = NULL;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
488 while(list) {
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
489 if(list->status == statuscode) {
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
490 errlist = list;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
491 break;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
492 }
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
493 last = list;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
494 list = list->next;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
495 }
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
496
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
497 if(!errlist) {
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
498 // no list available for this statuscode
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
499 PropertyErrorList *newelm = pool_malloc(pool,
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
500 sizeof(PropertyErrorList));
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
501 if(!newelm) {
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
502 return 1;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
503 }
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
504 newelm->begin = NULL;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
505 newelm->end = NULL;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
506 newelm->next = NULL;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
507 newelm->status = statuscode;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
508
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
509 if(last) {
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
510 last->next = newelm;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
511 } else {
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
512 response->errors = newelm;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
513 }
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
514 errlist = newelm;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
515 }
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
516
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
517 // we have the list -> add the new element
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
518 if(webdav_plist_add(pool, &errlist->begin, &errlist->end, property)) {
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
519 return 1;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
520 }
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
521 return 0;
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
522 }
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
523
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
524 static CxHashKey ms_property_key(
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
525 CxAllocator *a,
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
526 const xmlChar *href,
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
527 const char *property_name)
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
528 {
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
529 cxmutstr key_data = cx_strcat_a(a, 3, cx_str((const char*)href), (cxstring){ "\0", 1 }, cx_str(property_name));
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
530 return cx_hash_key_bytes((unsigned char*)key_data.ptr, key_data.length);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
531 }
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
532
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
533 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
534 WebdavResource *res,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
535 WebdavProperty *property,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
536 int status)
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
537 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
538 MSResponse *response = (MSResponse*)res;
227
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
539 Session *sn = response->multistatus->sn;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
540 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
541 log_ereport(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
542 LOG_WARN,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
543 "%s",
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
544 "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
545 return 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
546 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
547
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
548 // 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
549 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
550 // 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
551 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
552 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
553 "%s",
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
554 "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
555 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
556 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
557 }
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
558
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
559 // check if the property was already added to the resource
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
560 CxAllocator *a = pool_allocator(sn->pool);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
561 CxHashKey key = ms_property_key(a, property->namespace->href, property->name);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
562 if(cxMapGet(response->properties, key)) {
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 484
diff changeset
563 cxFree(a, (void*)key.data);
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
564 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
565 }
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
566 if(cxMapPut(response->properties, key, property)) {
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
567 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
568 }
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 484
diff changeset
569 cxFree(a, (void*)key.data);
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
570
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
571 // list of namespace definitions for this property
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
572 WebdavNSList *nsdef_begin = NULL;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
573 WebdavNSList *nsdef_end = NULL;
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
574
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
575 // add namespace of this property to the namespace map
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
576 // the namespace map will be used for global namespace definitions
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
577 if(property->namespace->prefix) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
578 WSNamespace *ns = cxMapGet(
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
579 response->multistatus->namespaces,
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
580 cx_hash_key_str((const char*)property->namespace->prefix));
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
581 if(!ns) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
582 // prefix is not in use -> we can add the namespace to the ns map
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
583 int err = cxMapPut(
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
584 response->multistatus->namespaces,
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
585 cx_hash_key_str((const char*)property->namespace->prefix),
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
586 property->namespace);
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
587 if(err) {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
588 return 1; // OOM
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
589 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
590 } else if(
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
591 strcmp((const char*)property->namespace->href,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
592 (const char*)ns->href))
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
593 {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
594 // global namespace != local namespace
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
595 // therefore we need a namespace definition in this element
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
596
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
597 // ns-prefix != property-prefix -> add ns to nsdef
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
598 if(webdav_nslist_add(
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
599 sn->pool,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
600 &nsdef_begin,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
601 &nsdef_end,
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
602 property->namespace))
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
603 {
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
604 return 1; // OOM
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
605 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
606 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
607 }
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
608
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
609 if(response->multistatus->proppatch && response->errors) {
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
610 // 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
611 // 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
612 // 424 Failed Dependency
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
613 status = 424;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
614 }
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
615
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
616 // 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
617 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
618 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
619 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
620
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
621 // 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
622 WebdavNSList *nslist = NULL;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
623 if(property->vtype == WS_VALUE_XML_NODE) {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
624 // 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
625 int err = 0;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
626 nslist = wsxml_get_required_namespaces(
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
627 response->multistatus->sn->pool,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
628 property->value.node,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
629 &err);
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
630 if(err) {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
631 return 1; // OOM
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
632 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
633 } 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
634 // xml data contains a list of all used namespaces
376
61d481d3c2e4 Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
635 nslist = property->value.data.namespaces;
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
636 } // 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
637
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
638 while(nslist) {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
639 // 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
640 // 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
641 // 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
642 if(strcmp(
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
643 (const char*)nslist->namespace->prefix,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
644 (const char*)property->namespace->prefix))
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
645 {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
646 // 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
647 if(webdav_nslist_add(
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
648 sn->pool,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
649 &nsdef_begin,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
650 &nsdef_end,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
651 nslist->namespace))
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
652 {
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
653 return 1; // OOM
231
4714468b9b7e implement multistatus writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
654 }
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
655 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
656 nslist = nslist->next;
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
657 }
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
658
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
659 // add property to the list
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
660 if(oklist_add(
227
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
661 sn->pool,
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
662 &response->plist_begin,
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
663 &response->plist_end,
230
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
664 property,
ca50e1ebdc4d readd namespace handling to msresponse_addproperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
665 nsdef_begin))
227
3c23855f7b46 remove nsdef from WebdavProperty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
666 {
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
667 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
668 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
669 return 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
670 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
671
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
672 int msresponse_close(WebdavResource *res) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
673 MSResponse *response = (MSResponse*)res;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
674 if(response->closing) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
675 return 0; // close already in progress
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
676 }
252
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
677 response->closing = TRUE;
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
678 Multistatus *ms = response->multistatus;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
679
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
680 int ret = REQ_PROCEED;
252
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
681
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
682 // PROPFIND:
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
683 // response_close will execute propfind_do of all remaining backends
5653a9626cc0 prepare webdav copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
684 // 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
685 WebdavOperation *op = ms->response.op;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
686 if(op->response_close(op, res)) {
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
687 ret = REQ_ABORTED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
688 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
689
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
690 // add missing properties with status code 404
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
691 CxAllocator *a = pool_allocator(ms->sn->pool);
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
692 WebdavPList *pl = ms->response.op->reqprops;
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
693 while(pl) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
694 CxHashKey key = ms_property_key(a, pl->property->namespace->href, pl->property->name);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
695 if(!cxMapGet(response->properties, key)) {
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
696 // 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
697 if(ms->proppatch) {
403
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
698 if(msresponse_addproperty(res, pl->property, 424)) {
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
699 ret = REQ_ABORTED;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
700 break;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
701 }
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
702 } else {
403
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
703 if(msresponse_addproperty(res, pl->property, 404)) {
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
704 ret = REQ_ABORTED;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
705 break;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
706 }
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
707 }
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
708 }
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
709
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
710 pl = pl->next;
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
711 }
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
712
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
713 if(ms->proppatch && response->errors) {
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
714 // a proppatch response must succeed entirely
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
715 // 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
716 // to the error list
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
717 PropertyOkList *elm = response->plist_begin;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
718 PropertyOkList *nextelm;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
719 while(elm) {
403
0f678595d497 fix multistatus response creating namespace definitions twice in some cases
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 381
diff changeset
720 if(msresponse_addproperty(res, elm->property, 424)) {
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
721 return 1;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
722 }
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
723 nextelm = elm->next;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
724 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
725 elm = nextelm;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
726 }
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
727 response->plist_begin = NULL;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
728 response->plist_end = NULL;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
729 }
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 238
diff changeset
730
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
731 // we don't need the properties anymore
579
e10457d74fe1 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 513
diff changeset
732 cxMapFree(response->properties);
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
733
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
734 response->resource.isclosed = TRUE;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
735 return ret;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
736 }

mercurial