00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef WINMAINCPP
00020 #define WINMAINCPP
00021
00026
00027
00028 #define PROGRAM_NAME "Funambol Outlook Plug-in"
00029 #define WPROGRAM_NAME L"Funambol Outlook Plug-in"
00030 #define PROGRAM_NAME_EXE "OutlookPlugin.exe"
00031 #define OL_PLUGIN_LOG_NAME "OLPlugin.txt"
00032 #define SYNC_MUTEX_NAME "fol-SyncInProgress"
00033 #define TIME_OUT_ABORT 8
00034 #define ASK_SLOW_TIMEOUT 25
00035 #define SCHED_DEFAULT_REPEAT_MINS 15
00036 #define SCHED_DURATION_DAYS 1
00037 #define SYNC_TIMEOUT 120
00038 #define MAX_LOG_SIZE 10000000
00039 #define EMPTY_WSTRING L""
00040
00041
00042 #define SIF_VERSION_SUPPORTED "1.0"
00043 #define VCARD_VERSION_SUPPORTED "2.1"
00044 #define ICAL_VERSION_SUPPORTED "1.0"
00045
00046
00047 #define VCARD_DEFAULT_NAME L"card"
00048 #define VCALENDAR_DEFAULT_NAME L"event"
00049 #define SIFC_DEFAULT_NAME L"scard"
00050 #define SIFE_DEFAULT_NAME L"scal"
00051
00052
00054 #define FUNAMBOL_DIR_NAME L"Funambol"
00055 #define OLPLUGIN_DIR_NAME L"Outlook Plug-in"
00056 #define MAX_PATH_LENGTH 512
00057
00058
00059
00060
00062 #define MAIL L"mail"
00063 #define CONTACT L"contact"
00064 #define APPOINTMENT L"appointment"
00065 #define TASK L"task"
00066 #define JOURNAL L"journal"
00067 #define NOTE L"note"
00068 #define POST L"post"
00069 #define DISTRIBUTION_LIST L"distribution list"
00070
00071 #define MAIL_ "mail"
00072 #define CONTACT_ "contact"
00073 #define APPOINTMENT_ "appointment"
00074 #define TASK_ "task"
00075 #define JOURNAL_ "journal"
00076 #define NOTE_ "note"
00077 #define POST_ "post"
00078 #define DISTRIBUTION_LIST_ "distribution list"
00079
00081 static WCHAR* itemTypesUsed[] = {
00082 {CONTACT },
00083 {APPOINTMENT },
00084 {TASK },
00085 {NOTE },
00086 {NULL}
00087 };
00088
00090 #define APPOINTMENT_FORCED_MODIFIED L"appointment_modified"
00091
00093 #define DEFAULT_FOLDER L"DEFAULT_FOLDER"
00094
00095 #define SYNCSOURCE_STATE_OK 1
00096 #define SYNCSOURCE_STATE_NOT_SYNCED 2
00097 #define SYNCSOURCE_STATE_CANCELED 3
00098
00099 #define ERR_CODE_DROPPED_ITEMS 2100
00100 #define ERR_CODE_DROPPED_ITEMS_SERVER 2101
00101 #define ERR_CODE_NO_SOURCES 2102
00102
00105
00108 #define SCHED_COMMENT L"Funambol Outlook Plug-in scheduler"
00109 #define SCHED_PARAM L"schedule"
00110 #define NEVER "Never"
00111 #define EVERY_DAY "Every day"
00112
00116
00117
00118
00120
00121 #define WMSGBOX_ERROR_TITLE L"Funambol Outlook Client Error"
00122 #define MSGBOX_ERROR_TITLE "Funambol Outlook Client Error"
00123 #define MSG_BOX_CANCEL_SYNC "Are you really sure you want to cancel current synchronization?"
00124 #define WMSG_BOX_CANCEL_SYNC L"Are you really sure you want to cancel current synchronization?"
00125 #define WMSG_BOX_ASK_SLOW_1 L"The server has requested a full sync of all items for "
00126 #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...)"
00127 #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?"
00128
00129
00130
00131 #define ERR_UNKNOWN "Unknown error."
00132 #define ERR_OPEN_OUTLOOK "Error opening Outlook application."
00133 #define ERR_TAG_NOT_FOUND "Bad XML format: tag '%ls' not found."
00134 #define ERR_BAD_FOLDER_PATH "Bad folder path: %ls"
00135 #define ERR_INSTALL_DIR "Error retrieving the install directory path."
00136 #define ERR_THREAD_PRIORITY "Error setting sync thread priority: code %d (%s)."
00137 #define ERR_THREAD_NOT_TERMINATED "Could not terminate the synchronization process. %s"
00138 #define ERR_MUTEX_CREATE "Could not create the mutex for synchronization process. %s"
00139 #define ERR_MUTEX_ALREADY_EXISTS "Error creating the mutex for sync process: mutex already exists. %s"
00140 #define ERR_MUTEX_NOT_RELEASED "Could not release the mutex of synchronization process. %s"
00141 #define ERR_MUTEX_OPEN "Could not open the mutex of synchronization process. %s"
00142 #define ERR_CLASS_REG_FAILED "Class Registration Failed! class name = %s"
00143 #define ERR_ENCRYPT_DATA "Error occurred encrypting private data"
00144 #define ERR_DECRYPT_DATA "Error occurred decrypting private data"
00145 #define ERR_NO_SOURCES_TO_SYNC "No sources to synchronize."
00146
00147 #define ERR_BEGIN_SYNC "Error in begin sync of source '%ls'."
00148 #define ERR_CLOSE_OUTLOOK "Some error occurred closing Outlook session. Outlook may become unstable."
00149 #define ERR_COM_INITIALIZE "Error occurred initializing COM library."
00150 #define ERR_COM_CREATE_INSTANCE "Error occurred creating an instance for COM library."
00151 #define ERR_END_SYNC "Error in end sync of source '%ls'."
00152 #define ERR_APPDATA_PATH "Error retrieving current user application data path: code %d (%s)"
00153 #define ERR_FILE_OPEN "Error opening file: %s"
00154 #define ERR_WFILE_OPEN "Error opening file: %ls"
00155 #define ERR_FILE_WRITE "Error writing file: %s"
00156 #define ERR_WFILE_WRITE "Error writing file: %ls"
00157 #define ERR_FILE_OPEN_MODE "Error writing file: bad fopen mode."
00158 #define ERR_DIR_CREATE "Error creating directory: %ls"
00159 #define ERR_DEFAULT_SSCONFIG "Error creating default config for %s: %s"
00160 #define ERR_MACHINE_NAME "GetComputerName error: code %d (%s)"
00161 #define ERR_USER_NAME "GetUserName error: code %d (%s)"
00162 #define ERR_USER_NAME_EX "GetUserNameEx error: code %d (%s)"
00163 #define ERR_INIT_LOG "Could not create the LOG file."
00164 #define ERR_INVALID_REG_PATH "Invalid windows registry path: %s."
00165 #define ERR_HKLM_KEYNOTFOUND "Error reading HKLM registry key '%s'.\nPlease reinstall the application."
00166
00167 #define ERR_FOLDER_OPEN "Error opening Outlook folder for source '%ls' with path '%ls'."
00168 #define ERR_FOLDER_PATH "'%ls' is not a folder selected for synchronization (see configuration of %ls source). Item received will be ignored."
00169 #define ERR_FOLDER_DEFAULT_PATH "Warning! No default folder found for %lss!"
00170 #define ERR_ITEM_GET "Error getting item \"%ls\" for source '%ls'."
00171 #define ERR_ITEM_GET_NEW "Error getting new item \"%ls\" for source '%ls'."
00172 #define ERR_ITEM_GET_MOD "Error getting modified item \"%ls\" for source '%ls'."
00173 #define ERR_ITEM_CREATE "Could not create a new %ls item into folder '%ls'"
00174 #define ERR_ITEM_FILL "Error setting properties of %ls item \"%ls\". Item not saved."
00175 #define ERR_ITEM_BAD_TYPE "Mime type not supported: \"%ls\""
00176 #define ERR_ITEM_SAVE "Could not save %ls item \"%ls\" into folder '%ls'"
00177 #define ERR_ITEM_DELETE "Could not delete %ls item \"%ls\" from folder '%ls'"
00178 #define ERR_ITEM_DELETE_INTERNALLY L"Error removing internally the item."
00179 #define ERR_ITEM_UPDATE_NOT_FOUND "Could not update %ls item: ID = %ls not found."
00180 #define ERR_ITEM_DELETE_NOT_FOUND "Could not delete %ls item: ID = %ls not found."
00181 #define ERR_EVENTS_CREATED "Error occurred while checking if Outlook created a birthday/anniversary event."
00182 #define ERR_SOURCE_TOO_MANY_ERRORS "%d errors occurred on source %ls: source will not be used any more."
00183 #define ERR_SOURCE_LASTSYNCTIME_NOT_FOUND "Error reading \"%ls\": <LastSyncTime> not found."
00184 #define ERR_OCCURRENCE_NOT_FOUND "Error creating the appointment exception: occurrence \"%ls\" not found."
00185 #define ERR_OCCURRENCE_NOT_DELETED "Could not delete one occurrence (date = %ls)."
00186 #define ERR_OCCURRENCE_NOT_SAVED "Could not save one occurrence (date = %ls)."
00187 #define ERR_EXCEPTIONS_DEADLOCK "Detected too many dependences between appointment exceptions (%d). Exceptions not saved correctly."
00188 #define ERR_PROPERTY_REQUIRED "Error creating %ls item: property \"%ls\" is required."
00189
00190 #define ERR_PARSE_SIF_TAG_NOT_FOUND "Parsing error: SIF tag \"%ls\" not found."
00191 #define ERR_PARSE_PROPERTY_NOT_FOUND "Parsing error: property \"%ls\" not found."
00192 #define ERR_PARSE_PROPERTY_EMPTY "Parsing error: property \"%ls\" should not be empty."
00193 #define ERR_PARSE_APP_EXCEPTION "Error parsing appointment exception: %s"
00194 #define ERR_PARSE_EXC_NOREC "Could not add exceptions on a not-recurring appointment."
00195 #define ERR_NORMALIZE_EXCEPTIONS "Error normalizing appointment exceptions: %s"
00196
00197 #define ERR_SCHED_INIT_TASK "Error initializing Windows task scheduler."
00198 #define ERR_SCHED_SAVE "Scheduler error - failed to save the task, code = 0x%x - %s"
00199 #define ERR_SCHED_DELETE "Scheduler error - failed to delete the task, code = 0x%x - %s"
00200 #define ERR_SCHED_NEWWORKITEM "Scheduler error - failed calling ITask::NewWorkItem, code = 0x%x - %s"
00201 #define ERR_SCHED_CREATE_TRIGGER "Scheduler error - failed calling ITask::CreateTrigger, code = 0x%x - %s"
00202 #define ERR_SCHED_GET_TRIGGER "Scheduler error - failed calling ITask::GetTrigger, code = 0x%x - %s"
00203 #define ERR_SCHED_GET_TRIGGER2 "Scheduler error - failed calling ITaskTrigger::GetTrigger, code = 0x%x - %s"
00204 #define ERR_SCHED_SET_TRIGGER "Scheduler error - failed calling ITaskTrigger::SetTrigger, code = 0x%x - %s"
00205 #define ERR_SCHED_QUERY_INTERFACE "Scheduler error - failed calling ITask::QueryInterface, code = 0x%x - %s"
00206 #define ERR_SCHED_ACTIVATE "Scheduler error - failed calling ITaskScheduler::Activate, code = 0x%x - %s"
00207 #define ERR_SCHED_INVALID_PARAM "One or more arguments are invalid - please select a correct interval for scheduler"
00208 #define E_OBJECT_NOT_FOUND 0x80070002L // This should be mapped in winerror.h ??
00209
00210
00211 #define INFO_ITEM_ADDED "Added %ls item: \"%ls\""
00212 #define INFO_ITEM_UPDATED "Updated %ls item: \"%ls\""
00213 #define INFO_ITEM_DELETED "Deleted %ls item: \"%ls\""
00214 #define INFO_GET_ITEM "Retrieved %ls item: \"%ls\""
00215 #define INFO_GET_NEW_ITEM "Retrieved new %ls item: \"%ls\""
00216 #define INFO_GET_UPDATED_ITEM "Retrieved updated %ls item: \"%ls\""
00217 #define INFO_CONFIG_GENERATED "Configuration not found: default configuration will be used."
00218 #define INFO_SWV_UPGRADED "Configuration upgraded to new software version: %s"
00219 #define INFO_CONFIG_DEVID_SAVED "Set configuration deviceID = %s"
00220 #define INFO_OLD_ITEMS_NOT_FOUND "Cannot find list of items from previous sync. All items will be sent as modified."
00221 #define INFO_SYNC_COMPLETED "Syncronization process completed."
00222 #define INFO_SYNC_COMPLETED_ERRORS "Syncronization process completed with errors (code = %d)."
00223 #define INFO_EXIT "Exiting from Outlook client."
00224 #define INFO_SYNC_ABORTING "Aborting synchronization session..."
00225 #define INFO_SYNC_ABORTED_BY_USER "Synchronization aborted by user."
00226 #define INFO_SYNC_ABORTED_BY_USER_SLOW "Synchronization aborted by user to avoid full-sync of %ls."
00227 #define INFO_SCHED_TASK_CREATED "Scheduler task created."
00228 #define INFO_SCHED_TASK_DELETED "Scheduler task deleted."
00229 #define INFO_WRONG_MIME_TYPE "Warning: mime type not recognized: \"%ls\""
00230 #define INFO_REMOVING_ALL_ITEMS "Removing all existing %lss (%d items to delete)..."
00231 #define INFO_REMOVED_INTERNALLY L"Removed internally before sync"
00232
00233
00234 #define DBG_OUTLOOK_OPEN "beginSync of %ls source: opening Outlook session..."
00235 #define DBG_READ_ALL_ITEMS "Reading ALL %lss from folder '%ls' (%d found)..."
00236 #define DBG_CONFIG_CLOSED "Outlook configuration closed."
00237 #define DBG_STATE_ERR_ITEM_IGNORED "Source state is ERROR -> item will be ignored."
00238 #define DBG_LAST_SYNC_ABORTED "Last synchronization has been aborted, mutex of sync process will be released now."
00239 #define DBG_SYNC_ABORT_REQUEST "User requested to abort synchronization process..."
00240 #define DBG_THREAD_TERMINATED "Synchronization thread has been terminated."
00241 #define DBG_RRULE_BAD_FORMAT "Error parsing RRULE, bad format: %ls"
00242 #define DBG_SAFE_ITEM_NAME "Client Exception on getSafeName: %s"
00243 #define DBG_ANNIVERSARY_DELETED "While saving contact \"%ls\" an anniversary event was automatically created by Outlook and then just deleted!"
00244 #define DBG_BIRTHDAY_DELETED "While saving contact \"%ls\" a birthday event was automatically created by Outlook and then just deleted!"
00245 #define DBG_SCHED_TASK_NOT_FOUND "Scheduled task not found."
00246 #define DBG_SCHED_LAST_EXECUTION "The last task excecution was not performed. Please check windows task scheduler for more details"
00247 #define DBG_SCHED_TASK_MANUALLY_CHANGED "Scheduled task has been manually modified."
00248 #define DBG_NORMALIZING_EXCEPTION "Normalizing appointment exception: item \"%ls\", occurrence = %ls. A new item is created in Outlook."
00249 #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."
00250 #define DBG_PARSING_SIF_DATA "Parsing SIF %ls..."
00251 #define DBG_PARSING_EXCEPTIONS "Parsing appointment exceptions..."
00252 #define DBG_PARSING_VOBJ_DATA "Parsing VObject %ls (mime type = \"%ls\")..."
00253
00254
00255
00256 #define SBAR_CHECK_ALL_ITEMS 1
00257 #define SBAR_CHECK_MOD_ITEMS 2
00258 #define SBAR_CHECK_MOD_ITEMS2 3
00259 #define SBAR_WRITE_OLD_ITEMS 4
00260 #define SBAR_SENDDATA_BEGIN 5
00261 #define SBAR_SENDDATA_END 6
00262 #define SBAR_RECEIVE_DATA_BEGIN 7
00263 #define SBAR_RECEIVE_DATA_END 8
00264 #define SBAR_DELETE_CLIENT_ITEMS 9
00265
00266
00267
00268 #define SBAR_READING_ALLITEMS "Reading all items from Outlook (%d)..."
00269 #define SBAR_CHECKING_MODITEMS "Checking changes since last successful sync..."
00270 #define SBAR_CHECKING_MODITEMS2 "Checking changes since last successful sync (%d) ..."
00271 #define SBAR_WRITING_OLDITEMS "Writing all items list for next sync..."
00272 #define SBAR_DELETING_ITEMS "Deleting %ss from Outlook..."
00273 #define SBAR_SENDING_DATA "Sending data to the Server..."
00274 #define SBAR_RECEIVING_DATA "Receiving data from the Server..."
00275 #define SBAR_WAITING "Waiting for Server response..."
00276
00277
00278
00279 #include <mstask.h>
00280 #include "spds/SyncItem.h"
00281 #include "vocl/WinItem.h"
00282 #include "outlook/ClientItem.h"
00283 #include "outlook/ClientAppointment.h"
00284 #include "OutlookConfig.h"
00285 #include "WindowsSyncSource.h"
00286
00287 #include <string>
00288
00289
00290
00291
00292
00293 int initializeClient (bool isScheduled);
00294 int initLog (bool isScheduled);
00295 int startSync ();
00296 int closeClient ();
00297 void closeOutlook ();
00298 void checkAbortedSync ();
00299 bool checkSyncInProgress();
00300 void softTerminateSync ();
00301 int hardTerminateSync (HANDLE hSyncThread);
00302 int exitSyncThread (int code);
00303 void endSync();
00304 void upgradePlugin (int oldVersion);
00305
00306
00307
00310 __declspec(dllexport) OutlookConfig* getConfig();
00311 void createDefaultConfig();
00312 std::wstring pickOutlookFolder (const std::wstring& itemType);
00313 std::wstring getDefaultFolderPath(const std::wstring& itemType);
00317
00320 WinItem* createWinItem (bool useSIF, const std::wstring itemType);
00321 WinItem* createWinItem (bool useSIF, const std::wstring itemType, const std::wstring& data, const WCHAR** sifFields);
00322 SyncItem* convertToSyncItem (ClientItem* cItem, const char* dataType, const std::wstring& defaultFolder);
00323 int fillClientItem (const std::wstring& sif, ClientItem* cItem, const std::wstring& itemType, const WCHAR* dataType);
00324 std::wstring formatAppExceptions(ClientAppointment* cApp);
00325 int parseAppExceptions (const std::wstring& sifString, ClientItem* cItem);
00326 int checkFreeOccurrence(ClientAppointment* cApp, const std::wstring& sifString, const std::wstring& originalDate);
00327 WCHAR** getProperSifArray (const std::wstring& type);
00328 int normalizeExceptions(ClientItem* cItem, itemKeyList& allItems, itemKeyList& allItemsPaths);
00329 int deleteOccurrencesInInterval(const DATE startDate, const DATE originalDate, ClientRecurrence* cRec);
00330 int setRecurrenceExceptions (ClientItem* cItem, std::list<std::wstring> &excludeDates, std::list<std::wstring> &includeDates);
00331 int checkIllegalXMLChars(char* data);
00332 std::wstring getVPropertyValue (const std::wstring& dataString, const std::wstring& propertyName);
00333 void addPropertyToSIF(const std::wstring propertyName, std::wstring propertyValue, std::wstring& sif);
00334 std::wstring adaptToSIFSpecs(const std::wstring& propName, const std::wstring& propValue, const std::wstring& type);
00335 std::wstring adaptFromSIFSpecs(const std::wstring& propName, const std::wstring& propValue, const std::wstring& type);
00336 void replaceDefaultPath(std::wstring& path, const std::wstring& defaultFolder);
00340
00343 int setScheduler (const bool enable, const int minutes);
00344 bool getScheduler (int* minutes);
00345 int setScheduleTask (const char* frequency, const int dayNum, const int minNum);
00346 int getScheduleTask (bool* active, int* dayNum, int* minNum);
00347 int deleteScheduleTask();
00348 ITaskScheduler* initScheduleInstance();
00349 int ".">getScheduledTaskName(std::wstring& taskName);
00352 char* getClientLastErrorMsg ();
00353 int getClientLastErrorCode();
00354
00355
00358 #endif