diff options
Diffstat (limited to 'src/native/addrbook/msoutlook')
22 files changed, 1082 insertions, 400 deletions
diff --git a/src/native/addrbook/msoutlook/MAPINotification.cxx b/src/native/addrbook/msoutlook/MAPINotification.cxx index d2f2422..5a3a500 100644 --- a/src/native/addrbook/msoutlook/MAPINotification.cxx +++ b/src/native/addrbook/msoutlook/MAPINotification.cxx @@ -43,13 +43,23 @@ static ULONG MAPINotification_nbMsgStores = 0; static jmethodID MAPINotification_notificationsDelegateMethodIdDeleted = NULL; static jmethodID MAPINotification_notificationsDelegateMethodIdInserted = NULL; static jmethodID MAPINotification_notificationsDelegateMethodIdUpdated = NULL; +static jmethodID MAPINotification_notificationsDelegateCalendarMethodIdDeleted + = NULL; +static jmethodID MAPINotification_notificationsDelegateCalendarMethodIdInserted + = NULL; +static jmethodID MAPINotification_notificationsDelegateCalendarMethodIdUpdated + = NULL; static jobject MAPINotification_notificationsDelegateObject = NULL; +static jobject MAPINotification_notificationsDelegateCalendarObject = NULL; static ULONG MAPINotification_openEntryUlFlags = MAPI_BEST_ACCESS; static JavaVM * MAPINotification_VM = NULL; void (*MAPINotification_callDeletedMethod)(LPSTR iUnknown) = NULL; void (*MAPINotification_callInsertedMethod)(LPSTR iUnknown) = NULL; void (*MAPINotification_callUpdatedMethod)(LPSTR iUnknown) = NULL; +void (*MAPINotification_callCalendarDeletedMethod)(LPSTR iUnknown) = NULL; +void (*MAPINotification_callCalendarInsertedMethod)(LPSTR iUnknown) = NULL; +void (*MAPINotification_callCalendarUpdatedMethod)(LPSTR iUnknown) = NULL; ULONG MAPINotification_registerNotifyMessageDataBase (LPMDB iUnknown, LPMAPIADVISESINK * adviseSink); @@ -129,10 +139,17 @@ void MAPINotification_jniCallDeletedMethod(LPSTR iUnknown) { jstring value = tmpJniEnv->NewStringUTF(iUnknown); - tmpJniEnv->CallVoidMethod( - MAPINotification_notificationsDelegateObject, - MAPINotification_notificationsDelegateMethodIdDeleted, - value); + if(MAPINotification_notificationsDelegateObject != NULL) + tmpJniEnv->CallVoidMethod( + MAPINotification_notificationsDelegateObject, + MAPINotification_notificationsDelegateMethodIdDeleted, + value); + + if(MAPINotification_notificationsDelegateCalendarObject != NULL) + tmpJniEnv->CallVoidMethod( + MAPINotification_notificationsDelegateCalendarObject, + MAPINotification_notificationsDelegateCalendarMethodIdDeleted, + value); tmpJniEnv->DeleteLocalRef(value); @@ -154,10 +171,17 @@ void MAPINotification_jniCallInsertedMethod(LPSTR iUnknown) { jstring value = tmpJniEnv->NewStringUTF(iUnknown); - tmpJniEnv->CallVoidMethod( - MAPINotification_notificationsDelegateObject, - MAPINotification_notificationsDelegateMethodIdInserted, - value); + if(MAPINotification_notificationsDelegateObject != NULL) + tmpJniEnv->CallVoidMethod( + MAPINotification_notificationsDelegateObject, + MAPINotification_notificationsDelegateMethodIdInserted, + value); + + if(MAPINotification_notificationsDelegateCalendarObject != NULL) + tmpJniEnv->CallVoidMethod( + MAPINotification_notificationsDelegateCalendarObject, + MAPINotification_notificationsDelegateCalendarMethodIdInserted, + value); tmpJniEnv->DeleteLocalRef(value); @@ -173,16 +197,23 @@ void MAPINotification_jniCallInsertedMethod(LPSTR iUnknown) void MAPINotification_jniCallUpdatedMethod(LPSTR iUnknown) { JNIEnv *tmpJniEnv = NULL; - if(MAPINotification_VM ->AttachCurrentThreadAsDaemon((void**) &tmpJniEnv, NULL) == 0) { jstring value = tmpJniEnv->NewStringUTF(iUnknown); - tmpJniEnv->CallVoidMethod( - MAPINotification_notificationsDelegateObject, - MAPINotification_notificationsDelegateMethodIdUpdated, - value); + if(MAPINotification_notificationsDelegateObject != NULL) + tmpJniEnv->CallVoidMethod( + MAPINotification_notificationsDelegateObject, + MAPINotification_notificationsDelegateMethodIdUpdated, + value); + + if(MAPINotification_notificationsDelegateCalendarObject != NULL) + tmpJniEnv->CallVoidMethod( + MAPINotification_notificationsDelegateCalendarObject, + MAPINotification_notificationsDelegateCalendarMethodIdUpdated, + value); + tmpJniEnv->DeleteLocalRef(value); @@ -425,6 +456,60 @@ MAPINotification_registerJniNotificationsDelegate } } + +/** + * Registers java callback functions when a calendar item is deleted, inserted or + * updated. + * + * @param jniEnv The Java native interface environment. + * @param notificationsDelegate The object called when a notification is fired + * (contact updated, inserted or deleted). + */ +void +MAPINotification_registerCalendarJniNotificationsDelegate + (JNIEnv *jniEnv, jobject notificationsDelegate) +{ + if(jniEnv->GetJavaVM(&MAPINotification_VM) < 0) + { + fprintf(stderr, "Failed to get the Java VM\n"); + fflush(stderr); + } + + if(notificationsDelegate != NULL) + { + MAPINotification_notificationsDelegateCalendarObject + = jniEnv->NewGlobalRef(notificationsDelegate); + if(MAPINotification_notificationsDelegateCalendarObject != NULL) + { + jclass callbackClass + = jniEnv->GetObjectClass(notificationsDelegate); + MAPINotification_notificationsDelegateCalendarMethodIdInserted + = jniEnv->GetMethodID( + callbackClass, + "inserted", + "(Ljava/lang/String;)V"); + MAPINotification_notificationsDelegateCalendarMethodIdUpdated + = jniEnv->GetMethodID( + callbackClass, + "updated", + "(Ljava/lang/String;)V"); + MAPINotification_notificationsDelegateCalendarMethodIdDeleted + = jniEnv->GetMethodID( + callbackClass, + "deleted", + "(Ljava/lang/String;)V"); + + MAPINotification_callDeletedMethod + = MAPINotification_jniCallDeletedMethod; + MAPINotification_callInsertedMethod + = MAPINotification_jniCallInsertedMethod; + MAPINotification_callUpdatedMethod + = MAPINotification_jniCallUpdatedMethod; + + jniEnv->DeleteLocalRef(callbackClass); + } + } +} /** * Registers C callback functions when a contact is deleted, inserted or * updated. diff --git a/src/native/addrbook/msoutlook/MAPINotification.h b/src/native/addrbook/msoutlook/MAPINotification.h index f1517d7..f7b9f05 100644 --- a/src/native/addrbook/msoutlook/MAPINotification.h +++ b/src/native/addrbook/msoutlook/MAPINotification.h @@ -36,6 +36,10 @@ STDAPICALLTYPE MAPINotification_onNotify void MAPINotification_registerJniNotificationsDelegate (JNIEnv *jniEnv, jobject notificationsDelegate); + +void +MAPINotification_registerCalendarJniNotificationsDelegate + (JNIEnv *jniEnv, jobject notificationsDelegate); void MAPINotification_registerNativeNotificationsDelegate (void * deletedMethod, void * insertedMethod, void *updatedMethod); diff --git a/src/native/addrbook/msoutlook/MAPISession.cxx b/src/native/addrbook/msoutlook/MAPISession.cxx index fb672b4..2b6988d 100644 --- a/src/native/addrbook/msoutlook/MAPISession.cxx +++ b/src/native/addrbook/msoutlook/MAPISession.cxx @@ -5,6 +5,7 @@ * See terms of license at gnu.org.
*/
#include "MAPISession.h"
+#include <stdio.h>
static LPMAPISESSION MAPISession_mapiSession = NULL;
static CRITICAL_SECTION MAPISession_mapiSessionCriticalSection;
diff --git a/src/native/addrbook/msoutlook/MsOutlookAddrBookContactQuery.cxx b/src/native/addrbook/msoutlook/MsOutlookAddrBookContactQuery.cxx index d24b305..f3d9d2f 100644 --- a/src/native/addrbook/msoutlook/MsOutlookAddrBookContactQuery.cxx +++ b/src/native/addrbook/msoutlook/MsOutlookAddrBookContactQuery.cxx @@ -5,6 +5,7 @@ * See terms of license at gnu.org. */ +#include "MsOutlookUtils.h" #include "MsOutlookAddrBookContactQuery.h" #include "MsOutlookAddrBookContactSourceService.h" @@ -43,22 +44,10 @@ typedef struct MsOutlookAddrBookContactQuery_OneOffEntryID typedef UNALIGNED ONEOFFENTRYID *MsOutlookAddrBookContactQuery_LPONEOFFENTRYID; -typedef - jboolean (*MsOutlookAddrBookContactQuery_ForeachRowInTableCallback) - (LPUNKNOWN iUnknown, - ULONG entryIDByteCount, LPENTRYID entryID, ULONG objType, - const char * query, - void * callbackMethod, - void * callbackClient, - long callbackAddress); - static ULONG MsOutlookAddrBookContactQuery_rdOpenEntryUlFlags = 0x0; static ULONG MsOutlookAddrBookContactQuery_rwOpenEntryUlFlags = MAPI_BEST_ACCESS; -static HRESULT MsOutlookAddrBookContactQuery_HrGetOneProp - (LPMAPIPROP mapiProp, ULONG propTag, LPSPropValue *prop); - HRESULT MsOutlookAddrBookContactQuery_buildOneOff (LPWSTR displayName, LPWSTR addressType, LPWSTR emailAddress, ULONG* oneOffEntryIdLength, LPBYTE* oneOffEntryId); @@ -69,26 +58,12 @@ HRESULT MsOutlookAddrBookContactQuery_createEmailAddress static jboolean MsOutlookAddrBookContactQuery_foreachContactInMsgStoresTable (LPMAPISESSION mapiSession, const char * query, void * callbackMethod, void * callbackClient, long callbackAddress); -static jboolean MsOutlookAddrBookContactQuery_foreachMailUser - (ULONG objType, LPUNKNOWN iUnknown, - const char * query, - void * callbackMethod, - void * callbackClient, - long callbackAddress); static jboolean MsOutlookAddrBookContactQuery_foreachMailUserInContainerTable (LPMAPICONTAINER mapiContainer, LPMAPITABLE mapiTable, const char * query, void * callbackMethod, void * callbackClient, long callbackAddress); -static jboolean MsOutlookAddrBookContactQuery_foreachRowInTable - (LPMAPITABLE mapiTable, - MsOutlookAddrBookContactQuery_ForeachRowInTableCallback rowCallback, - LPUNKNOWN iUnknown, - const char * query, - void * callbackMethod, - void * callbackClient, - long callbackAddress); static void MsOutlookAddrBookContactQuery_freeSRowSet(LPSRowSet rows); static void* MsOutlookAddrBookContactQuery_getAttachmentContactPhoto (LPMESSAGE message, ULONGLONG * length); @@ -104,9 +79,9 @@ LPMAPIFOLDER MsOutlookAddrBookContactQuery_getDefaultContactFolderId (ULONG flags); LPMDB MsOutlookAddrBookContactQuery_getDefaultMsgStores(ULONG flags); ULONG MsOutlookAddrBookContactQuery_getPropTag - (LPMAPIPROP mapiProp, long propId, long propType); + (LPMAPIPROP mapiProp, long propId, long propType, UUID UUID_Address); static ULONG MsOutlookAddrBookContactQuery_getPropTagFromLid - (LPMAPIPROP mapiProp, LONG lid); + (LPMAPIPROP mapiProp, LONG lid, UUID UUID_Address); static jboolean MsOutlookAddrBookContactQuery_mailUserMatches (LPMAPIPROP mailUser, const char * query); static jboolean MsOutlookAddrBookContactQuery_onForeachContactInMsgStoresTableRow @@ -470,7 +445,7 @@ MsOutlookAddrBookContactQuery_foreachContactInMsgStoresTable return proceed; } -static jboolean +jboolean MsOutlookAddrBookContactQuery_foreachMailUser (ULONG objType, LPUNKNOWN iUnknown, const char * query, @@ -567,7 +542,7 @@ MsOutlookAddrBookContactQuery_foreachMailUserInContainerTable callbackAddress); } -static jboolean +jboolean MsOutlookAddrBookContactQuery_foreachRowInTable (LPMAPITABLE mapiTable, MsOutlookAddrBookContactQuery_ForeachRowInTableCallback rowCallback, @@ -823,46 +798,14 @@ MsOutlookAddrBookContactQuery_getContactsFolderEntryID ULONG *contactsFolderEntryIDByteCount, LPENTRYID *contactsFolderEntryID, ULONG flags) { - HRESULT hResult; - ULONG objType; - LPUNKNOWN folder; - - hResult = msgStore->OpenEntry( - folderEntryIDByteCount, - folderEntryID, - NULL, - flags, - &objType, - &folder); - - if (HR_SUCCEEDED(hResult)) - { - LPSPropValue prop; - - hResult - = MsOutlookAddrBookContactQuery_HrGetOneProp( - (LPMAPIPROP) folder, - 0x36D10102 /* PR_IPM_CONTACT_ENTRYID */, - &prop); - if (HR_SUCCEEDED(hResult)) - { - LPSBinary bin = &(prop->Value.bin); - if (S_OK - == MAPIAllocateBuffer( - bin->cb, - (void **) contactsFolderEntryID)) - { - hResult = S_OK; - *contactsFolderEntryIDByteCount = bin->cb; - CopyMemory(*contactsFolderEntryID, bin->lpb, bin->cb); - } - else - hResult = MAPI_E_NOT_ENOUGH_MEMORY; - MAPIFreeBuffer(prop); - } - folder->Release(); - } - return hResult; + return MsOutlookUtils_getFolderEntryIDByType( + msgStore, + folderEntryIDByteCount, + folderEntryID, + contactsFolderEntryIDByteCount, + contactsFolderEntryID, + flags, + 0x36D10102 /* PR_IPM_CONTACT_ENTRYID */); } /** @@ -1038,7 +981,8 @@ LPMDB MsOutlookAddrBookContactQuery_getDefaultMsgStores(ULONG flags) * @return The property tag associated for the given identifier and type. */ ULONG MsOutlookAddrBookContactQuery_getPropTag - (LPMAPIPROP mapiProp, long propId, long propType) + (LPMAPIPROP mapiProp, long propId, long propType, + UUID UUID_Address) { ULONG propTag; @@ -1053,7 +997,7 @@ ULONG MsOutlookAddrBookContactQuery_getPropTag { propTag = MsOutlookAddrBookContactQuery_getPropTagFromLid( (LPMAPIPROP) mapiProp, - (LONG)propId); + (LONG)propId, UUID_Address); propTag = CHANGE_PROP_TYPE(propTag, propType); } @@ -1061,17 +1005,15 @@ ULONG MsOutlookAddrBookContactQuery_getPropTag } static ULONG -MsOutlookAddrBookContactQuery_getPropTagFromLid(LPMAPIPROP mapiProp, LONG lid) +MsOutlookAddrBookContactQuery_getPropTagFromLid(LPMAPIPROP mapiProp, LONG lid, + UUID UUID_Address) { - GUID PSETID_Address - = {0x00062004, 0x0000, 0x0000, - {0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}; MAPINAMEID propName; LPMAPINAMEID propNamePtr; HRESULT hResult; LPSPropTagArray propTagArray; - propName.lpguid = (LPGUID) &PSETID_Address; + propName.lpguid = (LPGUID) &UUID_Address; propName.ulKind = MNID_ID; propName.Kind.lID = lid; propNamePtr = &propName; @@ -1094,55 +1036,6 @@ MsOutlookAddrBookContactQuery_getPropTagFromLid(LPMAPIPROP mapiProp, LONG lid) } /** - * Get one property for a given contact. - * - * @param mapiProp A pointer to the contact. - * @param propTag The tag of the property to get. - * @param prop The memory location to store the property value. - * - * @return S_OK if everything work fine. Any other value is a failure. - */ -static HRESULT -MsOutlookAddrBookContactQuery_HrGetOneProp( - LPMAPIPROP mapiProp, - ULONG propTag, - LPSPropValue *prop) -{ - SPropTagArray propTagArray; - HRESULT hResult; - ULONG valueCount; - LPSPropValue values; - - propTagArray.cValues = 1; - propTagArray.aulPropTag[0] = propTag; - - hResult = mapiProp->GetProps(&propTagArray, 0, &valueCount, &values); - if (HR_SUCCEEDED(hResult)) - { - ULONG i; - jboolean propHasBeenAssignedTo = JNI_FALSE; - - for (i = 0; i < valueCount; i++) - { - LPSPropValue value = values; - - values++; - if (value->ulPropTag == propTag) - { - *prop = value; - propHasBeenAssignedTo = JNI_TRUE; - } - else - MAPIFreeBuffer(value); - } - if (!propHasBeenAssignedTo) - hResult = MAPI_E_NOT_FOUND; - MAPIFreeBuffer(values); - } - return hResult; -} - -/** * Deletes one property from a contact. * * @param propId The outlook property identifier. @@ -1199,7 +1092,8 @@ int MsOutlookAddrBookContactQuery_IMAPIProp_1DeleteProp propTag = MsOutlookAddrBookContactQuery_getPropTag( (LPMAPIPROP) mapiProp, propIds[i], - PT_UNICODE); + PT_UNICODE, + MsOutlookAddrBookContactQuery_UUID_Address); *(propTagArray->aulPropTag + i) = propTag; } @@ -1233,7 +1127,8 @@ int MsOutlookAddrBookContactQuery_IMAPIProp_1DeleteProp propToDelete.aulPropTag[0] = MsOutlookAddrBookContactQuery_getPropTag( (LPMAPIPROP) mapiProp, propId, - PT_UNICODE); + PT_UNICODE, + MsOutlookAddrBookContactQuery_UUID_Address); HRESULT hResult = ((LPMAPIPROP) mapiProp)->DeleteProps( @@ -1265,7 +1160,8 @@ HRESULT MsOutlookAddrBookContactQuery_IMAPIProp_1GetProps( long flags, void ** props, unsigned long* propsLength, - char * propsType) + char * propsType, + UUID UUID_Address) { HRESULT hr = E_FAIL; LPSPropTagArray propTagArray; @@ -1296,7 +1192,8 @@ HRESULT MsOutlookAddrBookContactQuery_IMAPIProp_1GetProps( ULONG propTag = MsOutlookAddrBookContactQuery_getPropTag( (LPMAPIPROP) mapiProp, propId, - PT_UNSPECIFIED); + PT_UNSPECIFIED, + UUID_Address); *(propTagArray->aulPropTag + i) = propTag; } @@ -1334,6 +1231,19 @@ HRESULT MsOutlookAddrBookContactQuery_IMAPIProp_1GetProps( (ULONGLONG*) &propsLength[j]); propsType[j] = 'b'; // byte array } + else if(prop->Value.b) + { + propsLength[j] = sizeof(prop->Value.b); + if( (props[j] = malloc(propsLength[j])) + != NULL) + { + memcpy( + props[j], + &prop->Value.b, + propsLength[j]); + propsType[j] = 'B'; + } + } break; } @@ -1391,18 +1301,55 @@ HRESULT MsOutlookAddrBookContactQuery_IMAPIProp_1GetProps( case PT_BINARY: { - propsLength[j] = prop->Value.bin.cb * 2 + 1; - if((props[j] = malloc(propsLength[j])) - != NULL) - { - HexFromBin( - prop->Value.bin.lpb, - prop->Value.bin.cb, - (LPSTR) props[j]); + if(IsEqualGUID(UUID_Address, MsOutlookAddrBookContactQuery_UUID_Address)) + { + propsLength[j] = prop->Value.bin.cb * 2 + 1; + if((props[j] = malloc(propsLength[j])) + != NULL) + { + HexFromBin( + prop->Value.bin.lpb, + prop->Value.bin.cb, + (LPSTR) props[j]); + + propsType[j] = 's'; // 16 bits string + } + + } + else + { + propsLength[j] = prop->Value.bin.cb; + if((props[j] = malloc(propsLength[j])) + != NULL) + { + memcpy(props[j], + prop->Value.bin.lpb, + prop->Value.bin.cb); + + propsType[j] = 'b'; + } + } + break; + } - propsType[j] = 's'; // 16 bits string - } - break; + case PT_SYSTIME: + { + propsLength[j] = sizeof(SYSTEMTIME); + if((props[j] = malloc(propsLength[j])) + != NULL) + { + FILETIME lpLocalFileTime; + SYSTEMTIME systime; + FileTimeToLocalFileTime( + &prop->Value.ft, + &lpLocalFileTime); + FileTimeToSystemTime( + &prop->Value.ft, + &systime); + memcpy(props[j],&systime, propsLength[j]); + propsType[j] = 't'; + } + break; } } } @@ -1486,7 +1433,8 @@ int MsOutlookAddrBookContactQuery_IMAPIProp_1SetPropString propTag = MsOutlookAddrBookContactQuery_getPropTag( (LPMAPIPROP) mapiProp, propIds[i], - PT_UNSPECIFIED); + PT_UNSPECIFIED, + MsOutlookAddrBookContactQuery_UUID_Address); *(propTagArray->aulPropTag + i) = propTag; } hResult = ((LPMAPIPROP) mapiProp)->GetProps( @@ -1569,7 +1517,8 @@ int MsOutlookAddrBookContactQuery_IMAPIProp_1SetPropString updateValue.ulPropTag = MsOutlookAddrBookContactQuery_getPropTag( (LPMAPIPROP) mapiProp, propId, - PT_UNICODE); + PT_UNICODE, + MsOutlookAddrBookContactQuery_UUID_Address); updateValue.Value.lpszW = wCharValue; hResult = ((LPMAPIPROP) mapiProp)->SetProps( @@ -1809,7 +1758,7 @@ MsOutlookAddrBookContactQuery_readAttachment { LPSPropValue condValue; - hResult = MsOutlookAddrBookContactQuery_HrGetOneProp( + hResult = MsOutlookUtils_HrGetOneProp( (LPMAPIPROP) attach, cond, &condValue); diff --git a/src/native/addrbook/msoutlook/MsOutlookAddrBookContactQuery.h b/src/native/addrbook/msoutlook/MsOutlookAddrBookContactQuery.h index 99fd749..a535543 100644 --- a/src/native/addrbook/msoutlook/MsOutlookAddrBookContactQuery.h +++ b/src/native/addrbook/msoutlook/MsOutlookAddrBookContactQuery.h @@ -8,6 +8,32 @@ #define _NET_JAVA_SIP_COMMUNICATOR_PLUGIN_ADDRBOOK_MSOUTLOOK_MSOUTLOOKADDRBOOKCONTACTQUERY_H_ #include <mapidefs.h> +#include <jni.h> + +typedef + jboolean (*MsOutlookAddrBookContactQuery_ForeachRowInTableCallback) + (LPUNKNOWN iUnknown, + ULONG entryIDByteCount, LPENTRYID entryID, ULONG objType, + const char * query, + void * callbackMethod, + void * callbackClient, + long callbackAddress); + +jboolean MsOutlookAddrBookContactQuery_foreachRowInTable + (LPMAPITABLE mapiTable, + MsOutlookAddrBookContactQuery_ForeachRowInTableCallback rowCallback, + LPUNKNOWN iUnknown, + const char * query, + void * callbackMethod, + void * callbackClient, + long callbackAddress); + +jboolean MsOutlookAddrBookContactQuery_foreachMailUser + (ULONG objType, LPUNKNOWN iUnknown, + const char * query, + void * callbackMethod, + void * callbackClient, + long callbackAddress); int MsOutlookAddrBookContactQuery_IMAPIProp_1DeleteProp (long propId, const char * nativeEntryId); @@ -19,7 +45,8 @@ long MsOutlookAddrBookContactQuery_IMAPIProp_1GetProps( long flags, void ** props, unsigned long* propsLength, - char * propsType); + char * propsType, + UUID UUID_Address); int MsOutlookAddrBookContactQuery_IMAPIProp_1SetPropString (long propId, const wchar_t* nativeValue, const char* nativeEntryId); @@ -40,4 +67,6 @@ char* MsOutlookAddrBookContactQuery_getStringUnicodeProp int MsOutlookAddrBookContactQuery_compareEntryIds (LPSTR id1, LPSTR id2); +#define MsOutlookAddrBookContactQuery_UUID_Address (UUID){0x00062004, 0x0000, 0x0000, {0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}} + #endif 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); +} diff --git a/src/native/addrbook/msoutlook/MsOutlookCalendar.h b/src/native/addrbook/msoutlook/MsOutlookCalendar.h new file mode 100644 index 0000000..e0e5322 --- /dev/null +++ b/src/native/addrbook/msoutlook/MsOutlookCalendar.h @@ -0,0 +1,21 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +#ifndef _NET_JAVA_SIP_COMMUNICATOR_PLUGIN_ADDRBOOK_MSOUTLOOK_MSOUTLOOKCALENDAR_H_ +#define _NET_JAVA_SIP_COMMUNICATOR_PLUGIN_ADDRBOOK_MSOUTLOOK_MSOUTLOOKCALENDAR_H_ + +void MsOutlookCalendar_getAllCalendarItems( + void * callbackMethod, + void * callbackClient, + long callbackAddress); +jboolean MsOutlookCalendar_foreachCalendarItemCallback( + LPSTR iUnknown, + long callbackAddress); + +void MsOutlookCalendar_setCallbackObject(void *callback); + +#define MsOutlookCalendar_UUID_Address (UUID){0x00062002, 0x0000, 0x0000, {0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}} +#endif diff --git a/src/native/addrbook/msoutlook/MsOutlookUtils.cxx b/src/native/addrbook/msoutlook/MsOutlookUtils.cxx new file mode 100644 index 0000000..86e501a --- /dev/null +++ b/src/native/addrbook/msoutlook/MsOutlookUtils.cxx @@ -0,0 +1,404 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ + +#include "MsOutlookUtils.h" +#include "MsOutlookAddrBookContactSourceService.h" + +#include "MAPIBitness.h" +#include "MAPISession.h" + +#include "com/ComClient.h" +#include "com/MsOutlookAddrBookServer.h" +#include "MsOutlookMAPIHResultException.h" +#include "StringUtils.h" + +#include <initguid.h> +#include <jni.h> +#include <Mapidefs.h> +#include <Mapix.h> +#include <windows.h> + + + +HRESULT +MsOutlookUtils_getFolderEntryIDByType + (LPMDB msgStore, + ULONG folderEntryIDByteCount, LPENTRYID folderEntryID, + ULONG *contactsFolderEntryIDByteCount, LPENTRYID *contactsFolderEntryID, + ULONG flags, ULONG type) +{ + HRESULT hResult; + ULONG objType; + LPUNKNOWN folder; + + hResult = msgStore->OpenEntry( + folderEntryIDByteCount, + folderEntryID, + NULL, + flags, + &objType, + &folder); + + if (HR_SUCCEEDED(hResult)) + { + LPSPropValue prop; + + hResult + = MsOutlookUtils_HrGetOneProp( + (LPMAPIPROP) folder, + type, + &prop); + if (HR_SUCCEEDED(hResult)) + { + LPSBinary bin = &(prop->Value.bin); + if (S_OK + == MAPIAllocateBuffer( + bin->cb, + (void **) contactsFolderEntryID)) + { + hResult = S_OK; + *contactsFolderEntryIDByteCount = bin->cb; + CopyMemory(*contactsFolderEntryID, bin->lpb, bin->cb); + } + else + hResult = MAPI_E_NOT_ENOUGH_MEMORY; + MAPIFreeBuffer(prop); + } + folder->Release(); + } + return hResult; +} + + + +/** + * Get one property for a given contact. + * + * @param mapiProp A pointer to the contact. + * @param propTag The tag of the property to get. + * @param prop The memory location to store the property value. + * + * @return S_OK if everything work fine. Any other value is a failure. + */ +HRESULT +MsOutlookUtils_HrGetOneProp( + LPMAPIPROP mapiProp, + ULONG propTag, + LPSPropValue *prop) +{ + SPropTagArray propTagArray; + HRESULT hResult; + ULONG valueCount; + LPSPropValue values; + + propTagArray.cValues = 1; + propTagArray.aulPropTag[0] = propTag; + + hResult = mapiProp->GetProps(&propTagArray, 0, &valueCount, &values); + if (HR_SUCCEEDED(hResult)) + { + ULONG i; + jboolean propHasBeenAssignedTo = JNI_FALSE; + + for (i = 0; i < valueCount; i++) + { + LPSPropValue value = values; + + values++; + if (value->ulPropTag == propTag) + { + *prop = value; + propHasBeenAssignedTo = JNI_TRUE; + } + else + MAPIFreeBuffer(value); + } + if (!propHasBeenAssignedTo) + hResult = MAPI_E_NOT_FOUND; + MAPIFreeBuffer(values); + } + return hResult; +} + + +jobjectArray +MsOutlookUtils_IMAPIProp_GetProps( + JNIEnv *jniEnv, + jclass clazz, + jstring entryId, + jlongArray propIds, + jlong flags, + UUID UUID_Address) +{ + HRESULT hr = E_FAIL; + jobjectArray javaProps = NULL; + const char *nativeEntryId = jniEnv->GetStringUTFChars(entryId, NULL); + jsize propIdCount = jniEnv->GetArrayLength(propIds); + long nativePropIds[propIdCount]; + + for(int i = 0; i < propIdCount; ++i) + { + jlong propId; + + jniEnv->GetLongArrayRegion(propIds, i, 1, &propId); + nativePropIds[i] = propId; + } + + if(jniEnv->ExceptionCheck()) + { + jniEnv->ReleaseStringUTFChars(entryId, nativeEntryId); + return NULL; + } + + void ** props = NULL; + unsigned long* propsLength = NULL; + // b = byteArray, l = long, s = 8 bits string, u = 16 bits string. + char * propsType = NULL; + + if((props = (void**) malloc(propIdCount * sizeof(void*))) != NULL) + { + memset(props, 0, propIdCount * sizeof(void*)); + if((propsLength = (unsigned long*) malloc( + propIdCount * sizeof(unsigned long))) != NULL) + { + if((propsType = (char*) malloc(propIdCount * sizeof(char))) + != NULL) + { + IMsOutlookAddrBookServer * iServer = ComClient_getIServer(); + if(iServer) + { + LPWSTR unicodeEntryId + = StringUtils::MultiByteToWideChar(nativeEntryId); + BSTR comEntryId = SysAllocString(unicodeEntryId); + + LPSAFEARRAY comPropIds + = SafeArrayCreateVector(VT_I4, 0, propIdCount); + SafeArrayLock(comPropIds); + comPropIds->pvData = nativePropIds; + SafeArrayUnlock(comPropIds); + + LPSAFEARRAY comProps; + LPSAFEARRAY comPropsLength; + LPSAFEARRAY comPropsType; + + hr = iServer->IMAPIProp_GetProps( + comEntryId, + propIdCount, + comPropIds, + flags, + UUID_Address, + &comProps, + &comPropsLength, + &comPropsType); + + if(HR_SUCCEEDED(hr)) + { + SafeArrayLock(comPropsType); + memcpy( + propsType, + comPropsType->pvData, + propIdCount * sizeof(char)); + SafeArrayUnlock(comPropsType); + + SafeArrayLock(comPropsLength); + memcpy( + propsLength, + comPropsLength->pvData, + propIdCount * sizeof(unsigned long)); + SafeArrayUnlock(comPropsLength); + + SafeArrayLock(comProps); + byte * data = (byte*) comProps->pvData; + for(int j = 0; j < propIdCount; ++j) + { + if((props[j] = malloc(propsLength[j])) != NULL) + { + memcpy(props[j], data, propsLength[j]); + data += propsLength[j]; + } + } + SafeArrayUnlock(comProps); + + // Decode properties to java + jclass objectClass + = jniEnv->FindClass("java/lang/Object"); + if (objectClass) + { + javaProps = jniEnv->NewObjectArray( + propIdCount, + objectClass, + NULL); + for(int j = 0; j < propIdCount; ++j) + { + // byte array + if(propsType[j] == 'b' && props[j] != NULL) + { + jbyteArray value = jniEnv->NewByteArray( + (jsize) propsLength[j]); + if(value) + { + jbyte *bytes + = jniEnv->GetByteArrayElements( + value, NULL); + + if (bytes) + { + memcpy( + bytes, + props[j], + propsLength[j]); + jniEnv->ReleaseByteArrayElements( + value, + bytes, + 0); + jniEnv->SetObjectArrayElement( + javaProps, + j, + value); + } + } + } + // long + else if(propsType[j] == 'l' && props[j] != NULL) + { + jclass longClass + = jniEnv->FindClass("java/lang/Long"); + if (longClass) + { + jmethodID longMethodID + = jniEnv->GetMethodID( + longClass, + "<init>", + "(J)V"); + + if (longMethodID) + { + jlong l = (jlong)(*((long*)props[j])); + memcpy(&l, props[j], propsLength[j]); + jobject value = jniEnv->NewObject( + longClass, + longMethodID, + l); + + if (value) + { + jniEnv->SetObjectArrayElement( + javaProps, + j, + value); + } + } + } + } + // 8 bits string + else if(propsType[j] == 's' && props[j] != NULL) + { + jstring value = jniEnv->NewStringUTF( + (const char*) props[j]); + if (value) + { + jniEnv->SetObjectArrayElement( + javaProps, + j, + value); + } + } + // 16 bits string + else if(propsType[j] == 'u' && props[j] != NULL) + { + jstring value + = jniEnv->NewString( + (const jchar *) props[j], + wcslen((const wchar_t *) props[j])); + if (value) + { + jniEnv->SetObjectArrayElement( + javaProps, + j, + value); + } + } + else if(propsType[j] == 'B' && props[j] != NULL) + { + jclass booleanClass + = jniEnv->FindClass("java/lang/Boolean"); + jmethodID boolMethodID + = jniEnv->GetStaticMethodID( + booleanClass, + "valueOf", + "(Z)Ljava/lang/Boolean;"); + bool value = false; + if((bool)props[j]) + value = true; + jobject jValue + = jniEnv->CallStaticObjectMethod( + booleanClass, + boolMethodID, + value); + jniEnv->SetObjectArrayElement( + javaProps, + j, + jValue); + } + else if(propsType[j] == 't' && props[j] != NULL) + { char dateTime[20]; + LPSYSTEMTIME sysTime + = (LPSYSTEMTIME) props[j]; + sprintf(dateTime, + "%u-%02u-%02u %02u:%02u:%02u", + sysTime->wYear, sysTime->wMonth, + sysTime->wDay, sysTime->wHour, + sysTime->wMinute, sysTime->wSecond); + jstring value = jniEnv->NewStringUTF( + (const char*) dateTime); + if (value) + { + jniEnv->SetObjectArrayElement( + javaProps, + j, + value); + } + } + + if(jniEnv->ExceptionCheck()) + javaProps = NULL; + } + } + } + else + { + MsOutlookMAPIHResultException_throwNew( + jniEnv, + hr, + __FILE__, __LINE__); + } + + SafeArrayDestroy(comPropsType); + SafeArrayDestroy(comPropsLength); + SafeArrayDestroy(comProps); + SafeArrayDestroy(comPropIds); + SysFreeString(comEntryId); + free(unicodeEntryId); + } + + + for(int j = 0; j < propIdCount; ++j) + { + if(props[j] != NULL) + free(props[j]); + } + free(propsType); + } + free(propsLength); + } + free(props); + } + + jniEnv->ReleaseStringUTFChars(entryId, nativeEntryId); + + return javaProps; +} diff --git a/src/native/addrbook/msoutlook/MsOutlookUtils.h b/src/native/addrbook/msoutlook/MsOutlookUtils.h new file mode 100644 index 0000000..023d4d1 --- /dev/null +++ b/src/native/addrbook/msoutlook/MsOutlookUtils.h @@ -0,0 +1,34 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +#ifndef _NET_JAVA_SIP_COMMUNICATOR_PLUGIN_ADDRBOOK_MSOUTLOOK_MSOUTLOOKUTILS_H_ +#define _NET_JAVA_SIP_COMMUNICATOR_PLUGIN_ADDRBOOK_MSOUTLOOK_MSOUTLOOKUTILS_H_ + +#include <mapidefs.h> +#include <jni.h> + +HRESULT +MsOutlookUtils_getFolderEntryIDByType + (LPMDB msgStore, + ULONG folderEntryIDByteCount, LPENTRYID folderEntryID, + ULONG *contactsFolderEntryIDByteCount, LPENTRYID *contactsFolderEntryID, + ULONG flags, ULONG type); + +HRESULT +MsOutlookUtils_HrGetOneProp( + LPMAPIPROP mapiProp, + ULONG propTag, + LPSPropValue *prop); + +jobjectArray +MsOutlookUtils_IMAPIProp_GetProps( + JNIEnv *jniEnv, + jclass clazz, + jstring entryId, + jlongArray propIds, + jlong flags, + UUID UUID_Address); +#endif diff --git a/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookClient.h b/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookClient.h index 4337015..9aeedce 100644 --- a/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookClient.h +++ b/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookClient.h @@ -3,11 +3,11 @@ /* this ALWAYS GENERATED file contains the definitions for the interfaces */ - /* File created by MIDL compiler version 8.00.0603 */ -/* at Mon Mar 24 09:03:06 2014 + /* File created by MIDL compiler version 7.00.0555 */ +/* at Tue Apr 01 12:24:18 2014 */ /* Compiler settings for IMsOutlookAddrBookClient.idl: - Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 8.00.0603 + Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 7.00.0555 protocol : dce , ms_ext, c_ext, robust error checks: allocation ref bounds_check enum stub_data VC __declspec() decoration level: @@ -48,14 +48,12 @@ #ifndef __IMsOutlookAddrBookClient_FWD_DEFINED__ #define __IMsOutlookAddrBookClient_FWD_DEFINED__ typedef interface IMsOutlookAddrBookClient IMsOutlookAddrBookClient; - #endif /* __IMsOutlookAddrBookClient_FWD_DEFINED__ */ #ifndef __IMsOutlookAddrBookClient_FWD_DEFINED__ #define __IMsOutlookAddrBookClient_FWD_DEFINED__ typedef interface IMsOutlookAddrBookClient IMsOutlookAddrBookClient; - #endif /* __IMsOutlookAddrBookClient_FWD_DEFINED__ */ @@ -87,6 +85,10 @@ EXTERN_C const IID IID_IMsOutlookAddrBookClient; /* [in] */ BSTR id, /* [in] */ long callback) = 0; + virtual HRESULT STDMETHODCALLTYPE foreachCalendarItemCallback( + /* [in] */ BSTR id, + /* [in] */ long callback) = 0; + virtual HRESULT STDMETHODCALLTYPE deleted( /* [in] */ BSTR id) = 0; @@ -98,7 +100,6 @@ EXTERN_C const IID IID_IMsOutlookAddrBookClient; }; - #else /* C style interface */ typedef struct IMsOutlookAddrBookClientVtbl @@ -109,7 +110,7 @@ EXTERN_C const IID IID_IMsOutlookAddrBookClient; IMsOutlookAddrBookClient * This, /* [in] */ REFIID riid, /* [annotation][iid_is][out] */ - _COM_Outptr_ void **ppvObject); + __RPC__deref_out void **ppvObject); ULONG ( STDMETHODCALLTYPE *AddRef )( IMsOutlookAddrBookClient * This); @@ -122,6 +123,11 @@ EXTERN_C const IID IID_IMsOutlookAddrBookClient; /* [in] */ BSTR id, /* [in] */ long callback); + HRESULT ( STDMETHODCALLTYPE *foreachCalendarItemCallback )( + IMsOutlookAddrBookClient * This, + /* [in] */ BSTR id, + /* [in] */ long callback); + HRESULT ( STDMETHODCALLTYPE *deleted )( IMsOutlookAddrBookClient * This, /* [in] */ BSTR id); @@ -160,6 +166,9 @@ EXTERN_C const IID IID_IMsOutlookAddrBookClient; #define IMsOutlookAddrBookClient_foreachMailUserCallback(This,id,callback) \ ( (This)->lpVtbl -> foreachMailUserCallback(This,id,callback) ) +#define IMsOutlookAddrBookClient_foreachCalendarItemCallback(This,id,callback) \ + ( (This)->lpVtbl -> foreachCalendarItemCallback(This,id,callback) ) + #define IMsOutlookAddrBookClient_deleted(This,id) \ ( (This)->lpVtbl -> deleted(This,id) ) diff --git a/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookClient.idl b/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookClient.idl index 6e1fad5..30f457a 100644 --- a/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookClient.idl +++ b/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookClient.idl @@ -12,6 +12,9 @@ interface IMsOutlookAddrBookClient : IUnknown HRESULT foreachMailUserCallback( [in] BSTR id, [in] long callback); + HRESULT foreachCalendarItemCallback( + [in] BSTR id, + [in] long callback); HRESULT deleted( [in] BSTR id); diff --git a/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookClient.tlb b/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookClient.tlb Binary files differindex 168d9ad..6873acd 100644 --- a/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookClient.tlb +++ b/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookClient.tlb diff --git a/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookServer.h b/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookServer.h index aee8983..a263d2a 100644 --- a/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookServer.h +++ b/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookServer.h @@ -3,11 +3,11 @@ /* this ALWAYS GENERATED file contains the definitions for the interfaces */ - /* File created by MIDL compiler version 8.00.0603 */ -/* at Mon Mar 24 09:03:14 2014 + /* File created by MIDL compiler version 7.00.0555 */ +/* at Tue Apr 01 12:24:24 2014 */ /* Compiler settings for IMsOutlookAddrBookServer.idl: - Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 8.00.0603 + Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 7.00.0555 protocol : dce , ms_ext, c_ext, robust error checks: allocation ref bounds_check enum stub_data VC __declspec() decoration level: @@ -48,14 +48,12 @@ #ifndef __IMsOutlookAddrBookServer_FWD_DEFINED__ #define __IMsOutlookAddrBookServer_FWD_DEFINED__ typedef interface IMsOutlookAddrBookServer IMsOutlookAddrBookServer; - #endif /* __IMsOutlookAddrBookServer_FWD_DEFINED__ */ #ifndef __IMsOutlookAddrBookServer_FWD_DEFINED__ #define __IMsOutlookAddrBookServer_FWD_DEFINED__ typedef interface IMsOutlookAddrBookServer IMsOutlookAddrBookServer; - #endif /* __IMsOutlookAddrBookServer_FWD_DEFINED__ */ @@ -87,11 +85,15 @@ EXTERN_C const IID IID_IMsOutlookAddrBookServer; /* [in] */ BSTR query, /* [in] */ long callback) = 0; + virtual HRESULT STDMETHODCALLTYPE getAllCalendarItems( + /* [in] */ long callback) = 0; + virtual HRESULT STDMETHODCALLTYPE IMAPIProp_GetProps( /* [in] */ BSTR entryId, /* [in] */ int nbPropIds, /* [in] */ SAFEARRAY * propIds, /* [in] */ long flags, + /* [in] */ GUID UUID_Address, /* [out] */ SAFEARRAY * *props, /* [out] */ SAFEARRAY * *propsLength, /* [out] */ SAFEARRAY * *propsType) = 0; @@ -118,7 +120,6 @@ EXTERN_C const IID IID_IMsOutlookAddrBookServer; }; - #else /* C style interface */ typedef struct IMsOutlookAddrBookServerVtbl @@ -129,7 +130,7 @@ EXTERN_C const IID IID_IMsOutlookAddrBookServer; IMsOutlookAddrBookServer * This, /* [in] */ REFIID riid, /* [annotation][iid_is][out] */ - _COM_Outptr_ void **ppvObject); + __RPC__deref_out void **ppvObject); ULONG ( STDMETHODCALLTYPE *AddRef )( IMsOutlookAddrBookServer * This); @@ -142,12 +143,17 @@ EXTERN_C const IID IID_IMsOutlookAddrBookServer; /* [in] */ BSTR query, /* [in] */ long callback); + HRESULT ( STDMETHODCALLTYPE *getAllCalendarItems )( + IMsOutlookAddrBookServer * This, + /* [in] */ long callback); + HRESULT ( STDMETHODCALLTYPE *IMAPIProp_GetProps )( IMsOutlookAddrBookServer * This, /* [in] */ BSTR entryId, /* [in] */ int nbPropIds, /* [in] */ SAFEARRAY * propIds, /* [in] */ long flags, + /* [in] */ GUID UUID_Address, /* [out] */ SAFEARRAY * *props, /* [out] */ SAFEARRAY * *propsLength, /* [out] */ SAFEARRAY * *propsType); @@ -203,8 +209,11 @@ EXTERN_C const IID IID_IMsOutlookAddrBookServer; #define IMsOutlookAddrBookServer_foreachMailUser(This,query,callback) \ ( (This)->lpVtbl -> foreachMailUser(This,query,callback) ) -#define IMsOutlookAddrBookServer_IMAPIProp_GetProps(This,entryId,nbPropIds,propIds,flags,props,propsLength,propsType) \ - ( (This)->lpVtbl -> IMAPIProp_GetProps(This,entryId,nbPropIds,propIds,flags,props,propsLength,propsType) ) +#define IMsOutlookAddrBookServer_getAllCalendarItems(This,callback) \ + ( (This)->lpVtbl -> getAllCalendarItems(This,callback) ) + +#define IMsOutlookAddrBookServer_IMAPIProp_GetProps(This,entryId,nbPropIds,propIds,flags,UUID_Address,props,propsLength,propsType) \ + ( (This)->lpVtbl -> IMAPIProp_GetProps(This,entryId,nbPropIds,propIds,flags,UUID_Address,props,propsLength,propsType) ) #define IMsOutlookAddrBookServer_createContact(This,id) \ ( (This)->lpVtbl -> createContact(This,id) ) diff --git a/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookServer.idl b/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookServer.idl index 5fbaffa..638435e 100644 --- a/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookServer.idl +++ b/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookServer.idl @@ -12,12 +12,16 @@ interface IMsOutlookAddrBookServer : IUnknown HRESULT foreachMailUser( [in] BSTR query, [in] long callback); + + HRESULT getAllCalendarItems( + [in] long callback); HRESULT IMAPIProp_GetProps( [in] BSTR entryId, [in] int nbPropIds, [in] SAFEARRAY(long) propIds, [in] long flags, + [in] GUID UUID_Address, [out] SAFEARRAY(byte) * props, [out] SAFEARRAY(unsigned long) * propsLength, [out] SAFEARRAY(byte) * propsType); diff --git a/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookServer.tlb b/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookServer.tlb Binary files differindex 9492af3..267171f 100644 --- a/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookServer.tlb +++ b/src/native/addrbook/msoutlook/com/IMsOutlookAddrBookServer.tlb diff --git a/src/native/addrbook/msoutlook/com/MsOutlookAddrBookClient.cxx b/src/native/addrbook/msoutlook/com/MsOutlookAddrBookClient.cxx index b21a636..c0564e2 100644 --- a/src/native/addrbook/msoutlook/com/MsOutlookAddrBookClient.cxx +++ b/src/native/addrbook/msoutlook/com/MsOutlookAddrBookClient.cxx @@ -10,6 +10,7 @@ #include <wchar.h> #include "../MAPINotification.h" +#include "../MsOutlookCalendar.h" #include "../net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.h" #include "../StringUtils.h" @@ -117,6 +118,15 @@ HRESULT STDMETHODCALLTYPE MsOutlookAddrBookClient::foreachMailUserCallback( return E_ABORT; } +HRESULT STDMETHODCALLTYPE MsOutlookAddrBookClient::foreachCalendarItemCallback( + BSTR id, long callback) +{ + char * charId = StringUtils::WideCharToMultiByte(id); + MsOutlookCalendar_foreachCalendarItemCallback(charId, callback); + + return S_OK; +} + /** * Callback called each time the COM server forward a contact deleted notify * event from MAPI. diff --git a/src/native/addrbook/msoutlook/com/MsOutlookAddrBookClient.h b/src/native/addrbook/msoutlook/com/MsOutlookAddrBookClient.h index 159e0f8..06e1847 100644 --- a/src/native/addrbook/msoutlook/com/MsOutlookAddrBookClient.h +++ b/src/native/addrbook/msoutlook/com/MsOutlookAddrBookClient.h @@ -37,6 +37,8 @@ class MsOutlookAddrBookClient: // IMsOutlookAddrBookClient HRESULT STDMETHODCALLTYPE foreachMailUserCallback( BSTR id, long callback); + HRESULT STDMETHODCALLTYPE foreachCalendarItemCallback( + BSTR id, long callback); HRESULT STDMETHODCALLTYPE deleted(BSTR id); HRESULT STDMETHODCALLTYPE inserted(BSTR id); diff --git a/src/native/addrbook/msoutlook/com/MsOutlookAddrBookServer.cxx b/src/native/addrbook/msoutlook/com/MsOutlookAddrBookServer.cxx index f80b60b..6a7300e 100644 --- a/src/native/addrbook/msoutlook/com/MsOutlookAddrBookServer.cxx +++ b/src/native/addrbook/msoutlook/com/MsOutlookAddrBookServer.cxx @@ -14,6 +14,7 @@ #include "../StringUtils.h" #include "../MsOutlookAddrBookContactQuery.h" +#include "../MsOutlookCalendar.h" /** * Instanciates a new MsOutlookAddrBookServer. @@ -135,6 +136,68 @@ HRESULT STDMETHODCALLTYPE MsOutlookAddrBookServer::foreachMailUser( } /** + * Starts a search for calendar items using MAPI.A + * + * @param callbackAddress the address for the callback method + * @return S_OK. + */ +HRESULT STDMETHODCALLTYPE MsOutlookAddrBookServer::getAllCalendarItems( + long callbackAddress) +{ + HRESULT hr = E_FAIL; + IMsOutlookAddrBookClient * msOutlookAddrBookClient = NULL; + if((hr = CoCreateInstance( + CLSID_MsOutlookAddrBookClient, + NULL, + CLSCTX_LOCAL_SERVER, + IID_IMsOutlookAddrBookClient, + (void**) &msOutlookAddrBookClient)) == S_OK) + { + MsOutlookCalendar_getAllCalendarItems( + (void *) MsOutlookAddrBookServer::foreachCalendarItemCallback, + (void *) msOutlookAddrBookClient, + callbackAddress); + msOutlookAddrBookClient->Release(); + } + + return S_OK; +} + +/** + * Calls back the java side to add a calendar item. + * + * @param iUnknown The string representation of the entry id of the calendar + * item. + * + * @return True everything works fine and that we must continue to list the + * other contacts. False otherwise. + */ +boolean MsOutlookAddrBookServer::foreachCalendarItemCallback( + LPSTR iUnknown, + void * callbackClient, + long callbackAddress) +{ + HRESULT hr = E_FAIL; + + if(callbackClient) + { + LPWSTR iUnknownW = StringUtils::MultiByteToWideChar(iUnknown); + BSTR res = SysAllocString(iUnknownW); + + hr = ((IMsOutlookAddrBookClient *)callbackClient) + ->foreachCalendarItemCallback(res, callbackAddress); + + SysFreeString(res); + free(iUnknownW); + } + + + return (hr == S_OK); +} + + + +/** * Calls back the java side to list a contact. * * @param iUnknown The string representation of the entry id of the contact. @@ -186,6 +249,7 @@ HRESULT STDMETHODCALLTYPE MsOutlookAddrBookServer::IMAPIProp_GetProps( int nbPropIds, SAFEARRAY * propIds, long flags, + UUID UUID_Address, SAFEARRAY ** props, SAFEARRAY ** propsLength, SAFEARRAY ** propsType) @@ -218,7 +282,8 @@ HRESULT STDMETHODCALLTYPE MsOutlookAddrBookServer::IMAPIProp_GetProps( flags, localProps, localPropsLength, - localPropsType); + localPropsType, + UUID_Address); free(id); diff --git a/src/native/addrbook/msoutlook/com/MsOutlookAddrBookServer.h b/src/native/addrbook/msoutlook/com/MsOutlookAddrBookServer.h index 190217a..261c46f 100644 --- a/src/native/addrbook/msoutlook/com/MsOutlookAddrBookServer.h +++ b/src/native/addrbook/msoutlook/com/MsOutlookAddrBookServer.h @@ -37,11 +37,14 @@ class MsOutlookAddrBookServer: // IMsOutlookAddrBookServer HRESULT STDMETHODCALLTYPE foreachMailUser(BSTR query, long callback); + HRESULT STDMETHODCALLTYPE getAllCalendarItems(long callback); + HRESULT STDMETHODCALLTYPE IMAPIProp_GetProps( BSTR entryId, int nbPropIds, SAFEARRAY * propIds, long flags, + UUID UUID_Address, SAFEARRAY ** props, SAFEARRAY ** propsLength, SAFEARRAY ** propsType); @@ -76,6 +79,10 @@ class MsOutlookAddrBookServer: LPSTR iUnknown, void * callbackClient, long callbackAddress); + static boolean foreachCalendarItemCallback( + LPSTR iUnknown, + void * callbackClient, + long callbackAddress); }; #endif diff --git a/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.cxx b/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.cxx index 9e34c65..0987a62 100644 --- a/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.cxx +++ b/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.cxx @@ -8,6 +8,7 @@ #include "net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.h" #include "MsOutlookAddrBookContactQuery.h" +#include "MsOutlookUtils.h" #include "com/ComClient.h" #include "com/MsOutlookAddrBookServer.h" #include "MAPIBitness.h" @@ -193,231 +194,8 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac jlongArray propIds, jlong flags) { - HRESULT hr = E_FAIL; - jobjectArray javaProps = NULL; - const char *nativeEntryId = jniEnv->GetStringUTFChars(entryId, NULL); - jsize propIdCount = jniEnv->GetArrayLength(propIds); - long nativePropIds[propIdCount]; - - for(int i = 0; i < propIdCount; ++i) - { - jlong propId; - - jniEnv->GetLongArrayRegion(propIds, i, 1, &propId); - nativePropIds[i] = propId; - } - - if(jniEnv->ExceptionCheck()) - { - jniEnv->ReleaseStringUTFChars(entryId, nativeEntryId); - return NULL; - } - - void ** props = NULL; - unsigned long* propsLength = NULL; - // b = byteArray, l = long, s = 8 bits string, u = 16 bits string. - char * propsType = NULL; - - if((props = (void**) malloc(propIdCount * sizeof(void*))) != NULL) - { - memset(props, 0, propIdCount * sizeof(void*)); - if((propsLength = (unsigned long*) malloc( - propIdCount * sizeof(unsigned long))) != NULL) - { - if((propsType = (char*) malloc(propIdCount * sizeof(char))) - != NULL) - { - IMsOutlookAddrBookServer * iServer = ComClient_getIServer(); - if(iServer) - { - LPWSTR unicodeEntryId - = StringUtils::MultiByteToWideChar(nativeEntryId); - BSTR comEntryId = SysAllocString(unicodeEntryId); - - LPSAFEARRAY comPropIds - = SafeArrayCreateVector(VT_I4, 0, propIdCount); - SafeArrayLock(comPropIds); - comPropIds->pvData = nativePropIds; - SafeArrayUnlock(comPropIds); - - LPSAFEARRAY comProps; - LPSAFEARRAY comPropsLength; - LPSAFEARRAY comPropsType; - - hr = iServer->IMAPIProp_GetProps( - comEntryId, - propIdCount, - comPropIds, - flags, - &comProps, - &comPropsLength, - &comPropsType); - - if(HR_SUCCEEDED(hr)) - { - SafeArrayLock(comPropsType); - memcpy( - propsType, - comPropsType->pvData, - propIdCount * sizeof(char)); - SafeArrayUnlock(comPropsType); - - SafeArrayLock(comPropsLength); - memcpy( - propsLength, - comPropsLength->pvData, - propIdCount * sizeof(unsigned long)); - SafeArrayUnlock(comPropsLength); - - SafeArrayLock(comProps); - byte * data = (byte*) comProps->pvData; - for(int j = 0; j < propIdCount; ++j) - { - if((props[j] = malloc(propsLength[j])) != NULL) - { - memcpy(props[j], data, propsLength[j]); - data += propsLength[j]; - } - } - SafeArrayUnlock(comProps); - - // Decode properties to java - jclass objectClass - = jniEnv->FindClass("java/lang/Object"); - if (objectClass) - { - javaProps = jniEnv->NewObjectArray( - propIdCount, - objectClass, - NULL); - for(int j = 0; j < propIdCount; ++j) - { - // byte array - if(propsType[j] == 'b' && props[j] != NULL) - { - jbyteArray value = jniEnv->NewByteArray( - (jsize) propsLength[j]); - if(value) - { - jbyte *bytes - = jniEnv->GetByteArrayElements( - value, NULL); - - if (bytes) - { - memcpy( - bytes, - props[j], - propsLength[j]); - jniEnv->ReleaseByteArrayElements( - value, - bytes, - 0); - jniEnv->SetObjectArrayElement( - javaProps, - j, - value); - } - } - } - // long - else if(propsType[j] == 'l' && props[j] != NULL) - { - jclass longClass - = jniEnv->FindClass("java/lang/Long"); - if (longClass) - { - jmethodID longMethodID - = jniEnv->GetMethodID( - longClass, - "<init>", - "(J)V"); - - if (longMethodID) - { - jlong l; - memcpy(&l, props[j], propsLength[j]); - jobject value = jniEnv->NewObject( - longClass, - longMethodID, - l); - - if (value) - { - jniEnv->SetObjectArrayElement( - javaProps, - j, - value); - } - } - } - } - // 8 bits string - else if(propsType[j] == 's' && props[j] != NULL) - { - jstring value = jniEnv->NewStringUTF( - (const char*) props[j]); - if (value) - { - jniEnv->SetObjectArrayElement( - javaProps, - j, - value); - } - } - // 16 bits string - else if(propsType[j] == 'u' && props[j] != NULL) - { - jstring value - = jniEnv->NewString( - (const jchar *) props[j], - wcslen((const wchar_t *) props[j])); - if (value) - { - jniEnv->SetObjectArrayElement( - javaProps, - j, - value); - } - } - - if(jniEnv->ExceptionCheck()) - javaProps = NULL; - } - } - } - else - { - MsOutlookMAPIHResultException_throwNew( - jniEnv, - hr, - __FILE__, __LINE__); - } - - SafeArrayDestroy(comPropsType); - SafeArrayDestroy(comPropsLength); - SafeArrayDestroy(comProps); - SafeArrayDestroy(comPropIds); - SysFreeString(comEntryId); - free(unicodeEntryId); - } - - - for(int j = 0; j < propIdCount; ++j) - { - if(props[j] != NULL) - free(props[j]); - } - free(propsType); - } - free(propsLength); - } - free(props); - } - - jniEnv->ReleaseStringUTFChars(entryId, nativeEntryId); - - return javaProps; + return MsOutlookUtils_IMAPIProp_GetProps(jniEnv, clazz, entryId, propIds, + flags, MsOutlookAddrBookContactQuery_UUID_Address); } diff --git a/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_calendar_CalendarServiceImpl.cxx b/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_calendar_CalendarServiceImpl.cxx new file mode 100644 index 0000000..449775c --- /dev/null +++ b/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_calendar_CalendarServiceImpl.cxx @@ -0,0 +1,44 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ + +#include "net_java_sip_communicator_plugin_addrbook_msoutlook_calendar_CalendarServiceImpl.h" +#include "MsOutlookUtils.h" +#include "MsOutlookCalendar.h" +#include "MAPINotification.h" +#include "com/ComClient.h" +#include "com/MsOutlookAddrBookServer.h" + +JNIEXPORT void JNICALL Java_net_java_sip_communicator_plugin_addrbook_msoutlook_calendar_CalendarServiceImpl_getAllCalendarItems( + JNIEnv *jniEnv, + jclass clazz, + jobject callback) +{ + MAPINotification_registerCalendarJniNotificationsDelegate( + jniEnv, + callback); + MsOutlookCalendar_setCallbackObject(callback); + IMsOutlookAddrBookServer * iServer = ComClient_getIServer(); + if(iServer) + { + iServer->getAllCalendarItems((long)(intptr_t)callback); + } + +} + + + +JNIEXPORT jobjectArray JNICALL +Java_net_java_sip_communicator_plugin_addrbook_msoutlook_calendar_CalendarServiceImpl_IMAPIProp_1GetProps( + JNIEnv *jniEnv, + jclass clazz, + jstring entryId, + jlongArray propIds, + jlong flags) +{ + return MsOutlookUtils_IMAPIProp_GetProps(jniEnv, clazz, entryId, propIds, flags, MsOutlookCalendar_UUID_Address); +} + diff --git a/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_calendar_CalendarServiceImpl.h b/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_calendar_CalendarServiceImpl.h new file mode 100644 index 0000000..499dc97 --- /dev/null +++ b/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_calendar_CalendarServiceImpl.h @@ -0,0 +1,30 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include <jni.h> +/* Header for class net_java_sip_communicator_plugin_addrbook_msoutlook_calendar_CalendarServiceImpl */ + +#ifndef _Included_net_java_sip_communicator_plugin_addrbook_msoutlook_calendar_CalendarServiceImpl +#define _Included_net_java_sip_communicator_plugin_addrbook_msoutlook_calendar_CalendarServiceImpl +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Class: net_java_sip_communicator_plugin_addrbook_msoutlook_calendar_CalendarServiceImpl + * Method: getAllCalendarItems + * Signature: (Lnet/java/sip/communicator/plugin/addrbook/msoutlook/calendar/CalendarServiceImpl/PtrOutlookCalendarCallback;)V + */ +JNIEXPORT void JNICALL Java_net_java_sip_communicator_plugin_addrbook_msoutlook_calendar_CalendarServiceImpl_getAllCalendarItems + (JNIEnv *, jclass, jobject); + +/* + * Class: net_java_sip_communicator_plugin_addrbook_msoutlook_calendar_CalendarServiceImpl + * Method: IMAPIProp_GetProps + * Signature: (Ljava/lang/String;[JJ)[Ljava/lang/Object; + */ +JNIEXPORT jobjectArray JNICALL Java_net_java_sip_communicator_plugin_addrbook_msoutlook_calendar_CalendarServiceImpl_IMAPIProp_1GetProps + (JNIEnv *, jclass, jstring, jlongArray, jlong); + +#ifdef __cplusplus +} +#endif +#endif |