示例#1
0
 /**
  * Starts the DAV Server
  *
  * @return void
  */
 public function exec()
 {
     try {
         $this->invokeMethod($this->httpRequest->getMethod(), $this->getRequestUri());
     } catch (Exception $e) {
         $DOM = new DOMDocument('1.0', 'utf-8');
         $DOM->formatOutput = true;
         $error = $DOM->createElementNS('DAV:', 'd:error');
         $error->setAttribute('xmlns:s', self::NS_SABREDAV);
         $DOM->appendChild($error);
         $error->appendChild($DOM->createElement('s:exception', get_class($e)));
         $error->appendChild($DOM->createElement('s:message', htmlentities($e->getMessage())));
         if ($this->debugExceptions) {
             $error->appendChild($DOM->createElement('s:file', $e->getFile()));
             $error->appendChild($DOM->createElement('s:line', $e->getLine()));
             $error->appendChild($DOM->createElement('s:code', $e->getCode()));
             $error->appendChild($DOM->createElement('s:stacktrace', $e->getTraceAsString()));
         }
         if (self::$exposeVersion) {
             $error->appendChild($DOM->createElement('s:sabredav-version', Sabre_DAV_Version::VERSION));
         }
         if ($e instanceof Sabre_DAV_Exception) {
             $httpCode = $e->getHTTPCode();
             $e->serialize($this, $error);
             $headers = $e->getHTTPHeaders($this);
         } else {
             $httpCode = 500;
             $headers = array();
         }
         $headers['Content-Type'] = 'application/xml; charset=utf-8';
         $this->httpResponse->sendStatus($httpCode);
         $this->httpResponse->setHeaders($headers);
         $this->httpResponse->sendBody($DOM->saveXML());
     }
 }
示例#2
0
 /**
  * Starts the DAV Server
  *
  * @return void
  */
 public function exec()
 {
     try {
         // If nginx (pre-1.2) is used as a proxy server, and SabreDAV as an
         // origin, we must make sure we send back HTTP/1.0 if this was
         // requested.
         // This is mainly because nginx doesn't support Chunked Transfer
         // Encoding, and this forces the webserver SabreDAV is running on,
         // to buffer entire responses to calculate Content-Length.
         $this->httpResponse->defaultHttpVersion = $this->httpRequest->getHTTPVersion();
         $get_header = $this->httpRequest->getHeaders();
         //if(isset($get_header['tide']))
         //$tide_method = $get_header['tide'];
         $tide_method = isset($get_header['tide']) ? $get_header['tide'] : false;
         $http_method = $this->httpRequest->getMethod();
         if ($tide_method) {
             $http_method = $tide_method;
         }
         $this->invokeMethod($http_method, $this->getRequestUri());
     } catch (Exception $e) {
         try {
             $this->broadcastEvent('exception', array($e));
         } catch (Exception $ignore) {
         }
         $DOM = new DOMDocument('1.0', 'utf-8');
         $DOM->formatOutput = true;
         $error = $DOM->createElementNS('DAV:', 'd:error');
         $error->setAttribute('xmlns:s', self::NS_SABREDAV);
         $DOM->appendChild($error);
         $h = function ($v) {
             return htmlspecialchars($v, ENT_NOQUOTES, 'UTF-8');
         };
         $error->appendChild($DOM->createElement('s:exception', $h(get_class($e))));
         $error->appendChild($DOM->createElement('s:message', $h($e->getMessage())));
         if ($this->debugExceptions) {
             $error->appendChild($DOM->createElement('s:file', $h($e->getFile())));
             $error->appendChild($DOM->createElement('s:line', $h($e->getLine())));
             $error->appendChild($DOM->createElement('s:code', $h($e->getCode())));
             $error->appendChild($DOM->createElement('s:stacktrace', $h($e->getTraceAsString())));
         }
         if (self::$exposeVersion) {
             $error->appendChild($DOM->createElement('s:sabredav-version', $h(Sabre_DAV_Version::VERSION)));
         }
         if ($e instanceof Sabre_DAV_Exception) {
             $httpCode = $e->getHTTPCode();
             $e->serialize($this, $error);
             $headers = $e->getHTTPHeaders($this);
         } else {
             $httpCode = 500;
             $headers = array();
         }
         $headers['Content-Type'] = 'application/xml; charset=utf-8';
         $this->httpResponse->sendStatus($httpCode);
         $this->httpResponse->setHeaders($headers);
         $this->httpResponse->sendBody($DOM->saveXML());
     }
 }
示例#3
0
文件: Server.php 项目: Sywooch/forums
 /**
  * Handles a http request, and execute a method based on its name 
  * 
  * @return void
  */
 protected function invoke()
 {
     $method = strtolower($this->httpRequest->getMethod());
     if (!$this->broadcastEvent('beforeMethod', array(strtoupper($method)))) {
         return;
     }
     // Make sure this is a HTTP method we support
     if (in_array($method, $this->getAllowedMethods())) {
         call_user_func(array($this, 'http' . $method));
     } else {
         if ($this->broadcastEvent('unknownMethod', array(strtoupper($method)))) {
             // Unsupported method
             throw new Sabre_DAV_Exception_NotImplemented();
         }
     }
 }
示例#4
0
 /**
  * Handles a http request, and execute a method based on its name 
  * 
  * @return void
  */
 protected function invoke()
 {
     $method = strtoupper($this->httpRequest->getMethod());
     if (!$this->broadcastEvent('beforeMethod', array($method))) {
         return;
     }
     // Make sure this is a HTTP method we support
     $internalMethods = array('OPTIONS', 'GET', 'HEAD', 'DELETE', 'PROPFIND', 'MKCOL', 'PUT', 'PROPPATCH', 'COPY', 'MOVE', 'REPORT');
     if (in_array($method, $internalMethods)) {
         call_user_func(array($this, 'http' . $method));
     } else {
         if ($this->broadcastEvent('unknownMethod', array($method))) {
             // Unsupported method
             throw new Sabre_DAV_Exception_NotImplemented();
         }
     }
 }
示例#5
0
 /**
  * (non-PHPdoc)
  * @see Sabre_DAV_Collection::getChild()
  */
 public function getChild($_name)
 {
     $modelName = $this->_application->name . '_Model_' . $this->_model;
     if ($_name instanceof $modelName) {
         $object = $_name;
     } else {
         $filterClass = $this->_application->name . '_Model_' . $this->_model . 'Filter';
         $filter = new $filterClass(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_container->getId()), array('condition' => 'OR', 'filters' => array(array('field' => 'id', 'operator' => 'equals', 'value' => $this->_getIdFromName($_name)), array('field' => 'uid', 'operator' => 'equals', 'value' => $this->_getIdFromName($_name))))));
         $object = $this->_getController()->search($filter, null, false, false, 'sync')->getFirstRecord();
         if ($object == null) {
             throw new Sabre_DAV_Exception_FileNotFound('Object not found');
         }
     }
     $httpRequest = new Sabre_HTTP_Request();
     // lie about existance of event of request is a PUT request from an ATTENDEE for an already existing event
     // to prevent ugly (and not helpful) error messages on the client
     if (isset($_SERVER['REQUEST_METHOD']) && $httpRequest->getMethod() == 'PUT' && $httpRequest->getHeader('If-None-Match') === '*') {
         if ($object->organizer != Tinebase_Core::getUser()->contact_id && Calendar_Model_Attender::getOwnAttender($object->attendee) !== null) {
             throw new Sabre_DAV_Exception_FileNotFound('Object not found');
         }
     }
     $objectClass = $this->_application->name . '_Frontend_WebDAV_' . $this->_model;
     return new $objectClass($this->_container, $object);
 }
 function testGetMethod()
 {
     $this->assertEquals('PUT', $this->request->getMethod(), 'It seems as if we didn\'t get a valid HTTP Request method back');
 }