* Generate well-formed XML for Funambol and SyncEvolution clients (community bug#2975)

This commit is contained in:
Jörg Lehrke 2011-07-08 19:45:40 +00:00
parent 3e405cc1b7
commit d9581a6ff3
2 changed files with 129 additions and 130 deletions

View File

@ -32,21 +32,13 @@ class Horde_SyncML_Command_Sync_ContentSyncElement extends Horde_SyncML_Command_
}
$attrs = array();
$strict_xml = strtolower($this->_contentFormat) == 'strictxml';
$output->startElement($state->getURI(), $command, $attrs);
$output->startElement($state->getURI(), 'CmdID', $attrs);
$output->characters($currentCmdID);
$output->endElement($state->getURI(), 'CmdID');
/*
if (isset($this->_contentType)) {
$output->startElement($state->getURI(), 'Meta', $attrs);
$output->startElement($state->getURIMeta(), 'Type', $attrs);
$output->characters($this->_contentType);
$output->endElement($state->getURIMeta(), 'Type');
$output->endElement($state->getURI(), 'Meta');
}
*/
if (isset($this->_content) && !$this->_moreData) {
//$this->_content = trim($this->_content);
$this->_contentSize = strlen($this->_content);
@ -58,14 +50,15 @@ class Horde_SyncML_Command_Sync_ContentSyncElement extends Horde_SyncML_Command_
}
// <command><Meta>
if ($this->_contentSize || isset($this->_contentType) || isset($this->_contentFormat)) {
if ($this->_contentSize || isset($this->_contentType) ||
(!$strict_xml && isset($this->_contentFormat))) {
$output->startElement($state->getURI(), 'Meta', $attrs);
if (isset($this->_contentType)) {
$output->startElement($state->getURIMeta(), 'Type', $attrs);
$output->characters($this->_contentType);
$output->endElement($state->getURIMeta(), 'Type');
}
if (isset($this->_contentFormat)) {
if (!$strict_xml && isset($this->_contentFormat)) {
$output->startElement($state->getURIMeta(), 'Format', $attrs);
$output->characters($this->_contentFormat);
$output->endElement($state->getURIMeta(), 'Format');
@ -105,16 +98,15 @@ class Horde_SyncML_Command_Sync_ContentSyncElement extends Horde_SyncML_Command_
// <command><Item><Data>
if (isset($this->_content)) {
$output->startElement($state->getURI(), 'Data', $attrs);
#$chars = '<![CDATA['.$this->_content.']]>';
$currentSize = $output->getOutputSize();
Horde::logMessage("SyncML: $command: current = $currentSize, max = $maxMsgSize", __FILE__, __LINE__, PEAR_LOG_DEBUG);
if (!$maxMsgSize ||
(($currentSize + MIN_MSG_LEFT + $this->_contentSize) <= $maxMsgSize)) {
(($currentSize + MIN_MSG_LEFT + $this->_contentSize + 12) <= $maxMsgSize)) {
$chars = $this->_content;
unset($this->_content);
$this->_moreData = false;
} else {
$sizeLeft = $maxMsgSize - $currentSize - MIN_MSG_LEFT;
$sizeLeft = $maxMsgSize - $currentSize - MIN_MSG_LEFT - 12;
if ($sizeLeft < 0) {
Horde::logMessage("SyncML: $command: split with $currentSize for $maxMsgSize, increase MIN_MSG_LEFT!", __FILE__, __LINE__, PEAR_LOG_WARNING);
$sizeLeft = 0;
@ -132,6 +124,9 @@ class Horde_SyncML_Command_Sync_ContentSyncElement extends Horde_SyncML_Command_
. $chars, __FILE__, __LINE__, PEAR_LOG_DEBUG);
$this->_moreData = true;
}
if ($strict_xml) {
$chars = '<![CDATA['. $chars. ']]>';
}
$output->characters($chars);
$output->endElement($state->getURI(), 'Data');
@ -150,5 +145,4 @@ class Horde_SyncML_Command_Sync_ContentSyncElement extends Horde_SyncML_Command_
return $currentCmdID;
}
}

View File

@ -838,6 +838,8 @@ class Horde_SyncML_State {
$manufacturer = isset($deviceInfo['manufacturer']) ? strtolower($deviceInfo['manufacturer']) : 'unknown';
switch ($manufacturer) {
case 'funambol':
// Funambol requires well-formed XML
$res['ContentFormat'] = 'strictxml';
switch (strtolower($deviceInfo['model'])) {
case 'thunderbird':
case 'mozilla plugin':
@ -853,6 +855,9 @@ class Horde_SyncML_State {
break;
}
break;
case 'patrick ohly':
// SyncEvolution requires well-formed XML, too
$res['ContentFormat'] = 'strictxml';
default:
$res['mayFragment'] = 1;
break;