libpurple/network.c

Mon, 21 Dec 2015 22:14:59 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Mon, 21 Dec 2015 22:14:59 -0600
branch
use-gresolver
changeset 37466
ef015fb22744
parent 37464
8785324c1740
parent 37426
6fd4989b77e4
child 37488
88afe246144e
permissions
-rw-r--r--

Merge default back in

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"
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
23
37450
703722d83214 Update network.c for the dns code removal
Gary Kramlich <grim@reaperworld.com>
parents: 36031
diff changeset
24 #include <gio/gio.h>
703722d83214 Update network.c for the dns code removal
Gary Kramlich <grim@reaperworld.com>
parents: 36031
diff changeset
25
13156
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
26 #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
27 #include <arpa/nameser.h>
14864
a1cbdeffee69 [gaim-migrate @ 17567]
Sean Egan <seanegan@pidgin.im>
parents: 14862
diff changeset
28 #include <resolv.h>
a1cbdeffee69 [gaim-migrate @ 17567]
Sean Egan <seanegan@pidgin.im>
parents: 14862
diff changeset
29 #include <netinet/in.h>
13156
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
30 #include <net/if.h>
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
31 #include <sys/ioctl.h>
29714
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
32 #ifdef HAVE_GETIFADDRS
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
33 #include <ifaddrs.h>
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
34 #endif
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
35 #else
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
36 #include <nspapi.h>
13156
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
37 #endif
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
38
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
39 /* Solaris */
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
40 #if defined (__SVR4) && defined (__sun)
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
41 #include <sys/sockio.h>
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
42 #endif
539a637c61dc [gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13131
diff changeset
43
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
44 #include "debug.h"
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
45 #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
46 #include "nat-pmp.h"
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
47 #include "network.h"
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
48 #include "prefs.h"
11411
b74834586187 [gaim-migrate @ 13648]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11391
diff changeset
49 #include "stun.h"
11195
d84d542a04ac [gaim-migrate @ 13319]
Adam Warrington <awarring@users.sourceforge.net>
parents: 11033
diff changeset
50 #include "upnp.h"
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
51
27898
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
52 #ifdef USE_IDN
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
53 #include <idna.h>
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
54 #endif
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
55
15278
7f469b5c8d7a [gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents: 15116
diff changeset
56 /*
7f469b5c8d7a [gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents: 15116
diff changeset
57 * Calling sizeof(struct ifreq) isn't always correct on
7f469b5c8d7a [gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents: 15116
diff changeset
58 * Mac OS X (and maybe others).
7f469b5c8d7a [gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents: 15116
diff changeset
59 */
7f469b5c8d7a [gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents: 15116
diff changeset
60 #ifdef _SIZEOF_ADDR_IFREQ
7f469b5c8d7a [gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents: 15116
diff changeset
61 # define HX_SIZE_OF_IFREQ(a) _SIZEOF_ADDR_IFREQ(a)
7f469b5c8d7a [gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents: 15116
diff changeset
62 #else
7f469b5c8d7a [gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents: 15116
diff changeset
63 # define HX_SIZE_OF_IFREQ(a) sizeof(a)
7f469b5c8d7a [gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents: 15116
diff changeset
64 #endif
7f469b5c8d7a [gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents: 15116
diff changeset
65
23060
db9632a9b374 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@pidgin.im>
parents: 23054
diff changeset
66 #ifdef HAVE_NETWORKMANAGER
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
67 #include <dbus/dbus-glib.h>
23060
db9632a9b374 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@pidgin.im>
parents: 23054
diff changeset
68 #include <NetworkManager.h>
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
69
31653
a36102ecb723 Support new connection states in NetworkMakanter 0.9. Fixes #13505.
Dan Williams <dcbw@redhat.com>
parents: 31294
diff changeset
70 #if !defined(NM_CHECK_VERSION)
a36102ecb723 Support new connection states in NetworkMakanter 0.9. Fixes #13505.
Dan Williams <dcbw@redhat.com>
parents: 31294
diff changeset
71 #define NM_CHECK_VERSION(x,y,z) 0
a36102ecb723 Support new connection states in NetworkMakanter 0.9. Fixes #13505.
Dan Williams <dcbw@redhat.com>
parents: 31294
diff changeset
72 #endif
a36102ecb723 Support new connection states in NetworkMakanter 0.9. Fixes #13505.
Dan Williams <dcbw@redhat.com>
parents: 31294
diff changeset
73
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
74 static DBusGConnection *nm_conn = NULL;
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
75 static DBusGProxy *nm_proxy = NULL;
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
76 static DBusGProxy *dbus_proxy = NULL;
24519
d4af3d043211 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@pidgin.im>
parents: 24044
diff changeset
77 static NMState nm_state = NM_STATE_UNKNOWN;
d4af3d043211 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@pidgin.im>
parents: 24044
diff changeset
78 static gboolean have_nm_state = FALSE;
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
79
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
80 #elif defined _WIN32
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
81 static int current_network_count;
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
82
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
83 /* Mutex for the other global vars */
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
84 #if GLIB_CHECK_VERSION(2, 32, 0)
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
85 static GMutex mutex;
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
86 #else
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
87 static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
88 #endif
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
89
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
90 static gboolean network_initialized = FALSE;
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
91 static HANDLE network_change_handle = NULL;
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
92 static int (WSAAPI *MyWSANSPIoctl) (
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
93 HANDLE hLookup, DWORD dwControlCode, LPVOID lpvInBuffer,
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
94 DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
95 LPDWORD lpcbBytesReturned, LPWSACOMPLETION lpCompletion) = NULL;
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
96 #endif
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
97
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
98 struct _PurpleNetworkListenData {
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
99 int listenfd;
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
100 int socket_type;
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
101 gboolean retry;
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
102 gboolean adding;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
103 PurpleNetworkListenCallback cb;
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
104 gpointer cb_data;
35499
c4c5e0a670b1 Fix namespaces issues in libpurple.
Ankit Vani <a@nevitus.org>
parents: 35462
diff changeset
105 PurpleUPnPMappingAddRemove *mapping_data;
30614
ba7a36c1696b Make sure we keep track of this timer and remove it if our caller frees
Mark Doliner <markdoliner@pidgin.im>
parents: 30027
diff changeset
106 int timer;
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
107 };
11391
d172e72988cc [gaim-migrate @ 13620]
Adam Warrington <awarring@users.sourceforge.net>
parents: 11336
diff changeset
108
23060
db9632a9b374 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@pidgin.im>
parents: 23054
diff changeset
109 #ifdef HAVE_NETWORKMANAGER
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
110 static NMState nm_get_network_state(void);
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
111 #endif
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
112
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
113 #if defined(HAVE_NETWORKMANAGER) || defined(_WIN32)
84d597b7e7c6 Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@pidgin.im>
parents: 24519
diff changeset
114 static gboolean 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
115 #endif
84d597b7e7c6 Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@pidgin.im>
parents: 24519
diff changeset
116
26261
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
117 /* 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
118 static gchar *stun_ip = NULL;
26261
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
119 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
120
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
121 /* 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
122 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
123 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
124
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
125 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
126 purple_network_set_public_ip(const char *ip)
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
127 {
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
128 g_return_if_fail(ip != NULL);
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
129
8838
c23227da7b4a [gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents: 8834
diff changeset
130 /* XXX - Ensure the IP address is valid */
c23227da7b4a [gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents: 8834
diff changeset
131
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
132 purple_prefs_set_string("/purple/network/public_ip", ip);
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
133 }
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
134
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
135 const char *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
136 purple_network_get_public_ip(void)
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
137 {
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
138 return purple_prefs_get_string("/purple/network/public_ip");
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
139 }
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
140
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
141 const char *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
142 purple_network_get_local_system_ip(int fd)
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
143 {
35683
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
144 struct ifreq buffer[100];
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
145 guchar *it, *it_end;
13346
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
146 static char ip[16];
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
147 struct ifconf ifc;
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
148 struct ifreq *ifr;
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
149 struct sockaddr_in *sinptr;
29704
1e17cbbf18a3 Clean up a little.
Paul Aurich <darkrain42@pidgin.im>
parents: 29513
diff changeset
150 guint32 lhost = htonl((127 << 24) + 1); /* 127.0.0.1 */
13346
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
151 long unsigned int add;
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
152 int source = fd;
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
153
13346
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
154 if (fd < 0)
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
155 source = socket(PF_INET,SOCK_STREAM, 0);
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
156
13346
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
157 ifc.ifc_len = sizeof(buffer);
35683
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
158 ifc.ifc_req = buffer;
13346
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
159 ioctl(source, SIOCGIFCONF, &ifc);
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
160
35991
e6937e52930b Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 32077
diff changeset
161 if (fd < 0 && source >= 0)
13346
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
162 close(source);
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
163
35683
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
164 it = (guchar*)buffer;
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
165 it_end = it + ifc.ifc_len;
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
166 while (it < it_end) {
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
167 /* in this case "it" is:
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
168 * a) (struct ifreq)-aligned
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
169 * b) not aligned, because of OS quirks (see
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
170 * _SIZEOF_ADDR_IFREQ), so the OS should deal with it.
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
171 */
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
172 ifr = (struct ifreq *)(gpointer)it;
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
173 it += HX_SIZE_OF_IFREQ(*ifr);
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
174
13346
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
175 if (ifr->ifr_addr.sa_family == AF_INET)
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
176 {
35683
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
177 sinptr = (struct sockaddr_in *)(gpointer)&ifr->ifr_addr;
13346
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
178 if (sinptr->sin_addr.s_addr != lhost)
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
179 {
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
180 add = ntohl(sinptr->sin_addr.s_addr);
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
181 g_snprintf(ip, 16, "%lu.%lu.%lu.%lu",
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
182 ((add >> 24) & 255),
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
183 ((add >> 16) & 255),
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
184 ((add >> 8) & 255),
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
185 add & 255);
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
186
13346
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
187 return ip;
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
188 }
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
189 }
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
190 }
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
191
a024b2b0a160 [gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents: 13168
diff changeset
192 return "0.0.0.0";
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
193 }
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
194
29510
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
195 GList *
29511
7c4b1ba4f2aa Remove IPv6 support from _get_local_system_ips, since I couldn't get it to
Marcus Lundblad <malu@pidgin.im>
parents: 29510
diff changeset
196 purple_network_get_all_local_system_ips(void)
29510
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
197 {
29716
59a5b6c2e6cb Oops, probably better if we have both getifaddrs() and inet_ntop()
Paul Aurich <darkrain42@pidgin.im>
parents: 29714
diff changeset
198 #if defined(HAVE_GETIFADDRS) && defined(HAVE_INET_NTOP)
29714
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
199 GList *result = NULL;
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
200 struct ifaddrs *start, *ifa;
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
201 int ret;
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
202
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
203 ret = getifaddrs(&start);
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
204 if (ret < 0) {
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
205 purple_debug_warning("network",
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
206 "getifaddrs() failed: %s\n", g_strerror(errno));
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
207 return NULL;
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
208 }
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
209
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
210 for (ifa = start; ifa; ifa = ifa->ifa_next) {
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
211 int family = ifa->ifa_addr ? ifa->ifa_addr->sa_family : AF_UNSPEC;
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
212 char host[INET6_ADDRSTRLEN];
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
213 const char *tmp = NULL;
35683
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
214 common_sockaddr_t *addr =
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
215 (common_sockaddr_t *)(gpointer)ifa->ifa_addr;
29714
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
216
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
217 if ((family != AF_INET && family != AF_INET6) || ifa->ifa_flags & IFF_LOOPBACK)
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
218 continue;
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
219
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
220 if (family == AF_INET)
35683
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
221 tmp = inet_ntop(family, &addr->in.sin_addr, host, sizeof(host));
29714
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
222 else {
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
223 /* Peer-peer link-local communication is a big TODO. I am not sure
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
224 * how communicating link-local addresses is supposed to work, and
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
225 * it seems like it would require attempting the cartesian product
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
226 * of the local and remote interfaces to see if any match (eww).
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
227 */
35683
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
228 if (!IN6_IS_ADDR_LINKLOCAL(&addr->in6.sin6_addr))
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
229 tmp = inet_ntop(family, &addr->in6.sin6_addr, host, sizeof(host));
29714
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
230 }
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
231 if (tmp != NULL)
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
232 result = g_list_prepend(result, g_strdup(tmp));
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
233 }
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
234
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
235 freeifaddrs(start);
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
236
8c1f3beb9fdc network: Use getifaddrs() to enumerate local interfaces/IPs if available.
Paul Aurich <darkrain42@pidgin.im>
parents: 29704
diff changeset
237 return g_list_reverse(result);
29716
59a5b6c2e6cb Oops, probably better if we have both getifaddrs() and inet_ntop()
Paul Aurich <darkrain42@pidgin.im>
parents: 29714
diff changeset
238 #else /* HAVE_GETIFADDRS && HAVE_INET_NTOP */
29510
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
239 GList *result = NULL;
29704
1e17cbbf18a3 Clean up a little.
Paul Aurich <darkrain42@pidgin.im>
parents: 29513
diff changeset
240 int source = socket(PF_INET,SOCK_STREAM, 0);
35683
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
241 struct ifreq buffer[100];
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
242 guchar *it, *it_end;
29510
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
243 struct ifconf ifc;
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
244 struct ifreq *ifr;
29704
1e17cbbf18a3 Clean up a little.
Paul Aurich <darkrain42@pidgin.im>
parents: 29513
diff changeset
245
29510
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
246 ifc.ifc_len = sizeof(buffer);
35683
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
247 ifc.ifc_req = buffer;
29510
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
248 ioctl(source, SIOCGIFCONF, &ifc);
29511
7c4b1ba4f2aa Remove IPv6 support from _get_local_system_ips, since I couldn't get it to
Marcus Lundblad <malu@pidgin.im>
parents: 29510
diff changeset
249 close(source);
29510
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
250
35683
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
251 it = (guchar*)buffer;
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
252 it_end = it + ifc.ifc_len;
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
253 while (it < it_end) {
29511
7c4b1ba4f2aa Remove IPv6 support from _get_local_system_ips, since I couldn't get it to
Marcus Lundblad <malu@pidgin.im>
parents: 29510
diff changeset
254 char dst[INET_ADDRSTRLEN];
29510
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
255
35683
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
256 /* alignment: see purple_network_get_local_system_ip */
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
257 ifr = (struct ifreq *)(gpointer)it;
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
258 it += HX_SIZE_OF_IFREQ(*ifr);
29510
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
259
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
260 if (ifr->ifr_addr.sa_family == AF_INET) {
35683
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
261 struct sockaddr_in *sinptr =
8b6b8a3b5039 Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35499
diff changeset
262 (struct sockaddr_in *)(gpointer)&ifr->ifr_addr;
29510
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
263
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
264 inet_ntop(AF_INET, &sinptr->sin_addr, dst,
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
265 sizeof(dst));
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 31191
diff changeset
266 purple_debug_info("network",
29510
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
267 "found local i/f with address %s on IPv4\n", dst);
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
268 if (!purple_strequal(dst, "127.0.0.1")) {
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
269 result = g_list_append(result, g_strdup(dst));
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
270 }
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
271 }
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
272 }
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
273
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
274 return result;
29716
59a5b6c2e6cb Oops, probably better if we have both getifaddrs() and inet_ntop()
Paul Aurich <darkrain42@pidgin.im>
parents: 29714
diff changeset
275 #endif /* HAVE_GETIFADDRS && HAVE_INET_NTOP */
29510
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
276 }
9c636f4b965c Add a function to enumerate all local IPs
Marcus Lundblad <malu@pidgin.im>
parents: 27898
diff changeset
277
35462
901dfa763f15 Fix some gtk-doc warnings till proxy.c
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
278 /*
901dfa763f15 Fix some gtk-doc warnings till proxy.c
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
279 * purple_network_is_ipv4:
901dfa763f15 Fix some gtk-doc warnings till proxy.c
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
280 * @hostname: The hostname to be verified.
901dfa763f15 Fix some gtk-doc warnings till proxy.c
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
281 *
33894
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
282 * 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
283 *
35462
901dfa763f15 Fix some gtk-doc warnings till proxy.c
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
284 * 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
285 */
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
286 static gboolean
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
287 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
288 {
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
289 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
290
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
291 /* 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
292 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
293 return FALSE;
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
294
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
295 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
296 }
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
297
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
298 const char *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
299 purple_network_get_my_ip(int fd)
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
300 {
12686
ec3e7c4ff045 [gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents: 11424
diff changeset
301 const char *ip = NULL;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
302 PurpleStunNatDiscovery *stun;
8834
0a798e3d2b84 [gaim-migrate @ 9598]
Mark Doliner <markdoliner@pidgin.im>
parents: 8251
diff changeset
303
0a798e3d2b84 [gaim-migrate @ 9598]
Mark Doliner <markdoliner@pidgin.im>
parents: 8251
diff changeset
304 /* 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
305 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
306 ip = purple_network_get_public_ip();
15116
037b787407ba [gaim-migrate @ 17838]
Mark Doliner <markdoliner@pidgin.im>
parents: 14959
diff changeset
307 /* Make sure the IP address entered by the user is valid */
33894
7e3ea8475aad Get rid of useless form of purple_network_ip_atoi
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33883
diff changeset
308 if ((ip != NULL) && (purple_network_is_ipv4(ip)))
8834
0a798e3d2b84 [gaim-migrate @ 9598]
Mark Doliner <markdoliner@pidgin.im>
parents: 8251
diff changeset
309 return 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
310 } else {
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
311 /* Check if STUN discovery was already done */
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
312 stun = purple_stun_discover(NULL);
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
313 if ((stun != NULL) && (stun->status == PURPLE_STUN_STATUS_DISCOVERED))
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
314 return stun->publicip;
11424
b0f8535daa74 [gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11411
diff changeset
315
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
316 /* Attempt to get the IP from a NAT device using UPnP */
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
317 ip = purple_upnp_get_public_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
318 if (ip != NULL)
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
319 return ip;
11195
d84d542a04ac [gaim-migrate @ 13319]
Adam Warrington <awarring@users.sourceforge.net>
parents: 11033
diff changeset
320
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
321 /* Attempt to get the IP from a NAT device using NAT-PMP */
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
322 ip = purple_pmp_get_public_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
323 if (ip != NULL)
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
324 return 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
325 }
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
326
8834
0a798e3d2b84 [gaim-migrate @ 9598]
Mark Doliner <markdoliner@pidgin.im>
parents: 8251
diff changeset
327 /* Just fetch the IP of the local system */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
328 return purple_network_get_local_system_ip(fd);
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
329 }
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
330
11391
d172e72988cc [gaim-migrate @ 13620]
Adam Warrington <awarring@users.sourceforge.net>
parents: 11336
diff changeset
331
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
332 static void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
333 purple_network_set_upnp_port_mapping_cb(gboolean success, gpointer data)
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
334 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
335 PurpleNetworkListenData *listen_data;
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
336
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
337 listen_data = data;
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
338 /* TODO: Once we're keeping track of upnp requests... */
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
339 /* listen_data->pnp_data = NULL; */
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
340
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
341 if (!success) {
27497
2dc5a0e0c4c2 Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents: 27334
diff changeset
342 purple_debug_warning("network", "Couldn't create UPnP mapping\n");
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
343 if (listen_data->retry) {
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
344 listen_data->retry = FALSE;
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
345 listen_data->adding = FALSE;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
346 listen_data->mapping_data = purple_upnp_remove_port_mapping(
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
347 purple_network_get_port_from_fd(listen_data->listenfd),
15502
250802f80d94 Fix a crash when a network_listen_range process is canceled before its UPnP port mapping completes, which occurs regularly on certain routers when file transfers are initiated and then quickly finished. Much thanks to Elliott Harris and Eric Richie for their hard work with me hunting this down and fixing it.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
348 (listen_data->socket_type == SOCK_STREAM) ? "TCP" : "UDP",
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
349 purple_network_set_upnp_port_mapping_cb, listen_data);
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
350 return;
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
351 }
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
352 } else if (!listen_data->adding) {
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
353 /* We've tried successfully to remove the port mapping.
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
354 * Try to add it again */
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
355 listen_data->adding = TRUE;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
356 listen_data->mapping_data = purple_upnp_set_port_mapping(
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
357 purple_network_get_port_from_fd(listen_data->listenfd),
15502
250802f80d94 Fix a crash when a network_listen_range process is canceled before its UPnP port mapping completes, which occurs regularly on certain routers when file transfers are initiated and then quickly finished. Much thanks to Elliott Harris and Eric Richie for their hard work with me hunting this down and fixing it.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
358 (listen_data->socket_type == SOCK_STREAM) ? "TCP" : "UDP",
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
359 purple_network_set_upnp_port_mapping_cb, listen_data);
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
360 return;
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
361 }
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
362
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
363 if (success) {
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
364 /* add port mapping to hash table */
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
365 gint key = purple_network_get_port_from_fd(listen_data->listenfd);
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
366 gint value = listen_data->socket_type;
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
367 g_hash_table_insert(upnp_port_mappings, GINT_TO_POINTER(key), GINT_TO_POINTER(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
368 }
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
369
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
370 if (listen_data->cb)
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
371 listen_data->cb(listen_data->listenfd, listen_data->cb_data);
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
372
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
373 /* Clear the UPnP mapping data, since it's complete and purple_network_listen_cancel() will try to cancel
15502
250802f80d94 Fix a crash when a network_listen_range process is canceled before its UPnP port mapping completes, which occurs regularly on certain routers when file transfers are initiated and then quickly finished. Much thanks to Elliott Harris and Eric Richie for their hard work with me hunting this down and fixing it.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
374 * it otherwise. */
250802f80d94 Fix a crash when a network_listen_range process is canceled before its UPnP port mapping completes, which occurs regularly on certain routers when file transfers are initiated and then quickly finished. Much thanks to Elliott Harris and Eric Richie for their hard work with me hunting this down and fixing it.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
375 listen_data->mapping_data = NULL;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
376 purple_network_listen_cancel(listen_data);
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
377 }
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
378
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
379 static gboolean
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
380 purple_network_finish_pmp_map_cb(gpointer data)
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
381 {
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
382 PurpleNetworkListenData *listen_data;
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
383 gint key;
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
384 gint value;
15963
effb28723fee Whitespace and make sure stuff is #defined to an actual value.
Mark Doliner <markdoliner@pidgin.im>
parents: 15956
diff changeset
385
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
386 listen_data = data;
30614
ba7a36c1696b Make sure we keep track of this timer and remove it if our caller frees
Mark Doliner <markdoliner@pidgin.im>
parents: 30027
diff changeset
387 listen_data->timer = 0;
15963
effb28723fee Whitespace and make sure stuff is #defined to an actual value.
Mark Doliner <markdoliner@pidgin.im>
parents: 15956
diff changeset
388
27334
1e3e27346559 Remove port mappings from the hash tables when removing them.
Marcus Lundblad <malu@pidgin.im>
parents: 27332
diff changeset
389 /* add port mapping to hash table */
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
390 key = purple_network_get_port_from_fd(listen_data->listenfd);
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
391 value = listen_data->socket_type;
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
392 g_hash_table_insert(nat_pmp_port_mappings, GINT_TO_POINTER(key), GINT_TO_POINTER(value));
27334
1e3e27346559 Remove port mappings from the hash tables when removing them.
Marcus Lundblad <malu@pidgin.im>
parents: 27332
diff changeset
393
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
394 if (listen_data->cb)
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
395 listen_data->cb(listen_data->listenfd, listen_data->cb_data);
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
396
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
397 purple_network_listen_cancel(listen_data);
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
398
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
399 return FALSE;
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
400 }
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
401
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
402 static PurpleNetworkListenData *
32594
f2feea134fdb Remove deprecated purple_network_listen_map_external().
Andrew Victor <andrew.victor@mxit.com>
parents: 32593
diff changeset
403 purple_network_do_listen(unsigned short port, int socket_family, int socket_type, gboolean map_external,
f2feea134fdb Remove deprecated purple_network_listen_map_external().
Andrew Victor <andrew.victor@mxit.com>
parents: 32593
diff changeset
404 PurpleNetworkListenCallback cb, gpointer cb_data)
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
405 {
9452
0e3cdb898d3e [gaim-migrate @ 10276]
Mark Doliner <markdoliner@pidgin.im>
parents: 9449
diff changeset
406 int listenfd = -1;
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
407 const int on = 1;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
408 PurpleNetworkListenData *listen_data;
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
409 unsigned short actual_port;
13426
032ea2c9ce2d [gaim-migrate @ 15800]
Daniel Atallah <datallah@pidgin.im>
parents: 13346
diff changeset
410 #ifdef HAVE_GETADDRINFO
9449
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
411 int errnum;
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
412 struct addrinfo hints, *res, *next;
9456
b5f072bbe9d2 [gaim-migrate @ 10280]
Tim Ringenbach <marv@pidgin.im>
parents: 9455
diff changeset
413 char serv[6];
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
414
9449
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
415 /*
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
416 * Get a list of addresses on this machine.
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
417 */
27116
19dff7b3ed0f A patch from Scott Wolchok to replace snprintf() with g_snprintf() and
Richard Laager <rlaager@pidgin.im>
parents: 26782
diff changeset
418 g_snprintf(serv, sizeof(serv), "%hu", port);
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
419 memset(&hints, 0, sizeof(struct addrinfo));
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
420 hints.ai_flags = AI_PASSIVE;
30027
2ab6e591cf72 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <darkrain42@pidgin.im>
parents: 29716
diff changeset
421 hints.ai_family = socket_family;
12730
f64fdbc34677 [gaim-migrate @ 15074]
Daniel Atallah <datallah@pidgin.im>
parents: 12728
diff changeset
422 hints.ai_socktype = socket_type;
9449
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
423 errnum = getaddrinfo(NULL /* any IP */, serv, &hints, &res);
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
424 if (errnum != 0) {
11221
be3982550ac0 [gaim-migrate @ 13353]
Daniel Atallah <datallah@pidgin.im>
parents: 11215
diff changeset
425 #ifndef _WIN32
21977
c87889698afb Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <markdoliner@pidgin.im>
parents: 21817
diff changeset
426 purple_debug_warning("network", "getaddrinfo: %s\n", purple_gai_strerror(errnum));
9449
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
427 if (errnum == EAI_SYSTEM)
21389
e1dd8142bb87 replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20239
diff changeset
428 purple_debug_warning("network", "getaddrinfo: system error: %s\n", g_strerror(errno));
11221
be3982550ac0 [gaim-migrate @ 13353]
Daniel Atallah <datallah@pidgin.im>
parents: 11215
diff changeset
429 #else
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
430 purple_debug_warning("network", "getaddrinfo: Error Code = %d\n", errnum);
11221
be3982550ac0 [gaim-migrate @ 13353]
Daniel Atallah <datallah@pidgin.im>
parents: 11215
diff changeset
431 #endif
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
432 return NULL;
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
433 }
9449
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
434
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
435 /*
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
436 * Go through the list of addresses and attempt to listen on
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
437 * one of them.
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
438 * XXX - Try IPv6 addresses first?
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
439 */
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
440 for (next = res; next != NULL; next = next->ai_next) {
9455
b16e0c0ac03c [gaim-migrate @ 10279]
Tim Ringenbach <marv@pidgin.im>
parents: 9452
diff changeset
441 listenfd = socket(next->ai_family, next->ai_socktype, next->ai_protocol);
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
442 if (listenfd < 0)
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
443 continue;
9449
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
444 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0)
30027
2ab6e591cf72 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <darkrain42@pidgin.im>
parents: 29716
diff changeset
445 purple_debug_warning("network", "setsockopt(SO_REUSEADDR): %s\n", g_strerror(errno));
9455
b16e0c0ac03c [gaim-migrate @ 10279]
Tim Ringenbach <marv@pidgin.im>
parents: 9452
diff changeset
446 if (bind(listenfd, next->ai_addr, next->ai_addrlen) == 0)
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
447 break; /* success */
12730
f64fdbc34677 [gaim-migrate @ 15074]
Daniel Atallah <datallah@pidgin.im>
parents: 12728
diff changeset
448 /* XXX - It is unclear to me (datallah) whether we need to be
f64fdbc34677 [gaim-migrate @ 15074]
Daniel Atallah <datallah@pidgin.im>
parents: 12728
diff changeset
449 using a new socket each time */
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
450 close(listenfd);
9449
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
451 }
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
452
9449
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
453 freeaddrinfo(res);
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
454
9449
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
455 if (next == NULL)
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
456 return NULL;
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
457 #else
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
458 struct sockaddr_in sockin;
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
459
30027
2ab6e591cf72 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <darkrain42@pidgin.im>
parents: 29716
diff changeset
460 if (socket_family != AF_INET && socket_family != AF_UNSPEC) {
2ab6e591cf72 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <darkrain42@pidgin.im>
parents: 29716
diff changeset
461 purple_debug_warning("network", "Address family %d only "
2ab6e591cf72 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <darkrain42@pidgin.im>
parents: 29716
diff changeset
462 "supported when built with getaddrinfo() "
2ab6e591cf72 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <darkrain42@pidgin.im>
parents: 29716
diff changeset
463 "support\n", socket_family);
2ab6e591cf72 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <darkrain42@pidgin.im>
parents: 29716
diff changeset
464 return NULL;
2ab6e591cf72 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <darkrain42@pidgin.im>
parents: 29716
diff changeset
465 }
2ab6e591cf72 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <darkrain42@pidgin.im>
parents: 29716
diff changeset
466
12730
f64fdbc34677 [gaim-migrate @ 15074]
Daniel Atallah <datallah@pidgin.im>
parents: 12728
diff changeset
467 if ((listenfd = socket(AF_INET, socket_type, 0)) < 0) {
21389
e1dd8142bb87 replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20239
diff changeset
468 purple_debug_warning("network", "socket: %s\n", g_strerror(errno));
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
469 return NULL;
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
470 }
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
471
9449
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
472 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0)
21389
e1dd8142bb87 replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20239
diff changeset
473 purple_debug_warning("network", "setsockopt: %s\n", g_strerror(errno));
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
474
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
475 memset(&sockin, 0, sizeof(struct sockaddr_in));
9449
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
476 sockin.sin_family = PF_INET;
8251
091ca9b900c1 [gaim-migrate @ 8974]
Mark Doliner <markdoliner@pidgin.im>
parents: 8250
diff changeset
477 sockin.sin_port = htons(port);
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
478
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
479 if (bind(listenfd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) {
21389
e1dd8142bb87 replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20239
diff changeset
480 purple_debug_warning("network", "bind: %s\n", g_strerror(errno));
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
481 close(listenfd);
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
482 return NULL;
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
483 }
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
484 #endif
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
485
12730
f64fdbc34677 [gaim-migrate @ 15074]
Daniel Atallah <datallah@pidgin.im>
parents: 12728
diff changeset
486 if (socket_type == SOCK_STREAM && listen(listenfd, 4) != 0) {
21389
e1dd8142bb87 replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20239
diff changeset
487 purple_debug_warning("network", "listen: %s\n", g_strerror(errno));
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
488 close(listenfd);
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
489 return NULL;
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
490 }
36028
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
491 _purple_network_set_common_socket_flags(listenfd);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
492 actual_port = purple_network_get_port_from_fd(listenfd);
11391
d172e72988cc [gaim-migrate @ 13620]
Adam Warrington <awarring@users.sourceforge.net>
parents: 11336
diff changeset
493
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
494 purple_debug_info("network", "Listening on port: %hu\n", actual_port);
15963
effb28723fee Whitespace and make sure stuff is #defined to an actual value.
Mark Doliner <markdoliner@pidgin.im>
parents: 15956
diff changeset
495
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
496 listen_data = g_new0(PurpleNetworkListenData, 1);
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
497 listen_data->listenfd = listenfd;
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
498 listen_data->adding = TRUE;
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
499 listen_data->retry = TRUE;
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
500 listen_data->cb = cb;
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
501 listen_data->cb_data = cb_data;
19822
a533aa745702 Store the socket_type in the PurpleNetworkListenData correctly so that callback functions can use it correctly. Fixes #2933.
Daniel Atallah <datallah@pidgin.im>
parents: 19585
diff changeset
502 listen_data->socket_type = socket_type;
11195
d84d542a04ac [gaim-migrate @ 13319]
Adam Warrington <awarring@users.sourceforge.net>
parents: 11033
diff changeset
503
32594
f2feea134fdb Remove deprecated purple_network_listen_map_external().
Andrew Victor <andrew.victor@mxit.com>
parents: 32593
diff changeset
504 if (!purple_socket_speaks_ipv4(listenfd) || !map_external ||
30027
2ab6e591cf72 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <darkrain42@pidgin.im>
parents: 29716
diff changeset
505 !purple_prefs_get_bool("/purple/network/map_ports"))
21549
7436059db33b Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents: 21389
diff changeset
506 {
7436059db33b Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents: 21389
diff changeset
507 purple_debug_info("network", "Skipping external port mapping.\n");
7436059db33b Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents: 21389
diff changeset
508 /* The pmp_map_cb does what we want to do */
30614
ba7a36c1696b Make sure we keep track of this timer and remove it if our caller frees
Mark Doliner <markdoliner@pidgin.im>
parents: 30027
diff changeset
509 listen_data->timer = purple_timeout_add(0, purple_network_finish_pmp_map_cb, listen_data);
21549
7436059db33b Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents: 21389
diff changeset
510 }
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
511 /* Attempt a NAT-PMP Mapping, which will return immediately */
21549
7436059db33b Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents: 21389
diff changeset
512 else if (purple_pmp_create_map(((socket_type == SOCK_STREAM) ? PURPLE_PMP_TYPE_TCP : PURPLE_PMP_TYPE_UDP),
16012
77b7fe1bfe69 purple_pmp_create_map() returns a gboolean now, not a pointer
Evan Schoenberg <evands@pidgin.im>
parents: 15963
diff changeset
513 actual_port, actual_port, PURPLE_PMP_LIFETIME))
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
514 {
21549
7436059db33b Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents: 21389
diff changeset
515 purple_debug_info("network", "Created NAT-PMP mapping on port %i\n", actual_port);
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
516 /* We want to return listen_data now, and on the next run loop trigger the cb and destroy listen_data */
30614
ba7a36c1696b Make sure we keep track of this timer and remove it if our caller frees
Mark Doliner <markdoliner@pidgin.im>
parents: 30027
diff changeset
517 listen_data->timer = purple_timeout_add(0, purple_network_finish_pmp_map_cb, listen_data);
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
518 }
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
519 else
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
520 {
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
521 /* Attempt a UPnP Mapping */
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
522 listen_data->mapping_data = purple_upnp_set_port_mapping(
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
523 actual_port,
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
524 (socket_type == SOCK_STREAM) ? "TCP" : "UDP",
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
525 purple_network_set_upnp_port_mapping_cb, listen_data);
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
526 }
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
527
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
528 return listen_data;
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
529 }
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
530
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
531 PurpleNetworkListenData *
32594
f2feea134fdb Remove deprecated purple_network_listen_map_external().
Andrew Victor <andrew.victor@mxit.com>
parents: 32593
diff changeset
532 purple_network_listen(unsigned short port, int socket_family, int socket_type,
f2feea134fdb Remove deprecated purple_network_listen_map_external().
Andrew Victor <andrew.victor@mxit.com>
parents: 32593
diff changeset
533 gboolean map_external, PurpleNetworkListenCallback cb,
30027
2ab6e591cf72 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <darkrain42@pidgin.im>
parents: 29716
diff changeset
534 gpointer cb_data)
8246
c83c0421149a [gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents: 8245
diff changeset
535 {
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
536 g_return_val_if_fail(port != 0, NULL);
8250
e855dcce1fa0 [gaim-migrate @ 8973]
Mark Doliner <markdoliner@pidgin.im>
parents: 8248
diff changeset
537
32594
f2feea134fdb Remove deprecated purple_network_listen_map_external().
Andrew Victor <andrew.victor@mxit.com>
parents: 32593
diff changeset
538 return purple_network_do_listen(port, socket_family, socket_type, map_external,
30027
2ab6e591cf72 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <darkrain42@pidgin.im>
parents: 29716
diff changeset
539 cb, cb_data);
8246
c83c0421149a [gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents: 8245
diff changeset
540 }
c83c0421149a [gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents: 8245
diff changeset
541
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
542 PurpleNetworkListenData *
32593
8fe5585c5397 Rename purple_network_listen_range_family() to purple_network_listen_range().
Andrew Victor <andrew.victor@mxit.com>
parents: 32592
diff changeset
543 purple_network_listen_range(unsigned short start, unsigned short end,
32594
f2feea134fdb Remove deprecated purple_network_listen_map_external().
Andrew Victor <andrew.victor@mxit.com>
parents: 32593
diff changeset
544 int socket_family, int socket_type, gboolean map_external,
30027
2ab6e591cf72 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <darkrain42@pidgin.im>
parents: 29716
diff changeset
545 PurpleNetworkListenCallback cb,
2ab6e591cf72 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <darkrain42@pidgin.im>
parents: 29716
diff changeset
546 gpointer cb_data)
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
547 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
548 PurpleNetworkListenData *ret = NULL;
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
549
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
550 if (purple_prefs_get_bool("/purple/network/ports_range_use")) {
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
551 start = purple_prefs_get_int("/purple/network/ports_range_start");
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
552 end = purple_prefs_get_int("/purple/network/ports_range_end");
8250
e855dcce1fa0 [gaim-migrate @ 8973]
Mark Doliner <markdoliner@pidgin.im>
parents: 8248
diff changeset
553 } else {
e855dcce1fa0 [gaim-migrate @ 8973]
Mark Doliner <markdoliner@pidgin.im>
parents: 8248
diff changeset
554 if (end < start)
e855dcce1fa0 [gaim-migrate @ 8973]
Mark Doliner <markdoliner@pidgin.im>
parents: 8248
diff changeset
555 end = start;
8239
d19f1c66720c [gaim-migrate @ 8962]
Mark Doliner <markdoliner@pidgin.im>
parents: 8231
diff changeset
556 }
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
557
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
558 for (; start <= end; start++) {
32594
f2feea134fdb Remove deprecated purple_network_listen_map_external().
Andrew Victor <andrew.victor@mxit.com>
parents: 32593
diff changeset
559 ret = purple_network_do_listen(start, AF_UNSPEC, socket_type, map_external, cb, cb_data);
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
560 if (ret != NULL)
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
561 break;
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
562 }
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
563
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
564 return ret;
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
565 }
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
566
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
567 void purple_network_listen_cancel(PurpleNetworkListenData *listen_data)
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
568 {
15502
250802f80d94 Fix a crash when a network_listen_range process is canceled before its UPnP port mapping completes, which occurs regularly on certain routers when file transfers are initiated and then quickly finished. Much thanks to Elliott Harris and Eric Richie for their hard work with me hunting this down and fixing it.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
569 if (listen_data->mapping_data != NULL)
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
570 purple_upnp_cancel_port_mapping(listen_data->mapping_data);
15502
250802f80d94 Fix a crash when a network_listen_range process is canceled before its UPnP port mapping completes, which occurs regularly on certain routers when file transfers are initiated and then quickly finished. Much thanks to Elliott Harris and Eric Richie for their hard work with me hunting this down and fixing it.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
571
30614
ba7a36c1696b Make sure we keep track of this timer and remove it if our caller frees
Mark Doliner <markdoliner@pidgin.im>
parents: 30027
diff changeset
572 if (listen_data->timer > 0)
ba7a36c1696b Make sure we keep track of this timer and remove it if our caller frees
Mark Doliner <markdoliner@pidgin.im>
parents: 30027
diff changeset
573 purple_timeout_remove(listen_data->timer);
ba7a36c1696b Make sure we keep track of this timer and remove it if our caller frees
Mark Doliner <markdoliner@pidgin.im>
parents: 30027
diff changeset
574
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
575 g_free(listen_data);
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
576 }
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
577
8834
0a798e3d2b84 [gaim-migrate @ 9598]
Mark Doliner <markdoliner@pidgin.im>
parents: 8251
diff changeset
578 unsigned short
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
579 purple_network_get_port_from_fd(int fd)
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
580 {
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
581 struct sockaddr_in addr;
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
582 socklen_t len;
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
583
9449
8c5a1697bca6 [gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents: 8981
diff changeset
584 g_return_val_if_fail(fd >= 0, 0);
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
585
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
586 len = sizeof(addr);
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
587 if (getsockname(fd, (struct sockaddr *) &addr, &len) == -1) {
21389
e1dd8142bb87 replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20239
diff changeset
588 purple_debug_warning("network", "getsockname: %s\n", g_strerror(errno));
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
589 return 0;
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
590 }
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
591
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
592 return ntohs(addr.sin_port);
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
593 }
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
594
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
595 #ifdef _WIN32
14853
d06b1f28a8b2 [gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents: 14842
diff changeset
596 #ifndef NS_NLA
d06b1f28a8b2 [gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents: 14842
diff changeset
597 #define NS_NLA 15
d06b1f28a8b2 [gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents: 14842
diff changeset
598 #endif
14842
fe08ba80d369 [gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents: 14839
diff changeset
599 static gint
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
600 wpurple_get_connected_network_count(void)
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
601 {
19585
14b519abcc26 Fix some conversion warnings about using negative values with unsigned types. There are more, but these were easy fixes. You may think that I'm changing the API, but I'm really not - it was just wrong.
Daniel Atallah <datallah@pidgin.im>
parents: 18555
diff changeset
602 gint net_cnt = 0;
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
603
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
604 WSAQUERYSET qs;
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
605 HANDLE h;
14957
1519e663dd9b [gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents: 14877
diff changeset
606 gint retval;
1519e663dd9b [gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents: 14877
diff changeset
607 int errorid;
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
608
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
609 memset(&qs, 0, sizeof(WSAQUERYSET));
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
610 qs.dwSize = sizeof(WSAQUERYSET);
14853
d06b1f28a8b2 [gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents: 14842
diff changeset
611 qs.dwNameSpace = NS_NLA;
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
612
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
613 retval = WSALookupServiceBegin(&qs, LUP_RETURN_ALL, &h);
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
614 if (retval != ERROR_SUCCESS) {
14957
1519e663dd9b [gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents: 14877
diff changeset
615 gchar *msg;
1519e663dd9b [gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents: 14877
diff changeset
616 errorid = WSAGetLastError();
1519e663dd9b [gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents: 14877
diff changeset
617 msg = g_win32_error_message(errorid);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
618 purple_debug_warning("network", "Couldn't retrieve NLA SP lookup handle. "
14853
d06b1f28a8b2 [gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents: 14842
diff changeset
619 "NLA service is probably not running. Message: %s (%d).\n",
d06b1f28a8b2 [gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents: 14842
diff changeset
620 msg, errorid);
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
621 g_free(msg);
14838
40cc5f858426 [gaim-migrate @ 17540]
Daniel Atallah <datallah@pidgin.im>
parents: 14784
diff changeset
622
14842
fe08ba80d369 [gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents: 14839
diff changeset
623 return -1;
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
624 } else {
14959
eb5cf3522fda [gaim-migrate @ 17669]
Daniel Atallah <datallah@pidgin.im>
parents: 14957
diff changeset
625 char buf[4096];
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
626 WSAQUERYSET *res = (LPWSAQUERYSET) buf;
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
627 DWORD size = sizeof(buf);
14957
1519e663dd9b [gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents: 14877
diff changeset
628 while ((retval = WSALookupServiceNext(h, 0, &size, res)) == ERROR_SUCCESS) {
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
629 net_cnt++;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
630 purple_debug_info("network", "found network '%s'\n",
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
631 res->lpszServiceInstanceName ? res->lpszServiceInstanceName : "(NULL)");
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
632 size = sizeof(buf);
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
633 }
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
634
14957
1519e663dd9b [gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents: 14877
diff changeset
635 errorid = WSAGetLastError();
1519e663dd9b [gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents: 14877
diff changeset
636 if (!(errorid == WSA_E_NO_MORE || errorid == WSAENOMORE)) {
1519e663dd9b [gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents: 14877
diff changeset
637 gchar *msg = g_win32_error_message(errorid);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
638 purple_debug_error("network", "got unexpected NLA response %s (%d)\n", msg, errorid);
14957
1519e663dd9b [gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents: 14877
diff changeset
639 g_free(msg);
1519e663dd9b [gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents: 14877
diff changeset
640
1519e663dd9b [gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents: 14877
diff changeset
641 net_cnt = -1;
1519e663dd9b [gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents: 14877
diff changeset
642 }
1519e663dd9b [gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents: 14877
diff changeset
643
1519e663dd9b [gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents: 14877
diff changeset
644 retval = WSALookupServiceEnd(h);
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
645 }
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
646
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
647 return net_cnt;
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
648
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
649 }
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
650
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
651 static gboolean wpurple_network_change_thread_cb(gpointer data)
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
652 {
14842
fe08ba80d369 [gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents: 14839
diff changeset
653 gint new_count;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
654 PurpleConnectionUiOps *ui_ops = purple_connections_get_ui_ops();
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
655
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
656 new_count = wpurple_get_connected_network_count();
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
657
14842
fe08ba80d369 [gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents: 14839
diff changeset
658 if (new_count < 0)
fe08ba80d369 [gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents: 14839
diff changeset
659 return FALSE;
fe08ba80d369 [gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents: 14839
diff changeset
660
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
661 purple_debug_info("network", "Received Network Change Notification. Current network count is %d, previous count was %d.\n", new_count, current_network_count);
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
662
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
663 purple_signal_emit(purple_network_get_handle(), "network-configuration-changed", NULL);
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
664
14877
084d14fe0445 [gaim-migrate @ 17581]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 14864
diff changeset
665 if (new_count > 0 && ui_ops != NULL && ui_ops->network_connected != NULL) {
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
666 ui_ops->network_connected();
14877
084d14fe0445 [gaim-migrate @ 17581]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 14864
diff changeset
667 } else if (new_count == 0 && current_network_count > 0 &&
084d14fe0445 [gaim-migrate @ 17581]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 14864
diff changeset
668 ui_ops != NULL && ui_ops->network_disconnected != NULL) {
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
669 ui_ops->network_disconnected();
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
670 }
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
671
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
672 current_network_count = new_count;
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
673
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
674 return FALSE;
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
675 }
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
676
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
677 static gboolean _print_debug_msg(gpointer data) {
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
678 gchar *msg = data;
30792
155b65d26118 Fix some cases where an arbitrary string was being specified as a printf format.
Daniel Atallah <datallah@pidgin.im>
parents: 30753
diff changeset
679 purple_debug_warning("network", "%s", msg);
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
680 g_free(msg);
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
681 return FALSE;
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
682 }
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
683
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
684 static gpointer wpurple_network_change_thread(gpointer data)
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
685 {
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
686 WSAQUERYSET qs;
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
687 WSAEVENT *nla_event;
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
688 time_t last_trigger = time(NULL) - 31;
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
689 char buf[4096];
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
690 WSAQUERYSET *res = (LPWSAQUERYSET) buf;
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
691 DWORD size;
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
692
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
693 if ((nla_event = WSACreateEvent()) == WSA_INVALID_EVENT) {
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
694 int errorid = WSAGetLastError();
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
695 gchar *msg = g_win32_error_message(errorid);
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
696 purple_timeout_add(0, _print_debug_msg,
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
697 g_strdup_printf("Couldn't create WSA event. "
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
698 "Message: %s (%d).\n", msg, errorid));
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
699 g_free(msg);
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
700 g_thread_exit(NULL);
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
701 return NULL;
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
702 }
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
703
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
704 while (TRUE) {
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
705 int retval;
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
706 DWORD retLen = 0;
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
707 WSACOMPLETION completion;
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
708 WSAOVERLAPPED overlapped;
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
709
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
710 #if GLIB_CHECK_VERSION(2, 32, 0)
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
711 g_mutex_lock(&mutex);
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
712 #else
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
713 g_static_mutex_lock(&mutex);
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
714 #endif
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
715 if (network_initialized == FALSE) {
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
716 /* purple_network_uninit has been called */
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
717 WSACloseEvent(nla_event);
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
718 #if GLIB_CHECK_VERSION(2, 32, 0)
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
719 g_mutex_unlock(&mutex);
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
720 #else
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
721 g_static_mutex_unlock(&mutex);
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
722 #endif
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
723 g_thread_exit(NULL);
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
724 return NULL;
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
725 }
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
726
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
727 if (network_change_handle == NULL) {
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
728 memset(&qs, 0, sizeof(WSAQUERYSET));
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
729 qs.dwSize = sizeof(WSAQUERYSET);
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
730 qs.dwNameSpace = NS_NLA;
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
731 if (WSALookupServiceBegin(&qs, 0, &network_change_handle) == SOCKET_ERROR) {
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
732 int errorid = WSAGetLastError();
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
733 gchar *msg = g_win32_error_message(errorid);
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
734 purple_timeout_add(0, _print_debug_msg,
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
735 g_strdup_printf("Couldn't retrieve NLA SP lookup handle. "
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
736 "NLA service is probably not running. Message: %s (%d).\n",
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
737 msg, errorid));
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
738 g_free(msg);
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
739 WSACloseEvent(nla_event);
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
740 #if GLIB_CHECK_VERSION(2, 32, 0)
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
741 g_mutex_unlock(&mutex);
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
742 #else
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
743 g_static_mutex_unlock(&mutex);
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
744 #endif
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
745 g_thread_exit(NULL);
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
746 return NULL;
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
747 }
14853
d06b1f28a8b2 [gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents: 14842
diff changeset
748 }
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
749 #if GLIB_CHECK_VERSION(2, 32, 0)
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
750 g_mutex_unlock(&mutex);
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
751 #else
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
752 g_static_mutex_unlock(&mutex);
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
753 #endif
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
754
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
755 memset(&completion, 0, sizeof(WSACOMPLETION));
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
756 completion.Type = NSP_NOTIFY_EVENT;
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
757 overlapped.hEvent = nla_event;
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
758 completion.Parameters.Event.lpOverlapped = &overlapped;
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
759
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
760 if (MyWSANSPIoctl(network_change_handle, SIO_NSP_NOTIFY_CHANGE, NULL, 0, NULL, 0, &retLen, &completion) == SOCKET_ERROR) {
14853
d06b1f28a8b2 [gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents: 14842
diff changeset
761 int errorid = WSAGetLastError();
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
762 if (errorid == WSA_INVALID_HANDLE) {
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
763 purple_timeout_add(0, _print_debug_msg,
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
764 g_strdup("Invalid NLA handle; resetting.\n"));
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
765 #if GLIB_CHECK_VERSION(2, 32, 0)
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
766 g_mutex_lock(&mutex);
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
767 #else
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
768 g_static_mutex_lock(&mutex);
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
769 #endif
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
770 retval = WSALookupServiceEnd(network_change_handle);
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
771 network_change_handle = NULL;
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
772 #if GLIB_CHECK_VERSION(2, 32, 0)
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
773 g_mutex_unlock(&mutex);
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
774 #else
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
775 g_static_mutex_unlock(&mutex);
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
776 #endif
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
777 continue;
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
778 /* WSA_IO_PENDING indicates successful async notification will happen */
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
779 } else if (errorid != WSA_IO_PENDING) {
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
780 gchar *msg = g_win32_error_message(errorid);
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
781 purple_timeout_add(0, _print_debug_msg,
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
782 g_strdup_printf("Unable to wait for changes. Message: %s (%d).\n",
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
783 msg, errorid));
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
784 g_free(msg);
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
785 }
14853
d06b1f28a8b2 [gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents: 14842
diff changeset
786 }
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
787
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
788 /* Make sure at least 30 seconds have elapsed since the last
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
789 * notification so we don't peg the cpu if this keeps changing. */
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
790 if ((time(NULL) - last_trigger) < 30)
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
791 Sleep(30000);
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
792
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
793 /* This will block until NLA notifies us */
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
794 retval = WaitForSingleObjectEx(nla_event, WSA_INFINITE, TRUE);
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
795
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
796 last_trigger = time(NULL);
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
797
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
798 #if GLIB_CHECK_VERSION(2, 32, 0)
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
799 g_mutex_lock(&mutex);
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
800 #else
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
801 g_static_mutex_lock(&mutex);
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
802 #endif
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
803 if (network_initialized == FALSE) {
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
804 /* Time to die */
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
805 WSACloseEvent(nla_event);
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
806 #if GLIB_CHECK_VERSION(2, 32, 0)
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
807 g_mutex_unlock(&mutex);
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
808 #else
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
809 g_static_mutex_unlock(&mutex);
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
810 #endif
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
811 g_thread_exit(NULL);
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
812 return NULL;
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
813 }
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
814
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
815 size = sizeof(buf);
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
816 while ((retval = WSALookupServiceNext(network_change_handle, 0, &size, res)) == ERROR_SUCCESS) {
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
817 /*purple_timeout_add(0, _print_debug_msg,
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
818 g_strdup_printf("thread found network '%s'\n",
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
819 res->lpszServiceInstanceName ? res->lpszServiceInstanceName : "(NULL)"));*/
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
820 size = sizeof(buf);
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
821 }
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
822
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
823 WSAResetEvent(nla_event);
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
824 #if GLIB_CHECK_VERSION(2, 32, 0)
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
825 g_mutex_unlock(&mutex);
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
826 #else
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
827 g_static_mutex_unlock(&mutex);
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
828 #endif
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
829
21549
7436059db33b Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents: 21389
diff changeset
830 purple_timeout_add(0, wpurple_network_change_thread_cb, NULL);
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
831 }
14853
d06b1f28a8b2 [gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents: 14842
diff changeset
832
d06b1f28a8b2 [gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents: 14842
diff changeset
833 g_thread_exit(NULL);
d06b1f28a8b2 [gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents: 14842
diff changeset
834 return NULL;
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
835 }
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
836 #endif
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
837
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
838 gboolean
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
839 purple_network_is_available(void)
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
840 {
23060
db9632a9b374 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@pidgin.im>
parents: 23054
diff changeset
841 #ifdef HAVE_NETWORKMANAGER
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
842 if (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
843 return TRUE;
84d597b7e7c6 Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@pidgin.im>
parents: 24519
diff changeset
844
24519
d4af3d043211 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@pidgin.im>
parents: 24044
diff changeset
845 if (!have_nm_state)
23047
f2c25bf1e0fd Fix some whitespace as noticed by QuLogic.
Richard Laager <rlaager@pidgin.im>
parents: 23041
diff changeset
846 {
24519
d4af3d043211 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@pidgin.im>
parents: 24044
diff changeset
847 have_nm_state = TRUE;
d4af3d043211 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@pidgin.im>
parents: 24044
diff changeset
848 nm_state = nm_get_network_state();
d4af3d043211 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@pidgin.im>
parents: 24044
diff changeset
849 if (nm_state == NM_STATE_UNKNOWN)
d4af3d043211 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@pidgin.im>
parents: 24044
diff changeset
850 purple_debug_warning("network", "NetworkManager not active. Assuming connection exists.\n");
23041
58661da65e36 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@pidgin.im>
parents: 23040
diff changeset
851 }
24519
d4af3d043211 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@pidgin.im>
parents: 24044
diff changeset
852
32077
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
853 switch (nm_state)
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
854 {
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
855 case NM_STATE_UNKNOWN:
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
856 #if NM_CHECK_VERSION(0,8,992)
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
857 case NM_STATE_CONNECTED_LOCAL:
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
858 case NM_STATE_CONNECTED_SITE:
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
859 case NM_STATE_CONNECTED_GLOBAL:
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
860 #else
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
861 case NM_STATE_CONNECTED:
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
862 #endif
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
863 return TRUE;
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
864 default:
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
865 break;
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
866 }
23041
58661da65e36 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@pidgin.im>
parents: 23040
diff changeset
867
58661da65e36 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@pidgin.im>
parents: 23040
diff changeset
868 return FALSE;
58661da65e36 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@pidgin.im>
parents: 23040
diff changeset
869
14839
221c60cc76e0 [gaim-migrate @ 17541]
Daniel Atallah <datallah@pidgin.im>
parents: 14838
diff changeset
870 #elif defined _WIN32
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
871 return (current_network_count > 0 || force_online);
23041
58661da65e36 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@pidgin.im>
parents: 23040
diff changeset
872 #else
58661da65e36 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@pidgin.im>
parents: 23040
diff changeset
873 return TRUE;
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
874 #endif
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
875 }
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
876
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
877 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
878 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
879 {
84d597b7e7c6 Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@pidgin.im>
parents: 24519
diff changeset
880 #if defined(HAVE_NETWORKMANAGER) || defined(_WIN32)
84d597b7e7c6 Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@pidgin.im>
parents: 24519
diff changeset
881 force_online = TRUE;
84d597b7e7c6 Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@pidgin.im>
parents: 24519
diff changeset
882 #endif
84d597b7e7c6 Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@pidgin.im>
parents: 24519
diff changeset
883 }
84d597b7e7c6 Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@pidgin.im>
parents: 24519
diff changeset
884
23060
db9632a9b374 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@pidgin.im>
parents: 23054
diff changeset
885 #ifdef HAVE_NETWORKMANAGER
22735
a9c84e4679d8 Make some more things static
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 21977
diff changeset
886 static void
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
887 nm_update_state(NMState state)
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
888 {
24519
d4af3d043211 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@pidgin.im>
parents: 24044
diff changeset
889 NMState prev = nm_state;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
890 PurpleConnectionUiOps *ui_ops = purple_connections_get_ui_ops();
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
891
24519
d4af3d043211 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@pidgin.im>
parents: 24044
diff changeset
892 have_nm_state = TRUE;
d4af3d043211 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@pidgin.im>
parents: 24044
diff changeset
893 nm_state = state;
d4af3d043211 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@pidgin.im>
parents: 24044
diff changeset
894
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
895 purple_signal_emit(purple_network_get_handle(), "network-configuration-changed", NULL);
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
896
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
897 switch(state)
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
898 {
31653
a36102ecb723 Support new connection states in NetworkMakanter 0.9. Fixes #13505.
Dan Williams <dcbw@redhat.com>
parents: 31294
diff changeset
899 #if NM_CHECK_VERSION(0,8,992)
a36102ecb723 Support new connection states in NetworkMakanter 0.9. Fixes #13505.
Dan Williams <dcbw@redhat.com>
parents: 31294
diff changeset
900 case NM_STATE_CONNECTED_LOCAL:
a36102ecb723 Support new connection states in NetworkMakanter 0.9. Fixes #13505.
Dan Williams <dcbw@redhat.com>
parents: 31294
diff changeset
901 case NM_STATE_CONNECTED_SITE:
a36102ecb723 Support new connection states in NetworkMakanter 0.9. Fixes #13505.
Dan Williams <dcbw@redhat.com>
parents: 31294
diff changeset
902 case NM_STATE_CONNECTED_GLOBAL:
a36102ecb723 Support new connection states in NetworkMakanter 0.9. Fixes #13505.
Dan Williams <dcbw@redhat.com>
parents: 31294
diff changeset
903 #else
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
904 case NM_STATE_CONNECTED:
31653
a36102ecb723 Support new connection states in NetworkMakanter 0.9. Fixes #13505.
Dan Williams <dcbw@redhat.com>
parents: 31294
diff changeset
905 #endif
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
906 /* Call res_init in case DNS servers have changed */
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
907 res_init();
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
908 /* update STUN IP in case we it changed (theoretically we could
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
909 have gone from IPv4 to IPv6, f.ex. or we were previously
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
910 offline */
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
911 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
912 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
913 purple_network_set_turn_server(
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
914 purple_prefs_get_string("/purple/network/turn_server"));
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 31191
diff changeset
915
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
916 if (ui_ops != NULL && ui_ops->network_connected != NULL)
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
917 ui_ops->network_connected();
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
918 break;
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
919 case NM_STATE_ASLEEP:
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
920 case NM_STATE_CONNECTING:
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
921 case NM_STATE_DISCONNECTED:
31653
a36102ecb723 Support new connection states in NetworkMakanter 0.9. Fixes #13505.
Dan Williams <dcbw@redhat.com>
parents: 31294
diff changeset
922 #if NM_CHECK_VERSION(0,8,992)
a36102ecb723 Support new connection states in NetworkMakanter 0.9. Fixes #13505.
Dan Williams <dcbw@redhat.com>
parents: 31294
diff changeset
923 case NM_STATE_DISCONNECTING:
a36102ecb723 Support new connection states in NetworkMakanter 0.9. Fixes #13505.
Dan Williams <dcbw@redhat.com>
parents: 31294
diff changeset
924 #endif
24519
d4af3d043211 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@pidgin.im>
parents: 24044
diff changeset
925 if (prev != NM_STATE_CONNECTED && prev != NM_STATE_UNKNOWN)
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
926 break;
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
927 if (ui_ops != NULL && ui_ops->network_disconnected != NULL)
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
928 ui_ops->network_disconnected();
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
929 break;
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
930 case NM_STATE_UNKNOWN:
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
931 default:
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
932 break;
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
933 }
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
934 }
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
935
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
936 static void
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
937 nm_state_change_cb(DBusGProxy *proxy, NMState state, gpointer user_data)
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
938 {
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
939 purple_debug_info("network", "Got StateChange from NetworkManager: %d.\n", state);
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
940 nm_update_state(state);
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
941 }
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
942
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
943 static NMState
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
944 nm_get_network_state(void)
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
945 {
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
946 GError *err = NULL;
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
947 NMState state = NM_STATE_UNKNOWN;
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
948
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
949 if (!nm_proxy)
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
950 return NM_STATE_UNKNOWN;
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
951
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
952 if (!dbus_g_proxy_call(nm_proxy, "state", &err, G_TYPE_INVALID, G_TYPE_UINT, &state, G_TYPE_INVALID)) {
23185
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 23060
diff changeset
953 g_error_free(err);
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
954 return NM_STATE_UNKNOWN;
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
955 }
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
956
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
957 return state;
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
958 }
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
959
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
960 static void
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
961 nm_dbus_name_owner_changed_cb(DBusGProxy *proxy, char *service, char *old_owner, char *new_owner, gpointer user_data)
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
962 {
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
963 if (g_str_equal(service, NM_DBUS_SERVICE)) {
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
964 gboolean old_owner_good = old_owner && (old_owner[0] != '\0');
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
965 gboolean new_owner_good = new_owner && (new_owner[0] != '\0');
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
966
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
967 purple_debug_info("network", "Got NameOwnerChanged signal, service = '%s', old_owner = '%s', new_owner = '%s'\n", service, old_owner, new_owner);
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
968 if (!old_owner_good && new_owner_good) { /* Equivalent to old ServiceCreated signal */
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
969 purple_debug_info("network", "NetworkManager has started.\n");
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
970 nm_update_state(nm_get_network_state());
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
971 } else if (old_owner_good && !new_owner_good) { /* Equivalent to old ServiceDeleted signal */
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
972 purple_debug_info("network", "NetworkManager has gone away.\n");
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
973 nm_update_state(NM_STATE_UNKNOWN);
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
974 }
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
975 }
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
976 }
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
977
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
978 #endif
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
979
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
980 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
981 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
982 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
983 GList *addresses = NULL;
37450
703722d83214 Update network.c for the dns code removal
Gary Kramlich <grim@reaperworld.com>
parents: 36031
diff changeset
984 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
985 const gchar **ip_address = (const gchar **)data;
26262
1ad96aa2e92a Removed some extra tabs on blank lines
Marcus Lundblad <malu@pidgin.im>
parents: 26261
diff changeset
986
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
987 addresses = g_resolver_lookup_by_name_finish(g_resolver_get_default(), result, &error);
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
988 if(error) {
37450
703722d83214 Update network.c for the dns code removal
Gary Kramlich <grim@reaperworld.com>
parents: 36031
diff changeset
989 purple_debug_info("network", "lookup of IP address failed: %s\n", error->message);
703722d83214 Update network.c for the dns code removal
Gary Kramlich <grim@reaperworld.com>
parents: 36031
diff changeset
990
703722d83214 Update network.c for the dns code removal
Gary Kramlich <grim@reaperworld.com>
parents: 36031
diff changeset
991 g_error_free(error);
703722d83214 Update network.c for the dns code removal
Gary Kramlich <grim@reaperworld.com>
parents: 36031
diff changeset
992
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
993 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
994 }
26262
1ad96aa2e92a Removed some extra tabs on blank lines
Marcus Lundblad <malu@pidgin.im>
parents: 26261
diff changeset
995
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
996 address = G_INET_ADDRESS(addresses->data);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 31191
diff changeset
997
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
998 *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
999
37450
703722d83214 Update network.c for the dns code removal
Gary Kramlich <grim@reaperworld.com>
parents: 36031
diff changeset
1000 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
1001 }
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
1002
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
1003 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
1004 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
1005 {
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
1006 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
1007 if (purple_network_is_available()) {
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
1008 g_resolver_lookup_by_name_async(g_resolver_get_default(),
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
1009 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
1010 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
1011 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
1012 &stun_ip);
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
1013 } else {
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 31191
diff changeset
1014 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
1015 "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
1016 }
37426
6fd4989b77e4 The last of the NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents: 36031
diff changeset
1017 } 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
1018 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
1019 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
1020 }
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
1021 }
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
1022
26261
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1023 void
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1024 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
1025 {
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1026 if (turn_server && turn_server[0] != '\0') {
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1027 if (purple_network_is_available()) {
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
1028 g_resolver_lookup_by_name_async(g_resolver_get_default(),
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
1029 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
1030 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
1031 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
1032 &turn_server);
26261
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1033 } else {
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 31191
diff changeset
1034 purple_debug_info("network",
26261
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1035 "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
1036 }
37426
6fd4989b77e4 The last of the NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents: 36031
diff changeset
1037 } else {
26261
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1038 g_free(turn_ip);
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1039 turn_ip = NULL;
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1040 }
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1041 }
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1042
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1043
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
1044 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
1045 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
1046 {
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
1047 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
1048 }
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
1049
26261
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1050 const gchar *
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1051 purple_network_get_turn_ip(void)
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1052 {
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1053 return turn_ip;
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1054 }
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1055
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
1056 void *
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
1057 purple_network_get_handle(void)
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
1058 {
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
1059 static int handle;
19585
14b519abcc26 Fix some conversion warnings about using negative values with unsigned types. There are more, but these were easy fixes. You may think that I'm changing the API, but I'm really not - it was just wrong.
Daniel Atallah <datallah@pidgin.im>
parents: 18555
diff changeset
1060
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
1061 return &handle;
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
1062 }
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
1063
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
1064 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
1065 purple_network_upnp_mapping_remove_cb(gboolean sucess, gpointer 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
1066 {
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
1067 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
1068 }
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
1069
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
1070 /* 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
1071 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
1072 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
1073 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
1074 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
1075 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
1076 {
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
1077 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
1078 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
1079 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
1080 port);
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
1081 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
1082 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
1083 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
1084 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
1085 }
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
1086
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
1087 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
1088 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
1089 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
1090 {
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
1091 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
1092 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
1093 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
1094 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
1095 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
1096 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
1097 port);
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
1098 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
1099 }
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
1100
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
1101 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
1102 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
1103 {
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
1104 int port = purple_network_get_port_from_fd(fd);
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
1105 gint 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
1106
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
1107 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
1108 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
1109 } else {
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
1110 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
1111 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
1112 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
1113 }
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
1114 }
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
1115 }
27898
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1116
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1117 int purple_network_convert_idn_to_ascii(const gchar *in, gchar **out)
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1118 {
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1119 #ifdef USE_IDN
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1120 char *tmp;
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1121 int ret;
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1122
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1123 g_return_val_if_fail(out != NULL, -1);
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1124
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1125 ret = idna_to_ascii_8z(in, &tmp, IDNA_USE_STD3_ASCII_RULES);
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1126 if (ret != IDNA_SUCCESS) {
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1127 *out = NULL;
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1128 return ret;
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1129 }
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1130
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1131 *out = g_strdup(tmp);
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1132 /* This *MUST* be freed with free, not g_free */
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1133 free(tmp);
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1134 return 0;
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1135 #else
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1136 g_return_val_if_fail(out != NULL, -1);
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1137
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1138 *out = g_strdup(in);
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1139 return 0;
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1140 #endif
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1141 }
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27497
diff changeset
1142
36028
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1143 gboolean
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1144 _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
1145 {
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1146 int flags;
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1147 gboolean succ = TRUE;
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1148
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1149 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
1150
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1151 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
1152
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1153 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
1154 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
1155 "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
1156 succ = FALSE;
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1157 }
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1158
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1159 #ifndef _WIN32
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1160 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
1161 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
1162 "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
1163 succ = FALSE;
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1164 }
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1165 #endif
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1166
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1167 return succ;
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1168 }
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1169
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
1170 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
1171 purple_network_init(void)
8231
347c8992c445 [gaim-migrate @ 8954]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
1172 {
23060
db9632a9b374 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@pidgin.im>
parents: 23054
diff changeset
1173 #ifdef HAVE_NETWORKMANAGER
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1174 GError *error = NULL;
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1175 #endif
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
1176 #ifdef _WIN32
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
1177 GError *err = NULL;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
1178 gint cnt = wpurple_get_connected_network_count();
14842
fe08ba80d369 [gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents: 14839
diff changeset
1179
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1180 network_initialized = TRUE;
14842
fe08ba80d369 [gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents: 14839
diff changeset
1181 if (cnt < 0) /* Assume there is a network */
fe08ba80d369 [gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents: 14839
diff changeset
1182 current_network_count = 1;
fe08ba80d369 [gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents: 14839
diff changeset
1183 /* Don't listen for network changes if we can't tell anyway */
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
1184 else {
14842
fe08ba80d369 [gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents: 14839
diff changeset
1185 current_network_count = cnt;
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
1186 if ((MyWSANSPIoctl = (void*) wpurple_find_and_loadproc("ws2_32.dll", "WSANSPIoctl"))) {
33883
8a0d96bd9cf4 Replace deprecated g_thread_create with g_thread_try_new
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 32859
diff changeset
1187 GThread *thread = g_thread_try_new("Network Monitor thread", wpurple_network_change_thread, NULL, &err);
8a0d96bd9cf4 Replace deprecated g_thread_create with g_thread_try_new
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 32859
diff changeset
1188 if (thread)
8a0d96bd9cf4 Replace deprecated g_thread_create with g_thread_try_new
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 32859
diff changeset
1189 g_thread_unref(thread);
8a0d96bd9cf4 Replace deprecated g_thread_create with g_thread_try_new
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 32859
diff changeset
1190 else
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
1191 purple_debug_error("network", "Couldn't create Network Monitor thread: %s\n", err ? err->message : "");
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
1192 }
14842
fe08ba80d369 [gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents: 14839
diff changeset
1193 }
14784
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
1194 #endif
3a82321f46f2 [gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents: 14758
diff changeset
1195
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
1196 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
1197 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
1198 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
1199 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
1200 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
1201 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
1202 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
1203 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
1204 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
1205 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
1206 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
1207 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
1208 purple_prefs_add_int ("/purple/network/ports_range_end", 2048);
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
1209
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
1210 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
1211 purple_upnp_discover(NULL, NULL);
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
1212
23060
db9632a9b374 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@pidgin.im>
parents: 23054
diff changeset
1213 #ifdef HAVE_NETWORKMANAGER
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1214 nm_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1215 if (!nm_conn) {
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1216 purple_debug_warning("network", "Error connecting to DBus System service: %s.\n", error->message);
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1217 } else {
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1218 nm_proxy = dbus_g_proxy_new_for_name(nm_conn,
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1219 NM_DBUS_SERVICE,
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1220 NM_DBUS_PATH,
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1221 NM_DBUS_INTERFACE);
32077
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
1222 /* NM 0.6 signal */
23054
2dc4cdd54b28 Modify the NetworkManager support to use "StateChange" directly, instead of
Richard Laager <rlaager@pidgin.im>
parents: 23047
diff changeset
1223 dbus_g_proxy_add_signal(nm_proxy, "StateChange", G_TYPE_UINT, G_TYPE_INVALID);
2dc4cdd54b28 Modify the NetworkManager support to use "StateChange" directly, instead of
Richard Laager <rlaager@pidgin.im>
parents: 23047
diff changeset
1224 dbus_g_proxy_connect_signal(nm_proxy, "StateChange",
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1225 G_CALLBACK(nm_state_change_cb), NULL, NULL);
32077
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
1226 /* NM 0.7 and later signal */
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
1227 dbus_g_proxy_add_signal(nm_proxy, "StateChanged", G_TYPE_UINT, G_TYPE_INVALID);
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
1228 dbus_g_proxy_connect_signal(nm_proxy, "StateChanged",
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
1229 G_CALLBACK(nm_state_change_cb), NULL, NULL);
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1230
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1231 dbus_proxy = dbus_g_proxy_new_for_name(nm_conn,
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1232 DBUS_SERVICE_DBUS,
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1233 DBUS_PATH_DBUS,
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1234 DBUS_INTERFACE_DBUS);
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1235 dbus_g_proxy_add_signal(dbus_proxy, "NameOwnerChanged", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1236 dbus_g_proxy_connect_signal(dbus_proxy, "NameOwnerChanged",
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1237 G_CALLBACK(nm_dbus_name_owner_changed_cb), NULL, NULL);
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1238 }
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
1239 #endif
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
1240
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
1241 purple_signal_register(purple_network_get_handle(), "network-configuration-changed",
34820
7a89045601ae Refactored log, network, notify to use GType instead of PurpleValue
Ankit Vani <a@nevitus.org>
parents: 33900
diff changeset
1242 purple_marshal_VOID, G_TYPE_NONE, 0);
19585
14b519abcc26 Fix some conversion warnings about using negative values with unsigned types. There are more, but these were easy fixes. You may think that I'm changing the API, but I'm really not - it was just wrong.
Daniel Atallah <datallah@pidgin.im>
parents: 18555
diff changeset
1243
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
1244 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
1245 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
1246
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
1247 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
1248 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
1249 purple_network_set_turn_server(
ffabb135a4b6 Added support to generate relayed candidates (TURN).
Marcus Lundblad <malu@pidgin.im>
parents: 26256
diff changeset
1250 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
1251
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
1252 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
1253 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
1254 }
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
1255
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
1256
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
1257
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
1258 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
1259 purple_network_uninit(void)
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
1260 {
23060
db9632a9b374 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@pidgin.im>
parents: 23054
diff changeset
1261 #ifdef HAVE_NETWORKMANAGER
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1262 if (nm_proxy) {
23054
2dc4cdd54b28 Modify the NetworkManager support to use "StateChange" directly, instead of
Richard Laager <rlaager@pidgin.im>
parents: 23047
diff changeset
1263 dbus_g_proxy_disconnect_signal(nm_proxy, "StateChange", G_CALLBACK(nm_state_change_cb), NULL);
32077
09eab14835d9 *** Plucked rev 10ead4688e3af4132d454fa3bc241480500651c9 (dcbw@redhat.com):
Mark Doliner <markdoliner@pidgin.im>
parents: 31831
diff changeset
1264 dbus_g_proxy_disconnect_signal(nm_proxy, "StateChanged", G_CALLBACK(nm_state_change_cb), NULL);
23039
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1265 g_object_unref(G_OBJECT(nm_proxy));
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1266 }
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1267 if (dbus_proxy) {
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1268 dbus_g_proxy_disconnect_signal(dbus_proxy, "NameOwnerChanged", G_CALLBACK(nm_dbus_name_owner_changed_cb), NULL);
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1269 g_object_unref(G_OBJECT(dbus_proxy));
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1270 }
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1271 if (nm_conn)
c9b53691fe42 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@pidgin.im>
parents: 22735
diff changeset
1272 dbus_g_connection_unref(nm_conn);
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
1273 #endif
21143
239b2f43bef5 Make purple_xfers_uninit, purple_network_uninit, and purple_plugins_uninit
Etan Reisner <deryni@pidgin.im>
parents: 20239
diff changeset
1274
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1275 #ifdef _WIN32
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
1276 #if GLIB_CHECK_VERSION(2, 32, 0)
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
1277 g_mutex_lock(&mutex);
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
1278 #else
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1279 g_static_mutex_lock(&mutex);
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
1280 #endif
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1281 network_initialized = FALSE;
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1282 if (network_change_handle != NULL) {
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1283 int retval;
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1284 /* Trigger the NLA thread to stop waiting for network changes. Not
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1285 * doing this can cause hangs on WSACleanup. */
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1286 purple_debug_warning("network", "Terminating the NLA thread\n");
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1287 if ((retval = WSALookupServiceEnd(network_change_handle)) == SOCKET_ERROR) {
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1288 int errorid = WSAGetLastError();
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1289 gchar *msg = g_win32_error_message(errorid);
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1290 purple_debug_warning("network", "Unable to kill NLA thread. Message: %s (%d).\n",
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1291 msg, errorid);
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1292 g_free(msg);
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1293 }
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
1294 network_change_handle = NULL;
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
1295
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1296 }
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
1297 #if GLIB_CHECK_VERSION(2, 32, 0)
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
1298 g_mutex_unlock(&mutex);
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
1299 #else
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1300 g_static_mutex_unlock(&mutex);
33900
f4924591ef06 Don't use deprecated threads API for recent GLib versions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33894
diff changeset
1301 #endif
25326
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1302
c4f4b222dbac Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <darkrain42@pidgin.im>
parents: 24519
diff changeset
1303 #endif
21143
239b2f43bef5 Make purple_xfers_uninit, purple_network_uninit, and purple_plugins_uninit
Etan Reisner <deryni@pidgin.im>
parents: 20239
diff changeset
1304 purple_signal_unregister(purple_network_get_handle(),
25541
1b82a0195ff5 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <datallah@pidgin.im>
parents: 25326
diff changeset
1305 "network-configuration-changed");
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
1306
37426
6fd4989b77e4 The last of the NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents: 36031
diff changeset
1307 g_free(stun_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
1308
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
1309 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
1310 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
1311
31191
163f03d8d1d2 Cast back and forth between int and pointer instead of putting pointers
Mark Doliner <markdoliner@pidgin.im>
parents: 30792
diff changeset
1312 /* 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
1313 purple_upnp_remove_port_mapping from here doesn't quite work... */
14758
13b9adc9efd2 [gaim-migrate @ 17448]
Sean Egan <seanegan@pidgin.im>
parents: 14329
diff changeset
1314 }

mercurial