30 |
30 |
31 #include "../daemon/log.h" |
31 #include "../daemon/log.h" |
32 #include "../daemon/request.h" |
32 #include "../daemon/request.h" |
33 #include "../util/pblock.h" |
33 #include "../util/pblock.h" |
34 #include "../util/util.h" |
34 #include "../util/util.h" |
|
35 #include "../public/webdav.h" |
|
36 |
|
37 #include "../daemon/session.h" |
|
38 #include "../daemon/config.h" |
|
39 |
|
40 #include "../public/vfs.h" |
|
41 |
|
42 static int initialize_dav_repo(pblock *pb, Session *sn, Request *rq, WebdavRepository *repo) { |
|
43 if(repo->vfs) { |
|
44 VFS *vfs = repo->vfs->create(sn, rq, pb, repo->vfsInitData); |
|
45 if(!vfs) { |
|
46 return REQ_ABORTED; |
|
47 } |
|
48 rq->vfs = vfs; |
|
49 } |
|
50 |
|
51 WebdavBackend *backend_first = NULL; |
|
52 WebdavBackend *backend_last = NULL; |
|
53 UCX_FOREACH(elm, repo->davBackends) { |
|
54 WebdavBackendInitData *davInit = elm->data; |
|
55 WebdavBackend *backend = davInit->davType->create(sn, rq, pb, davInit->davInitData); |
|
56 if(!backend) { |
|
57 return REQ_ABORTED; |
|
58 } |
|
59 |
|
60 if(backend_last) { |
|
61 backend_last->next = backend; |
|
62 backend_last = backend; |
|
63 } else { |
|
64 backend_first = backend; |
|
65 backend_last = backend; |
|
66 } |
|
67 } |
|
68 rq->davCollection = backend_first; |
|
69 |
|
70 return 0; |
|
71 } |
|
72 |
|
73 static int nametrans_set_dav_repository(pblock *pb, Session *sn, Request *rq) { |
|
74 char *dav = pblock_findkeyval(pb_key_dav, pb); |
|
75 if(!dav) return 0; |
|
76 |
|
77 ServerConfiguration *config = session_get_config(sn); |
|
78 WebdavRepository *repo = ucx_map_cstr_get(config->dav, dav); |
|
79 |
|
80 if(!repo) { |
|
81 log_ereport(LOG_MISCONFIG, "nametrans: unknown dav repository '%s'", dav); |
|
82 return REQ_ABORTED; |
|
83 } |
|
84 |
|
85 return initialize_dav_repo(pb, sn, rq, repo); |
|
86 } |
|
87 |
|
88 static int nametrans_set_vfs(pblock *pb, Session *sn, Request *rq) { |
|
89 char *vfsclass = pblock_findkeyval(pb_key_vfsclass, pb); |
|
90 if(!vfsclass) return 0; |
|
91 |
|
92 VFS *vfs = vfs_create(sn, rq, vfsclass, pb, NULL); |
|
93 if(!vfs) { |
|
94 return 1; |
|
95 } |
|
96 rq->vfs = vfs; |
|
97 return 0; |
|
98 } |
|
99 |
|
100 static int nametrans_set_dav(pblock *pb, Session *sn, Request *rq) { |
|
101 char *davclass = pblock_findkeyval(pb_key_davclass, pb); |
|
102 if(!davclass) return 0; |
|
103 |
|
104 WebdavBackend *dav = webdav_create(sn, rq, davclass, pb, NULL); |
|
105 |
|
106 rq->davCollection = dav; |
|
107 return 0; |
|
108 } |
35 |
109 |
36 /* |
110 /* |
37 * assign_name |
111 * assign_name |
38 * |
112 * |
39 * Assigns the name specified by the name parameter if the uri has the |
113 * Assigns the name specified by the name parameter if the uri has the |
64 return REQ_NOACTION; |
138 return REQ_NOACTION; |
65 } |
139 } |
66 i++; |
140 i++; |
67 } |
141 } |
68 } |
142 } |
|
143 |
|
144 if(nametrans_set_dav_repository(pb, sn, rq)) { |
|
145 log_ereport(LOG_FAILURE, "assign-name: cannot create dav repository: name=%s from=%s", name, from); |
|
146 return REQ_ABORTED; |
|
147 } |
|
148 if(nametrans_set_vfs(pb, sn, rq)) { |
|
149 log_ereport(LOG_FAILURE, "assign-name: cannot create VFS: name=%s from=%s", name, from); |
|
150 return REQ_ABORTED; |
|
151 } |
|
152 if(nametrans_set_dav(pb, sn, rq)) { |
|
153 log_ereport(LOG_FAILURE, "assign-name: cannot create Webdav Backend: name=%s from=%s", name, from); |
|
154 return REQ_ABORTED; |
|
155 } |
69 |
156 |
70 // add object to rq->vars |
157 // add object to rq->vars |
71 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars); |
158 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars); |
72 |
159 |
73 return REQ_NOACTION; |
160 return REQ_NOACTION; |
87 log_ereport(LOG_MISCONFIG, "document-root: missing root parameter"); |
174 log_ereport(LOG_MISCONFIG, "document-root: missing root parameter"); |
88 protocol_status(sn, rq, 500, NULL); |
175 protocol_status(sn, rq, 500, NULL); |
89 return REQ_ABORTED; |
176 return REQ_ABORTED; |
90 } |
177 } |
91 |
178 |
|
179 if(nametrans_set_vfs(pb, sn, rq)) { |
|
180 log_ereport(LOG_FAILURE, "document-root: cannot create VFS"); |
|
181 return REQ_ABORTED; |
|
182 } |
|
183 |
92 sstr_t root_str = sstr(root); |
184 sstr_t root_str = sstr(root); |
93 sstr_t uri_str = sstr(pblock_findkeyval(pb_key_uri, rq->reqpb)); |
185 sstr_t uri_str = sstr(pblock_findkeyval(pb_key_uri, rq->reqpb)); |
94 |
186 |
95 request_set_path(root_str, uri_str, rq->vars); |
187 request_set_path(root_str, uri_str, rq->vars); |
96 |
188 |
104 * |
196 * |
105 * pblock parameter: |
197 * pblock parameter: |
106 * from prefix |
198 * from prefix |
107 * dir file system directory |
199 * dir file system directory |
108 * name (optional) object name |
200 * name (optional) object name |
|
201 * dav (optional) dav repository name |
|
202 * vfsclass (optional) vfs name |
|
203 * davclass (optional) dav backend |
109 * |
204 * |
110 */ |
205 */ |
111 int pfx2dir(pblock *pb, Session *sn, Request *rq) { |
206 int pfx2dir(pblock *pb, Session *sn, Request *rq) { |
112 char *from = pblock_findkeyval(pb_key_from, pb); |
207 char *from = pblock_findkeyval(pb_key_from, pb); |
113 char *dir = pblock_findkeyval(pb_key_dir, pb); |
208 char *dir = pblock_findkeyval(pb_key_dir, pb); |
145 uri = uri + i; |
240 uri = uri + i; |
146 if(uri[0] == '/') { |
241 if(uri[0] == '/') { |
147 uri++; |
242 uri++; |
148 } |
243 } |
149 |
244 |
|
245 if(nametrans_set_dav_repository(pb, sn, rq)) { |
|
246 log_ereport(LOG_FAILURE, "pfx2dir: cannot create dav repository: from=%s dir=%s name=%s", from, dir, name); |
|
247 return REQ_ABORTED; |
|
248 } |
|
249 if(nametrans_set_vfs(pb, sn, rq)) { |
|
250 log_ereport(LOG_FAILURE, "pfx2dir: cannot create VFS: from=%s dir=%s name=%s", from, dir, name); |
|
251 return REQ_ABORTED; |
|
252 } |
|
253 if(nametrans_set_dav(pb, sn, rq)) { |
|
254 log_ereport(LOG_FAILURE, "pfx2dir: cannot create Webdav Backend: from=%s dir=%s name=%s", from, dir, name); |
|
255 return REQ_ABORTED; |
|
256 } |
|
257 |
150 request_set_path(sstr(dir), sstr(uri), rq->vars); |
258 request_set_path(sstr(dir), sstr(uri), rq->vars); |
151 |
259 |
152 if(name) { |
260 if(name) { |
153 // add object to rq->vars |
261 // add object to rq->vars |
154 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars); |
262 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars); |
187 char *path = pblock_findval("path", pb); |
295 char *path = pblock_findval("path", pb); |
188 char *name = pblock_findval("name", pb); |
296 char *name = pblock_findval("name", pb); |
189 |
297 |
190 if(!from || !path || !root) { |
298 if(!from || !path || !root) { |
191 log_ereport(LOG_MISCONFIG, "simple-rewrite: missing parameter (from, root, path)"); |
299 log_ereport(LOG_MISCONFIG, "simple-rewrite: missing parameter (from, root, path)"); |
|
300 return REQ_ABORTED; |
|
301 } |
|
302 |
|
303 if(nametrans_set_vfs(pb, sn, rq)) { |
|
304 log_ereport(LOG_FAILURE, "simple-rewrite: cannot create VFS: from=%s root=%s path=%s name=%s", from, root, path, name); |
192 return REQ_ABORTED; |
305 return REQ_ABORTED; |
193 } |
306 } |
194 |
307 |
195 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb); |
308 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb); |
196 sstr_t u = sstr(uri); |
309 sstr_t u = sstr(uri); |