/** * validates a subscription's url * @param ISubscription $subscription * @throws \OCA\Calendar\Backend\Exception */ protected function validateSubscriptionUrl(ISubscription &$subscription) { $url = $subscription->getUrl(); $parsed = parse_url($url); if (!$parsed) { throw new BackendUtils\Exception('URL not processable'); } if (!isset($parsed['scheme'])) { //TODO - try to use https first $newUrl = 'http://'; $newUrl .= $url; $subscription->setUrl($newUrl); $parsed['scheme'] = 'http'; } if ($parsed['scheme'] === 'webcal') { $newUrl = preg_replace("/^webcal:/i", "http:", $url); $subscription->setUrl($newUrl); $parsed['scheme'] = 'http'; } if ($parsed['scheme'] !== 'http' && $parsed['scheme'] !== 'https') { throw new BackendUtils\Exception('Protocol not supported'); } }
/** * @param ISubscription $subscription * @throws BackendUtils\SubscriptionInvalidException */ private function sendTestRequest(ISubscription &$subscription) { $curl = curl_init(); $url = $subscription->getUrl(); $data = null; $this->prepareRequest($curl, $url); $this->getRequestData($curl, $data); $this->validateRequest($curl); try { $vobject = Reader::read($data); //Is it an address-book instead of a calendar? if (!$vobject instanceof VCalendar) { throw new BackendUtils\SubscriptionInvalidException('Calendar-data is not valid!'); } } catch (ParseException $ex) { throw new BackendUtils\SubscriptionInvalidException('Calendar-data is not valid!'); } }
/** * @param ISubscription $subscription * @return \OCA\Calendar\IEntity * @throws CorruptDataException */ private function generateCalendar(ISubscription $subscription) { $curl = curl_init(); $url = $subscription->getUrl(); $data = null; //TODO - replace webcal with https or http $this->prepareRequest($curl, $url); $this->getRequestData($curl, $data); $this->validateRequest($curl); $this->stripOfObjectData($data); try { $vobject = Reader::read($data); //Is it an address-book instead of a calendar? if (!$vobject instanceof VCalendar) { throw new ParseException(); } $calendar = new \OCA\Calendar\Db\Calendar(); $calendar->fromVObject($vobject); } catch (ParseException $ex) { throw new CorruptDataException('Calendar-data is not valid!'); } $calendar->setUserId($subscription->getUserId()); $calendar->setOwnerId($subscription->getUserId()); $calendar->setBackend($this->backend); $calendar->setPrivateUri($subscription->getId()); $calendar->setComponents(ObjectType::EVENT); // TODO hardcoding this to events only is bullshit $calendar->setEnabled(true); $calendar->setCruds(Permissions::READ); $calendar->setOrder(0); //TODO - use something better for ctag $calendar->setCtag(time()); return $calendar; }