/soc/2012/michael/android: 0d1aef86a654: Added dns srv and txt u...

Michael Zangl michael at soc.pidgin.im
Fri Aug 3 04:43:18 EDT 2012


Changeset: 0d1aef86a654fb183b2ab9540699d6cc8c1b2677
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2012-08-03 10:42 +0200
Branch:	 soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/0d1aef86a654

Description:

Added dns srv and txt ui ops.

diffstat:

 android/workspace/im.pidgin.libpurple/native/DnsQueryResolvedCallback.c                                        |    9 +-
 android/workspace/im.pidgin.libpurple/native/DnsQueryUiOps.c                                                   |   54 ++-
 android/workspace/im.pidgin.libpurple/native/SrvTxtQueryData.c                                                 |   59 +++
 android/workspace/im.pidgin.libpurple/native/SrvTxtQueryData.h                                                 |    5 +
 android/workspace/im.pidgin.libpurple/native/SrvTxtQueryFailedCallback.c                                       |   24 +
 android/workspace/im.pidgin.libpurple/native/SrvTxtQueryResolvedCallback.c                                     |   84 ++++
 android/workspace/im.pidgin.libpurple/native/build.ant                                                         |    9 +-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/DnsExeption.java                        |   23 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/DnsQuery.java                           |    5 +-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/DnsQueryUiOps.java                      |   16 +-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/DnsQueryWorker.java                     |    8 +-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/DnsResolver.java                        |  194 ++++++++++
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/srvtxt/DnsSrvResolver.java              |   45 ++
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/srvtxt/SrvResponse.java                 |   58 ++
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/srvtxt/SrvTxtQuery.java                 |   38 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/srvtxt/SrvTxtQueryData.java             |   42 ++
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/srvtxt/SrvTxtQueryFailedCallback.java   |   20 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/dns/srvtxt/SrvTxtQueryResolvedCallback.java |   25 +
 18 files changed, 703 insertions(+), 15 deletions(-)

diffs (truncated from 898 to 300 lines):

diff --git a/android/workspace/im.pidgin.libpurple/native/DnsQueryResolvedCallback.c b/android/workspace/im.pidgin.libpurple/native/DnsQueryResolvedCallback.c
--- a/android/workspace/im.pidgin.libpurple/native/DnsQueryResolvedCallback.c
+++ b/android/workspace/im.pidgin.libpurple/native/DnsQueryResolvedCallback.c
@@ -36,7 +36,8 @@ Java_im_pidgin_libpurple_core_dns_DnsQue
 			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,
+					GINT_TO_POINTER(sizeof(entry_native)));
 			hosts = g_slist_append(hosts,
 					g_memdup(&entry_native, sizeof(entry_native)));
 
@@ -44,9 +45,11 @@ Java_im_pidgin_libpurple_core_dns_DnsQue
 			(*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));
+			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,
+					GINT_TO_POINTER(sizeof(entry_native6)));
 			hosts = g_slist_append(hosts,
 					g_memdup(&entry_native6, sizeof(entry_native6)));
 
diff --git a/android/workspace/im.pidgin.libpurple/native/DnsQueryUiOps.c b/android/workspace/im.pidgin.libpurple/native/DnsQueryUiOps.c
--- a/android/workspace/im.pidgin.libpurple/native/DnsQueryUiOps.c
+++ b/android/workspace/im.pidgin.libpurple/native/DnsQueryUiOps.c
@@ -1,6 +1,7 @@
 #include "DnsQueryUiOps.h"
 #include "helpers.h"
 #include <libpurple/dnsquery.h>
+#include <libpurple/dnssrv.h>
 #include "DnsQueryData.h"
 
 static JavaObjectReference dns = JAVA_NULL_OBJECT_REF;
@@ -32,7 +33,9 @@ resolve_host(PurpleDnsQueryData* query_d
 	return (gboolean) result;
 }
 
-static void destroy(PurpleDnsQueryData *query_data) {
+static void
+destroy(PurpleDnsQueryData *query_data)
+{
 	JavaObjectReference *ref;
 
 	CALLBACK_START_VOID(&dns);
@@ -43,9 +46,51 @@ static void destroy(PurpleDnsQueryData *
 	unsetJavaObject(ref, env);
 }
 
-static PurpleDnsQueryUiOps uiOps = {
-		resolve_host, destroy, NULL, NULL, NULL, NULL
-};
+static gboolean
+resolve_srv(PurpleSrvTxtQueryData* query_data,
+		PurpleSrvTxtQueryResolvedCallback resolved_cb,
+		PurpleSrvTxtQueryFailedCallback failed_cb)
+{
+	static JavaMethodIDCache methodCache = METHOD_CACHE("resolveSrvTxt", "(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)->CallBooleanMethod(env, dns.handlerObject, mid,
+				query_data_ptr, resolved_cb_ptr, failed_cb_ptr);
+	}
+	return (gboolean) result;
+}
+
+static void
+destroy_srv(PurpleSrvTxtQueryData *query_data)
+{
+	JavaObjectReference *ref;
+
+	CALLBACK_START_VOID(&dns);
+
+	ref = purple_srv_txt_query_get_ui_data(query_data);
+
+	notifyPeerDestroyed(env, ref->handlerObject);
+	unsetJavaObject(ref, env);
+}
+
+static PurpleDnsQueryUiOps uiOps = { resolve_host, destroy, NULL, NULL, NULL,
+		NULL };
+
+static PurpleSrvTxtQueryUiOps srvUiOps = { resolve_srv, destroy_srv, NULL, NULL,
+		NULL, NULL };
 
 /*
  * Class:     im_pidgin_libpurple_core_dns_DnsQueryUiOps
@@ -57,4 +102,5 @@ Java_im_pidgin_libpurple_core_dns_DnsQue
 {
 	setJavaObject(&dns, env, object);
 	purple_dnsquery_set_ui_ops(&uiOps);
+	purple_srv_txt_query_set_ui_ops(&srvUiOps);
 }
diff --git a/android/workspace/im.pidgin.libpurple/native/SrvTxtQueryData.c b/android/workspace/im.pidgin.libpurple/native/SrvTxtQueryData.c
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/SrvTxtQueryData.c
@@ -0,0 +1,59 @@
+#include "SrvTxtQueryData.h"
+#include "helpers.h"
+#include <libpurple/dnssrv.h>
+
+PurpleSrvTxtQueryData *
+getNativeSrvTxtData(JNIEnv *env, jobject object)
+{
+	return (PurpleSrvTxtQueryData*) getNativePointer(env, object);
+}
+
+/*
+ * Class:     im_pidgin_libpurple_core_dns_srvtxt_SrvTxtQueryData
+ * Method:    register_native
+ * Signature: ()V
+ */JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_core_dns_srvtxt_SrvTxtQueryData_register_1native(
+		JNIEnv *env, jobject object)
+{
+	PurpleSrvTxtQueryData* object_native;
+	JavaObjectReference *ref;
+
+	object_native = getNativeSrvTxtData(env, object);
+	ref = g_new0(JavaObjectReference, 1);
+	setJavaObject(ref, env, object);
+
+	purple_srv_txt_query_set_ui_data(object_native, ref);
+}
+
+/*
+ * Class:     im_pidgin_libpurple_core_dns_srvtxt_SrvTxtQueryData
+ * Method:    getType_native
+ * Signature: ()I
+ */JNIEXPORT jint JNICALL
+Java_im_pidgin_libpurple_core_dns_srvtxt_SrvTxtQueryData_getType_1native(
+		JNIEnv *env, jobject object)
+{
+	PurpleSrvTxtQueryData* object_native;
+
+	object_native = getNativeSrvTxtData(env, object);
+
+	return purple_srv_txt_query_get_type(object_native);
+}
+
+/*
+ * Class:     im_pidgin_libpurple_core_dns_srvtxt_SrvTxtQueryData
+ * Method:    getQuery_native
+ * Signature: ()Ljava/lang/String;
+ */JNIEXPORT jstring JNICALL
+Java_im_pidgin_libpurple_core_dns_srvtxt_SrvTxtQueryData_getQuery_1native(
+		JNIEnv *env, jobject object)
+{
+	PurpleSrvTxtQueryData* object_native;
+
+	object_native = getNativeSrvTxtData(env, object);
+
+	return (*env)->NewStringUTF(env,
+			purple_srv_txt_query_get_query(object_native));
+}
+
diff --git a/android/workspace/im.pidgin.libpurple/native/SrvTxtQueryData.h b/android/workspace/im.pidgin.libpurple/native/SrvTxtQueryData.h
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/SrvTxtQueryData.h
@@ -0,0 +1,5 @@
+#include "SrvTxtQueryData_jni.h"
+#include <libpurple/dnssrv.h>
+
+PurpleSrvTxtQueryData *
+getNativeSrvTxtData(JNIEnv *env, jobject object);
diff --git a/android/workspace/im.pidgin.libpurple/native/SrvTxtQueryFailedCallback.c b/android/workspace/im.pidgin.libpurple/native/SrvTxtQueryFailedCallback.c
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/SrvTxtQueryFailedCallback.c
@@ -0,0 +1,24 @@
+#include "SrvTxtQueryFailedCallback.h"
+#include "SrvTxtQueryData.h"
+#include "helpers.h"
+#include <libpurple/dnssrv.h>
+
+/*
+ * Class:     im_pidgin_libpurple_core_dns_srvtxt_SrvTxtQueryFailedCallback
+ * Method:    call_native
+ * Signature: (Lim/pidgin/libpurple/core/dns/srvtxt/SrvTxtQueryData;Ljava/lang/String;)V
+ */JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_core_dns_srvtxt_SrvTxtQueryFailedCallback_call_1native(
+		JNIEnv *env, jobject object, jobject data, jstring message)
+{
+	PurpleSrvTxtQueryFailedCallback failedCallback;
+	const char* message_native;
+
+	failedCallback = getNativePointer(env, object);
+
+	message_native = (*env)->GetStringUTFChars(env, message, NULL);
+	g_return_if_fail(message_native != NULL);
+
+	failedCallback(getNativeSrvTxtData(env, data), message_native);
+	(*env)->ReleaseStringUTFChars(env, message, message_native);
+}
diff --git a/android/workspace/im.pidgin.libpurple/native/SrvTxtQueryResolvedCallback.c b/android/workspace/im.pidgin.libpurple/native/SrvTxtQueryResolvedCallback.c
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/SrvTxtQueryResolvedCallback.c
@@ -0,0 +1,84 @@
+#include "SrvTxtQueryResolvedCallback.h"
+#include "SrvTxtQueryData.h"
+#include "helpers.h"
+#include <libpurple/dnssrv.h>
+
+PurpleSrvResponse *
+convert_srv_response(JNIEnv *env, jobject object)
+{
+	static JavaMethodIDCache getPriorityCache =
+			METHOD_CACHE("getPriority", "()I");
+	static JavaMethodIDCache getWeigthCache = METHOD_CACHE("getWeigth", "()I");
+	static JavaMethodIDCache getPortCache = METHOD_CACHE("getPort", "()I");
+	static JavaMethodIDCache getHostCache =
+			METHOD_CACHE("getHost", "()Ljava/lang/String;");
+
+	PurpleSrvResponse *response;
+	jclass java_class;
+	jmethodID getPriorityMid;
+	jmethodID getWeigthMid;
+	jmethodID getPortMid;
+	jmethodID getHostMid;
+	jstring hostname;
+	jsize hostname_len;
+
+	java_class = (*env)->GetObjectClass(env, object);
+	g_return_val_if_fail(java_class != NULL, NULL);
+
+	getPriorityMid = getMethodIDCachedReferenced(env, java_class,
+			&getPriorityCache);
+	g_return_val_if_fail(getPriorityMid != NULL, NULL);
+	getWeigthMid = getMethodIDCachedReferenced(env, java_class,
+			&getWeigthCache);
+	g_return_val_if_fail(getWeigthMid != NULL, NULL);
+	getPortMid = getMethodIDCachedReferenced(env, java_class, &getPortCache);
+	g_return_val_if_fail(getPortMid != NULL, NULL);
+	getHostMid = getMethodIDCachedReferenced(env, java_class, &getHostCache);
+	g_return_val_if_fail(getHostMid != NULL, NULL);
+
+	response = g_new(PurpleSrvResponse, 1);
+	response->pref = (*env)->CallIntMethod(env, object, getPriorityMid);
+	response->port = (*env)->CallIntMethod(env, object, getPortMid);
+	response->weight = (*env)->CallIntMethod(env, object, getWeigthMid);
+	hostname = (*env)->CallObjectMethod(env, object, getHostMid);
+	hostname_len = (*env)->GetStringLength(env, hostname);
+	g_return_val_if_fail(hostname_len > sizeof(response->hostname), NULL);
+	(*env)->GetStringUTFRegion(env, hostname, 0, hostname_len,
+			response->hostname);
+	(*env)->ReleaseStringUTFChars(env, hostname, NULL);
+	return response;
+}
+
+/*
+ * Class:     im_pidgin_libpurple_core_dns_srvtxt_SrvTxtQueryResolvedCallback
+ * Method:    call_native
+ * Signature: (Lim/pidgin/libpurple/core/dns/srvtxt/SrvTxtQueryData;[Lim/pidgin/libpurple/core/dns/srvtxt/SrvResponse;)V
+ */JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_core_dns_srvtxt_SrvTxtQueryResolvedCallback_call_1native(
+		JNIEnv *env, jobject object, jobject data, jobjectArray result)
+{
+	PurpleSrvTxtQueryResolvedCallback resolvedCallback;
+	PurpleSrvTxtQueryData *data_native;
+	jsize length;
+	jsize i;
+	jobject entry;
+	GList *result_native;
+
+	resolvedCallback = getNativePointer(env, object);
+	data_native = getNativeSrvTxtData(env, data);
+	result_native = g_list_alloc();
+	length = (*env)->GetArrayLength(env, result);
+
+	if (purple_srv_txt_query_get_type(data_native) == PurpleDnsTypeSrv) {
+		for (i = 0; i < length; ++i) {
+			entry = (*env)->GetObjectArrayElement(env, result, i);
+
+			result_native = g_list_append(result_native,
+					convert_srv_response(env, entry));
+		}
+	} else {
+		g_return_if_reached();
+	}
+



More information about the Commits mailing list