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" |
35 #include "../public/webdav.h" |
36 |
36 |
|
37 #include "../daemon/session.h" |
|
38 #include "../daemon/config.h" |
|
39 |
37 #include "../public/vfs.h" |
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 } |
38 |
87 |
39 static int nametrans_set_vfs(pblock *pb, Session *sn, Request *rq) { |
88 static int nametrans_set_vfs(pblock *pb, Session *sn, Request *rq) { |
40 char *vfsclass = pblock_findkeyval(pb_key_vfsclass, pb); |
89 char *vfsclass = pblock_findkeyval(pb_key_vfsclass, pb); |
41 if(!vfsclass) return 0; |
90 if(!vfsclass) return 0; |
42 |
91 |
90 } |
139 } |
91 i++; |
140 i++; |
92 } |
141 } |
93 } |
142 } |
94 |
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 } |
95 if(nametrans_set_vfs(pb, sn, rq)) { |
148 if(nametrans_set_vfs(pb, sn, rq)) { |
96 log_ereport(LOG_FAILURE, "assign-name: cannot create VFS: name=%s from=%s", name, from); |
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); |
97 return REQ_ABORTED; |
154 return REQ_ABORTED; |
98 } |
155 } |
99 |
156 |
100 // add object to rq->vars |
157 // add object to rq->vars |
101 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars); |
158 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars); |
139 * |
196 * |
140 * pblock parameter: |
197 * pblock parameter: |
141 * from prefix |
198 * from prefix |
142 * dir file system directory |
199 * dir file system directory |
143 * name (optional) object name |
200 * name (optional) object name |
|
201 * dav (optional) dav repository name |
144 * vfsclass (optional) vfs name |
202 * vfsclass (optional) vfs name |
145 * davclass (optional) dav backend |
203 * davclass (optional) dav backend |
146 * |
204 * |
147 */ |
205 */ |
148 int pfx2dir(pblock *pb, Session *sn, Request *rq) { |
206 int pfx2dir(pblock *pb, Session *sn, Request *rq) { |
182 uri = uri + i; |
240 uri = uri + i; |
183 if(uri[0] == '/') { |
241 if(uri[0] == '/') { |
184 uri++; |
242 uri++; |
185 } |
243 } |
186 |
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 } |
187 if(nametrans_set_vfs(pb, sn, rq)) { |
249 if(nametrans_set_vfs(pb, sn, rq)) { |
188 log_ereport(LOG_FAILURE, "pfx2dir: cannot create VFS: from=%s dir=%s name=%s", from, dir, name); |
250 log_ereport(LOG_FAILURE, "pfx2dir: cannot create VFS: from=%s dir=%s name=%s", from, dir, name); |
189 return REQ_ABORTED; |
251 return REQ_ABORTED; |
190 } |
252 } |
191 if(nametrans_set_dav(pb, sn, rq)) { |
253 if(nametrans_set_dav(pb, sn, rq)) { |