Throw exception if synckey is mangled, and return appropriate status code to PIM
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 10 Apr 2010 14:09:42 +0000 (10:09 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 10 Apr 2010 14:09:42 +0000 (10:09 -0400)
framework/ActiveSync/lib/Horde/ActiveSync.php
framework/ActiveSync/lib/Horde/ActiveSync/Request/FolderSync.php
framework/ActiveSync/lib/Horde/ActiveSync/Request/Sync.php
framework/ActiveSync/lib/Horde/ActiveSync/State/Base.php

index e6dced1..1f6556e 100644 (file)
@@ -678,8 +678,12 @@ class Horde_ActiveSync
         }
 
         // Get state of hierarchy
-        $syncstate = $this->_stateMachine->loadState($synckey);
-        $newsynckey = $this->_stateMachine->getNewSyncKey($synckey);
+        try {
+            $syncstate = $this->_stateMachine->loadState($synckey);
+            $newsynckey = $this->_stateMachine->getNewSyncKey($synckey);
+        } catch (Horde_ActiveSync_Exception $e) {
+            // @TODO - send error status keymism when refactored.
+        }
 
         // additional information about already seen folders
         $seenfolders = unserialize($this->_stateMachine->loadState('s' . $synckey));
index 85ba7d0..7a5d5c0 100644 (file)
@@ -74,15 +74,15 @@ class Horde_ActiveSync_Request_FolderSync extends Horde_ActiveSync_Request_Base
         try {
             /* Get folders that we know about already */
             $state->loadState($synckey);
+            
+            /* Get new synckey to send back */
+            $newsynckey = $state->getNewSyncKey($synckey);
         } catch (Horde_ActiveSync_Exception $e) {
             $this->_statusCode = self::STATUS_KEYMISM;
             $this->_handleError();
             exit;
         }
         $seenfolders = $state->getKnownFolders();
-
-        /* Get new synckey to send back */
-        $newsynckey = $state->getNewSyncKey($synckey);
         $this->_logger->debug('[Horde_ActiveSync::handleFolderSync] newSyncKey: ' . $newsynckey);
 
         /* Deal with folder hierarchy changes */
index a2b17f8..5261747 100644 (file)
@@ -367,8 +367,11 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
             if (isset($collection['importedchanges']) ||
                 isset($collection['getchanges']) ||
                 $collection['synckey'] == '0') {
-
-                $collection['newsynckey'] = $state->getNewSyncKey($collection['synckey']);
+                try {
+                    $collection['newsynckey'] = $state->getNewSyncKey($collection['synckey']);
+                } catch (Horde_ActiveSync_Exception $e) {
+                    $this->_statusCode = self::STATUS_KEYMISM;
+                }
             }
 
             $this->_encoder->startTag(Horde_ActiveSync::SYNC_FOLDER);
index c55c803..6dd5a0d 100644 (file)
@@ -296,6 +296,7 @@ abstract class Horde_ActiveSync_State_Base
      * @param string $syncKey  The old syncKey
      *
      * @return string  The new synckey
+     * @throws Horde_ActiveSync_Exception
      */
     static public function getNewSyncKey($syncKey)
     {
@@ -308,9 +309,7 @@ abstract class Horde_ActiveSync_State_Base
 
                 return '{' . $matches[1] . '}' . $n;
             }
-
-            // @TODO: should this thrown an exception instead of returning false?
-            return false;
+            throw new Horde_ActiveSync_Exception('Invalid SyncKey format passed to getNewSyncKey()');
         }
     }