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 WINMAINCPP
00037 #define WINMAINCPP
00038
00043
00044
00045 #define SYNC_MUTEX_NAME "fol-SyncInProgress"
00046 #define EMPTY_WSTRING L""
00047
00048
00049
00050 #define VCARD_DEFAULT_NAME L"card"
00051 #define VCALENDAR_DEFAULT_NAME L"event"
00052 #define VTODO_DEFAULT_NAME L"task"
00053 #define VNOTE_DEFAULT_NAME L"note"
00054
00055 #define SIFC_DEFAULT_NAME L"scard"
00056 #define SIFE_DEFAULT_NAME L"scal"
00057 #define SIFT_DEFAULT_NAME L"stask"
00058 #define SIFN_DEFAULT_NAME L"snote"
00059
00060 #define MAX_PATH_LENGTH 512
00061
00062
00063
00064
00066 #define MAIL L"mail"
00067 #define CONTACT L"contact"
00068 #define APPOINTMENT L"appointment"
00069 #define TASK L"task"
00070 #define JOURNAL L"journal"
00071 #define NOTE L"note"
00072 #define PICTURE L"picture"
00073 #define POST L"post"
00074 #define DISTRIBUTION_LIST L"distribution list"
00075
00076 #define MAIL_ "mail"
00077 #define CONTACT_ "contact"
00078 #define APPOINTMENT_ "appointment"
00079 #define TASK_ "task"
00080 #define JOURNAL_ "journal"
00081 #define NOTE_ "note"
00082 #define PICTURE_ "picture"
00083 #define POST_ "post"
00084 #define DISTRIBUTION_LIST_ "distribution list"
00085
00086
00088 #define APPOINTMENT_FORCED_MODIFIED L"appointment_modified"
00089
00091 #define DEFAULT_FOLDER L"DEFAULT_FOLDER"
00092
00093 #define SYNCSOURCE_STATE_OK 1
00094 #define SYNCSOURCE_STATE_NOT_SYNCED 2
00095 #define SYNCSOURCE_STATE_CANCELED 3
00096
00097 #define ERR_CODE_DROPPED_ITEMS 2100
00098 #define ERR_CODE_DROPPED_ITEMS_SERVER 2101
00099 #define ERR_CODE_NO_SOURCES 2102
00100
00101
00102 #define SYNC_MODE_TWO_WAY_TEXT "two-way"
00103 #define SYNC_MODE_ONE_WAY_FROM_CLIENT_TEXT "one-way-from-client"
00104 #define SYNC_MODE_ONE_WAY_FROM_SERVER_TEXT "one-way-from-server"
00105 #define SYNC_MODE_REFRESH_FROM_CLIENT_TEXT "refresh-from-client"
00106 #define SYNC_MODE_REFRESH_FROM_SERVER_TEXT "refresh-from-server"
00107 #define SYNC_MODE_SLOW_TEXT "slow"
00108 #define SYNC_MODE_NONE_TEXT "none" // deprecated: use 'enabled = 0' instead
00109 #define SYNC_MODE_SMART_ONE_WAY_FROM_CLIENT_TEXT "smart-one-way-from-client" // not used (only mobile clients, for pictures)
00110 #define SYNC_MODE_SMART_ONE_WAY_FROM_SERVER_TEXT "smart-one-way-from-server" // not used (future, for pictures)
00111
00115
00118 #define SCHED_PARAM L"schedule"
00119 #define NEVER "Never"
00120 #define EVERY_DAY "Every day"
00121
00125
00126
00127
00129
00130 #define MSG_BOX_CANCEL_SYNC "Are you really sure you want to cancel current synchronization?"
00131 #define WMSG_BOX_CANCEL_SYNC L"Are you really sure you want to cancel current synchronization?"
00132 #define WMSG_BOX_ASK_SLOW_1 L"The server has requested a full sync of all items for "
00133 #define WMSG_BOX_ASK_SLOW_2 L".\nThis process may take up to a few minutes depending on the number of items\nand network bandwidth. Do you wish to proceed? (YES in %d seconds...)"
00134 #define WMSG_BOX_REFRESH_FROM_SERVER L"A sync to replace your local data with your server data has been requested.\nAll the local items will be deleted before adding the server items.\nAre you sure you want to continue?"
00135
00136
00137
00138 #define ERR_UNKNOWN "Unknown error."
00139 #define ERR_OPEN_OUTLOOK "Error opening Outlook application."
00140 #define ERR_TAG_NOT_FOUND "Bad XML format: tag '%ls' not found."
00141 #define ERR_BAD_FOLDER_PATH "Bad folder path: %ls"
00142 #define ERR_INSTALL_DIR "Error retrieving the install directory path."
00143 #define ERR_THREAD_PRIORITY "Error setting sync thread priority: code %d (%s)."
00144 #define ERR_THREAD_NOT_TERMINATED "Could not terminate the synchronization process. %s"
00145 #define ERR_MUTEX_CREATE "Could not create the mutex for synchronization process. %s"
00146 #define ERR_MUTEX_ALREADY_EXISTS "Error creating the mutex for sync process: mutex already exists. %s"
00147 #define ERR_MUTEX_NOT_RELEASED "Could not release the mutex of synchronization process. %s"
00148 #define ERR_MUTEX_OPEN "Could not open the mutex of synchronization process. %s"
00149 #define ERR_CLASS_REG_FAILED "Class Registration Failed! class name = %s"
00150 #define ERR_ENCRYPT_DATA "Error occurred encrypting private data"
00151 #define ERR_DECRYPT_DATA "Error occurred decrypting private data"
00152 #define ERR_NO_SOURCES_TO_SYNC "No sources to synchronize."
00153
00154 #define ERR_BEGIN_SYNC "Error in begin sync of source '%ls'."
00155 #define ERR_CLOSE_OUTLOOK "Some error occurred closing Outlook session. Outlook may become unstable."
00156 #define ERR_COM_INITIALIZE "Error occurred initializing COM library."
00157 #define ERR_COM_CREATE_INSTANCE "Error occurred creating an instance for COM library."
00158 #define ERR_END_SYNC "Error in end sync of source '%ls'."
00159 #define ERR_APPDATA_PATH "Error retrieving current user application data path: code %d (%s)"
00160 #define ERR_FILE_OPEN "Error opening file: %s"
00161 #define ERR_WFILE_OPEN "Error opening file: %ls"
00162 #define ERR_FILE_WRITE_ON "Error writing file: %s"
00163 #define ERR_WFILE_WRITE_ON "Error writing file: %ls"
00164 #define ERR_FILE_OPEN_MODE "Error writing file: bad fopen mode."
00165 #define ERR_DIR_CREATE "Error creating directory: %ls"
00166 #define ERR_DEFAULT_SSCONFIG "Error creating default config for %s: %s"
00167 #define ERR_MACHINE_NAME "GetComputerName error: code %d (%s)"
00168 #define ERR_USER_NAME "GetUserName error: code %d (%s)"
00169 #define ERR_USER_NAME_EX "GetUserNameEx error: code %d (%s)"
00170 #define ERR_INIT_LOG "Could not create the LOG file."
00171 #define ERR_INVALID_REG_PATH "Invalid windows registry path: %s."
00172 #define ERR_HKLM_KEYNOTFOUND "Error reading HKLM registry key '%s'.\nPlease reinstall the application."
00173
00174 #define ERR_FOLDER_OPEN "Error opening Outlook folder for source '%ls' with path '%ls'."
00175 #define ERR_FOLDER_PATH "'%ls' is not a folder selected for synchronization (see configuration of %ls source). Item received will be ignored."
00176 #define ERR_FOLDER_DEFAULT_PATH "Warning! No default folder found for %lss!"
00177 #define ERR_ITEM_GET "Error getting item \"%ls\" for source '%ls'."
00178 #define ERR_ITEM_GET_NEW "Error getting new item \"%ls\" for source '%ls'."
00179 #define ERR_ITEM_GET_MOD "Error getting modified item \"%ls\" for source '%ls'."
00180 #define ERR_ITEM_CREATE "Could not create a new %ls item into folder '%ls'"
00181 #define ERR_ITEM_FILL "Error setting properties of %ls item \"%ls\". Item not saved."
00182 #define ERR_INPUT_ITEM_FILTERED "Incoming %ls item \"%ls\" discarded because it doesn't verify current filters. Item not saved."
00183 #define ERR_INPUT_ITEM_DEL_FILTERED "Incoming %ls item \"%ls\" not deleted because it doesn't verify current filters."
00184 #define ERR_ITEM_BAD_TYPE "Mime type not supported: \"%ls\""
00185 #define ERR_ITEM_SAVE "Could not save %ls item \"%ls\" into folder '%ls'"
00186 #define ERR_ITEM_DELETE "Could not delete %ls item \"%ls\" from folder '%ls'"
00187 #define ERR_ITEM_DELETE_INTERNALLY L"Error removing internally the item."
00188 #define ERR_ITEM_UPDATE_NOT_FOUND "Could not update %ls item: ID = %ls not found."
00189 #define ERR_ITEM_DELETE_NOT_FOUND "Could not delete %ls item: ID = %ls not found."
00190 #define ERR_EVENTS_CREATED "Error occurred while checking if Outlook created a birthday/anniversary event."
00191 #define ERR_SOURCE_TOO_MANY_ERRORS "%d errors occurred on source %ls: source will not be used any more."
00192 #define ERR_SOURCE_LASTSYNCTIME_NOT_FOUND "Error reading \"%ls\": <LastSyncTime> not found."
00193 #define ERR_OCCURRENCE_NOT_FOUND "Error creating the appointment exception: occurrence \"%ls\" not found."
00194 #define ERR_OCCURRENCE_NOT_DELETED "Could not delete one occurrence (date = %ls)."
00195 #define ERR_OCCURRENCE_NOT_SAVED "Could not save one occurrence (date = %ls)."
00196 #define ERR_EXCEPTIONS_DEADLOCK "Detected too many dependences between appointment exceptions (%d). Exceptions not saved correctly."
00197 #define ERR_PROPERTY_REQUIRED "Error creating %ls item: property \"%ls\" is required."
00198
00199 #define ERR_PARSE_SIF_TAG_NOT_FOUND "Parsing error: SIF tag \"%ls\" not found."
00200 #define ERR_PARSE_PROPERTY_NOT_FOUND "Parsing error: property \"%ls\" not found."
00201 #define ERR_PARSE_PROPERTY_EMPTY "Parsing error: property \"%ls\" should not be empty."
00202 #define ERR_PARSE_APP_EXCEPTION "Error parsing appointment exception: %s"
00203 #define ERR_PARSE_EXC_NOREC "Could not add exceptions on a not-recurring appointment."
00204 #define ERR_NORMALIZE_EXCEPTIONS "Error normalizing appointment exceptions: %s"
00205
00206 #define ERR_SCHED_INIT_TASK "Error initializing Windows task scheduler."
00207 #define ERR_SCHED_SAVE "Scheduler error - failed to save the task, code = 0x%x - %s"
00208 #define ERR_SCHED_DELETE "Scheduler error - failed to delete the task, code = 0x%x - %s"
00209 #define ERR_SCHED_NEWWORKITEM "Scheduler error - failed calling ITask::NewWorkItem, code = 0x%x - %s"
00210 #define ERR_SCHED_CREATE_TRIGGER "Scheduler error - failed calling ITask::CreateTrigger, code = 0x%x - %s"
00211 #define ERR_SCHED_GET_TRIGGER "Scheduler error - failed calling ITask::GetTrigger, code = 0x%x - %s"
00212 #define ERR_SCHED_GET_TRIGGER2 "Scheduler error - failed calling ITaskTrigger::GetTrigger, code = 0x%x - %s"
00213 #define ERR_SCHED_SET_TRIGGER "Scheduler error - failed calling ITaskTrigger::SetTrigger, code = 0x%x - %s"
00214 #define ERR_SCHED_QUERY_INTERFACE "Scheduler error - failed calling ITask::QueryInterface, code = 0x%x - %s"
00215 #define ERR_SCHED_ACTIVATE "Scheduler error - failed calling ITaskScheduler::Activate, code = 0x%x - %s"
00216 #define ERR_SCHED_INVALID_PARAM "One or more arguments are invalid - please select a correct interval for scheduler"
00217 #define E_OBJECT_NOT_FOUND 0x80070002L // This should be mapped in winerror.h ??
00218
00219
00220 #define INFO_ITEM_ADDED "Added %ls item: \"%ls\""
00221 #define INFO_ITEM_UPDATED "Updated %ls item: \"%ls\""
00222 #define INFO_ITEM_DELETED "Deleted %ls item: \"%ls\""
00223 #define INFO_GET_ITEM "Retrieved %ls item: \"%ls\""
00224 #define INFO_GET_NEW_ITEM "Retrieved new %ls item: \"%ls\""
00225 #define INFO_GET_UPDATED_ITEM "Retrieved updated %ls item: \"%ls\""
00226 #define INFO_CONFIG_GENERATED "Configuration not found: default configuration will be used."
00227 #define INFO_SWV_UPGRADED "Configuration upgraded to new software version: v.%s (Funambol v.%s)"
00228 #define INFO_CONFIG_DEVID_SAVED "Set configuration deviceID = %s"
00229 #define INFO_OLD_ITEMS_NOT_FOUND "Cannot find list of items from previous sync. All items will be sent as modified."
00230 #define INFO_SYNC_COMPLETED "Syncronization process completed."
00231 #define INFO_SYNC_COMPLETED_ERRORS "Syncronization process completed with errors (code = %d)."
00232 #define INFO_EXIT "Exiting from Outlook client."
00233 #define INFO_SYNC_ABORTING "Aborting synchronization session..."
00234 #define INFO_SYNC_ABORTED_BY_USER "Synchronization aborted by user."
00235 #define INFO_SYNC_ABORTED_BY_USER_SLOW "Synchronization aborted by user to avoid full-sync of %ls."
00236 #define INFO_SCHED_TASK_CREATED "Scheduler task created."
00237 #define INFO_SCHED_TASK_DELETED "Scheduler task deleted."
00238 #define INFO_WRONG_MIME_TYPE "Warning: mime type not recognized: \"%ls\""
00239 #define INFO_REMOVING_ALL_ITEMS "Removing all existing %lss (%d items to delete)..."
00240 #define INFO_REMOVED_INTERNALLY L"Removed internally before sync"
00241
00242
00243 #define DBG_OUTLOOK_OPEN "beginSync of %ls source: opening Outlook session..."
00244 #define DBG_READ_ALL_ITEMS "Reading ALL %lss from folder '%ls' (%d found)..."
00245 #define DBG_CONFIG_CLOSED "Outlook configuration closed."
00246 #define DBG_STATE_ERR_ITEM_IGNORED "Source state is ERROR -> item will be ignored."
00247 #define DBG_LAST_SYNC_ABORTED "Last synchronization has been aborted, mutex of sync process will be released now."
00248 #define DBG_SYNC_ABORT_REQUEST "User requested to abort synchronization process..."
00249 #define DBG_THREAD_TERMINATED "Synchronization thread has been terminated."
00250 #define DBG_RRULE_BAD_FORMAT "Error parsing RRULE, bad format: %ls"
00251 #define DBG_SAFE_ITEM_NAME "Client Exception on getSafeName: %s"
00252 #define DBG_ANNIVERSARY_DELETED "While saving contact \"%ls\" an anniversary event was automatically created by Outlook and then just deleted!"
00253 #define DBG_BIRTHDAY_DELETED "While saving contact \"%ls\" a birthday event was automatically created by Outlook and then just deleted!"
00254 #define DBG_SCHED_TASK_NOT_FOUND "Scheduled task not found."
00255 #define DBG_SCHED_LAST_EXECUTION "The last task excecution was not performed. Please check windows task scheduler for more details"
00256 #define DBG_SCHED_TASK_MANUALLY_CHANGED "Scheduled task has been manually modified."
00257 #define DBG_NORMALIZING_EXCEPTION "Normalizing appointment exception: item \"%ls\", occurrence = %ls. A new item is created in Outlook."
00258 #define DBG_ITEM_CREATED_FROM_EXCEPTION "A new appointment \"%ls\" has been created from an event exception. Will be sent as NEW item next sync."
00259 #define DBG_PARSING_SIF_DATA "Parsing SIF %ls..."
00260 #define DBG_PARSING_EXCEPTIONS "Parsing appointment exceptions..."
00261 #define DBG_PARSING_VOBJ_DATA "Parsing VObject %ls (mime type = \"%ls\")..."
00262
00263
00264
00265 #define SBAR_CHECK_ALL_ITEMS 1
00266 #define SBAR_CHECK_MOD_ITEMS 2
00267 #define SBAR_CHECK_MOD_ITEMS2 3
00268 #define SBAR_WRITE_OLD_ITEMS 4
00269 #define SBAR_SENDDATA_BEGIN 5
00270 #define SBAR_SENDDATA_END 6
00271 #define SBAR_RECEIVE_DATA_BEGIN 7
00272 #define SBAR_RECEIVE_DATA_END 8
00273 #define SBAR_DELETE_CLIENT_ITEMS 9
00274 #define SBAR_ENDING_SYNC 10
00275
00276
00277
00278 #define SBAR_READING_ALLITEMS "Reading all items from Outlook (%d)..."
00279 #define SBAR_CHECKING_MODITEMS "Checking changes since last successful sync..."
00280 #define SBAR_CHECKING_MODITEMS2 "Checking changes since last successful sync (%d) ..."
00281 #define SBAR_WRITING_OLDITEMS "Writing all items list for next sync..."
00282 #define SBAR_DELETING_ITEMS "Deleting %ss from Outlook..."
00283 #define SBAR_SENDING_DATA "Sending data to the Server..."
00284 #define SBAR_RECEIVING_DATA "Receiving data from the Server..."
00285 #define SBAR_WAITING "Waiting for Server response..."
00286
00287
00288
00289 #include <mstask.h>
00290 #include "spds/SyncItem.h"
00291 #include "vocl/WinItem.h"
00292 #include "outlook/ClientItem.h"
00293 #include "outlook/ClientAppointment.h"
00294 #include "OutlookConfig.h"
00295 #include "WindowsSyncSource.h"
00296
00297 #include <string>
00298
00299
00300
00301
00302
00303 int initializeClient (bool isScheduled);
00304 int initLog (bool isScheduled);
00305 int startSync ();
00306 int closeClient ();
00307 void closeOutlook ();
00308 void checkAbortedSync ();
00309 bool checkSyncInProgress();
00310 void softTerminateSync ();
00311 int hardTerminateSync (HANDLE hSyncThread);
00312 int exitSyncThread (int code);
00313 void endSync();
00314 void upgradePlugin (const int oldVersion, const int oldFunambolVersion);
00315
00316
00317
00320 __declspec(dllexport) OutlookConfig* getConfig();
00321 void createDefaultConfig();
00322 std::wstring pickOutlookFolder (const std::wstring& itemType);
00323 std::wstring getDefaultFolderPath(const std::wstring& itemType);
00327
00330 WinItem* createWinItem (bool useSIF, const std::wstring itemType);
00331 WinItem* createWinItem (bool useSIF, const std::wstring itemType, const std::wstring& data, const WCHAR** sifFields);
00332 SyncItem* convertToSyncItem (ClientItem* cItem, const char* dataType, const std::wstring& defaultFolder);
00333 int fillClientItem (const std::wstring& sif, ClientItem* cItem, const std::wstring& itemType, const WCHAR* dataType);
00334 WCHAR** getProperSifArray (const std::wstring& type);
00335 int normalizeExceptions(ClientItem* cItem, itemKeyList& allItems, itemKeyList& allItemsPaths);
00336 int deleteOccurrencesInInterval(const DATE startDate, const DATE originalDate, ClientRecurrence* cRec);
00337 int setRecurrenceExceptions (ClientItem* cItem, std::list<std::wstring> &excludeDates, std::list<std::wstring> &includeDates);
00338 int checkIllegalXMLChars(char* data);
00339 std::wstring getVPropertyValue (const std::wstring& dataString, const std::wstring& propertyName);
00340 void replaceDefaultPath(std::wstring& path, const std::wstring& defaultFolder);
00344
00347 int setScheduler (const bool enable, const int minutes);
00348 bool getScheduler (int* minutes);
00349 int setScheduleTask (const char* frequency, const int dayNum, const int minNum);
00350 int getScheduleTask (bool* active, int* dayNum, int* minNum);
00351 int deleteScheduleTask();
00352 ITaskScheduler* initScheduleInstance();
00353 int getScheduledTaskName(std::wstring& taskName);
00356 const char* getClientLastErrorMsg ();
00357 const int getClientLastErrorCode();
00358
00359 int OpenMessageBox(HWND hwnd, UINT type, UINT msg);
00360
00371 int updateProcedure(HWND hwnd, bool manual = false);
00372
00378 bool isNewSwVersionAvailable();
00379
00385 int checkUpdate();
00386
00387 bool checkForMandatoryUpdateBeforeStartingSync();
00388
00391 #endif