aboutsummaryrefslogtreecommitdiffstats
path: root/src/native
diff options
context:
space:
mode:
Diffstat (limited to 'src/native')
-rw-r--r--src/native/addrbook/AddrBookContactQuery.c56
-rw-r--r--src/native/addrbook/AddrBookContactQuery.h24
-rw-r--r--src/native/addrbook/macosx/Makefile16
-rw-r--r--src/native/addrbook/macosx/net_java_sip_communicator_plugin_addrbook_macosx_MacOSXAddrBookContactQuery.m132
-rw-r--r--src/native/addrbook/msoutlook/Makefile7
-rw-r--r--src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.cpp37
6 files changed, 233 insertions, 39 deletions
diff --git a/src/native/addrbook/AddrBookContactQuery.c b/src/native/addrbook/AddrBookContactQuery.c
new file mode 100644
index 0000000..45cdcd2
--- /dev/null
+++ b/src/native/addrbook/AddrBookContactQuery.c
@@ -0,0 +1,56 @@
+/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+#include "AddrBookContactQuery.h"
+
+static void Exception_throwNew
+ (JNIEnv *jniEnv, const char *className, const char *message);
+
+jmethodID
+AddrBookContactQuery_getPtrCallbackMethodID(JNIEnv *jniEnv, jobject callback)
+{
+ jclass callbackClass;
+ jmethodID callbackMethodID = 0;
+
+ /*
+ * Make sure that the specified arguments are valid. For example, check
+ * whether callback exists and has the necessary signature.
+ */
+ if (callback)
+ {
+ callbackClass = (*jniEnv)->GetObjectClass(jniEnv, callback);
+ if (callbackClass)
+ {
+ callbackMethodID
+ = (*jniEnv)->GetMethodID(
+ jniEnv,
+ callbackClass, "callback", "(J)Z");
+ if (!callbackMethodID)
+ {
+ Exception_throwNew(
+ jniEnv, "java/lang/IllegalArgumentException", "callback");
+ }
+ }
+ }
+ else
+ {
+ Exception_throwNew(
+ jniEnv, "java/lang/NullPointerException", "callback");
+ }
+ return callbackMethodID;
+}
+
+static void
+Exception_throwNew(JNIEnv *jniEnv, const char *className, const char *message)
+{
+ jclass clazz;
+
+ clazz = (*jniEnv)->FindClass(jniEnv, className);
+ if (clazz)
+ (*jniEnv)->ThrowNew(jniEnv, clazz, message);
+}
+
diff --git a/src/native/addrbook/AddrBookContactQuery.h b/src/native/addrbook/AddrBookContactQuery.h
new file mode 100644
index 0000000..fbd62bc
--- /dev/null
+++ b/src/native/addrbook/AddrBookContactQuery.h
@@ -0,0 +1,24 @@
+/*
+ * SIP Communicator, 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_ADDRBOOKCONTACTQUERY_H_
+#define _NET_JAVA_SIP_COMMUNICATOR_PLUGIN_ADDRBOOK_ADDRBOOKCONTACTQUERY_H_
+
+#include <jni.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* #ifdef __cplusplus */
+
+jmethodID AddrBookContactQuery_getPtrCallbackMethodID
+ (JNIEnv *jniEnv, jobject callback);
+
+#ifdef __cplusplus
+}
+#endif /* #ifdef __cplusplus */
+
+#endif /* #ifndef _NET_JAVA_SIP_COMMUNICATOR_PLUGIN_ADDRBOOK_ADDRBOOKCONTACTQUERY_H_ */
diff --git a/src/native/addrbook/macosx/Makefile b/src/native/addrbook/macosx/Makefile
new file mode 100644
index 0000000..6b71ff5
--- /dev/null
+++ b/src/native/addrbook/macosx/Makefile
@@ -0,0 +1,16 @@
+CC = cc -O2
+TARGET_BASENAME = jmacosxaddrbook
+
+JAVA_HOME = /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/JavaVM.framework/Versions/1.5
+
+CC := $(CC) -arch i386 -arch ppc -arch x86_64 -mmacosx-version-min=10.4
+CPPFLAGS = -Wall -Wreturn-type -DJNI_IMPLEMENTATION -I$(JAVA_HOME)/Headers -I..
+LDFLAGS = -dynamiclib
+LIBS = -framework AddressBook -framework Foundation
+TARGET = ../../../../lib/native/mac/lib$(TARGET_BASENAME).jnilib
+
+$(TARGET): \
+ ../AddrBookContactQuery.c \
+ net_java_sip_communicator_plugin_addrbook_macosx_MacOSXAddrBookContactQuery.m
+ $(CC) $(CPPFLAGS) $^ $(LDFLAGS) -o $@ $(LIBS)
+ -strip $(TARGET)
diff --git a/src/native/addrbook/macosx/net_java_sip_communicator_plugin_addrbook_macosx_MacOSXAddrBookContactQuery.m b/src/native/addrbook/macosx/net_java_sip_communicator_plugin_addrbook_macosx_MacOSXAddrBookContactQuery.m
index 358e7a8..23a2e50 100644
--- a/src/native/addrbook/macosx/net_java_sip_communicator_plugin_addrbook_macosx_MacOSXAddrBookContactQuery.m
+++ b/src/native/addrbook/macosx/net_java_sip_communicator_plugin_addrbook_macosx_MacOSXAddrBookContactQuery.m
@@ -7,21 +7,98 @@
#include "net_java_sip_communicator_plugin_addrbook_macosx_MacOSXAddrBookContactQuery.h"
+#include "AddrBookContactQuery.h"
+
#import <AddressBook/AddressBook.h>
+#import <Foundation/NSArray.h>
+#import <Foundation/NSAutoreleasePool.h>
+
+static void MacOSXAddrBookContactQuery_idToJObject
+ (JNIEnv *jniEnv, id o, jobjectArray jos, jint i, jclass objectClass);
JNIEXPORT jobjectArray JNICALL
Java_net_java_sip_communicator_plugin_addrbook_macosx_MacOSXAddrBookContactQuery_ABRecord_1valuesForProperties
(JNIEnv *jniEnv, jclass clazz, jlong record, jlongArray properties)
{
- /* TODO Auto-generated method stub */
- return NULL;
+ jsize propertyCount;
+ jobjectArray values = NULL;
+
+ propertyCount = (*jniEnv)->GetArrayLength(jniEnv, properties);
+ if (propertyCount)
+ {
+ jclass objectClass;
+
+ objectClass = (*jniEnv)->FindClass(jniEnv, "java/lang/Object");
+ if (objectClass)
+ {
+ values
+ = (*jniEnv)->NewObjectArray(
+ jniEnv,
+ propertyCount, objectClass, NULL);
+ if (values)
+ {
+ jint i;
+ ABRecord *r = (ABRecord *) record;
+
+ for (i = 0; i < propertyCount; i++)
+ {
+ jlong property;
+
+ (*jniEnv)->GetLongArrayRegion(
+ jniEnv,
+ properties, i, 1, &property);
+ MacOSXAddrBookContactQuery_idToJObject(
+ jniEnv,
+ [r valueForProperty:(NSString *)property],
+ values, i,
+ objectClass);
+ if (JNI_TRUE == (*jniEnv)->ExceptionCheck(jniEnv))
+ break;
+ }
+ }
+ }
+ }
+ return values;
}
JNIEXPORT void JNICALL
Java_net_java_sip_communicator_plugin_addrbook_macosx_MacOSXAddrBookContactQuery_foreachPerson
(JNIEnv *jniEnv, jclass clazz, jstring query, jobject callback)
{
- /* TODO Auto-generated method stub */
+ jmethodID callbackMethodID;
+ NSAutoreleasePool *autoreleasePool;
+ ABAddressBook *addressBook;
+ NSArray *people;
+ NSUInteger peopleCount;
+ NSUInteger i;
+
+ callbackMethodID
+ = AddrBookContactQuery_getPtrCallbackMethodID(jniEnv, callback);
+ if (!callbackMethodID || (JNI_TRUE == (*jniEnv)->ExceptionCheck(jniEnv)))
+ return;
+
+ autoreleasePool = [[NSAutoreleasePool alloc] init];
+
+ addressBook = [ABAddressBook addressBook];
+ people = [addressBook people];
+ peopleCount = [people count];
+ for (i = 0; i < peopleCount; i++)
+ {
+ jboolean proceed;
+ ABPerson *person = [people objectAtIndex:i];
+
+ proceed
+ = (*jniEnv)->CallBooleanMethod(
+ jniEnv,
+ callback, callbackMethodID,
+ person);
+ if ((JNI_FALSE == proceed)
+ || (JNI_TRUE == (*jniEnv)->ExceptionCheck(jniEnv)))
+ break;
+ }
+ [addressBook release];
+
+ [autoreleasePool release];
}
#define DEFINE_ABPERSON_PROPERTY_GETTER(property) \
@@ -46,3 +123,52 @@ DEFINE_ABPERSON_PROPERTY_GETTER(kABMSNInstantProperty)
DEFINE_ABPERSON_PROPERTY_GETTER(kABNicknameProperty)
DEFINE_ABPERSON_PROPERTY_GETTER(kABPhoneProperty)
DEFINE_ABPERSON_PROPERTY_GETTER(kABYahooInstantProperty)
+
+static void
+MacOSXAddrBookContactQuery_idToJObject
+ (JNIEnv *jniEnv,
+ id o,
+ jobjectArray jos, jint i,
+ jclass objectClass)
+{
+ if (o)
+ {
+ jobject jo;
+
+ if ([o isKindOfClass:[NSString class]])
+ {
+ jo = (*jniEnv)->NewStringUTF(jniEnv, [((NSString *) o) UTF8String]);
+ }
+ else if ([o isKindOfClass:[ABMultiValue class]])
+ {
+ ABMultiValue *mv = (ABMultiValue *) o;
+ NSUInteger mvCount = [mv count];
+ jobjectArray joArray
+ = (*jniEnv)->NewObjectArray(jniEnv, mvCount, objectClass, NULL);
+
+ jo = joArray;
+ if (joArray)
+ {
+ NSUInteger j;
+
+ for (j = 0; j < mvCount; j++)
+ {
+ MacOSXAddrBookContactQuery_idToJObject(
+ jniEnv,
+ [mv valueAtIndex:j],
+ joArray, j,
+ objectClass);
+ if (JNI_TRUE == (*jniEnv)->ExceptionCheck(jniEnv))
+ {
+ jo = NULL;
+ break;
+ }
+ }
+ }
+ }
+ else
+ jo = NULL;
+ if (jo)
+ (*jniEnv)->SetObjectArrayElement(jniEnv, jos, i, jo);
+ }
+}
diff --git a/src/native/addrbook/msoutlook/Makefile b/src/native/addrbook/msoutlook/Makefile
index 32d05f7..53e108c 100644
--- a/src/native/addrbook/msoutlook/Makefile
+++ b/src/native/addrbook/msoutlook/Makefile
@@ -1,6 +1,6 @@
CXX = c++ -O2
OUTLOOK_MAPI_HEADERS ?= /c/Users/lyubomir/Downloads/Outlook2010MAPIHeaders
-TARGET_BASENAME = jmsoutlook.dll
+TARGET_BASENAME = jmsoutlookaddrbook
ARCH = $(shell $(CXX) -dumpmachine | sed -e s/x86_64-.*/-64/ -e s/i.86-.*//)
ifeq "$(ARCH)" "-64"
@@ -9,12 +9,13 @@ else
JAVA_HOME ?= C:/PROGRA~2/jdk
endif
-CPPFLAGS = -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/win32 -I$(OUTLOOK_MAPI_HEADERS)
+CPPFLAGS = -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/win32 -I$(OUTLOOK_MAPI_HEADERS) -I..
LDFLAGS = -shared -Wl,--kill-at
LIBS = -lmapi32
-TARGET = ../../../../lib/native/windows$(ARCH)/jmsoutlookaddrbook.dll
+TARGET = ../../../../lib/native/windows$(ARCH)/$(TARGET_BASENAME).dll
$(TARGET): \
+ ../AddrBookContactQuery.c
MsOutlookMAPIHResultException.cpp \
net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.cpp \
net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.c
diff --git a/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.cpp b/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.cpp
index 033d297..f238e19 100644
--- a/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.cpp
+++ b/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.cpp
@@ -7,6 +7,7 @@
#include "net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.h"
+#include "AddrBookContactQuery.h"
#include "MsOutlookMAPI.h"
#include "MsOutlookMAPIHResultException.h"
@@ -15,9 +16,6 @@
#define WIND32_MEAN_AND_LEAK
#include <windows.h>
-static void Exception_throwNew
- (JNIEnv *jniEnv, const char *className, const char *message);
-
static jboolean MsOutlookAddrBookContactQuery_foreachMailUser
(ULONG objType, LPUNKNOWN iUnknown,
JNIEnv *jniEnv,
@@ -32,46 +30,19 @@ static void MsOutlookAddrBookContactQuery_freeSRowSet(LPSRowSet rows);
static jboolean MsOutlookAddrBookContactQuery_mailUserMatches
(LPMAPIPROP mailUser, JNIEnv *jniEnv, jstring query);
-static void
-Exception_throwNew(JNIEnv *jniEnv, const char *className, const char *message)
-{
- jclass clazz;
-
- clazz = jniEnv->FindClass(className);
- if (clazz)
- jniEnv->ThrowNew(clazz, message);
-}
-
JNIEXPORT void JNICALL
Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery_foreachMailUser
(JNIEnv *jniEnv, jclass clazz, jstring query, jobject callback)
{
- jclass callbackClass;
jmethodID callbackMethodID;
HRESULT hResult;
LPMAPISESSION mapiSession;
- /*
- * Make sure that the specified arguments are valid. For example, check
- * whether callback exists and has the necessary signature.
- */
- if (!callback)
- {
- Exception_throwNew(
- jniEnv, "java/lang/NullPointerException", "callback");
- return;
- }
- callbackClass = jniEnv->GetObjectClass(callback);
- if (!callbackClass)
+ callbackMethodID
+ = AddrBookContactQuery_getPtrCallbackMethodID(jniEnv, callback);
+ if (!callbackMethodID || (JNI_TRUE == jniEnv->ExceptionCheck()))
return;
- callbackMethodID = jniEnv->GetMethodID(callbackClass, "callback", "(J)Z");
- if (!callbackMethodID)
- {
- Exception_throwNew(
- jniEnv, "java/lang/IllegalArgumentException", "callback");
- return;
- }
hResult
= MAPILogonEx(