From a86affb697f66d23d3fcea9adf4fbad2a26fcd90 Mon Sep 17 00:00:00 2001 From: Patrick Bihan-Faou Date: Wed, 19 Dec 2007 07:44:09 +0000 Subject: [PATCH] Make the detection of the device types a little smarter and able to use out-of-band data such as the HTTP user agent. Use that to determine weither message fragmentation should be used or not. Indicate that Funambol 6+ supports fragmentation (this solves cases where big addressbooks cannot be syncrhonized because there are too many entries). --- .../inc/horde/Horde/SyncML/Command/Put.php | 45 +++++++++++ .../horde/Horde/SyncML/Command/Results.php | 59 +++++++++++--- phpgwapi/inc/horde/Horde/SyncML/State.php | 81 ++++++++----------- 3 files changed, 124 insertions(+), 61 deletions(-) diff --git a/phpgwapi/inc/horde/Horde/SyncML/Command/Put.php b/phpgwapi/inc/horde/Horde/SyncML/Command/Put.php index c87b8a83b3..fe9767423a 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/Command/Put.php +++ b/phpgwapi/inc/horde/Horde/SyncML/Command/Put.php @@ -193,6 +193,50 @@ class Horde_SyncML_Command_Put extends Horde_SyncML_Command { parent::endElement($uri, $element); } + function finalizeDeviceInfo() + { + // get some more information about the device from out of band data + + $ua = $_SERVER['HTTP_USER_AGENT']; + + if (preg_match("/^\s*Funambol (.*) (\d+\.\d+\.\d+)\s*$/i", $ua, $matches)) + { + if (!isset($this->_deviceInfo['manufacturer'])) + $this->_deviceInfo['manufacturer'] = 'Funambol'; + if (!isset($this->_deviceInfo['model'])) + $this->_deviceInfo['model'] = 'Funambol ' . trim($matches[1]); + if (!isset($this->_deviceInfo['softwareVersion'])) + $this->_deviceInfo['softwareVersion'] = $matches[2]; + + if (!isset($this->_deviceInfo['deviceType'])) + { + switch (strtolower(trim($matches[1]))) + { + case 'outlook plug-in' + default: + $this->_deviceInfo['deviceType'] = 'workstation'; + break; + case 'pocket pc plug-in' + $this->_deviceInfo['deviceType'] = 'windowsmobile'; + break; + } + } + } + + $devid = $this->_deviceInfo['deviceID']; + switch (strtolower($devid)) + { + case 'fmz-thunderbird-plugin': + if (empty($this->_devinceInfo['manufacturer'])) + $this->_deviceInfo['manufacturer'] = 'Funambol'; + if (empty($this->_devinceInfo['model'])) + $this->_deviceInfo['model'] = 'ThunderBird'; + if (empty($this->_devinceInfo['softwareVersion'])) + $this->_deviceInfo['softwareVersion'] = '0.3'; + break; + } + } + function output($currentCmdID, &$output ) { $state = &$_SESSION['SyncML.state']; @@ -204,6 +248,7 @@ class Horde_SyncML_Command_Put extends Horde_SyncML_Command { $status->setSourceRef($ref); if($state->isAuthorized()) { + $this->finalizeDeviceInfo(); if(count((array)$this->_deviceInfo) > 0) { $state->setClientDeviceInfo($this->_deviceInfo); $state->writeClientDeviceInfo(); diff --git a/phpgwapi/inc/horde/Horde/SyncML/Command/Results.php b/phpgwapi/inc/horde/Horde/SyncML/Command/Results.php index 40f1c68952..e608a528ca 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/Command/Results.php +++ b/phpgwapi/inc/horde/Horde/SyncML/Command/Results.php @@ -40,19 +40,7 @@ class Horde_SyncML_Command_Results extends Horde_SyncML_Command { break; case 'DevID': - $devid = trim($this->_chars); - $this->_deviceInfo['deviceID'] = $devid; - switch ($devid) - { - case 'fmz-thunderbird-plugin': - if (empty($this->_devinceInfo['manufacturer'])) - $this->_deviceInfo['manufacturer'] = 'funambol'; - if (empty($this->_devinceInfo['model'])) - $this->_deviceInfo['model'] = 'thunderbird'; - if (empty($this->_devinceInfo['softwareVersion'])) - $this->_deviceInfo['softwareVersion'] = '0.3'; - break; - } + $this->_deviceInfo['deviceID'] = trim($this->_chars); break; case 'DevTyp': @@ -146,6 +134,50 @@ class Horde_SyncML_Command_Results extends Horde_SyncML_Command { parent::endElement($uri, $element); } + + function finalizeDeviceInfo() + { + // get some more information about the device from out of band data + + $ua = $_SERVER['HTTP_USER_AGENT']; + + if (preg_match("/^\s*Funambol (.*) (\d+\.\d+\.\d+)\s*$/i", $ua, $matches)) + { + if (!isset($this->_deviceInfo['manufacturer'])) + $this->_deviceInfo['manufacturer'] = 'Funambol'; + if (!isset($this->_deviceInfo['model'])) + $this->_deviceInfo['model'] = 'Funambol ' . trim($matches[1]); + if (!isset($this->_deviceInfo['softwareVersion'])) + $this->_deviceInfo['softwareVersion'] = $matches[2]; + + if (!isset($this->_deviceInfo['deviceType'])) + { + switch (strtolower(trim($matches[1]))) + { + case 'outlook plug-in' + default: + $this->_deviceInfo['deviceType'] = 'workstation'; + break; + case 'pocket pc plug-in' + $this->_deviceInfo['deviceType'] = 'windowsmobile'; + break; + } + } + } + + $devid = $this->_deviceInfo['deviceID']; + switch (strtolower($devid)) + { + case 'fmz-thunderbird-plugin': + if (empty($this->_devinceInfo['manufacturer'])) + $this->_deviceInfo['manufacturer'] = 'Funambol'; + if (empty($this->_devinceInfo['model'])) + $this->_deviceInfo['model'] = 'ThunderBird'; + if (empty($this->_devinceInfo['softwareVersion'])) + $this->_deviceInfo['softwareVersion'] = '0.3'; + break; + } + } function output($currentCmdID, &$output) { if(!isset($this->_locSourceURI)) { @@ -160,6 +192,7 @@ class Horde_SyncML_Command_Results extends Horde_SyncML_Command { $status->setSourceRef($ref); if($state->isAuthorized()) { + $this->finalizeDeviceInfo(); if(count((array)$this->_deviceInfo) > 0) { $state->setClientDeviceInfo($this->_deviceInfo); $state->writeClientDeviceInfo(); diff --git a/phpgwapi/inc/horde/Horde/SyncML/State.php b/phpgwapi/inc/horde/Horde/SyncML/State.php index 7cb93898f8..df1c356b85 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/State.php +++ b/phpgwapi/inc/horde/Horde/SyncML/State.php @@ -670,62 +670,47 @@ class Horde_SyncML_State { $res['ContentType'] = $ctype; } + $deviceInfo = $this->getClientDeviceInfo(); + + if (isset($deviceInfo['manufacturer'])) + { + switch (strtolower($deviceInfo['manufacturer'])) + { + case 'funambol': + if (strtolower($deviceInfo['model']) == 'thunderbird') + { + $res['mayFragment'] = 1; + } + + if (isset($deviceInfo['softwareVersion']) + && $deviceInfo['softwareVersion']{0} == '3') + { + // anything beyond 6.0 supports fragmentation + $res['mayFragment'] = 0; + } + else + { + $res['mayFragment'] = 1; + } + break; + } + } + + if (!isset($res['mayFragment'])) + { + $res['mayFragment'] = 1; + } + + + // the funambol specific types need to be encoded in base 64 switch(strtolower($ctype)) { - case 'text/x-vcard': - case 'text/x-vcalendar': - case 'text/x-vnote': - case 'text/calendar': - case 'text/plain': - $res['mayFragment'] = 1; - break; - case 'text/x-s4j-sifc': case 'text/x-s4j-sife': case 'text/x-s4j-sift': case 'text/x-s4j-sifn': $res['ContentFormat'] = 'b64'; - $res['mayFragment'] = 0; break; - - default: - Horde::logMessage("SyncML: unrecognized content type '$ctype'", __FILE__, __LINE__, PEAR_LOG_ERR); - break; - } - - if ($target != null) - { - $_target = str_replace('./','',$target); - switch(strtolower($_target)) - { - case 'calendar': - case 'tasks': - case 'caltasks': - case 'notes': - case 'contacts': - $res['mayFragment'] = 1; - break; - - case 'sifcalendar': - case 'siftasks': - case 'sifnotes': - case 'sifcontacts': - case 'scard': - case 'scal': - case 'stask': - case 'snote': - $res['mayFragment'] = 0; - break; - - default: - Horde::logMessage("SyncML: unrecognized target '$_target'", __FILE__, __LINE__, PEAR_LOG_ERR); - break; - } - } - - if (!isset($res['mayFragment'])) - { - $res['mayFragment'] = 0; } return $res;