From 490af5f06283849082b81e4a86ddcd87c8758efb Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Tue, 15 Sep 2009 14:55:04 +0200 Subject: [PATCH] Basic skeleton for Sabre backends. Not sure if those should go under the Sabre/ or the Horde/ namespace. --- framework/Sabre/lib/Sabre/CalDAV/Backend/Horde.php | 164 +++++++++++++++++++++ .../Sabre/lib/Sabre/DAV/Auth/Backend/Horde.php | 55 +++++++ framework/Sabre/package.xml | 73 +++++++++ 3 files changed, 292 insertions(+) create mode 100644 framework/Sabre/lib/Sabre/CalDAV/Backend/Horde.php create mode 100644 framework/Sabre/lib/Sabre/DAV/Auth/Backend/Horde.php create mode 100644 framework/Sabre/package.xml diff --git a/framework/Sabre/lib/Sabre/CalDAV/Backend/Horde.php b/framework/Sabre/lib/Sabre/CalDAV/Backend/Horde.php new file mode 100644 index 000000000..72ca06b36 --- /dev/null +++ b/framework/Sabre/lib/Sabre/CalDAV/Backend/Horde.php @@ -0,0 +1,164 @@ + + * @license @todo + */ +class Sabre_CalDAV_Backend_Horde extends Sabre_CalDAV_Backend_Abstract +{ + /** + * @var Horde_Registry + */ + protected $_registry; + + public function __construct(Horde_Registry $registry) + { + $this->_registry = $registry; + } + + /** + * Returns a list of calendars for a users' uri + * + * The uri is not a full path, just the actual last part + * + * @param string $userUri + * @return array + */ + public function getCalendarsForUser($userUri) + { + // If possible we should ressamble the existing WebDAV structure with + // CalDAV. Listing just the calendars is not sufficient for this. + $result = array(); + $owners = $this->_registry->calendar->browse('', array('name')); + foreach (reset($owners) as $owner) { + $calendars = $this->_registry->calendar->browse($owner['name'], array('name')); + foreach ($calendars as $name => $calendar) { + $result[] = substr($name, strrpos($name, '/')); + } + } + return $result; + + // Alternative solution (without hierarchy): + return $this->_registry->calendar->listCalendars(); + } + + /** + * Creates a new calendar for a user + * + * The userUri and calendarUri are not full paths, just the 'basename'. + * + * @param string $userUri + * @param string $calendarUri + * @param string $displayName + * @param string $description + * @return void + */ + public function createCalendar($userUri, $calendarUri, $displayName, + $description) + { + // To be implemented. We can't create the Horde_Share directly, + // because each application defines its own share namespace + // (e.g. horde.shares.kronolith), but this namespace is unknown + // outside of the application. + // Why Uri? Is it anything different than the plain user name and + // calendar ID? + $this->_registry->calendar->createCalendar($userUri, $calendarUri, $displayName, $description); + } + + /** + * Updates a calendar's basic information + * + * @param string $calendarId + * @param string $displayName + * @param string $description + * @return void + */ + public function updateCalendar($calendarId, $displayName, $description) + { + // To be implemented. + // ID == calendar name in Horde. + $this->_registry->calendar->updateCalendar($calendarId, $displayName, $description); + } + + /** + * Returns all calendar objects within a calendar object. + * + * @param string $calendarId + * @return array + */ + public function getCalendarObjects($calendarId) + { + // browse() assumes an intermediate owner directory at the moment. + $owner = 'foo'; + $events = $this->_registry->calendar->browse($owner . '/' . $calendarId, array('name')); + + // Return format? + return $events; + } + + /** + * Returns information from a single calendar object, based on it's object + * uri. + * + * @param mixed $calendarId + * @param string $objectUri + * @return array + */ + public function getCalendarObject($calendarId, $objectUri) + { + // browse() assumes an intermediate owner directory at the moment. + $owner = 'foo'; + $event = $this->_registry->calendar->browse($owner . '/' . $calendarId . '/' . $objectUri); + return array('calendardata' => $event['data'], + 'lastmodified' => $event['mtime']); + // What else to return? Mime type? + } + + /** + * Creates a new calendar object. + * + * @param mixed $calendarId + * @param string $objectUri + * @param string $calendarData + * @return void + */ + public function createCalendarObject($calendarId, $objectUri, $calendarData) + { + // No Content-Type? + // We don't accept object ids at the moment. + $this->_registry->import($calendarData, 'text/calendar', $calendarId); + } + + /** + * Updates an existing calendarobject, based on it's uri. + * + * @param mixed $calendarId + * @param string $objectUri + * @param string $calendarData + * @return void + */ + public function updateCalendarObject($calendarId, $objectUri, $calendarData) + { + // No Content-Type? + // Object ID or UID? + $this->_registry->import($objectUri, $calendarData, 'text/calendar'); + } + + /** + * Deletes an existing calendar object. + * + * @param mixed $calendarId + * @param string $objectUri + * @return void + */ + public function deleteCalendarObject($calendarId, $objectUri) + { + // Object ID or UID? + $this->_registry->delete($objectUri); + } + +} diff --git a/framework/Sabre/lib/Sabre/DAV/Auth/Backend/Horde.php b/framework/Sabre/lib/Sabre/DAV/Auth/Backend/Horde.php new file mode 100644 index 000000000..a7f775fe9 --- /dev/null +++ b/framework/Sabre/lib/Sabre/DAV/Auth/Backend/Horde.php @@ -0,0 +1,55 @@ + + * @license @todo + */ +class Sabre_DAV_Auth_Backend_Horde extends Sabre_DAV_Auth_Backend_Abstract +{ + /** + * @var Horde_Auth + */ + protected $_auth; + + public function __construct(Horde_Auth $auth) + { + $this->_auth = $auth; + } + + /** + * Returns the HTTP Digest hash for a username + * + * This must be the A1 part of the digest hash + * + * @param string $username + * @return string + */ + public function getDigestHash($username) + { + // We don't have the A1 hash stored, and we don't have the plaintext + // passwords. Workaround? + } + + public function getUserList() + { + if (!$this->_auth->hasCapability('list')) { + return array(); + } + + $users = array(); + foreach ($this->_auth->listUsers() as $user) { + $users[] = array('href' => $user); + // We could potentially get {DAV:}displayname from the users' + // identities, but we should only do that if this method is not + // supposed to be called too often. + } + + return $users; + } + +} diff --git a/framework/Sabre/package.xml b/framework/Sabre/package.xml new file mode 100644 index 000000000..31bd72873 --- /dev/null +++ b/framework/Sabre/package.xml @@ -0,0 +1,73 @@ + + + Sabre + pear.horde.org + Backend implementations for SabreDAV + This package contains all Horde-specific backend implementations for Sabre's abstract classes. + + Jan Schneider + jan + jan@horde.org + yes + + 2009-12-31 + + 0.1.0 + 0.1.0 + + + beta + beta + + LGPL + * Initial Horde 4 package. + + + + + + + + + + + + + + + + + + + + + + + + 5.2.0 + + + 1.5.0 + + + Core + pear.horde.org + + + Auth + pear.horde.org + + + + + + + + + + + + -- 2.11.0