Fix chunked item issue (bug#2576)

This commit is contained in:
Jörg Lehrke 2010-05-20 10:48:45 +00:00
parent a91b9f2ebf
commit fb3cc3f594
6 changed files with 39 additions and 44 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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() {

View File

@ -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;
}