diff libpurple/dnsquery.c @ 15704:6a0b9734a722

The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
author Evan Schoenberg <evan.s@dreskin.net>
date Sun, 25 Feb 2007 18:43:25 +0000
parents 61b42cf81aa4
children 15123896e5c9
line wrap: on
line diff
--- a/libpurple/dnsquery.c	Sun Feb 25 18:35:08 2007 +0000
+++ b/libpurple/dnsquery.c	Sun Feb 25 18:43:25 2007 +0000
@@ -35,6 +35,8 @@
  * DNS query API
  **************************************************************************/
 
+static GaimDnsQueryUiOps *dns_query_ui_ops = NULL;
+
 typedef struct _GaimDnsQueryResolverProcess GaimDnsQueryResolverProcess;
 
 struct _GaimDnsQueryData {
@@ -114,6 +116,20 @@
 	gaim_dnsquery_destroy(query_data);
 }
 
+static gboolean
+gaim_dnsquery_ui_resolve(GaimDnsQueryData *query_data)
+{
+    GaimDnsQueryUiOps *ops = gaim_dnsquery_get_ui_ops();
+
+    if (ops && ops->resolve_host)
+    {
+        if (ops->resolve_host(query_data, gaim_dnsquery_resolved, gaim_dnsquery_failed))
+            return TRUE;
+    }
+
+	return FALSE;
+}
+
 #if defined(__unix__) || defined(__APPLE__)
 
 /*
@@ -157,7 +173,7 @@
 #endif
 
 #ifdef HAVE_SIGNAL_H
-	gaim_restore_default_signal_handlers();	
+	gaim_restore_default_signal_handlers();
 	signal(SIGTRAP, trap_gdb_bug);
 #endif
 
@@ -455,6 +471,13 @@
 	query_data = queued_requests->data;
 	queued_requests = g_slist_delete_link(queued_requests, queued_requests);
 
+    if (gaim_dnsquery_ui_resolve(query_data))
+    {
+        /* The UI is handling the resolve; we're done */
+    	handle_next_queued_request();
+    	return;
+    }
+
 	/*
 	 * If we have any children, attempt to have them perform the DNS
 	 * query.  If we're able to send the query then resolver will be
@@ -704,6 +727,12 @@
 	query_data = data;
 	query_data->timeout = 0;
 
+    if (gaim_dnsquery_ui_resolve(query_data))
+    {
+        /* The UI is handling the resolve; we're done */
+    	return FALSE;
+    }
+
 	if (inet_aton(query_data->hostname, &sin.sin_addr))
 	{
 		/*
@@ -788,6 +817,12 @@
 	query_data = data;
 	query_data->timeout = 0;
 
+    if (gaim_dnsquery_ui_resolve(query_data))
+    {
+        /* The UI is handling the resolve; we're done */
+    	return FALSE;
+    }
+
 	if (!inet_aton(query_data->hostname, &sin.sin_addr)) {
 		struct hostent *hp;
 		if(!(hp = gethostbyname(query_data->hostname))) {
@@ -846,6 +881,11 @@
 void
 gaim_dnsquery_destroy(GaimDnsQueryData *query_data)
 {
+    GaimDnsQueryUiOps *ops = gaim_dnsquery_get_ui_ops();
+
+    if (ops && ops->destroy)
+        ops->destroy(query_data);
+
 #if defined(__unix__) || defined(__APPLE__)
 	queued_requests = g_slist_remove(queued_requests, query_data);
 
@@ -887,6 +927,36 @@
 	g_free(query_data);
 }
 
+char *
+gaim_dnsquery_get_host(GaimDnsQueryData *query_data)
+{
+	g_return_val_if_fail(query_data != NULL, NULL);
+
+	return query_data->hostname;
+}
+
+int
+gaim_dnsquery_get_port(GaimDnsQueryData *query_data)
+{
+	g_return_val_if_fail(query_data != NULL, NULL);
+
+	return query_data->port;	
+}
+
+void
+gaim_dnsquery_set_ui_ops(GaimDnsQueryUiOps *ops)
+{
+	dns_query_ui_ops = ops;
+}
+
+GaimDnsQueryUiOps *
+gaim_dnsquery_get_ui_ops(void)
+{
+	g_return_val_if_fail(dns_query_ui_ops != NULL, NULL);
+
+	return dns_query_ui_ops;
+}
+
 void
 gaim_dnsquery_init(void)
 {