D:/develop/v65/clients/outlook/install/output/export/funambol/clients/outlook/mainclientDll/src/include/winmaincpp.h

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

Generated on Mon Feb 4 09:50:49 2008 for Funambol Outlook Plug-in Library by  doxygen 1.5.2