Sun, 01 May 2022 10:56:36 +0200
fix memory initialization for WebdavProperty in webdav tests
217
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2019 Olaf Wintermann. All rights reserved. |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include <stdio.h> |
8ed14d76db42
add backend chaining
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #include <stdlib.h> |
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 | |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
285 | VFSContext *ctx = NULL; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
286 | VFSFile *file = NULL; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
287 | |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
288 | // requests for each backends |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
289 | WebdavProppatchRequest **requests = pool_calloc( |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
290 | op->sn->pool, |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
291 | webdav_num_backends(op->dav), |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
292 | sizeof(WebdavProppatchRequest*)); |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
293 | if(requests == NULL) { |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
294 | return REQ_ABORTED; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
295 | } |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
296 | |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
297 | WebdavPList *prev_set = orig_request->set; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
298 | WebdavPList *prev_remove = orig_request->remove; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
299 | size_t set_count = orig_request->setcount; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
300 | size_t remove_count = orig_request->removecount; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
301 | |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
302 | int ret = REQ_PROCEED; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
303 | |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
304 | // iterate backends and execute proppatch_do |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
305 | WebdavBackend *dav = op->dav; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
306 | size_t numrequests = 0; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
307 | while(dav) { |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
308 | WebdavPList *set = webdav_plist_clone_s( |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
309 | op->sn->pool, |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
310 | prev_set, |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
311 | &set_count); |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
312 | WebdavPList *remove = webdav_plist_clone_s( |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
313 | op->sn->pool, |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
314 | prev_remove, |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
315 | &remove_count); |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
316 | if((prev_set && !set) || (prev_remove && !remove)) { |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
317 | // clone failed, OOM |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
318 | ret = REQ_ABORTED; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
319 | break; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
320 | } |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
321 | |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
322 | // create new WebdavProppatchRequest object for this backend |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
323 | WebdavProppatchRequest *req = pool_malloc( |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
324 | op->sn->pool, |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
325 | sizeof(WebdavProppatchRequest)); |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
326 | memcpy(req, orig_request, sizeof(WebdavProppatchRequest)); |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
327 | req->dav = dav; |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
328 | req->set = set; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
329 | req->setcount = set_count; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
330 | req->remove = remove; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
331 | req->removecount = remove_count; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
332 | req->userdata = NULL; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
333 | |
263
533f9097d712
fix kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
334 | // 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
|
335 | if(!file && (dav->settings & WS_WEBDAV_PROPPATCH_USE_VFS) |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
336 | == WS_WEBDAV_PROPPATCH_USE_VFS) |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
337 | { |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
338 | ctx = vfs_request_context(op->sn, op->rq); |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
339 | if(!ctx) { |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
340 | ret = REQ_ABORTED; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
341 | break; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
342 | } |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
343 | |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
344 | file = vfs_open(ctx, path, O_RDONLY); |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
345 | if(!file) { |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
346 | protocol_status( |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
347 | op->sn, |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
348 | op->rq, |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
349 | util_errno2status(ctx->vfs_errno), |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
350 | NULL); |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
351 | ret = REQ_ABORTED; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
352 | } |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
353 | } |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
354 | |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
355 | // execute proppatch_do |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
356 | if(dav->proppatch_do(req, resource, file, &set, &remove)) { |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
357 | // return later, because we need do execute proppatch_finish |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
358 | // for all successfully called backends |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
359 | ret = REQ_ABORTED; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
360 | break; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
361 | } |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
362 | |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
363 | // 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
|
364 | // 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
|
365 | prev_set = set; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
366 | prev_remove = remove; |
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 | requests[numrequests++] = req; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
369 | |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
370 | // continue with next backend |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
371 | dav = dav->next; |
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 | WSBool commit = FALSE; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
375 | if(ret == REQ_PROCEED && resource->err == 0) { |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
376 | // no errors, no properties with errors -> save the changes |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
377 | commit = TRUE; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
378 | } |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
379 | |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
380 | // call proppatch_finish for each successfully called proppatch_do |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
381 | dav = op->dav; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
382 | int i = 0; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
383 | while(dav && i < numrequests) { |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
384 | if(dav->proppatch_finish(requests[i], resource, file, commit)) { |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
385 | ret = REQ_ABORTED; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
386 | } |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
387 | i++; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
388 | dav = dav->next; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
389 | } |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
390 | |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
391 | if(file) { |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
392 | vfs_close(file); |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
393 | } |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
394 | |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
395 | if(resource->close(resource)) { |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
396 | ret = REQ_ABORTED; |
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 | |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
399 | return ret; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
400 | } |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
401 | |
239
d5031c30022c
make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
237
diff
changeset
|
402 | int webdav_op_proppatch_close_resource( |
d5031c30022c
make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
237
diff
changeset
|
403 | WebdavOperation *op, |
d5031c30022c
make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
237
diff
changeset
|
404 | WebdavResource *resource) |
d5031c30022c
make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
237
diff
changeset
|
405 | { |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
406 | return 0; // NOP |
239
d5031c30022c
make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
237
diff
changeset
|
407 | } |
d5031c30022c
make multistatus response ready for proppatch requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
237
diff
changeset
|
408 | |
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
|
409 | |
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
|
410 | /**************************************************************************** |
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
|
411 | * |
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
|
412 | * 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
|
413 | * |
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
|
414 | ****************************************************************************/ |
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
|
415 | |
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
|
416 | 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
|
417 | 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
|
418 | 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
|
419 | 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
|
420 | 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
|
421 | { |
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
|
422 | 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
|
423 | 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
|
424 | 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
|
425 | } |
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
|
426 | 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
|
427 | |
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
|
428 | 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
|
429 | 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
|
430 | 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
|
431 | 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
|
432 | 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
|
433 | |
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
|
434 | // 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
|
435 | 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
|
436 | 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
|
437 | 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
|
438 | 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
|
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 | 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
|
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 | 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
|
443 | 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
|
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 | 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
|
446 | } |
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 | |
247
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
448 | WebdavVFSOperation webdav_vfs_sub_op( |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
449 | WebdavVFSOperation *op, |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
450 | char *path, |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
451 | struct stat *s) |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
452 | { |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
453 | WebdavVFSOperation sub; |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
454 | sub.dav = op->dav; |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
455 | sub.path = path; |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
456 | sub.sn = op->sn; |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
457 | sub.vfs = op->vfs; |
249
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
247
diff
changeset
|
458 | sub.path = path; |
247
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
459 | sub.stat = s; |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
460 | sub.stat_errno = 0; |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
461 | return sub; |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
462 | } |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
463 | |
246
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
464 | int webdav_op_iterate_children( |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
465 | VFSContext *vfs, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
466 | int depth, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
467 | const char *href, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
468 | const char *path, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
469 | vfs_op_child_func func, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
470 | void *userdata) |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
471 | { |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
472 | 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
|
473 | 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
|
474 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
475 | 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
|
476 | start_elm->href = pool_strdup(pool, href ? href : ""); |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
477 | start_elm->path = pool_strdup(pool, path ? path : ""); |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
478 | start_elm->hreflen = href ? strlen(href) : 0; |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
479 | 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
|
480 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
481 | 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
|
482 | UcxList *stack_end = stack; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
483 | if(!stack) { |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
484 | return 1; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
485 | } |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
486 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
487 | // 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
|
488 | char *newpath = pool_malloc(pool, 256); |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
489 | size_t newpathlen = 256; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
490 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
491 | char *newhref = pool_malloc(pool, 256); |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
492 | size_t newhreflen = 256; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
493 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
494 | int err = 0; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
495 | while(stack && !err) { |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
496 | PathSearchElm *cur_elm = stack->data; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
497 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
498 | // 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
|
499 | // set path_buf_init to TRUE |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
500 | WSBool href_buf_init = FALSE; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
501 | WSBool path_buf_init = FALSE; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
502 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
503 | 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
|
504 | if(!dir) { |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
505 | log_ereport( |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
506 | LOG_FAILURE, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
507 | "webdav: propfind: cannot open directory %d", |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
508 | vfs->vfs_errno); |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
509 | err = 1; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
510 | break; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
511 | } |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
512 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
513 | VFS_ENTRY f; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
514 | while(vfs_readdir_stat(dir, &f)) { |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
515 | if(f.stat_errno != 0) { |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
516 | continue; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
517 | } |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
518 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
519 | 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
|
520 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
521 | // 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
|
522 | if(path_buf_concat( |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
523 | pool, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
524 | &newhref, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
525 | &newhreflen, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
526 | &href_buf_init, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
527 | cur_elm->href, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
528 | cur_elm->hreflen, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
529 | f.name, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
530 | child_len)) |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
531 | { |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
532 | err = 1; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
533 | break; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
534 | } |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
535 | if(path_buf_concat( |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
536 | pool, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
537 | &newpath, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
538 | &newpathlen, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
539 | &path_buf_init, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
540 | cur_elm->path, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
541 | cur_elm->pathlen, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
542 | f.name, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
543 | child_len)) |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
544 | { |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
545 | err = 1; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
546 | break; |
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 | 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
|
549 | 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
|
550 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
551 | // execute callback func for this file |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
552 | 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
|
553 | err = 1; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
554 | break; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
555 | } |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
556 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
557 | // depth of -1 means infinity |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
558 | 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
|
559 | 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
|
560 | memcpy(hrefcp, newhref, childhreflen + 1); |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
561 | hrefcp[childhreflen] = '\0'; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
562 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
563 | 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
|
564 | memcpy(pathcp, newpath, childpathlen + 1); |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
565 | pathcp[childpathlen] = '\0'; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
566 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
567 | PathSearchElm *new_elm = pool_malloc(pool, |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
568 | sizeof(PathSearchElm)); |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
569 | new_elm->href = hrefcp; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
570 | new_elm->path = pathcp; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
571 | new_elm->hreflen = childhreflen; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
572 | new_elm->pathlen = childpathlen; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
573 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
574 | // 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
|
575 | // 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
|
576 | // 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
|
577 | 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
|
578 | if(!newlistelm) { |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
579 | err = 1; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
580 | break; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
581 | } |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
582 | stack_end = newlistelm; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
583 | } |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
584 | } |
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 | vfs_closedir(dir); |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
587 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
588 | pool_free(pool, cur_elm->path); |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
589 | pool_free(pool, cur_elm->href); |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
590 | pool_free(pool, cur_elm); |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
591 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
592 | 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
|
593 | } |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
594 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
595 | // 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
|
596 | UCX_FOREACH(elm, stack) { |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
597 | char *data = elm->data; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
598 | if(data != path) { |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
599 | pool_free(pool, data); |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
600 | } |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
601 | } |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
602 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
603 | return err; |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
604 | } |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
605 | |
155bdef7fe7e
add webdav op function for iterating directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
245
diff
changeset
|
606 | |
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
|
607 | 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
|
608 | 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
|
609 | 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
|
610 | } 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
|
611 | // 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
|
612 | 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
|
613 | } |
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
|
614 | |
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
|
615 | // 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
|
616 | 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
|
617 | 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
|
618 | 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
|
619 | // 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
|
620 | 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
|
621 | 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
|
622 | 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
|
623 | } 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
|
624 | 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
|
625 | 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
|
626 | } |
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
|
627 | } 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
|
628 | 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
|
629 | } |
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
|
630 | |
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
|
631 | 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
|
632 | } |
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
|
633 | |
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
|
634 | 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
|
635 | 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
|
636 | |
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 | // 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
|
638 | 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
|
639 | 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
|
640 | 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
|
641 | 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
|
642 | 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
|
643 | 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
|
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 | |
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 | 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
|
647 | |
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 | // 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
|
649 | 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
|
650 | 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
|
651 | 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
|
652 | 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
|
653 | |
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 | // 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
|
655 | 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
|
656 | 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
|
657 | |
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 | 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
|
659 | 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
|
660 | 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
|
661 | } 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
|
662 | 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
|
663 | 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
|
664 | } |
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 | |
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 | 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
|
667 | // 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
|
668 | 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
|
669 | 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
|
670 | 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
|
671 | 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
|
672 | 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
|
673 | } |
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 | 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
|
675 | 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
|
676 | 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
|
677 | 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
|
678 | |
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 | 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
|
680 | } |
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 | |
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 | // 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
|
683 | // 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
|
684 | 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
|
685 | 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
|
686 | 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
|
687 | 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
|
688 | 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
|
689 | 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
|
690 | 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
|
691 | } |
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 | } |
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 | 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
|
694 | 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
|
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 | |
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 | 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
|
698 | } |
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 | |
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 | // 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
|
701 | 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
|
702 | 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
|
703 | 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
|
704 | 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
|
705 | } 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
|
706 | 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
|
707 | } |
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 | 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
|
710 | 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
|
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 | } |
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 | |
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 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
|
715 | |
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 | // 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
|
717 | 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
|
718 | 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
|
719 | 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
|
720 | // 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
|
721 | 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
|
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(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
|
724 | 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
|
725 | } 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
|
726 | 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
|
727 | } |
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 | 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
|
730 | 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
|
731 | 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
|
732 | } |
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 | } |
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 | |
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 | 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
|
736 | 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
|
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 | 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
|
740 | } |
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 | 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
|
743 | // 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
|
744 | 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
|
745 | 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
|
746 | } 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
|
747 | 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
|
748 | return vfs_unlink(op->vfs, op->path); |
247
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
749 | } else { |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
246
diff
changeset
|
750 | 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
|
751 | } |
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 | } |