changeset 26589:400f74b95c0e

First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
author Paul Aurich <paul@darkrain42.org>
date Sat, 11 Apr 2009 20:31:19 +0000
parents 538b4175fd24
children acee7d2b1983
files libpurple/dnssrv.c libpurple/dnssrv.h libpurple/protocols/jabber/jabber.c
diffstat 3 files changed, 34 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/dnssrv.c	Sat Apr 11 04:39:48 2009 +0000
+++ b/libpurple/dnssrv.c	Sat Apr 11 20:31:19 2009 +0000
@@ -183,7 +183,7 @@
 			ret = g_list_insert_sorted(ret, srvres, responsecompare);
 		} else if (query.type == T_TXT) {
 			txtres = g_new0(PurpleTxtResponse, 1);
-			strncpy(txtres->content, (gchar*)(++cp), dlen-1);
+			txtres->content = g_strndup((gchar*)(++cp), dlen-1);
 			ret = g_list_append(ret, txtres);
 			cp += dlen - 1;
 		} else {
@@ -389,7 +389,33 @@
 			MyDnsRecordListFree(dr, DnsFreeRecordList);
 			query_data->results = lst;
 		} else if (type == T_TXT) {
-			#error IMPLEMENTATION MISSING		
+			PDNS_RECORD dr_tmp;
+			GSList *lst = NULL;
+			DNS_TXT_DATA *txt_data;
+			PurpleTxtResponse *txtres;
+
+			for (dr_tmp = dr; dr_tmp != NULL; dr_tmp = dr_tmp->pNext) {
+				GString *s;
+				int i;
+
+				/* Discard any incorrect entries. I'm not sure if this is necessary */
+				if (dr_tmp->wType != type || strcmp(dr_tmp->pName, query_data->query) != 0) {
+					continue;
+				}
+
+				txt_data = &dr_tmp->Data.TXT;
+				txtres = g_new0(PurpleTxtResponse, 1);
+
+				s = g_string_new("");
+				for (i = 0; i < txt_data->dwStringCount; ++i)
+					s = g_string_append(s, txt_data->pStringArray[i]);
+				txtres->content = g_string_free(s, FALSE);
+
+				lst = g_slist_append(lst, txtres);
+			}
+
+			MyDnsRecordListFree(dr, DnsFreeRecordList);
+			query_data->results = lst;
 		} else {
 			
 		}
--- a/libpurple/dnssrv.h	Sat Apr 11 04:39:48 2009 +0000
+++ b/libpurple/dnssrv.h	Sat Apr 11 20:31:19 2009 +0000
@@ -40,7 +40,7 @@
 };
 
 struct _PurpleTxtResponse {
-    char content[256];
+    char *content;
 };
 
 typedef void (*PurpleSrvCallback)(PurpleSrvResponse *resp, int results, gpointer data);
--- a/libpurple/protocols/jabber/jabber.c	Sat Apr 11 04:39:48 2009 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Sat Apr 11 20:31:19 2009 +0000
@@ -617,6 +617,11 @@
 	} else {
 		purple_debug_info("jabber","Didn't find an alternative connection method.\n");
 	}
+
+	for (n = 0; n < results; ++n)
+		g_free(resp[n].content);
+
+	g_free(resp);
 }
 
 static void