pidgin: 5cbaf3c8: Cast back and forth between int and poin...
markdoliner at pidgin.im
markdoliner at pidgin.im
Mon Nov 29 02:21:35 EST 2010
----------------------------------------------------------------------
Revision: 5cbaf3c8817820dc12f258a56398157a73c4cc40
Parent: 5b55e54444f895327a1bd0004528f37977869fdc
Author: markdoliner at pidgin.im
Date: 11/29/10 02:13:08
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/5cbaf3c8817820dc12f258a56398157a73c4cc40
Changelog:
Cast back and forth between int and pointer instead of putting pointers
to ints in these two hash tables. I think this is easier to follow
and less error prone (in addition to being ever so slightly more efficient)
Changes against parent 5b55e54444f895327a1bd0004528f37977869fdc
patched libpurple/network.c
-------------- next part --------------
============================================================
--- libpurple/network.c b5d913bea1b6c65c1dc41b7dae0f755ae882c787
+++ libpurple/network.c d334af276edca3df1776b42495f7a3981f3c7056
@@ -350,17 +350,15 @@ purple_network_set_upnp_port_mapping_cb(
if (success) {
/* add port mapping to hash table */
- gint *key = g_new(gint, 1);
- gint *value = g_new(gint, 1);
- *key = purple_network_get_port_from_fd(listen_data->listenfd);
- *value = listen_data->socket_type;
- g_hash_table_insert(upnp_port_mappings, key, value);
+ gint key = purple_network_get_port_from_fd(listen_data->listenfd);
+ gint value = listen_data->socket_type;
+ g_hash_table_insert(upnp_port_mappings, GINT_TO_POINTER(key), GINT_TO_POINTER(value));
}
if (listen_data->cb)
listen_data->cb(listen_data->listenfd, listen_data->cb_data);
- /* Clear the UPnP mapping data, since it's complete and purple_netweork_listen_cancel() will try to cancel
+ /* Clear the UPnP mapping data, since it's complete and purple_network_listen_cancel() will try to cancel
* it otherwise. */
listen_data->mapping_data = NULL;
purple_network_listen_cancel(listen_data);
@@ -370,16 +368,16 @@ purple_network_finish_pmp_map_cb(gpointe
purple_network_finish_pmp_map_cb(gpointer data)
{
PurpleNetworkListenData *listen_data;
- gint *key = g_new(gint, 1);
- gint *value = g_new(gint, 1);
+ gint key;
+ gint value;
listen_data = data;
listen_data->timer = 0;
/* add port mapping to hash table */
- *key = purple_network_get_port_from_fd(listen_data->listenfd);
- *value = listen_data->socket_type;
- g_hash_table_insert(nat_pmp_port_mappings, key, value);
+ key = purple_network_get_port_from_fd(listen_data->listenfd);
+ value = listen_data->socket_type;
+ g_hash_table_insert(nat_pmp_port_mappings, GINT_TO_POINTER(key), GINT_TO_POINTER(value));
if (listen_data->cb)
listen_data->cb(listen_data->listenfd, listen_data->cb_data);
@@ -1045,42 +1043,42 @@ purple_network_upnp_mapping_remove(gpoin
purple_network_upnp_mapping_remove(gpointer key, gpointer value,
gpointer user_data)
{
- gint port = (gint) *((gint *) key);
- gint protocol = (gint) *((gint *) value);
+ gint port = GPOINTER_TO_INT(key);
+ gint protocol = GPOINTER_TO_INT(value);
purple_debug_info("network", "removing UPnP port mapping for port %d\n",
port);
- purple_upnp_remove_port_mapping(port,
- protocol == SOCK_STREAM ? "TCP" : "UDP",
+ purple_upnp_remove_port_mapping(port,
+ protocol == SOCK_STREAM ? "TCP" : "UDP",
purple_network_upnp_mapping_remove_cb, NULL);
- g_hash_table_remove(upnp_port_mappings, key);
+ g_hash_table_remove(upnp_port_mappings, GINT_TO_POINTER(port));
}
static void
purple_network_nat_pmp_mapping_remove(gpointer key, gpointer value,
gpointer user_data)
{
- gint port = (gint) *((gint *) key);
- gint protocol = (gint) *((gint *) value);
+ gint port = GPOINTER_TO_INT(key);
+ gint protocol = GPOINTER_TO_INT(value);
purple_debug_info("network", "removing NAT-PMP port mapping for port %d\n",
port);
purple_pmp_destroy_map(
- protocol == SOCK_STREAM ? PURPLE_PMP_TYPE_TCP : PURPLE_PMP_TYPE_UDP,
+ protocol == SOCK_STREAM ? PURPLE_PMP_TYPE_TCP : PURPLE_PMP_TYPE_UDP,
port);
- g_hash_table_remove(nat_pmp_port_mappings, key);
+ g_hash_table_remove(nat_pmp_port_mappings, GINT_TO_POINTER(port));
}
void
purple_network_remove_port_mapping(gint fd)
{
int port = purple_network_get_port_from_fd(fd);
- gint *protocol = g_hash_table_lookup(upnp_port_mappings, &port);
+ gint protocol = GPOINTER_TO_INT(g_hash_table_lookup(upnp_port_mappings, GINT_TO_POINTER(port)));
if (protocol) {
- purple_network_upnp_mapping_remove(&port, protocol, NULL);
+ purple_network_upnp_mapping_remove(GINT_TO_POINTER(port), GINT_TO_POINTER(protocol), NULL);
} else {
- protocol = g_hash_table_lookup(nat_pmp_port_mappings, &port);
+ protocol = GPOINTER_TO_INT(g_hash_table_lookup(nat_pmp_port_mappings, GINT_TO_POINTER(port)));
if (protocol) {
- purple_network_nat_pmp_mapping_remove(&port, protocol, NULL);
+ purple_network_nat_pmp_mapping_remove(GINT_TO_POINTER(port), GINT_TO_POINTER(protocol), NULL);
}
}
}
@@ -1178,16 +1176,14 @@ purple_network_init(void)
purple_pmp_init();
purple_upnp_init();
-
+
purple_network_set_stun_server(
purple_prefs_get_string("/purple/network/stun_server"));
purple_network_set_turn_server(
purple_prefs_get_string("/purple/network/turn_server"));
- upnp_port_mappings =
- g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free);
- nat_pmp_port_mappings =
- g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free);
+ upnp_port_mappings = g_hash_table_new(g_direct_hash, g_direct_equal);
+ nat_pmp_port_mappings = g_hash_table_new(g_direct_hash, g_direct_equal);
}
@@ -1231,13 +1227,13 @@ purple_network_uninit(void)
#endif
purple_signal_unregister(purple_network_get_handle(),
"network-configuration-changed");
-
+
if (stun_ip)
g_free(stun_ip);
g_hash_table_destroy(upnp_port_mappings);
g_hash_table_destroy(nat_pmp_port_mappings);
- /* TODO: clean up remaining port mappings, note calling
+ /* TODO: clean up remaining port mappings, note calling
purple_upnp_remove_port_mapping from here doesn't quite work... */
}
More information about the Commits
mailing list