changeset 21466:7a05b6f84545

Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
author Daniel Atallah <daniel.atallah@gmail.com>
date Tue, 13 Nov 2007 04:29:06 +0000
parents e489c81e1f6f
children 3d70e3ec8a47
files ChangeLog.API libpurple/network.c libpurple/network.h libpurple/protocols/bonjour/bonjour_ft.c libpurple/protocols/bonjour/jabber.c
diffstat 5 files changed, 73 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Tue Nov 13 02:20:58 2007 +0000
+++ b/ChangeLog.API	Tue Nov 13 04:29:06 2007 +0000
@@ -50,6 +50,9 @@
 		* purple_util_init()
 		* purple_util_uninit()
 
+		* purple_network_listen_map_external() to temporarily disable
+		  mapping ports externally via NAT-PMP or UPnP.
+
 		* pidgin_dialogs_about_with_parent()
 		* pidgin_log_show_contact_with_parent()
 		* pidgin_log_show_with_parent()
--- a/libpurple/network.c	Tue Nov 13 02:20:58 2007 +0000
+++ b/libpurple/network.c	Tue Nov 13 04:29:06 2007 +0000
@@ -259,6 +259,12 @@
 	return FALSE;
 }
 
+static gboolean listen_map_external = TRUE;
+void purple_network_listen_map_external(gboolean map_external)
+{
+	listen_map_external = map_external;
+}
+
 static PurpleNetworkListenData *
 purple_network_do_listen(unsigned short port, int socket_type, PurpleNetworkListenCallback cb, gpointer cb_data)
 {
@@ -356,11 +362,17 @@
 	listen_data->cb_data = cb_data;
 	listen_data->socket_type = socket_type;
 
+	if (!listen_map_external)
+	{
+		purple_debug_info("network", "Skipping external port mapping.\n");
+		/* The pmp_map_cb does what we want to do */
+		purple_timeout_add(0, purple_network_finish_pmp_map_cb, listen_data);
+	}
 	/* Attempt a NAT-PMP Mapping, which will return immediately */
-	if (purple_pmp_create_map(((socket_type == SOCK_STREAM) ? PURPLE_PMP_TYPE_TCP : PURPLE_PMP_TYPE_UDP),
+	else if (purple_pmp_create_map(((socket_type == SOCK_STREAM) ? PURPLE_PMP_TYPE_TCP : PURPLE_PMP_TYPE_UDP),
 							  actual_port, actual_port, PURPLE_PMP_LIFETIME))
 	{
-		purple_debug_info("network", "Created NAT-PMP mapping on port %i\n",actual_port);
+		purple_debug_info("network", "Created NAT-PMP mapping on port %i\n", actual_port);
 		/* We want to return listen_data now, and on the next run loop trigger the cb and destroy listen_data */
 		purple_timeout_add(0, purple_network_finish_pmp_map_cb, listen_data);
 	}
@@ -567,7 +579,7 @@
 
 		retval = WSALookupServiceEnd(h);
 
-		g_idle_add(wpurple_network_change_thread_cb, NULL);
+		purple_timeout_add(0, wpurple_network_change_thread_cb, NULL);
 
 	}
 
--- a/libpurple/network.h	Tue Nov 13 02:20:58 2007 +0000
+++ b/libpurple/network.h	Tue Nov 13 04:29:06 2007 +0000
@@ -106,6 +106,20 @@
  */
 const char *purple_network_get_my_ip(int fd);
 
+#ifndef PURPLE_DISABLE_DEPRECATED
+/**
+ * Should calls to purple_network_listen() and purple_network_listen_range()
+ * map the port externally using NAT-PMP or UPnP?
+ * The default value is TRUE
+ *
+ * @param map_external Should the open port be mapped externally?
+ * @deprecated In 3.0.0 a boolean will be added to the above functions to
+ *             perform the same function.
+ * @since 2.3.0
+ */
+void purple_network_listen_map_external(gboolean map_external);
+#endif
+
 /**
  * Attempts to open a listening port ONLY on the specified port number.
  * You probably want to use purple_network_listen_range() instead of this.
--- a/libpurple/protocols/bonjour/bonjour_ft.c	Tue Nov 13 02:20:58 2007 +0000
+++ b/libpurple/protocols/bonjour/bonjour_ft.c	Tue Nov 13 04:29:06 2007 +0000
@@ -58,7 +58,7 @@
 	if(!xf)
 		return;
 
-	purple_debug_info("Bonjour", "xep file transfer stream initialization error.\n");
+	purple_debug_info("bonjour", "xep file transfer stream initialization error.\n");
 	iq = xep_iq_new(xf->data, XEP_IQ_ERROR, to, xf->sid);
 	if(iq == NULL)
 		return;
@@ -79,27 +79,27 @@
 
 static void bonjour_xfer_cancel_send(PurpleXfer *xfer)
 {
-	purple_debug_info("Bonjour", "Bonjour-xfer-cancel-send.\n");
+	purple_debug_info("bonjour", "Bonjour-xfer-cancel-send.\n");
 	bonjour_free_xfer(xfer);
 }
 
 static void bonjour_xfer_request_denied(PurpleXfer *xfer)
 {
-	purple_debug_info("Bonjour", "Bonjour-xfer-request-denied.\n");
+	purple_debug_info("bonjour", "Bonjour-xfer-request-denied.\n");
 	xep_ft_si_reject(xfer, xfer->who);
 	bonjour_free_xfer(xfer);
 }
 
 static void bonjour_xfer_cancel_recv(PurpleXfer *xfer)
 {
-	purple_debug_info("Bonjour", "Bonjour-xfer-cancel-recv.\n");
+	purple_debug_info("bonjour", "Bonjour-xfer-cancel-recv.\n");
 	bonjour_free_xfer(xfer);
 }
 
 
 static void bonjour_xfer_end(PurpleXfer *xfer)
 {
-	purple_debug_info("Bonjour", "Bonjour-xfer-end.\n");
+	purple_debug_info("bonjour", "Bonjour-xfer-end.\n");
 	bonjour_free_xfer(xfer);
 }
 
@@ -113,7 +113,7 @@
 	if(!sid || !from || !bd)
 		return NULL;
 
-	purple_debug_info("Bonjour", "Look for sid=%s from=%s xferlists.\n",
+	purple_debug_info("bonjour", "Look for sid=%s from=%s xferlists.\n",
 			  sid, from);
 
 	for(xfers = bd->xfer_lists; xfers; xfers = xfers->next) {
@@ -128,7 +128,7 @@
 			return xfer;
 	}
 
-	purple_debug_info("Bonjour", "Look for xfer list fail\n");
+	purple_debug_info("bonjour", "Look for xfer list fail\n");
 
 	return NULL;
 }
@@ -156,7 +156,7 @@
 	if(!bd)
 		return;
 
-	purple_debug_info("Bonjour", "xep file transfer stream initialization offer-id=%d.\n", next_id);
+	purple_debug_info("bonjour", "xep file transfer stream initialization offer-id=%d.\n", next_id);
 
 	/* Assign stream id. */
 	memset(buf, 0, 32);
@@ -215,7 +215,7 @@
 	if(!to || !sid)
 		return;
 
-	purple_debug_info("Bonjour", "xep file transfer stream initialization error.\n");
+	purple_debug_info("bonjour", "xep file transfer stream initialization error.\n");
 	iq = xep_iq_new(bd, XEP_IQ_ERROR, to, sid);
 	if(iq == NULL)
 		return;
@@ -251,7 +251,7 @@
 	if(!xf)
 		return;
 
-	purple_debug_info("Bonjour", "xep file transfer stream initialization result.\n");
+	purple_debug_info("bonjour", "xep file transfer stream initialization result.\n");
 	iq = xep_iq_new(xf->data, XEP_IQ_RESULT, to, xf->sid);
 	if(iq == NULL)
 		return;
@@ -282,18 +282,18 @@
 	BonjourData *bd = NULL;
 
 	if(xfer == NULL) {
-		purple_debug_info("Bonjour", "bonjour-free-xfer-null.\n");
+		purple_debug_info("bonjour", "bonjour-free-xfer-null.\n");
 		return;
 	}
 
-	purple_debug_info("Bonjour", "bonjour-free-xfer-%p.\n", xfer);
+	purple_debug_info("bonjour", "bonjour-free-xfer-%p.\n", xfer);
 
 	xf = (XepXfer*)xfer->data;
 	if(xf != NULL) {
 		bd = (BonjourData*)xf->data;
 		if(bd != NULL) {
 			bd->xfer_lists = g_list_remove(bd->xfer_lists, xfer);
-			purple_debug_info("Bonjour", "B free xfer from lists(%p).\n", bd->xfer_lists);
+			purple_debug_info("bonjour", "B free xfer from lists(%p).\n", bd->xfer_lists);
 		}
 		if (xf->proxy_connection != NULL)
 			purple_proxy_connect_cancel(xf->proxy_connection);
@@ -307,7 +307,7 @@
 		xfer->data = NULL;
 	}
 
-	purple_debug_info("Bonjour", "Need close socket=%d.\n", xfer->fd);
+	purple_debug_info("bonjour", "Need close socket=%d.\n", xfer->fd);
 }
 
 PurpleXfer *
@@ -320,7 +320,7 @@
 	if(who == NULL || gc == NULL)
 		return NULL;
 
-	purple_debug_info("Bonjour", "Bonjour-new-xfer to %s.\n", who);
+	purple_debug_info("bonjour", "Bonjour-new-xfer to %s.\n", who);
 	bd = (BonjourData*) gc->proto_data;
 	if(bd == NULL)
 		return NULL;
@@ -330,7 +330,7 @@
 	xfer->data = xep_xfer = g_new0(XepXfer, 1);
 	xep_xfer->data = bd;
 
-	purple_debug_info("Bonjour", "Bonjour-new-xfer bd=%p data=%p.\n", bd, xep_xfer->data);
+	purple_debug_info("bonjour", "Bonjour-new-xfer bd=%p data=%p.\n", bd, xep_xfer->data);
 
 	xep_xfer->mode = XEP_BYTESTREAMS | XEP_IBB;
 	xep_xfer->sid = NULL;
@@ -351,7 +351,7 @@
 	PurpleXfer *xfer = NULL;
 	if(gc == NULL || who == NULL)
 		return;
-	purple_debug_info("Bonjour", "Bonjour-send-file to=%s.\n", who);
+	purple_debug_info("bonjour", "Bonjour-send-file to=%s.\n", who);
 	xfer = bonjour_new_xfer(gc, who);
 	if(xfer == NULL)
 		return;
@@ -374,7 +374,7 @@
 	xf = (XepXfer*)xfer->data;
 	if(xf == NULL)
 		return;
-	purple_debug_info("Bonjour", "Bonjour-xfer-init.\n");
+	purple_debug_info("bonjour", "Bonjour-xfer-init.\n");
 
 	buddy = purple_find_buddy(xfer->account, xfer->who);
 	/* this buddy is offline. */
@@ -385,13 +385,13 @@
 	xf->buddy_ip = g_strdup(bd->ip);
 	if (purple_xfer_get_type(xfer) == PURPLE_XFER_SEND) {
 		/* initiate file transfer, send SI offer. */
-		purple_debug_info("Bonjour", "Bonjour xfer type is PURPLE_XFER_SEND.\n");
+		purple_debug_info("bonjour", "Bonjour xfer type is PURPLE_XFER_SEND.\n");
 		xep_ft_si_offer(xfer, xfer->who);
 
 	} else {
 		/* accept file transfer request, send SI result. */
 		xep_ft_si_result(xfer, xfer->who);
-		purple_debug_info("Bonjour", "Bonjour xfer type is PURPLE_XFER_RECEIVE.\n");
+		purple_debug_info("bonjour", "Bonjour xfer type is PURPLE_XFER_RECEIVE.\n");
 	}
 	return;
 }
@@ -413,7 +413,7 @@
 	if(bd == NULL)
 		return;
 
-	purple_debug_info("Bonjour", "xep-si-parse.\n");
+	purple_debug_info("bonjour", "xep-si-parse.\n");
 
 	type = xmlnode_get_attrib(packet, "type");
 	from = pb->name;
@@ -421,7 +421,7 @@
 	if(type) {
 		if(!strcmp(type, "set")){
 			si = xmlnode_get_child(packet,"si");
-			purple_debug_info("Bonjour", "si offer Message type - SET.\n");
+			purple_debug_info("bonjour", "si offer Message type - SET.\n");
 			file = xmlnode_get_child(si, "file");
 			/**/
 			filename = xmlnode_get_attrib(file, "name");
@@ -430,24 +430,24 @@
 			bonjour_xfer_receive(pc, id, from, filesize, filename, option);
 		} else if(!strcmp(type, "result")){
 			si = xmlnode_get_child(packet,"si");
-			purple_debug_info("Bonjour", "si offer Message type - RESULT.\n");
+			purple_debug_info("bonjour", "si offer Message type - RESULT.\n");
 			xfer = bonjour_si_xfer_find(bd, id, from);
 			if(xfer == NULL){
-				purple_debug_info("Bonjour", "xfer find fail.\n");
+				purple_debug_info("bonjour", "xfer find fail.\n");
 				xep_ft_si_reject2((BonjourData *)pc->proto_data, from, id);
 			} else {
 				bonjour_bytestreams_init(xfer);
 			}
 		} else if(!strcmp(type, "error")){
-			purple_debug_info("Bonjour", "si offer Message type - ERROR.\n");
+			purple_debug_info("bonjour", "si offer Message type - ERROR.\n");
 			xfer = bonjour_si_xfer_find(bd, id, from);
 			if(xfer == NULL){
-				purple_debug_info("Bonjour", "xfer find fail.\n");
+				purple_debug_info("bonjour", "xfer find fail.\n");
 			} else {
 				purple_xfer_cancel_remote(xfer);
 			}
 		} else {
-			purple_debug_info("Bonjour", "si offer Message type - Unknown-%d.\n", type);
+			purple_debug_info("bonjour", "si offer Message type - Unknown-%d.\n", type);
 		}
 	}
 }
@@ -470,14 +470,14 @@
 	if(bd == NULL)
 		return;
 
-	purple_debug_info("Bonjour", "xep-bytestreams-parse.\n");
+	purple_debug_info("bonjour", "xep-bytestreams-parse.\n");
 
 	type = xmlnode_get_attrib(packet, "type");
 	from = pb->name;
 	query = xmlnode_get_child(packet,"query");
 	if(type) {
 		if(!strcmp(type, "set")){
-			purple_debug_info("Bonjour", "bytestream offer Message type - SET.\n");
+			purple_debug_info("bonjour", "bytestream offer Message type - SET.\n");
 
 			id = xmlnode_get_attrib(query, "sid");
 			xfer = bonjour_si_xfer_find(bd, id, from);
@@ -497,14 +497,14 @@
 							xf->jid = g_strdup(jid);
 							xf->proxy_host = g_strdup(host);
 							xf->proxy_port = portnum;
-							purple_debug_info("Bonjour", "bytestream offer parse"
+							purple_debug_info("bonjour", "bytestream offer parse"
 									  "jid=%s host=%s port=%d.\n", jid, host, portnum);
 							bonjour_bytestreams_connect(xfer);
 							break;
 						}
 
 					} else {
-						purple_debug_info("Bonjour", "bytestream offer Message parse error.\n");
+						purple_debug_info("bonjour", "bytestream offer Message parse error.\n");
 					}
 				}
 			} else {
@@ -512,7 +512,7 @@
 			}
 
 		} else {
-			purple_debug_info("Bonjour", "bytestream offer Message type - Unknown-%d.\n", type);
+			purple_debug_info("bonjour", "bytestream offer Message type - Unknown-%d.\n", type);
 		}
 	}
 }
@@ -532,7 +532,7 @@
 	if(bd == NULL)
 		return;
 
-	purple_debug_info("Bonjour", "bonjour-xfer-receive.\n");
+	purple_debug_info("bonjour", "bonjour-xfer-receive.\n");
 
 	/* Build the file transfer handle */
 	xfer = purple_xfer_new(pc->account, PURPLE_XFER_RECEIVE, from);
@@ -576,7 +576,7 @@
 		} else if(acceptfd == -1) {
 
 		} else {
-			purple_debug_info("Bonjour", "Conjour-sock5-request-cb. state= %d, accept=%d\n", xf->sock5_req_state, acceptfd);
+			purple_debug_info("bonjour", "Conjour-sock5-request-cb. state= %d, accept=%d\n", xf->sock5_req_state, acceptfd);
 			purple_input_remove(xfer->watcher);
 			close(source);
 			xfer->watcher = purple_input_add(acceptfd, PURPLE_INPUT_READ,
@@ -681,7 +681,7 @@
 	const char *local_ip = NULL;
 	char token [] = ";";
 
-	purple_debug_info("Bonjour", "Bonjour-bytestreams-listen. sock=%d.\n", sock);
+	purple_debug_info("bonjour", "Bonjour-bytestreams-listen. sock=%d.\n", sock);
 	if (sock < 0 || xfer == NULL) {
 		/*purple_xfer_cancel_local(xfer);*/
 		return;
@@ -724,10 +724,12 @@
 	XepXfer *xf = NULL;
 	if(xfer == NULL)
 		return;
-	purple_debug_info("Bonjour", "Bonjour-bytestreams-init.\n");
+	purple_debug_info("bonjour", "Bonjour-bytestreams-init.\n");
 	xf = xfer->data;
+	purple_network_listen_map_external(FALSE);
 	xf->listen_data = purple_network_listen_range(0, 0, SOCK_STREAM,
 						      bonjour_bytestreams_listen, xfer);
+	purple_network_listen_map_external(TRUE);
 	if (xf->listen_data == NULL) {
 		purple_xfer_cancel_local(xfer);
 	}
@@ -762,7 +764,7 @@
 	if(xfer == NULL)
 		return;
 
-	purple_debug_info("Bonjour", "bonjour-bytestreams-connect.\n");
+	purple_debug_info("bonjour", "bonjour-bytestreams-connect.\n");
 
 	xf = (XepXfer*)xfer->data;
 	if(!xf)
--- a/libpurple/protocols/bonjour/jabber.c	Tue Nov 13 02:20:58 2007 +0000
+++ b/libpurple/protocols/bonjour/jabber.c	Tue Nov 13 04:29:06 2007 +0000
@@ -733,7 +733,7 @@
 		PurpleProxyConnectData *connect_data;
 		PurpleProxyInfo *proxy_info;
 
-		purple_debug_info("Bonjour", "Starting conversation with %s\n", to);
+		purple_debug_info("bonjour", "Starting conversation with %s\n", to);
 
 		/* Make sure that the account always has a proxy of "none".
 		 * This is kind of dirty, but proxy_connect_none() isn't exposed. */
@@ -928,7 +928,7 @@
 
 	for(l = acc->deny; l != NULL; l = l->next) {
 		if(!purple_utf8_strcasecmp(pb->name, (char *)l->data)) {
-			purple_debug_info("Bonjour", "%s has been blocked.\n", pb->name, acc->username);
+			purple_debug_info("bonjour", "%s has been blocked.\n", pb->name, acc->username);
 			blocked = TRUE;
 			break;
 		}