changeset 32677:d2ef8926b960

Remove deprecated purple_network_listen_map_external(). Update purple_network_listen() and purple_network_listen_range() to have a boolean parameter that indicates if the port should be mapped externally.
author andrew.victor@mxit.com
date Sat, 24 Sep 2011 21:10:41 +0000
parents 32b2a17d2f92
children 348a933fed78
files ChangeLog.API libpurple/network.c libpurple/network.h libpurple/plugins/perl/common/Network.xs libpurple/protocols/bonjour/bonjour_ft.c libpurple/protocols/bonjour/jabber.c libpurple/protocols/irc/dcc_send.c libpurple/protocols/jabber/si.c libpurple/protocols/msn/slpcall.c libpurple/protocols/oscar/peer.c libpurple/protocols/simple/simple.c libpurple/protocols/yahoo/libymsg.c libpurple/protocols/yahoo/yahoo_filexfer.c libpurple/stun.c
diffstat 14 files changed, 35 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Sat Sep 24 20:48:59 2011 +0000
+++ b/ChangeLog.API	Sat Sep 24 21:10:41 2011 +0000
@@ -128,6 +128,7 @@
 		* purple_conv_chat_set_users
 		* purple_core_migrate
 		* purple_dnsquery_a_account
+		* purple_network_listen_map_external
 		* purple_notify_searchresults_column_get_title
 		* purple_notify_searchresults_get_columns_count
 		* purple_notify_searchresults_get_rows_count
--- a/libpurple/network.c	Sat Sep 24 20:48:59 2011 +0000
+++ b/libpurple/network.c	Sat Sep 24 21:10:41 2011 +0000
@@ -391,14 +391,9 @@
 	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_family, int socket_type, PurpleNetworkListenCallback cb, gpointer cb_data)
+purple_network_do_listen(unsigned short port, int socket_family, int socket_type, gboolean map_external,
+                             PurpleNetworkListenCallback cb, gpointer cb_data)
 {
 	int listenfd = -1;
 	int flags;
@@ -503,7 +498,7 @@
 	listen_data->cb_data = cb_data;
 	listen_data->socket_type = socket_type;
 
-	if (!purple_socket_speaks_ipv4(listenfd) || !listen_map_external ||
+	if (!purple_socket_speaks_ipv4(listenfd) || !map_external ||
 			!purple_prefs_get_bool("/purple/network/map_ports"))
 	{
 		purple_debug_info("network", "Skipping external port mapping.\n");
@@ -531,19 +526,19 @@
 }
 
 PurpleNetworkListenData *
-purple_network_listen(unsigned short port, int socket_family,
-                             int socket_type, PurpleNetworkListenCallback cb,
+purple_network_listen(unsigned short port, int socket_family, int socket_type,
+                             gboolean map_external, PurpleNetworkListenCallback cb,
                              gpointer cb_data)
 {
 	g_return_val_if_fail(port != 0, NULL);
 
-	return purple_network_do_listen(port, socket_family, socket_type,
+	return purple_network_do_listen(port, socket_family, socket_type, map_external,
 	                                cb, cb_data);
 }
 
 PurpleNetworkListenData *
 purple_network_listen_range(unsigned short start, unsigned short end,
-                                   int socket_family, int socket_type,
+                                   int socket_family, int socket_type, gboolean map_external,
                                    PurpleNetworkListenCallback cb,
                                    gpointer cb_data)
 {
@@ -558,7 +553,7 @@
 	}
 
 	for (; start <= end; start++) {
-		ret = purple_network_do_listen(start, AF_UNSPEC, socket_type, cb, cb_data);
+		ret = purple_network_do_listen(start, AF_UNSPEC, socket_type, map_external, cb, cb_data);
 		if (ret != NULL)
 			break;
 	}
--- a/libpurple/network.h	Sat Sep 24 20:48:59 2011 +0000
+++ b/libpurple/network.h	Sat Sep 24 21:10:41 2011 +0000
@@ -118,18 +118,6 @@
 const char *purple_network_get_my_ip(int fd);
 
 /**
- * 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 functions mentioned
- *             above to perform the same function.
- * @since 2.3.0
- */
-void purple_network_listen_map_external(gboolean map_external);
-
-/**
  * 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
@@ -156,6 +144,8 @@
  *                      need a second listener to support both v4 and v6.
  * @param socket_type The type of socket to open for listening.
  *   This will be either SOCK_STREAM for TCP or SOCK_DGRAM for UDP.
+ * @param map_external Should the open port be mapped externally using
+ *           NAT-PNP or UPnP?  (default should be TRUE)
  * @param cb The callback to be invoked when the port to listen on is available.
  *           The file descriptor of the listening socket will be specified in
  *           this callback, or -1 if no socket could be established.
@@ -166,8 +156,8 @@
  *         socket to listen on.
  */
 PurpleNetworkListenData *purple_network_listen(unsigned short port,
-	int socket_family, int socket_type, PurpleNetworkListenCallback cb,
-	gpointer cb_data);
+	int socket_family, int socket_type, gboolean map_external,
+	PurpleNetworkListenCallback cb, gpointer cb_data);
 
 /**
  * Opens a listening port selected from a range of ports.  The range of
@@ -201,6 +191,8 @@
  *                      need a second listener to support both v4 and v6.
  * @param socket_type The type of socket to open for listening.
  *   This will be either SOCK_STREAM for TCP or SOCK_DGRAM for UDP.
+ * @param map_external Should the open port be mapped externally using
+ *           NAT-PNP or UPnP?  (default should be TRUE)
  * @param cb The callback to be invoked when the port to listen on is available.
  *           The file descriptor of the listening socket will be specified in
  *           this callback, or -1 if no socket could be established.
@@ -212,7 +204,8 @@
  */
 PurpleNetworkListenData *purple_network_listen_range(
 	unsigned short start, unsigned short end, int socket_family,
-	int socket_type, PurpleNetworkListenCallback cb, gpointer cb_data);
+	int socket_type, gboolean map_external,
+	PurpleNetworkListenCallback cb, gpointer cb_data);
 
 /**
  * This can be used to cancel any in-progress listener connection
--- a/libpurple/plugins/perl/common/Network.xs	Sat Sep 24 20:48:59 2011 +0000
+++ b/libpurple/plugins/perl/common/Network.xs	Sat Sep 24 21:10:41 2011 +0000
@@ -23,19 +23,21 @@
 	const char *ip
 
 Purple::NetworkListenData
-purple_network_listen(port, socket_family, socket_type, cb, cb_data)
+purple_network_listen(port, socket_family, socket_type, map_external, cb, cb_data)
 	unsigned short port
 	int socket_family
 	int socket_type
+	gboolean map_external
 	Purple::NetworkListenCallback cb
 	gpointer cb_data
 
 Purple::NetworkListenData
-purple_network_listen_range(start, end, socket_family, socket_type, cb, cb_data)
+purple_network_listen_range(start, end, socket_family, socket_type, map_external, cb, cb_data)
 	unsigned short start
 	unsigned short end
 	int socket_family
 	int socket_type
+	gboolean map_external
 	Purple::NetworkListenCallback cb
 	gpointer cb_data
 
--- a/libpurple/protocols/bonjour/bonjour_ft.c	Sat Sep 24 20:48:59 2011 +0000
+++ b/libpurple/protocols/bonjour/bonjour_ft.c	Sat Sep 24 21:10:41 2011 +0000
@@ -792,10 +792,8 @@
 	purple_debug_info("bonjour", "Bonjour-bytestreams-init.\n");
 	xf = purple_xfer_get_protocol_data(xfer);
 
-	purple_network_listen_map_external(FALSE);
-	xf->listen_data = purple_network_listen_range(0, 0, AF_UNSPEC, SOCK_STREAM,
+	xf->listen_data = purple_network_listen_range(0, 0, AF_UNSPEC, SOCK_STREAM, FALSE,
 						      bonjour_bytestreams_listen, xfer);
-	purple_network_listen_map_external(TRUE);
 	if (xf->listen_data == NULL)
 		purple_xfer_cancel_local(xfer);
 
--- a/libpurple/protocols/bonjour/jabber.c	Sat Sep 24 20:48:59 2011 +0000
+++ b/libpurple/protocols/bonjour/jabber.c	Sat Sep 24 21:10:41 2011 +0000
@@ -744,7 +744,7 @@
 
 #if 0
 	/* TODO: Why isn't this being used? */
-	data->socket = purple_network_listen(jdata->port, AF_UNSPEC, SOCK_STREAM);
+	data->socket = purple_network_listen(jdata->port, AF_UNSPEC, SOCK_STREAM, TRUE);
 
 	if (jdata->socket == -1)
 	{
--- a/libpurple/protocols/irc/dcc_send.c	Sat Sep 24 20:48:59 2011 +0000
+++ b/libpurple/protocols/irc/dcc_send.c	Sat Sep 24 21:10:41 2011 +0000
@@ -339,7 +339,7 @@
 	purple_xfer_ref(xfer);
 
 	/* Create a listening socket */
-	xd->listen_data = purple_network_listen_range(0, 0, AF_UNSPEC, SOCK_STREAM,
+	xd->listen_data = purple_network_listen_range(0, 0, AF_UNSPEC, SOCK_STREAM, TRUE,
 			irc_dccsend_network_listen_cb, xfer);
 	if (xd->listen_data == NULL) {
 		purple_xfer_unref(xfer);
--- a/libpurple/protocols/jabber/si.c	Sat Sep 24 20:48:59 2011 +0000
+++ b/libpurple/protocols/jabber/si.c	Sat Sep 24 21:10:41 2011 +0000
@@ -959,7 +959,7 @@
 		purple_debug_info("jabber", "Skipping attempting local streamhost.\n");
 		jsx->listen_data = NULL;
 	} else
-		jsx->listen_data = purple_network_listen_range(0, 0, AF_UNSPEC, SOCK_STREAM,
+		jsx->listen_data = purple_network_listen_range(0, 0, AF_UNSPEC, SOCK_STREAM, TRUE,
 				jabber_si_xfer_bytestreams_listen_cb, xfer);
 
 	if (jsx->listen_data == NULL) {
--- a/libpurple/protocols/msn/slpcall.c	Sat Sep 24 20:48:59 2011 +0000
+++ b/libpurple/protocols/msn/slpcall.c	Sat Sep 24 21:10:41 2011 +0000
@@ -733,6 +733,7 @@
 				0, 0,
 				AF_UNSPEC,
 				SOCK_STREAM,
+				TRUE,
 				msn_dc_listen_socket_created_cb,
 				dc
 			);
@@ -835,6 +836,7 @@
 			0, 0,
 			AF_UNSPEC,
 			SOCK_STREAM,
+			TRUE,
 			msn_dc_listen_socket_created_cb,
 			dc
 		);
--- a/libpurple/protocols/oscar/peer.c	Sat Sep 24 20:48:59 2011 +0000
+++ b/libpurple/protocols/oscar/peer.c	Sat Sep 24 21:10:41 2011 +0000
@@ -842,7 +842,7 @@
 		 */
 		conn->flags |= PEER_CONNECTION_FLAG_IS_INCOMING;
 
-		conn->listen_data = purple_network_listen_range(5190, 5290, AF_UNSPEC, SOCK_STREAM,
+		conn->listen_data = purple_network_listen_range(5190, 5290, AF_UNSPEC, SOCK_STREAM, TRUE,
 				peer_connection_establish_listener_cb, conn);
 		if (conn->listen_data != NULL)
 		{
--- a/libpurple/protocols/simple/simple.c	Sat Sep 24 20:48:59 2011 +0000
+++ b/libpurple/protocols/simple/simple.c	Sat Sep 24 21:10:41 2011 +0000
@@ -1823,7 +1823,7 @@
 	}
 
 	/* create socket for incoming connections */
-	sip->listen_data = purple_network_listen_range(5060, 5160, AF_UNSPEC, SOCK_DGRAM,
+	sip->listen_data = purple_network_listen_range(5060, 5160, AF_UNSPEC, SOCK_DGRAM, TRUE,
 				simple_udp_host_resolved_listen_cb, sip);
 	if (sip->listen_data == NULL) {
 		purple_connection_error(sip->gc,
@@ -1893,7 +1893,7 @@
 	/* TCP case */
 	if(!sip->udp) {
 		/* create socket for incoming connections */
-		sip->listen_data = purple_network_listen_range(5060, 5160, AF_UNSPEC, SOCK_STREAM,
+		sip->listen_data = purple_network_listen_range(5060, 5160, AF_UNSPEC, SOCK_STREAM, TRUE,
 					simple_tcp_connect_listen_cb, sip);
 		if (sip->listen_data == NULL) {
 			purple_connection_error(sip->gc,
--- a/libpurple/protocols/yahoo/libymsg.c	Sat Sep 24 20:48:59 2011 +0000
+++ b/libpurple/protocols/yahoo/libymsg.c	Sat Sep 24 21:10:41 2011 +0000
@@ -2770,7 +2770,7 @@
 	if (yd->listen_data)
 		purple_debug_warning("yahoo","p2p: Failed to create p2p server - server already exists\n");
 	else {
-		yd->listen_data = purple_network_listen(YAHOO_PAGER_PORT_P2P, AF_UNSPEC, SOCK_STREAM, yahoo_p2p_server_listen_cb, p2p_data);
+		yd->listen_data = purple_network_listen(YAHOO_PAGER_PORT_P2P, AF_UNSPEC, SOCK_STREAM, TRUE, yahoo_p2p_server_listen_cb, p2p_data);
 		if (yd->listen_data == NULL)
 			purple_debug_warning("yahoo","p2p: Failed to created p2p server\n");
 	}
--- a/libpurple/protocols/yahoo/yahoo_filexfer.c	Sat Sep 24 20:48:59 2011 +0000
+++ b/libpurple/protocols/yahoo/yahoo_filexfer.c	Sat Sep 24 21:10:41 2011 +0000
@@ -1216,7 +1216,7 @@
 		close(source);
 		xfer->fd = -1;
 		/* start local server, listen for connections */
-		purple_network_listen(xd->yahoo_local_p2p_ft_server_port, AF_UNSPEC, SOCK_STREAM, yahoo_p2p_ft_server_listen_cb, xfer);
+		purple_network_listen(xd->yahoo_local_p2p_ft_server_port, AF_UNSPEC, SOCK_STREAM, TRUE, yahoo_p2p_ft_server_listen_cb, xfer);
 	}
 	else
 	{
@@ -1570,7 +1570,7 @@
 
 	p2p_data = g_hash_table_lookup(yd->peers, purple_xfer_get_remote_user(xfer));
 	if( p2p_data->connection_type == YAHOO_P2P_WE_ARE_SERVER )
-		if(purple_network_listen_range(0, 0, AF_UNSPEC, SOCK_STREAM, yahoo_p2p_ft_server_listen_cb, xfer))
+		if(purple_network_listen_range(0, 0, AF_UNSPEC, SOCK_STREAM, TRUE, yahoo_p2p_ft_server_listen_cb, xfer))
 			return;
 
 	pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_INFO_15, YAHOO_STATUS_AVAILABLE, yd->session_id);
@@ -1871,7 +1871,7 @@
 			purple_xfer_cancel_remote(xfer);
 			return;
 		}
-		if(!purple_network_listen_range(0, 0, AF_UNSPEC, SOCK_STREAM, yahoo_p2p_ft_server_listen_cb, xfer)) {
+		if(!purple_network_listen_range(0, 0, AF_UNSPEC, SOCK_STREAM, TRUE, yahoo_p2p_ft_server_listen_cb, xfer)) {
 			purple_xfer_cancel_remote(xfer);
 			return;
 		}
--- a/libpurple/stun.c	Sat Sep 24 20:48:59 2011 +0000
+++ b/libpurple/stun.c	Sat Sep 24 21:10:41 2011 +0000
@@ -338,7 +338,7 @@
 		return;
 	}
 
-	if (!purple_network_listen_range(12108, 12208, AF_UNSPEC, SOCK_DGRAM, hbn_listen_cb, hosts)) {
+	if (!purple_network_listen_range(12108, 12208, AF_UNSPEC, SOCK_DGRAM, TRUE, hbn_listen_cb, hosts)) {
 		while (hosts) {
 			hosts = g_slist_delete_link(hosts, hosts);
 			g_free(hosts->data);