libpurple/network.c

changeset 41828
023b57b090f6
parent 41741
83b658257a8a
child 41840
fe350460fb1c
equal deleted inserted replaced
41827:c0c9eeca7d4b 41828:023b57b090f6
44 #include "account.h" 44 #include "account.h"
45 #include "nat-pmp.h" 45 #include "nat-pmp.h"
46 #include "network.h" 46 #include "network.h"
47 #include "prefs.h" 47 #include "prefs.h"
48 #include "stun.h" 48 #include "stun.h"
49 #include "upnp.h"
50 49
51 static gboolean force_online = FALSE; 50 static gboolean force_online = FALSE;
52 51
53 /* Cached IP addresses for STUN and TURN servers (set globally in prefs) */ 52 /* Cached IP addresses for STUN and TURN servers (set globally in prefs) */
54 static gchar *stun_ip = NULL; 53 static gchar *stun_ip = NULL;
132 stun = purple_stun_discover(NULL); 131 stun = purple_stun_discover(NULL);
133 if (stun != NULL && stun->status == PURPLE_STUN_STATUS_DISCOVERED) { 132 if (stun != NULL && stun->status == PURPLE_STUN_STATUS_DISCOVERED) {
134 return; 133 return;
135 } 134 }
136 135
137 /* Attempt to get the IP from a NAT device using UPnP */
138 ip = purple_upnp_get_public_ip();
139 if (ip != NULL) {
140 return;
141 }
142
143 /* Attempt to get the IP from a NAT device using NAT-PMP */ 136 /* Attempt to get the IP from a NAT device using NAT-PMP */
144 ip = purple_pmp_get_public_ip(); 137 ip = purple_pmp_get_public_ip();
145 if (ip != NULL) { 138 if (ip != NULL) {
146 return; 139 return;
147 } 140 }
163 } else { 156 } else {
164 /* Check if STUN discovery was already done */ 157 /* Check if STUN discovery was already done */
165 stun = purple_stun_discover(NULL); 158 stun = purple_stun_discover(NULL);
166 if ((stun != NULL) && (stun->status == PURPLE_STUN_STATUS_DISCOVERED)) { 159 if ((stun != NULL) && (stun->status == PURPLE_STUN_STATUS_DISCOVERED)) {
167 return g_strdup(stun->publicip); 160 return g_strdup(stun->publicip);
168 }
169
170 /* Attempt to get the IP from a NAT device using UPnP */
171 ip = purple_upnp_get_public_ip();
172 if (ip != NULL) {
173 return g_strdup(ip);
174 } 161 }
175 162
176 /* Attempt to get the IP from a NAT device using NAT-PMP */ 163 /* Attempt to get the IP from a NAT device using NAT-PMP */
177 ip = purple_pmp_get_public_ip(); 164 ip = purple_pmp_get_public_ip();
178 if (ip != NULL) { 165 if (ip != NULL) {
323 purple_prefs_add_bool ("/purple/network/map_ports", TRUE); 310 purple_prefs_add_bool ("/purple/network/map_ports", TRUE);
324 purple_prefs_add_bool ("/purple/network/ports_range_use", FALSE); 311 purple_prefs_add_bool ("/purple/network/ports_range_use", FALSE);
325 purple_prefs_add_int ("/purple/network/ports_range_start", 1024); 312 purple_prefs_add_int ("/purple/network/ports_range_start", 1024);
326 purple_prefs_add_int ("/purple/network/ports_range_end", 2048); 313 purple_prefs_add_int ("/purple/network/ports_range_end", 2048);
327 314
328 if(purple_prefs_get_bool("/purple/network/map_ports") || purple_prefs_get_bool("/purple/network/auto_ip"))
329 purple_upnp_discover(NULL, NULL);
330
331 purple_pmp_init(); 315 purple_pmp_init();
332 purple_upnp_init();
333 316
334 purple_network_set_stun_server( 317 purple_network_set_stun_server(
335 purple_prefs_get_string("/purple/network/stun_server")); 318 purple_prefs_get_string("/purple/network/stun_server"));
336 purple_network_set_turn_server( 319 purple_network_set_turn_server(
337 purple_prefs_get_string("/purple/network/turn_server")); 320 purple_prefs_get_string("/purple/network/turn_server"));
340 void 323 void
341 purple_network_uninit(void) 324 purple_network_uninit(void)
342 { 325 {
343 g_free(stun_ip); 326 g_free(stun_ip);
344 g_free(turn_ip); 327 g_free(turn_ip);
345 328 }
346 /* TODO: clean up remaining port mappings, note calling
347 purple_upnp_remove_port_mapping from here doesn't quite work... */
348
349 purple_upnp_uninit();
350 }

mercurial