libpurple/network.c

Fri, 10 Jun 2022 20:42:36 -0500

author
ivanhoe <ivanhoe@fiscari.de>
date
Fri, 10 Jun 2022 20:42:36 -0500
changeset 41432
aaff9cefb423
parent 41153
5f034a5261c3
child 41682
289867067994
permissions
-rw-r--r--

fix memory leak when using purple accounts

Testing Done:
ran test_account_manager and test_notification (from /r/1502 where I first encountered that leak) in valgrind -> no more leak and no new invalid read/write

Reviewed at https://reviews.imfreedom.org/r/1503/

20147
66f05a854eee applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
1 /* purple
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
2 *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
3 * Purple is the legal property of its developers, whose names are too numerous
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
4 * to list here. Please refer to the COPYRIGHT file distributed with this
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
5 * source distribution.
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
6 *
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
10 * (at your option) any later version.
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
11 *
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
15 * GNU General Public License for more details.
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
16 *
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
19859
71d37b57eff2 The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19832
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
20 */
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
21
8245
c1397ca0a619 [gaim-migrate @ 8968]
Herman Bloggs <herman@bluedigits.com>
parents: 8240
diff changeset
22 #include "internal.h"
40439
e9838d634d5e Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents: 40264
diff changeset
23 #include "purpleprivate.h"
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
24
37450
703722d83214 Update network.c for the dns code removal
Gary Kramlich <grim@reaperworld.com>
parents: 36031
diff changeset
25 #include <gio/gio.h>
703722d83214 Update network.c for the dns code removal
Gary Kramlich <grim@reaperworld.com>
parents: 36031
diff changeset
26
13156
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
27 #ifndef _WIN32
23352
9714223ca7a7 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 23185
diff changeset
28 #include <arpa/nameser.h>
14864
a1cbdeffee69 [gaim-migrate @ 17567]
Sean Egan <seanegan@pidgin.im>
parents: 14862
diff changeset
29 #include <resolv.h>
a1cbdeffee69 [gaim-migrate @ 17567]
Sean Egan <seanegan@pidgin.im>
parents: 14862
diff changeset
30 #include <netinet/in.h>
13156
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
31 #include <net/if.h>
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
32 #else
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
33 #include <nspapi.h>
13156
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
34 #endif
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
35
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
36 /* Solaris */
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
37 #if defined (__SVR4) && defined (__sun)
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
38 #include <sys/sockio.h>
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
39 #endif
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
40
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
41 #include "debug.h"
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
42 #include "account.h"
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16012
diff changeset
43 #include "nat-pmp.h"
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
44 #include "network.h"
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
45 #include "prefs.h"
11411
b74834586187 [gaim-migrate @ 13648]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11391
diff changeset
46 #include "stun.h"
11195
d84d542a04ac [gaim-migrate @ 13319]
Adam Warrington <awarring@users.sourceforge.net>
parents: 11033
diff changeset
47 #include "upnp.h"
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
48
37488
88afe246144e First stab at replacing network-manager with gio, this probably breaks win32, need to test and see
Gary Kramlich <grim@reaperworld.com>
parents: 37466
diff changeset
49 static gboolean force_online = FALSE;
24999
84d597b7e7c6 Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@pidgin.im>
parents: 24519
diff changeset
50
26261
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
51 /* Cached IP addresses for STUN and TURN servers (set globally in prefs) */
26256
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
52 static gchar *stun_ip = NULL;
26261
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
53 static gchar *turn_ip = NULL;
26256
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
54
27332
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
55 /* Keep track of port mappings done with UPnP and NAT-PMP */
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
56 static GHashTable *upnp_port_mappings = NULL;
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
57 static GHashTable *nat_pmp_port_mappings = NULL;
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
58
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
59 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
60 purple_network_set_public_ip(const char *ip)
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
61 {
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
62 g_return_if_fail(ip != NULL);
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
63
8838
c23227da7b4a [gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents: 8834
diff changeset
64 /* XXX - Ensure the IP address is valid */
c23227da7b4a [gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents: 8834
diff changeset
65
16478
19107605c565 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents: 16035
diff changeset
66 purple_prefs_set_string("/purple/network/public_ip", ip);
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
67 }
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
68
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
69 const char *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
70 purple_network_get_public_ip(void)
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
71 {
16478
19107605c565 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents: 16035
diff changeset
72 return purple_prefs_get_string("/purple/network/public_ip");
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
73 }
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
74
40110
bc2b94f2595a Make purple_network_get_my_ip_from_gio return non-const.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40107
diff changeset
75 static gchar *
40107
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
76 purple_network_get_local_system_ip_from_gio(GSocketConnection *sockconn)
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
77 {
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
78 GSocketAddress *addr;
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
79 GInetSocketAddress *inetsockaddr;
40110
bc2b94f2595a Make purple_network_get_my_ip_from_gio return non-const.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40107
diff changeset
80 gchar *ip;
40107
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
81
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
82 addr = g_socket_connection_get_local_address(sockconn, NULL);
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
83 if ((inetsockaddr = G_INET_SOCKET_ADDRESS(addr)) != NULL) {
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
84 GInetAddress *inetaddr =
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
85 g_inet_socket_address_get_address(inetsockaddr);
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
86 if (g_inet_address_get_family(inetaddr) == G_SOCKET_FAMILY_IPV4 &&
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
87 !g_inet_address_get_is_loopback(inetaddr)) {
40110
bc2b94f2595a Make purple_network_get_my_ip_from_gio return non-const.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40107
diff changeset
88 ip = g_inet_address_to_string(inetaddr);
bc2b94f2595a Make purple_network_get_my_ip_from_gio return non-const.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40107
diff changeset
89 g_object_unref(addr);
bc2b94f2595a Make purple_network_get_my_ip_from_gio return non-const.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40107
diff changeset
90 return ip;
40107
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
91 }
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
92 }
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
93 g_object_unref(addr);
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
94
40110
bc2b94f2595a Make purple_network_get_my_ip_from_gio return non-const.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40107
diff changeset
95 return g_strdup("0.0.0.0");
40107
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
96 }
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
97
35462
901dfa763f15 Fix some gtk-doc warnings till proxy.c
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
98 /*
901dfa763f15 Fix some gtk-doc warnings till proxy.c
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
99 * purple_network_is_ipv4:
901dfa763f15 Fix some gtk-doc warnings till proxy.c
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
100 * @hostname: The hostname to be verified.
901dfa763f15 Fix some gtk-doc warnings till proxy.c
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
101 *
33894
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
102 * Checks, if specified hostname is valid ipv4 address.
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
103 *
35462
901dfa763f15 Fix some gtk-doc warnings till proxy.c
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
104 * Returns: TRUE, if the hostname is valid.
33894
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
105 */
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
106 static gboolean
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
107 purple_network_is_ipv4(const gchar *hostname)
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
108 {
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
109 g_return_val_if_fail(hostname != NULL, FALSE);
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
110
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
111 /* We don't accept ipv6 here. */
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
112 if (strchr(hostname, ':') != NULL)
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
113 return FALSE;
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
114
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
115 return g_hostname_is_ip_address(hostname);
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
116 }
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
117
40663
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
118 void
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
119 purple_network_discover_my_ip(void)
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
120 {
12686
ec3e7c4ff045 [gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents: 11424
diff changeset
121 const char *ip = NULL;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
122 PurpleStunNatDiscovery *stun;
8834
0a798e3d2b84 [gaim-migrate @ 9598]
Mark Doliner <markdoliner@pidgin.im>
parents: 8251
diff changeset
123
0a798e3d2b84 [gaim-migrate @ 9598]
Mark Doliner <markdoliner@pidgin.im>
parents: 8251
diff changeset
124 /* Check if the user specified an IP manually */
16478
19107605c565 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents: 16035
diff changeset
125 if (!purple_prefs_get_bool("/purple/network/auto_ip")) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
126 ip = purple_network_get_public_ip();
15116
037b787407ba [gaim-migrate @ 17838]
Mark Doliner <markdoliner@pidgin.im>
parents: 14959
diff changeset
127 /* Make sure the IP address entered by the user is valid */
40663
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
128 if (ip != NULL && purple_network_is_ipv4(ip)) {
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
129 return;
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
130 }
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
131 }
11424
b0f8535daa74 [gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11411
diff changeset
132
40663
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
133 /* Check if STUN discovery was already done */
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
134 stun = purple_stun_discover(NULL);
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
135 if (stun != NULL && stun->status == PURPLE_STUN_STATUS_DISCOVERED) {
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
136 return;
21810
0b5181178201 Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents: 21549
diff changeset
137 }
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents: 15502
diff changeset
138
40663
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
139 /* Attempt to get the IP from a NAT device using UPnP */
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
140 ip = purple_upnp_get_public_ip();
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
141 if (ip != NULL) {
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
142 return;
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
143 }
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
144
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
145 /* Attempt to get the IP from a NAT device using NAT-PMP */
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
146 ip = purple_pmp_get_public_ip();
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
147 if (ip != NULL) {
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
148 return;
2453bef0abe7 Cleanup local IP getters
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40659
diff changeset
149 }
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
150 }
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
151
40110
bc2b94f2595a Make purple_network_get_my_ip_from_gio return non-const.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40107
diff changeset
152 gchar *
40107
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
153 purple_network_get_my_ip_from_gio(GSocketConnection *sockconn)
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
154 {
40110
bc2b94f2595a Make purple_network_get_my_ip_from_gio return non-const.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40107
diff changeset
155 const gchar *ip = NULL;
40107
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
156 PurpleStunNatDiscovery *stun;
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
157
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
158 /* Check if the user specified an IP manually */
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
159 if (!purple_prefs_get_bool("/purple/network/auto_ip")) {
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
160 ip = purple_network_get_public_ip();
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
161 /* Make sure the IP address entered by the user is valid */
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
162 if ((ip != NULL) && (purple_network_is_ipv4(ip))) {
40110
bc2b94f2595a Make purple_network_get_my_ip_from_gio return non-const.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40107
diff changeset
163 return g_strdup(ip);
40107
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
164 }
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
165 } else {
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
166 /* Check if STUN discovery was already done */
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
167 stun = purple_stun_discover(NULL);
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
168 if ((stun != NULL) && (stun->status == PURPLE_STUN_STATUS_DISCOVERED)) {
40110
bc2b94f2595a Make purple_network_get_my_ip_from_gio return non-const.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40107
diff changeset
169 return g_strdup(stun->publicip);
40107
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
170 }
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
171
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
172 /* Attempt to get the IP from a NAT device using UPnP */
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
173 ip = purple_upnp_get_public_ip();
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
174 if (ip != NULL) {
40110
bc2b94f2595a Make purple_network_get_my_ip_from_gio return non-const.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40107
diff changeset
175 return g_strdup(ip);
40107
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
176 }
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
177
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
178 /* Attempt to get the IP from a NAT device using NAT-PMP */
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
179 ip = purple_pmp_get_public_ip();
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
180 if (ip != NULL) {
40110
bc2b94f2595a Make purple_network_get_my_ip_from_gio return non-const.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40107
diff changeset
181 return g_strdup(ip);
40107
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
182 }
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
183 }
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
184
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
185 /* Just fetch the IP of the local system */
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
186 return purple_network_get_local_system_ip_from_gio(sockconn);
6320c272e8b2 xmpp: Convert unencrypted connections to pure GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40017
diff changeset
187 }
11391
d172e72988cc [gaim-migrate @ 13620]
Adam Warrington <awarring@users.sourceforge.net>
parents: 11336
diff changeset
188
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
189 gboolean
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
190 purple_network_is_available(void)
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
191 {
37488
88afe246144e First stab at replacing network-manager with gio, this probably breaks win32, need to test and see
Gary Kramlich <grim@reaperworld.com>
parents: 37466
diff changeset
192 if(force_online) {
24999
84d597b7e7c6 Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@pidgin.im>
parents: 24519
diff changeset
193 return TRUE;
23041
58661da65e36 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@pidgin.im>
parents: 23040
diff changeset
194 }
24519
d4af3d043211 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@pidgin.im>
parents: 24044
diff changeset
195
37488
88afe246144e First stab at replacing network-manager with gio, this probably breaks win32, need to test and see
Gary Kramlich <grim@reaperworld.com>
parents: 37466
diff changeset
196 return g_network_monitor_get_network_available(g_network_monitor_get_default());
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
197 }
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
198
24999
84d597b7e7c6 Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@pidgin.im>
parents: 24519
diff changeset
199 void
84d597b7e7c6 Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@pidgin.im>
parents: 24519
diff changeset
200 purple_network_force_online()
84d597b7e7c6 Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@pidgin.im>
parents: 24519
diff changeset
201 {
84d597b7e7c6 Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@pidgin.im>
parents: 24519
diff changeset
202 force_online = TRUE;
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
203 }
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
204
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
205 static void
37464
8785324c1740 Remove some async lookups that accidentally got left in from my first run at this
Gary Kramlich <grim@reaperworld.com>
parents: 37453
diff changeset
206 purple_network_ip_lookup_cb(GObject *sender, GAsyncResult *result, gpointer data) {
37450
703722d83214 Update network.c for the dns code removal
Gary Kramlich <grim@reaperworld.com>
parents: 36031
diff changeset
207 GError *error = NULL;
37464
8785324c1740 Remove some async lookups that accidentally got left in from my first run at this
Gary Kramlich <grim@reaperworld.com>
parents: 37453
diff changeset
208 GList *addresses = NULL;
37450
703722d83214 Update network.c for the dns code removal
Gary Kramlich <grim@reaperworld.com>
parents: 36031
diff changeset
209 GInetAddress *address = NULL;
37464
8785324c1740 Remove some async lookups that accidentally got left in from my first run at this
Gary Kramlich <grim@reaperworld.com>
parents: 37453
diff changeset
210 const gchar **ip_address = (const gchar **)data;
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
211
37517
a67be31f9c7e Use the GResolver which was passed to g_resolver_lookup_*_async()
Mike Ruprecht <cmaiku@gmail.com>
parents: 37489
diff changeset
212 addresses = g_resolver_lookup_by_name_finish(G_RESOLVER(sender),
a67be31f9c7e Use the GResolver which was passed to g_resolver_lookup_*_async()
Mike Ruprecht <cmaiku@gmail.com>
parents: 37489
diff changeset
213 result, &error);
37464
8785324c1740 Remove some async lookups that accidentally got left in from my first run at this
Gary Kramlich <grim@reaperworld.com>
parents: 37453
diff changeset
214 if(error) {
37450
703722d83214 Update network.c for the dns code removal
Gary Kramlich <grim@reaperworld.com>
parents: 36031
diff changeset
215 purple_debug_info("network", "lookup of IP address failed: %s\n", error->message);
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
216
37450
703722d83214 Update network.c for the dns code removal
Gary Kramlich <grim@reaperworld.com>
parents: 36031
diff changeset
217 g_error_free(error);
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
218
26256
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
219 return;
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
220 }
26262
1ad96aa2e92a Removed some extra tabs on blank lines
Marcus Lundblad <malu@pidgin.im>
parents: 26261
diff changeset
221
37464
8785324c1740 Remove some async lookups that accidentally got left in from my first run at this
Gary Kramlich <grim@reaperworld.com>
parents: 37453
diff changeset
222 address = G_INET_ADDRESS(addresses->data);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 31191
diff changeset
223
37464
8785324c1740 Remove some async lookups that accidentally got left in from my first run at this
Gary Kramlich <grim@reaperworld.com>
parents: 37453
diff changeset
224 *ip_address = g_inet_address_to_string(address);
26262
1ad96aa2e92a Removed some extra tabs on blank lines
Marcus Lundblad <malu@pidgin.im>
parents: 26261
diff changeset
225
37450
703722d83214 Update network.c for the dns code removal
Gary Kramlich <grim@reaperworld.com>
parents: 36031
diff changeset
226 g_resolver_free_addresses(addresses);
26256
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
227 }
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
228
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
229 void
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
230 purple_network_set_stun_server(const gchar *stun_server)
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
231 {
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
232 if (stun_server && stun_server[0] != '\0') {
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
233 if (purple_network_is_available()) {
37518
53c9ebedf2b7 Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents: 37517
diff changeset
234 GResolver *resolver = g_resolver_get_default();
53c9ebedf2b7 Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents: 37517
diff changeset
235 g_resolver_lookup_by_name_async(resolver,
37464
8785324c1740 Remove some async lookups that accidentally got left in from my first run at this
Gary Kramlich <grim@reaperworld.com>
parents: 37453
diff changeset
236 stun_server,
8785324c1740 Remove some async lookups that accidentally got left in from my first run at this
Gary Kramlich <grim@reaperworld.com>
parents: 37453
diff changeset
237 NULL,
8785324c1740 Remove some async lookups that accidentally got left in from my first run at this
Gary Kramlich <grim@reaperworld.com>
parents: 37453
diff changeset
238 purple_network_ip_lookup_cb,
8785324c1740 Remove some async lookups that accidentally got left in from my first run at this
Gary Kramlich <grim@reaperworld.com>
parents: 37453
diff changeset
239 &stun_ip);
37518
53c9ebedf2b7 Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents: 37517
diff changeset
240 g_object_unref(resolver);
26256
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
241 } else {
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 31191
diff changeset
242 purple_debug_info("network",
26256
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
243 "network is unavailable, don't try to update STUN IP");
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
244 }
37426
6fd4989b77e4 The last of the NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents: 36031
diff changeset
245 } else {
26256
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
246 g_free(stun_ip);
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
247 stun_ip = NULL;
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
248 }
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
249 }
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
250
26261
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
251 void
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
252 purple_network_set_turn_server(const gchar *turn_server)
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
253 {
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
254 if (turn_server && turn_server[0] != '\0') {
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
255 if (purple_network_is_available()) {
37518
53c9ebedf2b7 Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents: 37517
diff changeset
256 GResolver *resolver = g_resolver_get_default();
53c9ebedf2b7 Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents: 37517
diff changeset
257 g_resolver_lookup_by_name_async(resolver,
37464
8785324c1740 Remove some async lookups that accidentally got left in from my first run at this
Gary Kramlich <grim@reaperworld.com>
parents: 37453
diff changeset
258 turn_server,
8785324c1740 Remove some async lookups that accidentally got left in from my first run at this
Gary Kramlich <grim@reaperworld.com>
parents: 37453
diff changeset
259 NULL,
8785324c1740 Remove some async lookups that accidentally got left in from my first run at this
Gary Kramlich <grim@reaperworld.com>
parents: 37453
diff changeset
260 purple_network_ip_lookup_cb,
40264
d253f767f6cc fix various memory leaks
Fabrice Bellet <fabrice@bellet.info>
parents: 40110
diff changeset
261 &turn_ip);
37518
53c9ebedf2b7 Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents: 37517
diff changeset
262 g_object_unref(resolver);
26261
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
263 } else {
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 31191
diff changeset
264 purple_debug_info("network",
26261
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
265 "network is unavailable, don't try to update TURN IP");
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
266 }
37426
6fd4989b77e4 The last of the NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents: 36031
diff changeset
267 } else {
26261
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
268 g_free(turn_ip);
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
269 turn_ip = NULL;
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
270 }
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
271 }
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
272
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
273
26256
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
274 const gchar *
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
275 purple_network_get_stun_ip(void)
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
276 {
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
277 return stun_ip;
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
278 }
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
279
26261
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
280 const gchar *
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
281 purple_network_get_turn_ip(void)
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
282 {
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
283 return turn_ip;
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
284 }
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
285
27332
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
286 static void
41083
590d533cf290 Fix several typos in libpurple
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40773
diff changeset
287 purple_network_upnp_mapping_remove_cb(gboolean success, gpointer data)
27332
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
288 {
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
289 purple_debug_info("network", "done removing UPnP port mapping\n");
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
290 }
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
291
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
292 /* the reason for these functions to have these signatures is to be able to
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
293 use them for g_hash_table_foreach to clean remaining port mappings, which is
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
294 not yet done */
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
295 static void
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
296 purple_network_upnp_mapping_remove(gpointer key, gpointer value,
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
297 gpointer user_data)
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
298 {
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
299 gint port = GPOINTER_TO_INT(key);
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
300 gint protocol = GPOINTER_TO_INT(value);
27332
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
301 purple_debug_info("network", "removing UPnP port mapping for port %d\n",
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
302 port);
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
303 purple_upnp_remove_port_mapping(port,
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
304 protocol == SOCK_STREAM ? "TCP" : "UDP",
27332
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
305 purple_network_upnp_mapping_remove_cb, NULL);
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
306 g_hash_table_remove(upnp_port_mappings, GINT_TO_POINTER(port));
27332
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
307 }
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
308
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
309 static void
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
310 purple_network_nat_pmp_mapping_remove(gpointer key, gpointer value,
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
311 gpointer user_data)
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
312 {
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
313 gint port = GPOINTER_TO_INT(key);
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
314 gint protocol = GPOINTER_TO_INT(value);
27332
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
315 purple_debug_info("network", "removing NAT-PMP port mapping for port %d\n",
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
316 port);
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
317 purple_pmp_destroy_map(
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
318 protocol == SOCK_STREAM ? PURPLE_PMP_TYPE_TCP : PURPLE_PMP_TYPE_UDP,
27332
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
319 port);
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
320 g_hash_table_remove(nat_pmp_port_mappings, GINT_TO_POINTER(port));
27332
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
321 }
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
322
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
323 void
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
324 purple_network_remove_port_mapping(gint fd)
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
325 {
40659
ae3652f5ca05 Remove network listener code.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40655
diff changeset
326 gint port, protocol;
ae3652f5ca05 Remove network listener code.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40655
diff changeset
327 struct sockaddr_in addr;
ae3652f5ca05 Remove network listener code.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40655
diff changeset
328 socklen_t len;
ae3652f5ca05 Remove network listener code.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40655
diff changeset
329
ae3652f5ca05 Remove network listener code.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40655
diff changeset
330 g_return_if_fail(fd >= 0);
27332
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
331
40659
ae3652f5ca05 Remove network listener code.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40655
diff changeset
332 len = sizeof(addr);
ae3652f5ca05 Remove network listener code.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40655
diff changeset
333 if (getsockname(fd, (struct sockaddr *) &addr, &len) == -1) {
ae3652f5ca05 Remove network listener code.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40655
diff changeset
334 purple_debug_warning("network", "getsockname: %s", g_strerror(errno));
ae3652f5ca05 Remove network listener code.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40655
diff changeset
335 port = 0;
ae3652f5ca05 Remove network listener code.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40655
diff changeset
336 } else {
ae3652f5ca05 Remove network listener code.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40655
diff changeset
337 port = g_ntohs(addr.sin_port);
ae3652f5ca05 Remove network listener code.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40655
diff changeset
338 }
ae3652f5ca05 Remove network listener code.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40655
diff changeset
339
ae3652f5ca05 Remove network listener code.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40655
diff changeset
340 protocol = GPOINTER_TO_INT(g_hash_table_lookup(upnp_port_mappings, GINT_TO_POINTER(port)));
27332
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
341 if (protocol) {
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
342 purple_network_upnp_mapping_remove(GINT_TO_POINTER(port), GINT_TO_POINTER(protocol), NULL);
27332
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
343 } else {
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
344 protocol = GPOINTER_TO_INT(g_hash_table_lookup(nat_pmp_port_mappings, GINT_TO_POINTER(port)));
27332
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
345 if (protocol) {
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
346 purple_network_nat_pmp_mapping_remove(GINT_TO_POINTER(port), GINT_TO_POINTER(protocol), NULL);
27332
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
347 }
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
348 }
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
349 }
27898
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
350
36028
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
351 gboolean
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
352 _purple_network_set_common_socket_flags(int fd)
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
353 {
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
354 int flags;
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
355 gboolean succ = TRUE;
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
356
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
357 g_return_val_if_fail(fd >= 0, FALSE);
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
358
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
359 flags = fcntl(fd, F_GETFL);
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
360
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
361 if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) != 0) {
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
362 purple_debug_warning("network",
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
363 "Couldn't set O_NONBLOCK flag\n");
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
364 succ = FALSE;
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
365 }
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
366
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
367 #ifndef _WIN32
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
368 if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) {
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
369 purple_debug_warning("network",
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
370 "Couldn't set FD_CLOEXEC flag\n");
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
371 succ = FALSE;
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
372 }
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
373 #endif
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
374
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
375 return succ;
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
376 }
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
377
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
378 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
379 purple_network_init(void)
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
380 {
16478
19107605c565 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents: 16035
diff changeset
381 purple_prefs_add_none ("/purple/network");
26256
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
382 purple_prefs_add_string("/purple/network/stun_server", "");
26261
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
383 purple_prefs_add_string("/purple/network/turn_server", "");
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
384 purple_prefs_add_int ("/purple/network/turn_port", 3478);
31831
c3778a69ecee Add support for using TCP relaying with TURN
Marcus Lundblad <malu@pidgin.im>
parents: 31680
diff changeset
385 purple_prefs_add_int ("/purple/network/turn_port_tcp", 3478);
26261
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
386 purple_prefs_add_string("/purple/network/turn_username", "");
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
387 purple_prefs_add_string("/purple/network/turn_password", "");
16478
19107605c565 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents: 16035
diff changeset
388 purple_prefs_add_bool ("/purple/network/auto_ip", TRUE);
19107605c565 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents: 16035
diff changeset
389 purple_prefs_add_string("/purple/network/public_ip", "");
21810
0b5181178201 Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents: 21549
diff changeset
390 purple_prefs_add_bool ("/purple/network/map_ports", TRUE);
16478
19107605c565 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents: 16035
diff changeset
391 purple_prefs_add_bool ("/purple/network/ports_range_use", FALSE);
19107605c565 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents: 16035
diff changeset
392 purple_prefs_add_int ("/purple/network/ports_range_start", 1024);
19107605c565 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents: 16035
diff changeset
393 purple_prefs_add_int ("/purple/network/ports_range_end", 2048);
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
394
21810
0b5181178201 Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents: 21549
diff changeset
395 if(purple_prefs_get_bool("/purple/network/map_ports") || purple_prefs_get_bool("/purple/network/auto_ip"))
0b5181178201 Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents: 21549
diff changeset
396 purple_upnp_discover(NULL, NULL);
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
397
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16012
diff changeset
398 purple_pmp_init();
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16012
diff changeset
399 purple_upnp_init();
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
400
26256
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
401 purple_network_set_stun_server(
d2673c935184 Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <malu@pidgin.im>
parents: 25326
diff changeset
402 purple_prefs_get_string("/purple/network/stun_server"));
26261
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
403 purple_network_set_turn_server(
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
404 purple_prefs_get_string("/purple/network/turn_server"));
27332
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
405
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
406 upnp_port_mappings = g_hash_table_new(g_direct_hash, g_direct_equal);
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
407 nat_pmp_port_mappings = g_hash_table_new(g_direct_hash, g_direct_equal);
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
408 }
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
409
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
410 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
411 purple_network_uninit(void)
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
412 {
37426
6fd4989b77e4 The last of the NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents: 36031
diff changeset
413 g_free(stun_ip);
40264
d253f767f6cc fix various memory leaks
Fabrice Bellet <fabrice@bellet.info>
parents: 40110
diff changeset
414 g_free(turn_ip);
27332
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
415
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
416 g_hash_table_destroy(upnp_port_mappings);
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
417 g_hash_table_destroy(nat_pmp_port_mappings);
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
418
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
419 /* TODO: clean up remaining port mappings, note calling
27332
8240ab259385 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <malu@pidgin.im>
parents: 27116
diff changeset
420 purple_upnp_remove_port_mapping from here doesn't quite work... */
40017
258b6fab7e79 Convert UPnP mappings to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39291
diff changeset
421
258b6fab7e79 Convert UPnP mappings to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39291
diff changeset
422 purple_upnp_uninit();
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
423 }

mercurial