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).
This commit is contained in:
Patrick Bihan-Faou 2007-12-19 07:44:09 +00:00
parent ae9170ab85
commit a86affb697
3 changed files with 124 additions and 61 deletions

View File

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

View File

@ -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':
@ -147,6 +135,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)) {
#Horde::logMessage('SyncML: BIG TODO!!!!!!!!!!!!!!!!!! parse reply', __FILE__, __LINE__, PEAR_LOG_DEBUG);
@ -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();

View File

@ -670,62 +670,47 @@ class Horde_SyncML_State {
$res['ContentType'] = $ctype;
}
switch(strtolower($ctype))
$deviceInfo = $this->getClientDeviceInfo();
if (isset($deviceInfo['manufacturer']))
{
switch (strtolower($deviceInfo['manufacturer']))
{
case 'funambol':
if (strtolower($deviceInfo['model']) == 'thunderbird')
{
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)
if (isset($deviceInfo['softwareVersion'])
&& $deviceInfo['softwareVersion']{0} == '3')
{
$_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':
// anything beyond 6.0 supports fragmentation
$res['mayFragment'] = 0;
break;
default:
Horde::logMessage("SyncML: unrecognized target '$_target'", __FILE__, __LINE__, PEAR_LOG_ERR);
}
else
{
$res['mayFragment'] = 1;
}
break;
}
}
if (!isset($res['mayFragment']))
{
$res['mayFragment'] = 0;
$res['mayFragment'] = 1;
}
// the funambol specific types need to be encoded in base 64
switch(strtolower($ctype))
{
case 'text/x-s4j-sifc':
case 'text/x-s4j-sife':
case 'text/x-s4j-sift':
case 'text/x-s4j-sifn':
$res['ContentFormat'] = 'b64';
break;
}
return $res;