*/
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;
/* 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');
}
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();
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()) {
/* 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;
}
}
- 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;
}
}
- 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;
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;
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;
}
}
- 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;
}
}
- 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;
}
}
- 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;
}
}
- 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']);
$nchanges++;
- if ($this->_decoder->getElementStartTag(SYNC_SERVERENTRYID)) {
+ if ($this->_decoder->getElementStartTag(self::SERVERENTRYID)) {
$serverid = $this->_decoder->getElementContent();
if (!$this->_decoder->getElementEndTag()) {// end serverid
$serverid = false;
}
- if ($this->_decoder->getElementStartTag(SYNC_CLIENTENTRYID)) {
+ if ($this->_decoder->getElementStartTag(self::CLIENTENTRYID)) {
$clientid = $this->_decoder->getElementContent();
if (!$this->_decoder->getElementEndTag()) { // end clientid
}
/* 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
}
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.
$collection['importedchanges'] = true;
}
break;
- case SYNC_ADD:
+ case self::ADD:
if (isset($appdata)) {
$id = $importer->ImportMessageChange(false, $appdata);
if ($clientid && $id) {
}
}
break;
- case SYNC_REMOVE:
+ case self::REMOVE:
if (isset($collection['deletesasmoves'])) {
$folderid = $this->_driver->GetWasteBasket();
$importer->ImportMessageDeletion($serverid);
$collection['importedchanges'] = true;
break;
- case SYNC_FETCH:
+ case self::FETCH:
array_push($collection['fetchids'], $serverid);
break;
}
/* 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 {
}
$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();
/* 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();
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();
$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;
$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']));
}
}
}
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 {
}
$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();
}