/soc/2012/michael/android: 94152c4db216: Implemented dns query u...
Michael Zangl
michael at soc.pidgin.im
Wed Jul 25 16:01:05 EDT 2012
Changeset: 94152c4db216b6ab7b6d2c4f5b93cb2988ab26b3
Author: Michael Zangl <michael at soc.pidgin.im>
Date: 2012-07-25 16:19 +0200
Branch: soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/94152c4db216
Description:
Implemented dns query ui ops.
diffstat:
android/workspace/im.pidgin.libpurple.testclient/AndroidManifest.xml | 1 +
android/workspace/im.pidgin.libpurple/native/DnsQueryData.c | 24 ++++
android/workspace/im.pidgin.libpurple/native/DnsQueryData.h | 4 +
android/workspace/im.pidgin.libpurple/native/DnsQueryFailedCallback.c | 24 ++++
android/workspace/im.pidgin.libpurple/native/DnsQueryResolvedCallback.c | 57 ++++++++++
android/workspace/im.pidgin.libpurple/native/DnsQueryUiOps.c | 52 +++++++++
android/workspace/im.pidgin.libpurple/native/PurpleAccountManager.c | 4 +-
android/workspace/im.pidgin.libpurple/native/SslOps.c | 2 +-
android/workspace/im.pidgin.libpurple/native/build.ant | 15 +-
android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/CoreManager.java | 2 +
android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/DnsQueryData.java | 6 +
android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/DnsQueryFailedCallback.java | 12 +-
android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/DnsQueryResolvedCallback.java | 19 ++-
android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/DnsQueryUiOps.java | 26 +++-
14 files changed, 223 insertions(+), 25 deletions(-)
diffs (truncated from 426 to 300 lines):
diff --git a/android/workspace/im.pidgin.libpurple.testclient/AndroidManifest.xml b/android/workspace/im.pidgin.libpurple.testclient/AndroidManifest.xml
--- a/android/workspace/im.pidgin.libpurple.testclient/AndroidManifest.xml
+++ b/android/workspace/im.pidgin.libpurple.testclient/AndroidManifest.xml
@@ -5,6 +5,7 @@
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
+ <uses-permission android:name="android.permission.INTERNET"/>
<application
android:debuggable="true"
diff --git a/android/workspace/im.pidgin.libpurple/native/DnsQueryData.c b/android/workspace/im.pidgin.libpurple/native/DnsQueryData.c
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/DnsQueryData.c
@@ -0,0 +1,24 @@
+#include "DnsQueryData.h"
+#include "helpers.h"
+#include <libpurple/dnsquery.h>
+
+PurpleDnsQueryData *
+getNativeDnsData(JNIEnv *env, jobject object)
+{
+ return (PurpleDnsQueryData*) getNativePointer(env, object);
+}
+
+/*
+ * Class: im_pidgin_libpurple_core_dns_DnsQueryData
+ * Method: getHost_native
+ * Signature: ()Ljava/lang/String;
+ */JNIEXPORT jstring JNICALL
+Java_im_pidgin_libpurple_core_dns_DnsQueryData_getHost_1native(JNIEnv *env,
+ jobject object)
+{
+ PurpleDnsQueryData* object_native;
+
+ object_native = getNativeDnsData(env, object);
+
+ return (*env)->NewStringUTF(env, purple_dnsquery_get_host(object_native));
+}
diff --git a/android/workspace/im.pidgin.libpurple/native/DnsQueryData.h b/android/workspace/im.pidgin.libpurple/native/DnsQueryData.h
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/DnsQueryData.h
@@ -0,0 +1,4 @@
+#include "DnsQueryData_jni.h"
+#include <libpurple/dnsquery.h>
+
+PurpleDnsQueryData* getNativeDnsData(JNIEnv *env, jobject object);
diff --git a/android/workspace/im.pidgin.libpurple/native/DnsQueryFailedCallback.c b/android/workspace/im.pidgin.libpurple/native/DnsQueryFailedCallback.c
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/DnsQueryFailedCallback.c
@@ -0,0 +1,24 @@
+#include "DnsQueryFailedCallback.h"
+#include "DnsQueryData.h"
+#include "helpers.h"
+#include <libpurple/dnsquery.h>
+
+/*
+ * Class: im_pidgin_libpurple_core_dns_DnsQueryFailedCallback
+ * Method: call_native
+ * Signature: (Lim/pidgin/libpurple/core/dns/DnsQueryData;Ljava/lang/String;)V
+ */JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_core_dns_DnsQueryFailedCallback_call_1native(
+ JNIEnv *env, jobject object, jobject data, jstring message)
+{
+ PurpleDnsQueryFailedCallback failedCallback;
+ const char* message_native;
+
+ failedCallback = getNativePointer(env, object);
+
+ message_native = (*env)->GetStringUTFChars(env, message, NULL);
+ g_return_if_fail(message_native != NULL);
+
+ failedCallback(getNativeDnsData(env, data), message_native);
+ (*env)->ReleaseStringUTFChars(env, message, message_native);
+}
diff --git a/android/workspace/im.pidgin.libpurple/native/DnsQueryResolvedCallback.c b/android/workspace/im.pidgin.libpurple/native/DnsQueryResolvedCallback.c
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/DnsQueryResolvedCallback.c
@@ -0,0 +1,57 @@
+#include "DnsQueryResolvedCallback.h"
+#include "DnsQueryData.h"
+#include "helpers.h"
+#include <libpurple/dnsquery.h>
+#include <netinet/in.h>
+
+/*
+ * Class: im_pidgin_libpurple_core_dns_DnsQueryResolvedCallback
+ * Method: call_native
+ * Signature: (Lim/pidgin/libpurple/core/dns/DnsQueryData;[[B)V
+ */JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_core_dns_DnsQueryResolvedCallback_call_1native(
+ JNIEnv *env, jobject object, jobject data, jobjectArray result)
+{
+ PurpleDnsQueryResolvedCallback resolvedCallback;
+ PurpleDnsQueryData* query_data;
+ jsize length;
+ jsize i;
+ jbyteArray entry;
+ jsize entry_length;
+ struct sockaddr_in entry_native;
+ struct sockaddr_in6 entry_native6;
+ GSList *hosts;
+
+ resolvedCallback = getNativePointer(env, object);
+ query_data = getNativeDnsData(env, data);
+ hosts = NULL;
+ length = (*env)->GetArrayLength(env, result);
+
+ for (i = 0; i < length; ++i) {
+ entry = (*env)->GetObjectArrayElement(env, result, i);
+ entry_length = (*env)->GetArrayLength(env, entry);
+ if (entry_length == 4) {
+ (*env)->GetByteArrayRegion(env, entry, 0, entry_length,
+ (jbyte*) &entry_native.sin_addr);
+ entry_native.sin_family = AF_INET;
+ entry_native.sin_port = htons(purple_dnsquery_get_port(query_data));
+
+ hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(entry_native)));
+ hosts = g_slist_append(hosts,
+ g_memdup(&entry_native, sizeof(entry_native)));
+
+ } else if (entry_length == 16) {
+ (*env)->GetByteArrayRegion(env, entry, 0, entry_length,
+ (jbyte*) &entry_native6.sin6_addr);
+ entry_native6.sin6_family = AF_INET6;
+ entry_native6.sin6_port = htons(purple_dnsquery_get_port(query_data));
+
+ hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(entry_native6)));
+ hosts = g_slist_append(hosts,
+ g_memdup(&entry_native6, sizeof(entry_native6)));
+
+ }
+ }
+
+ resolvedCallback(query_data, hosts);
+}
diff --git a/android/workspace/im.pidgin.libpurple/native/DnsQueryUiOps.c b/android/workspace/im.pidgin.libpurple/native/DnsQueryUiOps.c
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/DnsQueryUiOps.c
@@ -0,0 +1,52 @@
+#include "DnsQueryUiOps.h"
+#include "helpers.h"
+#include <libpurple/dnsquery.h>
+
+static JavaObjectReference dns = JAVA_NULL_OBJECT_REF;
+
+static gboolean
+resolve_host(PurpleDnsQueryData* query_data,
+ PurpleDnsQueryResolvedCallback resolved_cb,
+ PurpleDnsQueryFailedCallback failed_cb)
+{
+ static JavaMethodIDCache methodCache = METHOD_CACHE("resolveHost", "(JJJ)Z");
+
+ jmethodID mid;
+ jlong query_data_ptr;
+ jlong resolved_cb_ptr;
+ jlong failed_cb_ptr;
+ jboolean result = JNI_FALSE;
+
+ CALLBACK_START(&dns, JNI_FALSE);
+
+ query_data_ptr = pToLong(query_data);
+ resolved_cb_ptr = pToLong(resolved_cb);
+ failed_cb_ptr = pToLong(failed_cb);
+
+ mid = getMethodIDCachedReferenced(env, dns.java_class, &methodCache);
+ if (mid != NULL) {
+ result = (*env)->CallLongMethod(env, dns.handlerObject, mid,
+ query_data_ptr, resolved_cb_ptr, failed_cb_ptr);
+ }
+ return (gboolean) result;
+}
+
+static void destroy(PurpleDnsQueryData *query_data) {
+
+}
+
+static PurpleDnsQueryUiOps uiOps = {
+ resolve_host, destroy, NULL, NULL, NULL, NULL
+};
+
+/*
+ * Class: im_pidgin_libpurple_core_dns_DnsQueryUiOps
+ * Method: register_native
+ * Signature: ()V
+ */JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_core_dns_DnsQueryUiOps_register_1native(JNIEnv *env,
+ jobject object)
+{
+ setJavaObject(&dns, env, object);
+ purple_dnsquery_set_ui_ops(&uiOps);
+}
diff --git a/android/workspace/im.pidgin.libpurple/native/PurpleAccountManager.c b/android/workspace/im.pidgin.libpurple/native/PurpleAccountManager.c
--- a/android/workspace/im.pidgin.libpurple/native/PurpleAccountManager.c
+++ b/android/workspace/im.pidgin.libpurple/native/PurpleAccountManager.c
@@ -29,10 +29,10 @@ account_abled_callback(PurpleAccount *ac
void
close_account_request(void* ui_handle);
-PurpleAccountUiOps uiOps = { notify_added, status_changed, request_add,
+static PurpleAccountUiOps uiOps = { notify_added, status_changed, request_add,
request_authorize, close_account_request, NULL, NULL, NULL, NULL };
-JavaObjectReference accountList = JAVA_NULL_OBJECT_REF;
+static JavaObjectReference accountList = JAVA_NULL_OBJECT_REF;
/*
* Class: im_pidgin_libpurple_account_PurpleAccountManager
diff --git a/android/workspace/im.pidgin.libpurple/native/SslOps.c b/android/workspace/im.pidgin.libpurple/native/SslOps.c
--- a/android/workspace/im.pidgin.libpurple/native/SslOps.c
+++ b/android/workspace/im.pidgin.libpurple/native/SslOps.c
@@ -2,7 +2,7 @@
#include "helpers.h"
#include <libpurple/sslconn.h>
-JavaObjectReference ssl = JAVA_NULL_OBJECT_REF;
+static JavaObjectReference ssl = JAVA_NULL_OBJECT_REF;
static JavaObjectReference*
getJavaObject(PurpleSslConnection* gsc)
diff --git a/android/workspace/im.pidgin.libpurple/native/build.ant b/android/workspace/im.pidgin.libpurple/native/build.ant
--- a/android/workspace/im.pidgin.libpurple/native/build.ant
+++ b/android/workspace/im.pidgin.libpurple/native/build.ant
@@ -14,7 +14,7 @@
<import file="../../im.pidgin.libpurple.build/buildscripts/common.ant" />
<import file="generateheaders.ant" />
- <import file="distribute.ant"/>
+ <import file="distribute.ant" />
<property name="libpurple.java.gen" location="../gen" />
<property name="libpurple.constants.outdir" location="${libpurple.java.gen}/im/pidgin/libpurple/constants" />
@@ -46,17 +46,18 @@
<javah classdefinition="im.pidgin.libpurple.conversation.PurpleConversation" to="${javah.out}" />
<javah classdefinition="im.pidgin.libpurple.conversation.ConversationManager" to="${javah.out}" headerfilename="ConversationManager_jni.h" />
- <javah classdefinition="im.pidgin.libpurple.core.EventLoop" to="${javah.out}" headerfilename="EventLoop_jni.h"/>
+ <javah classdefinition="im.pidgin.libpurple.core.EventLoop" to="${javah.out}" headerfilename="EventLoop_jni.h" />
<javah classdefinition="im.pidgin.libpurple.core.PurpleInstance" to="${javah.out}" />
<javah classdefinition="im.pidgin.libpurple.core.CoreManager" to="${javah.out}" />
- <javah classdefinition="im.pidgin.libpurple.core.dns.DnsQueryData" to="${javah.out}" />
+ <javah classdefinition="im.pidgin.libpurple.core.dns.DnsQueryData" to="${javah.out}" headerfilename="DnsQueryData_jni.h" />
<javah classdefinition="im.pidgin.libpurple.core.dns.DnsQueryFailedCallback" to="${javah.out}" />
<javah classdefinition="im.pidgin.libpurple.core.dns.DnsQueryResolvedCallback" to="${javah.out}" />
-
+ <javah classdefinition="im.pidgin.libpurple.core.dns.DnsQueryUiOps" to="${javah.out}" />
+
<javah classdefinition="im.pidgin.libpurple.core.ssl.SslConnection" to="${javah.out}" />
- <javah classdefinition="im.pidgin.libpurple.core.ssl.SslOps" to="${javah.out}"/>
-
+ <javah classdefinition="im.pidgin.libpurple.core.ssl.SslOps" to="${javah.out}" />
+
<javah classdefinition="im.pidgin.libpurple.glib.GHashTableReference" to="${javah.out}" />
<javah classdefinition="im.pidgin.libpurple.glib.GListReference" to="${javah.out}" />
<javah classdefinition="im.pidgin.libpurple.glib.GSourceFunctionCall" to="${javah.out}" />
@@ -92,5 +93,5 @@
</extractconstants>
</target>
-
+
</project>
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/CoreManager.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/CoreManager.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/CoreManager.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/CoreManager.java
@@ -3,6 +3,7 @@ package im.pidgin.libpurple.core;
import im.pidgin.libpurple.account.PurpleAccountManager;
import im.pidgin.libpurple.blist.PurpleBlistManager;
import im.pidgin.libpurple.conversation.ConversationManager;
+import im.pidgin.libpurple.core.dns.DnsQueryUiOps;
import im.pidgin.libpurple.core.ssl.SslOps;
import im.pidgin.libpurple.core.thread.PurpleThread;
import im.pidgin.libpurple.plugin.PurplePluginList;
@@ -62,6 +63,7 @@ public class CoreManager {
blist.register();
conversationManager.register();
new SslOps().register();
+ new DnsQueryUiOps().register();
}
public PurpleThread getThread() {
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/DnsQueryData.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/DnsQueryData.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/DnsQueryData.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/DnsQueryData.java
@@ -13,4 +13,10 @@ public class DnsQueryData extends Peered
super(nativePointer);
}
+ public String getHost() {
+ return getHost_native();
+ }
+
+ private native String getHost_native();
+
More information about the Commits
mailing list