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); parent::startElement($uri, $element, $attrs);
switch (count($this->_stack)) { switch (count($this->_stack)) {
case 2: case 2:
if ($element == 'Replace' || if ($element == 'Replace' ||
$element == 'Add' || $element == 'Add' ||
$element == 'Delete') { $element == 'Delete') {
Horde::logMessage("SyncML: sync element $element found", __FILE__, __LINE__, PEAR_LOG_DEBUG); Horde::logMessage("SyncML: sync element $element found", __FILE__, __LINE__, PEAR_LOG_DEBUG);
$this->_curItem = &Horde_SyncML_Command_Sync_SyncElement::factory($element); $this->_curItem = &Horde_SyncML_Command_Sync_SyncElement::factory($element);
} }
break; break;
} }
if (isset($this->_curItem)) { if (isset($this->_curItem)) {
$this->_curItem->startElement($uri, $element, $attrs); $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 $_luid;
var $_guid; var $_guid;
var $_contentSize; var $_contentSize = 0;
var $_contentType; var $_contentType;
var $_contentFormat; var $_contentFormat;
var $_status = RESPONSE_OK; var $_status = RESPONSE_OK;
var $_curItem; var $_curItem;
var $_items = array(); var $_items = array();
var $_moreData = false; var $_moreData = false;
var $_command = false; var $_command = false;
function &factory($command, $params = null) { function &factory($command, $params = null) {
include_once 'Horde/SyncML/Command/Sync/SyncElementItem.php'; include_once 'Horde/SyncML/Command/Sync/SyncElementItem.php';
@ -89,15 +89,15 @@ class Horde_SyncML_Command_Sync_SyncElement extends Horde_SyncML_Command {
break; break;
case 2; case 2;
if($element == 'Item') { if($element == 'Item') {
if($this->_luid) { if ($this->_luid) {
$this->_curItem->setLocURI($this->_luid); $this->_curItem->setLocURI($this->_luid);
$this->_curItem->setContentType($this->_contentType); $this->_curItem->setContentType($this->_contentType);
$this->_curItem->setContentFormat($this->_contentFormat); $this->_curItem->setContentFormat($this->_contentFormat);
$this->_curItem->setCommand($this->_command); $this->_curItem->setCommand($this->_command);
if($this->_contentSize) if ($this->_contentSize)
$this->_curItem->setContentSize($this->_contentSize); $this->_curItem->setContentSize($this->_contentSize);
if($this->_moreData) { if ($this->_moreData) {
$state->curSyncItem = &$this->_curItem; $state->curSyncItem = &$this->_curItem;
Horde::logMessage('SyncML: moreData item saved for LocURI ' . $this->_curItem->_luid, __FILE__, __LINE__, PEAR_LOG_DEBUG); Horde::logMessage('SyncML: moreData item saved for LocURI ' . $this->_curItem->_luid, __FILE__, __LINE__, PEAR_LOG_DEBUG);
} else { } else {
@ -108,6 +108,7 @@ class Horde_SyncML_Command_Sync_SyncElement extends Horde_SyncML_Command {
#Horde::logMessage('SyncML: BASE64 encoded item for LocURI ' #Horde::logMessage('SyncML: BASE64 encoded item for LocURI '
# . $this->_curItem->_luid . ":\n $content", __FILE__, __LINE__, PEAR_LOG_DEBUG); # . $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; $this->_items[$this->_luid] = $this->_curItem;
} }
} }
@ -118,13 +119,16 @@ class Horde_SyncML_Command_Sync_SyncElement extends Horde_SyncML_Command {
case 3: case 3:
switch ($element) { switch ($element) {
case 'Data': 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; break;
case 'MoreData': case 'MoreData':
$this->_moreData = true; $this->_moreData = true;
break; break;
case 'Type': case 'Type':
if(empty($this->_contentType)) { if (empty($this->_contentType)) {
$this->_contentType = trim($this->_chars); $this->_contentType = trim($this->_chars);
} }
break; break;
@ -132,7 +136,7 @@ class Horde_SyncML_Command_Sync_SyncElement extends Horde_SyncML_Command {
$this->_contentFormat = strtolower(trim($this->_chars)); $this->_contentFormat = strtolower(trim($this->_chars));
break; break;
case 'Size': case 'Size':
$this->_contentSize = $this->_chars; $this->_contentSize = trim($this->_chars);
break; break;
} }
break; break;

View File

@ -90,7 +90,11 @@ class Horde_SyncML_Sync {
} }
function nextSyncCommand($currentCmdID, &$syncCommand, &$output) { 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); return $syncCommand->output($currentCmdID, $output);
} }
@ -157,11 +161,6 @@ class Horde_SyncML_Sync {
$history = $GLOBALS['egw']->contenthistory; $history = $GLOBALS['egw']->contenthistory;
$state = &$_SESSION['SyncML.state']; $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; $type = $this->_targetLocURI;
@ -213,11 +212,11 @@ class Horde_SyncML_Sync {
$contentSize = strlen($syncItem->_content); $contentSize = strlen($syncItem->_content);
if ((($size = $syncItem->getContentSize()) !== false) && if ((($size = $syncItem->getContentSize()) !== false) &&
abs($contentSize - $size) > 3) { abs($contentSize - $size) > 3) {
Horde::logMessage('SyncML: content size mismatch for LocURI ' Horde::logMessage('SyncML: content size mismatch for LocURI ' . $syncItem->_luid .
. $syncItem->getLocURI() . ": $contentSize ($size)", ": $contentSize ($size) : " . $syncItem->_content,
__FILE__, __LINE__, PEAR_LOG_ERROR); __FILE__, __LINE__, PEAR_LOG_WARNING);
$command->setStatus(RESPONSE_SIZE_MISMATCH); //$command->setStatus(RESPONSE_SIZE_MISMATCH);
return false; continue;
} }
if (is_a($command, 'Horde_SyncML_Command_Sync_Add')) { 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')) { if (!is_a($cmd, 'Horde_SyncML_Command_Sync_ContentSyncElement')) {
// Conflict with other datastore // Conflict with other datastore
Horde :: logMessage("SyncML: handleSync($currentCmdID, $hordeType, $syncType) moreData conflict found", 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); $state->setSyncStatus(SERVER_SYNC_DATA_PENDING);
return $currentCmdID; 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')) { if (!is_a($cmd, 'Horde_SyncML_Command_Sync_ContentSyncElement')) {
// Conflict with other datastore // Conflict with other datastore
Horde :: logMessage("SyncML: handleSync($currentCmdID, $hordeType, $syncType) moreData conflict found", 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); $state->setSyncStatus(SERVER_SYNC_DATA_PENDING);
return $currentCmdID; return $currentCmdID;
} }
@ -202,12 +202,6 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync {
$history = $GLOBALS['egw']->contenthistory; $history = $GLOBALS['egw']->contenthistory;
$state = &$_SESSION['SyncML.state']; $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; $type = $this->_targetLocURI;
$syncml_prefs = $GLOBALS['egw_info']['user']['preferences']['syncml']; $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) && if ((($size = $syncItem->getContentSize()) !== false) &&
abs($contentSize - $size) > 3) { abs($contentSize - $size) > 3) {
Horde::logMessage('SyncML: content size mismatch for LocURI ' . $syncItem->_luid . Horde::logMessage('SyncML: content size mismatch for LocURI ' . $syncItem->_luid .
": $contentSize ($size)", __FILE__, __LINE__, PEAR_LOG_ERROR); ": $contentSize ($size) : " . $syncItem->_content,
$command->setStatus(RESPONSE_SIZE_MISMATCH); __FILE__, __LINE__, PEAR_LOG_WARNING);
return; //$command->setStatus(RESPONSE_SIZE_MISMATCH);
continue;
} }
if(!$contentType = $syncItem->getContentType()) { if(!$contentType = $syncItem->getContentType()) {
@ -248,7 +243,7 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync {
$guid = $registry->call($hordeType . '/search', $guid = $registry->call($hordeType . '/search',
array($state->convertClient2Server($syncItem->getContent(), $contentType), $contentType, $oguid, $type)); 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 // Check if the found entry came from the client
$guid_ts = $state->getSyncTSforAction($guid, 'add'); $guid_ts = $state->getSyncTSforAction($guid, 'add');
$sync_ts = $state->getChangeTS($type, $guid); $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); __FILE__, __LINE__, PEAR_LOG_DEBUG);
$guid = $registry->call($hordeType . '/import', $guid = $registry->call($hordeType . '/import',
array($state->convertClient2Server($syncItem->getContent(), $contentType), $contentType)); 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->setUID($type, $syncItem->getLocURI(), $guid);
$state->log("Client-AddReplace"); $state->log("Client-AddReplace");
Horde::logMessage('SyncML: replaced/added client entry as ' . $guid, 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"); $state->log("Client-AddFailure");
} }
} }
return true;
} }
function loadData() { 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')) { if (!is_a($cmd, 'Horde_SyncML_Command_Sync_ContentSyncElement')) {
// Conflict with other datastore // Conflict with other datastore
Horde :: logMessage("SyncML: handleSync($currentCmdID, $hordeType, $syncType) moreData conflict found", 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); $state->setSyncStatus(SERVER_SYNC_DATA_PENDING);
return $currentCmdID; return $currentCmdID;
} }