src/server/webdav/multistatus.c

Thu, 16 Jan 2020 22:28:22 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 16 Jan 2020 22:28:22 +0100
branch
webdav
changeset 226
49adcbd7d473
parent 223
bbaec8415c10
child 227
3c23855f7b46
permissions
-rw-r--r--

msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once

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 *
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2019 Olaf Wintermann. All rights reserved.
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"
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
34 #include "operation.h"
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
35
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "multistatus.h"
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #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
39
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 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
41 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
42 if(!ms) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 return NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 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
46 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
47 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
48 ms->rq = rq;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 ms->namespaces = ucx_map_new_a(session_get_allocator(ms->sn), 8);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 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
51 return NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 if(ucx_map_cstr_put(ms->namespaces, "D", "DAV:")) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 return NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 return ms;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 int multistatus_send(Multistatus *ms, SYS_NETFD net) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 char 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
61 Writer writer;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 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
63 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
64
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 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
69 WebdavResponse *response,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 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
71 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 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
73 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
74 if(!res) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 return NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 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
78
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
79 // set href
223
bbaec8415c10 add xml tree iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
80 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
81 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
82 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
83 }
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
84
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
85 // 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
86 res->resource.addproperty = msresponse_addproperty;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
87 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
88
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
89 res->properties = ucx_map_new_a(session_get_allocator(ms->sn), 32);
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
90 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
91 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
92 }
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
93
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 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
95 res->errors = NULL;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
96 res->resource.isclosed = 0;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
97 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
98
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
99 // 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
100 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
101 // 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
102 if(!ms->current->resource.isclosed) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
103 msresponse_close((WebdavResource*)ms->current);
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
104 }
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 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
106 } else {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 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
108 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 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
110
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 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
112 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 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
115 WebdavResource *res,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 WebdavProperty *property,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 int status)
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 MSResponse *response = (MSResponse*)res;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
120 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
121 log_ereport(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 LOG_WARN,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 "%s",
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 "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
125 return 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
128 // 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
129 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
130 // 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
131 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
132 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
133 "%s",
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
134 "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
135 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
136 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
137 }
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
138 if(property->nsdef) {
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
139 // error: nsdef MUST be NULL, only fill nsdef in this func
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
140 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
141 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
142 "%s",
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
143 "webdav: property '%s': nsdef must be null",
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
144 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
145 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
146 }
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
147
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
148 // check if the property was already added to the resource
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
149 UcxAllocator *a = session_get_allocator(response->multistatus->sn);
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
150 sstr_t key = sstrcat_a(
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
151 a,
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
152 3,
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
153 sstr((char*)property->namespace->href),
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
154 S("\0"),
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
155 sstr((char*)property->name));
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
156 if(ucx_map_sstr_get(response->properties, key)) {
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
157 a->free(a->pool, key.ptr);
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
158 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
159 }
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
160 if(ucx_map_sstr_put(response->properties, key, property)) {
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
161 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
162 }
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
163 a->free(a->pool, key.ptr);
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
164
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 // add namespace of this property to the namespace map
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
166 // the namespace map will be used for global namespace definitions
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
167 if(property->namespace->prefix) {
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 char *ns = ucx_map_cstr_get(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 response->multistatus->namespaces,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 (const char*)property->namespace->prefix);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 if(!ns) {
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
172 // prefix is not in use -> we can add the namespace to the ns map
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 int err = ucx_map_cstr_put(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 response->multistatus->namespaces,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 (const char*)property->namespace->prefix,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 property->namespace->href);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 if(err) {
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
178 return 1; // OOM
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 }
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
180 } else if(strcmp((char*)property->namespace->href, ns)) {
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
181 // global namespace != local namespace
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
182 // therefore we need a namespace definition in this element
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
183
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
184 if(webdav_property_add_nsdef(
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
185 property,
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
186 response->multistatus->sn->pool,
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
187 (const char*)property->namespace->prefix,
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
188 (const char*)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
189 {
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
190 return 1; // OOM
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
191 }
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
195 // 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
196 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
197 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
198 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
200 // add all namespaces used by this property to the nsdef list
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
201 WebdavNSList *nslist = NULL;
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
202 if(property->vtype == WS_VALUE_XML_NODE) {
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
203 // iterate over xml tree and collect all namespaces
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
204 int err = 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
205 WebdavNSList *nsdef = wsxml_get_required_namespaces(
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
206 response->multistatus->sn->pool,
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
207 property->value.node,
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
208 &err);
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
209 if(err) {
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
210 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
211 }
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
212 nslist = nsdef;
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
213 } else if(property->vtype == WS_VALUE_XML_DATA) {
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
214 // xml data contains a list of all used namespaces
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
215 nslist = property->value.data->namespaces;
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
216 } // other value types don't contain xml namespaces
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
217
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
218 while(nslist) {
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
219 // only add the namespace to the definitions list, if it isn't a
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
220 // property namespace, because the prop ns is already added
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
221 // to the element's def list or global definitions list
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
222 if(strcmp(
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
223 (const char*)nslist->namespace->prefix,
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
224 (const char*)property->namespace->prefix))
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
225 {
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
226 // ns-prefix != property-prefix -> add ns to nsdef
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
227 if(webdav_property_add_nsdef(
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
228 property,
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
229 response->multistatus->sn->pool,
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
230 (const char*)nslist->namespace->prefix,
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
231 (const char*)nslist->namespace->href))
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
232 {
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
233 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
234 }
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
235 }
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
236 nslist = nslist->next;
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
237 }
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
238
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 // add property to the list
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 WebdavPList *listelm = pool_malloc(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 response->multistatus->sn->pool,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 sizeof(WebdavPList));
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 if(!listelm) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 listelm->property = property;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 listelm->next = NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 if(response->plist_end) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 response->plist_end->next = listelm;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252 } else {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 response->plist_begin = listelm;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 response->plist_end = listelm;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 return 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 int msresponse_addproperror(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 MSResponse *response,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 WebdavProperty *property,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 int statuscode)
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 pool_handle_t *pool = response->multistatus->sn->pool;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 UcxAllocator *a = session_get_allocator(response->multistatus->sn);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 // MSResponse contains a list of properties for each status code
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 // at first find the list for this status code
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 PropertyErrorList *errlist = NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 PropertyErrorList *list = response->errors;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 PropertyErrorList *last = NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 while(list) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 if(list->status == statuscode) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274 errlist = list;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 break;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 last = list;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278 list = list->next;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281 if(!errlist) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 // no list available for this statuscode
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 PropertyErrorList *newelm = pool_malloc(pool,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 sizeof(PropertyErrorList));
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 if(!newelm) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 newelm->begin = NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289 newelm->end = NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 newelm->next = NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 newelm->status = statuscode;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 if(last) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294 last->next = newelm;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 } else {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 response->errors = newelm;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 errlist = newelm;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 // we have the list -> add the new element
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 UcxList *newlistelm = ucx_list_append_a(a, errlist->end, property);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303 if(!newlistelm) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 errlist->end = newlistelm;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 if(!errlist->begin) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 errlist->begin = newlistelm;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310 return 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311 }
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
312
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
313 int msresponse_close(WebdavResource *res) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
314 MSResponse *response = (MSResponse*)res;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
315 if(response->closing) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
316 return 0; // close already in progress
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
317 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
318
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
319 int ret = REQ_PROCEED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
320 WebdavOperation *op = response->multistatus->response.op;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
321 if(webdav_op_propfiond_close_resource(op, res)) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
322 ret = REQ_ABORTED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
323 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
324
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
325 // we don't need the properties anymore
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
326 ucx_map_free(response->properties);
49adcbd7d473 msresponse_addproperty: add support for xmlNode property values and add check to make sure, properties are only added once
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
327
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
328 response->resource.isclosed = TRUE;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
329 response->closing = FALSE;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
330 return ret;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
331 }

mercurial