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 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
|
<?php
require_once 'SyncML/DeviceInfo.php';
require_once 'SyncML/Device.php';
require_once 'SyncML/Constants.php';
/**
* The SyncML_State class provides a SyncML state object.
*
* $Horde: framework/SyncML/SyncML/State.php,v 1.17.2.8 2006/01/01 21:28:36 jan Exp $
*
* Copyright 2003-2006 Anthony Mills <amills@pyramid6.com>
*
* 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>
* @since Horde 3.0
* @package SyncML
*/
class SyncML_State {
/**
* Session id of this session.
*/
var $_sessionID;
/**
* Id of current message.
*/
var $_msgID;
/**
* The target URI as sent by the client. This is normally the URL
* of the Horde rpc server. However the client is free to send
* anything: sync4j for example does not send the path part.
*/
var $_targetURI;
/**
* The source URI as sent by the client. Can be used to identify
* the client; the session id is constructed mainly from this
* data.
*/
var $_sourceURI;
/**
* 0 for syncml 1.0, 1 for syncml 1.1.
*/
var $_version;
/**
* Username used to auth with the backend.
*/
var $_locName;
/**
* Password used to auth with the backend.
*/
var $_password;
/**
* True means that this session has authenticated successfully.
*/
var $_isAuthorized;
/**
* Namespace information.
*/
var $_uri;
/**
* Namespace information.
*/
var $_uriMeta;
/**
* Namespace information.
*/
var $_uriDevInf;
var $_wbxml; // boolean
var $_maxMsgSize;
var $_syncs = array();
/**
* Written to db after successful sync.
*/
var $_clientAnchorNext = array();
var $_serverAnchorLast = array();
/**
* Written to db after successful sync.
*/
var $_serverAnchorNext = array();
/**
* Small hash to store the number of adds, deletes, etc. during a
* session for creation of summary for logfile.
*/
var $_log = array();
/**
* The SyncML_Device class defined in Device.php. This class
* handles decice specific stuff.
*/
var $_device;
/**
* Device info provided by the SyncML DevInf data. Mainly used by
* the SyncML_Device class.
*/
var $_deviceInfo;
/**
* If we are expecting a Result packet, this stores where to
* route it.
*/
var $_expectedResult = array();
/**
* Creates a new instance of SyncML_State.
*/
function SyncML_State($sourceURI, $locName, $sessionID, $password = false)
{
$this->setSourceURI($sourceURI);
$this->setLocName($locName);
$this->setSessionID($sessionID);
if ($password) {
$this->setPassword($password);
}
$this->isAuthorized = false;
// Create empty dummy device info. Will be replaced with real
// DevInf information if they are transferred.
$this->_deviceInfo = &new SyncML_DeviceInfo();
/* allow very big messages unless told otherwise: */
$this->setMaxMsgSize(1000000000);
}
function setDeviceInfo($di)
{
$this->_deviceInfo = $di;
}
function getDeviceInfo()
{
return $this->_deviceInfo;
}
function getLocName()
{
return $this->_locName;
}
function getSourceURI()
{
return $this->_sourceURI;
}
function getTargetURI()
{
return $this->_targetURI;
}
function getVersion()
{
return $this->_version;
}
function getMsgID()
{
return $this->_msgID;
}
function setWBXML($wbxml)
{
$this->_wbxml = $wbxml;
}
function isWBXML()
{
return !empty($this->_wbxml);
}
function setMaxMsgSize($s)
{
$this->_maxMsgSize = $s;
}
function getMaxMsgSize()
{
return $this->_maxMsgSize;
}
/**
* Setter for property msgID.
*
* @param string $msgID New value of property msgID.
*/
function setMsgID($msgID)
{
$this->_msgID = $msgID;
}
/**
* Setter for property locName.
*
* @param string $locName New value of property locName.
*/
function setLocName($locName)
{
$this->_locName = $locName;
}
function setPassword($password)
{
$this->_password = $password;
}
function setSourceURI($sourceURI)
{
$this->_sourceURI = $sourceURI;
}
function setTargetURI($targetURI)
{
$this->_targetURI = $targetURI;
}
function setVersion($version)
{
$this->_version = $version;
if ($version == 0) {
$this->_uri = NAME_SPACE_URI_SYNCML;
$this->_uriMeta = NAME_SPACE_URI_METINF;
$this->_uriDevInf = NAME_SPACE_URI_DEVINF;
} else {
$this->_uri = NAME_SPACE_URI_SYNCML_1_1;
$this->_uriMeta = NAME_SPACE_URI_METINF_1_1;
$this->_uriDevInf = NAME_SPACE_URI_DEVINF_1_1;
}
}
function setSessionID($sessionID)
{
$this->_sessionID = $sessionID;
}
function isAuthorized()
{
if (!$this->_isAuthorized && !empty($this->_password)) {
$GLOBALS['backend']->logMessage('checking auth for user='
. $this->_locName,
__FILE__, __LINE__, PEAR_LOG_DEBUG);
$auth = &Auth::singleton($GLOBALS['conf']['auth']['driver']);
$this->_isAuthorized = $auth->authenticate($this->_locName, array('password' => $this->_password));
}
return $this->_isAuthorized;
}
function setSync($target, &$sync)
{
$this->_syncs[$target] = &$sync;
}
function &getSync($target)
{
if (isset($this->_syncs[$target])) {
return $this->_syncs[$target];
} else {
$false = false;
return $false;
}
}
function getURI()
{
/*
* The non WBXML devices (notably P900 and Sync4j seem to get confused
* by a <SyncML xmlns="syncml:SYNCML1.1"> element. They require
* just <SyncML>. So don't use an ns for non wbxml devices.
*/
if ($this->isWBXML()) {
return $this->_uri;
} else {
return '';
}
}
function getURIMeta()
{
return $this->_uriMeta;
}
function getURIDevInf()
{
return $this->_uriDevInf;
}
function setClientAnchorNext($type, $a)
{
$this->_clientAnchorNext[$type] = $a;
}
function setServerAnchorLast($type, $a)
{
$this->_serverAnchorLast[$type] = $a;
}
function setServerAnchorNext($type, $a)
{
$this->_serverAnchorNext[$type] = $a;
}
function getClientAnchorNext($type)
{
return $this->_clientAnchorNext[$type];
}
function getServerAnchorNext($type)
{
return $this->_serverAnchorNext[$type];
}
function getServerAnchorLast($type)
{
return $this->_serverAnchorLast[$type];
}
/**
* The log simply counts the entries for each topic.
*/
function log($topic)
{
if (isset($this->_log[$topic])) {
$this->_log[$topic] += 1;
} else {
$this->_log[$topic] = 1;
}
}
/**
* The Log is an array where the key is the event name and the
* value says how often this event occured.
*/
function getLog()
{
return $this->_log;
}
/**
* Returns an identifier used to identify the sync device in the
* map. Currently "locname:sourceURI".
*/
function getSyncIdentifier()
{
return str_replace(':', '_', $this->_locName)
. ':'
. str_replace(':', '_', $this->_sourceURI);
}
function &getDevice()
{
return SyncML_Device::singleton();
}
/**
* Returns the expected result type for a Results tag, used to redirect the
* incoming command somewhere special. For example, if we have requested
* device info, the Results tag should be sent to the Put command so we can
* read it in.
*
* Clears the hash of this Command Reference before returning a value.
*
* @param integer $cmdRef The CmdRef of the incoming command.
*
* @return string The command type to redirect to, or
* undefined if no redirect registered.
*/
function getExpectedResultType($cmdRef)
{
if ( isset($this->_expectedResult[$cmdRef]) ) {
$cmdType = $this->_expectedResult[$cmdRef];
unset($this->_expectedResult[$cmdRef]);
}
return $cmdType;
}
/**
* Sets up a command redirection for a future Result command.
*
* @param integer $cmdID The CmdID of the command we are sending to
* the client.
* @param string $cmdType The type of command to redirect to when
* the Results command is received.
*/
function setExpectedResultType($cmdID, $cmdType)
{
$this->_expectedResult[$cmdID] = $cmdType;
}
/**
* Check if there are any pending elements that have not been sent to due
* to message sitze restrictions. These will be sent int the next msg.
*
*/
function hasPendingElements()
{
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.
* Returns an array of TargetLocURIs which can be used
* as a key in getSync calls.
*/
function getPendingSyncs()
{
$r = array();
if (is_array($this->_syncs)) {
foreach ($this->_syncs as $target => $sync) {
if ($sync->hasPendingElements()) {
$r[] = $target;
}
}
}
return $r;
}
}
|