<?php
/**
- * There are two global objects that are used by SyncML:
- * 1) $_SESSION['SyncML.state']:
- * session object used to maintain the state between the individual
- * SyncML messages.
- *
- * 2) $GLOBALS['backend']
+ * There is one global object used by SyncML:
+ * 1) $GLOBALS['backend']
* Backend to handle the communication with the datastore.
*
* @todo: Main Todos:
/* Start the session. */
$hdr->setupState();
- $state = &$_SESSION['SyncML.state'];
+ $state = $GLOBALS['backend']->state;
$state->wbxml = $this->_xmlWriter->isWBXML();
/* Check auth. */
{
global $messageFull;
- $state = &$_SESSION['SyncML.state'];
+ $state = $GLOBALS['backend']->state;
/* If there's pending sync data and space left in the message, send
* data now. */
class SyncML_Backend {
/**
+ * The State object.
+ *
+ * @var SyncML_State
+ */
+ var $state;
+
+ /**
* The concatenated log messages.
*
* @var string
/**
* Is called after the SyncML_State object has been set up, either
* restored from the session, or freshly created.
- *
- * @param SyncML_State The current state object.
*/
- function setupState(&$state)
+ function setupState()
{
}
$backendMode = SYNCML_BACKENDMODE_SERVER)
{
$this->_backendMode = $backendMode;
+ $this->_syncDeviceID = $syncDeviceID;
/* Only the server needs to start a session. */
if ($this->_backendMode == SYNCML_BACKENDMODE_SERVER) {
/* Reload the Horde SessionHandler if necessary. */
- $GLOBALS['session'] = new Horde_Session();
$GLOBALS['session']->setup(false);
+ $this->state = $GLOBALS['session']->get('horde', 'syncml');
+ register_shutdown_function(array($this, 'sessionShutdown'));
}
+ }
- parent::sessionStart($syncDeviceID, $sessionId, $backendMode);
+ function sessionShutdown()
+ {
+ if ($this->state) {
+ $GLOBALS['session']->set('horde', 'syncml', $this->state);
+ }
}
/**
*/
function handleCommand($debug = false)
{
- $state = &$_SESSION['SyncML.state'];
+ $state = $GLOBALS['backend']->state;
+
// Handle unauthenticated first.
if (!$state->authenticated) {
$this->_outputHandler->outputStatus($this->_cmdID, $this->_cmdName,
*/
function handleCommand($debug = false)
{
- $state = &$_SESSION['SyncML.state'];
+ $state = $GLOBALS['backend']->state;
// If the client hasn't sent us device info, request it now.
// @todo: only do this once, not in every msg if the client does not
*/
function handleCommand($debug = false)
{
- $state = &$_SESSION['SyncML.state'];
+ $state = $GLOBALS['backend']->state;
// Create status response.
$this->_outputHandler->outputStatus($this->_cmdID, $this->_cmdName,
function handleCommand($debug = false)
{
if (!$debug && $this->_mapSources) {
- $state = &$_SESSION['SyncML.state'];
+ $state = $GLOBALS['backend']->state;
$sync = &$state->getSync($this->_targetLocURI);
if (!$state->authenticated) {
$GLOBALS['backend']->logMessage(
*/
function handleCommand($debug = false)
{
- $state = &$_SESSION['SyncML.state'];
+ $state = $GLOBALS['backend']->state;
// Store received data.
$state->deviceInfo = $this->_devinf;
break;
case 1:
- $state = &$_SESSION['SyncML.state'];
+ $state = $GLOBALS['backend']->state;
switch ($this->_Cmd) {
case 'Replace':
case 'Add':
function startElement($uri, $element, $attrs)
{
parent::startElement($uri, $element, $attrs);
- $state = &$_SESSION['SyncML.state'];
+ $state = $GLOBALS['backend']->state;
switch (count($this->_stack)) {
case 2:
case 'Item':
if ($this->_itemMoreData) {
// Store to continue in next session.
- $_SESSION['SyncML.state']->curSyncItem = $this->_curItem;
+ $GLOBALS['backend']->state->curSyncItem = $this->_curItem;
} else {
// Finished. Store to syncElements[].
if (empty($this->_curItem->contentType)) {
*/
function handleCommand($debug = false)
{
- $state = &$_SESSION['SyncML.state'];
+ $state = $GLOBALS['backend']->state;
// Handle unauthenticated first.
if (!$state->authenticated) {
*/
function setupState()
{
- $GLOBALS['backend']->sessionStart($this->_sourceURI,
- $this->_sessionID);
+ global $backend;
- if (!isset($_SESSION['SyncML.state'])) {
- $GLOBALS['backend']->logMessage(
+ $backend->sessionStart($this->_sourceURI, $this->_sessionID);
+
+ if (!$backend->state) {
+ $backend->logMessage(
'New session created: ' . session_id(), 'DEBUG');
- $_SESSION['SyncML.state'] = new SyncML_State($this->_sourceURI,
- $this->user,
- $this->_sessionID);
+ $backend->state = new SyncML_State($this->_sourceURI,
+ $this->user,
+ $this->_sessionID);
} else {
- $GLOBALS['backend']->logMessage(
- 'Existing session continued: ' . session_id(), 'DEBUG');
+ $backend->logMessage('Existing session continued: ' . session_id(), 'DEBUG');
}
- $state = &$_SESSION['SyncML.state'];
- $state->setVersion($this->_version);
- $state->messageID = $this->_message;
- $state->targetURI = $this->_targetURI;
- $state->sourceURI = $this->_sourceURI;
- $state->sessionID = $this->_sessionID;
+ $backend->state->setVersion($this->_version);
+ $backend->state->messageID = $this->_message;
+ $backend->state->targetURI = $this->_targetURI;
+ $backend->state->sourceURI = $this->_sourceURI;
+ $backend->state->sessionID = $this->_sessionID;
if (!empty($this->_maxMsgSize)) {
- $state->maxMsgSize = $this->_maxMsgSize;
+ $backend->state->maxMsgSize = $this->_maxMsgSize;
}
- $GLOBALS['backend']->setupState($state);
+ $backend->setupState();
}
}
*/
function getPreferredContentTypeClient($serverSyncURI, $sourceSyncURI)
{
- $di = $_SESSION['SyncML.state']->deviceInfo;
+ $di = $GLOBALS['backend']->state->deviceInfo;
$ds = $di->getDataStore($sourceSyncURI);
if (!empty($ds)) {
$r = $ds->getPreferredRXContentType();
/* At least the Nokia E series seems to prefix category values with
* X-, see bugs #6849 and #7824. */
- $di = $_SESSION['SyncML.state']->deviceInfo;
+ $di = $GLOBALS['backend']->state->deviceInfo;
if ($di->Mod[0] == 'E') {
$content = preg_replace('/(\r\n|\r|\n)CATEGORIES:X-/',
'\1CATEGORIES:', $content, 1);
*/
function handleTasksInCalendar()
{
- $di = $_SESSION['SyncML.state']->deviceInfo;
+ $di = $GLOBALS['backend']->state->deviceInfo;
if (isset($di->CTCaps['text/x-vcalendar']) &&
!empty($di->CTCaps['text/x-vcalendar']['BEGIN']->ValEnum['VEVENT']) &&
case 'text/calendar':
case 'text/x-vcalendar':
- $si = $_SESSION['SyncML.state']->sourceURI;
+ $si = $GLOBALS['backend']->state->sourceURI;
if (stristr($si, 'fol-') !== false) {
// The Funambol Outlook connector uses invalid STATUS
// values. Actually it maps MeetingStatus values of the
if ($this->requestedContentType == $contentType) {
if ($contentType == 'text/calendar' ||
$contentType == 'text/x-vcalendar') {
- $si = $_SESSION['SyncML.state']->sourceURI;
+ $si = $GLOBALS['backend']->state->sourceURI;
if (stristr($si, 'fol-') !== false) {
// The Funambol Outlook connector uses invalid STATUS
// values. Actually it maps MeetingStatus values of the
list($content, $contentType, $encodingType) =
parent::convertServer2Client($content, $contentType, $database);
- $di = $_SESSION['SyncML.state']->deviceInfo;
+ $di = $GLOBALS['backend']->state->deviceInfo;
if (stristr($di->Mod,'palm') === false) {
// Some special priority handling is required. Synthesis uses
// 1 (high), 2 (medium), 3(low), at least for my windows mobile device.
list($content, $contentType) =
parent::convertClient2Server($content, $contentType);
- $di = $_SESSION['SyncML.state']->deviceInfo;
+ $di = $GLOBALS['backend']->state->deviceInfo;
if (stristr($di->Mod, 'palm') === false) {
// Some special priority handling is required. Synthesis uses 1
// (high), 2 (medium), 3(low), at least for my windows mobile
}
}
- $device = $_SESSION['SyncML.state']->getDevice();
+ $device = $GLOBALS['backend']->state->getDevice();
$hordedatabase = $database = $this->_targetLocURI;
$content = $item->content;
if ($item->contentFormat == 'b64') {
if (($item->contentType == 'text/calendar' ||
$item->contentType == 'text/x-vcalendar') &&
- $backend->_normalize($database) == 'calendar' &&
+ $backend->_normalize($database) == 'calendar' &&
$device->handleTasksInCalendar()) {
$tasksincalendar = true;
/* Check if the client sends us a vtodo in a calendar sync. */
* pending Sync data, the final command will sent the pending data. */
$messageFull = false;
- $state = &$_SESSION['SyncML.state'];
+ $state = $GLOBALS['backend']->state;
$device = $state->getDevice();
$contentType = $device->getPreferredContentTypeClient(
$this->_targetLocURI, $this->_sourceLocURI);
function createUidMap($databaseURI, $cuid, $suid)
{
- $device = $_SESSION['SyncML.state']->getDevice();
+ $device = $GLOBALS['backend']->state->getDevice();
if ($GLOBALS['backend']->_normalize($databaseURI) == 'calendar' &&
$device->handleTasksInCalendar() &&
$GLOBALS['backend']->logMessage(
'Created map for client id ' . $cuid . ' and server id ' . $suid
. ' in database ' . $db, 'DEBUG');
-
}
/**
*/
function outputHeader($respURI)
{
- $state = &$_SESSION['SyncML.state'];
+ $state = $GLOBALS['backend']->state;
+
$this->_uriMeta = $state->uriMeta;
$this->_output->startElement($this->_uri, 'SyncHdr');
function outputInit()
{
- $this->_uri = $_SESSION['SyncML.state']->getURI();
+ $this->_uri = $GLOBALS['backend']->state->getURI();
$this->_output->startElement($this->_uri, 'SyncML', array());
}
$syncAnchorNext = '',
$syncAnchorLast = '')
{
- $state = &$_SESSION['SyncML.state'];
+ $state = $GLOBALS['backend']->state;
$uriMeta = $state->uriMeta;
$this->_output->startElement($this->_uri, 'Status');
function outputDevInf($cmdRef)
{
- $state = &$_SESSION['SyncML.state'];
+ $state = $GLOBALS['backend']->state;
$uriMeta = $state->uriMeta;
$uriDevInf = $state->uriDevInf;
function _writeDataStore($sourceref, $mimetype, $version, &$output,
$additionaltypes = array())
{
- $uriDevInf = $_SESSION['SyncML.state']->uriDevInf;
+ $uriDevInf = $GLOBALS['backend']->state->uriDevInf;
$output->startElement($uriDevInf , 'DataStore');
$output->startElement($uriDevInf , 'SourceRef');
function outputAlert($alertCode, $clientDB = '', $serverDB = '', $lastAnchor = '', $nextAnchor = '')
{
- $uriMeta = $_SESSION['SyncML.state']->uriMeta;
+ $uriMeta = $GLOBALS['backend']->state->uriMeta;
$this->_output->startElement($this->_uri, 'Alert');
$this->_outputCmdID();
// MaxObjSize, required by protocol for SyncML1.1 and higher.
- if ($_SESSION['SyncML.state']->version > 0) {
+ if ($GLOBALS['backend']->state->version > 0) {
$this->_output->startElement($uriMeta, 'MaxObjSize');
$this->_output->characters(SERVER_MAXOBJSIZE);
$this->_output->endElement($uriMeta, 'MaxObjSize');
function outputGetDevInf()
{
- $state = &$_SESSION['SyncML.state'];
+ $state = $GLOBALS['backend']->state;
$uriMeta = $state->uriMeta;
$this->_output->startElement($this->_uri, 'Get');
function outputSyncCommand($command, $content = null, $contentType = null,
$encodingType = null, $cuid = null, $suid = null)
{
- $uriMeta = $_SESSION['SyncML.state']->uriMeta;
+ $uriMeta = $GLOBALS['backend']->state->uriMeta;
$this->_output->startElement($this->_uri, $command);
$this->_outputCmdID();
if($this->isWBXML()) {
$this->_output->characters($content);
} else {
- $device = $_SESSION['SyncML.state']->getDevice();
+ $device = $GLOBALS['backend']->state->getDevice();
if ($device->useCdataTag()) {
/* Enclose data in CDATA if possible to avoid */
/* problems with &,< and >. */
return strlen($username) ? $username : true;
}
- function setupState(&$state)
+ function setupState()
{
- $state->user = 'dummyUser';
- $state->authenticated = true;
+ $this->state->user = 'dummyUser';
+ $this->state->authenticated = true;
}
function addEntry($databaseURI, $content, $contentType, $cuid)