Class constants for various sync request tags
authorMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 9 Apr 2010 20:07:15 +0000 (16:07 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 9 Apr 2010 20:07:15 +0000 (16:07 -0400)
framework/ActiveSync/lib/Horde/ActiveSync.php
framework/ActiveSync/lib/Horde/ActiveSync/Request/Sync.php
framework/ActiveSync/lib/Horde/ActiveSync/State/File.php

index 5a76218..7bef4d2 100644 (file)
  * This file is distributed under GPL v2.
  * Consult LICENSE file for details
  */
-// TODO Class constant these:
-define("SYNC_SYNCHRONIZE","Synchronize");
-define("SYNC_REPLIES","Replies");
-define("SYNC_ADD","Add");
-define("SYNC_MODIFY","Modify");
-define("SYNC_REMOVE","Remove");
-define("SYNC_FETCH","Fetch");
-define("SYNC_SYNCKEY","SyncKey");
-define("SYNC_CLIENTENTRYID","ClientEntryId");
-define("SYNC_SERVERENTRYID","ServerEntryId");
-define("SYNC_STATUS","Status");
-define("SYNC_FOLDER","Folder");
-define("SYNC_FOLDERTYPE","FolderType");
-define("SYNC_VERSION","Version");
-define("SYNC_FOLDERID","FolderId");
-define("SYNC_GETCHANGES","GetChanges");
-define("SYNC_MOREAVAILABLE","MoreAvailable");
-define("SYNC_WINDOWSIZE","WindowSize");
-define("SYNC_COMMANDS","Commands");
-define("SYNC_OPTIONS","Options");
-define("SYNC_FILTERTYPE","FilterType");
-define("SYNC_TRUNCATION","Truncation");
-define("SYNC_RTFTRUNCATION","RtfTruncation");
-define("SYNC_CONFLICT","Conflict");
-define("SYNC_FOLDERS","Folders");
-define("SYNC_DATA","Data");
-define("SYNC_DELETESASMOVES","DeletesAsMoves");
-define("SYNC_NOTIFYGUID","NotifyGUID");
-define("SYNC_SUPPORTED","Supported");
-define("SYNC_SOFTDELETE","SoftDelete");
-define("SYNC_MIMESUPPORT","MIMESupport");
-define("SYNC_MIMETRUNCATION","MIMETruncation");
-define("SYNC_NEWMESSAGE","NewMessage");
 
 // POOMMAIL
 define("SYNC_POOMMAIL_ATTACHMENT","POOMMAIL:Attachment");
index 5b6dfa5..81d9626 100644 (file)
  */
 class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
 {
+    /* Codepage constants */
+    const SYNCHRONIZE = 'Synchronize';
+    const REPLIES = 'Replies';
+    const ADD = 'Add';
+    const MODIFY = 'Modify';
+    const REMOVE = 'Remove';
+    const FETCH = 'Fetch';
+    const SYNCKEY = 'SyncKey';
+    const CLIENTENTRYID = 'ClientEntryId';
+    const SERVERENTRYID = 'ServerEntryId';
+    const STATUS = 'Status';
+    const FOLDER = 'Folder';
+    const FOLDERTYPE = 'FolderType';
+    const VERSION = 'Version';
+    const FOLDERID = 'FolderId';
+    const GETCHANGES = 'GetChanges';
+    const MOREAVAILABLE = 'MoreAvailable';
+    const WINDOWSIZE = 'WindowSize';
+    const COMMANDS = 'Commands';
+    const OPTIONS = 'Options';
+    const FILTERTYPE = 'FilterType';
+    const TRUNCATION = 'Truncation';
+    const RTFTRUNCATION = 'RtfTruncation';
+    const CONFLICT = 'Conflict';
+    const FOLDERS = 'Folders';
+    const DATA = 'Data';
+    const DELETESASMOVES = 'DeletesAsMoves';
+    const NOTIFYGUID = 'NotifyGUID';
+    const SUPPORTED = 'Supported';
+    const SOFTDELETE = 'SoftDelete';
+    const MIMESUPPORT = 'MIMESupport';
+    const MIMETRUNCATION = 'MIMETruncation';
+    const NEWMESSAGE = 'NewMessage';
+    
+    /* Status */
     const STATUS_SUCCESS = 1;
     const STATUS_VERSIONMISM = 2;
     const STATUS_KEYMISM = 3;
@@ -45,22 +80,22 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
         /* Start decoding request */
         // FIXME: Need to figure out the proper response structure for errors
         // that occur this early
-        if (!$this->_decoder->getElementStartTag(SYNC_SYNCHRONIZE)) {
+        if (!$this->_decoder->getElementStartTag(self::SYNCHRONIZE)) {
             throw new Horde_ActiveSync_Exception('Protocol error');
         }
-        if (!$this->_decoder->getElementStartTag(SYNC_FOLDERS)) {
+        if (!$this->_decoder->getElementStartTag(self::FOLDERS)) {
             throw new Horde_ActiveSync_Exception('Protocol error');
         }
 
         while ($this->_statusCode == self::STATUS_SUCCESS &&
-               $this->_decoder->getElementStartTag(SYNC_FOLDER)) {
+               $this->_decoder->getElementStartTag(self::FOLDER)) {
 
             $collection = array();
             $collection['truncation'] = SYNC_TRUNCATION_ALL;
             $collection['clientids'] = array();
             $collection['fetchids'] = array();
 
-            if (!$this->_decoder->getElementStartTag(SYNC_FOLDERTYPE)) {
+            if (!$this->_decoder->getElementStartTag(self::FOLDERTYPE)) {
                 throw new Horde_ActiveSync_Exception('Protocol error');
             }
 
@@ -70,7 +105,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                 throw new Horde_ActiveSync_Exception('Protocol error');
             }
 
-            if (!$this->_decoder->getElementStartTag(SYNC_SYNCKEY)) {
+            if (!$this->_decoder->getElementStartTag(self::SYNCKEY)) {
                 throw new Horde_ActiveSync_Exception('Protocol error');
             }
             $collection['synckey'] = $this->_decoder->getElementContent();
@@ -78,7 +113,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                 throw new Horde_ActiveSync_Exception('Protocol error');
             }
 
-            if ($this->_decoder->getElementStartTag(SYNC_FOLDERID)) {
+            if ($this->_decoder->getElementStartTag(self::FOLDERID)) {
                 $collection['id'] = $this->_decoder->getElementContent();
                 $this->_logger->info('[' . $this->_devId . '] Folder server id: ' . $collection['id']);
                 if (!$this->_decoder->getElementEndTag()) {
@@ -89,7 +124,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
             /* Looks like we ignore the SYNC_SUPPORTED Tag? */
             // @TODO: This needs to be captured and stored in the state so we
             // can correctly support ghosted properties
-            if ($this->_decoder->getElementStartTag(SYNC_SUPPORTED)) {
+            if ($this->_decoder->getElementStartTag(self::SUPPORTED)) {
                 // SUPPORTED only allowed on initial sync request
                 if ($collection['synckey'] != 0) {
                     $this->_statusCode = self::STATUS_PROTERROR;
@@ -104,15 +139,15 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                 }
             }
 
-            if ($this->_decoder->getElementStartTag(SYNC_DELETESASMOVES)) {
-                $collection["deletesasmoves"] = true;
+            if ($this->_decoder->getElementStartTag(self::DELETESASMOVES)) {
+                $collection['deletesasmoves'] = true;
             }
 
-            if ($this->_decoder->getElementStartTag(SYNC_GETCHANGES)) {
+            if ($this->_decoder->getElementStartTag(self::GETCHANGES)) {
                 $collection['getchanges'] = true;
             }
 
-            if ($this->_decoder->getElementStartTag(SYNC_WINDOWSIZE)) {
+            if ($this->_decoder->getElementStartTag(self::WINDOWSIZE)) {
                 $collection['windowsize'] = $this->_decoder->getElementContent();
                 if (!$this->_decoder->getElementEndTag()) {
                     $this->_statusCode = self::STATUS_PROTERROR;
@@ -121,9 +156,9 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                 }
             }
 
-            if ($this->_decoder->getElementStartTag(SYNC_OPTIONS)) {
+            if ($this->_decoder->getElementStartTag(self::OPTIONS)) {
                 while(1) {
-                    if ($this->_decoder->getElementStartTag(SYNC_FILTERTYPE)) {
+                    if ($this->_decoder->getElementStartTag(self::FILTERTYPE)) {
                         $collection['filtertype'] = $this->_decoder->getElementContent();
                         if (!$this->_decoder->getElementEndTag()) {
                             $this->_statusCode = self::STATUS_PROTERROR;
@@ -131,7 +166,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                             exit;
                         }
                     }
-                    if ($this->_decoder->getElementStartTag(SYNC_TRUNCATION)) {
+                    if ($this->_decoder->getElementStartTag(self::TRUNCATION)) {
                         $collection['truncation'] = $this->_decoder->getElementContent();
                         if (!$this->_decoder->getElementEndTag()) {
                             $this->_statusCode = self::STATUS_PROTERROR;
@@ -139,7 +174,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                             exit;
                         }
                     }
-                    if ($this->_decoder->getElementStartTag(SYNC_RTFTRUNCATION)) {
+                    if ($this->_decoder->getElementStartTag(self::RTFTRUNCATION)) {
                         $collection['rtftruncation'] = $this->_decoder->getElementContent();
                         if (!$this->_decoder->getElementEndTag()) {
                             $this->_statusCode = self::STATUS_PROTERROR;
@@ -148,7 +183,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                         }
                     }
 
-                    if ($this->_decoder->getElementStartTag(SYNC_MIMESUPPORT)) {
+                    if ($this->_decoder->getElementStartTag(self::MIMESUPPORT)) {
                         $collection['mimesupport'] = $this->_decoder->getElementContent();
                         if (!$this->_decoder->getElementEndTag()) {
                             $this->_statusCode = self::STATUS_PROTERROR;
@@ -157,7 +192,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                         }
                     }
 
-                    if ($this->_decoder->getElementStartTag(SYNC_MIMETRUNCATION)) {
+                    if ($this->_decoder->getElementStartTag(self::MIMETRUNCATION)) {
                         $collection['mimetruncation'] = $this->_decoder->getElementContent();
                         if (!$this->_decoder->getElementEndTag()) {
                             $this->_statusCode = self::STATUS_PROTERROR;
@@ -166,7 +201,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                         }
                     }
 
-                    if ($this->_decoder->getElementStartTag(SYNC_CONFLICT)) {
+                    if ($this->_decoder->getElementStartTag(self::CONFLICT)) {
                         $collection['conflict'] = $this->_decoder->getElementContent();
                         if (!$this->_decoder->getElementEndTag()) {
                             $this->_statusCode = self::STATUS_PROTERROR;
@@ -205,7 +240,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                 }
             }
 
-            if ($this->_decoder->getElementStartTag(SYNC_COMMANDS)) {
+            if ($this->_decoder->getElementStartTag(self::COMMANDS)) {
                 /* Configure importer with last state */
                 $importer = $this->_driver->getImporter();
                 $importer->init($state, $collection['id'], $collection['conflict']);
@@ -220,7 +255,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
 
                     $nchanges++;
 
-                    if ($this->_decoder->getElementStartTag(SYNC_SERVERENTRYID)) {
+                    if ($this->_decoder->getElementStartTag(self::SERVERENTRYID)) {
                         $serverid = $this->_decoder->getElementContent();
 
                         if (!$this->_decoder->getElementEndTag()) {// end serverid
@@ -232,7 +267,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                         $serverid = false;
                     }
 
-                    if ($this->_decoder->getElementStartTag(SYNC_CLIENTENTRYID)) {
+                    if ($this->_decoder->getElementStartTag(self::CLIENTENTRYID)) {
                         $clientid = $this->_decoder->getElementContent();
 
                         if (!$this->_decoder->getElementEndTag()) { // end clientid
@@ -245,7 +280,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                     }
 
                     /* Create Streamer object from messages passed from PIM */
-                    if ($this->_decoder->getElementStartTag(SYNC_DATA)) {
+                    if ($this->_decoder->getElementStartTag(self::DATA)) {
                         switch ($collection['class']) {
                         case 'Email':
                             //@TODO
@@ -277,7 +312,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                     }
 
                     switch ($element[Horde_ActiveSync_Wbxml::EN_TAG]) {
-                    case SYNC_MODIFY:
+                    case self::MODIFY:
                         if (isset($appdata)) {
                             // Currently, 'read' is only sent by the PDA when it
                             // is ONLY setting the read flag.
@@ -289,7 +324,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                             $collection['importedchanges'] = true;
                         }
                         break;
-                    case SYNC_ADD:
+                    case self::ADD:
                         if (isset($appdata)) {
                             $id = $importer->ImportMessageChange(false, $appdata);
                             if ($clientid && $id) {
@@ -298,7 +333,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                             }
                         }
                         break;
-                    case SYNC_REMOVE:
+                    case self::REMOVE:
                         if (isset($collection['deletesasmoves'])) {
                             $folderid = $this->_driver->GetWasteBasket();
 
@@ -312,7 +347,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                         $importer->ImportMessageDeletion($serverid);
                         $collection['importedchanges'] = true;
                         break;
-                    case SYNC_FETCH:
+                    case self::FETCH:
                         array_push($collection['fetchids'], $serverid);
                         break;
                     }
@@ -358,24 +393,24 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
         /* Start output to PIM */
         $this->_logger->info('[' . $this->_devId . '] Beginning SYNC Response.');
         $this->_encoder->startWBXML();
-        $this->_encoder->startTag(SYNC_SYNCHRONIZE);
-        $this->_encoder->startTag(SYNC_FOLDERS);
+        $this->_encoder->startTag(self::SYNCHRONIZE);
+        $this->_encoder->startTag(self::FOLDERS);
         foreach ($collections as $collection) {
 
             /* Get new synckey if needed */
             if (isset($collection['importedchanges']) ||
                 isset($collection['getchanges']) ||
-                $collection['synckey'] == "0") {
+                $collection['synckey'] == '0') {
 
                 $collection['newsynckey'] = $state->getNewSyncKey($collection['synckey']);
             }
 
-            $this->_encoder->startTag(SYNC_FOLDER);
-            $this->_encoder->startTag(SYNC_FOLDERTYPE);
+            $this->_encoder->startTag(self::FOLDER);
+            $this->_encoder->startTag(self::FOLDERTYPE);
             $this->_encoder->content($collection['class']);
             $this->_encoder->endTag();
 
-            $this->_encoder->startTag(SYNC_SYNCKEY);
+            $this->_encoder->startTag(self::SYNCKEY);
             if (isset($collection['newsynckey'])) {
                 $this->_encoder->content($collection['newsynckey']);
             } else {
@@ -383,11 +418,11 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
             }
             $this->_encoder->endTag();
 
-            $this->_encoder->startTag(SYNC_FOLDERID);
+            $this->_encoder->startTag(self::FOLDERID);
             $this->_encoder->content($collection['id']);
             $this->_encoder->endTag();
 
-            $this->_encoder->startTag(SYNC_STATUS);
+            $this->_encoder->startTag(self::STATUS);
             $this->_encoder->content($this->_statusCode);
             $this->_encoder->endTag();
 
@@ -396,16 +431,16 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
 
             /* Output server IDs for new items we received and added from PIM */
             if (isset($collection['clientids']) || count($collection['fetchids']) > 0) {
-                $this->_encoder->startTag(SYNC_REPLIES);
-                foreach ($collection["clientids"] as $clientid => $serverid) {
-                    $this->_encoder->startTag(SYNC_ADD);
-                    $this->_encoder->startTag(SYNC_CLIENTENTRYID);
+                $this->_encoder->startTag(self::REPLIES);
+                foreach ($collection['clientids'] as $clientid => $serverid) {
+                    $this->_encoder->startTag(self::ADD);
+                    $this->_encoder->startTag(self::CLIENTENTRYID);
                     $this->_encoder->content($clientid);
                     $this->_encoder->endTag();
-                    $this->_encoder->startTag(SYNC_SERVERENTRYID);
+                    $this->_encoder->startTag(self::SERVERENTRYID);
                     $this->_encoder->content($serverid);
                     $this->_encoder->endTag();
-                    $this->_encoder->startTag(SYNC_STATUS);
+                    $this->_encoder->startTag(self::STATUS);
                     $this->_encoder->content(1);
                     $this->_encoder->endTag();
                     $this->_encoder->endTag();
@@ -415,14 +450,14 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                 foreach ($collection['fetchids'] as $id) {
                     $data = $this->_driver->Fetch($collection['id'], $id, $mimesupport);
                     if ($data !== false) {
-                        $this->_encoder->startTag(SYNC_FETCH);
-                        $this->_encoder->startTag(SYNC_SERVERENTRYID);
+                        $this->_encoder->startTag(self::FETCH);
+                        $this->_encoder->startTag(self::SERVERENTRYID);
                         $this->_encoder->content($id);
                         $this->_encoder->endTag();
-                        $this->_encoder->startTag(SYNC_STATUS);
+                        $this->_encoder->startTag(self::STATUS);
                         $this->_encoder->content(1);
                         $this->_encoder->endTag();
-                        $this->_encoder->startTag(SYNC_DATA);
+                        $this->_encoder->startTag(self::DATA);
                         $data->encodeStream($this->_encoder);
                         $this->_encoder->endTag();
                         $this->_encoder->endTag();
@@ -441,11 +476,11 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                 $sync->init($state, $exporter, $collection);
                 $changecount = $sync->getChangeCount();
                 if (!empty($collection['windowsize']) && $changecount > $collection['windowsize']) {
-                    $this->_encoder->startTag(SYNC_MOREAVAILABLE, false, true);
+                    $this->_encoder->startTag(self::MOREAVAILABLE, false, true);
                 }
 
                 /* Output message changes per folder */
-                $this->_encoder->startTag(SYNC_COMMANDS);
+                $this->_encoder->startTag(self::COMMANDS);
 
                 // Stream the changes to the PDA
                 $n = 0;
@@ -472,7 +507,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                     $state->setNewSyncKey($collection['newsynckey']);
                     $state->save();
                 } else {
-                    $this->_logger->err(sprintf('[%s] Error saving %s - no state information available.', $this->_devId, $collection["newsynckey"]));
+                    $this->_logger->err(sprintf('[%s] Error saving %s - no state information available.', $this->_devId, $collection['newsynckey']));
                 }
             }
         }
@@ -492,27 +527,27 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
     private function _handleError($collection)
     {
         $this->_encoder->startWBXML();
-        $this->_encoder->startTag(SYNC_SYNCHRONIZE);
+        $this->_encoder->startTag(self::SYNCHRONIZE);
 
-        $this->_encoder->startTag(SYNC_FOLDERS);
+        $this->_encoder->startTag(self::FOLDERS);
 
         /* Get new synckey if needed */
         if ($this->_statusCode == self::STATUS_KEYMISM ||
             isset($collection['importedchanges']) ||
             isset($collection['getchanges']) ||
-            $collection['synckey'] == "0") {
+            $collection['synckey'] == '0') {
 
             $collection['newsynckey'] = Horde_ActiveSync_State_Base::getNewSyncKey(($this->_statusCode == self::STATUS_KEYMISM) ? 0 : $collection['synckey']);
             // @TODO: Need to reset the state??
         }
 
-        $this->_encoder->startTag(SYNC_FOLDER);
+        $this->_encoder->startTag(self::FOLDER);
 
-        $this->_encoder->startTag(SYNC_FOLDERTYPE);
+        $this->_encoder->startTag(self::FOLDERTYPE);
         $this->_encoder->content($collection['class']);
         $this->_encoder->endTag();
 
-        $this->_encoder->startTag(SYNC_SYNCKEY);
+        $this->_encoder->startTag(self::SYNCKEY);
         if (isset($collection['newsynckey'])) {
             $this->_encoder->content($collection['newsynckey']);
         } else {
@@ -520,15 +555,15 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
         }
         $this->_encoder->endTag();
 
-        $this->_encoder->startTag(SYNC_FOLDERID);
+        $this->_encoder->startTag(self::FOLDERID);
         $this->_encoder->content($collection['id']);
         $this->_encoder->endTag();
 
-        $this->_encoder->startTag(SYNC_STATUS);
+        $this->_encoder->startTag(self::STATUS);
         $this->_encoder->content($this->_statusCode);
         $this->_encoder->endTag();
 
-        $this->_encoder->endTag(); // SYNC_FOLDER
+        $this->_encoder->endTag(); // self::FOLDER
         $this->_encoder->endTag();
         $this->_encoder->endTag();
     }
index f813b71..55eeb5b 100644 (file)
@@ -738,7 +738,7 @@ class Horde_ActiveSync_State_File extends Horde_ActiveSync_State_Base
                 } else {
                     // Message in new seems to be new (add)
                     $change['type'] = 'change';
-                    $change['flags'] = SYNC_NEWMESSAGE;
+                    $change['flags'] = Horde_ActiveSync_Request_Sync::NEWMESSAGE;
                     $change['id'] = $new[$inew]['id'];
                     $changes[] = $change;
                     $inew++;
@@ -757,7 +757,7 @@ class Horde_ActiveSync_State_File extends Horde_ActiveSync_State_Base
         while ($inew < count($new)) {
             // All data left in new have been added
             $change['type'] = 'change';
-            $change['flags'] = SYNC_NEWMESSAGE;
+            $change['flags'] = Horde_ActiveSync_Request_Sync::NEWMESSAGE;
             $change['id'] = $new[$inew]['id'];
             $changes[] = $change;
             $inew++;