[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/SyncML/ -> State.php (source)

   1  <?php
   2  
   3  require_once 'SyncML/DeviceInfo.php';
   4  require_once 'SyncML/Device.php';
   5  require_once 'SyncML/Constants.php';
   6  
   7  /**
   8   * The SyncML_State class provides a SyncML state object.
   9   *
  10   * $Horde: framework/SyncML/SyncML/State.php,v 1.17.2.8 2006/01/01 21:28:36 jan Exp $
  11   *
  12   * Copyright 2003-2006 Anthony Mills <amills@pyramid6.com>
  13   *
  14   * See the enclosed file COPYING for license information (LGPL). If you
  15   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  16   *
  17   * @author  Anthony Mills <amills@pyramid6.com>
  18   * @since   Horde 3.0
  19   * @package SyncML
  20   */
  21  class SyncML_State {
  22  
  23      /**
  24       * Session id of this session.
  25       */
  26      var $_sessionID;
  27  
  28      /**
  29       * Id of current message.
  30       */
  31      var $_msgID;
  32  
  33      /**
  34       * The target URI as sent by the client. This is normally the URL
  35       * of the Horde rpc server. However the client is free to send
  36       * anything: sync4j for example does not send the path part.
  37       */
  38      var $_targetURI;
  39  
  40      /**
  41       * The source URI as sent by the client. Can be used to identify
  42       * the client; the session id is constructed mainly from this
  43       * data.
  44       */
  45      var $_sourceURI;
  46  
  47      /**
  48       * 0 for syncml 1.0, 1 for syncml 1.1.
  49       */
  50      var $_version;
  51  
  52      /**
  53       * Username used to auth with the backend.
  54       */
  55      var $_locName;
  56  
  57      /**
  58       * Password used to auth with the backend.
  59       */
  60      var $_password;
  61  
  62      /**
  63       * True means that this session has authenticated successfully.
  64       */
  65      var $_isAuthorized;
  66  
  67      /**
  68       * Namespace information.
  69       */
  70      var $_uri;
  71  
  72      /**
  73       * Namespace information.
  74       */
  75      var $_uriMeta;
  76  
  77      /**
  78       * Namespace information.
  79       */
  80      var $_uriDevInf;
  81  
  82      var $_wbxml; // boolean
  83  
  84      var $_maxMsgSize;
  85  
  86      var $_syncs = array();
  87  
  88      /**
  89       * Written to db after successful sync.
  90       */
  91      var $_clientAnchorNext = array();
  92  
  93      var $_serverAnchorLast = array();
  94  
  95      /**
  96       * Written to db after successful sync.
  97       */
  98      var $_serverAnchorNext = array();
  99  
 100      /**
 101       * Small hash to store the number of adds, deletes, etc. during a
 102       * session for creation of summary for logfile.
 103       */
 104      var $_log = array();
 105  
 106      /**
 107       * The SyncML_Device class defined in Device.php. This class
 108       * handles decice specific stuff.
 109       */
 110      var $_device;
 111  
 112      /**
 113       * Device info provided by the SyncML DevInf data. Mainly used by
 114       * the SyncML_Device class.
 115       */
 116      var $_deviceInfo;
 117  
 118      /**
 119       * If we are expecting a Result packet, this stores where to
 120       * route it.
 121       */
 122      var $_expectedResult = array();
 123  
 124      /**
 125       * Creates a new instance of SyncML_State.
 126       */
 127      function SyncML_State($sourceURI, $locName, $sessionID, $password = false)
 128      {
 129          $this->setSourceURI($sourceURI);
 130          $this->setLocName($locName);
 131          $this->setSessionID($sessionID);
 132          if ($password) {
 133              $this->setPassword($password);
 134          }
 135  
 136          $this->isAuthorized = false;
 137  
 138          // Create empty dummy device info. Will be replaced with real
 139          // DevInf information if they are transferred.
 140          $this->_deviceInfo = &new SyncML_DeviceInfo();
 141  
 142          /* allow very big messages unless told otherwise: */
 143          $this->setMaxMsgSize(1000000000);
 144      }
 145  
 146      function setDeviceInfo($di)
 147      {
 148          $this->_deviceInfo = $di;
 149      }
 150  
 151      function getDeviceInfo()
 152      {
 153          return $this->_deviceInfo;
 154      }
 155  
 156      function getLocName()
 157      {
 158          return $this->_locName;
 159      }
 160  
 161      function getSourceURI()
 162      {
 163          return $this->_sourceURI;
 164      }
 165  
 166      function getTargetURI()
 167      {
 168          return $this->_targetURI;
 169      }
 170  
 171      function getVersion()
 172      {
 173          return $this->_version;
 174      }
 175  
 176      function getMsgID()
 177      {
 178          return $this->_msgID;
 179      }
 180  
 181      function setWBXML($wbxml)
 182      {
 183          $this->_wbxml = $wbxml;
 184      }
 185  
 186      function isWBXML()
 187      {
 188          return !empty($this->_wbxml);
 189      }
 190  
 191      function setMaxMsgSize($s)
 192      {
 193          $this->_maxMsgSize = $s;
 194      }
 195  
 196      function getMaxMsgSize()
 197      {
 198          return $this->_maxMsgSize;
 199      }
 200  
 201      /**
 202       * Setter for property msgID.
 203       *
 204       * @param string $msgID  New value of property msgID.
 205       */
 206      function setMsgID($msgID)
 207      {
 208          $this->_msgID = $msgID;
 209      }
 210  
 211      /**
 212       * Setter for property locName.
 213       *
 214       * @param string $locName  New value of property locName.
 215       */
 216      function setLocName($locName)
 217      {
 218          $this->_locName = $locName;
 219      }
 220  
 221      function setPassword($password)
 222      {
 223          $this->_password = $password;
 224      }
 225  
 226      function setSourceURI($sourceURI)
 227      {
 228          $this->_sourceURI = $sourceURI;
 229      }
 230  
 231      function setTargetURI($targetURI)
 232      {
 233          $this->_targetURI = $targetURI;
 234      }
 235  
 236      function setVersion($version)
 237      {
 238          $this->_version = $version;
 239  
 240          if ($version == 0) {
 241              $this->_uri = NAME_SPACE_URI_SYNCML;
 242              $this->_uriMeta = NAME_SPACE_URI_METINF;
 243              $this->_uriDevInf = NAME_SPACE_URI_DEVINF;
 244          } else {
 245              $this->_uri = NAME_SPACE_URI_SYNCML_1_1;
 246              $this->_uriMeta = NAME_SPACE_URI_METINF_1_1;
 247              $this->_uriDevInf = NAME_SPACE_URI_DEVINF_1_1;
 248          }
 249      }
 250  
 251      function setSessionID($sessionID)
 252      {
 253          $this->_sessionID = $sessionID;
 254      }
 255  
 256      function isAuthorized()
 257      {
 258          if (!$this->_isAuthorized && !empty($this->_password)) {
 259              $GLOBALS['backend']->logMessage('checking auth for user='
 260              . $this->_locName,
 261               __FILE__, __LINE__, PEAR_LOG_DEBUG);
 262  
 263              $auth = &Auth::singleton($GLOBALS['conf']['auth']['driver']);
 264              $this->_isAuthorized = $auth->authenticate($this->_locName, array('password' => $this->_password));
 265          }
 266  
 267          return $this->_isAuthorized;
 268      }
 269  
 270      function setSync($target, &$sync)
 271      {
 272          $this->_syncs[$target] = &$sync;
 273      }
 274  
 275      function &getSync($target)
 276      {
 277          if (isset($this->_syncs[$target])) {
 278              return $this->_syncs[$target];
 279          } else {
 280              $false = false;
 281              return $false;
 282          }
 283      }
 284  
 285      function getURI()
 286      {
 287          /*
 288           * The non WBXML devices (notably P900 and Sync4j seem to get confused
 289           * by a <SyncML xmlns="syncml:SYNCML1.1"> element. They require
 290           * just <SyncML>. So don't use an ns for non wbxml devices.
 291           */
 292          if ($this->isWBXML()) {
 293              return $this->_uri;
 294          } else {
 295              return '';
 296          }
 297      }
 298      function getURIMeta()
 299      {
 300          return $this->_uriMeta;
 301      }
 302  
 303      function getURIDevInf()
 304      {
 305          return $this->_uriDevInf;
 306      }
 307  
 308      function setClientAnchorNext($type, $a)
 309      {
 310          $this->_clientAnchorNext[$type] = $a;
 311      }
 312  
 313      function setServerAnchorLast($type, $a)
 314      {
 315          $this->_serverAnchorLast[$type] = $a;
 316      }
 317  
 318      function setServerAnchorNext($type, $a)
 319      {
 320          $this->_serverAnchorNext[$type] = $a;
 321      }
 322  
 323      function getClientAnchorNext($type)
 324      {
 325          return $this->_clientAnchorNext[$type];
 326      }
 327  
 328      function getServerAnchorNext($type)
 329      {
 330          return $this->_serverAnchorNext[$type];
 331      }
 332  
 333      function getServerAnchorLast($type)
 334      {
 335          return $this->_serverAnchorLast[$type];
 336      }
 337  
 338      /**
 339       * The log simply counts the entries for each topic.
 340       */
 341      function log($topic)
 342      {
 343          if (isset($this->_log[$topic])) {
 344              $this->_log[$topic] += 1;
 345          } else {
 346              $this->_log[$topic] = 1;
 347          }
 348      }
 349  
 350      /**
 351       * The Log is an array where the key is the event name and the
 352       * value says how often this event occured.
 353       */
 354      function getLog()
 355      {
 356          return $this->_log;
 357      }
 358  
 359      /**
 360       * Returns an identifier used to identify the sync device in the
 361       * map. Currently "locname:sourceURI".
 362       */
 363      function getSyncIdentifier()
 364      {
 365          return str_replace(':', '_', $this->_locName)
 366                  . ':'
 367                  . str_replace(':', '_', $this->_sourceURI);
 368      }
 369  
 370      function &getDevice()
 371      {
 372          return SyncML_Device::singleton();
 373      }
 374  
 375      /**
 376       * Returns the expected result type for a Results tag, used to redirect the
 377       * incoming command somewhere special.  For example, if we have requested
 378       * device info, the Results tag should be sent to the Put command so we can
 379       * read it in.
 380       *
 381       * Clears the hash of this Command Reference before returning a value.
 382       *
 383       * @param integer $cmdRef  The CmdRef of the incoming command.
 384       *
 385       * @return string  The command type to redirect to, or
 386       *                 undefined if no redirect registered.
 387       */
 388      function getExpectedResultType($cmdRef)
 389      {
 390          if ( isset($this->_expectedResult[$cmdRef]) ) {
 391              $cmdType = $this->_expectedResult[$cmdRef];
 392              unset($this->_expectedResult[$cmdRef]);
 393          }
 394          return $cmdType;
 395      }
 396  
 397      /**
 398       * Sets up a command redirection for a future Result command.
 399       *
 400       * @param integer $cmdID    The CmdID of the command we are sending to
 401       *                          the client.
 402       * @param string  $cmdType  The type of command to redirect to when
 403       *                          the Results command is received.
 404       */
 405      function setExpectedResultType($cmdID, $cmdType)
 406      {
 407          $this->_expectedResult[$cmdID] = $cmdType;
 408      }
 409  
 410      /**
 411       * Check if there are any pending elements that have not been sent to due
 412       * to message sitze restrictions. These will be sent int the next msg.
 413       *
 414       */
 415      function hasPendingElements()
 416      {
 417  
 418          if (is_array($this->_syncs)) {
 419              foreach ($this->_syncs as $sync) {
 420                  if ($sync->hasPendingElements()) {
 421                      return true;
 422                  }
 423              }
 424          }
 425          return false;
 426      }
 427  
 428      /**
 429       * Returns all syncs which have pending elements left.
 430       * Returns an array of TargetLocURIs which can be used
 431       * as a key in getSync calls.
 432       */
 433      function getPendingSyncs()
 434      {
 435          $r = array();
 436          if (is_array($this->_syncs)) {
 437              foreach ($this->_syncs as $target => $sync) {
 438                  if ($sync->hasPendingElements()) {
 439                      $r[] = $target;
 440                  }
 441              }
 442          }
 443          return $r;
 444      }
 445  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7