$this->_decoder,
$this->_encoder,
$this->_request,
+ $this,
$this->_provisioning);
$request->setLogger($this->_logger);
*/
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;
/**
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;
*/
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();
$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 */
/* 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));
// 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()));
$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;
}
/* 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;
$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();
const FOLDERTYPE = 'Ping:FolderType';
protected $_ping_settings;
- protected $_state;
protected function _checkHeartbeat($lifetime)
{
}
/* 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)) {
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 */
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);
}
}
}
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);
$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);
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);
/* 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
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
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;
}
$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);
/* 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']));
}
$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']);
}
}