From 1426368d44039ac2883f7c49bc5a3114493b7330 Mon Sep 17 00:00:00 2001 From: Damian Minkov <damencho@jitsi.org> Date: Tue, 29 Jan 2013 12:40:22 +0000 Subject: Updates junbound after package update. --- lib/native/mac/libjunbound.jnilib | Bin 2938740 -> 49884 bytes src/native/libjunbound/make-linux.sh | 2 +- src/native/libjunbound/make-mac.sh | 6 +- src/native/libjunbound/src/Makefile.am | 2 +- ...t_java_sip_communicator_impl_dns_UnboundApi.cpp | 273 +++++++++++++++++++++ ...net_java_sip_communicator_impl_dns_UnboundApi.h | 94 +++++++ ...municator_impl_dns_UnboundApi_UnboundCallback.h | 13 + ...t_java_sip_communicator_util_dns_UnboundApi.cpp | 273 --------------------- ...net_java_sip_communicator_util_dns_UnboundApi.h | 94 ------- ...municator_util_dns_UnboundApi_UnboundCallback.h | 13 - 10 files changed, 385 insertions(+), 385 deletions(-) create mode 100644 src/native/libjunbound/src/net_java_sip_communicator_impl_dns_UnboundApi.cpp create mode 100644 src/native/libjunbound/src/net_java_sip_communicator_impl_dns_UnboundApi.h create mode 100644 src/native/libjunbound/src/net_java_sip_communicator_impl_dns_UnboundApi_UnboundCallback.h delete mode 100644 src/native/libjunbound/src/net_java_sip_communicator_util_dns_UnboundApi.cpp delete mode 100644 src/native/libjunbound/src/net_java_sip_communicator_util_dns_UnboundApi.h delete mode 100644 src/native/libjunbound/src/net_java_sip_communicator_util_dns_UnboundApi_UnboundCallback.h diff --git a/lib/native/mac/libjunbound.jnilib b/lib/native/mac/libjunbound.jnilib index 4ed848c..f31eedc 100644 Binary files a/lib/native/mac/libjunbound.jnilib and b/lib/native/mac/libjunbound.jnilib differ diff --git a/src/native/libjunbound/make-linux.sh b/src/native/libjunbound/make-linux.sh index 0da7ec9..20bb0d8 100644 --- a/src/native/libjunbound/make-linux.sh +++ b/src/native/libjunbound/make-linux.sh @@ -38,6 +38,6 @@ make make install cd $out -gcc $out/../../src/net_java_sip_communicator_util_dns_UnboundApi.cpp -fpic -shared -o libjunbound.so -I/usr/lib/jvm/java-6-openjdk/include -Wl,-Bstatic -L$prefix/lib -lunbound -lldns -I$prefix/include -Wl,-Bdynamic -lcrypto +gcc $out/../../src/net_java_sip_communicator_impl_dns_UnboundApi.cpp -fpic -shared -o libjunbound.so -I/usr/lib/jvm/java-6-openjdk/include -Wl,-Bstatic -L$prefix/lib -lunbound -lldns -I$prefix/include -Wl,-Bdynamic -lcrypto strip libjunbound.so diff --git a/src/native/libjunbound/make-mac.sh b/src/native/libjunbound/make-mac.sh index 1634c6e..ed0127a 100644 --- a/src/native/libjunbound/make-mac.sh +++ b/src/native/libjunbound/make-mac.sh @@ -11,7 +11,7 @@ prefix=$out/libs mkdir -p $out mkdir -p $prefix/lib -mkdir -p $prefix/include +#mkdir -p $prefix/include cd $out @@ -32,7 +32,7 @@ mv $ldns ldns mv $unbound unbound export MACOSX_DEPLOYMENT_TARGET=10.5 -export CC="/usr/bin/gcc -arch i386 -arch x86_64 -arch ppc -mmacosx-version-min=10.5" +export CC="/usr/bin/gcc -arch i386 -arch x86_64 -mmacosx-version-min=10.5" export CPP="/usr/bin/gcc -E" function build_arch { @@ -58,4 +58,4 @@ function build_lib { cp -r ${prefix}_all/include $prefix/ cd $out -g++ -mmacosx-version-min=10.4 -arch x86_64 -arch i386 -arch ppc $out/../../src/net_java_sip_communicator_util_dns_UnboundApi.cpp -fpic -shared -o $out/libjunbound.jnilib -I/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers -I${prefix}_all/include -L${prefix}_all/lib -lunbound -lldns -lcrypto +g++ -mmacosx-version-min=10.4 -arch x86_64 -arch i386 $out/../../src/net_java_sip_communicator_impl_dns_UnboundApi.cpp -fpic -shared -o $out/libjunbound.jnilib -I/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers -I${prefix}_all/include -L${prefix}_all/lib -lunbound -lldns -lcrypto diff --git a/src/native/libjunbound/src/Makefile.am b/src/native/libjunbound/src/Makefile.am index c3e4261..9cdbd7f 100644 --- a/src/native/libjunbound/src/Makefile.am +++ b/src/native/libjunbound/src/Makefile.am @@ -1,3 +1,3 @@ lib_LTLIBRARIES = libjunbound.la -libjunbound_la_SOURCES = net_java_sip_communicator_util_dns_UnboundApi.cpp +libjunbound_la_SOURCES = net_java_sip_communicator_impl_dns_UnboundApi.cpp AM_CPPFLAGS = ${includedirs} ${VS_JNI_INCLUDE} -DJNI_IMPLEMENTATION diff --git a/src/native/libjunbound/src/net_java_sip_communicator_impl_dns_UnboundApi.cpp b/src/native/libjunbound/src/net_java_sip_communicator_impl_dns_UnboundApi.cpp new file mode 100644 index 0000000..4db28d6 --- /dev/null +++ b/src/native/libjunbound/src/net_java_sip_communicator_impl_dns_UnboundApi.cpp @@ -0,0 +1,273 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +#include <jni.h> +#include <unbound.h> +#include "net_java_sip_communicator_impl_dns_UnboundApi.h" + +void ub_async_cb(void* my_arg, int err, struct ub_result* result); +jobject createUnboundResult(JNIEnv* env, ub_result* resolveResult); + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: setDebugLevel + * Signature: (JI)V + */ +JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_setDebugLevel + (JNIEnv* env, jclass clazz, jlong context, jint level) +{ + int result = ub_ctx_debuglevel((ub_ctx*)context, level); + if(result != 0) + { + env->ThrowNew(env->FindClass("net/java/sip/communicator/impl/dns/UnboundException"), ub_strerror(result)); + return; + } +} + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: createContext + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_createContext + (JNIEnv* env, jclass clazz) +{ + return (jlong)ub_ctx_create(); +} + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: deleteContext + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_deleteContext + (JNIEnv* env, jclass clazz, jlong context) +{ + ub_ctx_delete((ub_ctx*)context); +} + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: setForwarder + * Signature: (JLjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_setForwarder + (JNIEnv* env, jclass clazz, jlong context, jstring server) +{ + char* chars = (char*)env->GetStringUTFChars(server, NULL); + int result = ub_ctx_set_fwd((ub_ctx*)context, chars); + env->ReleaseStringUTFChars(server, chars); + if(result != 0) + { + env->ThrowNew(env->FindClass("net/java/sip/communicator/impl/dns/UnboundException"), ub_strerror(result)); + return; + } +} + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: addTrustAnchor + * Signature: (JLjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_addTrustAnchor + (JNIEnv* env, jclass clazz, jlong context, jstring anchor) +{ + char* chars = (char*)env->GetStringUTFChars(anchor, NULL); + int result = ub_ctx_add_ta((ub_ctx*)context, chars); + env->ReleaseStringUTFChars(anchor, chars); + if(result != 0) + { + env->ThrowNew(env->FindClass("net/java/sip/communicator/impl/dns/UnboundException"), ub_strerror(result)); + return; + } +} + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: resolve + * Signature: (JLjava/lang/String;II)Lnet/java/sip/communicator/impl/dns/UnboundResult; + */ +JNIEXPORT jobject JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_resolve + (JNIEnv* env, jclass clazz, jlong context, jstring name, jint rrtype, jint rrclass) +{ + char* chars = (char*)env->GetStringUTFChars(name, NULL); + ub_result* resolveResult; + int result = ub_resolve((ub_ctx*)context, chars, rrtype, rrclass, &resolveResult); + env->ReleaseStringUTFChars(name, chars); + if(result != 0) + { + env->ThrowNew(env->FindClass("net/java/sip/communicator/impl/dns/UnboundException"), ub_strerror(result)); + return NULL; + } + return createUnboundResult(env, resolveResult); +} + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: resolveAsync + * Signature: (JLjava/lang/String;IILnet/java/sip/communicator/impl/dns/UnboundApi/UnboundCallback;)J + */ +JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_resolveAsync + (JNIEnv* env, jclass clazz, jlong context, jstring name, jint rrtype, jint rrclass, jobject data, jobject cb) +{ + JavaVM* jvm; + if(env->GetJavaVM(&jvm) != 0) + { + env->ThrowNew(env->FindClass("net/java/sip/communicator/impl/dns/UnboundException"), "Unable to obtain Java VM pointer"); + return 0; + } + + int result = ub_ctx_async((ub_ctx*)context, true); + if(result != 0) + { + env->ThrowNew(env->FindClass("net/java/sip/communicator/impl/dns/UnboundException"), ub_strerror(result)); + return 0; + } + + //ensure the objects stay alive when this method leaves + void** cbData = new void*[3]; + cbData[0] = env->NewGlobalRef(data); + cbData[1] = env->NewGlobalRef(cb); + cbData[2] = jvm; + + int asyncId; + char* chars = (char*)env->GetStringUTFChars(name, NULL); + result = ub_resolve_async((ub_ctx*)context, chars, rrtype, rrclass, cbData, &ub_async_cb, &asyncId); + env->ReleaseStringUTFChars(name, chars); + if(result != 0) + { + delete[] cbData; + env->ThrowNew(env->FindClass("net/java/sip/communicator/impl/dns/UnboundException"), ub_strerror(result)); + return 0; + } + return asyncId; +} + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: cancelAsync + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_cancelAsync + (JNIEnv* env, jclass clazz, jlong context, jint asyncId) +{ + int result = ub_cancel((ub_ctx*)context, asyncId); + if(result != 0) + { + env->ThrowNew(env->FindClass("net/java/sip/communicator/impl/dns/UnboundException"), ub_strerror(result)); + return; + } +} + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: errorCodeToString + * Signature: (I)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_errorCodeToString + (JNIEnv* env, jclass clazz, jint code) +{ + return env->NewStringUTF(ub_strerror(code)); +} + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: processAsync + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_processAsync + (JNIEnv* env, jclass clazz, jlong context) +{ + int result = ub_wait((ub_ctx*)context); + if(result != 0) + { + env->ThrowNew(env->FindClass("net/java/sip/communicator/impl/dns/UnboundException"), ub_strerror(result)); + return; + } +} + + + + + +void ub_async_cb(void* my_arg, int err, struct ub_result* result) +{ + void** cbData = (void**)my_arg; + JavaVM* jvm = ((JavaVM*)cbData[2]); + JNIEnv* env; + if(jvm->AttachCurrentThreadAsDaemon((void**)&env, NULL) == 0) + { + jobject data = (jobject)cbData[0]; + jobject cb = (jobject)cbData[1]; + delete[] cbData; + + jobject ubResult = NULL; + if(err == 0) + { + ubResult = createUnboundResult(env, result); + } + env->CallVoidMethod( + cb, env->GetMethodID( + env->FindClass("net/java/sip/communicator/impl/dns/UnboundApi$UnboundCallback"), + "UnboundResolveCallback", + "(Ljava/lang/Object;ILnet/java/sip/communicator/impl/dns/UnboundResult;)V" + ), data, (jint)err, ubResult + ); + + env->DeleteGlobalRef(data); + env->DeleteGlobalRef(cb); + env->DeleteLocalRef(ubResult); + } + jvm->DetachCurrentThread(); +} + + + + +jobject createUnboundResult(JNIEnv* env, ub_result* resolveResult) +{ + jclass ubResultClass = env->FindClass("net/java/sip/communicator/impl/dns/UnboundResult"); + jmethodID constructor = env->GetMethodID(ubResultClass, "<init>", "()V"); + jobject ubResult = env->NewObject(ubResultClass, constructor); + + //copy data + //int numData = 0; + //char** data = resolveResult->data; + //while(*(data++) != NULL) + // numData++; + + //jobjectArray dataArray = env->NewObjectArray(numData, env->FindClass("[B"), NULL); + //for(int i = 0; i < numData; i++) + //{ + // jbyteArray dataEntry = env->NewByteArray(resolveResult->len[i]); + // env->SetByteArrayRegion(dataEntry, 0, resolveResult->len[i], (jbyte*)resolveResult->data[i]); + // env->SetObjectArrayElement(dataArray, i, dataEntry); + // env->DeleteLocalRef(dataEntry); + //} + + //copy answer packet + jbyteArray answerPacket = env->NewByteArray(resolveResult->answer_len); + env->SetByteArrayRegion(answerPacket, 0, resolveResult->answer_len, (jbyte*)resolveResult->answer_packet); + + //set fields + env->SetObjectField( ubResult, env->GetFieldID(ubResultClass, "qname", "Ljava/lang/String;"), env->NewStringUTF(resolveResult->qname)); + env->SetIntField( ubResult, env->GetFieldID(ubResultClass, "qtype", "I"), resolveResult->qtype); + env->SetIntField( ubResult, env->GetFieldID(ubResultClass, "qclass", "I"), resolveResult->qclass); + + //env->SetObjectField( ubResult, env->GetFieldID(ubResultClass, "data", "[[B"), dataArray); + //env->SetObjectField( ubResult, env->GetFieldID(ubResultClass, "canonname", "Ljava/lang/String;"), env->NewStringUTF(resolveResult->canonname)); + env->SetIntField( ubResult, env->GetFieldID(ubResultClass, "rcode", "I"), resolveResult->rcode); + env->SetObjectField( ubResult, env->GetFieldID(ubResultClass, "answerPacket", "[B"), answerPacket); + + env->SetBooleanField(ubResult, env->GetFieldID(ubResultClass, "haveData", "Z"), resolveResult->havedata); + env->SetBooleanField(ubResult, env->GetFieldID(ubResultClass, "nxDomain", "Z"), resolveResult->nxdomain); + env->SetBooleanField(ubResult, env->GetFieldID(ubResultClass, "secure", "Z"), resolveResult->secure); + env->SetBooleanField(ubResult, env->GetFieldID(ubResultClass, "bogus", "Z"), resolveResult->bogus); + env->SetObjectField( ubResult, env->GetFieldID(ubResultClass, "whyBogus", "Ljava/lang/String;"), env->NewStringUTF(resolveResult->why_bogus)); + + ub_resolve_free(resolveResult); + return ubResult; +} diff --git a/src/native/libjunbound/src/net_java_sip_communicator_impl_dns_UnboundApi.h b/src/native/libjunbound/src/net_java_sip_communicator_impl_dns_UnboundApi.h new file mode 100644 index 0000000..71b59b9 --- /dev/null +++ b/src/native/libjunbound/src/net_java_sip_communicator_impl_dns_UnboundApi.h @@ -0,0 +1,94 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include <jni.h> +/* Header for class net_java_sip_communicator_impl_dns_UnboundApi */ + +#ifndef _Included_net_java_sip_communicator_impl_dns_UnboundApi +#define _Included_net_java_sip_communicator_impl_dns_UnboundApi +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: setDebugLevel + * Signature: (JI)V + */ +JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_setDebugLevel + (JNIEnv *, jclass, jlong, jint); + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: createContext + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_createContext + (JNIEnv *, jclass); + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: deleteContext + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_deleteContext + (JNIEnv *, jclass, jlong); + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: setForwarder + * Signature: (JLjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_setForwarder + (JNIEnv *, jclass, jlong, jstring); + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: addTrustAnchor + * Signature: (JLjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_addTrustAnchor + (JNIEnv *, jclass, jlong, jstring); + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: resolve + * Signature: (JLjava/lang/String;II)Lnet/java/sip/communicator/impl/dns/UnboundResult; + */ +JNIEXPORT jobject JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_resolve + (JNIEnv *, jclass, jlong, jstring, jint, jint); + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: resolveAsync + * Signature: (JLjava/lang/String;IILjava/lang/Object;Lnet/java/sip/communicator/impl/dns/UnboundApi/UnboundCallback;)I + */ +JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_resolveAsync + (JNIEnv *, jclass, jlong, jstring, jint, jint, jobject, jobject); + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: cancelAsync + * Signature: (JI)V + */ +JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_cancelAsync + (JNIEnv *, jclass, jlong, jint); + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: errorCodeToString + * Signature: (I)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_errorCodeToString + (JNIEnv *, jclass, jint); + +/* + * Class: net_java_sip_communicator_impl_dns_UnboundApi + * Method: processAsync + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_processAsync + (JNIEnv *, jclass, jlong); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/native/libjunbound/src/net_java_sip_communicator_impl_dns_UnboundApi_UnboundCallback.h b/src/native/libjunbound/src/net_java_sip_communicator_impl_dns_UnboundApi_UnboundCallback.h new file mode 100644 index 0000000..f9b9de6 --- /dev/null +++ b/src/native/libjunbound/src/net_java_sip_communicator_impl_dns_UnboundApi_UnboundCallback.h @@ -0,0 +1,13 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include <jni.h> +/* Header for class net_java_sip_communicator_impl_dns_UnboundApi_UnboundCallback */ + +#ifndef _Included_net_java_sip_communicator_impl_dns_UnboundApi_UnboundCallback +#define _Included_net_java_sip_communicator_impl_dns_UnboundApi_UnboundCallback +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/native/libjunbound/src/net_java_sip_communicator_util_dns_UnboundApi.cpp b/src/native/libjunbound/src/net_java_sip_communicator_util_dns_UnboundApi.cpp deleted file mode 100644 index f07156a..0000000 --- a/src/native/libjunbound/src/net_java_sip_communicator_util_dns_UnboundApi.cpp +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -#include <jni.h> -#include <unbound.h> -#include "net_java_sip_communicator_util_dns_UnboundApi.h" - -void ub_async_cb(void* my_arg, int err, struct ub_result* result); -jobject createUnboundResult(JNIEnv* env, ub_result* resolveResult); - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: setDebugLevel - * Signature: (JI)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_setDebugLevel - (JNIEnv* env, jclass clazz, jlong context, jint level) -{ - int result = ub_ctx_debuglevel((ub_ctx*)context, level); - if(result != 0) - { - env->ThrowNew(env->FindClass("net/java/sip/communicator/util/dns/UnboundException"), ub_strerror(result)); - return; - } -} - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: createContext - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_createContext - (JNIEnv* env, jclass clazz) -{ - return (jlong)ub_ctx_create(); -} - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: deleteContext - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_deleteContext - (JNIEnv* env, jclass clazz, jlong context) -{ - ub_ctx_delete((ub_ctx*)context); -} - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: setForwarder - * Signature: (JLjava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_setForwarder - (JNIEnv* env, jclass clazz, jlong context, jstring server) -{ - char* chars = (char*)env->GetStringUTFChars(server, NULL); - int result = ub_ctx_set_fwd((ub_ctx*)context, chars); - env->ReleaseStringUTFChars(server, chars); - if(result != 0) - { - env->ThrowNew(env->FindClass("net/java/sip/communicator/util/dns/UnboundException"), ub_strerror(result)); - return; - } -} - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: addTrustAnchor - * Signature: (JLjava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_addTrustAnchor - (JNIEnv* env, jclass clazz, jlong context, jstring anchor) -{ - char* chars = (char*)env->GetStringUTFChars(anchor, NULL); - int result = ub_ctx_add_ta((ub_ctx*)context, chars); - env->ReleaseStringUTFChars(anchor, chars); - if(result != 0) - { - env->ThrowNew(env->FindClass("net/java/sip/communicator/util/dns/UnboundException"), ub_strerror(result)); - return; - } -} - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: resolve - * Signature: (JLjava/lang/String;II)Lnet/java/sip/communicator/util/dns/UnboundResult; - */ -JNIEXPORT jobject JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_resolve - (JNIEnv* env, jclass clazz, jlong context, jstring name, jint rrtype, jint rrclass) -{ - char* chars = (char*)env->GetStringUTFChars(name, NULL); - ub_result* resolveResult; - int result = ub_resolve((ub_ctx*)context, chars, rrtype, rrclass, &resolveResult); - env->ReleaseStringUTFChars(name, chars); - if(result != 0) - { - env->ThrowNew(env->FindClass("net/java/sip/communicator/util/dns/UnboundException"), ub_strerror(result)); - return NULL; - } - return createUnboundResult(env, resolveResult); -} - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: resolveAsync - * Signature: (JLjava/lang/String;IILnet/java/sip/communicator/util/dns/UnboundApi/UnboundCallback;)J - */ -JNIEXPORT jint JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_resolveAsync - (JNIEnv* env, jclass clazz, jlong context, jstring name, jint rrtype, jint rrclass, jobject data, jobject cb) -{ - JavaVM* jvm; - if(env->GetJavaVM(&jvm) != 0) - { - env->ThrowNew(env->FindClass("net/java/sip/communicator/util/dns/UnboundException"), "Unable to obtain Java VM pointer"); - return 0; - } - - int result = ub_ctx_async((ub_ctx*)context, true); - if(result != 0) - { - env->ThrowNew(env->FindClass("net/java/sip/communicator/util/dns/UnboundException"), ub_strerror(result)); - return 0; - } - - //ensure the objects stay alive when this method leaves - void** cbData = new void*[3]; - cbData[0] = env->NewGlobalRef(data); - cbData[1] = env->NewGlobalRef(cb); - cbData[2] = jvm; - - int asyncId; - char* chars = (char*)env->GetStringUTFChars(name, NULL); - result = ub_resolve_async((ub_ctx*)context, chars, rrtype, rrclass, cbData, &ub_async_cb, &asyncId); - env->ReleaseStringUTFChars(name, chars); - if(result != 0) - { - delete[] cbData; - env->ThrowNew(env->FindClass("net/java/sip/communicator/util/dns/UnboundException"), ub_strerror(result)); - return 0; - } - return asyncId; -} - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: cancelAsync - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_cancelAsync - (JNIEnv* env, jclass clazz, jlong context, jint asyncId) -{ - int result = ub_cancel((ub_ctx*)context, asyncId); - if(result != 0) - { - env->ThrowNew(env->FindClass("net/java/sip/communicator/util/dns/UnboundException"), ub_strerror(result)); - return; - } -} - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: errorCodeToString - * Signature: (I)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_errorCodeToString - (JNIEnv* env, jclass clazz, jint code) -{ - return env->NewStringUTF(ub_strerror(code)); -} - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: processAsync - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_processAsync - (JNIEnv* env, jclass clazz, jlong context) -{ - int result = ub_wait((ub_ctx*)context); - if(result != 0) - { - env->ThrowNew(env->FindClass("net/java/sip/communicator/util/dns/UnboundException"), ub_strerror(result)); - return; - } -} - - - - - -void ub_async_cb(void* my_arg, int err, struct ub_result* result) -{ - void** cbData = (void**)my_arg; - JavaVM* jvm = ((JavaVM*)cbData[2]); - JNIEnv* env; - if(jvm->AttachCurrentThreadAsDaemon((void**)&env, NULL) == 0) - { - jobject data = (jobject)cbData[0]; - jobject cb = (jobject)cbData[1]; - delete[] cbData; - - jobject ubResult = NULL; - if(err == 0) - { - ubResult = createUnboundResult(env, result); - } - env->CallVoidMethod( - cb, env->GetMethodID( - env->FindClass("net/java/sip/communicator/util/dns/UnboundApi$UnboundCallback"), - "UnboundResolveCallback", - "(Ljava/lang/Object;ILnet/java/sip/communicator/util/dns/UnboundResult;)V" - ), data, (jint)err, ubResult - ); - - env->DeleteGlobalRef(data); - env->DeleteGlobalRef(cb); - env->DeleteLocalRef(ubResult); - } - jvm->DetachCurrentThread(); -} - - - - -jobject createUnboundResult(JNIEnv* env, ub_result* resolveResult) -{ - jclass ubResultClass = env->FindClass("net/java/sip/communicator/util/dns/UnboundResult"); - jmethodID constructor = env->GetMethodID(ubResultClass, "<init>", "()V"); - jobject ubResult = env->NewObject(ubResultClass, constructor); - - //copy data - //int numData = 0; - //char** data = resolveResult->data; - //while(*(data++) != NULL) - // numData++; - - //jobjectArray dataArray = env->NewObjectArray(numData, env->FindClass("[B"), NULL); - //for(int i = 0; i < numData; i++) - //{ - // jbyteArray dataEntry = env->NewByteArray(resolveResult->len[i]); - // env->SetByteArrayRegion(dataEntry, 0, resolveResult->len[i], (jbyte*)resolveResult->data[i]); - // env->SetObjectArrayElement(dataArray, i, dataEntry); - // env->DeleteLocalRef(dataEntry); - //} - - //copy answer packet - jbyteArray answerPacket = env->NewByteArray(resolveResult->answer_len); - env->SetByteArrayRegion(answerPacket, 0, resolveResult->answer_len, (jbyte*)resolveResult->answer_packet); - - //set fields - env->SetObjectField( ubResult, env->GetFieldID(ubResultClass, "qname", "Ljava/lang/String;"), env->NewStringUTF(resolveResult->qname)); - env->SetIntField( ubResult, env->GetFieldID(ubResultClass, "qtype", "I"), resolveResult->qtype); - env->SetIntField( ubResult, env->GetFieldID(ubResultClass, "qclass", "I"), resolveResult->qclass); - - //env->SetObjectField( ubResult, env->GetFieldID(ubResultClass, "data", "[[B"), dataArray); - //env->SetObjectField( ubResult, env->GetFieldID(ubResultClass, "canonname", "Ljava/lang/String;"), env->NewStringUTF(resolveResult->canonname)); - env->SetIntField( ubResult, env->GetFieldID(ubResultClass, "rcode", "I"), resolveResult->rcode); - env->SetObjectField( ubResult, env->GetFieldID(ubResultClass, "answerPacket", "[B"), answerPacket); - - env->SetBooleanField(ubResult, env->GetFieldID(ubResultClass, "haveData", "Z"), resolveResult->havedata); - env->SetBooleanField(ubResult, env->GetFieldID(ubResultClass, "nxDomain", "Z"), resolveResult->nxdomain); - env->SetBooleanField(ubResult, env->GetFieldID(ubResultClass, "secure", "Z"), resolveResult->secure); - env->SetBooleanField(ubResult, env->GetFieldID(ubResultClass, "bogus", "Z"), resolveResult->bogus); - env->SetObjectField( ubResult, env->GetFieldID(ubResultClass, "whyBogus", "Ljava/lang/String;"), env->NewStringUTF(resolveResult->why_bogus)); - - ub_resolve_free(resolveResult); - return ubResult; -} diff --git a/src/native/libjunbound/src/net_java_sip_communicator_util_dns_UnboundApi.h b/src/native/libjunbound/src/net_java_sip_communicator_util_dns_UnboundApi.h deleted file mode 100644 index f10f4dd..0000000 --- a/src/native/libjunbound/src/net_java_sip_communicator_util_dns_UnboundApi.h +++ /dev/null @@ -1,94 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include <jni.h> -/* Header for class net_java_sip_communicator_util_dns_UnboundApi */ - -#ifndef _Included_net_java_sip_communicator_util_dns_UnboundApi -#define _Included_net_java_sip_communicator_util_dns_UnboundApi -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: setDebugLevel - * Signature: (JI)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_setDebugLevel - (JNIEnv *, jclass, jlong, jint); - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: createContext - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_createContext - (JNIEnv *, jclass); - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: deleteContext - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_deleteContext - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: setForwarder - * Signature: (JLjava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_setForwarder - (JNIEnv *, jclass, jlong, jstring); - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: addTrustAnchor - * Signature: (JLjava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_addTrustAnchor - (JNIEnv *, jclass, jlong, jstring); - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: resolve - * Signature: (JLjava/lang/String;II)Lnet/java/sip/communicator/util/dns/UnboundResult; - */ -JNIEXPORT jobject JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_resolve - (JNIEnv *, jclass, jlong, jstring, jint, jint); - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: resolveAsync - * Signature: (JLjava/lang/String;IILjava/lang/Object;Lnet/java/sip/communicator/util/dns/UnboundApi/UnboundCallback;)I - */ -JNIEXPORT jint JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_resolveAsync - (JNIEnv *, jclass, jlong, jstring, jint, jint, jobject, jobject); - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: cancelAsync - * Signature: (JI)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_cancelAsync - (JNIEnv *, jclass, jlong, jint); - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: errorCodeToString - * Signature: (I)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_errorCodeToString - (JNIEnv *, jclass, jint); - -/* - * Class: net_java_sip_communicator_util_dns_UnboundApi - * Method: processAsync - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_util_dns_UnboundApi_processAsync - (JNIEnv *, jclass, jlong); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/native/libjunbound/src/net_java_sip_communicator_util_dns_UnboundApi_UnboundCallback.h b/src/native/libjunbound/src/net_java_sip_communicator_util_dns_UnboundApi_UnboundCallback.h deleted file mode 100644 index 9df4856..0000000 --- a/src/native/libjunbound/src/net_java_sip_communicator_util_dns_UnboundApi_UnboundCallback.h +++ /dev/null @@ -1,13 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include <jni.h> -/* Header for class net_java_sip_communicator_util_dns_UnboundApi_UnboundCallback */ - -#ifndef _Included_net_java_sip_communicator_util_dns_UnboundApi_UnboundCallback -#define _Included_net_java_sip_communicator_util_dns_UnboundApi_UnboundCallback -#ifdef __cplusplus -extern "C" { -#endif -#ifdef __cplusplus -} -#endif -#endif -- cgit v1.1