im.pidgin.pidgin: a3430424ec320991ba0e73fcd49b3c87526dd307

datallah at pidgin.im datallah at pidgin.im
Tue Nov 13 01:35:46 EST 2007


-----------------------------------------------------------------
Revision: a3430424ec320991ba0e73fcd49b3c87526dd307
Ancestor: bb61896dfa54afa64688154c8949b8c34262b6b1
Author: datallah at pidgin.im
Date: 2007-11-13T04:29:06
Branch: im.pidgin.pidgin

Modified files:
        ChangeLog.API libpurple/network.c libpurple/network.h
        libpurple/protocols/bonjour/bonjour_ft.c
        libpurple/protocols/bonjour/jabber.c

ChangeLog: 

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.

-------------- next part --------------
============================================================
--- ChangeLog.API	3d881990d3ebc047122cfe0ca0d3b1588f54b24c
+++ ChangeLog.API	ed1fec86a1506b2fe7ee886e09beff862bf5299e
@@ -50,6 +50,9 @@ version 2.3.0 (??/??/????):
 		* 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()
============================================================
--- libpurple/network.c	1aacfba7a244514983803a537e98303b78208699
+++ libpurple/network.c	e365eb68b6e415d5b1f5e046cb7d2ba04be39a95
@@ -259,6 +259,12 @@ purple_network_finish_pmp_map_cb(gpointe
 	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 @@ purple_network_do_listen(unsigned short 
 	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 @@ static gpointer wpurple_network_change_t
 
 		retval = WSALookupServiceEnd(h);
 
-		g_idle_add(wpurple_network_change_thread_cb, NULL);
+		purple_timeout_add(0, wpurple_network_change_thread_cb, NULL);
 
 	}
 
============================================================
--- libpurple/network.h	689632cfc916c27dd7e060f89fc508ec9a297c97
+++ libpurple/network.h	6ed2e88bbafab7105c48de92ad82262a72fe2174
@@ -106,7 +106,21 @@ const char *purple_network_get_my_ip(int
  */
 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.
  * This function is useful, for example, if you wanted to write a telnet
============================================================
--- libpurple/protocols/bonjour/bonjour_ft.c	0245fea87c58e7c0756b3626664b39baeede7062
+++ libpurple/protocols/bonjour/bonjour_ft.c	41e0adc50742131e79c29cf0df5f46a29e695459
@@ -58,7 +58,7 @@ xep_ft_si_reject(PurpleXfer *xfer, char 
 	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(Pur
 
 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 @@ bonjour_si_xfer_find(BonjourData *bd, co
 	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 @@ bonjour_si_xfer_find(BonjourData *bd, co
 			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 @@ xep_ft_si_offer(PurpleXfer *xfer, const 
 	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 @@ xep_ft_si_reject2(BonjourData *bd, const
 	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 @@ xep_ft_si_result(PurpleXfer *xfer, char 
 	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 @@ bonjour_free_xfer(PurpleXfer *xfer)
 	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 @@ bonjour_free_xfer(PurpleXfer *xfer)
 		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 @@ bonjour_new_xfer(PurpleConnection *gc, c
 	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 @@ bonjour_new_xfer(PurpleConnection *gc, c
 	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 @@ bonjour_send_file(PurpleConnection *gc, 
 	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 @@ bonjour_xfer_init(PurpleXfer *xfer)
 	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 @@ bonjour_xfer_init(PurpleXfer *xfer)
 	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 @@ xep_si_parse(PurpleConnection *pc, xmlno
 	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 @@ xep_si_parse(PurpleConnection *pc, xmlno
 	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 @@ xep_si_parse(PurpleConnection *pc, xmlno
 			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 @@ xep_bytestreams_parse(PurpleConnection *
 	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 @@ xep_bytestreams_parse(PurpleConnection *
 							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 @@ xep_bytestreams_parse(PurpleConnection *
 			}
 
 		} 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 @@ bonjour_xfer_receive(PurpleConnection *p
 	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 @@ bonjour_sock5_request_cb(gpointer data, 
 		} 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 @@ bonjour_bytestreams_listen(int sock, gpo
 	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 @@ bonjour_bytestreams_init(PurpleXfer *xfe
 	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 @@ bonjour_bytestreams_connect(PurpleXfer *
 	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)
============================================================
--- libpurple/protocols/bonjour/jabber.c	e1f2e1e7200dca9db5ee933b048510b2bd186fca
+++ libpurple/protocols/bonjour/jabber.c	463ced5fee0f15a3f78a6ddea960aac6b9482849
@@ -733,7 +733,7 @@ _find_or_start_conversation(BonjourJabbe
 		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 @@ check_if_blocked(PurpleBuddy *pb)
 
 	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;
 		}


More information about the Commits mailing list