src/server/webdav/webdav.c

branch
webdav
changeset 244
e59abb210584
parent 243
1a29b1d8d9d8
child 245
a193c42fc809
equal deleted inserted replaced
243:1a29b1d8d9d8 244:e59abb210584
64 default_backend.propfind_init = default_propfind_init; 64 default_backend.propfind_init = default_propfind_init;
65 default_backend.propfind_do = default_propfind_do; 65 default_backend.propfind_do = default_propfind_do;
66 default_backend.propfind_finish = default_propfind_finish; 66 default_backend.propfind_finish = default_propfind_finish;
67 default_backend.proppatch_do = default_proppatch_do; 67 default_backend.proppatch_do = default_proppatch_do;
68 default_backend.proppatch_finish = default_proppatch_finish; 68 default_backend.proppatch_finish = default_proppatch_finish;
69 default_backend.opt_mkcol = NULL;
70 default_backend.opt_delete = NULL;
69 default_backend.settings = WS_WEBDAV_PROPFIND_USE_VFS; 71 default_backend.settings = WS_WEBDAV_PROPFIND_USE_VFS;
70 } 72 }
71 73
72 int webdav_init(pblock *pb, Session *sn, Request *rq) { 74 int webdav_init(pblock *pb, Session *sn, Request *rq) {
73 init_default_backend(); 75 init_default_backend();
442 444
443 return ret; 445 return ret;
444 } 446 }
445 447
446 int webdav_mkcol(pblock *pb, Session *sn, Request *rq) { 448 int webdav_mkcol(pblock *pb, Session *sn, Request *rq) {
447 return REQ_ABORTED; 449 UcxBuffer *reqbuf;
450 VFSContext *vfs;
451 char *path;
452
453 if(webdav_init_vfs_op(sn, rq, &reqbuf, &vfs, &path)) {
454 return REQ_ABORTED;
455 }
456
457 int ret = REQ_PROCEED;
458 if(vfs_mkdir(vfs, path)) {
459 protocol_status(sn, rq, util_errno2status(vfs->vfs_errno), NULL);
460 return REQ_ABORTED;
461 }
462
463 protocol_status(sn, rq, 201, NULL);
464
465 // cleanup and return
466 if(reqbuf) {
467 ucx_buffer_free(reqbuf);
468 }
469 return ret;
448 } 470 }
449 471
450 int webdav_post(pblock *pb, Session *sn, Request *rq) { 472 int webdav_post(pblock *pb, Session *sn, Request *rq) {
451 return REQ_ABORTED; 473 return REQ_ABORTED;
452 } 474 }
453 475
476 static int webdav_delete_collection(
477 Session *sn,
478 Request *rq,
479 VFSContext *vfs,
480 const char *path)
481 {
482
483 }
484
454 int webdav_delete(pblock *pb, Session *sn, Request *rq) { 485 int webdav_delete(pblock *pb, Session *sn, Request *rq) {
455 return REQ_ABORTED; 486 UcxBuffer *reqbuf;
487 VFSContext *vfs;
488 char *path;
489
490 if(webdav_init_vfs_op(sn, rq, &reqbuf, &vfs, &path)) {
491 return REQ_ABORTED;
492 }
493
494 int ret = REQ_PROCEED;
495
496 // TODO
497
498 if(ret == REQ_PROCEED) {
499 protocol_status(sn, rq, 200, NULL);
500 }
501
502 // cleanup and return
503 if(reqbuf) {
504 ucx_buffer_free(reqbuf);
505 }
506 return ret;
456 } 507 }
457 508
458 int webdav_put(pblock *pb, Session *sn, Request *rq) { 509 int webdav_put(pblock *pb, Session *sn, Request *rq) {
459 return REQ_ABORTED; 510 return REQ_ABORTED;
460 } 511 }
481 532
482 int webdav_acl(pblock *pb, Session *sn, Request *rq) { 533 int webdav_acl(pblock *pb, Session *sn, Request *rq) {
483 return REQ_ABORTED; 534 return REQ_ABORTED;
484 } 535 }
485 536
537
538 int webdav_init_vfs_op(
539 Session *sn,
540 Request *rq,
541 UcxBuffer **out_reqbuf,
542 VFSContext **out_vfs,
543 char **out_path)
544 {
545 *out_reqbuf = NULL;
546 *out_vfs = NULL;
547 *out_path = NULL;
548
549 // create VFS context
550 VFSContext *vfs = vfs_request_context(sn, rq);
551 if(!vfs) {
552 return REQ_ABORTED;
553 }
554
555 // read request body, if it exists
556 char *expect = pblock_findkeyval(pb_key_expect, rq->headers);
557 if(expect) {
558 if(!strcasecmp(expect, "100-continue")) {
559 if(http_send_continue(sn)) {
560 return REQ_ABORTED;
561 }
562 }
563 }
564
565 UcxBuffer *reqbody = NULL;
566 if(sn->inbuf) {
567 reqbody = rqbody2buffer(sn, rq);
568 if(!reqbody) {
569 return REQ_ABORTED;
570 }
571 }
572
573 // requested uri and path
574 char *path = pblock_findkeyval(pb_key_path, rq->vars);
575
576 *out_reqbuf = reqbody;
577 *out_vfs = vfs;
578 *out_path = path;
579
580 return REQ_PROCEED;
581 }
486 582
487 /* ------------------------ default webdav backend ------------------------ */ 583 /* ------------------------ default webdav backend ------------------------ */
488 584
489 int default_propfind_init( 585 int default_propfind_init(
490 WebdavPropfindRequest *rq, 586 WebdavPropfindRequest *rq,

mercurial