/**
  * Unserializes the DOMElement back into a Property class.
  *
  * @param \DOMElement $node
  * @return Property_SupportedCalendarComponentSet
  */
 static function unserialize(\DOMElement $node)
 {
     $components = array();
     foreach ($node->childNodes as $childNode) {
         if (DAV\XMLUtil::toClarkNotation($childNode) === '{' . CalDAV\Plugin::NS_CALDAV . '}comp') {
             $components[] = $childNode->getAttribute('name');
         }
     }
     return new self($components);
 }
 /**
  * Unserializes this property from a DOM Element
  *
  * This method returns an instance of this class.
  * It will only decode {DAV:}href values.
  *
  * @param \DOMElement $dom
  * @return DAV\Property\HrefList
  */
 static function unserialize(\DOMElement $dom)
 {
     $hrefs = array();
     foreach ($dom->childNodes as $child) {
         if (DAV\XMLUtil::toClarkNotation($child) === '{DAV:}href') {
             $hrefs[] = $child->textContent;
         }
     }
     return new self($hrefs, false);
 }
 /**
  * Unserializes the DOMElement back into a Property class.
  *
  * @param \DOMElement $node
  * @return ScheduleCalendarTransp
  */
 static function unserialize(\DOMElement $node)
 {
     $value = null;
     foreach ($node->childNodes as $childNode) {
         switch (DAV\XMLUtil::toClarkNotation($childNode)) {
             case '{' . CalDAV\Plugin::NS_CALDAV . '}opaque':
                 $value = self::OPAQUE;
                 break;
             case '{' . CalDAV\Plugin::NS_CALDAV . '}transparent':
                 $value = self::TRANSPARENT;
                 break;
         }
     }
     if (is_null($value)) {
         return null;
     }
     return new self($value);
 }
 /**
  * Parses the request.
  *
  * @return void
  */
 public function parse()
 {
     $filterNode = null;
     $filter = $this->xpath->query('/cal:calendar-query/cal:filter');
     if ($filter->length !== 1) {
         throw new \SabreForRainLoop\DAV\Exception\BadRequest('Only one filter element is allowed');
     }
     $compFilters = $this->parseCompFilters($filter->item(0));
     if (count($compFilters) !== 1) {
         throw new \SabreForRainLoop\DAV\Exception\BadRequest('There must be exactly 1 top-level comp-filter.');
     }
     $this->filters = $compFilters[0];
     $this->requestedProperties = array_keys(\SabreForRainLoop\DAV\XMLUtil::parseProperties($this->dom->firstChild));
     $expand = $this->xpath->query('/cal:calendar-query/dav:prop/cal:calendar-data/cal:expand');
     if ($expand->length > 0) {
         $this->expand = $this->parseExpand($expand->item(0));
     }
 }
Example #5
0
 /**
  * This method is responsible for parsing the request and generating the
  * response for the CALDAV:free-busy-query REPORT.
  *
  * @param \DOMNode $dom
  * @return void
  */
 protected function freeBusyQueryReport(\DOMNode $dom)
 {
     $start = null;
     $end = null;
     foreach ($dom->firstChild->childNodes as $childNode) {
         $clark = DAV\XMLUtil::toClarkNotation($childNode);
         if ($clark == '{' . self::NS_CALDAV . '}time-range') {
             $start = $childNode->getAttribute('start');
             $end = $childNode->getAttribute('end');
             break;
         }
     }
     if ($start) {
         $start = VObject\DateTimeParser::parseDateTime($start);
     }
     if ($end) {
         $end = VObject\DateTimeParser::parseDateTime($end);
     }
     if (!$start && !$end) {
         throw new DAV\Exception\BadRequest('The freebusy report must have a time-range filter');
     }
     $acl = $this->server->getPlugin('acl');
     if (!$acl) {
         throw new DAV\Exception('The ACL plugin must be loaded for free-busy queries to work');
     }
     $uri = $this->server->getRequestUri();
     $acl->checkPrivileges($uri, '{' . self::NS_CALDAV . '}read-free-busy');
     $calendar = $this->server->tree->getNodeForPath($uri);
     if (!$calendar instanceof ICalendar) {
         throw new DAV\Exception\NotImplemented('The free-busy-query REPORT is only implemented on calendars');
     }
     // Doing a calendar-query first, to make sure we get the most
     // performance.
     $urls = $calendar->calendarQuery(array('name' => 'VCALENDAR', 'comp-filters' => array(array('name' => 'VEVENT', 'comp-filters' => array(), 'prop-filters' => array(), 'is-not-defined' => false, 'time-range' => array('start' => $start, 'end' => $end))), 'prop-filters' => array(), 'is-not-defined' => false, 'time-range' => null));
     $objects = array_map(function ($url) use($calendar) {
         $obj = $calendar->getChild($url)->get();
         return $obj;
     }, $urls);
     $generator = new VObject\FreeBusyGenerator();
     $generator->setObjects($objects);
     $generator->setTimeRange($start, $end);
     $result = $generator->getResult();
     $result = $result->serialize();
     $this->server->httpResponse->sendStatus(200);
     $this->server->httpResponse->setHeader('Content-Type', 'text/calendar');
     $this->server->httpResponse->setHeader('Content-Length', strlen($result));
     $this->server->httpResponse->sendBody($result);
 }
Example #6
0
 /**
  * parsePrincipalPropertySearchReportRequest
  *
  * This method parses the request body from a
  * {DAV:}principal-property-search report.
  *
  * This method returns an array with two elements:
  *  1. an array with properties to search on, and their values
  *  2. a list of propertyvalues that should be returned for the request.
  *
  * @param \DOMDocument $dom
  * @return array
  */
 protected function parsePrincipalPropertySearchReportRequest($dom)
 {
     $httpDepth = $this->server->getHTTPDepth(0);
     if ($httpDepth !== 0) {
         throw new DAV\Exception\BadRequest('This report is only defined when Depth: 0');
     }
     $searchProperties = array();
     $applyToPrincipalCollectionSet = false;
     // Parsing the search request
     foreach ($dom->firstChild->childNodes as $searchNode) {
         if (DAV\XMLUtil::toClarkNotation($searchNode) == '{DAV:}apply-to-principal-collection-set') {
             $applyToPrincipalCollectionSet = true;
         }
         if (DAV\XMLUtil::toClarkNotation($searchNode) !== '{DAV:}property-search') {
             continue;
         }
         $propertyName = null;
         $propertyValue = null;
         foreach ($searchNode->childNodes as $childNode) {
             switch (DAV\XMLUtil::toClarkNotation($childNode)) {
                 case '{DAV:}prop':
                     $property = DAV\XMLUtil::parseProperties($searchNode);
                     reset($property);
                     $propertyName = key($property);
                     break;
                 case '{DAV:}match':
                     $propertyValue = $childNode->textContent;
                     break;
             }
         }
         if (is_null($propertyName) || is_null($propertyValue)) {
             throw new DAV\Exception\BadRequest('Invalid search request. propertyname: ' . $propertyName . '. propertvvalue: ' . $propertyValue);
         }
         $searchProperties[$propertyName] = $propertyValue;
     }
     return array($searchProperties, array_keys(DAV\XMLUtil::parseProperties($dom->firstChild)), $applyToPrincipalCollectionSet);
 }
 /**
  * Unserializes a DOM element into a ResourceType property.
  *
  * @param \DOMElement $dom
  * @return DAV\Property\ResourceType
  */
 public static function unserialize(\DOMElement $dom)
 {
     $value = array();
     foreach ($dom->childNodes as $child) {
         $value[] = DAV\XMLUtil::toClarkNotation($child);
     }
     return new self($value);
 }
Example #8
0
 /**
  * Unserializes the {DAV:}acl xml element.
  *
  * @param \DOMElement $dom
  * @return Acl
  */
 public static function unserialize(\DOMElement $dom)
 {
     $privileges = array();
     $xaces = $dom->getElementsByTagNameNS('urn:DAV', 'ace');
     for ($ii = 0; $ii < $xaces->length; $ii++) {
         $xace = $xaces->item($ii);
         $principal = $xace->getElementsByTagNameNS('urn:DAV', 'principal');
         if ($principal->length !== 1) {
             throw new DAV\Exception\BadRequest('Each {DAV:}ace element must have one {DAV:}principal element');
         }
         $principal = Principal::unserialize($principal->item(0));
         switch ($principal->getType()) {
             case Principal::HREF:
                 $principal = $principal->getHref();
                 break;
             case Principal::AUTHENTICATED:
                 $principal = '{DAV:}authenticated';
                 break;
             case Principal::UNAUTHENTICATED:
                 $principal = '{DAV:}unauthenticated';
                 break;
             case Principal::ALL:
                 $principal = '{DAV:}all';
                 break;
         }
         $protected = false;
         if ($xace->getElementsByTagNameNS('urn:DAV', 'protected')->length > 0) {
             $protected = true;
         }
         $grants = $xace->getElementsByTagNameNS('urn:DAV', 'grant');
         if ($grants->length < 1) {
             throw new DAV\Exception\NotImplemented('Every {DAV:}ace element must have a {DAV:}grant element. {DAV:}deny is not yet supported');
         }
         $grant = $grants->item(0);
         $xprivs = $grant->getElementsByTagNameNS('urn:DAV', 'privilege');
         for ($jj = 0; $jj < $xprivs->length; $jj++) {
             $xpriv = $xprivs->item($jj);
             $privilegeName = null;
             for ($kk = 0; $kk < $xpriv->childNodes->length; $kk++) {
                 $childNode = $xpriv->childNodes->item($kk);
                 if ($t = DAV\XMLUtil::toClarkNotation($childNode)) {
                     $privilegeName = $t;
                     break;
                 }
             }
             if (is_null($privilegeName)) {
                 throw new DAV\Exception\BadRequest('{DAV:}privilege elements must have a privilege element contained within them.');
             }
             $privileges[] = array('principal' => $principal, 'protected' => $protected, 'privilege' => $privilegeName);
         }
     }
     return new self($privileges);
 }
 /**
  * Unserializes the {DAV:}current-user-privilege-set element.
  *
  * @param DOMElement $node
  * @return CurrentUserPrivilegeSet
  */
 public static function unserialize(\DOMElement $node)
 {
     $result = array();
     $xprivs = $node->getElementsByTagNameNS('urn:DAV', 'privilege');
     for ($jj = 0; $jj < $xprivs->length; $jj++) {
         $xpriv = $xprivs->item($jj);
         $privilegeName = null;
         for ($kk = 0; $kk < $xpriv->childNodes->length; $kk++) {
             $childNode = $xpriv->childNodes->item($kk);
             if ($t = DAV\XMLUtil::toClarkNotation($childNode)) {
                 $privilegeName = $t;
                 break;
             }
         }
         $result[] = $privilegeName;
     }
     return new self($result);
 }
Example #10
0
 /**
  * Unserializes this property from a DOM Element
  *
  * This method returns an instance of this class.
  * It will only decode {DAV:}href values. For non-compatible elements null will be returned.
  *
  * @param \DOMElement $dom
  * @return DAV\Property\Href
  */
 static function unserialize(\DOMElement $dom)
 {
     if ($dom->firstChild && DAV\XMLUtil::toClarkNotation($dom->firstChild) === '{DAV:}href') {
         return new self($dom->firstChild->textContent, false);
     }
 }
Example #11
0
 /**
  * Deserializes a DOM element into a property object.
  *
  * @param \DOMElement $dom
  * @return Principal
  */
 public static function unserialize(\DOMElement $dom)
 {
     $parent = $dom->firstChild;
     while (!DAV\XMLUtil::toClarkNotation($parent)) {
         $parent = $parent->nextSibling;
     }
     switch (DAV\XMLUtil::toClarkNotation($parent)) {
         case '{DAV:}unauthenticated':
             return new self(self::UNAUTHENTICATED);
         case '{DAV:}authenticated':
             return new self(self::AUTHENTICATED);
         case '{DAV:}href':
             return new self(self::HREF, $parent->textContent);
         case '{DAV:}all':
             return new self(self::ALL);
         default:
             throw new DAV\Exception\BadRequest('Unexpected element (' . DAV\XMLUtil::toClarkNotation($parent) . '). Could not deserialize');
     }
 }
Example #12
0
 /**
  * This function handles the addressbook-multiget REPORT.
  *
  * This report is used by the client to fetch the content of a series
  * of urls. Effectively avoiding a lot of redundant requests.
  *
  * @param \DOMNode $dom
  * @return void
  */
 public function addressbookMultiGetReport($dom)
 {
     $properties = array_keys(DAV\XMLUtil::parseProperties($dom->firstChild));
     $hrefElems = $dom->getElementsByTagNameNS('urn:DAV', 'href');
     $propertyList = array();
     foreach ($hrefElems as $elem) {
         $uri = $this->server->calculateUri($elem->nodeValue);
         list($propertyList[]) = $this->server->getPropertiesForPath($uri, $properties);
     }
     $prefer = $this->server->getHTTPPRefer();
     $this->server->httpResponse->sendStatus(207);
     $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
     $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer');
     $this->server->httpResponse->sendBody($this->server->generateMultiStatus($propertyList, $prefer['return-minimal']));
 }
 /**
  * Parses the request.
  *
  * @return void
  */
 public function parse()
 {
     $filterNode = null;
     $limit = $this->xpath->evaluate('number(/card:addressbook-query/card:limit/card:nresults)');
     if (is_nan($limit)) {
         $limit = null;
     }
     $filter = $this->xpath->query('/card:addressbook-query/card:filter');
     // According to the CardDAV spec there needs to be exactly 1 filter
     // element. However, KDE 4.8.2 contains a bug that will encode 0 filter
     // elements, so this is a workaround for that.
     //
     // See: https://bugs.kde.org/show_bug.cgi?id=300047
     if ($filter->length === 0) {
         $test = null;
         $filter = null;
     } elseif ($filter->length === 1) {
         $filter = $filter->item(0);
         $test = $this->xpath->evaluate('string(@test)', $filter);
     } else {
         throw new DAV\Exception\BadRequest('Only one filter element is allowed');
     }
     if (!$test) {
         $test = self::TEST_ANYOF;
     }
     if ($test !== self::TEST_ANYOF && $test !== self::TEST_ALLOF) {
         throw new DAV\Exception\BadRequest('The test attribute must either hold "anyof" or "allof"');
     }
     $propFilters = array();
     $propFilterNodes = $this->xpath->query('card:prop-filter', $filter);
     for ($ii = 0; $ii < $propFilterNodes->length; $ii++) {
         $propFilters[] = $this->parsePropFilterNode($propFilterNodes->item($ii));
     }
     $this->filters = $propFilters;
     $this->limit = $limit;
     $this->requestedProperties = array_keys(DAV\XMLUtil::parseProperties($this->dom->firstChild));
     $this->test = $test;
 }
Example #14
0
 /**
  * This method parses the PROPFIND request and returns its information
  *
  * This will either be a list of properties, or an empty array; in which case
  * an {DAV:}allprop was requested.
  *
  * @param string $body
  * @return array
  */
 public function parsePropFindRequest($body)
 {
     // If the propfind body was empty, it means IE is requesting 'all' properties
     if (!$body) {
         return array();
     }
     $dom = XMLUtil::loadDOMDocument($body);
     $elem = $dom->getElementsByTagNameNS('urn:DAV', 'propfind')->item(0);
     return array_keys(XMLUtil::parseProperties($elem));
 }
 /**
  * This event is triggered when the server didn't know how to handle a
  * certain request.
  *
  * We intercept this to handle POST requests on calendars.
  *
  * @param string $method
  * @param string $uri
  * @return null|bool
  */
 public function unknownMethod($method, $uri)
 {
     if ($method !== 'POST') {
         return;
     }
     // Only handling xml
     $contentType = $this->server->httpRequest->getHeader('Content-Type');
     if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) {
         return;
     }
     // Making sure the node exists
     try {
         $node = $this->server->tree->getNodeForPath($uri);
     } catch (DAV\Exception\NotFound $e) {
         return;
     }
     $requestBody = $this->server->httpRequest->getBody(true);
     // If this request handler could not deal with this POST request, it
     // will return 'null' and other plugins get a chance to handle the
     // request.
     //
     // However, we already requested the full body. This is a problem,
     // because a body can only be read once. This is why we preemptively
     // re-populated the request body with the existing data.
     $this->server->httpRequest->setBody($requestBody);
     $dom = DAV\XMLUtil::loadDOMDocument($requestBody);
     $documentType = DAV\XMLUtil::toClarkNotation($dom->firstChild);
     switch ($documentType) {
         // Dealing with the 'share' document, which modified invitees on a
         // calendar.
         case '{' . Plugin::NS_CALENDARSERVER . '}share':
             // We can only deal with IShareableCalendar objects
             if (!$node instanceof IShareableCalendar) {
                 return;
             }
             // Getting ACL info
             $acl = $this->server->getPlugin('acl');
             // If there's no ACL support, we allow everything
             if ($acl) {
                 $acl->checkPrivileges($uri, '{DAV:}write');
             }
             $mutations = $this->parseShareRequest($dom);
             $node->updateShares($mutations[0], $mutations[1]);
             $this->server->httpResponse->sendStatus(200);
             // Adding this because sending a response body may cause issues,
             // and I wanted some type of indicator the response was handled.
             $this->server->httpResponse->setHeader('X-Sabre-Status', 'everything-went-well');
             // Breaking the event chain
             return false;
             // The invite-reply document is sent when the user replies to an
             // invitation of a calendar share.
         // The invite-reply document is sent when the user replies to an
         // invitation of a calendar share.
         case '{' . Plugin::NS_CALENDARSERVER . '}invite-reply':
             // This only works on the calendar-home-root node.
             if (!$node instanceof UserCalendars) {
                 return;
             }
             // Getting ACL info
             $acl = $this->server->getPlugin('acl');
             // If there's no ACL support, we allow everything
             if ($acl) {
                 $acl->checkPrivileges($uri, '{DAV:}write');
             }
             $message = $this->parseInviteReplyRequest($dom);
             $url = $node->shareReply($message['href'], $message['status'], $message['calendarUri'], $message['inReplyTo'], $message['summary']);
             $this->server->httpResponse->sendStatus(200);
             // Adding this because sending a response body may cause issues,
             // and I wanted some type of indicator the response was handled.
             $this->server->httpResponse->setHeader('X-Sabre-Status', 'everything-went-well');
             if ($url) {
                 $dom = new \DOMDocument('1.0', 'UTF-8');
                 $dom->formatOutput = true;
                 $root = $dom->createElement('cs:shared-as');
                 foreach ($this->server->xmlNamespaces as $namespace => $prefix) {
                     $root->setAttribute('xmlns:' . $prefix, $namespace);
                 }
                 $dom->appendChild($root);
                 $href = new DAV\Property\Href($url);
                 $href->serialize($this->server, $root);
                 $this->server->httpResponse->setHeader('Content-Type', 'application/xml');
                 $this->server->httpResponse->sendBody($dom->saveXML());
             }
             // Breaking the event chain
             return false;
         case '{' . Plugin::NS_CALENDARSERVER . '}publish-calendar':
             // We can only deal with IShareableCalendar objects
             if (!$node instanceof IShareableCalendar) {
                 return;
             }
             // Getting ACL info
             $acl = $this->server->getPlugin('acl');
             // If there's no ACL support, we allow everything
             if ($acl) {
                 $acl->checkPrivileges($uri, '{DAV:}write');
             }
             $node->setPublishStatus(true);
             // iCloud sends back the 202, so we will too.
             $this->server->httpResponse->sendStatus(202);
             // Adding this because sending a response body may cause issues,
             // and I wanted some type of indicator the response was handled.
             $this->server->httpResponse->setHeader('X-Sabre-Status', 'everything-went-well');
             // Breaking the event chain
             return false;
         case '{' . Plugin::NS_CALENDARSERVER . '}unpublish-calendar':
             // We can only deal with IShareableCalendar objects
             if (!$node instanceof IShareableCalendar) {
                 return;
             }
             // Getting ACL info
             $acl = $this->server->getPlugin('acl');
             // If there's no ACL support, we allow everything
             if ($acl) {
                 $acl->checkPrivileges($uri, '{DAV:}write');
             }
             $node->setPublishStatus(false);
             $this->server->httpResponse->sendStatus(200);
             // Adding this because sending a response body may cause issues,
             // and I wanted some type of indicator the response was handled.
             $this->server->httpResponse->setHeader('X-Sabre-Status', 'everything-went-well');
             // Breaking the event chain
             return false;
     }
 }
Example #16
-1
 /**
  * Parses a webdav lock xml body, and returns a new SabreForRainLoop\DAV\Locks\LockInfo object
  *
  * @param string $body
  * @return DAV\Locks\LockInfo
  */
 protected function parseLockRequest($body)
 {
     $xml = simplexml_load_string(DAV\XMLUtil::convertDAVNamespace($body), null, LIBXML_NOWARNING);
     $xml->registerXPathNamespace('d', 'urn:DAV');
     $lockInfo = new LockInfo();
     $children = $xml->children("urn:DAV");
     $lockInfo->owner = (string) $children->owner;
     $lockInfo->token = DAV\UUIDUtil::getUUID();
     $lockInfo->scope = count($xml->xpath('d:lockscope/d:exclusive')) > 0 ? LockInfo::EXCLUSIVE : LockInfo::SHARED;
     return $lockInfo;
 }