From: Michael J. Rubinsky Date: Mon, 26 Apr 2010 16:48:42 +0000 (-0400) Subject: make state a class member, pass the activesync server instance to the request X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=6fc1d801785b867883b6489c024a66d38b84175e;p=horde.git make state a class member, pass the activesync server instance to the request --- diff --git a/framework/ActiveSync/lib/Horde/ActiveSync.php b/framework/ActiveSync/lib/Horde/ActiveSync.php index 619a6f957..e0f083f7c 100644 --- a/framework/ActiveSync/lib/Horde/ActiveSync.php +++ b/framework/ActiveSync/lib/Horde/ActiveSync.php @@ -1012,6 +1012,7 @@ class Horde_ActiveSync $this->_decoder, $this->_encoder, $this->_request, + $this, $this->_provisioning); $request->setLogger($this->_logger); diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/Request/Base.php b/framework/ActiveSync/lib/Horde/ActiveSync/Request/Base.php index 06f22458c..9d25dd273 100644 --- a/framework/ActiveSync/lib/Horde/ActiveSync/Request/Base.php +++ b/framework/ActiveSync/lib/Horde/ActiveSync/Request/Base.php @@ -73,6 +73,25 @@ abstract class Horde_ActiveSync_Request_Base */ protected $_statusCode = 0; + /** + * State object + * + * @var Horde_ActiveSync_State_Base + */ + protected $_state; + + /** + * ActiveSync server + * + * @var Horde_ActiveSync + */ + protected $_activeSync; + + /** + * Logger + * + * @var Horde_Log_Logger + */ protected $_logger; /** @@ -90,11 +109,15 @@ abstract class Horde_ActiveSync_Request_Base Horde_ActiveSync_Wbxml_Decoder $decoder, Horde_ActiveSync_Wbxml_Encoder $encoder, Horde_Controller_Request_Http $request, + Horde_ActiveSync $as, $provisioning) { /* Backend driver */ $this->_driver = $driver; + /* server */ + $this->_activeSync = $as; + /* Wbxml handlers */ $this->_encoder = $encoder; $this->_decoder = $decoder; @@ -115,6 +138,12 @@ abstract class Horde_ActiveSync_Request_Base */ public function checkPolicyKey($sentKey) { + /* Android devices don't support provisioning, but also send a policykey + * header - which is against the specification. Check the user agent + * for Android (maybe need version sniffing in the future) and set the + * policykey to null for those devices. */ + + /* Don't attempt if we don't care */ if ($this->_provisioning !== false) { $state = $this->_driver->getStateObject(); diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/Request/FolderSync.php b/framework/ActiveSync/lib/Horde/ActiveSync/Request/FolderSync.php index 6d911d367..4494e690f 100644 --- a/framework/ActiveSync/lib/Horde/ActiveSync/Request/FolderSync.php +++ b/framework/ActiveSync/lib/Horde/ActiveSync/Request/FolderSync.php @@ -70,20 +70,20 @@ class Horde_ActiveSync_Request_FolderSync extends Horde_ActiveSync_Request_Base $this->_logger->debug('[Horde_ActiveSync::handleFolderSync] syncKey: ' . $synckey); /* Initialize state engine */ - $state = &$this->_driver->getStateObject(array('synckey' => $synckey)); - $state->getDeviceInfo($devId); + $this->_state = &$this->_driver->getStateObject(array('synckey' => $synckey)); + $this->_state->getDeviceInfo($devId); try { /* Get folders that we know about already */ - $state->loadState($synckey, 'foldersync'); + $this->_state->loadState($synckey, 'foldersync'); /* Get new synckey to send back */ - $newsynckey = $state->getNewSyncKey($synckey); + $newsynckey = $this->_state->getNewSyncKey($synckey); } catch (Horde_ActiveSync_Exception $e) { $this->_statusCode = self::STATUS_KEYMISM; $this->_handleError(); exit; } - $seenfolders = $state->getKnownFolders(); + $seenfolders = $this->_state->getKnownFolders(); $this->_logger->debug('[Horde_ActiveSync::handleFolderSync] newSyncKey: ' . $newsynckey); /* Deal with folder hierarchy changes */ @@ -108,7 +108,7 @@ class Horde_ActiveSync_Request_FolderSync extends Horde_ActiveSync_Request_Base /* Configure importer with last state */ $importer = $this->_driver->getImporter(); - $importer->init($state, false); + $importer->init($this->_state, false); while (1) { $folder = new Horde_ActiveSync_Message_Folder(array('logger' => $this->_logger)); @@ -153,7 +153,7 @@ class Horde_ActiveSync_Request_FolderSync extends Horde_ActiveSync_Request_Base // count before sending the actual data. $exporter = new Horde_ActiveSync_Connector_Exporter(); $sync = $this->_driver->GetSyncObject(); - $sync->init($state, $exporter, array('synckey' => $synckey)); + $sync->init($this->_state, $exporter, array('synckey' => $synckey)); /* Perform the actual sync operation */ while(is_array($sync->syncronize())); @@ -203,8 +203,8 @@ class Horde_ActiveSync_Request_FolderSync extends Horde_ActiveSync_Request_Base $this->_encoder->endTag(); /* Save the state as well as the known folder cache */ - $state->setNewSyncKey($newsynckey); - $state->save(); + $this->_state->setNewSyncKey($newsynckey); + $this->_state->save(); return true; } diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/Request/GetItemEstimate.php b/framework/ActiveSync/lib/Horde/ActiveSync/Request/GetItemEstimate.php index 871fa01e0..2ee07ffaa 100644 --- a/framework/ActiveSync/lib/Horde/ActiveSync/Request/GetItemEstimate.php +++ b/framework/ActiveSync/lib/Horde/ActiveSync/Request/GetItemEstimate.php @@ -115,9 +115,9 @@ class Horde_ActiveSync_Request_GetItemEstimate extends Horde_ActiveSync_Request_ /* compatibility mode - get id from state */ if (!isset($collectionid)) { - $state = &$this->_driver->getStateObject(); - $state->getDeviceInfo($devId); - $collectionid = $state>getFolderData($this->_devid, $collection['class']); + $this->_state = &$this->_driver->getStateObject(); + $this->_state->getDeviceInfo($devId); + $collectionid = $this->_state>getFolderData($this->_devid, $collection['class']); } $collection['id'] = $collectionid; $status[$collection['id']] = $cStatus; @@ -143,10 +143,10 @@ class Horde_ActiveSync_Request_GetItemEstimate extends Horde_ActiveSync_Request_ $this->_encoder->endTag(); $this->_encoder->startTag(self::ESTIMATE); - $state = $this->_driver->getStateObject($collection); - $state->loadState($collection['synckey']); + $this->_state = $this->_driver->getStateObject($collection); + $this->_state->loadState($collection['synckey']); $sync = $this->_driver->getSyncObject(); - $sync->init($state, null, $collection); + $sync->init($this->_state, null, $collection); $this->_encoder->content($sync->GetChangeCount()); $this->_encoder->endTag(); diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/Request/Ping.php b/framework/ActiveSync/lib/Horde/ActiveSync/Request/Ping.php index 7e58688e1..e9d4b7c68 100644 --- a/framework/ActiveSync/lib/Horde/ActiveSync/Request/Ping.php +++ b/framework/ActiveSync/lib/Horde/ActiveSync/Request/Ping.php @@ -37,7 +37,6 @@ class Horde_ActiveSync_Request_Ping extends Horde_ActiveSync_Request_Base const FOLDERTYPE = 'Ping:FolderType'; protected $_ping_settings; - protected $_state; protected function _checkHeartbeat($lifetime) { diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/Request/Provision.php b/framework/ActiveSync/lib/Horde/ActiveSync/Request/Provision.php index 12fde6034..6444a31b3 100644 --- a/framework/ActiveSync/lib/Horde/ActiveSync/Request/Provision.php +++ b/framework/ActiveSync/lib/Horde/ActiveSync/Request/Provision.php @@ -69,8 +69,8 @@ class Horde_ActiveSync_Request_Provision extends Horde_ActiveSync_Request_Base } /* Get state object */ - $state = $this->_driver->getStateObject(); - $state->getDeviceInfo($devId); + $this->_state = $this->_driver->getStateObject(); + $this->_state->getDeviceInfo($devId); /* Handle android remote wipe */ if ($this->_decoder->getElementStartTag(Horde_ActiveSync::PROVISION_REMOTEWIPE)) { @@ -83,7 +83,7 @@ class Horde_ActiveSync_Request_Provision extends Horde_ActiveSync_Request_Base return $this->_globalError(self::STATUS_PROTERROR); } if ($status == self::STATUS_CLIENT_SUCCESS) { - $state->setDeviceRWStatus($this->_devId, Horde_ActiveSync::RWSTATUS_WIPED); + $this->_state->setDeviceRWStatus($this->_devId, Horde_ActiveSync::RWSTATUS_WIPED); } /* Need to send *something* in the policytype field even if wiping */ @@ -146,7 +146,7 @@ class Horde_ActiveSync_Request_Provision extends Horde_ActiveSync_Request_Base return $this->_globalError(self::STATUS_PROTERROR); } if ($status == self::STATUS_CLIENT_SUCCESS) { - $state->setDeviceRWStatus($this->_devId, Horde_ActiveSync::RWSTATUS_WIPED); + $this->_state->setDeviceRWStatus($this->_devId, Horde_ActiveSync::RWSTATUS_WIPED); } } } @@ -162,17 +162,17 @@ class Horde_ActiveSync_Request_Provision extends Horde_ActiveSync_Request_Base send it to the client. */ if (!$phase2) { /* Verify intermediate key */ - if ($state->getPolicyKey($this->_devId) != $policykey) { + if ($this->_state->getPolicyKey($this->_devId) != $policykey) { $policyStatus = self::STATUS_POLKEYMISM; } else { /* Set the final key */ - $policykey = $state->generatePolicyKey(); - $state->setPolicyKey($this->_devId, $policykey); + $policykey = $this->_state->generatePolicyKey(); + $this->_state->setPolicyKey($this->_devId, $policykey); } } elseif (empty($policykey)) { // This is phase2 - we need to set the intermediate key - $policykey = $state->generatePolicyKey(); - $state->setPolicyKey($this->_devId, $policykey); + $policykey = $this->_state->generatePolicyKey(); + $this->_state->setPolicyKey($this->_devId, $policykey); } $this->_encoder->startTag(Horde_ActiveSync::PROVISION_PROVISION); @@ -181,10 +181,10 @@ class Horde_ActiveSync_Request_Provision extends Horde_ActiveSync_Request_Base $this->_encoder->endTag(); /* Wipe data if status is pending or wiped */ - $rwstatus = $state->getDeviceRWStatus($this->_devId); + $rwstatus = $this->_state->getDeviceRWStatus($this->_devId); if ($rwstatus == Horde_ActiveSync::RWSTATUS_PENDING || $rwstatus == Horde_ActiveSync::RWSTATUS_WIPED) { $this->_encoder->startTag(Horde_ActiveSync::PROVISION_REMOTEWIPE, false, true); - $state->setDeviceRWStatus($this->_devId, Horde_ActiveSync::RWSTATUS_WIPED); + $this->_state->setDeviceRWStatus($this->_devId, Horde_ActiveSync::RWSTATUS_WIPED); } else { $this->_encoder->startTag(Horde_ActiveSync::PROVISION_POLICIES); $this->_encoder->startTag(Horde_ActiveSync::PROVISION_POLICY); diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/Request/Sync.php b/framework/ActiveSync/lib/Horde/ActiveSync/Request/Sync.php index 4842c9dfc..80832d9db 100644 --- a/framework/ActiveSync/lib/Horde/ActiveSync/Request/Sync.php +++ b/framework/ActiveSync/lib/Horde/ActiveSync/Request/Sync.php @@ -184,18 +184,18 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base if ($this->_statusCode == self::STATUS_SUCCESS) { /* Initialize the state */ - $state = &$this->_driver->getStateObject($collection); - $device = $state->getDeviceInfo($devId); + $this->_state = &$this->_driver->getStateObject($collection); + $device = $this->_state->getDeviceInfo($devId); if (!empty($collection['supported'])) { /* Initial sync and we have SUPPORTED data - save it */ if (empty($device->supported)) { $device->supported = array(); } $device->supported[$collection['class']] = $collection['supported']; - $state->setDeviceInfo($devId, $device); + $this->_state->setDeviceInfo($devId, $device); } try { - $state->loadState($collection['synckey'], 'sync'); + $this->_state->loadState($collection['synckey'], 'sync'); } catch (Horde_ActiveSync_Exception $e) { $this->_statusCode = self::STATUS_KEYMISM; $this->_handleError($collection); @@ -204,7 +204,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base /* compatibility mode - get folderid from the state directory */ if (!isset($collection['id'])) { - $collection['id'] = $state->getFolderData($this->_devId, $collection['class']); + $collection['id'] = $this->_state->getFolderData($this->_devId, $collection['class']); } /* compatibility mode - set default conflict behavior if no @@ -217,7 +217,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base if ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_COMMANDS)) { /* Configure importer with last state */ $importer = $this->_driver->getImporter(); - $importer->init($state, $collection['id'], $collection['conflict']); + $importer->init($this->_state, $collection['id'], $collection['conflict']); $nchanges = 0; while (1) { // MODIFY or REMOVE or ADD or FETCH @@ -376,7 +376,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base isset($collection['getchanges']) || $collection['synckey'] == '0') { try { - $collection['newsynckey'] = $state->getNewSyncKey($collection['synckey']); + $collection['newsynckey'] = $this->_state->getNewSyncKey($collection['synckey']); } catch (Horde_ActiveSync_Exception $e) { $this->_statusCode = self::STATUS_KEYMISM; } @@ -450,7 +450,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base $filtertype = isset($collection['filtertype']) ? $collection['filtertype'] : false; $exporter = new Horde_ActiveSync_Connector_Exporter($this->_encoder, $collection['class']); $sync = $this->_driver->getSyncObject(); - $sync->init($state, $exporter, $collection); + $sync->init($this->_state, $exporter, $collection); $changecount = $sync->getChangeCount(); if (!empty($collection['windowsize']) && $changecount > $collection['windowsize']) { $this->_encoder->startTag(Horde_ActiveSync::SYNC_MOREAVAILABLE, false, true); @@ -481,8 +481,8 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base /* Save the sync state for the next time */ if (isset($collection['newsynckey'])) { if (!empty($sync) || !empty($importer) || !empty($exporter) || $collection['synckey'] == 0) { - $state->setNewSyncKey($collection['newsynckey']); - $state->save(); + $this->_state->setNewSyncKey($collection['newsynckey']); + $this->_state->save(); } else { $this->_logger->err(sprintf('[%s] Error saving %s - no state information available.', $this->_devId, $collection['newsynckey'])); } @@ -516,8 +516,8 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base $collection['newsynckey'] = Horde_ActiveSync_State_Base::getNewSyncKey(($this->_statusCode == self::STATUS_KEYMISM) ? 0 : $collection['synckey']); if ($collection['synckey'] != 0) { - $state = &$this->_driver->getStateObject($collection); - $state->removeState($collection['synckey']); + $this->_state = &$this->_driver->getStateObject($collection); + $this->_state->removeState($collection['synckey']); } }