Ejemplo n.º 1
0
 /**
  * Handles a POST request
  * @param DAV_Resource $resource
  * @return void
  * @throws DAV_Status
  */
 public function handle($resource)
 {
     $resource->assertLock();
     $headers = array();
     try {
         ob_start();
         $entity = $resource->method_POST($headers);
     } catch (DAV_Status $e) {
         ob_end_clean();
         throw $e;
     }
     if ($length = ob_get_length()) {
         $headers['Content-Length'] = $length;
         DAV::header($headers);
         ob_end_flush();
         return;
     } else {
         ob_end_clean();
     }
     if (is_string($entity)) {
         $headers['Content-Length'] = strlen($entity);
         DAV::header($headers);
         echo $entity;
         return;
     }
     DAV::header($headers);
 }
Ejemplo n.º 2
0
 /**
  * Deletes $resource.
  * Callers must check DAV_Multistatus::active() afterwards.
  * @param DAV_Resource $resource
  * @throws DAV_Status
  */
 public static function delete($resource)
 {
     $resource->assertLock();
     $resource->assertMemberLocks();
     $parent = $resource->collection();
     if (!$parent) {
         throw new DAV_Status(DAV::HTTP_FORBIDDEN);
     }
     $parent->assertLock();
     self::delete_member($parent, $resource);
 }
Ejemplo n.º 3
0
 /**
  * Handle the PROPPATCH request
  *
  * @param DAV_Resource $resource
  * @return void
  * @throws DAV_Status
  */
 protected function handle($resource)
 {
     $resource->assertLock();
     if (empty($this->props)) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'No properties found in request body.');
     }
     $priv_write = $resource->property_priv_write(array_keys($this->props));
     $errors = array();
     foreach ($this->props as $name => $value) {
         try {
             if (@DAV::$PROTECTED_PROPERTIES[$name]) {
                 throw new DAV_Status(DAV::HTTP_FORBIDDEN, DAV::COND_CANNOT_MODIFY_PROTECTED_PROPERTY);
             }
             if (!@$priv_write[$name]) {
                 throw DAV::forbidden();
             }
             $resource->method_PROPPATCH($name, $value);
         } catch (DAV_Status $e) {
             $errors[$name] = $e;
         }
     }
     $response = new DAV_Element_response(DAV::getPath());
     if (empty($errors)) {
         try {
             $resource->storeProperties();
         } catch (DAV_Status $e) {
             foreach (array_keys($this->props) as $propname) {
                 $errors[$propname] = $e;
             }
         }
     }
     if (empty($errors)) {
         foreach (array_keys($this->props) as $propname) {
             $response->setStatus($propname, DAV_Status::$OK);
         }
     } else {
         $failed_dependency = new DAV_Status(DAV::HTTP_FAILED_DEPENDENCY);
         foreach (array_keys($this->props) as $propname) {
             if (!isset($errors[$propname])) {
                 $errors[$propname] = $failed_dependency;
             }
         }
         foreach ($errors as $propname => $status) {
             $response->setStatus($propname, $status);
         }
     }
     DAV_Multistatus::inst()->addResponse($response);
     DAV_Multistatus::inst()->close();
 }
Ejemplo n.º 4
0
 /**
  * Determines whether the copy request is valid and if so, copies the resources
  * 
  * @param DAV_Resource $resource
  * @return void
  * @throws DAV_Status
  */
 protected function handle($resource)
 {
     $destination = $this->destination();
     if ($resource instanceof DAV_Collection) {
         $destination = DAV::slashify($destination);
     } else {
         // The next line is here to make the litmus test succeed. The author of
         // litmus had eir own doubts wether this is actually desirable behaviour,
         // but chose to require this behaviour anyway:
         $destination = DAV::unslashify($destination);
     }
     // Can't move the root collection:
     if ($this instanceof DAV_Request_MOVE && '/' === DAV::getPath()) {
         throw new DAV_Status(DAV::HTTP_FORBIDDEN);
     }
     // Assert proper Depth: header value:
     if (DAV::DEPTH_1 === $this->depth() or $this instanceof DAV_Request_MOVE && DAV::DEPTH_INF !== $this->depth()) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'Illegal value for Depth: header.');
     }
     // Check: Can't move a collection to one of its members.
     if ($this instanceof DAV_Request_MOVE && '/' === substr(DAV::getPath(), -1) && 0 === strpos($destination, DAV::getPath())) {
         throw new DAV_Status(DAV::HTTP_FORBIDDEN, "Can't move a collection to itself or one of its members.");
     }
     $resourceCollection = $resource->collection();
     if ($this instanceof DAV_Request_MOVE) {
         $resourceCollection->assertLock();
         $resource->assertLock();
         $resource->assertMemberLocks();
     }
     if ('/' !== $destination[0]) {
         // Copy to an external URI?
         $isCreated = $resource->method_COPY_external($destination, $this->overwrite());
         if ($this instanceof DAV_Request_MOVE && !DAV_Multistatus::active()) {
             DAV_Request_DELETE::delete($resource);
         }
         if (DAV_Multistatus::active()) {
             DAV_Multistatus::inst()->close();
         } elseif ($isCreated) {
             DAV::redirect(DAV::HTTP_CREATED, $destination);
         } else {
             DAV::header(array('status' => DAV::HTTP_NO_CONTENT));
         }
         return;
     }
     // Check: Won't move a resource to one of its parents.
     if (0 === strpos(DAV::slashify(DAV::getPath()), DAV::slashify($destination))) {
         throw new DAV_Status(DAV::HTTP_NOT_IMPLEMENTED, "Won't move or copy a resource to one of its parents.");
     }
     $destinationResource = DAV::$REGISTRY->resource($destination);
     $destinationCollection = DAV::$REGISTRY->resource(dirname($destination));
     if (!$destinationCollection) {
         throw new DAV_Status(DAV::HTTP_CONFLICT, 'Unable to COPY to unexisting destination collection');
     }
     if ($destinationResource) {
         if (!$this->overwrite()) {
             throw new DAV_Status(DAV::HTTP_PRECONDITION_FAILED);
         } else {
             $destinationResource->assertLock();
         }
     } else {
         $destinationCollection->assertLock();
     }
     if ($this instanceof DAV_Request_MOVE) {
         if (DAV::$LOCKPROVIDER) {
             foreach (DAV::$LOCKPROVIDER->memberLocks(DAV::getPath()) as $lock) {
                 DAV::$LOCKPROVIDER->unlock($lock->lockroot);
             }
             if ($lock = DAV::$LOCKPROVIDER->getlock(DAV::getPath())) {
                 DAV::$LOCKPROVIDER->unlock($lock->lockroot);
             }
         }
         $resourceCollection->method_MOVE(basename($resource->path), $destination);
     } else {
         $this->copy_recursively($resource, $destination);
     }
     #<<<<<<<<
     #// This version always returns a 207 Multistatus wrapper:
     #if (!DAV_Multistatus::active())
     #  if ( $destinationResource )
     #    DAV_Multistatus::inst()->addStatus(
     #      $resource->path,
     #      new DAV_Status( DAV::HTTP_NO_CONTENT )
     #    );
     #  else
     #    DAV_Multistatus::inst()->addStatus(
     #      $resource->path,
     #      new DAV_Status(
     #        DAV::HTTP_CREATED, DAV::path2uri($destination)
     #      )
     #    );
     #DAV_Multistatus::inst()->close();
     #========
     if (DAV_Multistatus::active()) {
         DAV_Multistatus::inst()->close();
     } elseif ($destinationResource) {
         DAV::header(array('status' => DAV::HTTP_NO_CONTENT));
     } else {
         DAV::redirect(DAV::HTTP_CREATED, $destination);
     }
     #>>>>>>>>
 }