From fb3cc3f594ea59d1b9ce4e33a907fd28dffd3224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Lehrke?= Date: Thu, 20 May 2010 10:48:45 +0000 Subject: [PATCH] Fix chunked item issue (bug#2576) --- .../inc/horde/Horde/SyncML/Command/Sync.php | 16 +++++++------- .../Horde/SyncML/Command/Sync/SyncElement.php | 20 ++++++++++------- phpgwapi/inc/horde/Horde/SyncML/Sync.php | 22 +++++++++---------- .../SyncML/Sync/RefreshFromServerSync.php | 2 +- .../inc/horde/Horde/SyncML/Sync/SlowSync.php | 21 ++++++------------ .../horde/Horde/SyncML/Sync/TwoWaySync.php | 2 +- 6 files changed, 39 insertions(+), 44 deletions(-) diff --git a/phpgwapi/inc/horde/Horde/SyncML/Command/Sync.php b/phpgwapi/inc/horde/Horde/SyncML/Command/Sync.php index 3c53651ddc..9e4704df22 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/Command/Sync.php +++ b/phpgwapi/inc/horde/Horde/SyncML/Command/Sync.php @@ -106,14 +106,14 @@ class Horde_SyncML_Command_Sync extends Horde_SyncML_Command { parent::startElement($uri, $element, $attrs); switch (count($this->_stack)) { - case 2: - if ($element == 'Replace' || - $element == 'Add' || - $element == 'Delete') { - Horde::logMessage("SyncML: sync element $element found", __FILE__, __LINE__, PEAR_LOG_DEBUG); - $this->_curItem = &Horde_SyncML_Command_Sync_SyncElement::factory($element); - } - break; + case 2: + if ($element == 'Replace' || + $element == 'Add' || + $element == 'Delete') { + Horde::logMessage("SyncML: sync element $element found", __FILE__, __LINE__, PEAR_LOG_DEBUG); + $this->_curItem = &Horde_SyncML_Command_Sync_SyncElement::factory($element); + } + break; } if (isset($this->_curItem)) { $this->_curItem->startElement($uri, $element, $attrs); diff --git a/phpgwapi/inc/horde/Horde/SyncML/Command/Sync/SyncElement.php b/phpgwapi/inc/horde/Horde/SyncML/Command/Sync/SyncElement.php index acad907b0d..1e4ff612f0 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/Command/Sync/SyncElement.php +++ b/phpgwapi/inc/horde/Horde/SyncML/Command/Sync/SyncElement.php @@ -20,14 +20,14 @@ class Horde_SyncML_Command_Sync_SyncElement extends Horde_SyncML_Command { var $_luid; var $_guid; - var $_contentSize; + var $_contentSize = 0; var $_contentType; var $_contentFormat; var $_status = RESPONSE_OK; var $_curItem; var $_items = array(); var $_moreData = false; - var $_command = false; + var $_command = false; function &factory($command, $params = null) { include_once 'Horde/SyncML/Command/Sync/SyncElementItem.php'; @@ -89,15 +89,15 @@ class Horde_SyncML_Command_Sync_SyncElement extends Horde_SyncML_Command { break; case 2; if($element == 'Item') { - if($this->_luid) { + if ($this->_luid) { $this->_curItem->setLocURI($this->_luid); $this->_curItem->setContentType($this->_contentType); $this->_curItem->setContentFormat($this->_contentFormat); $this->_curItem->setCommand($this->_command); - if($this->_contentSize) + if ($this->_contentSize) $this->_curItem->setContentSize($this->_contentSize); - if($this->_moreData) { + if ($this->_moreData) { $state->curSyncItem = &$this->_curItem; Horde::logMessage('SyncML: moreData item saved for LocURI ' . $this->_curItem->_luid, __FILE__, __LINE__, PEAR_LOG_DEBUG); } else { @@ -108,6 +108,7 @@ class Horde_SyncML_Command_Sync_SyncElement extends Horde_SyncML_Command { #Horde::logMessage('SyncML: BASE64 encoded item for LocURI ' # . $this->_curItem->_luid . ":\n $content", __FILE__, __LINE__, PEAR_LOG_DEBUG); } + #Horde::logMessage('SyncML: Data for ' . $this->_luid . ': ' . $this->_curItem->getContent(), __FILE__, __LINE__, PEAR_LOG_DEBUG); $this->_items[$this->_luid] = $this->_curItem; } } @@ -118,13 +119,16 @@ class Horde_SyncML_Command_Sync_SyncElement extends Horde_SyncML_Command { case 3: switch ($element) { case 'Data': - $this->_curItem->_content .= $this->_chars; + $content = $this->_chars; + if ($this->_contentFormat == 'b64') $content = trim($content); + #Horde::logMessage('SyncML: Data for ' . $this->_luid . ': ' . $content, __FILE__, __LINE__, PEAR_LOG_DEBUG); + $this->_curItem->_content .= $content; break; case 'MoreData': $this->_moreData = true; break; case 'Type': - if(empty($this->_contentType)) { + if (empty($this->_contentType)) { $this->_contentType = trim($this->_chars); } break; @@ -132,7 +136,7 @@ class Horde_SyncML_Command_Sync_SyncElement extends Horde_SyncML_Command { $this->_contentFormat = strtolower(trim($this->_chars)); break; case 'Size': - $this->_contentSize = $this->_chars; + $this->_contentSize = trim($this->_chars); break; } break; diff --git a/phpgwapi/inc/horde/Horde/SyncML/Sync.php b/phpgwapi/inc/horde/Horde/SyncML/Sync.php index 70b9cfaf75..5576f996f6 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/Sync.php +++ b/phpgwapi/inc/horde/Horde/SyncML/Sync.php @@ -90,7 +90,11 @@ class Horde_SyncML_Sync { } function nextSyncCommand($currentCmdID, &$syncCommand, &$output) { - $result = $this->runSyncCommand($syncCommand); + $this->runSyncCommand($syncCommand); + if ($syncCommand->hasMoreData()) { + Horde::logMessage('SyncML: moreData: TRUE', __FILE__, __LINE__, PEAR_LOG_DEBUG); + $syncCommand->setStatus(RESPONSE_CHUNKED_ITEM_ACCEPTED_AND_BUFFERED); + } return $syncCommand->output($currentCmdID, $output); } @@ -157,11 +161,6 @@ class Horde_SyncML_Sync { $history = $GLOBALS['egw']->contenthistory; $state = &$_SESSION['SyncML.state']; - if ($command->hasMoreData()) { - Horde::logMessage('SyncML: moreData: TRUE', __FILE__, __LINE__, PEAR_LOG_DEBUG); - $command->setStatus(RESPONSE_CHUNKED_ITEM_ACCEPTED_AND_BUFFERED); - return true; - } $type = $this->_targetLocURI; @@ -213,11 +212,11 @@ class Horde_SyncML_Sync { $contentSize = strlen($syncItem->_content); if ((($size = $syncItem->getContentSize()) !== false) && abs($contentSize - $size) > 3) { - Horde::logMessage('SyncML: content size mismatch for LocURI ' - . $syncItem->getLocURI() . ": $contentSize ($size)", - __FILE__, __LINE__, PEAR_LOG_ERROR); - $command->setStatus(RESPONSE_SIZE_MISMATCH); - return false; + Horde::logMessage('SyncML: content size mismatch for LocURI ' . $syncItem->_luid . + ": $contentSize ($size) : " . $syncItem->_content, + __FILE__, __LINE__, PEAR_LOG_WARNING); + //$command->setStatus(RESPONSE_SIZE_MISMATCH); + continue; } if (is_a($command, 'Horde_SyncML_Command_Sync_Add')) { @@ -454,6 +453,5 @@ class Horde_SyncML_Sync { } } } - return $guid; } } diff --git a/phpgwapi/inc/horde/Horde/SyncML/Sync/RefreshFromServerSync.php b/phpgwapi/inc/horde/Horde/SyncML/Sync/RefreshFromServerSync.php index 5a6a46cd89..bb0cc88951 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/Sync/RefreshFromServerSync.php +++ b/phpgwapi/inc/horde/Horde/SyncML/Sync/RefreshFromServerSync.php @@ -42,7 +42,7 @@ class Horde_SyncML_Sync_RefreshFromServerSync extends Horde_SyncML_Sync_TwoWaySy if (!is_a($cmd, 'Horde_SyncML_Command_Sync_ContentSyncElement')) { // Conflict with other datastore Horde :: logMessage("SyncML: handleSync($currentCmdID, $hordeType, $syncType) moreData conflict found", - __FILE__, __LINE__, PEAR_LOG_DEBUG); + __FILE__, __LINE__, PEAR_LOG_WARNING); $state->setSyncStatus(SERVER_SYNC_DATA_PENDING); return $currentCmdID; } diff --git a/phpgwapi/inc/horde/Horde/SyncML/Sync/SlowSync.php b/phpgwapi/inc/horde/Horde/SyncML/Sync/SlowSync.php index b78e4c2aee..d4cc0a59ad 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/Sync/SlowSync.php +++ b/phpgwapi/inc/horde/Horde/SyncML/Sync/SlowSync.php @@ -50,7 +50,7 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { if (!is_a($cmd, 'Horde_SyncML_Command_Sync_ContentSyncElement')) { // Conflict with other datastore Horde :: logMessage("SyncML: handleSync($currentCmdID, $hordeType, $syncType) moreData conflict found", - __FILE__, __LINE__, PEAR_LOG_DEBUG); + __FILE__, __LINE__, PEAR_LOG_WARNING); $state->setSyncStatus(SERVER_SYNC_DATA_PENDING); return $currentCmdID; } @@ -202,12 +202,6 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { $history = $GLOBALS['egw']->contenthistory; $state = &$_SESSION['SyncML.state']; - if ($command->hasMoreData()) { - Horde::logMessage('SyncML: moreData: TRUE', __FILE__, __LINE__, PEAR_LOG_DEBUG); - $command->setStatus(RESPONSE_CHUNKED_ITEM_ACCEPTED_AND_BUFFERED); - return true; - } - $type = $this->_targetLocURI; $syncml_prefs = $GLOBALS['egw_info']['user']['preferences']['syncml']; @@ -227,9 +221,10 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { if ((($size = $syncItem->getContentSize()) !== false) && abs($contentSize - $size) > 3) { Horde::logMessage('SyncML: content size mismatch for LocURI ' . $syncItem->_luid . - ": $contentSize ($size)", __FILE__, __LINE__, PEAR_LOG_ERROR); - $command->setStatus(RESPONSE_SIZE_MISMATCH); - return; + ": $contentSize ($size) : " . $syncItem->_content, + __FILE__, __LINE__, PEAR_LOG_WARNING); + //$command->setStatus(RESPONSE_SIZE_MISMATCH); + continue; } if(!$contentType = $syncItem->getContentType()) { @@ -248,7 +243,7 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { $guid = $registry->call($hordeType . '/search', array($state->convertClient2Server($syncItem->getContent(), $contentType), $contentType, $oguid, $type)); - if ($guid) { + if (!is_a($guid, 'PEAR_Error') && $guid) { // Check if the found entry came from the client $guid_ts = $state->getSyncTSforAction($guid, 'add'); $sync_ts = $state->getChangeTS($type, $guid); @@ -292,7 +287,7 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { __FILE__, __LINE__, PEAR_LOG_DEBUG); $guid = $registry->call($hordeType . '/import', array($state->convertClient2Server($syncItem->getContent(), $contentType), $contentType)); - if (!is_a($guid, 'PEAR_Error') && $guid != false) { + if (!is_a($guid, 'PEAR_Error') && $guid) { $state->setUID($type, $syncItem->getLocURI(), $guid); $state->log("Client-AddReplace"); Horde::logMessage('SyncML: replaced/added client entry as ' . $guid, @@ -303,8 +298,6 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { $state->log("Client-AddFailure"); } } - - return true; } function loadData() { diff --git a/phpgwapi/inc/horde/Horde/SyncML/Sync/TwoWaySync.php b/phpgwapi/inc/horde/Horde/SyncML/Sync/TwoWaySync.php index 6ede36367c..e26baae63e 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/Sync/TwoWaySync.php +++ b/phpgwapi/inc/horde/Horde/SyncML/Sync/TwoWaySync.php @@ -65,7 +65,7 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync { if (!is_a($cmd, 'Horde_SyncML_Command_Sync_ContentSyncElement')) { // Conflict with other datastore Horde :: logMessage("SyncML: handleSync($currentCmdID, $hordeType, $syncType) moreData conflict found", - __FILE__, __LINE__, PEAR_LOG_DEBUG); + __FILE__, __LINE__, PEAR_LOG_WARNING); $state->setSyncStatus(SERVER_SYNC_DATA_PENDING); return $currentCmdID; }