From 827132383fea5f6d294810b603501c256335a79a Mon Sep 17 00:00:00 2001 From: "Graham R. Cobb" Date: Tue, 5 Feb 2013 20:00:31 +0000 Subject: [PATCH] ActiveSync: added support for specifying folder names Previously, the database field was interpreted as a Collection ID. This adds logic to allow the database to be interpreted as a folder path. The logic is: 1) If the database is an empty string, pass it through (this is the most common case as it is interpreted as "use the default folder for the source type"). 2) If the database matches a Collection ID, use the ID (this is the same as the previous behaviour). 3) If the database matches a folder path name, with an optional leading "/", use the Collection ID for the matching folder. 4) Otherwise, force a FolderSync to get the latest folder changes from the server and repeat steps 2 and 3 5) If still no match, throw an error. Steps 2 and 3 are in the new function lookupFolder. The remaining logic has been added to the open function. Note that the result is that m_folder (and hence getFolder()) are always either empty or a Collection ID -- that is as before so the sync logic itself is unchanged. --- src/backends/activesync/ActiveSyncSource.cpp | 36 +++++++++++++++++++++++--- src/backends/activesync/ActiveSyncSource.h | 1 + 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/backends/activesync/ActiveSyncSource.cpp b/src/backends/activesync/ActiveSyncSource.cpp index f6fc3f4..a1d0932 100644 --- a/src/backends/activesync/ActiveSyncSource.cpp +++ b/src/backends/activesync/ActiveSyncSource.cpp @@ -174,18 +174,48 @@ ActiveSyncSource::Databases ActiveSyncSource::getDatabases() return result; } +std::string ActiveSyncSource::lookupFolder(std::string folder) { + // If folder matches a collectionId, use that + if (m_collections.find(folder) != m_collections.end()) return folder; + + // If folder begins with /, drop it + if (folder[0] == '/') folder.erase(0,1); + + // Lookup folder name + if (m_folderPaths.find(folder) != m_folderPaths.end()) return m_folderPaths[folder]; + + // Not found + return ""; +} void ActiveSyncSource::open() { // extract account ID and throw error if missing std::string username = m_context->getSyncUsername(); + std::string folder = getDatabaseID(); SE_LOG_DEBUG(NULL, NULL, - "using eas sync account %s from config %s", + "using eas sync account %s from config %s with folder %s", username.c_str(), - m_context->getConfigName().c_str()); + m_context->getConfigName().c_str(), + folder.c_str()); + + if (folder.empty()) { // Most common case is empty string + m_folder = folder; + } else { // Lookup folder name + // Try using cached folder list + findCollections(username, false); + m_folder = lookupFolder(folder); + if (m_folder.empty()) { + // Fetch latest folder list and try again + findCollections(username, true); + m_folder = lookupFolder(folder); + } + if (m_folder.empty()) { + throwError("could not find folder: "+folder); + } + } m_account = username; - m_folder = getDatabaseID(); // create handler m_handler.set(eas_sync_handler_new(m_account.c_str()), "EAS handler"); diff --git a/src/backends/activesync/ActiveSyncSource.h b/src/backends/activesync/ActiveSyncSource.h index 0274aa0..45dbd78 100644 --- a/src/backends/activesync/ActiveSyncSource.h +++ b/src/backends/activesync/ActiveSyncSource.h @@ -182,6 +182,7 @@ class ActiveSyncSource : void setCurrentSyncKey(const std::string ¤tSyncKey) { m_currentSyncKey = currentSyncKey; } void findCollections(const std::string account, bool force_update); std::string getCollectionPath(const std::string parentId, const std::string name); + std::string lookupFolder(std::string folder); boost::shared_ptr m_itemNode; -- 1.7.10.4