From 08d3e484dc268df6537422b7b3a3375fa2612f9a Mon Sep 17 00:00:00 2001 From: Lars Kneschke Date: Sat, 14 Jan 2006 08:29:23 +0000 Subject: [PATCH] final syncml fixes --- phpgwapi/inc/horde/Horde/SyncML.php | 1 - .../inc/horde/Horde/SyncML/Command/Get.php | 8 +- .../inc/horde/Horde/SyncML/Command/Sync.php | 94 ++++++++++--------- phpgwapi/inc/horde/Horde/SyncML/State.php | 2 +- .../inc/horde/XML/WBXML/DTD/SyncMLMetInf.php | 3 +- phpgwapi/inc/horde/XML/WBXML/Encoder.php | 13 +-- 6 files changed, 57 insertions(+), 64 deletions(-) diff --git a/phpgwapi/inc/horde/Horde/SyncML.php b/phpgwapi/inc/horde/Horde/SyncML.php index 2cf34a1483..b16083a33b 100644 --- a/phpgwapi/inc/horde/Horde/SyncML.php +++ b/phpgwapi/inc/horde/Horde/SyncML.php @@ -312,7 +312,6 @@ class Horde_SyncML_SyncMLHdr extends Horde_SyncML_ContentHandler { $uri = $state->getURI(); $uriMeta = $state->getURIMeta(); - $output->startElement($uri, 'SyncHdr', $attrs); $output->startElement($uri, 'VerDTD', $attrs); diff --git a/phpgwapi/inc/horde/Horde/SyncML/Command/Get.php b/phpgwapi/inc/horde/Horde/SyncML/Command/Get.php index 710110340a..f2b344a9c8 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/Command/Get.php +++ b/phpgwapi/inc/horde/Horde/SyncML/Command/Get.php @@ -85,11 +85,11 @@ class Horde_SyncML_Command_Get extends Horde_SyncML_Command { $output->startElement($state->getURIDevInf() , 'DevTyp', $attrs); $output->characters('server'); $output->endElement($state->getURIDevInf() , 'DevTyp', $attrs); - $this->_writeDataStore('notes', 'text/x-vnote', '1.1', $output, + $this->_writeDataStore('./notes', 'text/x-vnote', '1.1', $output, array('text/plain' => '1.0')); - $this->_writeDataStore('contacts', 'text/x-vcard', '2.1', $output); - $this->_writeDataStore('tasks', 'text/x-vcalendar', '1.0', $output); - $this->_writeDataStore('calendar', 'text/x-vcalendar', '1.0', $output); + $this->_writeDataStore('./contacts', 'text/x-vcard', '2.1', $output); + $this->_writeDataStore('./tasks', 'text/x-vcalendar', '1.0', $output); + $this->_writeDataStore('./calendar', 'text/x-vcalendar', '1.0', $output); $output->endElement($state->getURIDevInf() , 'DevInf', $attrs); $output->endElement($state->getURI(), 'Data'); diff --git a/phpgwapi/inc/horde/Horde/SyncML/Command/Sync.php b/phpgwapi/inc/horde/Horde/SyncML/Command/Sync.php index 2f294a91e2..6521a3c018 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/Command/Sync.php +++ b/phpgwapi/inc/horde/Horde/SyncML/Command/Sync.php @@ -97,58 +97,60 @@ class Horde_SyncML_Command_Sync extends Horde_Syncml_Command { $state = $_SESSION['SyncML.state']; if($state->getSyncStatus() == CLIENT_SYNC_FINNISHED || $state->getSyncStatus() == SERVER_SYNC_DATA_PENDING) { -############## - $state->setSyncStatus(SERVER_SYNC_DATA_PENDING); - $targets = $state->getTargets(); - Horde::logMessage('SyncML: starting sync to client '.$targets[0], __FILE__, __LINE__, PEAR_LOG_DEBUG); - $attrs = array(); + $deviceInfo = $state->getClientDeviceInfo(); + $state->setSyncStatus(SERVER_SYNC_DATA_PENDING); + $targets = $state->getTargets(); + Horde::logMessage('SyncML: starting sync to client '.$targets[0], __FILE__, __LINE__, PEAR_LOG_DEBUG); + $attrs = array(); - foreach($targets as $target) - { - $sync = $state->getSync($target); - - $output->startElement($state->getURI(), 'Sync', $attrs); - $output->startElement($state->getURI(), 'CmdID', $attrs); - $output->characters($currentCmdID); - $currentCmdID++; - $output->endElement($state->getURI(), 'CmdID'); - - $output->startElement($state->getURI(), 'Target', $attrs); - $output->startElement($state->getURI(), 'LocURI', $attrs); - $chars = $sync->_sourceLocURI; - $output->characters($chars); - $output->endElement($state->getURI(), 'LocURI'); - $output->endElement($state->getURI(), 'Target'); - - $output->startElement($state->getURI(), 'Source', $attrs); - $output->startElement($state->getURI(), 'LocURI', $attrs); - #$chars = $sync->_targetLocURI; - $chars = (isset($sync->_targetLocURIParameters) ? $sync->_targetLocURI.'?/'.$sync->_targetLocURIParameters : $sync->_targetLocURI); - $output->characters($chars); - $output->endElement($state->getURI(), 'LocURI'); - $output->endElement($state->getURI(), 'Source'); - - if(!$sync->_syncDataLoaded) + foreach($targets as $target) { - $numberOfItems = $sync->loadData(); - $output->startElement($state->getURI(), 'NumberOfChanged', $attrs); - $output->characters($numberOfItems); - $output->endElement($state->getURI(), 'NumberOfChanged'); + $sync = $state->getSync($target); + + $output->startElement($state->getURI(), 'Sync', $attrs); + $output->startElement($state->getURI(), 'CmdID', $attrs); + $output->characters($currentCmdID); + $currentCmdID++; + $output->endElement($state->getURI(), 'CmdID'); + + $output->startElement($state->getURI(), 'Target', $attrs); + $output->startElement($state->getURI(), 'LocURI', $attrs); + $chars = $sync->_sourceLocURI; + $output->characters($chars); + $output->endElement($state->getURI(), 'LocURI'); + $output->endElement($state->getURI(), 'Target'); + + $output->startElement($state->getURI(), 'Source', $attrs); + $output->startElement($state->getURI(), 'LocURI', $attrs); + #$chars = $sync->_targetLocURI; + $chars = (isset($sync->_targetLocURIParameters) ? $sync->_targetLocURI.'?/'.$sync->_targetLocURIParameters : $sync->_targetLocURI); + $output->characters($chars); + $output->endElement($state->getURI(), 'LocURI'); + $output->endElement($state->getURI(), 'Source'); + + if(!$sync->_syncDataLoaded) + { + $numberOfItems = $sync->loadData(); + if($deviceInfo['supportNumberOfChanges']) + { + $output->startElement($state->getURI(), 'NumberOfChanged', $attrs); + $output->characters($numberOfItems); + $output->endElement($state->getURI(), 'NumberOfChanged'); + } + } + + $currentCmdID = $sync->endSync($currentCmdID, $output); + + $output->endElement($state->getURI(), 'Sync'); + + break; } - $currentCmdID = $sync->endSync($currentCmdID, $output); + // no syncs left + if($state->getTargets() === FALSE) + $state->setSyncStatus(SERVER_SYNC_FINNISHED); - $output->endElement($state->getURI(), 'Sync'); - - break; - } - # - - // no syncs left - if($state->getTargets() === FALSE) - $state->setSyncStatus(SERVER_SYNC_FINNISHED); Horde::logMessage('SyncML: syncStatus(server_sync_finnished) '. $state->getSyncStatus, __FILE__, __LINE__, PEAR_LOG_DEBUG); -############################# } return $currentCmdID; diff --git a/phpgwapi/inc/horde/Horde/SyncML/State.php b/phpgwapi/inc/horde/Horde/SyncML/State.php index b4a888cd6b..52454e86ab 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/State.php +++ b/phpgwapi/inc/horde/Horde/SyncML/State.php @@ -117,7 +117,7 @@ define('RESPONSE_COMMAND_FAILED', 500); // define('RESPONSE_COMMAND_FAILED', 515); define('RESPONSE_ATOMIC_ROLL_BACK_FAILED', 516); -define('NAME_SPACE_URI_SYNCML', 'SYNCML:SYNCML1.0'); +define('NAME_SPACE_URI_SYNCML', 'syncml:syncml1.0'); define('NAME_SPACE_URI_SYNCML_1_1', 'syncml:syncml1.1'); define('NAME_SPACE_URI_METINF', 'syncml:metinf'); define('NAME_SPACE_URI_METINF_1_1', 'syncml:metinf1.1'); diff --git a/phpgwapi/inc/horde/XML/WBXML/DTD/SyncMLMetInf.php b/phpgwapi/inc/horde/XML/WBXML/DTD/SyncMLMetInf.php index 84010187cd..43a5737c2a 100644 --- a/phpgwapi/inc/horde/XML/WBXML/DTD/SyncMLMetInf.php +++ b/phpgwapi/inc/horde/XML/WBXML/DTD/SyncMLMetInf.php @@ -45,7 +45,8 @@ class XML_WBXML_DTD_SyncMLMetInf extends XML_WBXML_DTD { $this->setTag(0x14, "Version"); // 0x01 if ($this->version == 0) { - $this->setCodePage(0, '-//SYNCML//DTD SyncML 1.0//EN', 'syncml:SYNCML1.0'); + #$this->setCodePage(0, '-//SYNCML//DTD SyncML 1.0//EN', 'syncml:SYNCML1.0'); + $this->setCodePage(0, '-//SYNCML//DTD SyncML 1.0//EN', 'syncml:syncml1.0'); $this->setCodePage(1, '-//SYNCML//DTD MetInf 1.0//EN', 'syncml:metinf'); $this->setURI('syncml:metinf'); } else { diff --git a/phpgwapi/inc/horde/XML/WBXML/Encoder.php b/phpgwapi/inc/horde/XML/WBXML/Encoder.php index 729c360f6c..8efe94e1d0 100644 --- a/phpgwapi/inc/horde/XML/WBXML/Encoder.php +++ b/phpgwapi/inc/horde/XML/WBXML/Encoder.php @@ -96,7 +96,6 @@ class XML_WBXML_Encoder extends XML_WBXML_ContentHandler { */ function writeHeader($uri) { - error_log("getInstanceURI($uri)"); $this->_dtd = &$this->_dtdManager->getInstanceURI($uri); $dpiString = $this->_dtd->getDPI(); @@ -213,8 +212,6 @@ class XML_WBXML_Encoder extends XML_WBXML_ContentHandler { function startElement($uri, $name, $attributes) { - error_log("startElement::: <$name>"); -# error_log(" subparser is:: ".$this->_subParser); if ($this->_subParser == null) { if (!$this->_hasWrittenHeader) { $this->writeHeader($uri); @@ -252,7 +249,6 @@ class XML_WBXML_Encoder extends XML_WBXML_ContentHandler { function characters($chars) { $chars = trim($chars); - error_log("characters ::: ".$chars); if (strlen($chars)) { /* We definitely don't want any whitespace. */ @@ -284,7 +280,6 @@ class XML_WBXML_Encoder extends XML_WBXML_ContentHandler { } $t = $this->_dtd->toTagInt($name); -# error_log("writeTag ::: -> $name $t"); if ($t == -1) { $i = $this->_stringTable->get($name); if ($i == null) { @@ -355,11 +350,8 @@ class XML_WBXML_Encoder extends XML_WBXML_ContentHandler { function endElement($uri, $name) { - error_log("endElement ::: "); -# error_log(" subparser is: ".$this->_subParser); if ($this->_subParser == null) { $this->_output .= chr(XML_WBXML_GLOBAL_TOKEN_END); -# error_log(" _output is: ".strlen($this->_output)); } else { $this->_subParser->endElement($uri, $name); $this->_subParserStack--; @@ -384,13 +376,12 @@ class XML_WBXML_Encoder extends XML_WBXML_ContentHandler { function changecodepage($uri) { -# error_log("changecodepage::: $uri"); // @todo: this is a hack! - if (!preg_match('/1\.1$/', $uri)) { + // what's the reason for this hack???? Lars + if ($uri != 'syncml:devinf' && $uri != 'syncml:metinf' && $uri != 'syncml:syncml1.0' && !preg_match('/1\.1$/', $uri)) { $uri .= '1.1'; } $cp = $this->_dtd->toCodePageURI($uri); -# error_log("--- \$cp:: $cp"); if (strlen($cp)) { $this->_dtd = &$this->_dtdManager->getInstanceURI($uri);