src/server/webdav/operation.c

Sat, 25 Jan 2020 09:00:27 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 25 Jan 2020 09:00:27 +0100
branch
webdav
changeset 238
e820d433f405
parent 237
ee1680ef1ef2
child 239
d5031c30022c
permissions
-rw-r--r--

fix multistatus response and add propfind tests

217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2019 Olaf Wintermann. All rights reserved.
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
8ed14d76db42 add backend chaining
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
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <ucx/list.h>
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "../daemon/session.h"
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "operation.h"
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #define WEBDAV_PATH_MAX 8192
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 WebdavOperation* webdav_operation_create(
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
41 Session *sn,
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
42 Request *rq,
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 WebdavBackend *dav,
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
44 WebdavPList *reqprops,
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 UcxList *requests,
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 WebdavResponse *response)
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 {
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
48 WebdavOperation *op = pool_malloc(sn->pool, sizeof(WebdavOperation));
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 ZERO(op, sizeof(WebdavOperation));
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 op->dav = dav;
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
51 op->sn = sn;
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
52 op->rq = rq;
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
53 op->reqprops = reqprops;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 op->requests = requests;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 op->response = response;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 response->op = op;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 return op;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 int webdav_op_propfind_begin(
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 WebdavOperation *op,
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
64 const char *href,
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 VFS_DIR parent,
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 struct stat *s)
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 // create WebdavResource object for requested resource
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
69 WebdavResource *resource = op->response->addresource(op->response, href);
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 if(!resource) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 return REQ_ABORTED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 // store data that we need when the resource will be closed
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 op->stat = s;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 op->parent = parent;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 // get first propfind object
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 WebdavPropfindRequest *propfind = op->requests->data;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 // execute propfind_do of the first backend for the first resource
218
2ba512b284b9 add webdav_op_propfind_begin test that checks backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
82 int ret = REQ_PROCEED;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 if(op->dav->propfind_do(propfind, op->response, NULL, resource, s)) {
218
2ba512b284b9 add webdav_op_propfind_begin test that checks backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
84 ret = REQ_ABORTED;
2ba512b284b9 add webdav_op_propfind_begin test that checks backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
85 } else {
2ba512b284b9 add webdav_op_propfind_begin test that checks backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
86 // propfind_do successful, close resource if needed
2ba512b284b9 add webdav_op_propfind_begin test that checks backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
87 // closing the resource will execute propfind_do of all remaining
2ba512b284b9 add webdav_op_propfind_begin test that checks backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
88 // backends
2ba512b284b9 add webdav_op_propfind_begin test that checks backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
89 if(!resource->isclosed) {
2ba512b284b9 add webdav_op_propfind_begin test that checks backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
90 ret = resource->close(resource);
2ba512b284b9 add webdav_op_propfind_begin test that checks backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
91 }
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93
218
2ba512b284b9 add webdav_op_propfind_begin test that checks backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
94 return ret;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
97 typedef struct PathSearchElm {
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
98 char *href;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
99 char *path;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
100 size_t hreflen;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
101 size_t pathlen;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
102 } PathSearchElm;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
103
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
104 /*
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
105 * concats base + / + elm
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
106 * if baseinit is true, only elm is copied
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
107 */
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
108 static int path_buf_concat(
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
109 pool_handle_t *pool,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
110 char **buf,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
111 size_t * restrict len,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
112 WSBool * restrict baseinit,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
113 const char *base,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
114 size_t baselen,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
115 const char *elm,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
116 size_t elmlen)
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
117 {
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
118 if(base[baselen-1] == '/') {
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
119 baselen--;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
120 }
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
121
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
122 size_t newlen = baselen + elmlen + 1;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
123 if(newlen > WEBDAV_PATH_MAX) {
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
124 log_ereport(LOG_FAILURE, "webdav: maximal path length exceeded");
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
125 return 1;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
126 }
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
127
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
128 // check if new path + terminator fits in the buffer
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
129 if(newlen + 1 > *len) {
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
130 *len = newlen + 128;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
131 char *newbuf = pool_realloc(pool, *buf, newlen);
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
132 if(newbuf) {
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
133 log_ereport(LOG_FAILURE, "webdav: path memory allocation failed");
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
134 return 1;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
135 }
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
136 *baseinit = FALSE;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
137
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
138 *buf = newbuf;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
139 }
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
140
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
141 // if baseinit is true, the parent is already in the buffer
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
142 // and we don't need to memcpy it again
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
143 if(!(*baseinit)) {
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
144 memcpy(*buf, base, baselen);
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
145 (*buf)[baselen] = '/';
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
146 *baseinit = TRUE;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
147 }
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
148 // copy child and terminate string
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
149 memcpy((*buf) + baselen + 1, elm, elmlen);
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
150 (*buf)[newlen] = '\0';
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
151
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
152 return 0;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
153 }
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
154
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 int webdav_op_propfind_children(
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 WebdavOperation *op,
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 VFSContext *vfs,
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
158 const char *href,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
159 const char *path)
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 WebdavPropfindRequest *request = op->requests->data;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 UcxAllocator *a = session_get_allocator(request->sn);
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 pool_handle_t *pool = request->sn->pool;
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
165
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
166 PathSearchElm *start_elm = pool_malloc(pool, sizeof(PathSearchElm));
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
167 start_elm->href = pool_strdup(pool, href);
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
168 start_elm->path = pool_strdup(pool, path);
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
169 start_elm->hreflen = strlen(href);
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
170 start_elm->pathlen = strlen(path);
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
171
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
172 UcxList *stack = ucx_list_prepend_a(a, NULL, start_elm);
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 UcxList *stack_end = stack;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 if(!stack) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 return 1;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
178 // reusable buffer for full child path and href
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
179 char *newpath = pool_malloc(pool, 256);
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
180 size_t newpathlen = 256;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
181
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
182 char *newhref = pool_malloc(pool, 256);
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
183 size_t newhreflen = 256;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 int err = 0;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 while(stack && !err) {
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
187 PathSearchElm *cur_elm = stack->data;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 // when newpath is initialized with the parent path
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 // set path_buf_init to TRUE
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
191 WSBool href_buf_init = FALSE;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 WSBool path_buf_init = FALSE;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
194 VFS_DIR dir = vfs_opendir(vfs, cur_elm->path);
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 if(!dir) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 log_ereport(
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 LOG_FAILURE,
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 "webdav: propfind: cannot open directory %d",
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 vfs->vfs_errno);
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 err = 1;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 break;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 VFS_ENTRY f;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 while(vfs_readdir_stat(dir, &f)) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 if(f.stat_errno != 0) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 continue;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 size_t child_len = strlen(f.name);
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
211
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
212 // create new path and href for the child
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
213 if(path_buf_concat(
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
214 pool,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
215 &newhref,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
216 &newhreflen,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
217 &href_buf_init,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
218 cur_elm->href,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
219 cur_elm->hreflen,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
220 f.name,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
221 child_len))
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
222 {
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 err = 1;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 break;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 }
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
226 if(path_buf_concat(
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
227 pool,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
228 &newpath,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
229 &newpathlen,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
230 &path_buf_init,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
231 cur_elm->path,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
232 cur_elm->pathlen,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
233 f.name,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
234 child_len))
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
235 {
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
236 err = 1;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
237 break;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 }
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
239 size_t childhreflen = cur_elm->hreflen + 1 + child_len;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
240 size_t childpathlen = cur_elm->pathlen + 1 + child_len;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 // propfind for this child
236
e81d3e517b57 fix response href
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
243 if(webdav_op_propfind_begin(op, newhref, dir, &f.stat)) {
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 err = 1;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 break;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 // depth of -1 means infinity
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 if(request->depth == -1 && S_ISDIR(f.stat.st_mode)) {
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
250 char *hrefcp = pool_malloc(pool, childhreflen + 1);
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
251 memcpy(hrefcp, newhref, childhreflen + 1);
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
252 hrefcp[childhreflen] = '\0';
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
253
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 char *pathcp = pool_malloc(pool, childpathlen + 1);
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 memcpy(pathcp, newpath, childpathlen + 1);
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
256 pathcp[childpathlen] = '\0';
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
258 PathSearchElm *new_elm = pool_malloc(pool,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
259 sizeof(PathSearchElm));
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
260 new_elm->href = hrefcp;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
261 new_elm->path = pathcp;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
262 new_elm->hreflen = childhreflen;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
263 new_elm->pathlen = childpathlen;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
264
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
265 // add the new_elm to the stack
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 // stack_end is always not NULL here, because we remove
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 // the first stack element at the end of the loop
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
268 UcxList *newlistelm = ucx_list_append_a(a, stack_end, new_elm);
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 if(!newlistelm) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 err = 1;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 break;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 stack_end = newlistelm;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 vfs_closedir(dir);
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
279 pool_free(pool, cur_elm->path);
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
280 pool_free(pool, cur_elm->href);
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
281 pool_free(pool, cur_elm);
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
282
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 stack = ucx_list_remove_a(a, stack, stack);
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 // in case of an error, we have to free all remaining stack elements
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 UCX_FOREACH(elm, stack) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 char *data = elm->data;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289 if(data != path) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 pool_free(pool, data);
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294 return err;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 int webdav_op_propfiond_close_resource(
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 WebdavOperation *op,
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 WebdavResource *resource)
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 // start with second backend and request, because
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 // the first one was already called by webdav_op_propfind_begin
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303 WebdavBackend *dav = op->dav->next;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 UcxList *request = op->requests->next;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 // call propfind_do of all remaining backends
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 int ret = REQ_PROCEED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 while(dav && request) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309 if(dav->propfind_do(
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310 request->data,
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311 op->response,
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
312 op->parent,
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 resource,
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314 op->stat))
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315 {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
316 ret = REQ_ABORTED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
317 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
318
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319 dav = dav->next;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320 request = request->next;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
321 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
322 return ret;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
324
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
325 /*
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 * Executes propfind_finish for each Backend
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327 */
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328 int webdav_op_propfind_finish(WebdavOperation *op) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329 WebdavBackend *dav = op->dav;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330 UcxList *requests = op->requests;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
332 int ret = REQ_PROCEED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
333 while(dav && requests) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 if(dav->propfind_finish(requests->data)) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 ret = REQ_ABORTED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338 dav = dav->next;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339 requests = requests->next;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341 return ret;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 }

mercurial