00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef INCL_WINDOWS_SYNC_SOURCE
00037 #define INCL_WINDOWS_SYNC_SOURCE
00038
00043 #include "base/fscapi.h"
00044 #include "spds/constants.h"
00045 #include "spds/SyncItem.h"
00046 #include "spds/SyncMap.h"
00047 #include "spds/SyncStatus.h"
00048 #include "spds/SyncSource.h"
00049 #include"WindowsSyncSourceConfig.h"
00050 #include "outlook/ClientApplication.h"
00051
00052 #include <string>
00053 #include <list>
00054 #include <map>
00055
00056
00057 typedef std::list<std::wstring> itemKeyList;
00058 typedef itemKeyList::iterator itemKeyIterator;
00059
00061
00062
00063
00064
00065
00066 #define ERR_CODE_FOLDER_PATH 1
00067 #define ERR_CODE_DELETE_NOT_FOUND 2
00068 #define ERR_CODE_OLD_ITEMS_PATH 100
00069 #define ERR_CODE_UPDATE_NOT_FOUND 101
00070 #define ERR_CODE_FOLDER_OPEN 102
00071 #define ERR_CODE_ITEM_CREATE 104
00072 #define ERR_CODE_ITEM_FILL 105
00073 #define ERR_CODE_ITEM_SAVE 106
00074 #define ERR_CODE_DELETE 107
00075 #define ERR_CODE_ITEM_BAD_TYPE 108
00076 #define ERR_CODE_ITEM_GET 109
00077 #define ERR_CODE_NO_ROOT_FOLDER 110
00078 #define ERR_CODE_OPEN_OUTLOOK 111
00079 #define ERR_CODE_READ_ALL_ITEMS 112
00080 #define ERR_CODE_ID_MAP_PATH 120
00081 #define ERR_CODE_FOLDER_PATH_MATCH 121
00082
00083
00084 #define MAX_SOURCE_ERRORS 500
00085 #define TIMESTAMP_DELAY 2
00099 class WindowsSyncSource : public SyncSource {
00100
00101 private:
00102
00104 ClientApplication* outlook;
00105 boolean forceOpenOutlook;
00106
00107 int filterDirection;
00108
00109
00110
00111 class CacheData
00112 {
00113 public:
00114 CacheData()
00115 {}
00116 CacheData(long ts, std::wstring p)
00117 {
00118 lastModified = ts;
00119 parentPath = p;
00120 }
00121
00122 long lastModified;
00123 std::wstring parentPath;
00124 };
00125 std::map<std::wstring, CacheData> cache;
00126
00127 std::wstring lastAddedId;
00128 std::map<std::wstring, std::wstring> idMap;
00129 std::map<std::wstring, std::wstring> idMapReverse;
00130
00131 void cacheItem(std::wstring itemID, long lastModified, std::wstring parentPath);
00132 void clearCache();
00133
00134 bool getItemDetails(const std::wstring & itemID, std::wstring & parentPath);
00135 bool getItemDetails(const std::wstring & itemID, std::wstring & parentPath, long & lastModified);
00136 bool getItemDetails(const std::wstring & itemID, std::wstring & parentPath, long & lastModified, ClientItem * & cItem);
00137 bool getItemDetailsFromCache(const std::wstring & itemID, std::wstring & parentPath, long & lastModified);
00138 std::map<std::wstring, CacheData> addedItems;
00139 void itemAdded(ClientItem * item);
00140
00141 std::wstring getIdMapFile();
00142 std::map<std::wstring, std::wstring> readIdMap(const std::wstring & idMapFile);
00143 int writeIdMap(const std::map<std::wstring, std::wstring> & idMap);
00144 void constructIdMaps(std::wstring idMapFile);
00145
00146 bool isNewIdInMap(const std::wstring & id);
00147 bool isOldIdInMap(const std::wstring & id);
00148 void addToIdMap(const std::wstring & oldId, const std::wstring & newId);
00149 std::wstring getOldIdFromNewId(const std::wstring & id);
00150 std::wstring getNewIdFromOldId(const std::wstring & id);
00151 void removeOldIdFromMap(const std::wstring & id);
00152 void removeNewIdFromMap(const std::wstring & id);
00153 void removeIdFromMap(const std::wstring & id);
00154
00155 protected:
00156
00159 WindowsSyncSourceConfig& winConfig;
00160
00161
00163 itemKeyList allItems;
00164 itemKeyList newItems;
00165 itemKeyList modItems;
00166 itemKeyList delItems;
00167 itemKeyList allItemsPaths;
00168 itemKeyList filteredItems;
00170
00171 itemKeyIterator iAll;
00172 itemKeyIterator iNew;
00173 itemKeyIterator iMod;
00174 itemKeyIterator iDel;
00175 itemKeyIterator iAllPaths;
00176 itemKeyIterator iFiltered;
00177
00178
00180 unsigned int numErrors;
00181
00183 std::wstring defaultFolderPath;
00184
00185
00186
00187
00188
00189 ClientFolder* getStartFolder();
00190
00191
00192 void pushAllSubfolderItemsToList(ClientFolder* folder, itemKeyList& listItems, itemKeyList& listItemsPaths);
00193 void pushAllItemsToList (ClientFolder* folder, itemKeyList& listItems, itemKeyList& listItemsPaths);
00194
00195
00196 void updateAllItemsLists(itemKeyList &itemsToDelete, itemKeyList &itemPathsToDelete,
00197 itemKeyList &itemsToAdd, itemKeyList &itemPathsToAdd);
00198
00199
00200 int manageModificationsFromLastSync();
00201
00202
00203 int addForcedItemsToModList(itemKeyList& forcedItems);
00204
00205
00206 std::wstring createOldItems();
00207 void parseOldItems(std::wstring& data, itemKeyList& listItems, itemKeyList& listFolders);
00208
00209
00210 int resetDataFile(const std::wstring& itemType);
00211 int closeDataFile(const std::wstring& itemType);
00212
00213
00214 bool folderPathAllowed(const std::wstring& p);
00215
00216
00217 void checkBirthdayAnniversary(ClientItem* cItem);
00218 int deleteAppointment(ClientItem* cItem, const std::wstring& propertyName);
00219
00220
00221 void manageSourceError(const int errorCode, const char* errorMsg);
00222
00224 void manageSourceErrorF(const int errorCode, const char *msgFormat, ...);
00225
00226 void extractFolder(const std::wstring dataString, const std::wstring dataType, std::wstring& path);
00227
00240 bool filterClientItem(ClientItem* item, DateFilter::FilterDirection direction, const char* command = NULL);
00241
00242
00247 void updateFilters();
00248
00254 bool smartGetFolderTag(const std::wstring& dataString, bool isSifFormat, std::wstring& propertyValue);
00255
00256 public:
00257
00266 WindowsSyncSource::WindowsSyncSource(const WCHAR* name, WindowsSyncSourceConfig* wsc);
00267
00268 virtual ~WindowsSyncSource();
00269
00270
00272 const WindowsSyncSourceConfig& getConfig() const;
00273 WindowsSyncSourceConfig& getConfig();
00274
00275 int beginSync();
00276 int endSync();
00277
00278 void WindowsSyncSource::setItemStatus(const WCHAR* key, int status);
00279 void assign(WindowsSyncSource& s);
00280
00281
00287 int removeAllItems();
00288
00289
00290 SyncItem* getFirstItem();
00291 SyncItem* getNextItem ();
00292
00293 SyncItem* getFirstNewItem();
00294 SyncItem* getNextNewItem ();
00295 SyncItem* getFirstUpdatedItem();
00296 SyncItem* getNextUpdatedItem ();
00297
00298 SyncItem* getFirstDeletedItem();
00299 SyncItem* getNextDeletedItem ();
00300
00301
00302
00303 int addItem (SyncItem& item);
00304 int updateItem(SyncItem& item);
00305 int deleteItem(SyncItem& item);
00306
00307
00309 DateFilter& getDateFilter() { return getConfig().getDateFilter(); }
00310
00311 int upgradeCalendarFolders(bool fixMyCalendar = false);
00312
00319 SyncItem* getItemFromId(const std::wstring& id);
00320 };
00321
00324 #endif