}
/**
- * @param $cmd
- * @param $devid
- * @param $protocolversion
- * @return unknown_type
+ * The heart of the server. Dispatch a request to the request object to
+ * handle.
+ *
+ * @param string $cmd The command we are requesting.
+ * @param string $devId The device id making the request.
+ *
+ * @return boolean
*/
public function handleRequest($cmd, $devId)
{
+ /* Check that this device is known */
+ $state = $this->_driver->getStateObject();
+ if (!empty($devId) && !$state->deviceExists($devId)) {
+ $get = $this->_request->getGetParams();
+ $device = new StdClass();
+ $device->userAgent = $this->_request->getHeader('User-Agent');
+ $device->deviceType = !empty($get['DeviceType']) ? $get['DeviceType'] : '';
+ $device->policykey = 0;
+ $state->setDeviceInfo($devId, $device);
+ }
+
+ /* Load the request handler to handle the request */
$class = 'Horde_ActiveSync_Request_' . basename($cmd);
$version = $this->getProtocolVersion();
if (class_exists($class)) {
- //@TODO: Remove version - get it in handle() since we pass self to it anyway
$request = new $class($this->_driver,
$this->_decoder,
$this->_encoder,
$this->_request,
- $version,
- $devId,
$this->_provisioning);
$request->setLogger($this->_logger);
- return $request->handle($this);
+
+ return $request->handle($this, $devId);
}
// @TODO: Leave the following in place until all are refactored...then throw
*/
protected $_devId;
- protected $_userAgent;
- protected $_deviceType;
-
/**
* Used to track what error code to send back to PIM on failure
*
Horde_ActiveSync_Wbxml_Decoder $decoder,
Horde_ActiveSync_Wbxml_Encoder $encoder,
Horde_Controller_Request_Http $request,
- $version, $devId, $provisioning)
+ $provisioning)
{
/* Backend driver */
$this->_driver = $driver;
/* The http request */
$this->_request = $request;
- /* Protocol Version */
- $this->_version = $version;
-
- /* Device Id */
- $this->_devId = $devId;
-
/* Provisioning support */
$this->_provisioning = $provisioning;
-
- /* Useragent and device identification */
- $this->_userAgent = $request->getHeader('User-Agent');
- $get = $request->getGetParams();
- $this->_deviceType = $get['DeviceType'];
-
- /* Logger */
- $this->_logger;
}
/**
* @param string $version
* @param string $devId
*/
- abstract public function handle(Horde_ActiveSync $activeSync);
+ public function handle(Horde_ActiveSync $activeSync, $devId)
+ {
+ $this->_version = $activeSync->getProtocolVersion();
+ $this->_devId = $devId;
+ }
}
\ No newline at end of file
const STATUS_KEYMISM = 9;
const STATUS_PROTOERR = 10;
- public function handle(Horde_ActiveSync $activeSync)
+ public function handle(Horde_ActiveSync $activeSync, $devId)
{
+ parent::handle($activeSync, $devId);
+
/* Be optimistic */
$this->_statusCode = self::STATUS_SUCCESS;
$this->_logger->info('[Horde_ActiveSync::handleFolderSync] Beginning FOLDERSYNC');
* @return boolean
* @throws Horde_ActiveSync_Exception
*/
- public function handle(Horde_ActiveSync $activeSync)
+ public function handle(Horde_ActiveSync $activeSync, $devId)
{
+ parent::handle($activeSync, $devId);
$this->_logger->info('[Horde_ActiveSync::handleFolderSync] Beginning GETITEMESTIMATE');
/* Check policy */
*/
class Horde_ActiveSync_Request_Options extends Horde_ActiveSync_Request_Base
{
- public function handle(Horde_ActiveSync $activeSync)
+ public function handle(Horde_ActiveSync $activeSync, $devId)
{
Horde_ActiveSync::activeSyncHeader();
Horde_ActiveSync::versionHeader();
*
* @return boolean
*/
- public function handle(Horde_ActiveSync $activeSync)
+ public function handle(Horde_ActiveSync $activeSync, $devId)
{
+ parent::handle($activeSync, $devId);
+
// FIXME
$timeout = 3;
$this->_logger->info('Ping received for: ' . $this->_devId);
*/
public function handle(Horde_ActiveSync $activeSync)
{
+ parent::handle($activeSync, $devId);
+
/* Get the policy key if it was sent */
$policykey = $activeSync->getPolicyKey();
if ($state->getPolicyKey($this->_devId) != $policykey) {
$policyStatus = self::STATUS_POLKEYMISM;
} else {
+ /* Set the final key */
$policykey = $this->_driver->generatePolicyKey();
- $info = array('policykey' => $policykey,
- 'useragent' => $this->_userAgent,
- 'devicetype' => $this->_deviceType);
- $state->setDeviceInfo($this->_devId, $info);
+ $state->setPolicyKey($this->_devId, $policykey);
}
} elseif (empty($policykey)) {
// This is phase2 - we need to set the intermediate key
* @return boolean
* @throws Horde_ActiveSync_Exception
*/
- public function handle(Horde_ActiveSync $activeSync)
+ public function handle(Horde_ActiveSync $activeSync, $devId)
{
+ parent::handle($activeSync, $devId);
$this->_logger->info('[Horde_ActiveSync::handleSync] Handling SYNC command.');
/* Check policy */
abstract public function isConflict($stat, $type);
/**
- * Get the specified device's policy key.
+ * Obtain the current policy key, if it exists.
*
- * @param string $devId The device id to get key for.
+ * @param string $devId The device id to obtain policy key for.
*
- * @return integer The policy key
+ * @return integer The current policy key for this device, or 0 if none
+ * exists.
*/
abstract public function getPolicyKey($devId);
/**
- * Set the policy key for the specified device id
+ * Save a new device policy key to storage.
*
- * @param string $devId The device id
- * @param integer $key The policy key
- *
- * @return void
+ * @param string $devId The device id
+ * @param integer $key The new policy key
*/
abstract public function setPolicyKey($devId, $key);
/**
+ * Obtain the device object.
+ *
+ * @param string $devId
+ *
+ * @return StdClass
+ */
+ abstract public function getDeviceInfo($devId);
+
+ /**
+ * Check that a given device id is known to the server. This is regardless
+ * of Provisioning status.
+ *
+ * @param string $devId
+ *
+ * @return boolean
+ */
+ abstract public function deviceExists($devId);
+
+ /**
+ * Set new device info
+ *
+ * @param string $devId The device id.
+ * @param StdClass $data The device information
+ *
+ * @return boolean
+ */
+ abstract public function setDeviceInfo($devId, $data);
+
+ /**
* Set the backend driver
* (should really only be called by a backend object when passing this
* object to client code)
}
/**
- * Obtain the device info array.
+ * Obtain the device object.
*
- * @param <type> $devId
+ * @param string $devId
+ *
+ * @return StdClass
*/
public function getDeviceInfo($devId)
{
return unserialize(file_get_contents($file));
}
- return array('policykey' => 0,
- 'rwstatus' => 0,
- 'devicetype' => '',
- 'useragent' => '');
+ /* Default structure */
+ $device = new StdClass();
+ $device->policykey = 0;
+ $device->rwstatus = 0; // ??
+ $device->deviceType = '';
+ $device->userAgent = '';
+
+ return $device;
}
/**
* Set new device info
*
+ * @param string $devId The device id.
+ * @param StdClass $data The device information
+ *
+ * @return boolean
*/
public function setDeviceInfo($devId, $data)
{
}
/**
+ * Check that a given device id is known to the server. This is regardless
+ * of Provisioning status.
+ *
+ * @param string $devId
+ *
+ * @return boolean
+ */
+ public function deviceExists($devId)
+ {
+ return file_exists($this->_stateDir . '/' . $this->_backend->getUser() . '/info-' . $devId);
+ }
+
+ /**
* Load a specific collection's ping state. Ping state must already have
* been loaded.
*
public function getPolicyKey($devId)
{
$info = $this->getDeviceInfo($devId);
- return $info['policykey'];
+ return $info->policykey;
}
/**
public function setPolicyKey($devId, $key)
{
$info = $this->getDeviceInfo($devId);
- $info['policykey'] = $key;
+ $info->policykey = $key;
$this->setDeviceInfo($devId, $info);
}