diff libpurple/network.c @ 30876:6469c68fa093

propagate from branch 'im.pidgin.pidgin' (head fabc09bf724818b9b50e1c41d4afd6549f298c05) to branch 'im.pidgin.cpw.qulogic.msnp16' (head d8e8a3b3ec17b199432993002327e4ecf156d12b)
author masca@cpw.pidgin.im
date Sat, 11 Sep 2010 19:03:25 +0000
parents 3e7441e05be3
children 47ea27481972
line wrap: on
line diff
--- a/libpurple/network.c	Sun Aug 01 00:08:26 2010 +0000
+++ b/libpurple/network.c	Sat Sep 11 19:03:25 2010 +0000
@@ -98,6 +98,7 @@
 	PurpleNetworkListenCallback cb;
 	gpointer cb_data;
 	UPnPMappingAddRemove *mapping_data;
+	int timer;
 };
 
 #ifdef HAVE_NETWORKMANAGER
@@ -373,6 +374,7 @@
 	gint *value = g_new(gint, 1);
 
 	listen_data = data;
+	listen_data->timer = 0;
 
 	/* add port mapping to hash table */
 	*key = purple_network_get_port_from_fd(listen_data->listenfd);
@@ -504,7 +506,7 @@
 	{
 		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);
+		listen_data->timer = purple_timeout_add(0, purple_network_finish_pmp_map_cb, listen_data);
 	}
 	/* Attempt a NAT-PMP Mapping, which will return immediately */
 	else if (purple_pmp_create_map(((socket_type == SOCK_STREAM) ? PURPLE_PMP_TYPE_TCP : PURPLE_PMP_TYPE_UDP),
@@ -512,7 +514,7 @@
 	{
 		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);
+		listen_data->timer = purple_timeout_add(0, purple_network_finish_pmp_map_cb, listen_data);
 	}
 	else
 	{
@@ -584,6 +586,9 @@
 	if (listen_data->mapping_data != NULL)
 		purple_upnp_cancel_port_mapping(listen_data->mapping_data);
 
+	if (listen_data->timer > 0)
+		purple_timeout_remove(listen_data->timer);
+
 	g_free(listen_data);
 }
 
@@ -1072,12 +1077,10 @@
 
 	if (protocol) {
 		purple_network_upnp_mapping_remove(&port, protocol, NULL);
-		g_hash_table_remove(upnp_port_mappings, protocol);
 	} else {
 		protocol = g_hash_table_lookup(nat_pmp_port_mappings, &port);
 		if (protocol) {
 			purple_network_nat_pmp_mapping_remove(&port, protocol, NULL);
-			g_hash_table_remove(nat_pmp_port_mappings, protocol);
 		}
 	}
 }