src/server/webdav/webdav.c

branch
webdav
changeset 247
1df803e06076
parent 246
155bdef7fe7e
child 249
3b302093945c
equal deleted inserted replaced
246:155bdef7fe7e 247:1df803e06076
459 459
460 int webdav_post(pblock *pb, Session *sn, Request *rq) { 460 int webdav_post(pblock *pb, Session *sn, Request *rq) {
461 return REQ_ABORTED; 461 return REQ_ABORTED;
462 } 462 }
463 463
464 typedef struct DeleteFile {
465 char *path;
466 struct stat s;
467 } DeleteFile;
468
469 typedef struct DeleteLists {
470 UcxAllocator *a;
471 UcxList *dirs_begin;
472 UcxList *dirs_end;
473 UcxList *files_begin;
474 UcxList *files_end;
475 } DeleteOp;
476
477 static int deletelist_add(
478 VFSContext *vfs,
479 const char *href,
480 const char *path,
481 VFSDir *parent,
482 struct stat *s,
483 void *userdata)
484 {
485 DeleteOp *op = userdata;
486
487 // create object for this file
488 DeleteFile *file = almalloc(op->a, sizeof(DeleteFile));
489 if(!file) {
490 return 1;
491 }
492 file->path = sstrdup_a(op->a, sstr((char*)path)).ptr;
493 if(!file->path) {
494 return 1;
495 }
496 file->s = *s;
497
498 // determine which list to use
499 UcxList **begin;
500 UcxList **end;
501 if(S_ISDIR(s->st_mode)) {
502 begin = &op->dirs_begin;
503 end = &op->dirs_end;
504 } else {
505 begin = &op->files_begin;
506 end = &op->files_end;
507 }
508
509 // add file to list
510 UcxList *elm = ucx_list_append_a(op->a, NULL, file);
511 if(!elm) {
512 alfree(op->a, file->path); // at least do some cleanup, although it
513 alfree(op->a, file); // isn't really necessary
514 return 1;
515 }
516 if(*begin == NULL) {
517 *begin = elm;
518 *end = elm;
519 } else {
520 ucx_list_concat(*end, elm);
521 *end = elm;
522 }
523
524 return 0;
525 }
526
464 static int webdav_delete_collection(WebdavVFSOperation *op) 527 static int webdav_delete_collection(WebdavVFSOperation *op)
465 { 528 {
466 // TODO 529 DeleteOp del;
530 ZERO(&del, sizeof(DeleteOp));
531 del.a = session_get_allocator(op->sn);
532
533 // get a list of all files
534 if(webdav_op_iterate_children(op->vfs, -1, NULL, op->path,
535 deletelist_add, &del))
536 {
537 return 1;
538 }
539
540 // delete files first
541 UCX_FOREACH(elm, del.files_begin) {
542 DeleteFile *file = elm->data;
543 WebdavVFSOperation sub = webdav_vfs_sub_op(op, file->path, &file->s);
544 if(webdav_vfs_op_do(&sub, WEBDAV_VFS_DELETE)) {
545 return 1;
546 }
547 }
548
549 // delete directories, reverse order
550 for(UcxList *elm=del.dirs_end;elm;elm=elm->prev) {
551 DeleteFile *file = elm->data;
552 WebdavVFSOperation sub = webdav_vfs_sub_op(op, file->path, &file->s);
553 if(webdav_vfs_op_do(&sub, WEBDAV_VFS_DELETE)) {
554 return 1;
555 }
556 }
557
558 return 0;
467 } 559 }
468 560
469 int webdav_delete(pblock *pb, Session *sn, Request *rq) { 561 int webdav_delete(pblock *pb, Session *sn, Request *rq) {
470 WebdavVFSOperation *op = webdav_vfs_op(sn, rq, rq->davCollection, TRUE); 562 WebdavVFSOperation *op = webdav_vfs_op(sn, rq, rq->davCollection, TRUE);
471 if(!op) { 563 if(!op) {

mercurial