Always uses the COM server to interoperate with Outlook and thus even if Jitsi

bitness is compatible with MAPI library.
cusax-fix
Vincent Lucas 13 years ago
parent 6035f9236c
commit 7850999c10

@ -18,26 +18,6 @@
* @author Vincent Lucas
*/
/**
* Returns the bitness of the current executable.
*
* @return 64 if the current executable is 64 bits. 32 otherwise.
*/
int MAPIBitness_getExecutableBitnessVersion(void)
{
char executable[FILENAME_MAX];
GetModuleFileName(NULL, executable, FILENAME_MAX);
DWORD type;
GetBinaryType(executable, &type);
if(type == SCS_64BIT_BINARY)
{
return 64;
}
return 32;
}
/**
* Returns the bitness of the Outlook installation.
*
@ -82,18 +62,3 @@ int MAPIBitness_getOutlookBitnessVersion(void)
return -1;
}
/**
* Tests if the bitness of the Outlook installation is identical to the current
* executable.
*
* Returns 1 if the bitness of the Outlook installation is identical to the
* current executable. 0 otherwise.
*/
int MAPIBitness_isOutlookBitnessCompatible(void)
{
int outlookVersion = MAPIBitness_getOutlookBitnessVersion();
int executableVersion = MAPIBitness_getExecutableBitnessVersion();
return (outlookVersion == executableVersion);
}

@ -14,8 +14,6 @@
* @author Vincent Lucas
*/
int MAPIBitness_getExecutableBitnessVersion(void);
int MAPIBitness_getOutlookBitnessVersion(void);
int MAPIBitness_isOutlookBitnessCompatible(void);
#endif

@ -440,12 +440,11 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
}
/**
* Starts the COM server if the bitness of Jitsi is different from the Outlook
* one (mapi32.dll).
* Starts the COM server.
*
* @return S_OK if eveything was fine. E_FAIL otherwise.
*/
HRESULT MsOutlookAddrBookContactSourceService_MAPIInitializeCOMServer()
HRESULT MsOutlookAddrBookContactSourceService_MAPIInitializeCOMServer(void)
{
HRESULT hr = E_FAIL;
@ -464,52 +463,54 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitializeCOMServer()
void MsOutlookAddrBookContactSourceService_MAPIUninitialize(void)
{
MAPISession_lock();
if(MAPIBitness_isOutlookBitnessCompatible())
{
LPMAPISESSION mapiSession = MAPISession_getMapiSession();
if(mapiSession != NULL)
{
MAPINotification_unregisterNotifyAllMsgStores();
mapiSession->Logoff(0, 0, 0);
mapiSession->Release();
MAPISession_setMapiSession(NULL);
}
if(MsOutlookAddrBookContactSourceService_hMapiLib)
{
MsOutlookAddrBookContactSourceService_mapiUninitialize();
MsOutlookAddrBookContactSourceService_mapiInitialize = NULL;
MsOutlookAddrBookContactSourceService_mapiUninitialize = NULL;
MsOutlookAddrBookContactSourceService_mapiAllocateBuffer = NULL;
MsOutlookAddrBookContactSourceService_mapiFreeBuffer = NULL;
MsOutlookAddrBookContactSourceService_mapiLogonEx = NULL;
MsOutlookAddrBookContactSourceService_fBinFromHex = NULL;
MsOutlookAddrBookContactSourceService_freeProws = NULL;
MsOutlookAddrBookContactSourceService_hexFromBin = NULL;
MsOutlookAddrBookContactSourceService_hrAllocAdviseSink = NULL;
MsOutlookAddrBookContactSourceService_hrQueryAllRows = NULL;
::FreeLibrary(MsOutlookAddrBookContactSourceService_hMapiLib);
MsOutlookAddrBookContactSourceService_hMapiLib = NULL;
}
}
else
LPMAPISESSION mapiSession = MAPISession_getMapiSession();
if(mapiSession != NULL)
{
if(MsOutlookAddrBookContactSourceService_comServerHandle != NULL)
{
TerminateProcess(
MsOutlookAddrBookContactSourceService_comServerHandle,
1);
MAPINotification_unregisterNotifyAllMsgStores();
mapiSession->Logoff(0, 0, 0);
mapiSession->Release();
MAPISession_setMapiSession(NULL);
}
CloseHandle(MsOutlookAddrBookContactSourceService_comServerHandle);
MsOutlookAddrBookContactSourceService_comServerHandle = NULL;
}
ComClient_stop();
if(MsOutlookAddrBookContactSourceService_hMapiLib)
{
MsOutlookAddrBookContactSourceService_mapiUninitialize();
MsOutlookAddrBookContactSourceService_mapiInitialize = NULL;
MsOutlookAddrBookContactSourceService_mapiUninitialize = NULL;
MsOutlookAddrBookContactSourceService_mapiAllocateBuffer = NULL;
MsOutlookAddrBookContactSourceService_mapiFreeBuffer = NULL;
MsOutlookAddrBookContactSourceService_mapiLogonEx = NULL;
MsOutlookAddrBookContactSourceService_fBinFromHex = NULL;
MsOutlookAddrBookContactSourceService_freeProws = NULL;
MsOutlookAddrBookContactSourceService_hexFromBin = NULL;
MsOutlookAddrBookContactSourceService_hrAllocAdviseSink = NULL;
MsOutlookAddrBookContactSourceService_hrQueryAllRows = NULL;
::FreeLibrary(MsOutlookAddrBookContactSourceService_hMapiLib);
MsOutlookAddrBookContactSourceService_hMapiLib = NULL;
}
MAPISession_unlock();
}
/**
* Stops the COM server.
*/
void MsOutlookAddrBookContactSourceService_MAPIUninitializeCOMServer(void)
{
if(MsOutlookAddrBookContactSourceService_comServerHandle != NULL)
{
TerminateProcess(
MsOutlookAddrBookContactSourceService_comServerHandle,
1);
CloseHandle(MsOutlookAddrBookContactSourceService_comServerHandle);
MsOutlookAddrBookContactSourceService_comServerHandle = NULL;
}
ComClient_stop();
}
/**
* Initializes the plugin but from the COM server point of view: natif side, no
* java available here.
@ -535,7 +536,7 @@ HRESULT MsOutlookAddrBookContactSourceService_NativeMAPIInitialize
return MsOutlookAddrBookContactSourceService_MAPIInitialize(version, flags);
}
void MsOutlookAddrBookContactSourceService_NativeMAPIUninitialize()
void MsOutlookAddrBookContactSourceService_NativeMAPIUninitialize(void)
{
MAPINotification_unregisterNativeNotificationsDelegate();
@ -588,7 +589,13 @@ MsOutlookAddrBookContactSourceService_isValidDefaultMailClient
HRESULT MsOutlookAddrBookContactSourceService_startComServer(void)
{
// Start COM service
char applicationName[] = "jmsoutlookaddrbookcomserver.exe";
char applicationName32[] = "jmsoutlookaddrbookcomserver32.exe";
char applicationName64[] = "jmsoutlookaddrbookcomserver64.exe";
char * applicationName = applicationName32;
if(MAPIBitness_getOutlookBitnessVersion() == 64)
{
applicationName = applicationName64;
}
int applicationNameLength = strlen(applicationName);
char currentDirectory[FILENAME_MAX - applicationNameLength - 8];
GetCurrentDirectory(

@ -47,14 +47,16 @@ HRESULT MsOutlookAddrBook_mapiLogonEx
HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
(jlong version, jlong flags);
HRESULT MsOutlookAddrBookContactSourceService_MAPIInitializeCOMServer();
HRESULT MsOutlookAddrBookContactSourceService_MAPIInitializeCOMServer(void);
void MsOutlookAddrBookContactSourceService_MAPIUninitialize(void);
void MsOutlookAddrBookContactSourceService_MAPIUninitializeCOMServer(void);
HRESULT MsOutlookAddrBookContactSourceService_NativeMAPIInitialize
(jlong version, jlong flags,
void * deletedMethod, void * insertedMethod, void * updatedMethod);
void MsOutlookAddrBookContactSourceService_NativeMAPIUninitialize();
void MsOutlookAddrBookContactSourceService_NativeMAPIUninitialize(void);
#endif

@ -31,22 +31,15 @@ JNIEXPORT jstring JNICALL Java_net_java_sip_communicator_plugin_addrbook_msoutlo
jstring value = NULL;
char* messageIdStr = NULL;
if(MAPIBitness_isOutlookBitnessCompatible())
IMsOutlookAddrBookServer * iServer = ComClient_getIServer();
if(iServer)
{
messageIdStr = MsOutlookAddrBookContactQuery_createContact();
}
else
{
IMsOutlookAddrBookServer * iServer = ComClient_getIServer();
if(iServer)
BSTR id;
iServer->createContact(&id);
if(id != NULL)
{
BSTR id;
iServer->createContact(&id);
if(id != NULL)
{
messageIdStr = StringUtils::WideCharToMultiByte(id);
SysFreeString(id);
}
messageIdStr = StringUtils::WideCharToMultiByte(id);
SysFreeString(id);
}
}
@ -75,24 +68,18 @@ JNIEXPORT jboolean JNICALL Java_net_java_sip_communicator_plugin_addrbook_msoutl
const char *nativeEntryId = jniEnv->GetStringUTFChars(id, NULL);
jboolean res = JNI_FALSE;
if(MAPIBitness_isOutlookBitnessCompatible())
IMsOutlookAddrBookServer * iServer = ComClient_getIServer();
if(iServer)
{
res = (MsOutlookAddrBookContactQuery_deleteContact(nativeEntryId) == 1);
}
else
{
IMsOutlookAddrBookServer * iServer = ComClient_getIServer();
if(iServer)
{
LPWSTR unicodeId = StringUtils::MultiByteToWideChar(nativeEntryId);
BSTR comId = SysAllocString(unicodeId);
LPWSTR unicodeId = StringUtils::MultiByteToWideChar(nativeEntryId);
BSTR comId = SysAllocString(unicodeId);
res = (iServer->deleteContact(comId) == S_OK);
res = (iServer->deleteContact(comId) == S_OK);
SysFreeString(comId);
free(unicodeId);
}
SysFreeString(comId);
free(unicodeId);
}
jniEnv->ReleaseStringUTFChars(id, nativeEntryId);
return res;
@ -107,25 +94,15 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
{
const char *nativeQuery = jniEnv->GetStringUTFChars(query, NULL);
if(MAPIBitness_isOutlookBitnessCompatible())
{
MsOutlookAddrBookContactQuery_foreachMailUser(
nativeQuery,
(void *) MAPINotification_callCallbackMethod,
(void *) callback);
}
else
IMsOutlookAddrBookServer * iServer = ComClient_getIServer();
if(iServer)
{
IMsOutlookAddrBookServer * iServer = ComClient_getIServer();
if(iServer)
{
LPWSTR unicodeQuery = StringUtils::MultiByteToWideChar(nativeQuery);
BSTR comQuery = SysAllocString(unicodeQuery);
LPWSTR unicodeQuery = StringUtils::MultiByteToWideChar(nativeQuery);
BSTR comQuery = SysAllocString(unicodeQuery);
iServer->foreachMailUser(comQuery);
SysFreeString(comQuery);
free(unicodeQuery);
}
iServer->foreachMailUser(comQuery);
SysFreeString(comQuery);
free(unicodeQuery);
}
jniEnv->ReleaseStringUTFChars(query, nativeQuery);
@ -149,25 +126,16 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
const char *nativeEntryId = jniEnv->GetStringUTFChars(entryId, NULL);
if(MAPIBitness_isOutlookBitnessCompatible())
{
res = (MsOutlookAddrBookContactQuery_IMAPIProp_1DeleteProp(
propId,
nativeEntryId) == 1);
}
else
IMsOutlookAddrBookServer * iServer = ComClient_getIServer();
if(iServer)
{
IMsOutlookAddrBookServer * iServer = ComClient_getIServer();
if(iServer)
{
LPWSTR unicodeId = StringUtils::MultiByteToWideChar(nativeEntryId);
BSTR comId = SysAllocString(unicodeId);
LPWSTR unicodeId = StringUtils::MultiByteToWideChar(nativeEntryId);
BSTR comId = SysAllocString(unicodeId);
res = (iServer->IMAPIProp_DeleteProp(propId, comId) == S_OK);
res = (iServer->IMAPIProp_DeleteProp(propId, comId) == S_OK);
SysFreeString(comId);
free(unicodeId);
}
SysFreeString(comId);
free(unicodeId);
}
jniEnv->ReleaseStringUTFChars(entryId, nativeEntryId);
@ -195,30 +163,22 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
const char *nativeEntryId = jniEnv->GetStringUTFChars(entryId, NULL);
const char *nativeValue = jniEnv->GetStringUTFChars(value, NULL);
if(MAPIBitness_isOutlookBitnessCompatible())
{
res = (MsOutlookAddrBookContactQuery_IMAPIProp_1SetPropString
(propId, nativeValue, nativeEntryId) == 1);
}
else
IMsOutlookAddrBookServer * iServer = ComClient_getIServer();
if(iServer)
{
IMsOutlookAddrBookServer * iServer = ComClient_getIServer();
if(iServer)
{
LPWSTR unicodeValue
= StringUtils::MultiByteToWideChar(nativeValue);
BSTR comValue = SysAllocString(unicodeValue);
LPWSTR unicodeId = StringUtils::MultiByteToWideChar(nativeEntryId);
BSTR comId = SysAllocString(unicodeId);
res = (iServer->IMAPIProp_SetPropString(propId, comValue, comId)
== S_OK);
SysFreeString(comId);
free(unicodeId);
SysFreeString(comValue);
free(unicodeValue);
}
LPWSTR unicodeValue
= StringUtils::MultiByteToWideChar(nativeValue);
BSTR comValue = SysAllocString(unicodeValue);
LPWSTR unicodeId = StringUtils::MultiByteToWideChar(nativeEntryId);
BSTR comId = SysAllocString(unicodeId);
res = (iServer->IMAPIProp_SetPropString(propId, comValue, comId)
== S_OK);
SysFreeString(comId);
free(unicodeId);
SysFreeString(comValue);
free(unicodeValue);
}
jniEnv->ReleaseStringUTFChars(entryId, nativeEntryId);
@ -267,78 +227,64 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
if((propsType = (char*) malloc(propIdCount * sizeof(char)))
!= NULL)
{
if(MAPIBitness_isOutlookBitnessCompatible())
IMsOutlookAddrBookServer * iServer = ComClient_getIServer();
if(iServer)
{
hr = MsOutlookAddrBookContactQuery_IMAPIProp_1GetProps(
nativeEntryId,
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,
nativePropIds,
comPropIds,
flags,
props,
&comProps,
&comPropsLength,
&comPropsType);
SafeArrayLock(comPropsType);
memcpy(
propsType,
comPropsType->pvData,
propIdCount * sizeof(char));
SafeArrayUnlock(comPropsType);
SafeArrayDestroy(comPropsType);
SafeArrayLock(comPropsLength);
memcpy(
propsLength,
propsType);
}
else
{
IMsOutlookAddrBookServer * iServer = ComClient_getIServer();
if(iServer)
comPropsLength->pvData,
propIdCount * sizeof(unsigned long));
SafeArrayUnlock(comPropsLength);
SafeArrayDestroy(comPropsLength);
SafeArrayLock(comProps);
byte * data = (byte*) comProps->pvData;
for(int j = 0; j < propIdCount; ++j)
{
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);
SafeArrayLock(comPropsType);
memcpy(
propsType,
comPropsType->pvData,
propIdCount * sizeof(char));
SafeArrayUnlock(comPropsType);
SafeArrayDestroy(comPropsType);
SafeArrayLock(comPropsLength);
memcpy(
propsLength,
comPropsLength->pvData,
propIdCount * sizeof(unsigned long));
SafeArrayUnlock(comPropsLength);
SafeArrayDestroy(comPropsLength);
SafeArrayLock(comProps);
byte * data = (byte*) comProps->pvData;
for(int j = 0; j < propIdCount; ++j)
if((props[j] = malloc(propsLength[j])) != NULL)
{
if((props[j] = malloc(propsLength[j])) != NULL)
{
memcpy(props[j], data, propsLength[j]);
data += propsLength[j];
}
memcpy(props[j], data, propsLength[j]);
data += propsLength[j];
}
SafeArrayUnlock(comProps);
SafeArrayDestroy(comProps);
SafeArrayDestroy(comPropIds);
SysFreeString(comEntryId);
free(unicodeEntryId);
}
SafeArrayUnlock(comProps);
SafeArrayDestroy(comProps);
SafeArrayDestroy(comPropIds);
SysFreeString(comEntryId);
free(unicodeEntryId);
}
if(HR_SUCCEEDED(hr))

@ -24,16 +24,7 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
jniEnv,
notificationsDelegate);
if(MAPIBitness_isOutlookBitnessCompatible())
{
hr = MsOutlookAddrBookContactSourceService_MAPIInitialize(
version,
flags);
}
else
{
hr = MsOutlookAddrBookContactSourceService_MAPIInitializeCOMServer();
}
hr = MsOutlookAddrBookContactSourceService_MAPIInitializeCOMServer();
if (HR_FAILED(hr))
{
@ -51,6 +42,6 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
{
MAPINotification_unregisterJniNotificationsDelegate(jniEnv);
MsOutlookAddrBookContactSourceService_MAPIUninitialize();
MsOutlookAddrBookContactSourceService_MAPIUninitializeCOMServer();
}

@ -879,6 +879,10 @@
<fileset dir="${src}/native/addrbook/msoutlook" includes="*.cxx" />
<fileset dir="${src}/native/addrbook/msoutlook/com/" includes="*.cxx" />
</cc>
<exec executable="strip">
<arg value="-x"/>
<arg value="${native_install_dir}/jmsoutlookaddrbook.dll"/>
</exec>
</target>
<!-- compile msoutlookaddrbookserver executable for Windows -->
@ -887,28 +891,49 @@
description="Build jmsoutlookaddrbookcomserver executable for Windows"
if="is.running.windows"
depends="init-native">
<fail message="Outlook2010MAPIHeaders not set!"
unless="Outlook2010MAPIHeaders" />
<exec executable="cp">
<arg value="${src}/native/addrbook/msoutlook/com/*.tlb"/>
<arg value="${native_install_dir}/"/>
</exec>
<fail message="Outlook2010MAPIHeaders not set!"
unless="Outlook2010MAPIHeaders" />
<cc
name="g++"
objdir="${obj}"
outfile="${native_install_dir}/jmsoutlookaddrbookcomserver">
outfile="${native_install_dir}/jmsoutlookaddrbookcomserver32">
<compilerarg value="-I${system.JAVA_HOME}/include" />
<compilerarg value="-I${system.JAVA_HOME}/include/win32" />
<compilerarg value="-I${Outlook2010MAPIHeaders}" />
<compilerarg value="-m32" if="cross_64" /> <!-- inverse cross compil /-->
<compilerarg value="-m64" if="cross_32" /> <!-- inverse cross compil /-->
<compilerarg value="-m32" />
<compilerarg value="-O2" />
<compilerarg value="-Wall" />
<linkerarg value="-ojmsoutlookaddrbookcomserver32.exe" />
<linkerarg value="-m32" />
<libset libs="uuid, ole32, oleaut32, msi, stdc++" />
<fileset dir="${src}/native/addrbook/msoutlook" includes="*.cxx" />
<fileset dir="${src}/native/addrbook/msoutlook/com" includes="*.cxx" />
<fileset dir="${src}/native/addrbook/msoutlook/com/server"
includes="*.cxx" />
</cc>
<exec executable="strip">
<arg value="-x"/>
<arg value="${native_install_dir}/jmsoutlookaddrbookcomserver32.exe"/>
</exec>
<cc
name="g++"
objdir="${obj}"
outfile="${native_install_dir}/jmsoutlookaddrbookcomserver64">
<compilerarg value="-I${system.JAVA_HOME}/include" />
<compilerarg value="-I${system.JAVA_HOME}/include/win32" />
<compilerarg value="-I${Outlook2010MAPIHeaders}" />
<compilerarg value="-m64" />
<compilerarg value="-O2" />
<compilerarg value="-Wall" />
<linkerarg value="-ojmsoutlookaddrbookcomserver.exe" />
<linkerarg value="-m32" if="cross_64" /> <!-- inverse cross compil /-->
<linkerarg value="-m64" if="cross_32" /> <!-- inverse cross compil /-->
<linkerarg value="-ojmsoutlookaddrbookcomserver64.exe" />
<linkerarg value="-m64" />
<libset libs="uuid, ole32, oleaut32, msi, stdc++" />
<fileset dir="${src}/native/addrbook/msoutlook" includes="*.cxx" />
@ -916,5 +941,9 @@
<fileset dir="${src}/native/addrbook/msoutlook/com/server"
includes="*.cxx" />
</cc>
<exec executable="strip">
<arg value="-x"/>
<arg value="${native_install_dir}/jmsoutlookaddrbookcomserver64.exe"/>
</exec>
</target>
</project>

Loading…
Cancel
Save