public function handleEnd()
{
global $messageFull;
$state = $GLOBALS['backend']->state;
/* If there's pending sync data and space left in the message, send
* data now. */
if ($messageFull || $state->hasPendingSyncs()) {
/* still something to do: don't close session. */
$GLOBALS['message_expectresponse'] = true;
}
if (!$messageFull && count($p = $state->getPendingSyncs()) > 0) {
foreach ($p as $pendingSync) {
if (!$messageFull) {
$GLOBALS['backend']->logMessage('Continuing sync for syncType ' . $pendingSync, 'DEBUG');
$sync =& $state->getSync($pendingSync);
$sync->createSyncOutput($this->_xmlWriter);
}
}
}
if (isset($state->curSyncItem)) {
$this->_xmlWriter->outputAlert(Horde_SyncMl::ALERT_NO_END_OF_DATA, $state->curSyncItem->sync->getClientLocURI(), $state->curSyncItem->sync->getServerLocURI(), $state->curSyncItem->sync->getServerAnchorLast(), $state->curSyncItem->sync->getServerAnchorNext());
}
/* Don't send the final tag if we haven't sent all sync data yet. */
if ($this->_gotFinal) {
if (!$messageFull && !$state->hasPendingSyncs()) {
/* Create <Final></Final>. */
$this->_xmlWriter->outputFinal();
$GLOBALS['backend']->logMessage('Sending <Final> to client', 'DEBUG');
$state->delayedFinal = false;
} else {
$GLOBALS['message_expectresponse'] = true;
/* Remember to send a Final. */
$state->delayedFinal = true;
}
} elseif ($state->delayedFinal) {
if (!$messageFull && !$state->hasPendingSyncs()) {
/* Create <Final></Final>. */
$this->_xmlWriter->outputFinal();
$GLOBALS['backend']->logMessage('Sending delayed <Final> to client', 'DEBUG');
$state->delayedFinal = false;
} else {
$GLOBALS['message_expectresponse'] = true;
}
}
/* Create </SyncML>. Message is finished now! */
$this->_xmlWriter->outputEnd();
if ($this->_gotFinal && !$GLOBALS['message_expectresponse'] && $state->isAllSyncsComplete()) {
/* This packet did not contain any real actions, just status and
* map. This means we're done. The session can be closed and the
* anchors saved for the next sync. */
foreach ($state->getSyncs() as $sync) {
$sync->closeSync();
}
$GLOBALS['backend']->logMessage('Session completed and closed', 'DEBUG');
/* Session can be closed here. */
$GLOBALS['backend']->sessionClose();
} else {
$GLOBALS['backend']->logMessage('Return message completed', 'DEBUG');
}
}