changeset 25766:d853f56dad8b

dnssrv.c: * Use a callback enum * Fix up the WIN32 code _a little_. I think it should compile now... Right up to the #error pragma.
author Paul Aurich <paul@darkrain42.org>
date Sun, 23 Nov 2008 05:45:26 +0000
parents a259d2711416
children 816c096d1ea8
files libpurple/dnssrv.c
diffstat 1 files changed, 26 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/dnssrv.c	Sun Nov 23 03:52:40 2008 +0000
+++ b/libpurple/dnssrv.c	Sun Nov 23 05:45:26 2008 +0000
@@ -36,7 +36,7 @@
 #ifndef T_TXT
 #define T_TXT	16
 #endif
-#else
+#else /* WIN32 */
 #include <windns.h>
 /* Missing from the mingw headers */
 #ifndef DNS_TYPE_SRV
@@ -66,8 +66,11 @@
 #endif
 
 struct _PurpleSrvQueryData {
-	PurpleSrvCallback srv_cb;
-	PurpleTxtCallback txt_cb;
+	union {
+		PurpleSrvCallback srv;
+		PurpleTxtCallback txt;
+	} cb;
+
 	gpointer extradata;
 	guint handle;
 	int type;
@@ -122,7 +125,6 @@
 	gchar name[256];
 	guint16 type, dlen, pref, weight, port;
 	PurpleSrvInternalQuery query;
-	int n;
 
 #ifdef HAVE_SIGNAL_H
 	purple_restore_default_signal_handlers();
@@ -181,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, ++cp, dlen-1);
+			strncpy(txtres->content, (gchar*)(++cp), dlen-1);
 			ret = g_list_append(ret, txtres);
 			cp += dlen - 1;
 		} else {
@@ -220,7 +222,7 @@
 		if (type == T_SRV) {
 			PurpleSrvResponse *res;
 			PurpleSrvResponse *tmp;
-			PurpleSrvCallback cb = query_data->srv_cb;
+			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);
@@ -244,7 +246,7 @@
 		} else if (type == T_TXT) {
 			PurpleTxtResponse *res;
 			PurpleTxtResponse *tmp;
-			PurpleTxtCallback cb = query_data->txt_cb;
+			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);
@@ -260,7 +262,7 @@
 					}
 				}
 			} else {
-				purple_debug_info("dnssrv","found 0 SRV entries; errno is %i\n", errno);
+				purple_debug_info("dnssrv","found 0 TXT entries; errno is %i\n", errno);
 				size = 0;
 				res = NULL;
 			}
@@ -294,10 +296,10 @@
 
 			size = g_slist_length(lst);
 
-			if(query_data->srv_cb && size > 0)
+			if(query_data->cb.srv && size > 0)
 				srvres_tmp = srvres = g_new0(PurpleSrvResponse, size);
 			while (lst) {
-				if(query_data->cb)
+				if(query_data->cb.srv)
 					memcpy(srvres_tmp++, lst->data, sizeof(PurpleSrvResponse));
 				g_free(lst->data);
 				lst = g_slist_remove(lst, lst->data);
@@ -307,17 +309,17 @@
 
 			purple_debug_info("dnssrv", "found %d SRV entries\n", size);
 			
-			if(query_data->srv_cb) query_data->srv_cb(srvres, size, query_data->extradata);
+			if(query_data->cb.srv) query_data->cb.srv(srvres, size, query_data->extradata);
 		} else if (query_data->type == T_TXT) {
 			PurpleTxtResponse *txtres_tmp = NULL;
 			GSList *lst = query_data->results;
 
 			size = g_slist_length(lst);
 
-			if(query_data->txt_cb && size > 0)
+			if(query_data->cb.txt && size > 0)
 				txtres_tmp = txtres = g_new0(PurpleTxtResponse, size);
 			while (lst) {
-				if(query_data->txt_cb)
+				if(query_data->cb.txt)
 					memcpy(txtres_tmp++, lst->data, sizeof(PurpleTxtResponse));
 				g_free(lst->data);
 				lst = g_slist_remove(lst, lst->data);
@@ -327,7 +329,7 @@
 
 			purple_debug_info("dnssrv", "found %d TXT entries\n", size);
 			
-			if(query_data->txt_cb) query_data->txt_cb(txtres, size, query_data->extradata);
+			if(query_data->cb.txt) query_data->cb.txt(txtres, size, query_data->extradata);
 		} else {
 			purple_debug_error("dnssrv", "unknown query type");
 		}
@@ -352,14 +354,14 @@
 	ds = MyDnsQuery_UTF8(query_data->query, type, DNS_QUERY_STANDARD, NULL, &dr, NULL);
 	if (ds != ERROR_SUCCESS) {
 		gchar *msg = g_win32_error_message(ds);
-		if (type == T_SRV) {
+		if (type == DNS_TYPE_SRV) {
 			query_data->error_message = g_strdup_printf("Couldn't look up SRV record. %s (%lu).\n", msg, ds);
-		} else if (type == T_TXT) {
+		} else if (type == DNS_TYPE_TXT) {
 			query_data->error_message = g_strdup_printf("Couldn't look up TXT record. %s (%lu).\n", msg, ds);
 		}
 		g_free(msg);
 	} else {
-		if (type == T_SRV) {
+		if (type == DNS_TYPE_SRV) {
 			PDNS_RECORD dr_tmp;
 			GSList *lst = NULL;
 			DNS_SRV_DATA *srv_data;
@@ -457,7 +459,7 @@
 
 	query_data = g_new0(PurpleSrvQueryData, 1);
 	query_data->type = T_SRV;
-	query_data->srv_cb = cb;
+	query_data->cb.srv = cb;
 	query_data->extradata = extradata;
 	query_data->pid = pid;
 	query_data->fd_out = out[0];
@@ -476,7 +478,8 @@
 	}
 
 	query_data = g_new0(PurpleSrvQueryData, 1);
-	query_data->srv_cb = cb;
+	query_data->type = DNS_TYPE_SRV;
+	query_data->cb.srv = cb;
 	query_data->query = query;
 	query_data->extradata = extradata;
 
@@ -554,7 +557,7 @@
 
 	query_data = g_new0(PurpleSrvQueryData, 1);
 	query_data->type = T_TXT;
-	query_data->txt_cb = cb;
+	query_data->cb.txt = cb;
 	query_data->extradata = extradata;
 	query_data->pid = pid;
 	query_data->fd_out = out[0];
@@ -573,7 +576,8 @@
 	}
 
 	query_data = g_new0(PurpleSrvQueryData, 1);
-	query_data->txt_cb = cb;
+	query_data->type = DNS_TYPE_TXT;
+	query_data->cb.txt = cb;
 	query_data->query = query;
 	query_data->extradata = extradata;
 
@@ -610,7 +614,7 @@
 		 * just set the callback to NULL and let the DNS lookup
 		 * finish.
 		 */
-		query_data->cb = NULL;
+		query_data->cb.srv = NULL;
 		return;
 	}
 	g_free(query_data->query);