aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lucas <chenzo@jitsi.org>2013-03-01 18:58:18 +0000
committerVincent Lucas <chenzo@jitsi.org>2013-03-01 18:58:18 +0000
commit85e6d5fc3829b22fd647ad6b3345777dcb214194 (patch)
tree5573b5c75ede0857bee87b7fc3e9d1508950f1de
parent8d2147e6365c47acb8e28c725147ceec4f6a0b9c (diff)
downloadjitsi-85e6d5fc3829b22fd647ad6b3345777dcb214194.zip
jitsi-85e6d5fc3829b22fd647ad6b3345777dcb214194.tar.gz
jitsi-85e6d5fc3829b22fd647ad6b3345777dcb214194.tar.bz2
Applies patch from Ingo Bauersachs to correct the LocalHostRetriever problem for the msoutlookaddrbook.dll. Corrects several JNI issues and code architecture. The .dll will be generated in the next commit.
-rw-r--r--src/native/addrbook/msoutlook/MAPINotification.cxx422
-rw-r--r--src/native/addrbook/msoutlook/MAPINotification.h18
-rw-r--r--src/native/addrbook/msoutlook/MAPISession.cxx33
-rw-r--r--src/native/addrbook/msoutlook/MAPISession.h17
-rw-r--r--src/native/addrbook/msoutlook/MsOutlookMAPI.h22
-rw-r--r--src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.cxx821
-rw-r--r--src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.h21
-rw-r--r--src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.cxx358
-rw-r--r--src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.h39
-rw-r--r--src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactSourceService.java15
10 files changed, 934 insertions, 832 deletions
diff --git a/src/native/addrbook/msoutlook/MAPINotification.cxx b/src/native/addrbook/msoutlook/MAPINotification.cxx
index 229699a..efa0d5f 100644
--- a/src/native/addrbook/msoutlook/MAPINotification.cxx
+++ b/src/native/addrbook/msoutlook/MAPINotification.cxx
@@ -6,11 +6,11 @@
*/
#include "MAPINotification.h"
-#include "MsOutlookMAPI.h"
+#include "MAPISession.h"
#include "net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.h"
#include "net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.h"
+
#include <mapidefs.h>
-#include <mapiutil.h>
#include <stdio.h>
#include <unknwn.h>
@@ -21,15 +21,111 @@
* @author Vincent Lucas
*/
+void MAPINotification_registerNotifyAllMsgStores(LPMAPISESSION mapiSession);
+
+void MAPINotification_unregisterNotifyAllMsgStores(void);
+
+
+
+
+
/**
* The List of events we want to retrieve.
*/
-static ULONG EVENT_MASK
+static ULONG MAPINotification_EVENT_MASK
= fnevObjectCreated
| fnevObjectDeleted
| fnevObjectModified
| fnevObjectMoved;
+static LPMDB * MAPINotification_msgStores = NULL;
+static ULONG * MAPINotification_msgStoresConnection = NULL;
+static LPMAPITABLE MAPINotification_msgStoresTable = NULL;
+static ULONG MAPINotification_msgStoresTableConnection = 0;
+static ULONG MAPINotification_nbMsgStores = 0;
+static jmethodID MAPINotification_notificationsDelegateMethodIdDeleted = NULL;
+static jmethodID MAPINotification_notificationsDelegateMethodIdInserted = NULL;
+static jmethodID MAPINotification_notificationsDelegateMethodIdUpdated = NULL;
+static jobject MAPINotification_notificationsDelegateObject = NULL;
+static ULONG MAPINotification_openEntryUlFlags = MAPI_BEST_ACCESS;
+static JavaVM * MAPINotification_VM = NULL;
+
+void MAPINotification_callDeletedMethod(LPSTR iUnknown);
+void MAPINotification_callInsertedMethod(LPUNKNOWN iUnknown);
+void MAPINotification_callUpdatedMethod(LPUNKNOWN iUnknown);
+LPUNKNOWN
+MAPINotification_openEntry
+ (ULONG cbEntryID, LPENTRYID lpEntryID, LPVOID lpvContext);
+ULONG MAPINotification_registerNotifyTable(LPMAPITABLE iUnknown);
+LONG STDAPICALLTYPE MAPINotification_tableChanged
+ (LPVOID lpvContext, ULONG cNotifications, LPNOTIFICATION lpNotifications);
+
+/**
+ * Calls back the java side when a contact is deleted.
+ *
+ * @param iUnknown The string representation of the entry id of the deleted
+ * contact.
+ */
+void MAPINotification_callDeletedMethod(LPSTR iUnknown)
+{
+ JNIEnv *tmpJniEnv = NULL;
+
+ if(MAPINotification_VM
+ ->AttachCurrentThreadAsDaemon((void**) &tmpJniEnv, NULL) == 0)
+ {
+ jstring value = tmpJniEnv->NewStringUTF(iUnknown);
+
+ tmpJniEnv->CallBooleanMethod(
+ MAPINotification_notificationsDelegateObject,
+ MAPINotification_notificationsDelegateMethodIdDeleted,
+ value);
+
+ MAPINotification_VM->DetachCurrentThread();
+ }
+}
+
+/**
+ * Calls back the java side when a contact is inserted.
+ *
+ * @param iUnknown A pointer to the newly created contact.
+ */
+void MAPINotification_callInsertedMethod(LPUNKNOWN iUnknown)
+{
+ JNIEnv *tmpJniEnv = NULL;
+
+ if(MAPINotification_VM
+ ->AttachCurrentThreadAsDaemon((void**) &tmpJniEnv, NULL) == 0)
+ {
+ tmpJniEnv->CallBooleanMethod(
+ MAPINotification_notificationsDelegateObject,
+ MAPINotification_notificationsDelegateMethodIdInserted,
+ iUnknown);
+
+ MAPINotification_VM->DetachCurrentThread();
+ }
+}
+
+/**
+ * Calls back the java side when a contact is updated.
+ *
+ * @param iUnknown A pointer to the updated contact.
+ */
+void MAPINotification_callUpdatedMethod(LPUNKNOWN iUnknown)
+{
+ JNIEnv *tmpJniEnv = NULL;
+
+ if(MAPINotification_VM
+ ->AttachCurrentThreadAsDaemon((void**) &tmpJniEnv, NULL) == 0)
+ {
+ tmpJniEnv->CallBooleanMethod(
+ MAPINotification_notificationsDelegateObject,
+ MAPINotification_notificationsDelegateMethodIdUpdated,
+ iUnknown);
+
+ MAPINotification_VM->DetachCurrentThread();
+ }
+}
+
/**
* Functions called when an event is fired from the message data base.
*
@@ -37,17 +133,16 @@ static ULONG EVENT_MASK
* @param cNotifications The number of event in this call.
* @param lpNotifications The list of notifications.
*/
-LONG STDAPICALLTYPE onNotify(
- LPVOID lpvContext,
- ULONG cNotifications,
- LPNOTIFICATION lpNotifications)
+LONG
+STDAPICALLTYPE MAPINotification_onNotify
+ (LPVOID lpvContext, ULONG cNotifications, LPNOTIFICATION lpNotifications)
{
for(unsigned int i = 0; i < cNotifications; ++i)
{
LPUNKNOWN iUnknown = NULL;
if(lpvContext != NULL)
{
- iUnknown = openEntry(
+ iUnknown = MAPINotification_openEntry(
lpNotifications[i].info.obj.cbEntryID,
lpNotifications[i].info.obj.lpEntryID,
lpvContext);
@@ -58,7 +153,7 @@ LONG STDAPICALLTYPE onNotify(
{
if(lpNotifications[i].info.obj.ulObjType == MAPI_MESSAGE)
{
- callInsertedCallbackMethod(iUnknown);
+ MAPINotification_callInsertedMethod(iUnknown);
}
}
// A contact has been Modified
@@ -66,7 +161,7 @@ LONG STDAPICALLTYPE onNotify(
{
if(lpNotifications[i].info.obj.ulObjType == MAPI_MESSAGE)
{
- callUpdatedCallbackMethod(iUnknown);
+ MAPINotification_callUpdatedMethod(iUnknown);
}
}
// A contact has been deleted.
@@ -76,15 +171,14 @@ LONG STDAPICALLTYPE onNotify(
{
char entryIdStr[lpNotifications[i].info.obj.cbEntryID * 2 + 1];
- MsOutlookAddrBookContact_hexFromBin(
- //HexFromBin(
+ HexFromBin(
(LPBYTE) lpNotifications[i].info.obj.lpEntryID,
lpNotifications[i].info.obj.cbEntryID,
entryIdStr);
if(lpNotifications[i].info.obj.ulObjType == MAPI_MESSAGE)
{
- callDeletedCallbackMethod(entryIdStr);
+ MAPINotification_callDeletedMethod(entryIdStr);
}
}
}
@@ -94,15 +188,13 @@ LONG STDAPICALLTYPE onNotify(
if(lpvContext != NULL)
{
char entryIdStr[lpNotifications[i].info.obj.cbEntryID * 2 + 1];
- MsOutlookAddrBookContact_hexFromBin(
- //HexFromBin(
+ HexFromBin(
(LPBYTE) lpNotifications[i].info.obj.lpEntryID,
lpNotifications[i].info.obj.cbEntryID,
entryIdStr);
char parentEntryIdStr[
lpNotifications[i].info.obj.cbParentID * 2 + 1];
- MsOutlookAddrBookContact_hexFromBin(
- //HexFromBin(
+ HexFromBin(
(LPBYTE) lpNotifications[i].info.obj.lpParentID,
lpNotifications[i].info.obj.cbParentID,
parentEntryIdStr);
@@ -116,13 +208,12 @@ LONG STDAPICALLTYPE onNotify(
&wasteBasketProps);
char wasteBasketEntryIdStr[
wasteBasketProps[0].Value.bin.cb * 2 + 1];
- MsOutlookAddrBookContact_hexFromBin(
- //HexFromBin(
+ HexFromBin(
(LPBYTE) wasteBasketProps[0].Value.bin.lpb,
wasteBasketProps[0].Value.bin.cb,
wasteBasketEntryIdStr);
- openEntry(
+ MAPINotification_openEntry(
lpNotifications[i].info.obj.cbParentID,
lpNotifications[i].info.obj.lpParentID,
lpvContext);
@@ -131,7 +222,7 @@ LONG STDAPICALLTYPE onNotify(
if(lpNotifications[i].info.obj.ulObjType == MAPI_MESSAGE
&& strcmp(parentEntryIdStr, wasteBasketEntryIdStr) == 0)
{
- callDeletedCallbackMethod(entryIdStr);
+ MAPINotification_callDeletedMethod(entryIdStr);
}
}
}
@@ -147,6 +238,183 @@ LONG STDAPICALLTYPE onNotify(
}
/**
+ * Opens an object from its entry id.
+ */
+LPUNKNOWN
+MAPINotification_openEntry
+ (ULONG cbEntryID, LPENTRYID lpEntryID, LPVOID lpvContext)
+{
+ if(lpvContext != NULL)
+ {
+ LPUNKNOWN iUnknown;
+ ULONG objType;
+
+ HRESULT hResult =
+ ((LPMDB) lpvContext)->OpenEntry(
+ cbEntryID,
+ lpEntryID,
+ NULL,
+ MAPINotification_openEntryUlFlags,
+ &objType,
+ &iUnknown);
+ if (HR_SUCCEEDED(hResult))
+ {
+ return iUnknown;
+ }
+ }
+ return NULL;
+}
+
+/**
+ * Registers java callback functions when a contact is deleted, inserted or
+ * updated.
+ *
+ * @param jniEnv The Java native interface environment.
+ * @param mapiSession The current MAPI session.
+ * @param notificationsDelegate The object called when a notification is fired
+ * (contact updated, inserted or deleted).
+ */
+void
+MAPINotification_registerNotificationsDelegate
+ (JNIEnv *jniEnv, LPMAPISESSION mapiSession, jobject notificationsDelegate)
+{
+ if(jniEnv->GetJavaVM(&MAPINotification_VM) < 0)
+ {
+ fprintf(stderr, "Failed to get the Java VM\n");
+ fflush(stderr);
+ }
+
+ // If this function is called once again, then check first to unregister
+ // previous notification advises.
+ MAPINotification_unregisterNotificationsDelegate(jniEnv);
+
+ if(notificationsDelegate != NULL && mapiSession != NULL)
+ {
+ MAPINotification_notificationsDelegateObject
+ = jniEnv->NewGlobalRef(notificationsDelegate);
+ if(MAPINotification_notificationsDelegateObject != NULL)
+ {
+ jclass callbackClass
+ = jniEnv->GetObjectClass(notificationsDelegate);
+ MAPINotification_notificationsDelegateMethodIdInserted
+ = jniEnv->GetMethodID(
+ callbackClass,
+ "inserted",
+ "(J)V");
+ MAPINotification_notificationsDelegateMethodIdUpdated
+ = jniEnv->GetMethodID(
+ callbackClass,
+ "updated",
+ "(J)V");
+ MAPINotification_notificationsDelegateMethodIdDeleted
+ = jniEnv->GetMethodID(
+ callbackClass,
+ "deleted",
+ "(Ljava/lang/String;)V");
+ // Register the notification of contact changed, created and
+ // deleted.
+ MAPINotification_registerNotifyAllMsgStores(mapiSession);
+ }
+ }
+}
+
+/**
+ * Opens all the message store and register to notifications.
+ */
+void MAPINotification_registerNotifyAllMsgStores(LPMAPISESSION mapiSession)
+{
+ HRESULT hResult;
+
+ hResult = mapiSession->GetMsgStoresTable(
+ 0,
+ &MAPINotification_msgStoresTable);
+ if(HR_SUCCEEDED(hResult) && MAPINotification_msgStoresTable)
+ {
+ MAPINotification_msgStoresTableConnection
+ = MAPINotification_registerNotifyTable(
+ MAPINotification_msgStoresTable);
+ hResult = MAPINotification_msgStoresTable->SeekRow(
+ BOOKMARK_BEGINNING,
+ 0,
+ NULL);
+ if (HR_SUCCEEDED(hResult))
+ {
+ LPSRowSet rows;
+ hResult = HrQueryAllRows(
+ MAPINotification_msgStoresTable,
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ &rows);
+ if (HR_SUCCEEDED(hResult))
+ {
+ MAPINotification_nbMsgStores = rows->cRows;
+ MAPINotification_msgStores
+ = (LPMDB*) malloc(rows->cRows * sizeof(LPMDB));
+ memset(
+ MAPINotification_msgStores,
+ 0,
+ rows->cRows * sizeof(LPMDB));
+ MAPINotification_msgStoresConnection
+ = (ULONG*) malloc(rows->cRows * sizeof(ULONG));
+ memset(
+ MAPINotification_msgStoresConnection,
+ 0,
+ rows->cRows * sizeof(ULONG));
+
+ if(MAPINotification_msgStores != NULL
+ && MAPINotification_msgStoresConnection != NULL)
+ {
+ for(unsigned int r = 0; r < rows->cRows; ++r)
+ {
+ SRow row = rows->aRow[r];
+ ULONG i;
+ ULONG objType = 0;
+ SBinary entryIDBinary = { 0, NULL };
+
+ for(i = 0; i < row.cValues; ++i)
+ {
+ LPSPropValue prop = (row.lpProps) + i;
+
+ switch (prop->ulPropTag)
+ {
+ case PR_OBJECT_TYPE:
+ objType = prop->Value.ul;
+ break;
+ case PR_ENTRYID:
+ entryIDBinary = prop->Value.bin;
+ break;
+ }
+ }
+
+ if(objType && entryIDBinary.cb && entryIDBinary.lpb)
+ {
+ hResult = mapiSession->OpenMsgStore(
+ 0,
+ entryIDBinary.cb,
+ (LPENTRYID) entryIDBinary.lpb,
+ NULL,
+ MDB_NO_MAIL
+ | MAPINotification_openEntryUlFlags,
+ &MAPINotification_msgStores[r]);
+ if (HR_SUCCEEDED(hResult))
+ {
+ MAPINotification_msgStoresConnection[r]
+ = MAPINotification_registerNotifyMessageDataBase(
+ MAPINotification_msgStores[r]);
+ }
+ }
+ }
+ }
+ FreeProws(rows);
+ }
+ }
+ }
+}
+
+
+/**
* Registers to notification for the given message data base.
*
* @param iUnknown The data base to register to in order to receive events.
@@ -154,22 +422,118 @@ LONG STDAPICALLTYPE onNotify(
* @return A unsigned long which is a token wich must be used to call the
* unadvise function for the same message data base.
*/
-ULONG registerNotifyMessageDataBase(
- LPMDB iUnknown)
+ULONG MAPINotification_registerNotifyMessageDataBase(LPMDB iUnknown)
{
LPMAPIADVISESINK adviseSink;
- MsOutlookAddrBookContact_HrAllocAdviseSink(
- //HrAllocAdviseSink(
- &onNotify,
- iUnknown,
- &adviseSink);
+
+ HrAllocAdviseSink(&MAPINotification_onNotify, iUnknown, &adviseSink);
+
ULONG nbConnection = 0;
iUnknown->Advise(
(ULONG) 0,
(LPENTRYID) NULL,
- EVENT_MASK,
+ MAPINotification_EVENT_MASK,
adviseSink,
(ULONG_PTR *) &nbConnection);
return nbConnection;
}
+
+/**
+ * Registers a callback function for when the message store table changes.
+ */
+ULONG MAPINotification_registerNotifyTable(LPMAPITABLE iUnknown)
+{
+ LPMAPIADVISESINK adviseSink;
+ HrAllocAdviseSink(
+ &MAPINotification_tableChanged,
+ iUnknown,
+ &adviseSink);
+ ULONG nbConnection = 0;
+ iUnknown->Advise(
+ fnevTableModified,
+ adviseSink,
+ (ULONG_PTR *) &nbConnection);
+
+ return nbConnection;
+}
+
+/**
+ * Function called when a message store table changed.
+ */
+LONG
+STDAPICALLTYPE MAPINotification_tableChanged
+ (LPVOID lpvContext, ULONG cNotifications, LPNOTIFICATION lpNotifications)
+{
+ if(lpNotifications->ulEventType == fnevTableModified
+ && (lpNotifications->info.tab.ulTableEvent == TABLE_CHANGED
+ || lpNotifications->info.tab.ulTableEvent == TABLE_ERROR
+ || lpNotifications->info.tab.ulTableEvent == TABLE_RELOAD
+ || lpNotifications->info.tab.ulTableEvent == TABLE_ROW_ADDED
+ || lpNotifications->info.tab.ulTableEvent == TABLE_ROW_DELETED))
+ {
+ // Frees and recreates all the notification for the table.
+ MAPINotification_unregisterNotifyAllMsgStores();
+ MAPINotification_registerNotifyAllMsgStores(
+ MAPISession_getMapiSession());
+ }
+
+ // A client must always return a S_OK.
+ return S_OK;
+}
+
+/**
+ * Unregisters java callback functions when a contact is deleted, inserted or
+ * updated.
+ *
+ * @param jniEnv The Java native interface environment.
+ */
+void MAPINotification_unregisterNotificationsDelegate(JNIEnv *jniEnv)
+{
+ MAPINotification_unregisterNotifyAllMsgStores();
+ if(MAPINotification_notificationsDelegateObject != NULL)
+ {
+ jniEnv->DeleteGlobalRef( MAPINotification_notificationsDelegateObject);
+ MAPINotification_notificationsDelegateMethodIdInserted = NULL;
+ MAPINotification_notificationsDelegateMethodIdUpdated = NULL;
+ MAPINotification_notificationsDelegateMethodIdDeleted = NULL;
+ }
+}
+
+/**
+ * Frees all memory used to keep in mind the list of the message store and
+ * unregister each of them from the notifications.
+ */
+void MAPINotification_unregisterNotifyAllMsgStores(void)
+{
+ if(MAPINotification_msgStoresConnection != NULL)
+ {
+ for(unsigned int i = 0; i < MAPINotification_nbMsgStores; ++i)
+ {
+ if(MAPINotification_msgStoresConnection[i] != 0)
+ {
+ MAPINotification_msgStores[i]->Unadvise(
+ MAPINotification_msgStoresConnection[i]);
+ }
+ }
+ free(MAPINotification_msgStoresConnection);
+ }
+ if(MAPINotification_msgStores != NULL)
+ {
+ for(unsigned int i = 0; i < MAPINotification_nbMsgStores; ++i)
+ {
+ if(MAPINotification_msgStores[i] != NULL)
+ {
+ MAPINotification_msgStores[i]->Release();
+ }
+ }
+ free(MAPINotification_msgStores);
+ }
+ if(MAPINotification_msgStoresTable != NULL)
+ {
+ MAPINotification_msgStoresTable->Unadvise(
+ MAPINotification_msgStoresTableConnection);
+ MAPINotification_msgStoresTable->Release();
+ }
+}
+
diff --git a/src/native/addrbook/msoutlook/MAPINotification.h b/src/native/addrbook/msoutlook/MAPINotification.h
index 9b1c8d3..c1cdeb0 100644
--- a/src/native/addrbook/msoutlook/MAPINotification.h
+++ b/src/native/addrbook/msoutlook/MAPINotification.h
@@ -13,15 +13,21 @@ extern "C" {
#endif
#include "MsOutlookMAPI.h"
+
+#include <jni.h>
#include <mapidefs.h>
-LONG STDAPICALLTYPE onNotify(
- LPVOID lpvContext,
- ULONG cNotifications,
- LPNOTIFICATION lpNotifications);
+LONG
+STDAPICALLTYPE MAPINotification_onNotify
+ (LPVOID lpvContext, ULONG cNotifications, LPNOTIFICATION lpNotifications);
+
+void
+MAPINotification_registerNotificationsDelegate
+ (JNIEnv *jniEnv, LPMAPISESSION, jobject);
+
+ULONG MAPINotification_registerNotifyMessageDataBase (LPMDB iUnknown);
-ULONG registerNotifyMessageDataBase(
- LPMDB iUnknown);
+void MAPINotification_unregisterNotificationsDelegate (JNIEnv *jniEnv);
#ifdef __cplusplus
}
diff --git a/src/native/addrbook/msoutlook/MAPISession.cxx b/src/native/addrbook/msoutlook/MAPISession.cxx
new file mode 100644
index 0000000..23b46b4
--- /dev/null
+++ b/src/native/addrbook/msoutlook/MAPISession.cxx
@@ -0,0 +1,33 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+#include "MAPISession.h"
+
+static LPMAPISESSION MAPISession_mapiSession = NULL;
+
+/**
+ * Returns the current mapi session which have been created using the
+ * MAPILogonEx function.
+ *
+ * @return The current mapi session which have been created using the
+ * MAPILogonEx function. NULL if no session is currently opened.
+ */
+LPMAPISESSION MAPISession_getMapiSession(void)
+{
+ return MAPISession_mapiSession;
+}
+
+/**
+ * Sets the current mapi session which have been created using the
+ * MAPILogonEx function.
+ *
+ * @param mapiSession The current mapi session which have been created using the
+ * MAPILogonEx function.
+ */
+void MAPISession_setMapiSession(LPMAPISESSION mapiSession)
+{
+ MAPISession_mapiSession = mapiSession;
+}
diff --git a/src/native/addrbook/msoutlook/MAPISession.h b/src/native/addrbook/msoutlook/MAPISession.h
new file mode 100644
index 0000000..f4676cb
--- /dev/null
+++ b/src/native/addrbook/msoutlook/MAPISession.h
@@ -0,0 +1,17 @@
+/*
+ * 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_MAPISESSION_H_
+#define _NET_JAVA_SIP_COMMUNICATOR_PLUGIN_ADDRBOOK_MSOUTLOOK_MAPISESSION_H_
+
+#include <Mapix.h>
+
+LPMAPISESSION MAPISession_getMapiSession(void);
+
+void MAPISession_setMapiSession(LPMAPISESSION mapiSession);
+
+#endif /* #ifndef _NET_JAVA_SIP_COMMUNICATOR_PLUGIN_ADDRBOOK_MSOUTLOOK_MAPISESSION_H_ */
diff --git a/src/native/addrbook/msoutlook/MsOutlookMAPI.h b/src/native/addrbook/msoutlook/MsOutlookMAPI.h
index ecab5b4..7cf055f 100644
--- a/src/native/addrbook/msoutlook/MsOutlookMAPI.h
+++ b/src/native/addrbook/msoutlook/MsOutlookMAPI.h
@@ -28,10 +28,32 @@
#include <mapitags.h>
#include <mapix.h>
+WINBOOL MsOutlookAddrBook_fBinFromHex(LPTSTR lpsz, LPBYTE lpb);
+#define FBinFromHex MsOutlookAddrBook_fBinFromHex
+
+void MsOutlookAddrBook_freeProws(LPSRowSet lpRows);
+#define FreeProws MsOutlookAddrBook_freeProws
+
+void MsOutlookAddrBook_hexFromBin(LPBYTE pb, int cb, LPTSTR sz);
+#define HexFromBin MsOutlookAddrBook_hexFromBin
+
+void MsOutlookAddrBook_hrAllocAdviseSink
+ (LPNOTIFCALLBACK lpfnCallback, LPVOID lpvContext,
+ LPMAPIADVISESINK* lppAdviseSink);
+#define HrAllocAdviseSink MsOutlookAddrBook_hrAllocAdviseSink
+
+HRESULT MsOutlookAddrBook_hrQueryAllRows
+ (LPMAPITABLE lpTable, LPSPropTagArray lpPropTags,
+ LPSRestriction lpRestriction, LPSSortOrderSet lpSortOrderSet,
+ LONG crowsMax, LPSRowSet* lppRows);
+#define HrQueryAllRows MsOutlookAddrBook_hrQueryAllRows
+
SCODE MsOutlookAddrBook_mapiAllocateBuffer(ULONG size, LPVOID FAR *buffer);
#define MAPIAllocateBuffer MsOutlookAddrBook_mapiAllocateBuffer
+
ULONG MsOutlookAddrBook_mapiFreeBuffer(LPVOID buffer);
#define MAPIFreeBuffer MsOutlookAddrBook_mapiFreeBuffer
+
HRESULT MsOutlookAddrBook_mapiLogonEx
(ULONG_PTR uiParam,
LPSTR profileName, LPSTR password,
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 e63fd33..48e0394 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,27 +8,14 @@
#include "net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.h"
#include "../AddrBookContactQuery.h"
-#include "MsOutlookMAPIHResultException.h"
#include "MAPINotification.h"
-#include "net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.h"
-#include <mapiutil.h>
+#include "MAPISession.h"
+#include "MsOutlookMAPIHResultException.h"
#include <stdio.h>
#include <string.h>
#define PR_ATTACHMENT_CONTACTPHOTO PROP_TAG(PT_BOOLEAN, 0x7FFF)
-static ULONG openEntryUlFlags = MAPI_BEST_ACCESS;
-
-LPUNKNOWN openEntryId(const char* entryId);
-
-ULONG registerNotifyTable(
- LPMAPITABLE iUnknown);
-
-LONG STDAPICALLTYPE tableChanged(
- LPVOID lpvContext,
- ULONG cNotifications,
- LPNOTIFICATION lpNotifications);
-
typedef
jboolean (*MsOutlookAddrBookContactQuery_ForeachRowInTableCallback)
(LPUNKNOWN iUnknown,
@@ -37,6 +24,8 @@ typedef
jstring query,
jobject callback, jmethodID callbackMethodID);
+static ULONG MsOutlookAddrBookContactQuery_openEntryUlFlags = MAPI_BEST_ACCESS;
+
static HRESULT MsOutlookAddrBookContactQuery_HrGetOneProp
(LPMAPIPROP mapiProp, ULONG propTag, LPSPropValue *prop);
@@ -85,6 +74,7 @@ static jboolean MsOutlookAddrBookContactQuery_onForeachMailUserInContainerTableR
(LPUNKNOWN mapiContainer,
ULONG entryIDByteCount, LPENTRYID entryID, ULONG objType,
JNIEnv *jniEnv, jstring query, jobject callback, jmethodID callbackMethodID);
+LPUNKNOWN MsOutlookAddrBookContactQuery_openEntryId(const char* entryId);
static jbyteArray MsOutlookAddrBookContactQuery_readAttachment
(LPMESSAGE message, LONG method, ULONG num, JNIEnv *jniEnv, ULONG cond);
@@ -97,8 +87,7 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
{
jmethodID callbackMethodID;
- LPMAPISESSION mapiSession
- = MsOutlookAddrBookContactSourceService_getMapiSession();
+ LPMAPISESSION mapiSession = MAPISession_getMapiSession();
callbackMethodID
= AddrBookContactQuery_getPtrCallbackMethodID(jniEnv, callback);
@@ -126,6 +115,117 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
}
}
+/**
+ * Deletes one property from a contact.
+ *
+ * @param jniEnv The Java native interface environment.
+ * @param clazz A Java class Object.
+ * @param propId The outlook property identifier.
+ * @param entryId The identifer of the outlook entry to modify.
+ *
+ * @return JNI_TRUE if the deletion succeded. JNI_FALSE otherwise.
+ */
+JNIEXPORT jboolean JNICALL
+Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery_IMAPIProp_1DeleteProp
+ (JNIEnv *jniEnv, jclass clazz, jlong propId, jstring entryId)
+{
+ const char *nativeEntryId = jniEnv->GetStringUTFChars(entryId, NULL);
+ LPUNKNOWN mapiProp;
+ if((mapiProp = MsOutlookAddrBookContactQuery_openEntryId(nativeEntryId))
+ == NULL)
+ {
+ return JNI_FALSE;
+ }
+ jniEnv->ReleaseStringUTFChars(entryId, nativeEntryId);
+
+ ULONG baseGroupEntryIdProp = 0;
+ switch(propId)
+ {
+ case 0x00008083: // dispidEmail1EmailAddress
+ baseGroupEntryIdProp = 0x00008080;
+ break;
+ case 0x00008093: // dispidEmail2EmailAddress
+ baseGroupEntryIdProp = 0x00008090;
+ break;
+ case 0x000080A3: // dispidEmail3EmailAddress
+ baseGroupEntryIdProp = 0x000080A0;
+ break;
+ }
+ // If this is a special entry (for email only), then deletes all the
+ // corresponding properties to make it work.
+ if(baseGroupEntryIdProp != 0)
+ {
+ ULONG nbProps = 5;
+ ULONG propIds[] =
+ {
+ (baseGroupEntryIdProp + 0), //0x8080 PidLidEmail1DisplayName
+ (baseGroupEntryIdProp + 2), // 0x8082 PidLidEmail1AddressType
+ (baseGroupEntryIdProp + 3), // 0x8083 PidLidEmail1EmailAddress
+ (baseGroupEntryIdProp + 4), // 0x8084 PidLidEmail1OriginalDisplayName
+ (baseGroupEntryIdProp + 5) // 0x8085 PidLidEmail1OriginalEntryID
+ };
+ ULONG propTag;
+ LPSPropTagArray propTagArray;
+ MAPIAllocateBuffer(
+ CbNewSPropTagArray(nbProps),
+ (void **) &propTagArray);
+ propTagArray->cValues = nbProps;
+ for(unsigned int i = 0; i < nbProps; ++i)
+ {
+ propTag = MsOutlookAddrBookContactQuery_getPropTagFromLid(
+ (LPMAPIPROP) mapiProp,
+ propIds[i]);
+ *(propTagArray->aulPropTag + i) = propTag;
+ }
+
+ HRESULT hResult
+ = ((LPMAPIPROP) mapiProp)->DeleteProps(
+ propTagArray,
+ NULL);
+
+ if (HR_SUCCEEDED(hResult))
+ {
+ hResult
+ = ((LPMAPIPROP) mapiProp)->SaveChanges(
+ FORCE_SAVE | KEEP_OPEN_READWRITE);
+
+ if (HR_SUCCEEDED(hResult))
+ {
+ MAPIFreeBuffer(propTagArray);
+ ((LPMAPIPROP) mapiProp)->Release();
+ return JNI_TRUE;
+ }
+ }
+ MAPIFreeBuffer(propTagArray);
+ ((LPMAPIPROP) mapiProp)->Release();
+ return JNI_FALSE;
+ }
+
+ SPropTagArray propToDelete;
+ propToDelete.cValues = 1;
+ propToDelete.aulPropTag[0] = PROP_TAG(PT_UNICODE, propId);
+
+ HRESULT hResult
+ = ((LPMAPIPROP) mapiProp)->DeleteProps(
+ (LPSPropTagArray) &propToDelete,
+ NULL);
+
+ if (HR_SUCCEEDED(hResult))
+ {
+ hResult
+ = ((LPMAPIPROP) mapiProp)->SaveChanges(
+ FORCE_SAVE | KEEP_OPEN_READWRITE);
+
+ if (HR_SUCCEEDED(hResult))
+ {
+ ((LPMAPIPROP) mapiProp)->Release();
+ return JNI_TRUE;
+ }
+ }
+ ((LPMAPIPROP) mapiProp)->Release();
+ return JNI_FALSE;
+}
+
JNIEXPORT jobjectArray JNICALL
Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery_IMAPIProp_1GetProps(
JNIEnv *jniEnv,
@@ -312,8 +412,7 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
{
char entryIdStr[prop->Value.bin.cb * 2 + 1];
- MsOutlookAddrBookContact_hexFromBin(
- //HexFromBin(
+ HexFromBin(
prop->Value.bin.lpb,
prop->Value.bin.cb,
entryIdStr);
@@ -356,6 +455,153 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
return props;
}
+/**
+ * Saves one contact property.
+ *
+ * @param jniEnv The Java native interface environment.
+ * @param clazz A Java class Object.
+ * @param propId The outlook property identifier.
+ * @param value The value to set to the outlook property.
+ * @param entryId The identifer of the outlook entry to modify.
+ *
+ * @return JNI_TRUE if the modification succeded. JNI_FALSE otherwise.
+ */
+JNIEXPORT jboolean JNICALL
+Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery_IMAPIProp_1SetPropString
+ (JNIEnv *jniEnv, jclass clazz, jlong propId, jstring value,
+ jstring entryId)
+{
+ HRESULT hResult;
+
+ const char *nativeEntryId = jniEnv->GetStringUTFChars(entryId, NULL);
+ LPUNKNOWN mapiProp;
+ if((mapiProp = MsOutlookAddrBookContactQuery_openEntryId(nativeEntryId))
+ == NULL)
+ {
+ return JNI_FALSE;
+ }
+ jniEnv->ReleaseStringUTFChars(entryId, nativeEntryId);
+
+ const char *nativeValue = jniEnv->GetStringUTFChars(value, NULL);
+ size_t valueLength = strlen(nativeValue);
+ wchar_t wCharValue[valueLength + 1];
+ if(mbstowcs(wCharValue, nativeValue, valueLength + 1)
+ != valueLength)
+ {
+ fprintf(stderr,
+ "setPropUnicode (addrbook/MsOutlookAddrBookContactQuery.c): \
+ \n\tmbstowcs\n");
+ fflush(stderr);
+ jniEnv->ReleaseStringUTFChars(value, nativeValue);
+ return JNI_FALSE;
+ }
+ jniEnv->ReleaseStringUTFChars(value, nativeValue);
+
+ ULONG baseGroupEntryIdProp = 0;
+ switch(propId)
+ {
+ case 0x00008083: // dispidEmail1EmailAddress
+ baseGroupEntryIdProp = 0x00008080;
+ break;
+ case 0x00008093: // dispidEmail2EmailAddress
+ baseGroupEntryIdProp = 0x00008090;
+ break;
+ case 0x000080A3: // dispidEmail3EmailAddress
+ baseGroupEntryIdProp = 0x000080A0;
+ break;
+ }
+ // If this is a special entry (for email only), then updates all the
+ // corresponding properties to make it work.
+ if(baseGroupEntryIdProp != 0)
+ {
+ ULONG nbProps = 7;
+ ULONG propIds[] =
+ {
+ 0x8028, // PidLidAddressBookProviderEmailList
+ 0x8029, // PidLidAddressBookProviderArrayType
+ (baseGroupEntryIdProp + 0), //0x8080 PidLidEmail1DisplayName
+ (baseGroupEntryIdProp + 2), // 0x8082 PidLidEmail1AddressType
+ (baseGroupEntryIdProp + 3), // 0x8083 PidLidEmail1EmailAddress
+ (baseGroupEntryIdProp + 4), // 0x8084 PidLidEmail1OriginalDisplayName
+ (baseGroupEntryIdProp + 5) // 0x8085 PidLidEmail1OriginalEntryID
+ };
+ ULONG propTag;
+ ULONG propCount;
+ LPSPropValue propArray;
+ LPSPropTagArray propTagArray;
+ MAPIAllocateBuffer(
+ CbNewSPropTagArray(nbProps),
+ (void **) &propTagArray);
+ propTagArray->cValues = nbProps;
+ for(unsigned int i = 0; i < nbProps; ++i)
+ {
+ propTag = MsOutlookAddrBookContactQuery_getPropTagFromLid(
+ (LPMAPIPROP) mapiProp,
+ propIds[i]);
+ *(propTagArray->aulPropTag + i) = propTag;
+ }
+ hResult = ((LPMAPIPROP) mapiProp)->GetProps(
+ propTagArray,
+ MAPI_UNICODE,
+ &propCount,
+ &propArray);
+
+ if(SUCCEEDED(hResult))
+ {
+ propArray[2].Value.lpszW = wCharValue;
+ propArray[4].Value.lpszW = wCharValue;
+ propArray[5].Value.lpszW = wCharValue;
+
+ if(SUCCEEDED(hResult))
+ {
+ hResult = ((LPMAPIPROP) mapiProp)->SetProps(
+ nbProps,
+ propArray,
+ NULL);
+ if(SUCCEEDED(hResult))
+ {
+ hResult = ((LPMAPIPROP) mapiProp)->SaveChanges(
+ FORCE_SAVE | KEEP_OPEN_READWRITE);
+ if (HR_SUCCEEDED(hResult))
+ {
+ MAPIFreeBuffer(propTagArray);
+ ((LPMAPIPROP) mapiProp)->Release();
+ return JNI_TRUE;
+ }
+ }
+ }
+ }
+ MAPIFreeBuffer(propTagArray);
+ ((LPMAPIPROP) mapiProp)->Release();
+ return JNI_FALSE;
+ }
+
+ SPropValue updateValue;
+ updateValue.ulPropTag = PROP_TAG(PT_UNICODE, propId);
+ updateValue.Value.lpszW = wCharValue;
+
+ hResult = ((LPMAPIPROP) mapiProp)->SetProps(
+ 1,
+ (LPSPropValue) &updateValue,
+ NULL);
+
+ if (HR_SUCCEEDED(hResult))
+ {
+ HRESULT hResult
+ = ((LPMAPIPROP) mapiProp)->SaveChanges(
+ FORCE_SAVE | KEEP_OPEN_READWRITE);
+
+ if (HR_SUCCEEDED(hResult))
+ {
+ ((LPMAPIPROP) mapiProp)->Release();
+ return JNI_TRUE;
+ }
+ }
+
+ ((LPMAPIPROP) mapiProp)->Release();
+ return JNI_FALSE;
+}
+
static HRESULT
MsOutlookAddrBookContactQuery_HrGetOneProp(
LPMAPIPROP mapiProp,
@@ -518,7 +764,7 @@ MsOutlookAddrBookContactQuery_foreachMailUserInAddressBook
0,
NULL,
NULL,
- openEntryUlFlags,
+ MsOutlookAddrBookContactQuery_openEntryUlFlags,
&objType,
&iUnknown);
@@ -789,7 +1035,7 @@ MsOutlookAddrBookContactQuery_getContactsFolderEntryID
folderEntryIDByteCount,
folderEntryID,
NULL,
- openEntryUlFlags,
+ MsOutlookAddrBookContactQuery_openEntryUlFlags,
&objType,
&folder);
@@ -878,7 +1124,7 @@ MsOutlookAddrBookContactQuery_onForeachContactInMsgStoresTableRow
0,
entryIDByteCount, entryID,
NULL,
- MDB_NO_MAIL | openEntryUlFlags,
+ MDB_NO_MAIL | MsOutlookAddrBookContactQuery_openEntryUlFlags,
&msgStore);
if (HR_SUCCEEDED(hResult))
{
@@ -918,7 +1164,7 @@ MsOutlookAddrBookContactQuery_onForeachContactInMsgStoresTableRow
= msgStore->OpenEntry(
contactsFolderEntryIDByteCount, contactsFolderEntryID,
NULL,
- openEntryUlFlags,
+ MsOutlookAddrBookContactQuery_openEntryUlFlags,
&contactsFolderObjType, &contactsFolder);
if (HR_SUCCEEDED(hResult))
{
@@ -970,7 +1216,7 @@ MsOutlookAddrBookContactQuery_onForeachMailUserInContainerTableRow
= ((LPMAPICONTAINER) mapiContainer)->OpenEntry(
entryIDByteCount, entryID,
NULL,
- openEntryUlFlags,
+ MsOutlookAddrBookContactQuery_openEntryUlFlags,
&objType, &iUnknown);
if (HR_SUCCEEDED(hResult))
{
@@ -988,6 +1234,39 @@ MsOutlookAddrBookContactQuery_onForeachMailUserInContainerTableRow
return proceed;
}
+/**
+ * Opens an object based on the string representation of its entry id.
+ *
+ * @param entryId The identifier of the entry to open.
+ *
+ * @return A pointer to the opened entry. NULL if anything goes wrong.
+ */
+LPUNKNOWN MsOutlookAddrBookContactQuery_openEntryId(const char* entryId)
+{
+ ULONG tmpEntryIdSize = strlen(entryId) / 2;
+ LPENTRYID tmpEntryId = (LPENTRYID) malloc(tmpEntryIdSize * sizeof(char));
+ if(FBinFromHex((LPSTR) entryId, (LPBYTE) tmpEntryId))
+ {
+ LPMAPISESSION mapiSession = MAPISession_getMapiSession();
+ ULONG objType;
+ LPUNKNOWN iUnknown;
+ HRESULT hResult = mapiSession->OpenEntry(
+ tmpEntryIdSize,
+ tmpEntryId,
+ NULL,
+ MAPI_BEST_ACCESS,
+ &objType,
+ &iUnknown);
+ if(hResult == S_OK)
+ {
+ free(tmpEntryId);
+ return iUnknown;
+ }
+ }
+ free(tmpEntryId);
+ return NULL;
+}
+
static jbyteArray
MsOutlookAddrBookContactQuery_readAttachment
(LPMESSAGE message, LONG method, ULONG num, JNIEnv *jniEnv, ULONG cond)
@@ -1072,497 +1351,3 @@ MsOutlookAddrBookContactQuery_readAttachment
}
return attachment;
}
-
-/**
- * Saves one contact property.
- */
-JNIEXPORT jboolean JNICALL
-Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery_IMAPIProp_1SetPropString
- (JNIEnv *jniEnv, jclass clazz, jlong propId, jstring value,
- jstring entryId)
-{
- HRESULT hResult;
-
- const char *nativeEntryId = jniEnv->GetStringUTFChars(entryId, NULL);
- LPUNKNOWN mapiProp;
- if((mapiProp = openEntryId(nativeEntryId)) == NULL)
- {
- return JNI_FALSE;
- }
- jniEnv->ReleaseStringUTFChars(entryId, nativeEntryId);
-
- const char *nativeValue = jniEnv->GetStringUTFChars(value, NULL);
- size_t valueLength = strlen(nativeValue);
- wchar_t wCharValue[valueLength + 1];
- if(mbstowcs(wCharValue, nativeValue, valueLength + 1)
- != valueLength)
- {
- fprintf(stderr,
- "setPropUnicode (addrbook/MsOutlookAddrBookContactQuery.c): \
- \n\tmbstowcs\n");
- fflush(stderr);
- jniEnv->ReleaseStringUTFChars(value, nativeValue);
- return JNI_FALSE;
- }
- jniEnv->ReleaseStringUTFChars(value, nativeValue);
-
- ULONG baseGroupEntryIdProp = 0;
- switch(propId)
- {
- case 0x00008083: // dispidEmail1EmailAddress
- baseGroupEntryIdProp = 0x00008080;
- break;
- case 0x00008093: // dispidEmail2EmailAddress
- baseGroupEntryIdProp = 0x00008090;
- break;
- case 0x000080A3: // dispidEmail3EmailAddress
- baseGroupEntryIdProp = 0x000080A0;
- break;
- }
- // If this is a special entry (for email only), then updates all the
- // corresponding properties to make it work.
- if(baseGroupEntryIdProp != 0)
- {
- ULONG nbProps = 7;
- ULONG propIds[] =
- {
- 0x8028, // PidLidAddressBookProviderEmailList
- 0x8029, // PidLidAddressBookProviderArrayType
- (baseGroupEntryIdProp + 0), //0x8080 PidLidEmail1DisplayName
- (baseGroupEntryIdProp + 2), // 0x8082 PidLidEmail1AddressType
- (baseGroupEntryIdProp + 3), // 0x8083 PidLidEmail1EmailAddress
- (baseGroupEntryIdProp + 4), // 0x8084 PidLidEmail1OriginalDisplayName
- (baseGroupEntryIdProp + 5) // 0x8085 PidLidEmail1OriginalEntryID
- };
- ULONG propTag;
- ULONG propCount;
- LPSPropValue propArray;
- LPSPropTagArray propTagArray;
- MAPIAllocateBuffer(
- CbNewSPropTagArray(nbProps),
- (void **) &propTagArray);
- propTagArray->cValues = nbProps;
- for(unsigned int i = 0; i < nbProps; ++i)
- {
- propTag = MsOutlookAddrBookContactQuery_getPropTagFromLid(
- (LPMAPIPROP) mapiProp,
- propIds[i]);
- *(propTagArray->aulPropTag + i) = propTag;
- }
- hResult = ((LPMAPIPROP) mapiProp)->GetProps(
- propTagArray,
- MAPI_UNICODE,
- &propCount,
- &propArray);
-
- if(SUCCEEDED(hResult))
- {
- propArray[2].Value.lpszW = wCharValue;
- propArray[4].Value.lpszW = wCharValue;
- propArray[5].Value.lpszW = wCharValue;
-
- if(SUCCEEDED(hResult))
- {
- hResult = ((LPMAPIPROP) mapiProp)->SetProps(
- nbProps,
- propArray,
- NULL);
- if(SUCCEEDED(hResult))
- {
- hResult = ((LPMAPIPROP) mapiProp)->SaveChanges(
- FORCE_SAVE | KEEP_OPEN_READWRITE);
- if (HR_SUCCEEDED(hResult))
- {
- MAPIFreeBuffer(propTagArray);
- ((LPMAPIPROP) mapiProp)->Release();
- return JNI_TRUE;
- }
- }
- }
- }
- MAPIFreeBuffer(propTagArray);
- ((LPMAPIPROP) mapiProp)->Release();
- return JNI_FALSE;
- }
-
- SPropValue updateValue;
- updateValue.ulPropTag = PROP_TAG(PT_UNICODE, propId);
- updateValue.Value.lpszW = wCharValue;
-
- hResult = ((LPMAPIPROP) mapiProp)->SetProps(
- 1,
- (LPSPropValue) &updateValue,
- NULL);
-
- if (HR_SUCCEEDED(hResult))
- {
- HRESULT hResult
- = ((LPMAPIPROP) mapiProp)->SaveChanges(
- FORCE_SAVE | KEEP_OPEN_READWRITE);
-
- if (HR_SUCCEEDED(hResult))
- {
- ((LPMAPIPROP) mapiProp)->Release();
- return JNI_TRUE;
- }
- }
-
- ((LPMAPIPROP) mapiProp)->Release();
- return JNI_FALSE;
-}
-
-/**
- * Deletes one property from a contact.
- */
-JNIEXPORT jboolean JNICALL
-Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery_IMAPIProp_1DeleteProp
- (JNIEnv *jniEnv, jclass clazz, jlong propId, jstring entryId)
-{
- const char *nativeEntryId = jniEnv->GetStringUTFChars(entryId, NULL);
- LPUNKNOWN mapiProp;
- if((mapiProp = openEntryId(nativeEntryId)) == NULL)
- {
- return JNI_FALSE;
- }
- jniEnv->ReleaseStringUTFChars(entryId, nativeEntryId);
-
- ULONG baseGroupEntryIdProp = 0;
- switch(propId)
- {
- case 0x00008083: // dispidEmail1EmailAddress
- baseGroupEntryIdProp = 0x00008080;
- break;
- case 0x00008093: // dispidEmail2EmailAddress
- baseGroupEntryIdProp = 0x00008090;
- break;
- case 0x000080A3: // dispidEmail3EmailAddress
- baseGroupEntryIdProp = 0x000080A0;
- break;
- }
- // If this is a special entry (for email only), then deletes all the
- // corresponding properties to make it work.
- if(baseGroupEntryIdProp != 0)
- {
- ULONG nbProps = 5;
- ULONG propIds[] =
- {
- (baseGroupEntryIdProp + 0), //0x8080 PidLidEmail1DisplayName
- (baseGroupEntryIdProp + 2), // 0x8082 PidLidEmail1AddressType
- (baseGroupEntryIdProp + 3), // 0x8083 PidLidEmail1EmailAddress
- (baseGroupEntryIdProp + 4), // 0x8084 PidLidEmail1OriginalDisplayName
- (baseGroupEntryIdProp + 5) // 0x8085 PidLidEmail1OriginalEntryID
- };
- ULONG propTag;
- LPSPropTagArray propTagArray;
- MAPIAllocateBuffer(
- CbNewSPropTagArray(nbProps),
- (void **) &propTagArray);
- propTagArray->cValues = nbProps;
- for(unsigned int i = 0; i < nbProps; ++i)
- {
- propTag = MsOutlookAddrBookContactQuery_getPropTagFromLid(
- (LPMAPIPROP) mapiProp,
- propIds[i]);
- *(propTagArray->aulPropTag + i) = propTag;
- }
-
- HRESULT hResult
- = ((LPMAPIPROP) mapiProp)->DeleteProps(
- propTagArray,
- NULL);
-
- if (HR_SUCCEEDED(hResult))
- {
- hResult
- = ((LPMAPIPROP) mapiProp)->SaveChanges(
- FORCE_SAVE | KEEP_OPEN_READWRITE);
-
- if (HR_SUCCEEDED(hResult))
- {
- MAPIFreeBuffer(propTagArray);
- ((LPMAPIPROP) mapiProp)->Release();
- return JNI_TRUE;
- }
- }
- MAPIFreeBuffer(propTagArray);
- ((LPMAPIPROP) mapiProp)->Release();
- return JNI_FALSE;
- }
-
- SPropTagArray propToDelete;
- propToDelete.cValues = 1;
- propToDelete.aulPropTag[0] = PROP_TAG(PT_UNICODE, propId);
-
- HRESULT hResult
- = ((LPMAPIPROP) mapiProp)->DeleteProps(
- (LPSPropTagArray) &propToDelete,
- NULL);
-
- if (HR_SUCCEEDED(hResult))
- {
- hResult
- = ((LPMAPIPROP) mapiProp)->SaveChanges(
- FORCE_SAVE | KEEP_OPEN_READWRITE);
-
- if (HR_SUCCEEDED(hResult))
- {
- ((LPMAPIPROP) mapiProp)->Release();
- return JNI_TRUE;
- }
- }
- ((LPMAPIPROP) mapiProp)->Release();
- return JNI_FALSE;
-}
-
-/**
- * Opens an object from its entry id.
- */
-LPUNKNOWN openEntry(
- ULONG cbEntryID,
- LPENTRYID lpEntryID,
- LPVOID lpvContext)
-{
- if(lpvContext != NULL)
- {
- LPUNKNOWN iUnknown;
- ULONG objType;
-
- HRESULT hResult =
- ((LPMDB) lpvContext)->OpenEntry(
- cbEntryID,
- lpEntryID,
- NULL,
- openEntryUlFlags,
- &objType,
- &iUnknown);
- if (HR_SUCCEEDED(hResult))
- {
- return iUnknown;
- }
- }
- return NULL;
-}
-
-static LPMAPITABLE MsOutlookAddrBookContactQuery_msgStoresTable = NULL;
-static ULONG MsOutlookAddrBookContactQuery_msgStoresTableConnection = 0;
-static ULONG MsOutlookAddrBookContactQuery_nbMsgStores = 0;
-static LPMDB * MsOutlookAddrBookContactQuery_msgStores = NULL;
-static ULONG * MsOutlookAddrBookContactQuery_msgStoresConnection = NULL;
-
-/**
- * Opens all the message store and register to notifications.
- */
-void openAllMsgStores(
- LPMAPISESSION mapiSession)
-{
- HRESULT hResult;
-
- hResult = mapiSession->GetMsgStoresTable(
- 0,
- &MsOutlookAddrBookContactQuery_msgStoresTable);
- if(HR_SUCCEEDED(hResult) && MsOutlookAddrBookContactQuery_msgStoresTable)
- {
- MsOutlookAddrBookContactQuery_msgStoresTableConnection
- = registerNotifyTable(MsOutlookAddrBookContactQuery_msgStoresTable);
- hResult = MsOutlookAddrBookContactQuery_msgStoresTable->SeekRow(
- BOOKMARK_BEGINNING,
- 0,
- NULL);
- if (HR_SUCCEEDED(hResult))
- {
- LPSRowSet rows;
- hResult = MsOutlookAddrBookContact_HrQueryAllRows(
- //hResult = HrQueryAllRows(
- MsOutlookAddrBookContactQuery_msgStoresTable,
- NULL,
- NULL,
- NULL,
- 0,
- &rows);
- if (HR_SUCCEEDED(hResult))
- {
- MsOutlookAddrBookContactQuery_nbMsgStores = rows->cRows;
- MsOutlookAddrBookContactQuery_msgStores
- = (LPMDB*) malloc(rows->cRows * sizeof(LPMDB));
- memset(
- MsOutlookAddrBookContactQuery_msgStores,
- 0,
- rows->cRows * sizeof(LPMDB));
- MsOutlookAddrBookContactQuery_msgStoresConnection
- = (ULONG*) malloc(rows->cRows * sizeof(ULONG));
- memset(
- MsOutlookAddrBookContactQuery_msgStoresConnection,
- 0,
- rows->cRows * sizeof(ULONG));
-
- if(MsOutlookAddrBookContactQuery_msgStores != NULL
- && MsOutlookAddrBookContactQuery_msgStoresConnection
- != NULL)
- {
- for(unsigned int r = 0; r < rows->cRows; ++r)
- {
- SRow row = rows->aRow[r];
- ULONG i;
- ULONG objType = 0;
- SBinary entryIDBinary = { 0, NULL };
-
- for(i = 0; i < row.cValues; ++i)
- {
- LPSPropValue prop = (row.lpProps) + i;
-
- switch (prop->ulPropTag)
- {
- case PR_OBJECT_TYPE:
- objType = prop->Value.ul;
- break;
- case PR_ENTRYID:
- entryIDBinary = prop->Value.bin;
- break;
- }
- }
-
- if(objType && entryIDBinary.cb && entryIDBinary.lpb)
- {
- hResult = mapiSession->OpenMsgStore(
- 0,
- entryIDBinary.cb,
- (LPENTRYID) entryIDBinary.lpb,
- NULL,
- MDB_NO_MAIL | openEntryUlFlags,
- &MsOutlookAddrBookContactQuery_msgStores[r]
- );
- if (HR_SUCCEEDED(hResult))
- {
- MsOutlookAddrBookContactQuery_msgStoresConnection[r]
- = registerNotifyMessageDataBase(
- MsOutlookAddrBookContactQuery_msgStores[r]);
- }
- }
- }
- }
- MsOutlookAddrBookContact_FreeProws(rows);
- //FreeProws(rows);
- }
- }
- }
-}
-
-/**
- * Frees all memory used to keep in mind the list of the message store and
- * unregister each of them from the notifications.
- */
-void freeAllMsgStores(void)
-{
- if(MsOutlookAddrBookContactQuery_msgStoresConnection != NULL)
- {
- for(unsigned int i = 0;
- i < MsOutlookAddrBookContactQuery_nbMsgStores;
- ++i)
- {
- if(MsOutlookAddrBookContactQuery_msgStoresConnection[i] != 0)
- {
- MsOutlookAddrBookContactQuery_msgStores[i]->Unadvise(
- MsOutlookAddrBookContactQuery_msgStoresConnection[i]);
- }
- }
- free(MsOutlookAddrBookContactQuery_msgStoresConnection);
- }
- if(MsOutlookAddrBookContactQuery_msgStores != NULL)
- {
- for(unsigned int i = 0;
- i < MsOutlookAddrBookContactQuery_nbMsgStores;
- ++i)
- {
- if(MsOutlookAddrBookContactQuery_msgStores[i] != NULL)
- {
- MsOutlookAddrBookContactQuery_msgStores[i]->Release();
- }
- }
- free(MsOutlookAddrBookContactQuery_msgStores);
- }
- if(MsOutlookAddrBookContactQuery_msgStoresTable != NULL)
- {
- MsOutlookAddrBookContactQuery_msgStoresTable->Unadvise(
- MsOutlookAddrBookContactQuery_msgStoresTableConnection);
- MsOutlookAddrBookContactQuery_msgStoresTable->Release();
- }
-}
-
-/**
- * Opens an object based on the string representation of its entry id.
- */
-LPUNKNOWN openEntryId(const char* entryId)
-{
- ULONG tmpEntryIdSize = strlen(entryId) / 2;
- LPENTRYID tmpEntryId = (LPENTRYID) malloc(tmpEntryIdSize * sizeof(char));
- if(MsOutlookAddrBookContact_FBinFromHex(
- (LPSTR) entryId,
- (LPBYTE) tmpEntryId))
- //if(FBinFromHex((LPSTR) entryId, (LPBYTE) tmpEntryId))
- {
- LPMAPISESSION mapiSession
- = MsOutlookAddrBookContactSourceService_getMapiSession();
- ULONG objType;
- LPUNKNOWN iUnknown;
- HRESULT hResult = mapiSession->OpenEntry(
- tmpEntryIdSize,
- tmpEntryId,
- NULL,
- MAPI_BEST_ACCESS,
- &objType,
- &iUnknown);
- if(hResult == S_OK)
- {
- free(tmpEntryId);
- return iUnknown;
- }
- }
- free(tmpEntryId);
- return NULL;
-}
-
-/**
- * Registers a callback function for when the message store table changes.
- */
-ULONG
-registerNotifyTable(LPMAPITABLE iUnknown)
-{
- LPMAPIADVISESINK adviseSink;
- MsOutlookAddrBookContact_HrAllocAdviseSink(
- //HrAllocAdviseSink(
- &tableChanged,
- iUnknown,
- &adviseSink);
- ULONG nbConnection = 0;
- iUnknown->Advise(
- fnevTableModified,
- adviseSink,
- (ULONG_PTR *) &nbConnection);
-
- return nbConnection;
-}
-
-/**
- * Function called when a message store table changed.
- */
-LONG STDAPICALLTYPE tableChanged(
- LPVOID lpvContext,
- ULONG cNotifications,
- LPNOTIFICATION lpNotifications)
-{
- if(lpNotifications->ulEventType == fnevTableModified
- && (lpNotifications->info.tab.ulTableEvent == TABLE_CHANGED
- || lpNotifications->info.tab.ulTableEvent == TABLE_ERROR
- || lpNotifications->info.tab.ulTableEvent == TABLE_RELOAD
- || lpNotifications->info.tab.ulTableEvent == TABLE_ROW_ADDED
- || lpNotifications->info.tab.ulTableEvent == TABLE_ROW_DELETED))
- {
- // Frees and recreates all the notification for the table.
- freeAllMsgStores();
- openAllMsgStores(
- MsOutlookAddrBookContactSourceService_getMapiSession());
- }
-
- // A client must always return a S_OK.
- return S_OK;
-}
diff --git a/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.h b/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.h
index 3c4786c..c1a310c 100644
--- a/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.h
+++ b/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.h
@@ -8,11 +8,6 @@
extern "C" {
#endif
-#include "MsOutlookMAPI.h"
-#include <mapidefs.h>
-#include <mapix.h>
-#include <unknwn.h>
-
/*
* Class: net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery
* Method: foreachMailUser
@@ -21,6 +16,9 @@ extern "C" {
JNIEXPORT void JNICALL Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery_foreachMailUser
(JNIEnv *, jclass, jstring, jobject);
+JNIEXPORT jboolean JNICALL Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery_IMAPIProp_1DeleteProp
+ (JNIEnv *, jclass, jlong, jstring);
+
/*
* Class: net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery
* Method: IMAPIProp_GetProps
@@ -32,19 +30,6 @@ JNIEXPORT jobjectArray JNICALL Java_net_java_sip_communicator_plugin_addrbook_ms
JNIEXPORT jboolean JNICALL Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery_IMAPIProp_1SetPropString
(JNIEnv *, jclass, jlong, jstring, jstring);
-JNIEXPORT jboolean JNICALL Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery_IMAPIProp_1DeleteProp
- (JNIEnv *, jclass, jlong, jstring);
-
-LPUNKNOWN openEntry(
- ULONG cbEntryID,
- LPENTRYID lpEntryID,
- LPVOID lpvContext);
-
-void openAllMsgStores(
- LPMAPISESSION mapiSession);
-
-void freeAllMsgStores(void);
-
#ifdef __cplusplus
}
#endif
diff --git a/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.cxx b/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.cxx
index 4514097..0624357 100644
--- a/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.cxx
+++ b/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.cxx
@@ -10,133 +10,24 @@
#include "../AddrBookContactQuery.h"
#include "MsOutlookMAPIHResultException.h"
#include "MAPINotification.h"
+#include "MAPISession.h"
#include "net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.h"
-#include <mapiutil.h>
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-static jobject contactSourceServiceObject;
-static jmethodID contactSourceServiceMethodIdInserted;
-static jmethodID contactSourceServiceMethodIdUpdated;
-static jmethodID contactSourceServiceMethodIdDeleted;
-static JNIEnv *contactSourceServiceJniEnv;
-static JavaVM *contactSourceServiceVM;
-
-/**
- * Registers java callback functions when a contact is deleted, inserted or
- * updated.
- */
-JNIEXPORT void JNICALL
-Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService_setDelegate
- (JNIEnv *jniEnv, jclass clazz, jobject callback)
-{
- if(jniEnv->GetJavaVM(&contactSourceServiceVM) < 0)
- {
- fprintf(stderr, "Failed to get the Java VM\n");
- fflush(stderr);
- }
- contactSourceServiceJniEnv = jniEnv;
- contactSourceServiceObject = jniEnv->NewGlobalRef(callback);
- jclass callbackClass = jniEnv->GetObjectClass(
- callback);
- contactSourceServiceMethodIdInserted = jniEnv->GetMethodID(
- callbackClass,
- "inserted",
- "(J)V");
- contactSourceServiceMethodIdUpdated = jniEnv->GetMethodID(
- callbackClass,
- "updated",
- "(J)V");
- contactSourceServiceMethodIdDeleted = jniEnv->GetMethodID(
- callbackClass,
- "deleted",
- "(Ljava/lang/String;)V");
-}
-
-/**
- * Calls back the java side when a contact is inserted.
- *
- * @param iUnknown A pointer to the newly created contact.
- */
-void callInsertedCallbackMethod(
- LPUNKNOWN iUnknown)
-{
- JNIEnv *tmpJniEnv = contactSourceServiceJniEnv;
-
- if(contactSourceServiceVM->GetEnv(
- (void**) &tmpJniEnv,
- JNI_VERSION_1_6)
- != JNI_OK)
- {
- contactSourceServiceVM->AttachCurrentThread((void**) &tmpJniEnv, NULL);
- }
-
- tmpJniEnv->CallBooleanMethod(
- contactSourceServiceObject,
- contactSourceServiceMethodIdInserted,
- iUnknown);
-
- contactSourceServiceVM->DetachCurrentThread();
-}
-
-/**
- * Calls back the java side when a contact is updated.
- *
- * @param iUnknown A pointer to the updated contact.
- */
-void callUpdatedCallbackMethod(
- LPUNKNOWN iUnknown)
-{
- JNIEnv *tmpJniEnv = contactSourceServiceJniEnv;
-
- if(contactSourceServiceVM->GetEnv(
- (void**) &tmpJniEnv,
- JNI_VERSION_1_6)
- != JNI_OK)
- {
- contactSourceServiceVM->AttachCurrentThread((void**) &tmpJniEnv, NULL);
- }
-
- tmpJniEnv->CallBooleanMethod(
- contactSourceServiceObject,
- contactSourceServiceMethodIdUpdated,
- iUnknown);
-
- contactSourceServiceVM->DetachCurrentThread();
-}
-
-/**
- * Calls back the java side when a contact is deleted.
- *
- * @param iUnknown The string representation of the entry id of the deleted
- * contact.
- */
-void callDeletedCallbackMethod(
- LPSTR iUnknown)
-{
- JNIEnv *tmpJniEnv = contactSourceServiceJniEnv;
-
- if(contactSourceServiceVM->GetEnv(
- (void**) &tmpJniEnv,
- JNI_VERSION_1_6)
- != JNI_OK)
- {
- contactSourceServiceVM->AttachCurrentThread((void**) &tmpJniEnv, NULL);
- }
-
- jstring value;
- value = tmpJniEnv->NewStringUTF(iUnknown);
-
-
- tmpJniEnv->CallBooleanMethod(
- contactSourceServiceObject,
- contactSourceServiceMethodIdDeleted,
- value);
-
- contactSourceServiceVM->DetachCurrentThread();
-}
+typedef BOOL (STDAPICALLTYPE *LPFBINFROMHEX)(LPTSTR, LPBYTE);
+typedef void (STDAPICALLTYPE *LPFREEPROWS)(LPSRowSet);
+typedef void (STDAPICALLTYPE *LPHEXFROMBIN)(LPBYTE, int, LPTSTR);
+typedef HRESULT (STDAPICALLTYPE *LPHRALLOCADVISESINK)(LPNOTIFCALLBACK, LPVOID, LPMAPIADVISESINK FAR *);
+typedef HRESULT (STDAPICALLTYPE *LPHRQUERYALLROWS)(LPMAPITABLE, LPSPropTagArray, LPSRestriction, LPSSortOrderSet, LONG, LPSRowSet FAR *);
+static LPFBINFROMHEX MsOutlookAddrBookContactSourceService_fBinFromHex;
+static LPFREEPROWS MsOutlookAddrBookContactSourceService_freeProws;
+static LPHEXFROMBIN MsOutlookAddrBookContactSourceService_hexFromBin;
+static LPHRALLOCADVISESINK MsOutlookAddrBookContactSourceService_hrAllocAdviseSink;
+static LPHRQUERYALLROWS MsOutlookAddrBookContactSourceService_hrQueryAllRows;
static LPMAPIALLOCATEBUFFER
MsOutlookAddrBookContactSourceService_mapiAllocateBuffer;
static LPMAPIFREEBUFFER MsOutlookAddrBookContactSourceService_mapiFreeBuffer;
@@ -144,21 +35,8 @@ static LPMAPIINITIALIZE MsOutlookAddrBookContactSourceService_mapiInitialize;
static LPMAPILOGONEX MsOutlookAddrBookContactSourceService_mapiLogonEx;
static LPMAPIUNINITIALIZE
MsOutlookAddrBookContactSourceService_mapiUninitialize;
-
-typedef void (STDAPICALLTYPE *LPHEXFROMBIN)(LPBYTE, int, LPTSTR);
-typedef HRESULT (STDAPICALLTYPE *LPHRALLOCADVISESINK)(LPNOTIFCALLBACK, LPVOID, LPMAPIADVISESINK FAR *);
-typedef BOOL (STDAPICALLTYPE *LPFBINFROMHEX)(LPTSTR, LPBYTE);
-typedef HRESULT (STDAPICALLTYPE *LPHRQUERYALLROWS)(LPMAPITABLE, LPSPropTagArray, LPSRestriction, LPSSortOrderSet, LONG, LPSRowSet FAR *);
-typedef void (STDAPICALLTYPE *LPFREEPROWS)(LPSRowSet);
-
-static LPHEXFROMBIN MsOutlookAddrBookContactSourceService_hexFromBin;
-static LPHRALLOCADVISESINK MsOutlookAddrBookContactSourceService_HrAllocAdviseSink;
-static LPFBINFROMHEX MsOutlookAddrBookContactSourceService_FBinFromHex;
-static LPHRQUERYALLROWS MsOutlookAddrBookContactSourceService_HrQueryAllRows;
-static LPFREEPROWS MsOutlookAddrBookContactSourceService_FreeProws;
-
-static LPMAPISESSION MsOutlookAddrBookContactSourceService_mapiSession = NULL;
-static CRITICAL_SECTION MsOutlookAddrBookContactSourceService_mapiSessionCriticalSection;
+static CRITICAL_SECTION
+ MsOutlookAddrBookContactSourceService_mapiSessionCriticalSection;
static jboolean
MsOutlookAddrBookContactSourceService_isValidDefaultMailClient
@@ -166,7 +44,8 @@ MsOutlookAddrBookContactSourceService_isValidDefaultMailClient
JNIEXPORT void JNICALL
Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService_MAPIInitialize
- (JNIEnv *jniEnv, jclass clazz, jlong version, jlong flags)
+ (JNIEnv *jniEnv, jclass clazz, jlong version, jlong flags,
+ jobject notificationsDelegate)
{
HKEY regKey;
HRESULT hResult = MAPI_E_NO_SUPPORT;
@@ -416,9 +295,31 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
{
MAPIINIT_0 mapiInit = { (ULONG) version, (ULONG) flags };
- hResult
- = MsOutlookAddrBookContactSourceService_mapiInitialize(
- &mapiInit);
+ DWORD dwSize = ::GetCurrentDirectory(0, NULL);
+ if (dwSize > 0)
+ {
+ LPTSTR lpszWorkingDir
+ = (LPTSTR)::malloc(dwSize*sizeof(TCHAR));
+ DWORD dwResult
+ = ::GetCurrentDirectory(dwSize, lpszWorkingDir);
+ if (dwResult != 0)
+ {
+ hResult
+ = MsOutlookAddrBookContactSourceService_mapiInitialize(
+ &mapiInit);
+ ::SetCurrentDirectory(lpszWorkingDir);
+ }
+ else
+ {
+ hResult = HRESULT_FROM_WIN32(::GetLastError());
+ }
+ ::free(lpszWorkingDir);
+ }
+ else
+ {
+ hResult = HRESULT_FROM_WIN32(::GetLastError());
+ }
+
if (HR_SUCCEEDED(hResult))
{
MsOutlookAddrBookContactSourceService_mapiAllocateBuffer
@@ -430,18 +331,18 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
MsOutlookAddrBookContactSourceService_mapiLogonEx
= (LPMAPILOGONEX) GetProcAddress(lib, "MAPILogonEx");
+ MsOutlookAddrBookContactSourceService_fBinFromHex
+ = (LPFBINFROMHEX) GetProcAddress(lib, "FBinFromHex@8");
+ MsOutlookAddrBookContactSourceService_freeProws
+ = (LPFREEPROWS) GetProcAddress(lib, "FreeProws@4");
MsOutlookAddrBookContactSourceService_hexFromBin
= (LPHEXFROMBIN) GetProcAddress(lib, "HexFromBin@12");
- MsOutlookAddrBookContactSourceService_HrAllocAdviseSink
+ MsOutlookAddrBookContactSourceService_hrAllocAdviseSink
= (LPHRALLOCADVISESINK)
GetProcAddress(lib, "HrAllocAdviseSink@12");
- MsOutlookAddrBookContactSourceService_FBinFromHex
- = (LPFBINFROMHEX) GetProcAddress(lib, "FBinFromHex@8");
- MsOutlookAddrBookContactSourceService_HrQueryAllRows
+ MsOutlookAddrBookContactSourceService_hrQueryAllRows
= (LPHRQUERYALLROWS)
GetProcAddress(lib, "HrQueryAllRows@24");
- MsOutlookAddrBookContactSourceService_FreeProws
- = (LPFREEPROWS) GetProcAddress(lib, "FreeProws@4");
InitializeCriticalSection(
&MsOutlookAddrBookContactSourceService_mapiSessionCriticalSection);
@@ -450,11 +351,13 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
&& MsOutlookAddrBookContactSourceService_mapiFreeBuffer
&& MsOutlookAddrBookContactSourceService_mapiLogonEx
+
+ && MsOutlookAddrBookContactSourceService_fBinFromHex
+ && MsOutlookAddrBookContactSourceService_freeProws
&& MsOutlookAddrBookContactSourceService_hexFromBin
- && MsOutlookAddrBookContactSourceService_HrAllocAdviseSink
- && MsOutlookAddrBookContactSourceService_FBinFromHex
- && MsOutlookAddrBookContactSourceService_HrQueryAllRows
- && MsOutlookAddrBookContactSourceService_FreeProws)
+ && MsOutlookAddrBookContactSourceService_hrAllocAdviseSink
+ &&
+ MsOutlookAddrBookContactSourceService_hrQueryAllRows)
{
hResult = S_OK;
}
@@ -470,17 +373,19 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
}
}
- if (HR_SUCCEEDED(hResult)
- && MsOutlookAddrBookContactSourceService_mapiSession == NULL)
+ if(HR_SUCCEEDED(hResult) && MAPISession_getMapiSession() == NULL)
{
+ LPMAPISESSION mapiSession = NULL;
hResult
= MsOutlookAddrBook_mapiLogonEx(
0,
NULL, NULL,
MAPI_EXTENDED | MAPI_NO_MAIL | MAPI_USE_DEFAULT,
- &MsOutlookAddrBookContactSourceService_mapiSession);
- openAllMsgStores(
- MsOutlookAddrBookContactSourceService_mapiSession);
+ &mapiSession);
+ MAPINotification_registerNotificationsDelegate(
+ jniEnv,
+ mapiSession,
+ notificationsDelegate);
}
/* Report any possible error regardless of where it has come from. */
@@ -499,12 +404,13 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
{
EnterCriticalSection(
&MsOutlookAddrBookContactSourceService_mapiSessionCriticalSection);
- if (MsOutlookAddrBookContactSourceService_mapiSession)
+ LPMAPISESSION mapiSession = MAPISession_getMapiSession();
+ if(mapiSession != NULL)
{
- freeAllMsgStores();
- MsOutlookAddrBookContactSourceService_mapiSession->Logoff(0, 0, 0);
- MsOutlookAddrBookContactSourceService_mapiSession->Release();
- MsOutlookAddrBookContactSourceService_mapiSession = NULL;
+ MAPINotification_unregisterNotificationsDelegate(jniEnv);
+ mapiSession->Logoff(0, 0, 0);
+ mapiSession->Release();
+ mapiSession = NULL;
}
LeaveCriticalSection(
&MsOutlookAddrBookContactSourceService_mapiSessionCriticalSection);
@@ -515,6 +421,47 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
&MsOutlookAddrBookContactSourceService_mapiSessionCriticalSection);
}
+WINBOOL MsOutlookAddrBook_fBinFromHex(LPTSTR lpsz, LPBYTE lpb)
+{
+ return MsOutlookAddrBookContactSourceService_fBinFromHex(lpsz, lpb);
+}
+
+void MsOutlookAddrBook_freeProws(LPSRowSet lpRows)
+{
+ MsOutlookAddrBookContactSourceService_freeProws(lpRows);
+}
+
+void MsOutlookAddrBook_hexFromBin(LPBYTE pb, int cb, LPTSTR sz)
+{
+ return MsOutlookAddrBookContactSourceService_hexFromBin(pb, cb, sz);
+}
+
+void
+MsOutlookAddrBook_hrAllocAdviseSink
+ (LPNOTIFCALLBACK lpfnCallback, LPVOID lpvContext, LPMAPIADVISESINK*
+ lppAdviseSink)
+{
+ MsOutlookAddrBookContactSourceService_hrAllocAdviseSink(
+ lpfnCallback,
+ lpvContext,
+ lppAdviseSink);
+}
+
+HRESULT
+MsOutlookAddrBook_hrQueryAllRows
+ (LPMAPITABLE lpTable, LPSPropTagArray lpPropTags,
+ LPSRestriction lpRestriction, LPSSortOrderSet lpSortOrderSet,
+ LONG crowsMax, LPSRowSet* lppRows)
+{
+ return MsOutlookAddrBookContactSourceService_hrQueryAllRows(
+ lpTable,
+ lpPropTags,
+ lpRestriction,
+ lpSortOrderSet,
+ crowsMax,
+ lppRows);
+}
+
SCODE
MsOutlookAddrBook_mapiAllocateBuffer(ULONG size, LPVOID FAR *buffer)
{
@@ -539,25 +486,52 @@ MsOutlookAddrBook_mapiLogonEx
EnterCriticalSection(
&MsOutlookAddrBookContactSourceService_mapiSessionCriticalSection);
- if (MsOutlookAddrBookContactSourceService_mapiSession)
+ LPMAPISESSION currentMapiSession = MAPISession_getMapiSession();
+ if (currentMapiSession != NULL)
hResult = S_OK;
else
{
- hResult
- = MsOutlookAddrBookContactSourceService_mapiLogonEx(
- uiParam,
- profileName, password,
- flags,
- &MsOutlookAddrBookContactSourceService_mapiSession);
+ DWORD dwSize = ::GetCurrentDirectory(0, NULL);
+ if (dwSize > 0)
+ {
+ LPTSTR lpszWorkingDir = (LPTSTR)::malloc(dwSize*sizeof(TCHAR));
+ DWORD dwResult = ::GetCurrentDirectory(dwSize, lpszWorkingDir);
+ if (dwResult != 0)
+ {
+ hResult
+ = MsOutlookAddrBookContactSourceService_mapiLogonEx(
+ uiParam,
+ profileName, password,
+ flags,
+ &currentMapiSession);
+ ::SetCurrentDirectory(lpszWorkingDir);
+
+ MAPISession_setMapiSession(currentMapiSession);
+ }
+ else
+ {
+ hResult = HRESULT_FROM_WIN32(::GetLastError());
+ }
+
+ ::free(lpszWorkingDir);
+ }
+ else
+ {
+ hResult = HRESULT_FROM_WIN32(::GetLastError());
+ }
+
+
+
}
if (HR_SUCCEEDED(hResult))
- *mapiSession = MsOutlookAddrBookContactSourceService_mapiSession;
+ *mapiSession = currentMapiSession;
LeaveCriticalSection(
&MsOutlookAddrBookContactSourceService_mapiSessionCriticalSection);
return hResult;
}
+
static jboolean
MsOutlookAddrBookContactSourceService_isValidDefaultMailClient
(LPCTSTR name, DWORD nameLength)
@@ -595,51 +569,3 @@ MsOutlookAddrBookContactSourceService_isValidDefaultMailClient
}
return validDefaultMailClient;
}
-
-LPMAPISESSION MsOutlookAddrBookContactSourceService_getMapiSession()
-{
- return MsOutlookAddrBookContactSourceService_mapiSession;
-}
-
-void MsOutlookAddrBookContact_hexFromBin(LPBYTE pb, int cb, LPTSTR sz)
-{
- return MsOutlookAddrBookContactSourceService_hexFromBin(pb, cb, sz);
-}
-
-void MsOutlookAddrBookContact_HrAllocAdviseSink(
- LPNOTIFCALLBACK lpfnCallback,
- LPVOID lpvContext,
- LPMAPIADVISESINK* lppAdviseSink)
-{
- MsOutlookAddrBookContactSourceService_HrAllocAdviseSink(
- lpfnCallback,
- lpvContext,
- lppAdviseSink);
-}
-
-WINBOOL MsOutlookAddrBookContact_FBinFromHex(LPTSTR lpsz, LPBYTE lpb)
-{
- return MsOutlookAddrBookContactSourceService_FBinFromHex(lpsz, lpb);
-}
-
-HRESULT MsOutlookAddrBookContact_HrQueryAllRows(
- LPMAPITABLE lpTable,
- LPSPropTagArray lpPropTags,
- LPSRestriction lpRestriction,
- LPSSortOrderSet lpSortOrderSet,
- LONG crowsMax,
- LPSRowSet* lppRows)
-{
- return MsOutlookAddrBookContactSourceService_HrQueryAllRows(
- lpTable,
- lpPropTags,
- lpRestriction,
- lpSortOrderSet,
- crowsMax,
- lppRows);
-}
-
-void MsOutlookAddrBookContact_FreeProws(LPSRowSet lpRows)
-{
- MsOutlookAddrBookContactSourceService_FreeProws(lpRows);
-}
diff --git a/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.h b/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.h
index c93b7fb..3eea7b0 100644
--- a/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.h
+++ b/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.h
@@ -9,9 +9,6 @@ extern "C" {
#endif
#include "MsOutlookMAPI.h"
-#include <mapidefs.h>
-#include <mapix.h>
-#include <unknwn.h>
/*
* Class: net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService
@@ -19,7 +16,7 @@ extern "C" {
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService_MAPIInitialize
- (JNIEnv *, jclass, jlong, jlong);
+ (JNIEnv *, jclass, jlong, jlong, jobject);
/*
* Class: net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService
@@ -29,40 +26,6 @@ JNIEXPORT void JNICALL Java_net_java_sip_communicator_plugin_addrbook_msoutlook_
JNIEXPORT void JNICALL Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService_MAPIUninitialize
(JNIEnv *, jclass);
-JNIEXPORT void JNICALL
-Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService_setDelegate
- (JNIEnv *jniEnv, jclass clazz, jobject callback);
-
-void callInsertedCallbackMethod(
- LPUNKNOWN iUnknown);
-
-void callUpdatedCallbackMethod(
- LPUNKNOWN iUnknown);
-
-void callDeletedCallbackMethod(
- LPSTR iUnknown);
-
-LPMAPISESSION MsOutlookAddrBookContactSourceService_getMapiSession();
-
-void MsOutlookAddrBookContact_hexFromBin(LPBYTE pb, int cb, LPTSTR sz);
-
-void MsOutlookAddrBookContact_HrAllocAdviseSink(
- LPNOTIFCALLBACK lpfnCallback,
- LPVOID lpvContext,
- LPMAPIADVISESINK* lppAdviseSink);
-
-WINBOOL MsOutlookAddrBookContact_FBinFromHex( LPTSTR lpsz, LPBYTE lpb);
-
-HRESULT MsOutlookAddrBookContact_HrQueryAllRows(
- LPMAPITABLE lpTable,
- LPSPropTagArray lpPropTags,
- LPSRestriction lpRestriction,
- LPSSortOrderSet lpSortOrderSet,
- LONG crowsMax,
- LPSRowSet* lppRows);
-
-void MsOutlookAddrBookContact_FreeProws(LPSRowSet lpRows);
-
#ifdef __cplusplus
}
#endif
diff --git a/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactSourceService.java b/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactSourceService.java
index 3e2a520..cc6abe1 100644
--- a/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactSourceService.java
+++ b/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactSourceService.java
@@ -86,9 +86,10 @@ public class MsOutlookAddrBookContactSourceService
public MsOutlookAddrBookContactSourceService()
throws MsOutlookMAPIHResultException
{
- MAPIInitialize(MAPI_INIT_VERSION, MAPI_MULTITHREAD_NOTIFICATIONS);
-
- setDelegate(new NotificationsDelegate());
+ MAPIInitialize(
+ MAPI_INIT_VERSION,
+ MAPI_MULTITHREAD_NOTIFICATIONS,
+ new NotificationsDelegate());
}
/**
@@ -117,7 +118,10 @@ public class MsOutlookAddrBookContactSourceService
return SEARCH_TYPE;
}
- private static native void MAPIInitialize(long version, long flags)
+ private static native void MAPIInitialize(
+ long version,
+ long flags,
+ NotificationsDelegate callback)
throws MsOutlookMAPIHResultException;
private static native void MAPIUninitialize();
@@ -215,7 +219,4 @@ public class MsOutlookAddrBookContactSourceService
latestQuery.deleted(id);
}
}
-
- public static native void setDelegate(
- NotificationsDelegate callback);
}