diff options
author | hristoterezov <hristo@jitsi.org> | 2014-04-02 17:04:44 +0300 |
---|---|---|
committer | hristoterezov <hristo@jitsi.org> | 2014-04-02 17:04:44 +0300 |
commit | 96ef724f2db9365250a7a9d76dbe8b19c3987f55 (patch) | |
tree | ef97430715621ab5579739acd4fa75903c048026 /src/native/addrbook/msoutlook/MsOutlookCalendar.cxx | |
parent | a325c6bc19214271cf7e98768179b5a71257eb91 (diff) | |
download | jitsi-96ef724f2db9365250a7a9d76dbe8b19c3987f55.zip jitsi-96ef724f2db9365250a7a9d76dbe8b19c3987f55.tar.gz jitsi-96ef724f2db9365250a7a9d76dbe8b19c3987f55.tar.bz2 |
Adds CalendarService implementation. The Calendar service calculates the free busy status based on outlook meetings.
Diffstat (limited to 'src/native/addrbook/msoutlook/MsOutlookCalendar.cxx')
-rw-r--r-- | src/native/addrbook/msoutlook/MsOutlookCalendar.cxx | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/src/native/addrbook/msoutlook/MsOutlookCalendar.cxx b/src/native/addrbook/msoutlook/MsOutlookCalendar.cxx new file mode 100644 index 0000000..5667488 --- /dev/null +++ b/src/native/addrbook/msoutlook/MsOutlookCalendar.cxx @@ -0,0 +1,194 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +#include "MsOutlookUtils.h" +#include "MsOutlookAddrBookContactQuery.h" +#include "MsOutlookCalendar.h" +#include "MAPINotification.h" +#include "MsOutlookAddrBookContactSourceService.h" + +#include "MAPISession.h" +#include "StringUtils.h" +#include <Mapidefs.h> +#include <jni.h> + +static ULONG MsOutlookCalendar_rdOpenEntryUlFlags = 0x0; + +static void* callbackObject = NULL; + +jboolean MsOutlookCalendar_foreachCalendarItemCallback( + LPSTR iUnknown, + void * object); + +static jboolean +MsOutlookCalendar_onForeachCalendarInMsgStoresTableRow + (LPUNKNOWN mapiSession, + ULONG entryIDByteCount, LPENTRYID entryID, ULONG objType, + const char * query, void * callbackMethod, void * callbackClient, + long callbackAddress); + +static HRESULT +MsOutlookCalendar_getCalendarFolderEntryID + (LPMDB msgStore, + ULONG folderEntryIDByteCount, LPENTRYID folderEntryID, + ULONG *calendarFolderEntryIDByteCount, LPENTRYID *calendarFolderEntryID, + ULONG flags); + +void MsOutlookCalendar_setCallbackObject(void *callback) +{ + callbackObject = callback; +} + +void MsOutlookCalendar_getAllCalendarItems( + void * callbackMethod, + void * callbackClient, + long callbackAddress) +{ + MAPISession_lock(); + LPMAPISESSION mapiSession = MAPISession_getMapiSession(); + if (mapiSession == NULL) + { + MAPISession_unlock(); + return; + } + HRESULT hResult; + LPMAPITABLE msgStoresTable = NULL; + hResult = mapiSession->GetMsgStoresTable(0, &msgStoresTable); + if (HR_SUCCEEDED(hResult) && msgStoresTable) + { + MsOutlookAddrBookContactQuery_foreachRowInTable( + msgStoresTable, + MsOutlookCalendar_onForeachCalendarInMsgStoresTableRow, + (LPUNKNOWN) mapiSession, + NULL,callbackMethod, + callbackClient, + callbackAddress); + msgStoresTable->Release(); + } + + MAPISession_unlock(); +} + +jboolean MsOutlookCalendar_foreachCalendarItemCallback( + LPSTR iUnknown, + long callbackObject) +{ + + LPWSTR iUnknownW = StringUtils::MultiByteToWideChar(iUnknown); + BSTR res = SysAllocString(iUnknownW); + + char * charId = StringUtils::WideCharToMultiByte(res); + MAPINotification_callCallbackMethod(charId, callbackObject); + free(charId); + + SysFreeString(res); + free(iUnknownW); + + return true; +} + + +static jboolean +MsOutlookCalendar_onForeachCalendarInMsgStoresTableRow + (LPUNKNOWN mapiSession, + ULONG entryIDByteCount, LPENTRYID entryID, ULONG objType, + const char * query, + void * callbackMethod, + void * callbackClient, + long callbackAddress) +{ + HRESULT hResult; + LPMDB msgStore; + // In case, that we've failed but other parts of the hierarchy may still + // succeed. + jboolean proceed = JNI_TRUE; + + hResult = ((LPMAPISESSION) mapiSession)->OpenMsgStore( + 0, + entryIDByteCount, entryID, + NULL, + MDB_NO_MAIL | MsOutlookCalendar_rdOpenEntryUlFlags, + &msgStore); + if (HR_SUCCEEDED(hResult)) + { + LPENTRYID receiveFolderEntryID = NULL; + ULONG calendarFolderEntryIDByteCount = 0; + LPENTRYID calendarFolderEntryID = NULL; + + hResult = msgStore->GetReceiveFolder( + NULL, + 0, + &entryIDByteCount, + &receiveFolderEntryID, + NULL); + if (HR_SUCCEEDED(hResult)) + { + hResult = MsOutlookCalendar_getCalendarFolderEntryID( + msgStore, + entryIDByteCount, + receiveFolderEntryID, + &calendarFolderEntryIDByteCount, + &calendarFolderEntryID, + MsOutlookCalendar_rdOpenEntryUlFlags); + MAPIFreeBuffer(receiveFolderEntryID); + } + if (HR_FAILED(hResult)) + { + hResult = MsOutlookCalendar_getCalendarFolderEntryID( + msgStore, + 0, + NULL, + &calendarFolderEntryIDByteCount, + &calendarFolderEntryID, + MsOutlookCalendar_rdOpenEntryUlFlags); + } + if (HR_SUCCEEDED(hResult)) + { + ULONG calendarFolderObjType; + LPUNKNOWN calendarFolder; + + hResult = msgStore->OpenEntry( + calendarFolderEntryIDByteCount, + calendarFolderEntryID, + NULL, + MsOutlookCalendar_rdOpenEntryUlFlags, + &calendarFolderObjType, + &calendarFolder); + if (HR_SUCCEEDED(hResult)) + { + proceed = MsOutlookAddrBookContactQuery_foreachMailUser( + calendarFolderObjType, + calendarFolder, + query, + callbackMethod, + callbackClient, + callbackAddress); + calendarFolder->Release(); + } + MAPIFreeBuffer(calendarFolderEntryID); + } + msgStore->Release(); + } + + return proceed; +} + +static HRESULT +MsOutlookCalendar_getCalendarFolderEntryID + (LPMDB msgStore, + ULONG folderEntryIDByteCount, LPENTRYID folderEntryID, + ULONG *calendarFolderEntryIDByteCount, LPENTRYID *calendarFolderEntryID, + ULONG flags) +{ + return MsOutlookUtils_getFolderEntryIDByType( + msgStore, + folderEntryIDByteCount, + folderEntryID, + calendarFolderEntryIDByteCount, + calendarFolderEntryID, + flags, + 0x36D00102); +} |