diff libpurple/dnssrv.c @ 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 e4a060a1e3de
children acee7d2b1983
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 {
 			
 		}