pidgin: d8736814: Call res_init() when DNS queries fail in...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Fri May 22 01:35:56 EDT 2009


-----------------------------------------------------------------
Revision: d8736814cb67ade87f1a48b8ff85c8690327fa71
Ancestor: f85ecfecb74adc7eb5b966a0d51ee930610fe837
Author: darkrain42 at pidgin.im
Date: 2009-05-22T04:44:07
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/d8736814cb67ade87f1a48b8ff85c8690327fa71

Modified files:
        ChangeLog libpurple/dnsquery.c libpurple/dnssrv.c

ChangeLog: 

Call res_init() when DNS queries fail in case the failure indicates a timeout
because we've moved networks.  Closes #2825.

-------------- next part --------------
============================================================
--- ChangeLog	af557f765c6a4e5b022ae1f90c3c1f030eadd28c
+++ ChangeLog	5ac03d1f17bf67264fcad4f09f5d8e0d8c9c541e
@@ -16,6 +16,8 @@ version 2.6.0 (??/??/2009):
 	* Report idle time 'From last message sent' should work properly.
 	* Show the invite message for buddies that requested authorization
 	  from you on MSN.
+	* DNS servers are re-read when DNS queries fail in case the system has
+	  moved to a new network and the old servers are not accessible.
 
 	XMPP:
 	* Voice & Video support with Jingle (XEP-0166, 0167, 0176, & 0177), and
============================================================
--- libpurple/dnsquery.c	425461336daaa45e12a84427cd9f069ac36aaa4a
+++ libpurple/dnsquery.c	c5dea896243eb2208c7b9e3d6b6b9324926d344a
@@ -32,6 +32,10 @@
 #include "prefs.h"
 #include "util.h"
 
+#ifndef _WIN32
+#include <resolv.h>
+#endif
+
 #if (defined(__APPLE__) || defined (__unix__)) && !defined(__osf__)
 #define PURPLE_DNSQUERY_USE_FORK
 #endif
@@ -571,8 +575,10 @@ host_resolved(gpointer data, gint source
 		g_snprintf(message, sizeof(message), _("Error resolving %s: %d"),
 				query_data->hostname, err);
 #endif
-		purple_dnsquery_failed(query_data, message);
+		/* Re-read resolv.conf and friends in case DNS servers have changed */
+		res_init();
 
+		purple_dnsquery_failed(query_data, message);
 	} else if (rc > 0) {
 		/* Success! */
 		while (rc > 0) {
============================================================
--- libpurple/dnssrv.c	a7fca9783cc0416e9f9061c9a1447b4b69385bff
+++ libpurple/dnssrv.c	bff87e8353d0a656f6ad248732109149616c6924
@@ -141,7 +141,14 @@ resolve(int in, int out)
 	}
 
 	size = res_query( query.query, C_IN, query.type, (u_char*)&answer, sizeof( answer));
-	
+	if (size == -1) {
+		write(out, &(query.type), sizeof(query.type));
+		write(out, &size, sizeof(int));
+		close(out);
+		close(in);
+		_exit(0);
+	}
+
 	qdcount = ntohs(answer.hdr.qdcount);
 	ancount = ntohs(answer.hdr.ancount);
 	cp = (guchar*)&answer + sizeof(HEADER);
@@ -223,59 +230,73 @@ resolved(gpointer data, gint source, Pur
 	PurpleSrvQueryData *query_data = (PurpleSrvQueryData*)data;
 	int i;
 	int status;
-	
+
 	if (read(source, &type, sizeof(type)) == sizeof(type)) {
-		if (type == T_SRV) {
-			PurpleSrvResponse *res;
-			PurpleSrvResponse *tmp;
-			PurpleSrvCallback cb = query_data->cb.srv;
-			if (read(source, &size, sizeof(int)) == sizeof(int)) {
-				ssize_t red;
-				purple_debug_info("dnssrv","found %d SRV entries\n", size);
-				tmp = res = g_new0(PurpleSrvResponse, size);
-				for (i = 0; i < size; i++) {
-					red = read(source, tmp++, sizeof(PurpleSrvResponse));
-					if (red != sizeof(PurpleSrvResponse)) {
-						purple_debug_error("dnssrv","unable to read srv "
-								"response: %s\n", g_strerror(errno));
-						size = 0;
-						g_free(res);
-						res = NULL;
-					}
+		if (read(source, &size, sizeof(size)) == sizeof(size)) {
+			if (size == -1 || size == 0) {
+				if (size == -1) {
+					purple_debug_warning("dnssrv", "res_query returned an error\n");
+					/* Re-read resolv.conf and friends in case DNS servers have changed */
+					res_init();
+				} else
+					purple_debug_info("dnssrv", "Found 0 entries, errno is %i\n", errno);
+
+				if (type == T_SRV) {
+					PurpleSrvCallback cb = query_data->cb.srv;
+					cb(NULL, 0, query_data->extradata);
+				} else if (type == T_TXT) {
+					PurpleTxtCallback cb = query_data->cb.txt;
+					cb(NULL, query_data->extradata);
+				} else {
+					purple_debug_error("dnssrv", "type unknown of DNS result entry; errno is %i\n", errno);
 				}
-			} else {
-				purple_debug_info("dnssrv","found 0 SRV entries; errno is %i\n", errno);
-				size = 0;
-				res = NULL;
-			}
-			cb(res, size, query_data->extradata);
-		} else if (type == T_TXT) {
-			GSList *responses = NULL;
-			PurpleTxtResponse *res;
-			PurpleTxtCallback cb = query_data->cb.txt;
-			if (read(source, &size, sizeof(int)) == sizeof(int)) {
-				ssize_t red;
-				purple_debug_info("dnssrv","found %d TXT entries\n", size);
-				res = g_new0(PurpleTxtResponse, 1);
-				for (i = 0; i < size; i++) {
-					red = read(source, res, sizeof(PurpleTxtResponse));
-					if (red != sizeof(PurpleTxtResponse)) {
-						purple_debug_error("dnssrv","unable to read txt "
-								"response: %s\n", g_strerror(errno));
-						size = 0;
-						g_free(res);
-						g_slist_foreach(responses, (GFunc)purple_txt_response_destroy, NULL);
-						g_slist_free(responses);
-						responses = NULL;
-						break;
+
+			} else if (size) {
+				if (type == T_SRV) {
+					PurpleSrvResponse *res;
+					PurpleSrvResponse *tmp;
+					PurpleSrvCallback cb = query_data->cb.srv;
+					ssize_t red;
+					purple_debug_info("dnssrv","found %d SRV entries\n", size);
+					tmp = res = g_new0(PurpleSrvResponse, size);
+					for (i = 0; i < size; i++) {
+						red = read(source, tmp++, sizeof(PurpleSrvResponse));
+						if (red != sizeof(PurpleSrvResponse)) {
+							purple_debug_error("dnssrv","unable to read srv "
+									"response: %s\n", g_strerror(errno));
+							size = 0;
+							g_free(res);
+							res = NULL;
+						}
 					}
+
+					cb(res, size, query_data->extradata);
+				} else if (type == T_TXT) {
+					GSList *responses = NULL;
+					PurpleTxtResponse *res;
+					PurpleTxtCallback cb = query_data->cb.txt;
+					ssize_t red;
+					purple_debug_info("dnssrv","found %d TXT entries\n", size);
+					res = g_new0(PurpleTxtResponse, 1);
+					for (i = 0; i < size; i++) {
+						red = read(source, res, sizeof(PurpleTxtResponse));
+						if (red != sizeof(PurpleTxtResponse)) {
+							purple_debug_error("dnssrv","unable to read txt "
+									"response: %s\n", g_strerror(errno));
+							size = 0;
+							g_free(res);
+							g_slist_foreach(responses, (GFunc)purple_txt_response_destroy, NULL);
+							g_slist_free(responses);
+							responses = NULL;
+							break;
+						}
+					}
+
+					cb(responses, query_data->extradata);
+				} else {
+					purple_debug_error("dnssrv", "type unknown of DNS result entry; errno is %i\n", errno);
 				}
-			} else {
-				purple_debug_info("dnssrv","found 0 TXT entries; errno is %i\n", errno);
 			}
-			cb(responses, query_data->extradata);			
-		} else {
-			purple_debug_info("dnssrv","type unknown of DNS result entry; errno is %i\n", errno);
 		}
 	}
 


More information about the Commits mailing list