/** * Get an activesync uid for the given backend serverid. If we've seen this * serverid before, return the previously created uid, otherwise return * a new one. * * @param string $id The server's current folder name E.g., INBOX * @param string $type The folder type, a Horde_ActiveSync::FOLDER_TYPE_* * constant. If empty, assumes FOLDER_TYPE_USER_MAIL * @param string $old_id The previous folder name for this folder, if the * folder is being renamed. @since 2.15.0 * @todo This is tempoarary until 3.0 (H6) when we * will have the collection manager take care of ALL * of the folder name <-> UID mapping management. * * @return string A unique identifier for the specified backend folder id. * The first character indicates the foldertype as such: * 'F' - Email * 'C' - Contact * 'A' - Appointment * 'T' - Task * 'N' - Note * @since 2.4.0 */ protected function _getFolderUidForBackendId($id, $type = null, $old_id = null) { // Always use 'RI' for Recipient cache. if ($id == 'RI') { return 'RI'; } $map = $this->_state->getFolderUidToBackendIdMap(); // Rename? if (!empty($old_id) && !empty($map[$old_id])) { $this->_tempMap[$id] = $map[$old_id]; } if (!empty($map[$id])) { return $map[$id]; } elseif (!empty($this->_tempMap[$id])) { return $this->_tempMap[$id]; } // Convert TYPE to CLASS $type = $this->_getClassFromType($type); $rMap = array_flip($this->_typeMap); $prefix = $rMap[$type]; // None found, generate a new UID. $this->_tempMap[$id] = sprintf('%s%04x%04x', $prefix, mt_rand(0, 0xffff), mt_rand(0, 0xffff)); $this->_logger->info(sprintf('[%s] Creating new folder uuid for %s: %s', getmypid(), $id, $this->_tempMap[$id])); return $this->_tempMap[$id]; }
/** * Check if this change conflicts with server changes * This is only true in the following situations: * * Changed here and changed there * Changed here and deleted there * Deleted here and changed there * * Any other combination of operations can be done * (e.g. change flags & move or move & delete) * * @param string $type The type of change('change', 'delete' etc...) * @param string $folderid The id of the folder this change is from. * @param string $id The uid for the changed message. * * @return boolean */ protected function _isConflict($type, $folderid, $id) { $stat = $this->_as->driver->statMessage($folderid, $id); if (!$stat) { /* Message is gone, if type is change, this is a conflict */ return $type == Horde_ActiveSync::CHANGE_TYPE_CHANGE; } return $this->_state->isConflict($stat, $type); }
/** * Save the dirty device info data. * * @param boolean $all If true, save all properties (deviceInfo and * deviceProperties). Otherwise, just save dirty * deviceProperties. @since 2.16.0 * @todo For 3.0, make it clearer taht deviceInfo is per-user and * deviceProperties is per-device. */ public function save($all = true) { if ($all) { $this->_state->setDeviceInfo($this, $this->_dirty); } if (!empty($this->_dirty['properties'])) { $this->_state->setDeviceProperties($this->properties, $this->id); } $this->_dirty = array(); }
/** * Clean up after initial pairing. Initial pairing can happen either as a * result of either a FOLDERSYNC or PROVISION command, depending on the * device capabilities. */ protected function _cleanUpAfterPairing() { // Android sends a bogus device id of 'validate' during initial // handshake. This data is never used again, and the resulting // FOLDERSYNC response is ignored by the client. Remove the entry, // to avoid having 2 device entries for every android client. if ($this->_device->id == 'validate') { $this->_logger->info(sprintf('[%s] Removing state for bogus VALIDATE device.', $this->_procid)); $this->_state->removeState(array('devId' => 'validate')); } }
/** * Helper for handling sync errors * * @param array $collection */ protected function _handleError(array $collection) { $this->_encoder->startWBXML(); $this->_encoder->startTag(Horde_ActiveSync::SYNC_SYNCHRONIZE); $this->_encoder->startTag(Horde_ActiveSync::SYNC_FOLDERS); // Get new synckey if needed if ($this->_statusCode == self::STATUS_KEYMISM || !empty($collection['importedchanges']) || !empty($collection['getchanges']) || $collection['synckey'] == '0') { $collection['newsynckey'] = Horde_ActiveSync_State_Base::getNewSyncKey($this->_statusCode == self::STATUS_KEYMISM ? 0 : $collection['synckey']); if ($collection['synckey'] != '0') { $this->_state->removeState(array('synckey' => $collection['synckey'])); } } $this->_encoder->startTag(Horde_ActiveSync::SYNC_FOLDER); $this->_encoder->startTag(Horde_ActiveSync::SYNC_FOLDERTYPE); $this->_encoder->content($collection['class']); $this->_encoder->endTag(); $this->_encoder->startTag(Horde_ActiveSync::SYNC_SYNCKEY); if (!empty($collection['newsynckey'])) { $this->_encoder->content($collection['newsynckey']); } else { $this->_encoder->content($collection['synckey']); } $this->_encoder->endTag(); $this->_encoder->startTag(Horde_ActiveSync::SYNC_FOLDERID); $this->_encoder->content($collection['id']); $this->_encoder->endTag(); $this->_encoder->startTag(Horde_ActiveSync::SYNC_STATUS); $this->_encoder->content($this->_statusCode); $this->_encoder->endTag(); $this->_encoder->endTag(); // Horde_ActiveSync::SYNC_FOLDER $this->_encoder->endTag(); $this->_encoder->endTag(); }
/** * Const'r * * @param array $params Must contain: * - db: (Horde_Db_Adapter_Base) The Horde_Db instance. * * @return Horde_ActiveSync_State_Sql */ public function __construct(array $params = array()) { parent::__construct($params); if (empty($this->_params['db']) || !$this->_params['db'] instanceof Horde_Db_Adapter) { throw new InvalidArgumentException('Missing or invalid Horde_Db parameter.'); } $this->_syncStateTable = 'horde_activesync_state'; $this->_syncMapTable = 'horde_activesync_map'; $this->_syncDeviceTable = 'horde_activesync_device'; $this->_syncUsersTable = 'horde_activesync_device_users'; $this->_syncMailMapTable = 'horde_activesync_mailmap'; $this->_syncCacheTable = 'horde_activesync_cache'; $this->_db = $params['db']; }
/** * Const'r * * @param array $params Must contain: * - connection: (Horde_Mongo_Client The Horde_Mongo instance. * * @return Horde_ActiveSync_State_Sql */ public function __construct(array $params = array()) { parent::__construct($params); if (empty($this->_params['connection']) || !$this->_params['connection'] instanceof MongoClient) { throw new InvalidArgumentException('Missing or invalid connection parameter.'); } $this->_mongo = $params['connection']; $this->_db = $this->_mongo->selectDb(null); }
/** * Delete the entire synccache from the backend. */ public function delete() { $this->_state->deleteSyncCache($this->_devid, $this->_user); $this->_data = array(); $this->_dirty = array(); }