Projects
Kolab:Winterfell
kolab-syncroton
0001-Nicely-handle-errors-on-FolderCreate-T2223...
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0001-Nicely-handle-errors-on-FolderCreate-T2223.patch of Package kolab-syncroton (Revision 16)
Currently displaying revision
16
,
Show latest
From 1d7e1237f2dd2cc3882ed0b5491ef401eddcf1d2 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak <machniak@kolabsys.com> Date: Fri, 10 Feb 2017 11:03:18 +0100 Subject: [PATCH 1/2] Nicely handle errors on FolderCreate (T2223) --- lib/ext/Syncroton/Command/FolderCreate.php | 75 +++++++++++++++++++----------- lib/kolab_sync_backend.php | 8 ++++ lib/kolab_sync_data.php | 16 ++++++- 3 files changed, 72 insertions(+), 27 deletions(-) diff --git a/lib/ext/Syncroton/Command/FolderCreate.php b/lib/ext/Syncroton/Command/FolderCreate.php index 1654b34..222c556 100644 --- a/lib/ext/Syncroton/Command/FolderCreate.php +++ b/lib/ext/Syncroton/Command/FolderCreate.php @@ -10,7 +10,7 @@ */ /** - * class to handle ActiveSync FolderSync command + * class to handle ActiveSync FolderCreate command * * @package Syncroton * @subpackage Command @@ -21,14 +21,17 @@ class Syncroton_Command_FolderCreate extends Syncroton_Command_Wbxml protected $_documentElement = 'FolderCreate'; /** - * * @var Syncroton_Model_Folder */ protected $_folder; + + /** + * @var int + */ + protected $_status; /** * parse FolderCreate request - * */ public function handle() { @@ -39,14 +42,23 @@ class Syncroton_Command_FolderCreate extends Syncroton_Command_Wbxml if ($this->_logger instanceof Zend_Log) $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " synckey is $syncKey"); - if (!($this->_syncState = $this->_syncStateBackend->validate($this->_device, 'FolderSync', $syncKey)) instanceof Syncroton_Model_SyncState) { - return; - } + if (!($this->_syncState = $this->_syncStateBackend->validate($this->_device, 'FolderSync', $syncKey)) instanceof Syncroton_Model_SyncState) { + if ($this->_logger instanceof Zend_Log) + $this->_logger->info(__METHOD__ . '::' . __LINE__ . " invalid synckey provided. FolderSync 0 needed."); + + $this->_status = Syncroton_Command_FolderSync::STATUS_INVALID_SYNC_KEY; + return; + } - $folder = new Syncroton_Model_Folder($xml); + $folder = new Syncroton_Model_Folder($xml); - if ($this->_logger instanceof Zend_Log) - $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " parentId: {$folder->parentId} displayName: {$folder->displayName}"); + if ($this->_logger instanceof Zend_Log) + $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " parentId: {$folder->parentId} displayName: {$folder->displayName}"); + + if (!strlen($folder->displayName)) { + $this->_status = Syncroton_Command_FolderSync::STATUS_MISFORMATTED; + return; + } switch($folder->type) { case Syncroton_Command_FolderSync::FOLDERTYPE_CALENDAR_USER_CREATED: @@ -73,15 +85,32 @@ class Syncroton_Command_FolderCreate extends Syncroton_Command_Wbxml // unsupported type return; } - - $dataController = Syncroton_Data_Factory::factory($folder->class, $this->_device, $this->_syncTimeStamp); - - $this->_folder = $dataController->createFolder($folder); - $this->_folder->class = $folder->class; - $this->_folder->deviceId = $this->_device; - $this->_folder->creationTime = $this->_syncTimeStamp; - - $this->_folderBackend->create($this->_folder); + + try { + $dataController = Syncroton_Data_Factory::factory($folder->class, $this->_device, $this->_syncTimeStamp); + + $this->_folder = $dataController->createFolder($folder); + + if (!$this->_folder) { + $this->_status = Syncroton_Command_FolderSync::STATUS_UNKNOWN_ERROR; + } else { + $this->_folder->class = $folder->class; + $this->_folder->deviceId = $this->_device; + $this->_folder->creationTime = $this->_syncTimeStamp; + + $this->_folderBackend->create($this->_folder); + } + } catch (Syncroton_Exception_Status $e) { + if ($this->_logger instanceof Zend_Log) + $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " " . $e->getMessage()); + + $this->_status = $e->getCode(); + } catch (Exception $e) { + if ($this->_logger instanceof Zend_Log) + $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " " . $e->getMessage()); + + $this->_status = Syncroton_Command_FolderSync::STATUS_UNKNOWN_ERROR; + } } /** @@ -91,14 +120,8 @@ class Syncroton_Command_FolderCreate extends Syncroton_Command_Wbxml { $folderCreate = $this->_outputDom->documentElement; - if (!$this->_syncState instanceof Syncroton_Model_SyncState) { - if ($this->_logger instanceof Zend_Log) - $this->_logger->info(__METHOD__ . '::' . __LINE__ . " invalid synckey provided. FolderSync 0 needed."); - $folderCreate->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'Status', Syncroton_Command_FolderSync::STATUS_INVALID_SYNC_KEY)); - - } else if (!$this->_folder instanceof Syncroton_Model_Folder) { - $folderCreate->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'Status', Syncroton_Command_FolderSync::STATUS_UNKNOWN_ERROR)); - + if ($this->_status) { + $folderCreate->appendChild($this->_outputDom->createElementNS('uri:FolderHierarchy', 'Status', $this->_status)); } else { $this->_syncState->counter++; $this->_syncState->lastsync = $this->_syncTimeStamp; diff --git a/lib/kolab_sync_backend.php b/lib/kolab_sync_backend.php index 8d2c9eb..315a803 100644 --- a/lib/kolab_sync_backend.php +++ b/lib/kolab_sync_backend.php @@ -993,6 +993,14 @@ class kolab_sync_backend } /** + * Return last storage error + */ + public static function last_error() + { + return kolab_storage::$last_error; + } + + /** * Compares two arrays * * @param array $array1 diff --git a/lib/kolab_sync_data.php b/lib/kolab_sync_data.php index ce0353a..500ab78 100644 --- a/lib/kolab_sync_data.php +++ b/lib/kolab_sync_data.php @@ -305,6 +305,10 @@ abstract class kolab_sync_data implements Syncroton_Data_IData if ($parentid) { $parent = $this->backend->folder_id2name($parentid, $this->device->deviceid); + + if ($parent === null) { + throw new Syncroton_Exception_Status_FolderCreate(Syncroton_Exception_Status_FolderCreate::PARENT_NOT_FOUND); + } } $name = rcube_charset::convert($display_name, kolab_sync::CHARSET, 'UTF7-IMAP'); @@ -324,7 +328,17 @@ abstract class kolab_sync_data implements Syncroton_Data_IData return $folder; } - // @TODO: throw exception + $errno = Syncroton_Exception_Status_FolderCreate::UNKNOWN_ERROR; + + // Special case when client tries to create a subfolder of INBOX + // which is not possible on Cyrus-IMAP (T2223) + if ($parent == 'INBOX' && stripos($this->backend->last_error(), 'invalid') !== false) { + $errno = Syncroton_Exception_Status_FolderCreate::SPECIAL_FOLDER; + } + + // Note: Looks like Outlook 2013 ignores any errors on FolderCreate command + + throw new Syncroton_Exception_Status_FolderCreate($errno); } /** -- 2.9.3
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.