** dav_inherit_locks: When a resource or collection is added to a collection, ** locks on the collection should be inherited to the resource/collection. ** (MOVE, MKCOL, etc) Here we propagate any direct or indirect locks from ** parent of resource to resource and below. */
| 586 | ** parent of resource to resource and below. |
| 587 | */ |
| 588 | static dav_error * dav_inherit_locks(request_rec *r, dav_lockdb *lockdb, |
| 589 | const dav_resource *resource, |
| 590 | int use_parent) |
| 591 | { |
| 592 | dav_error *err; |
| 593 | const dav_resource *which_resource; |
| 594 | dav_lock *locks; |
| 595 | dav_lock *scan; |
| 596 | dav_lock *prev; |
| 597 | dav_walker_ctx ctx = { { 0 } }; |
| 598 | const dav_hooks_repository *repos_hooks = resource->hooks; |
| 599 | dav_response *multi_status; |
| 600 | |
| 601 | if (use_parent) { |
| 602 | dav_resource *parent; |
| 603 | if ((err = (*repos_hooks->get_parent_resource)(resource, |
| 604 | &parent)) != NULL) { |
| 605 | /* ### add a higher-level desc? */ |
| 606 | return err; |
| 607 | } |
| 608 | if (parent == NULL) { |
| 609 | /* ### map result to something nice; log an error */ |
| 610 | return dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0, 0, |
| 611 | "Could not fetch parent resource. Unable to " |
| 612 | "inherit locks from the parent and apply " |
| 613 | "them to this resource."); |
| 614 | } |
| 615 | which_resource = parent; |
| 616 | } |
| 617 | else { |
| 618 | which_resource = resource; |
| 619 | } |
| 620 | |
| 621 | if ((err = (*lockdb->hooks->get_locks)(lockdb, which_resource, |
| 622 | DAV_GETLOCKS_PARTIAL, |
| 623 | &locks)) != NULL) { |
| 624 | /* ### maybe add a higher-level desc */ |
| 625 | return err; |
| 626 | } |
| 627 | |
| 628 | if (locks == NULL) { |
| 629 | /* No locks to propagate, just return */ |
| 630 | return NULL; |
| 631 | } |
| 632 | |
| 633 | /* |
| 634 | ** (1) Copy all indirect locks from our parent; |
| 635 | ** (2) Create indirect locks for the depth infinity, direct locks |
| 636 | ** in our parent. |
| 637 | ** |
| 638 | ** The append_locks call in the walker callback will do the indirect |
| 639 | ** conversion, but we need to remove any direct locks that are NOT |
| 640 | ** depth "infinity". |
| 641 | */ |
| 642 | for (scan = locks, prev = NULL; |
| 643 | scan != NULL; |
| 644 | prev = scan, scan = scan->next) { |
| 645 |
no test coverage detected