src/server/webdav/operation.c

Wed, 02 Nov 2022 19:10:10 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 02 Nov 2022 19:10:10 +0100
changeset 413
6afaebf003ea
parent 378
0344108db255
child 415
d938228c382e
permissions
-rw-r--r--

implement ACL check for proppatch requests

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>
245
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
31 #include <errno.h>
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <ucx/list.h>
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "../daemon/session.h"
245
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
36 #include "../util/pblock.h"
217
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 #include "operation.h"
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 #define WEBDAV_PATH_MAX 8192
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
42
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
43 size_t webdav_num_backends(WebdavBackend *dav) {
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
44 size_t count = 0;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
45 while(dav) {
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
46 count++;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
47 dav = dav->next;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
48 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
49 return count;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
50 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
51
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
52 /****************************************************************************
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
53 *
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
54 * PROPFIND OPERATION
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
55 *
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
56 ****************************************************************************/
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
57
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
58 WebdavOperation* webdav_create_propfind_operation(
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
59 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
60 Request *rq,
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 WebdavBackend *dav,
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
62 WebdavPList *reqprops,
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 UcxList *requests,
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 WebdavResponse *response)
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 {
222
5f05e56cb8e2 create namespace definition lists when properties are added to a multistatus response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
66 WebdavOperation *op = pool_malloc(sn->pool, sizeof(WebdavOperation));
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 ZERO(op, sizeof(WebdavOperation));
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 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
69 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
70 op->rq = rq;
237
ee1680ef1ef2 handle missing properties in multistatus.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
71 op->reqprops = reqprops;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 op->requests = requests;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 op->response = response;
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
74 op->response_close = webdav_op_propfiond_close_resource;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 response->op = op;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 return op;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 int webdav_op_propfind_begin(
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 WebdavOperation *op,
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
82 const char *href,
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 VFS_DIR parent,
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 struct stat *s)
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 // 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
87 WebdavResource *resource = op->response->addresource(op->response, href);
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 if(!resource) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 return REQ_ABORTED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 // store data that we need when the resource will be closed
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 op->stat = s;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 op->parent = parent;
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 // get first propfind object
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 WebdavPropfindRequest *propfind = op->requests->data;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 // 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
100 int ret = REQ_PROCEED;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 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
102 ret = REQ_ABORTED;
2ba512b284b9 add webdav_op_propfind_begin test that checks backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
103 } else {
2ba512b284b9 add webdav_op_propfind_begin test that checks backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
104 // 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
105 // 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
106 // backends
2ba512b284b9 add webdav_op_propfind_begin test that checks backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
107 if(!resource->isclosed) {
2ba512b284b9 add webdav_op_propfind_begin test that checks backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
108 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
109 }
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111
218
2ba512b284b9 add webdav_op_propfind_begin test that checks backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
112 return ret;
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
115 typedef struct PathSearchElm {
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
116 char *href;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
117 char *path;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
118 size_t hreflen;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
119 size_t pathlen;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
120 } PathSearchElm;
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 /*
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
123 * concats base + / + elm
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
124 * 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
125 */
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
126 static int path_buf_concat(
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
127 pool_handle_t *pool,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
128 char **buf,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
129 size_t * restrict len,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
130 WSBool * restrict baseinit,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
131 const char *base,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
132 size_t baselen,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
133 const char *elm,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
134 size_t elmlen)
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 if(base[baselen-1] == '/') {
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
137 baselen--;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
138 }
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 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
141 if(newlen > WEBDAV_PATH_MAX) {
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
142 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
143 return 1;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
144 }
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
145
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
146 // 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
147 if(newlen + 1 > *len) {
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
148 *len = newlen + 128;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
149 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
150 if(newbuf) {
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
151 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
152 return 1;
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 *baseinit = FALSE;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
155
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
156 *buf = newbuf;
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
157 }
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
158
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
159 // 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
160 // 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
161 if(!(*baseinit)) {
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
162 memcpy(*buf, base, baselen);
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
163 (*buf)[baselen] = '/';
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
164 *baseinit = TRUE;
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 // copy child and terminate string
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
167 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
168 (*buf)[newlen] = '\0';
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
169
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
170 return 0;
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
246
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
173 static int propfind_child_cb(
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
174 VFSContext *vfs,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
175 const char *href,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
176 const char *path,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
177 VFSDir *parent,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
178 struct stat *s,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
179 void *op)
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
180 {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
181 return webdav_op_propfind_begin(op, href, parent, s);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
182 }
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
183
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 int webdav_op_propfind_children(
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 WebdavOperation *op,
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 VFSContext *vfs,
221
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
187 const char *href,
ff5826fc6a6c add href parameter to webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
188 const char *path)
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 WebdavPropfindRequest *request = op->requests->data;
246
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
191 return webdav_op_iterate_children(
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
192 vfs, request->depth, href, path, propfind_child_cb, op);
217
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 int webdav_op_propfiond_close_resource(
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 WebdavOperation *op,
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 WebdavResource *resource)
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 // start with second backend and request, because
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 // the first one was already called by webdav_op_propfind_begin
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 WebdavBackend *dav = op->dav->next;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 UcxList *request = op->requests->next;
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 // call propfind_do of all remaining backends
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 int ret = REQ_PROCEED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 while(dav && request) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 if(dav->propfind_do(
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 request->data,
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 op->response,
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 op->parent,
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 resource,
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 op->stat))
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 ret = REQ_ABORTED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 dav = dav->next;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 request = request->next;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 return ret;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 /*
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 * Executes propfind_finish for each Backend
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 */
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 int webdav_op_propfind_finish(WebdavOperation *op) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 WebdavBackend *dav = op->dav;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 UcxList *requests = op->requests;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 int ret = REQ_PROCEED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 while(dav && requests) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 if(dav->propfind_finish(requests->data)) {
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 ret = REQ_ABORTED;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 dav = dav->next;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 requests = requests->next;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 }
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 return ret;
8ed14d76db42 add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 }
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
241
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
242 /****************************************************************************
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
243 *
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
244 * PROPPATCH OPERATION
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
245 *
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
246 ****************************************************************************/
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
247
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
248 WebdavOperation* webdav_create_proppatch_operation(
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
249 Session *sn,
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
250 Request *rq,
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
251 WebdavBackend *dav,
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
252 WebdavProppatchRequest *proppatch,
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
253 WebdavResponse *response)
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
254 {
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
255 WebdavOperation *op = pool_malloc(sn->pool, sizeof(WebdavOperation));
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
256 ZERO(op, sizeof(WebdavOperation));
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
257 op->dav = dav;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
258 op->sn = sn;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
259 op->rq = rq;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
260 op->reqprops = NULL;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
261 op->response = response;
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
262 op->proppatch = proppatch;
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
263 op->response_close = webdav_op_proppatch_close_resource;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
264 response->op = op;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
265
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
266 return op;
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
267 }
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
268
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
269
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
270
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
271 int webdav_op_proppatch(
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
272 WebdavOperation *op,
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
273 const char *href,
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
274 const char *path)
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
275 {
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
276 WebdavProppatchRequest *orig_request = op->proppatch;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
277 UcxAllocator *a = session_get_allocator(op->sn);
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
278
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
279 // create WebdavResource object for the requested resource
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
280 WebdavResource *resource = op->response->addresource(op->response, href);
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
281 if(!resource) {
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
282 return REQ_ABORTED;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
283 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
284
413
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
285 // check ACL
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
286 if(acl_evaluate(op->sn, op->rq, ACL_WRITE_XATTR)) {
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
287 // ACL check failed, either unauthorized or forbidden
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
288 // acl_evaluate() sets the http status code and may add
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
289 // response headers for authentication
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
290 if(op->rq->status_num == PROTOCOL_UNAUTHORIZED) {
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
291 return REQ_ABORTED; // return here to send an authenticate response
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
292 }
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
293
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
294 // send multistatus response with status code 403 for each property
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
295 log_ereport(LOG_VERBOSE, "webdav-proppatch: access forbidden");
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
296 int ret = REQ_PROCEED;
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
297 WebdavPList *plist = op->proppatch->set;
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
298 for(int i=0;i<2;i++) {
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
299 while(plist) {
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
300 if(resource->addproperty(resource, plist->property, PROTOCOL_FORBIDDEN)) {
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
301 ret = REQ_ABORTED;
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
302 break; // OOM
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
303 }
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
304 plist = plist->next;
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
305 }
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
306 plist = op->proppatch->remove;
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
307 }
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
308
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
309 if(resource->close(resource)) {
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
310 ret = REQ_ABORTED; // OOM
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
311 }
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
312 return ret;
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
313 }
6afaebf003ea implement ACL check for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
314
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
315 VFSContext *ctx = NULL;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
316 VFSFile *file = NULL;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
317
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
318 // requests for each backends
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
319 WebdavProppatchRequest **requests = pool_calloc(
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
320 op->sn->pool,
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
321 webdav_num_backends(op->dav),
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
322 sizeof(WebdavProppatchRequest*));
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
323 if(requests == NULL) {
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
324 return REQ_ABORTED;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
325 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
326
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
327 WebdavPList *prev_set = orig_request->set;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
328 WebdavPList *prev_remove = orig_request->remove;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
329 size_t set_count = orig_request->setcount;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
330 size_t remove_count = orig_request->removecount;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
331
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
332 int ret = REQ_PROCEED;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
333
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
334 // iterate backends and execute proppatch_do
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
335 WebdavBackend *dav = op->dav;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
336 size_t numrequests = 0;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
337 while(dav) {
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
338 WebdavPList *set = webdav_plist_clone_s(
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
339 op->sn->pool,
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
340 prev_set,
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
341 &set_count);
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
342 WebdavPList *remove = webdav_plist_clone_s(
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
343 op->sn->pool,
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
344 prev_remove,
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
345 &remove_count);
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
346 if((prev_set && !set) || (prev_remove && !remove)) {
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
347 // clone failed, OOM
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
348 ret = REQ_ABORTED;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
349 break;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
350 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
351
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
352 // create new WebdavProppatchRequest object for this backend
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
353 WebdavProppatchRequest *req = pool_malloc(
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
354 op->sn->pool,
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
355 sizeof(WebdavProppatchRequest));
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
356 memcpy(req, orig_request, sizeof(WebdavProppatchRequest));
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 263
diff changeset
357 req->dav = dav;
378
0344108db255 make original proppatch property list available to all backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 327
diff changeset
358 req->set = orig_request->set;
0344108db255 make original proppatch property list available to all backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 327
diff changeset
359 req->setcount = orig_request->setcount;
0344108db255 make original proppatch property list available to all backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 327
diff changeset
360 req->remove = orig_request->remove;
0344108db255 make original proppatch property list available to all backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 327
diff changeset
361 req->removecount = orig_request->removecount;
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
362 req->userdata = NULL;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
363
263
533f9097d712 fix kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
364 // check if we need to open the file because the backend wants it
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
365 if(!file && (dav->settings & WS_WEBDAV_PROPPATCH_USE_VFS)
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
366 == WS_WEBDAV_PROPPATCH_USE_VFS)
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
367 {
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
368 ctx = vfs_request_context(op->sn, op->rq);
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
369 if(!ctx) {
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
370 ret = REQ_ABORTED;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
371 break;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
372 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
373
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
374 file = vfs_open(ctx, path, O_RDONLY);
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
375 if(!file) {
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
376 protocol_status(
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
377 op->sn,
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
378 op->rq,
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
379 util_errno2status(ctx->vfs_errno),
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
380 NULL);
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
381 ret = REQ_ABORTED;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
382 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
383 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
384
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
385 // execute proppatch_do
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
386 if(dav->proppatch_do(req, resource, file, &set, &remove)) {
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
387 // return later, because we need do execute proppatch_finish
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
388 // for all successfully called backends
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
389 ret = REQ_ABORTED;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
390 break;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
391 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
392
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
393 // proppatch_do should remove all handled props from set and remove
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
394 // in the next iteration, the backend must use these reduced lists
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
395 prev_set = set;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
396 prev_remove = remove;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
397
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
398 requests[numrequests++] = req;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
399
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
400 // continue with next backend
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
401 dav = dav->next;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
402 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
403
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
404 WSBool commit = FALSE;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
405 if(ret == REQ_PROCEED && resource->err == 0) {
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
406 // no errors, no properties with errors -> save the changes
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
407 commit = TRUE;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
408 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
409
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
410 // call proppatch_finish for each successfully called proppatch_do
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
411 dav = op->dav;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
412 int i = 0;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
413 while(dav && i < numrequests) {
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
414 if(dav->proppatch_finish(requests[i], resource, file, commit)) {
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
415 ret = REQ_ABORTED;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
416 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
417 i++;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
418 dav = dav->next;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
419 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
420
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
421 if(file) {
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
422 vfs_close(file);
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
423 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
424
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
425 if(resource->close(resource)) {
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
426 ret = REQ_ABORTED;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
427 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
428
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
429 return ret;
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
430 }
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
431
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
432 int webdav_op_proppatch_close_resource(
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
433 WebdavOperation *op,
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
434 WebdavResource *resource)
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
435 {
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
436 return 0; // NOP
239
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
437 }
d5031c30022c make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 237
diff changeset
438
245
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
439
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
440 /****************************************************************************
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
441 *
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
442 * VFS OPERATION
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
443 *
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
444 ****************************************************************************/
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
445
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
446 WebdavVFSOperation* webdav_vfs_op(
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
447 Session *sn,
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
448 Request *rq,
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
449 WebdavBackend *dav,
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
450 WSBool precondition)
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
451 {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
452 WebdavVFSOperation *op = pool_malloc(sn->pool, sizeof(WebdavVFSOperation));
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
453 if(!op) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
454 return NULL;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
455 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
456 ZERO(op, sizeof(WebdavVFSOperation));
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
457
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
458 op->sn = sn;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
459 op->rq = rq;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
460 op->dav = dav;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
461 op->stat = NULL;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
462 op->stat_errno = 0;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
463
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
464 // create VFS context
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
465 VFSContext *vfs = vfs_request_context(sn, rq);
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
466 if(!vfs) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
467 pool_free(sn->pool, op);
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
468 return NULL;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
469 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
470 op->vfs = vfs;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
471
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
472 char *path = pblock_findkeyval(pb_key_path, rq->vars);
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
473 op->path = path;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
474
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
475 return op;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
476 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
477
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
478 WebdavVFSOperation webdav_vfs_sub_op(
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
479 WebdavVFSOperation *op,
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
480 char *path,
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
481 struct stat *s)
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
482 {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
483 WebdavVFSOperation sub;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
484 sub.dav = op->dav;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
485 sub.path = path;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
486 sub.sn = op->sn;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
487 sub.vfs = op->vfs;
249
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
488 sub.path = path;
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
489 sub.stat = s;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
490 sub.stat_errno = 0;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
491 return sub;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
492 }
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
493
246
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
494 int webdav_op_iterate_children(
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
495 VFSContext *vfs,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
496 int depth,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
497 const char *href,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
498 const char *path,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
499 vfs_op_child_func func,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
500 void *userdata)
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
501 {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
502 UcxAllocator *a = session_get_allocator(vfs->sn);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
503 pool_handle_t *pool = vfs->sn->pool;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
504
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
505 PathSearchElm *start_elm = pool_malloc(pool, sizeof(PathSearchElm));
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
506 start_elm->href = pool_strdup(pool, href ? href : "");
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
507 start_elm->path = pool_strdup(pool, path ? path : "");
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
508 start_elm->hreflen = href ? strlen(href) : 0;
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
509 start_elm->pathlen = path ? strlen(path) : 0;
246
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
510
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
511 UcxList *stack = ucx_list_prepend_a(a, NULL, start_elm);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
512 UcxList *stack_end = stack;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
513 if(!stack) {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
514 return 1;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
515 }
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
516
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
517 // reusable buffer for full child path and href
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
518 char *newpath = pool_malloc(pool, 256);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
519 size_t newpathlen = 256;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
520
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
521 char *newhref = pool_malloc(pool, 256);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
522 size_t newhreflen = 256;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
523
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
524 int err = 0;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
525 while(stack && !err) {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
526 PathSearchElm *cur_elm = stack->data;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
527
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
528 // when newpath is initialized with the parent path
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
529 // set path_buf_init to TRUE
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
530 WSBool href_buf_init = FALSE;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
531 WSBool path_buf_init = FALSE;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
532
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
533 VFS_DIR dir = vfs_opendir(vfs, cur_elm->path);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
534 if(!dir) {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
535 log_ereport(
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
536 LOG_FAILURE,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
537 "webdav: propfind: cannot open directory %d",
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
538 vfs->vfs_errno);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
539 err = 1;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
540 break;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
541 }
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
542
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
543 VFS_ENTRY f;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
544 while(vfs_readdir_stat(dir, &f)) {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
545 if(f.stat_errno != 0) {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
546 continue;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
547 }
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
548
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
549 size_t child_len = strlen(f.name);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
550
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
551 // create new path and href for the child
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
552 if(path_buf_concat(
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
553 pool,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
554 &newhref,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
555 &newhreflen,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
556 &href_buf_init,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
557 cur_elm->href,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
558 cur_elm->hreflen,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
559 f.name,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
560 child_len))
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
561 {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
562 err = 1;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
563 break;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
564 }
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
565 if(path_buf_concat(
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
566 pool,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
567 &newpath,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
568 &newpathlen,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
569 &path_buf_init,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
570 cur_elm->path,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
571 cur_elm->pathlen,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
572 f.name,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
573 child_len))
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
574 {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
575 err = 1;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
576 break;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
577 }
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
578 size_t childhreflen = cur_elm->hreflen + 1 + child_len;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
579 size_t childpathlen = cur_elm->pathlen + 1 + child_len;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
580
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
581 // execute callback func for this file
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
582 if(func(vfs, newhref, newpath, dir, &f.stat, userdata)) {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
583 err = 1;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
584 break;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
585 }
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
586
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
587 // depth of -1 means infinity
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
588 if(depth == -1 && S_ISDIR(f.stat.st_mode)) {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
589 char *hrefcp = pool_malloc(pool, childhreflen + 1);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
590 memcpy(hrefcp, newhref, childhreflen + 1);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
591 hrefcp[childhreflen] = '\0';
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
592
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
593 char *pathcp = pool_malloc(pool, childpathlen + 1);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
594 memcpy(pathcp, newpath, childpathlen + 1);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
595 pathcp[childpathlen] = '\0';
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
596
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
597 PathSearchElm *new_elm = pool_malloc(pool,
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
598 sizeof(PathSearchElm));
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
599 new_elm->href = hrefcp;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
600 new_elm->path = pathcp;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
601 new_elm->hreflen = childhreflen;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
602 new_elm->pathlen = childpathlen;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
603
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
604 // add the new_elm to the stack
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
605 // stack_end is always not NULL here, because we remove
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
606 // the first stack element at the end of the loop
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
607 UcxList *newlistelm = ucx_list_append_a(a, stack_end, new_elm);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
608 if(!newlistelm) {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
609 err = 1;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
610 break;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
611 }
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
612 stack_end = newlistelm;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
613 }
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
614 }
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
615
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
616 vfs_closedir(dir);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
617
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
618 pool_free(pool, cur_elm->path);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
619 pool_free(pool, cur_elm->href);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
620 pool_free(pool, cur_elm);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
621
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
622 stack = ucx_list_remove_a(a, stack, stack);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
623 }
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
624
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
625 // in case of an error, we have to free all remaining stack elements
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
626 UCX_FOREACH(elm, stack) {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
627 char *data = elm->data;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
628 if(data != path) {
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
629 pool_free(pool, data);
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
630 }
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
631 }
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
632
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
633 return err;
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
634 }
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
635
155bdef7fe7e add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 245
diff changeset
636
245
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
637 int webdav_vfs_stat(WebdavVFSOperation *op) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
638 if(op->stat) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
639 return 0;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
640 } else if(op->stat_errno != 0) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
641 // previous stat failed
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
642 return 1;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
643 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
644
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
645 // stat file
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
646 struct stat sbuf;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
647 int ret = vfs_stat(op->vfs, op->path, &sbuf);
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
648 if(!ret) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
649 // save result in op->stat and in s
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
650 op->stat = pool_malloc(op->sn->pool, sizeof(struct stat));
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
651 if(op->stat) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
652 memcpy(op->stat, &sbuf, sizeof(struct stat));
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
653 } else {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
654 ret = 1;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
655 op->stat_errno = ENOMEM;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
656 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
657 } else {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
658 op->stat_errno = errno;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
659 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
660
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
661 return ret;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
662 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
663
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
664 int webdav_vfs_op_do(WebdavVFSOperation *op, WebdavVFSOpType type) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
665 WSBool exec_vfs = TRUE;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
666
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
667 // requests for each backends
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
668 WebdavVFSRequest **requests = pool_calloc(
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
669 op->sn->pool,
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
670 webdav_num_backends(op->dav),
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
671 sizeof(WebdavVFSRequest*));
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
672 if(requests == NULL) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
673 return REQ_ABORTED;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
674 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
675
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
676 int ret = REQ_PROCEED;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
677
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
678 // call opt_* func for each backend
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
679 WebdavBackend *dav = op->dav;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
680 int called_backends = 0;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
681 while(dav) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
682 WebdavVFSRequest *request = NULL;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
683
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
684 // get vfs operation functions
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
685 vfs_op_func op_func = NULL;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
686 vfs_op_finish_func op_finish_func = NULL;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
687
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
688 if(type == WEBDAV_VFS_MKDIR) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
689 op_func = dav->opt_mkcol;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
690 op_finish_func = dav->opt_mkcol_finish;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
691 } else if(type == WEBDAV_VFS_DELETE) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
692 op_func = dav->opt_delete;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
693 op_finish_func = dav->opt_delete_finish;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
694 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
695
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
696 if(op_func || op_finish_func) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
697 // we need a request object
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
698 request = pool_malloc(op->sn->pool, sizeof(WebdavVFSRequest));
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
699 if(!request) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
700 exec_vfs = FALSE;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
701 ret = REQ_ABORTED;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
702 break;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
703 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
704 request->sn = op->sn;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
705 request->rq = op->rq;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
706 request->path = op->path;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
707 request->userdata = NULL;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
708
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
709 requests[called_backends] = request;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
710 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
711
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
712 // exec backend func for this operation
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
713 // this will set 'done' to TRUE, if no further vfs call is required
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
714 WSBool done = FALSE;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
715 called_backends++;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
716 if(op_func) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
717 if(op_func(request, &done)) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
718 exec_vfs = FALSE;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
719 ret = REQ_ABORTED;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
720 break;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
721 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
722 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
723 if(done) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
724 exec_vfs = FALSE;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
725 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
726
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
727 dav = dav->next;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
728 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
729
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
730 // if needed, call vfs func for this operation
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
731 if(exec_vfs) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
732 int r = 0;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
733 if(type == WEBDAV_VFS_MKDIR) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
734 r = vfs_mkdir(op->vfs, op->path);
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
735 } else if(type == WEBDAV_VFS_DELETE) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
736 r = webdav_vfs_unlink(op);
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
737 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
738
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
739 if(r) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
740 ret = REQ_ABORTED;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
741 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
742 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
743
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
744 WSBool success = ret == REQ_PROCEED ? TRUE : FALSE;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
745
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
746 // finish mkcol (cleanup) by calling opt_*_finish for each backend
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
747 dav = op->dav;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
748 int i = 0;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
749 while(dav && i < called_backends) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
750 // get vfs operation functions
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
751 vfs_op_finish_func op_finish_func = NULL;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
752
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
753 if(type == WEBDAV_VFS_MKDIR) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
754 op_finish_func = dav->opt_mkcol_finish;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
755 } else if(type == WEBDAV_VFS_DELETE) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
756 op_finish_func = dav->opt_delete_finish;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
757 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
758
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
759 if(op_finish_func) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
760 if(op_finish_func(requests[i], success)) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
761 ret = REQ_ABORTED; // don't exit loop
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
762 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
763 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
764
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
765 dav = dav->next;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
766 i++;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
767 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
768
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
769 return ret;
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
770 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
771
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
772 int webdav_vfs_unlink(WebdavVFSOperation *op) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
773 // stat the file first, to check if the file is a directory
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
774 if(webdav_vfs_stat(op)) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
775 return 1; // error
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
776 } else {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
777 if(!S_ISDIR(op->stat->st_mode)) {
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
778 return vfs_unlink(op->vfs, op->path);
247
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
779 } else {
1df803e06076 implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 246
diff changeset
780 return vfs_rmdir(op->vfs, op->path);
245
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
781 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
782 }
a193c42fc809 add mkcol and delete interface to webdav backend, move webdav vfs logic to operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
783 }

mercurial