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