1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
|
<?php
/* Load all libraries that we need immediately or when deserializing the
* SyncML_State object and its property objects from the session. */
require_once 'SyncML/DeviceInfo.php';
require_once 'SyncML/Device.php';
require_once 'SyncML/Constants.php';
require_once 'SyncML/Command/SyncElement.php';
/**
* The SyncML_State class provides a SyncML state object.
*
* $Horde: framework/SyncML/SyncML/State.php,v 1.17.2.19 2009/04/07 11:12:54 jan Exp $
*
* Copyright 2003-2009 The Horde Project (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Anthony Mills <amills@pyramid6.com>
* @author Jan Schneider <jan@horde.org>
* @since Horde 3.0
* @package SyncML
*/
class SyncML_State {
/**
* Id of this SyncML session.
*
* This is not to confuse with the PHP session id, though it is part of
* the generated PHP session id.
*
* @var string
*/
var $sessionID;
/**
* Id of the current message.
*
* @var integer
*/
var $messageID;
/**
* The target URI as sent by the client.
*
* This is normally the URL of the RPC server. However the client is
* free to send anything.
*
* @var string
*/
var $targetURI;
/**
* The source URI as sent by the client.
*
* Can be used to identify the client and is part of the PHP session id.
*
* @var string
*/
var $sourceURI;
/**
* SyncML protocol version.
*
* 0 for SyncML 1.0, 1 for SyncML 1.1, etc.
*
* @var integer
*/
var $version;
/**
* Username used to authenticate with the backend.
*
* @var string
*/
var $user;
/**
* Whether this session has authenticated successfully.
*
* @var boolean
*/
var $authenticated = false;
/**
* <SyncML> namespace uri.
*
* @var string
*/
var $_uri;
/**
* <Meta> namespace uri.
*
* @var string
*/
var $uriMeta;
/**
* <DevInf> namespace uri.
*
* @var string
*/
var $uriDevInf;
/**
* Whether WBXML encoding is used.
*
* @var boolean
*/
var $wbxml = false;
/**
* The maximum allowed message size in bytes.
*
* @todo Change to PHP_INT_MAX.
*
* @var integer
*/
var $maxMsgSize = 1000000000;
/**
* Array of SyncML_Sync objects.
*
* @var array
*/
var $_syncs = array();
/**
* The list of all server changes being sent to the client as a reference
* for Status responses from the client.
*
* @var array
*/
var $serverChanges = array();
/**
* Name of the appropriate device driver.
*
* @var string
*/
var $_deviceDriver;
/**
* Device info provided by the SyncML DevInf data.
*
* @var SyncML_DeviceInfo
*/
var $deviceInfo;
/**
* Current sync element sent from client.
*
* Stored in state if one element is split into multiple message packets.
*
* @var SyncML_SyncElement
*/
var $curSyncItem;
/**
* Flag that is set if the client sends a Final but we are not finished
* with the current package and thus can't final this package yet.
*
* @var boolean
*/
var $delayedFinal = false;
/**
* Constructor.
*/
function SyncML_State($sourceURI, $user, $sessionID)
{
$this->sourceURI = $sourceURI;
$this->user = $user;
$this->sessionID = $sessionID;
/* Create empty dummy device info. Will be replaced with real DevInf
* information if provided by the client. */
$this->deviceInfo = new SyncML_DeviceInfo();
}
/**
* Returns the <DevInf><VerDTD> content based on the protocol version.
*/
function getVerDTD()
{
switch ($this->version) {
case 1:
return '1.1';
case 2:
return '1.2';
default:
return '1.0';
}
}
/**
* Returns the DevInf URI based on the protocol version.
*/
function getDevInfURI()
{
switch ($this->version) {
case 1:
return './devinf11';
case 2:
return './devinf12';
default:
return './devinf10';
}
}
/**
* Returns the protocol name based on the protocol version.
*/
function getProtocolName()
{
switch ($this->version) {
case 1:
return 'SyncML/1.1';
case 2:
return 'SyncML/1.2';
default:
return 'SyncML/1.0';
}
}
/**
* Sets the protocol version
*
* @param integer $version The protocol version: 0 for SyncML 1.0, 1 for
* SyncML 1.1 etc.
*/
function setVersion($version)
{
switch ($version) {
case 1:
$this->_uri = NAME_SPACE_URI_SYNCML_1_1;
$this->uriMeta = NAME_SPACE_URI_METINF_1_1;
$this->uriDevInf = NAME_SPACE_URI_DEVINF_1_1;
break;
case 2:
$this->_uri = NAME_SPACE_URI_SYNCML_1_2;
$this->uriMeta = NAME_SPACE_URI_METINF_1_2;
$this->uriDevInf = NAME_SPACE_URI_DEVINF_1_2;
break;
default:
$this->_uri = NAME_SPACE_URI_SYNCML;
$this->uriMeta = NAME_SPACE_URI_METINF;
$this->uriDevInf = NAME_SPACE_URI_DEVINF;
break;
}
$this->version = $version;
}
/**
* Returns the namespace URI for the <SyncML> element.
*
* @return string The namespace URI to use, if any.
*/
function getURI()
{
/* The non WBXML devices (notably SonyEricsson and Funambol) seem to
* get confused by a <SyncML xmlns="syncml:SYNCML1.1"> element. They
* require just <SyncML>. So don't use a namespace for non-wbxml
* devices. */
if ($this->wbxml || $this->version > 0) {
return $this->_uri;
} else {
return '';
}
}
/**
* Returns a SyncML_Device instance for the device used in this session.
*
* @return SyncML_Device A SyncML_Device instance.
*/
function getDevice()
{
if (empty($this->_deviceDriver)) {
$si = $this->sourceURI;
$di = $this->deviceInfo;
if (stristr($si, 'sync4j') !== false ||
stristr($si, 'sc-pim') !== false ||
stristr($si, 'fol-') !== false ||
stristr($si, 'fwm-') !== false ||
stristr($si, 'fbb-') !== false) {
$this->_deviceDriver = 'Sync4j';
} elseif (!empty($di->Man) &&
(stristr($di->Man, 'Sony Ericsson') !== false ||
stristr($di->Mod, 'A1000') !== false)) {
/* The Morola A1000 has a similar (UIQ) firmware as the
* P800: */
$this->_deviceDriver = 'P800';
} elseif (!empty($di->Man) &&
stristr($di->Man, 'synthesis') !== false) {
$this->_deviceDriver = 'Synthesis';
} elseif (!empty($di->Man) &&
stristr($di->Man, 'nokia') !== false) {
$this->_deviceDriver = 'Nokia';
} elseif (stristr($si, 'fmz-') !== false) {
$this->_deviceDriver = 'Sync4JMozilla';
} else {
$this->_deviceDriver = 'default';
}
}
return SyncML_Device::factory($this->_deviceDriver);
}
/**
* @param string $target
* @param SyncML_Sync $sync
*/
function setSync($target, &$sync)
{
$this->_syncs[$target] = &$sync;
}
/**
* @param string $target
* @return SyncML_Sync
*/
function &getSync($target)
{
if (isset($this->_syncs[$target])) {
return $this->_syncs[$target];
} else {
$sync = false;
return $sync;
}
}
/**
* @return array
*/
function &getSyncs()
{
return $this->_syncs;
}
/**
* Returns whether there are any pending elements that have not been sent
* to due to message size restrictions. These will be sent int the next
* message.
*
* @return boolean True if there are pending elements that have yet to be
* sent.
*/
function hasPendingSyncs()
{
if (is_array($this->_syncs)) {
foreach ($this->_syncs as $sync) {
if ($sync->hasPendingElements()) {
return true;
}
}
}
return false;
}
/**
* Returns all syncs which have pending elements left.
*
* @return array Array of TargetLocURIs which can be used as a key in
* getSync() calls.
*/
function getPendingSyncs()
{
$pending = array();
if (is_array($this->_syncs)) {
foreach ($this->_syncs as $target => $sync) {
if ($sync->hasPendingElements()) {
$pending[] = $target;
}
}
}
return $pending;
}
/**
* Returns whether all syncs are in completed state or no syncs are
* present.
*
* @return boolean True if all syncs are in completed state.
*/
function isAllSyncsComplete()
{
if (is_array($this->_syncs)) {
foreach ($this->_syncs as $target => $sync) {
if (!$sync->isComplete()) {
return false;
}
}
}
return true;
}
/**
* Propagates final tags here and then further to every sync.
*
* This allows the sync objects to determine if they are complete.
*/
function handleFinal(&$output, $debug = false)
{
if (is_array($this->_syncs)) {
foreach (array_keys($this->_syncs) as $t) {
$this->_syncs[$t]->handleFinal($output, $debug);
}
}
}
}
|