/soc/2012/michael/libpurple: 87fee9883054: Made DNS changes need...
Michael Zangl
michael at soc.pidgin.im
Thu May 9 05:53:19 EDT 2013
Changeset: 87fee9883054778d5209fc27e6812f0ae1edb99b
Author: Michael Zangl <michael at soc.pidgin.im>
Date: 2013-05-09 10:28 +0200
Branch: default
URL: https://hg.pidgin.im/soc/2012/michael/libpurple/rev/87fee9883054
Description:
Made DNS changes needed for Android: Added an ui-data filed to the dns data struct and added the needed #ifdefs to not compile the normal Linux resolver for Android.
diffstat:
libpurple/dnsquery.c | 19 ++++++++++++++-
libpurple/dnsquery.h | 19 +++++++++++++++
libpurple/dnssrv.c | 64 ++++++++++++++++++++++++++++++++++++---------------
libpurple/dnssrv.h | 12 +++++++--
4 files changed, 91 insertions(+), 23 deletions(-)
diffs (truncated from 326 to 300 lines):
diff --git a/libpurple/dnsquery.c b/libpurple/dnsquery.c
--- a/libpurple/dnsquery.c
+++ b/libpurple/dnsquery.c
@@ -38,7 +38,7 @@
#include <resolv.h>
#endif
-#if (defined(__APPLE__) || defined (__unix__)) && !defined(__osf__)
+#if (defined(__APPLE__) || defined (__unix__)) && !defined(__osf__) && !defined(ANDROID)
#define PURPLE_DNSQUERY_USE_FORK
#endif
/**************************************************************************
@@ -64,6 +64,7 @@ struct _PurpleDnsQueryData {
GSList *hosts;
gchar *error_message;
#endif
+ void *ui_data;
};
#if defined(PURPLE_DNSQUERY_USE_FORK)
@@ -1012,6 +1013,22 @@ purple_dnsquery_get_port(PurpleDnsQueryD
return query_data->port;
}
+void *
+purple_dnsquery_get_ui_data(PurpleDnsQueryData *query_data)
+{
+ g_return_val_if_fail(query_data != NULL, 0);
+
+ return query_data->ui_data;
+}
+
+void
+purple_dnsquery_set_ui_data(PurpleDnsQueryData *query_data, void *ui_data)
+{
+ g_return_if_fail(query_data != NULL);
+
+ query_data->ui_data = ui_data;
+}
+
void
purple_dnsquery_set_ui_ops(PurpleDnsQueryUiOps *ops)
{
diff --git a/libpurple/dnsquery.h b/libpurple/dnsquery.h
--- a/libpurple/dnsquery.h
+++ b/libpurple/dnsquery.h
@@ -141,6 +141,25 @@ char *purple_dnsquery_get_host(PurpleDns
unsigned short purple_dnsquery_get_port(PurpleDnsQueryData *query_data);
/**
+ * Get the ui data associated with a PurpleDnsQueryData
+ *
+ * @param query_data The DNS query
+ * @return The ui data
+ */
+void *
+purple_dnsquery_get_ui_data(PurpleDnsQueryData *query_data);
+
+/**
+ * Sets the ui data for the PurpleDnsQueryData
+ *
+ * @param query_data The DNS query
+ * @param ui_data The UI data
+ */
+void
+purple_dnsquery_set_ui_data(PurpleDnsQueryData *query_data, void *ui_data);
+
+
+/**
* Initializes the DNS query subsystem.
*/
void purple_dnsquery_init(void);
diff --git a/libpurple/dnssrv.c b/libpurple/dnssrv.c
--- a/libpurple/dnssrv.c
+++ b/libpurple/dnssrv.c
@@ -71,20 +71,23 @@ struct _PurpleSrvTxtQueryData {
gpointer extradata;
guint handle;
- int type;
+ PurpleDnsType type;
char *query;
#ifdef _WIN32
GThread *resolver;
char *error_message;
GList *results;
+#elif defined(ANDROID)
+ char *error_message;
#else
int fd_in, fd_out;
pid_t pid;
#endif
+ void *ui_data;
};
typedef struct _PurpleSrvInternalQuery {
- int type;
+ PurpleDnsType type;
char query[256];
} PurpleSrvInternalQuery;
@@ -244,13 +247,13 @@ purple_srv_sort(GList *list)
}
static PurpleSrvTxtQueryData *
-query_data_new(int type, gchar *query, gpointer extradata)
+query_data_new(PurpleDnsType type, gchar *query, gpointer extradata)
{
PurpleSrvTxtQueryData *query_data = g_new0(PurpleSrvTxtQueryData, 1);
query_data->type = type;
query_data->extradata = extradata;
query_data->query = query;
-#ifndef _WIN32
+#if ! defined(_WIN32) && !defined(ANDROID)
query_data->fd_in = -1;
query_data->fd_out = -1;
#endif
@@ -279,12 +282,14 @@ purple_srv_txt_query_destroy(PurpleSrvTx
return;
}
g_free(query_data->error_message);
-#else
+#elif !defined(ANDROID)
if (query_data->fd_out != -1)
close(query_data->fd_out);
if (query_data->fd_in != -1)
close(query_data->fd_in);
#endif
+ /* Android only uses ui ops. */
+
g_free(query_data->query);
g_free(query_data);
}
@@ -303,7 +308,7 @@ dns_str_is_ascii(const char *name)
}
#endif
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(ANDROID)
static void
write_to_parent(int in, int out, gconstpointer data, gsize size)
{
@@ -474,7 +479,7 @@ static void
resolved(gpointer data, gint source, PurpleInputCondition cond)
{
int size;
- int type;
+ PurpleDnsType type;
PurpleSrvTxtQueryData *query_data = (PurpleSrvTxtQueryData*)data;
int i;
int status;
@@ -569,7 +574,7 @@ resolved(gpointer data, gint source, Pur
purple_srv_txt_query_destroy(query_data);
}
-#else /* _WIN32 */
+#elif !defined(ANDROID) /* _WIN32 */
/** The Jabber Server code was inspiration for parts of this. */
@@ -635,7 +640,7 @@ static gpointer
res_thread(gpointer data)
{
PDNS_RECORD dr = NULL;
- int type;
+ PurpleDnsType type;
DNS_STATUS ds;
PurpleSrvTxtQueryData *query_data = data;
type = query_data->type;
@@ -714,7 +719,8 @@ res_thread(gpointer data)
g_thread_exit(NULL);
return NULL;
}
-
+#else /* ANDROID */
+/* Android only supports ui ops because its libc does not include res_*. */
#endif
PurpleSrvTxtQueryData *
@@ -773,7 +779,7 @@ purple_srv_resolve(PurpleAccount *accoun
return query_data;
}
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(ANDROID)
if(pipe(in) || pipe(out)) {
purple_debug_error("dnssrv", "Could not create pipe\n");
g_free(query);
@@ -825,7 +831,7 @@ purple_srv_resolve(PurpleAccount *accoun
query_data->handle = purple_input_add(out[0], PURPLE_INPUT_READ, resolved, query_data);
return query_data;
-#else
+#elif !defined(ANDROID)
query_data->resolver = g_thread_try_new("dnssrv srv resolver", res_thread, query_data, &err);
if (query_data->resolver == NULL) {
query_data->error_message = g_strdup_printf("SRV thread create failure: %s\n", (err && err->message) ? err->message : "");
@@ -841,6 +847,10 @@ purple_srv_resolve(PurpleAccount *accoun
query_data->handle = purple_timeout_add(0, res_main_thread_cb, query_data);
return query_data;
+#else /* ANDROID */
+ /* Android needs UI ops. */
+ query_data->error_message = "UI ops not implemented.";
+ return query_data;
#endif
}
@@ -894,7 +904,7 @@ PurpleSrvTxtQueryData *purple_txt_resolv
return query_data;
}
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(ANDROID)
if(pipe(in) || pipe(out)) {
purple_debug_error("dnssrv", "Could not create pipe\n");
g_free(query);
@@ -946,7 +956,7 @@ PurpleSrvTxtQueryData *purple_txt_resolv
query_data->handle = purple_input_add(out[0], PURPLE_INPUT_READ, resolved, query_data);
return query_data;
-#else
+#elif !defined(ANDROID)
query_data->resolver = g_thread_try_new("dnssrv srv resolver", res_thread, query_data, &err);
if (query_data->resolver == NULL) {
query_data->error_message = g_strdup_printf("TXT thread create failure: %s\n", (err && err->message) ? err->message : "");
@@ -962,6 +972,10 @@ PurpleSrvTxtQueryData *purple_txt_resolv
query_data->handle = purple_timeout_add(0, res_main_thread_cb, query_data);
return query_data;
+#else /* ANDROID */
+ /* Android needs to implement UI ops. */
+ query_data->error_message = "UI ops not implemented.";
+ return query_data;
#endif
}
@@ -991,8 +1005,6 @@ purple_srv_query_resolved(PurpleSrvTxtQu
PurpleSrvResponse *records_array;
int i = 0, length;
- g_return_if_fail(records != NULL);
-
if (query_data->cb.srv == NULL) {
purple_srv_txt_query_destroy(query_data);
@@ -1030,8 +1042,6 @@ purple_srv_query_resolved(PurpleSrvTxtQu
static void
purple_txt_query_resolved(PurpleSrvTxtQueryData *query_data, GList *entries)
{
- g_return_if_fail(entries != NULL);
-
purple_debug_info("dnssrv", "TXT entries resolved for %s, count: %d\n", query_data->query, g_list_length(entries));
/* the callback should g_free the entries.
@@ -1085,6 +1095,22 @@ purple_srv_txt_query_get_ui_ops(void)
return srv_txt_query_ui_ops;
}
+void *
+purple_srv_txt_query_get_ui_data(PurpleSrvTxtQueryData *query_data)
+{
+ g_return_val_if_fail(query_data != NULL, NULL);
+
+ return query_data->ui_data;
+}
+
+void
+purple_srv_txt_query_set_ui_data(PurpleSrvTxtQueryData *query_data, void *ui_data)
+{
+ g_return_if_fail(query_data != NULL);
+
+ query_data->ui_data = ui_data;
+}
+
char *
purple_srv_txt_query_get_query(PurpleSrvTxtQueryData *query_data)
{
@@ -1094,7 +1120,7 @@ purple_srv_txt_query_get_query(PurpleSrv
}
-int
+PurpleDnsType
purple_srv_txt_query_get_type(PurpleSrvTxtQueryData *query_data)
{
g_return_val_if_fail(query_data != NULL, 0);
diff --git a/libpurple/dnssrv.h b/libpurple/dnssrv.h
--- a/libpurple/dnssrv.h
+++ b/libpurple/dnssrv.h
@@ -29,11 +29,12 @@ typedef struct _PurpleSrvResponse Purple
typedef struct _PurpleTxtResponse PurpleTxtResponse;
#include <glib.h>
+#include "account.h"
-enum PurpleDnsType {
+typedef enum {
PurpleDnsTypeTxt = 16,
PurpleDnsTypeSrv = 33
More information about the Commits
mailing list