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.
This commit is contained in:
Graham R. Cobb 2013-02-05 20:00:31 +00:00 committed by Patrick Ohly
parent e96ff22fdd
commit 36e8a6005a
2 changed files with 34 additions and 3 deletions

View File

@ -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");

View File

@ -182,6 +182,7 @@ class ActiveSyncSource :
void setCurrentSyncKey(const std::string &currentSyncKey) { 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<ConfigNode> m_itemNode;