More improvements to provisioning, fix variable names.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 26 Apr 2010 19:30:10 +0000 (15:30 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 26 Apr 2010 19:30:10 +0000 (15:30 -0400)
With this and the last commit, provisioning can now be set to Allow,
while still allowing Android devices to connect. The Android devices will
not be provisioned, so setting it to 'Force' will still prevent them from
connecting, but now at least using Android won't prevent allowing other
devices to be provisioned.

framework/ActiveSync/lib/Horde/ActiveSync.php
framework/ActiveSync/lib/Horde/ActiveSync/Request/Base.php
framework/ActiveSync/lib/Horde/ActiveSync/Request/Options.php [deleted file]
framework/ActiveSync/lib/Horde/ActiveSync/Request/Provision.php
framework/ActiveSync/package.xml

index eee7653..d6b8c66 100644 (file)
@@ -991,7 +991,18 @@ class Horde_ActiveSync
      */
     public function handleRequest($cmd, $devId)
     {
+        /* Don't bother with everything else if all we want are Options */
+        if ($cmd == 'Options') {
+            self::activeSyncHeader();
+            self::versionHeader();
+            self::commandsHeader();
+            return true;
+        }
+
         /* Check that this device is known */
+        if (is_null($devId)) {
+            throw new Horde_ActiveSync_Exception('Device failed to send device id.');
+        }
         $state = $this->_driver->getStateObject();
         if (!empty($devId) && !$state->deviceExists($devId)) {
             $get = $this->_request->getGetParams();
index 4d61f0c..bea0b85 100644 (file)
@@ -149,15 +149,15 @@ abstract class Horde_ActiveSync_Request_Base
          * 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. */
-         $this->_device = $this->_state->getDeviceInfo($this->_devId);
-         if (strpos($this->_device->agent, 'Android') !== false) {
+         $this->_device = $this->_state->getDeviceInfo($this->_device->id);
+         if (strpos($this->_device->userAgent, 'Android') !== false) {
              $sentKey = null;
          }
 
         /* Don't attempt if we don't care */
         if ($this->_provisioning !== false) {
             $state = $this->_driver->getStateObject();
-            $storedKey = $state->getPolicyKey($this->_devId);
+            $storedKey = $state->getPolicyKey($this->_device->id);
             /* Loose provsioning should allow a blank key */
             if ((empty($storedKey) || $storedKey != $sentKey) &&
                ($this->_provisioning !== 'loose' ||
@@ -185,7 +185,7 @@ abstract class Horde_ActiveSync_Request_Base
      */
     public function handle()
     {
-        $this->_version = $activeSync->getProtocolVersion();
+        $this->_version = $this->_activeSync->getProtocolVersion();
         $this->_logger->info('Request received from device: ' . $this->_device->id . ' Supporting protocol version: ' . $this->_version);
     }
 
diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/Request/Options.php b/framework/ActiveSync/lib/Horde/ActiveSync/Request/Options.php
deleted file mode 100644 (file)
index 21b4a4b..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-/**
- * ActiveSync Handler for OPTIONS requests
- *
- * Copyright 2009 - 2010 The Horde Project (http://www.horde.org)
- *
- * @author Michael J. Rubinsky <mrubinsk@horde.org>
- * @package Horde_ActiveSync
- */
-/**
- * Zarafa Deutschland GmbH, www.zarafaserver.de
- * This file is distributed under GPL v2.
- * Consult LICENSE file for details
- */
-class Horde_ActiveSync_Request_Options extends Horde_ActiveSync_Request_Base
-{
-    public function handle()
-    {
-        Horde_ActiveSync::activeSyncHeader();
-        Horde_ActiveSync::versionHeader();
-        Horde_ActiveSync::commandsHeader();
-
-        return true;
-    }
-
-}
index 7424a14..22ff75f 100644 (file)
@@ -140,7 +140,7 @@ class Horde_ActiveSync_Request_Provision extends Horde_ActiveSync_Request_Base
                     return $this->_globalError(self::STATUS_PROTERROR);
                 }
                 if ($status == self::STATUS_CLIENT_SUCCESS) {
-                    $this->_state->setDeviceRWStatus($this->_devId, Horde_ActiveSync::RWSTATUS_WIPED);
+                    $this->_state->setDeviceRWStatus($this->_device->id, Horde_ActiveSync::RWSTATUS_WIPED);
                 }
             }
         }
@@ -156,17 +156,17 @@ class Horde_ActiveSync_Request_Provision extends Horde_ActiveSync_Request_Base
         send it to the client. */
         if (!$phase2) {
             /* Verify intermediate key */
-            if ($this->_state->getPolicyKey($this->_devId) != $policykey) {
+            if ($this->_state->getPolicyKey($this->_device->id) != $policykey) {
                 $policyStatus = self::STATUS_POLKEYMISM;
             } else {
                 /* Set the final key */
                 $policykey = $this->_state->generatePolicyKey();
-                $this->_state->setPolicyKey($this->_devId, $policykey);
+                $this->_state->setPolicyKey($this->_device->id, $policykey);
             }
         } elseif (empty($policykey)) {
             // This is phase2 - we need to set the intermediate key
             $policykey = $this->_state->generatePolicyKey();
-            $this->_state->setPolicyKey($this->_devId, $policykey);
+            $this->_state->setPolicyKey($this->_device->id, $policykey);
         }
 
         $this->_encoder->startTag(Horde_ActiveSync::PROVISION_PROVISION);
@@ -175,10 +175,10 @@ class Horde_ActiveSync_Request_Provision extends Horde_ActiveSync_Request_Base
         $this->_encoder->endTag();
 
         /* Wipe data if status is pending or wiped */
-        $rwstatus = $this->_state->getDeviceRWStatus($this->_devId);
+        $rwstatus = $this->_state->getDeviceRWStatus($this->_device->id);
         if ($rwstatus == Horde_ActiveSync::RWSTATUS_PENDING || $rwstatus == Horde_ActiveSync::RWSTATUS_WIPED) {
             $this->_encoder->startTag(Horde_ActiveSync::PROVISION_REMOTEWIPE, false, true);
-            $this->_state->setDeviceRWStatus($this->_devId, Horde_ActiveSync::RWSTATUS_WIPED);
+            $this->_state->setDeviceRWStatus($this->_device->id, Horde_ActiveSync::RWSTATUS_WIPED);
         } else {
             $this->_encoder->startTag(Horde_ActiveSync::PROVISION_POLICIES);
             $this->_encoder->startTag(Horde_ActiveSync::PROVISION_POLICY);
index 5302062..9d16796 100644 (file)
@@ -68,7 +68,6 @@ http://pear.php.net/dtd/package-2.0.xsd">
          <file name="FolderSync.php" role="php" />
          <file name="Sync.php" role="php" />
          <file name="Ping.php" role="php" />
-         <file name="Options.php" role="php" />
          <file name="Provision.php" role="php" />
          <file name="GetItemEstimate.php" role="php" />
          <file name="SendMail.php" role="php" />
@@ -121,7 +120,6 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <install name="lib/Horde/ActiveSync/Request/FolderSync.php" as="Horde/ActiveSync/Request/FolderSync.php" />
    <install name="lib/Horde/ActiveSync/Request/Sync.php" as="Horde/ActiveSync/Request/Sync.php" />
    <install name="lib/Horde/ActiveSync/Request/Ping.php" as="Horde/ActiveSync/Request/Ping.php" />
-   <install name="lib/Horde/ActiveSync/Request/Options.php" as="Horde/ActiveSync/Request/Options.php" />
    <install name="lib/Horde/ActiveSync/Request/Provision.php" as="Horde/ActiveSync/Request/Provision.php" />
    <install name="lib/Horde/ActiveSync/Request/GetItemEstimate.php" as="Horde/ActiveSync/Request/GetItemEstimate.php" />
    <install name="lib/Horde/ActiveSync/Request/SendMail.php" as="Horde/ActiveSync/Request/SendMail.php" />