230 |
230 |
231 int webdav_options(pblock *pb, Session *sn, Request *rq) { |
231 int webdav_options(pblock *pb, Session *sn, Request *rq) { |
232 return REQ_ABORTED; |
232 return REQ_ABORTED; |
233 } |
233 } |
234 |
234 |
|
235 static const char* propfind_error2str(int error) { |
|
236 switch(error) { |
|
237 case PROPFIND_PARSER_OK: return "ok"; |
|
238 case PROPFIND_PARSER_NO_PROPFIND: return "invalid xml root element"; |
|
239 case PROPFIND_PARSER_NO_PROPERTIES: return "no properties specified"; |
|
240 case PROPFIND_PARSER_INVALID_REQUEST: return "invalid propfind request"; |
|
241 case PROPFIND_PARSER_OOM: return "OOM"; |
|
242 case PROPFIND_PARSER_ERROR: return "error"; |
|
243 } |
|
244 return ""; |
|
245 } |
|
246 |
235 int webdav_propfind(pblock *pb, Session *sn, Request *rq) { |
247 int webdav_propfind(pblock *pb, Session *sn, Request *rq) { |
236 char *expect = pblock_findkeyval(pb_key_expect, rq->headers); |
248 char *expect = pblock_findkeyval(pb_key_expect, rq->headers); |
237 if(expect) { |
249 if(expect) { |
238 if(!strcasecmp(expect, "100-continue")) { |
250 if(!strcasecmp(expect, "100-continue")) { |
239 if(http_send_continue(sn)) { |
251 if(http_send_continue(sn)) { |
244 |
256 |
245 UcxBuffer *reqbody = rqbody2buffer(sn, rq); |
257 UcxBuffer *reqbody = rqbody2buffer(sn, rq); |
246 if(!reqbody) { |
258 if(!reqbody) { |
247 return REQ_ABORTED; |
259 return REQ_ABORTED; |
248 } |
260 } |
249 |
|
250 UcxAllocator *a = session_get_allocator(sn); |
|
251 |
261 |
252 int error = 0; |
262 int error = 0; |
253 WebdavPropfindRequest *propfind = propfind_parse( |
263 WebdavPropfindRequest *propfind = propfind_parse( |
254 sn, |
264 sn, |
255 rq, |
265 rq, |
256 reqbody->space, |
266 reqbody->space, |
257 reqbody->size, |
267 reqbody->size, |
258 &error); |
268 &error); |
259 ucx_buffer_free(reqbody); |
269 ucx_buffer_free(reqbody); |
260 if(!propfind) { |
270 if(!propfind) { |
261 switch(error) { |
271 log_ereport(LOG_FAILURE, "webdav-propfind: %s", propfind_error2str(error)); |
262 // TODO: handle all errors |
272 return REQ_ABORTED; |
263 default: return REQ_ABORTED; |
|
264 } |
|
265 } |
273 } |
266 |
274 |
267 WebdavBackend *dav = rq->davCollection ? |
275 WebdavBackend *dav = rq->davCollection ? |
268 rq->davCollection : &default_backend; |
276 rq->davCollection : &default_backend; |
269 |
277 |
278 Multistatus *ms = multistatus_response(sn, rq); |
286 Multistatus *ms = multistatus_response(sn, rq); |
279 if(!ms) { |
287 if(!ms) { |
280 return REQ_ABORTED; |
288 return REQ_ABORTED; |
281 } |
289 } |
282 |
290 |
283 |
|
284 int ret = webdav_propfind_do(dav, propfind, (WebdavResponse*)ms, NULL, path, uri); |
291 int ret = webdav_propfind_do(dav, propfind, (WebdavResponse*)ms, NULL, path, uri); |
285 |
292 |
286 // if propfind was successful, send the result to the client |
293 // if propfind was successful, send the result to the client |
287 if(ret == REQ_PROCEED && multistatus_send(ms, sn->csd)) { |
294 if(ret == REQ_PROCEED) { |
288 ret = REQ_ABORTED; |
295 if(multistatus_send(ms, sn->csd)) { |
289 // TODO: log error |
296 ret = REQ_ABORTED; |
|
297 } |
290 } else { |
298 } else { |
291 // TODO: error response |
299 log_ereport(LOG_FAILURE, "webdav-propfind: operation failed"); |
292 } |
300 } |
293 |
301 |
294 // cleanup |
302 // cleanup |
295 if(propfind->doc) { |
303 if(propfind->doc) { |
296 xmlFreeDoc(propfind->doc); |
304 xmlFreeDoc(propfind->doc); |