summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2015-03-12 14:57:22 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2015-03-12 14:57:22 (GMT)
commitaa428fdbdb669692d921a6b5aef5fba81d4b3844 (patch)
treeedb6cc621903b826dc32ca24025faea8ec1fc17b
parent020eaeac4c08753e40049a25e231d052da20ba3d (diff)
downloadiRony-aa428fdbdb669692d921a6b5aef5fba81d4b3844.tar.gz
Check for storage errors and throw the according exceptions (#4406)
-rw-r--r--lib/Kolab/CalDAV/CalendarBackend.php1
-rw-r--r--lib/Kolab/CardDAV/ContactsBackend.php1
-rw-r--r--lib/Kolab/Utils/DAVBackend.php36
3 files changed, 36 insertions, 2 deletions
diff --git a/lib/Kolab/CalDAV/CalendarBackend.php b/lib/Kolab/CalDAV/CalendarBackend.php
index a7ee0f8..848c9dd 100644
--- a/lib/Kolab/CalDAV/CalendarBackend.php
+++ b/lib/Kolab/CalDAV/CalendarBackend.php
@@ -106,6 +106,7 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend
}
if ($this->folders[$id]) {
+ DAVBackend::check_storage_folder($this->folders[$id]);
return $this->folders[$id];
}
else {
diff --git a/lib/Kolab/CardDAV/ContactsBackend.php b/lib/Kolab/CardDAV/ContactsBackend.php
index 1a92fe0..fc09784 100644
--- a/lib/Kolab/CardDAV/ContactsBackend.php
+++ b/lib/Kolab/CardDAV/ContactsBackend.php
@@ -124,6 +124,7 @@ class ContactsBackend extends CardDAV\Backend\AbstractBackend
}
if ($this->folders[$id]) {
+ DAVBackend::check_storage_folder($this->folders[$id]);
return $this->folders[$id];
}
else {
diff --git a/lib/Kolab/Utils/DAVBackend.php b/lib/Kolab/Utils/DAVBackend.php
index 6c4b69f..615d6b8 100644
--- a/lib/Kolab/Utils/DAVBackend.php
+++ b/lib/Kolab/Utils/DAVBackend.php
@@ -27,6 +27,7 @@ use \rcube;
use \kolab_storage;
use \rcube_utils;
use \rcube_charset;
+use Sabre\DAV;
/**
*
@@ -49,11 +50,42 @@ class DAVBackend
public static function get_storage_folder($uid, $type)
{
foreach (kolab_storage::get_folders($type, false) as $folder) {
- if ($folder->get_uid() == $uid)
+ if ($folder->get_uid() == $uid) {
+ self::check_storage_folder($folder);
return $folder;
+ }
+ }
+
+ self::check_storage_folder(null);
+ }
+
+ /**
+ * Check the given storage folder instance for validity and throw
+ * the right exceptions according to the error state.
+ */
+ public static function check_storage_folder($folder)
+ {
+ if ($folder == null) {
+ throw new DAV\Exception\NotFound('The requested collection was not found');
}
- return null;
+ if (!$folder->valid || $folder->get_error()) {
+ $error = $folder->get_error();
+ if ($error === kolab_storage::ERROR_IMAP_CONN) {
+ throw new DAV\Exception\ServiceUnavailable('The service is temporarily unavailable (Storage failure)');
+ }
+ else if ($error === kolab_storage::ERROR_CACHE_DB) {
+ throw new DAV\Exception\ServiceUnavailable('The service is temporarily unavailable (Cache failure)');
+ }
+ else if ($error === kolab_storage::ERROR_NO_PERMISSION) {
+ throw new DAV\Exception\Forbidden('Access to this collection is not permitted');
+ }
+ else if ($error === kolab_storage::ERROR_INVALID_FOLDER) {
+ throw new DAV\Exception\NotFound('The requested collection was not found');
+ }
+
+ throw new DAV\Exception('Internal Server Error');
+ }
}
/**