annotate libpurple/network.c @ 27473:1d30e9d6de9b

Added the function in util.h, forgot it here.
author Paul Aurich <paul@darkrain42.org>
date Sat, 11 Jul 2009 08:11:14 +0000
parents 627d23bfdb05
children 7fbf964c6c6c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 * @file network.c Network Implementation
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 * @ingroup core
20074
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 19681
diff changeset
4 */
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 19681
diff changeset
5
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 19681
diff changeset
6 /* purple
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
8 * Purple is the legal property of its developers, whose names are too numerous
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 * to list here. Please refer to the COPYRIGHT file distributed with this
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 * source distribution.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 * This program is free software; you can redistribute it and/or modify
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 * it under the terms of the GNU General Public License as published by
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 * the Free Software Foundation; either version 2 of the License, or
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 * (at your option) any later version.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 * This program is distributed in the hope that it will be useful,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 * GNU General Public License for more details.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 * You should have received a copy of the GNU General Public License
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 * along with this program; if not, write to the Free Software
19681
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19654
diff changeset
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 #include "internal.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 #ifndef _WIN32
23201
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 23043
diff changeset
30 #include <arpa/nameser.h>
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 #include <resolv.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 #include <netinet/in.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 #include <net/if.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 #include <sys/ioctl.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 #include <nspapi.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 /* Solaris */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 #if defined (__SVR4) && defined (__sun)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 #include <sys/sockio.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 #include "debug.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 #include "account.h"
15974
1a12ce76c4f4 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 <evan.s@dreskin.net>
parents: 15949
diff changeset
46 #include "nat-pmp.h"
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 #include "network.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 #include "prefs.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 #include "stun.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 #include "upnp.h"
26050
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
51 #include "dnsquery.h"
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 * Calling sizeof(struct ifreq) isn't always correct on
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 * Mac OS X (and maybe others).
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 #ifdef _SIZEOF_ADDR_IFREQ
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 # define HX_SIZE_OF_IFREQ(a) _SIZEOF_ADDR_IFREQ(a)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 # define HX_SIZE_OF_IFREQ(a) sizeof(a)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62
22895
0bd86dae2734 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@wiktel.com>
parents: 22889
diff changeset
63 #ifdef HAVE_NETWORKMANAGER
22874
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
64 #include <dbus/dbus-glib.h>
22895
0bd86dae2734 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@wiktel.com>
parents: 22889
diff changeset
65 #include <NetworkManager.h>
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66
22874
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
67 static DBusGConnection *nm_conn = NULL;
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
68 static DBusGProxy *nm_proxy = NULL;
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
69 static DBusGProxy *dbus_proxy = NULL;
24301
785db7300ef2 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@wiktel.com>
parents: 23712
diff changeset
70 static NMState nm_state = NM_STATE_UNKNOWN;
785db7300ef2 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@wiktel.com>
parents: 23712
diff changeset
71 static gboolean have_nm_state = FALSE;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73 #elif defined _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 static int current_network_count;
24888
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
75
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
76 /* Mutex for the other global vars */
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
77 static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
25401
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
78 static gboolean network_initialized = FALSE;
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
79 static HANDLE network_change_handle = NULL;
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
80 static int (WSAAPI *MyWSANSPIoctl) (
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
81 HANDLE hLookup, DWORD dwControlCode, LPVOID lpvInBuffer,
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
82 DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer,
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
83 LPDWORD lpcbBytesReturned, LPWSACOMPLETION lpCompletion) = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
84 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
86 struct _PurpleNetworkListenData {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87 int listenfd;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88 int socket_type;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
89 gboolean retry;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90 gboolean adding;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
91 PurpleNetworkListenCallback cb;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92 gpointer cb_data;
15440
56a2a0bb290a 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 <evan.s@dreskin.net>
parents: 15373
diff changeset
93 UPnPMappingAddRemove *mapping_data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
94 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
95
22895
0bd86dae2734 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@wiktel.com>
parents: 22889
diff changeset
96 #ifdef HAVE_NETWORKMANAGER
22874
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
97 static NMState nm_get_network_state(void);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99
25852
b38cbefca6ad Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@wiktel.com>
parents: 24301
diff changeset
100 #if defined(HAVE_NETWORKMANAGER) || defined(_WIN32)
b38cbefca6ad Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@wiktel.com>
parents: 24301
diff changeset
101 static gboolean force_online;
b38cbefca6ad Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@wiktel.com>
parents: 24301
diff changeset
102 #endif
b38cbefca6ad Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@wiktel.com>
parents: 24301
diff changeset
103
26055
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
104 /* Cached IP addresses for STUN and TURN servers (set globally in prefs) */
26050
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
105 static gchar *stun_ip = NULL;
26055
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
106 static gchar *turn_ip = NULL;
26050
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
107
27108
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
108 /* Keep track of port mappings done with UPnP and NAT-PMP */
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
109 static GHashTable *upnp_port_mappings = NULL;
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
110 static GHashTable *nat_pmp_port_mappings = NULL;
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
111
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112 const unsigned char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
113 purple_network_ip_atoi(const char *ip)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 static unsigned char ret[4];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116 gchar *delimiter = ".";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 gchar **split;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118 int i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120 g_return_val_if_fail(ip != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122 split = g_strsplit(ip, delimiter, 4);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 for (i = 0; split[i] != NULL; i++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124 ret[i] = atoi(split[i]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125 g_strfreev(split);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127 /* i should always be 4 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128 if (i != 4)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
129 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
135 purple_network_set_public_ip(const char *ip)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
137 g_return_if_fail(ip != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
139 /* XXX - Ensure the IP address is valid */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140
16424
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15974
diff changeset
141 purple_prefs_set_string("/purple/network/public_ip", ip);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
145 purple_network_get_public_ip(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146 {
16424
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15974
diff changeset
147 return purple_prefs_get_string("/purple/network/public_ip");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
148 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
149
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
151 purple_network_get_local_system_ip(int fd)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153 char buffer[1024];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154 static char ip[16];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155 char *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156 struct ifconf ifc;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157 struct ifreq *ifr;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 struct sockaddr_in *sinptr;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159 guint32 lhost = htonl(127 * 256 * 256 * 256 + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160 long unsigned int add;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161 int source = fd;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
162
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163 if (fd < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
164 source = socket(PF_INET,SOCK_STREAM, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166 ifc.ifc_len = sizeof(buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167 ifc.ifc_req = (struct ifreq *)buffer;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
168 ioctl(source, SIOCGIFCONF, &ifc);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
169
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
170 if (fd < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
171 close(source);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
172
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173 tmp = buffer;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174 while (tmp < buffer + ifc.ifc_len)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
176 ifr = (struct ifreq *)tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 tmp += HX_SIZE_OF_IFREQ(*ifr);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
179 if (ifr->ifr_addr.sa_family == AF_INET)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
181 sinptr = (struct sockaddr_in *)&ifr->ifr_addr;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
182 if (sinptr->sin_addr.s_addr != lhost)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
183 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184 add = ntohl(sinptr->sin_addr.s_addr);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
185 g_snprintf(ip, 16, "%lu.%lu.%lu.%lu",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
186 ((add >> 24) & 255),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
187 ((add >> 16) & 255),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
188 ((add >> 8) & 255),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
189 add & 255);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
190
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
191 return ip;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
192 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
193 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
194 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
195
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
196 return "0.0.0.0";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
197 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
198
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
199 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
200 purple_network_get_my_ip(int fd)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
201 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
202 const char *ip = NULL;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
203 PurpleStunNatDiscovery *stun;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
204
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
205 /* Check if the user specified an IP manually */
16424
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15974
diff changeset
206 if (!purple_prefs_get_bool("/purple/network/auto_ip")) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
207 ip = purple_network_get_public_ip();
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
208 /* Make sure the IP address entered by the user is valid */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
209 if ((ip != NULL) && (purple_network_ip_atoi(ip) != NULL))
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
210 return ip;
21697
65ef019c000b 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 <daniel.atallah@gmail.com>
parents: 21466
diff changeset
211 } else {
65ef019c000b 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 <daniel.atallah@gmail.com>
parents: 21466
diff changeset
212 /* Check if STUN discovery was already done */
65ef019c000b 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 <daniel.atallah@gmail.com>
parents: 21466
diff changeset
213 stun = purple_stun_discover(NULL);
65ef019c000b 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 <daniel.atallah@gmail.com>
parents: 21466
diff changeset
214 if ((stun != NULL) && (stun->status == PURPLE_STUN_STATUS_DISCOVERED))
65ef019c000b 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 <daniel.atallah@gmail.com>
parents: 21466
diff changeset
215 return stun->publicip;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
216
21697
65ef019c000b 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 <daniel.atallah@gmail.com>
parents: 21466
diff changeset
217 /* Attempt to get the IP from a NAT device using UPnP */
65ef019c000b 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 <daniel.atallah@gmail.com>
parents: 21466
diff changeset
218 ip = purple_upnp_get_public_ip();
65ef019c000b 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 <daniel.atallah@gmail.com>
parents: 21466
diff changeset
219 if (ip != NULL)
65ef019c000b 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 <daniel.atallah@gmail.com>
parents: 21466
diff changeset
220 return ip;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
221
21697
65ef019c000b 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 <daniel.atallah@gmail.com>
parents: 21466
diff changeset
222 /* Attempt to get the IP from a NAT device using NAT-PMP */
65ef019c000b 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 <daniel.atallah@gmail.com>
parents: 21466
diff changeset
223 ip = purple_pmp_get_public_ip();
65ef019c000b 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 <daniel.atallah@gmail.com>
parents: 21466
diff changeset
224 if (ip != NULL)
65ef019c000b 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 <daniel.atallah@gmail.com>
parents: 21466
diff changeset
225 return ip;
65ef019c000b 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 <daniel.atallah@gmail.com>
parents: 21466
diff changeset
226 }
15646
552be3958d6a Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15440
diff changeset
227
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
228 /* Just fetch the IP of the local system */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
229 return purple_network_get_local_system_ip(fd);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
230 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
231
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
232
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
233 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
234 purple_network_set_upnp_port_mapping_cb(gboolean success, gpointer data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
235 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
236 PurpleNetworkListenData *listen_data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
237
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
238 listen_data = data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
239 /* TODO: Once we're keeping track of upnp requests... */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
240 /* listen_data->pnp_data = NULL; */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
241
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
242 if (!success) {
27231
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27110
diff changeset
243 purple_debug_warning("network", "Couldn't create UPnP mapping\n");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
244 if (listen_data->retry) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
245 listen_data->retry = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
246 listen_data->adding = FALSE;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
247 listen_data->mapping_data = purple_upnp_remove_port_mapping(
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
248 purple_network_get_port_from_fd(listen_data->listenfd),
15440
56a2a0bb290a 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 <evan.s@dreskin.net>
parents: 15373
diff changeset
249 (listen_data->socket_type == SOCK_STREAM) ? "TCP" : "UDP",
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
250 purple_network_set_upnp_port_mapping_cb, listen_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
251 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
252 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
253 } else if (!listen_data->adding) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
254 /* We've tried successfully to remove the port mapping.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
255 * Try to add it again */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
256 listen_data->adding = TRUE;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
257 listen_data->mapping_data = purple_upnp_set_port_mapping(
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
258 purple_network_get_port_from_fd(listen_data->listenfd),
15440
56a2a0bb290a 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 <evan.s@dreskin.net>
parents: 15373
diff changeset
259 (listen_data->socket_type == SOCK_STREAM) ? "TCP" : "UDP",
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
260 purple_network_set_upnp_port_mapping_cb, listen_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
261 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
262 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
263
27108
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
264 if (success) {
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
265 /* add port mapping to hash table */
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
266 gint *key = g_new(gint, 1);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
267 gint *value = g_new(gint, 1);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
268 *key = purple_network_get_port_from_fd(listen_data->listenfd);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
269 *value = listen_data->socket_type;
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
270 g_hash_table_insert(upnp_port_mappings, key, value);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
271 }
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
272
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
273 if (listen_data->cb)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
274 listen_data->cb(listen_data->listenfd, listen_data->cb_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
275
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
276 /* Clear the UPnP mapping data, since it's complete and purple_netweork_listen_cancel() will try to cancel
15440
56a2a0bb290a 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 <evan.s@dreskin.net>
parents: 15373
diff changeset
277 * it otherwise. */
56a2a0bb290a 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 <evan.s@dreskin.net>
parents: 15373
diff changeset
278 listen_data->mapping_data = NULL;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
279 purple_network_listen_cancel(listen_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
280 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
281
15855
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
282 static gboolean
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
283 purple_network_finish_pmp_map_cb(gpointer data)
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
284 {
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
285 PurpleNetworkListenData *listen_data;
27110
455e679ea0db Remove port mappings from the hash tables when removing them.
Marcus Lundblad <ml@update.uu.se>
parents: 27108
diff changeset
286 gint *key = g_new(gint, 1);
455e679ea0db Remove port mappings from the hash tables when removing them.
Marcus Lundblad <ml@update.uu.se>
parents: 27108
diff changeset
287 gint *value = g_new(gint, 1);
15900
3a45be1c3281 Whitespace and make sure stuff is #defined to an actual value.
Mark Doliner <mark@kingant.net>
parents: 15893
diff changeset
288
15855
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
289 listen_data = data;
15900
3a45be1c3281 Whitespace and make sure stuff is #defined to an actual value.
Mark Doliner <mark@kingant.net>
parents: 15893
diff changeset
290
27110
455e679ea0db Remove port mappings from the hash tables when removing them.
Marcus Lundblad <ml@update.uu.se>
parents: 27108
diff changeset
291 /* add port mapping to hash table */
455e679ea0db Remove port mappings from the hash tables when removing them.
Marcus Lundblad <ml@update.uu.se>
parents: 27108
diff changeset
292 *key = purple_network_get_port_from_fd(listen_data->listenfd);
455e679ea0db Remove port mappings from the hash tables when removing them.
Marcus Lundblad <ml@update.uu.se>
parents: 27108
diff changeset
293 *value = listen_data->socket_type;
455e679ea0db Remove port mappings from the hash tables when removing them.
Marcus Lundblad <ml@update.uu.se>
parents: 27108
diff changeset
294 g_hash_table_insert(nat_pmp_port_mappings, key, value);
455e679ea0db Remove port mappings from the hash tables when removing them.
Marcus Lundblad <ml@update.uu.se>
parents: 27108
diff changeset
295
15855
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
296 if (listen_data->cb)
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
297 listen_data->cb(listen_data->listenfd, listen_data->cb_data);
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
298
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
299 purple_network_listen_cancel(listen_data);
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
300
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
301 return FALSE;
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
302 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
303
21466
7a05b6f84545 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 <daniel.atallah@gmail.com>
parents: 21121
diff changeset
304 static gboolean listen_map_external = TRUE;
7a05b6f84545 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 <daniel.atallah@gmail.com>
parents: 21121
diff changeset
305 void purple_network_listen_map_external(gboolean map_external)
7a05b6f84545 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 <daniel.atallah@gmail.com>
parents: 21121
diff changeset
306 {
7a05b6f84545 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 <daniel.atallah@gmail.com>
parents: 21121
diff changeset
307 listen_map_external = map_external;
7a05b6f84545 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 <daniel.atallah@gmail.com>
parents: 21121
diff changeset
308 }
7a05b6f84545 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 <daniel.atallah@gmail.com>
parents: 21121
diff changeset
309
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
310 static PurpleNetworkListenData *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
311 purple_network_do_listen(unsigned short port, int socket_type, PurpleNetworkListenCallback cb, gpointer cb_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
312 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
313 int listenfd = -1;
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
314 int flags;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
315 const int on = 1;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
316 PurpleNetworkListenData *listen_data;
15646
552be3958d6a Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15440
diff changeset
317 unsigned short actual_port;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
318 #ifdef HAVE_GETADDRINFO
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
319 int errnum;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
320 struct addrinfo hints, *res, *next;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
321 char serv[6];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
322
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
323 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
324 * Get a list of addresses on this machine.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
325 */
26885
8290e36a5a73 A patch from Scott Wolchok to replace snprintf() with g_snprintf() and
Richard Laager <rlaager@wiktel.com>
parents: 26551
diff changeset
326 g_snprintf(serv, sizeof(serv), "%hu", port);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
327 memset(&hints, 0, sizeof(struct addrinfo));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
328 hints.ai_flags = AI_PASSIVE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
329 hints.ai_family = AF_UNSPEC;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
330 hints.ai_socktype = socket_type;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
331 errnum = getaddrinfo(NULL /* any IP */, serv, &hints, &res);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
332 if (errnum != 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
333 #ifndef _WIN32
21862
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21774
diff changeset
334 purple_debug_warning("network", "getaddrinfo: %s\n", purple_gai_strerror(errnum));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
335 if (errnum == EAI_SYSTEM)
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20347
diff changeset
336 purple_debug_warning("network", "getaddrinfo: system error: %s\n", g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
337 #else
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
338 purple_debug_warning("network", "getaddrinfo: Error Code = %d\n", errnum);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
339 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
340 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
341 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
342
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
343 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
344 * Go through the list of addresses and attempt to listen on
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
345 * one of them.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
346 * XXX - Try IPv6 addresses first?
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
347 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
348 for (next = res; next != NULL; next = next->ai_next) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
349 listenfd = socket(next->ai_family, next->ai_socktype, next->ai_protocol);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
350 if (listenfd < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
351 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
352 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0)
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20347
diff changeset
353 purple_debug_warning("network", "setsockopt: %s\n", g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
354 if (bind(listenfd, next->ai_addr, next->ai_addrlen) == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
355 break; /* success */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
356 /* XXX - It is unclear to me (datallah) whether we need to be
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
357 using a new socket each time */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
358 close(listenfd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
359 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
360
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
361 freeaddrinfo(res);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
362
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
363 if (next == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
364 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
365 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
366 struct sockaddr_in sockin;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
367
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
368 if ((listenfd = socket(AF_INET, socket_type, 0)) < 0) {
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20347
diff changeset
369 purple_debug_warning("network", "socket: %s\n", g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
370 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
371 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
372
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
373 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0)
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20347
diff changeset
374 purple_debug_warning("network", "setsockopt: %s\n", g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
375
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
376 memset(&sockin, 0, sizeof(struct sockaddr_in));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
377 sockin.sin_family = PF_INET;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
378 sockin.sin_port = htons(port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
379
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
380 if (bind(listenfd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) {
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20347
diff changeset
381 purple_debug_warning("network", "bind: %s\n", g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
382 close(listenfd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
383 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
384 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
385 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
386
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
387 if (socket_type == SOCK_STREAM && listen(listenfd, 4) != 0) {
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20347
diff changeset
388 purple_debug_warning("network", "listen: %s\n", g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
389 close(listenfd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
390 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
391 }
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
392 flags = fcntl(listenfd, F_GETFL);
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
393 fcntl(listenfd, F_SETFL, flags | O_NONBLOCK);
23712
91169093449d More leaks of fds to client processes.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23201
diff changeset
394 #ifndef _WIN32
91169093449d More leaks of fds to client processes.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23201
diff changeset
395 fcntl(listenfd, F_SETFD, FD_CLOEXEC);
91169093449d More leaks of fds to client processes.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23201
diff changeset
396 #endif
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
397 actual_port = purple_network_get_port_from_fd(listenfd);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
398
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
399 purple_debug_info("network", "Listening on port: %hu\n", actual_port);
15900
3a45be1c3281 Whitespace and make sure stuff is #defined to an actual value.
Mark Doliner <mark@kingant.net>
parents: 15893
diff changeset
400
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
401 listen_data = g_new0(PurpleNetworkListenData, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
402 listen_data->listenfd = listenfd;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
403 listen_data->adding = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
404 listen_data->retry = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
405 listen_data->cb = cb;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
406 listen_data->cb_data = cb_data;
19644
ec7b92cbf49f Store the socket_type in the PurpleNetworkListenData correctly so that callback functions can use it correctly. Fixes #2933.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19408
diff changeset
407 listen_data->socket_type = socket_type;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
408
21697
65ef019c000b 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 <daniel.atallah@gmail.com>
parents: 21466
diff changeset
409 if (!listen_map_external || !purple_prefs_get_bool("/purple/network/map_ports"))
21466
7a05b6f84545 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 <daniel.atallah@gmail.com>
parents: 21121
diff changeset
410 {
7a05b6f84545 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 <daniel.atallah@gmail.com>
parents: 21121
diff changeset
411 purple_debug_info("network", "Skipping external port mapping.\n");
7a05b6f84545 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 <daniel.atallah@gmail.com>
parents: 21121
diff changeset
412 /* The pmp_map_cb does what we want to do */
7a05b6f84545 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 <daniel.atallah@gmail.com>
parents: 21121
diff changeset
413 purple_timeout_add(0, purple_network_finish_pmp_map_cb, listen_data);
7a05b6f84545 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 <daniel.atallah@gmail.com>
parents: 21121
diff changeset
414 }
15646
552be3958d6a Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15440
diff changeset
415 /* Attempt a NAT-PMP Mapping, which will return immediately */
21466
7a05b6f84545 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 <daniel.atallah@gmail.com>
parents: 21121
diff changeset
416 else if (purple_pmp_create_map(((socket_type == SOCK_STREAM) ? PURPLE_PMP_TYPE_TCP : PURPLE_PMP_TYPE_UDP),
15949
b4ab4812838a purple_pmp_create_map() returns a gboolean now, not a pointer
Evan Schoenberg <evan.s@dreskin.net>
parents: 15900
diff changeset
417 actual_port, actual_port, PURPLE_PMP_LIFETIME))
15855
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
418 {
21466
7a05b6f84545 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 <daniel.atallah@gmail.com>
parents: 21121
diff changeset
419 purple_debug_info("network", "Created NAT-PMP mapping on port %i\n", actual_port);
15855
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
420 /* We want to return listen_data now, and on the next run loop trigger the cb and destroy listen_data */
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
421 purple_timeout_add(0, purple_network_finish_pmp_map_cb, listen_data);
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
422 }
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
423 else
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
424 {
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
425 /* Attempt a UPnP Mapping */
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
426 listen_data->mapping_data = purple_upnp_set_port_mapping(
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
427 actual_port,
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
428 (socket_type == SOCK_STREAM) ? "TCP" : "UDP",
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
429 purple_network_set_upnp_port_mapping_cb, listen_data);
9b875f0ecb86 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 <evan.s@dreskin.net>
parents: 15822
diff changeset
430 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
431
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
432 return listen_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
433 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
434
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
435 PurpleNetworkListenData *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
436 purple_network_listen(unsigned short port, int socket_type,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
437 PurpleNetworkListenCallback cb, gpointer cb_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
438 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
439 g_return_val_if_fail(port != 0, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
440
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
441 return purple_network_do_listen(port, socket_type, cb, cb_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
442 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
443
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
444 PurpleNetworkListenData *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
445 purple_network_listen_range(unsigned short start, unsigned short end,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
446 int socket_type, PurpleNetworkListenCallback cb, gpointer cb_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
447 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
448 PurpleNetworkListenData *ret = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
449
16424
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15974
diff changeset
450 if (purple_prefs_get_bool("/purple/network/ports_range_use")) {
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15974
diff changeset
451 start = purple_prefs_get_int("/purple/network/ports_range_start");
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15974
diff changeset
452 end = purple_prefs_get_int("/purple/network/ports_range_end");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
453 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
454 if (end < start)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
455 end = start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
456 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
457
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
458 for (; start <= end; start++) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
459 ret = purple_network_do_listen(start, socket_type, cb, cb_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
460 if (ret != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
461 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
462 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
463
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
464 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
465 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
466
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
467 void purple_network_listen_cancel(PurpleNetworkListenData *listen_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
468 {
15440
56a2a0bb290a 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 <evan.s@dreskin.net>
parents: 15373
diff changeset
469 if (listen_data->mapping_data != NULL)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
470 purple_upnp_cancel_port_mapping(listen_data->mapping_data);
15440
56a2a0bb290a 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 <evan.s@dreskin.net>
parents: 15373
diff changeset
471
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
472 g_free(listen_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
473 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
474
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
475 unsigned short
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
476 purple_network_get_port_from_fd(int fd)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
477 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
478 struct sockaddr_in addr;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
479 socklen_t len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
480
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
481 g_return_val_if_fail(fd >= 0, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
482
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
483 len = sizeof(addr);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
484 if (getsockname(fd, (struct sockaddr *) &addr, &len) == -1) {
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20347
diff changeset
485 purple_debug_warning("network", "getsockname: %s\n", g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
486 return 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
487 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
488
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
489 return ntohs(addr.sin_port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
490 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
491
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
492 #ifdef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
493 #ifndef NS_NLA
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
494 #define NS_NLA 15
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
495 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
496 static gint
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
497 wpurple_get_connected_network_count(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
498 {
19408
cc36a5aac908 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 <daniel.atallah@gmail.com>
parents: 18401
diff changeset
499 gint net_cnt = 0;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
500
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
501 WSAQUERYSET qs;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
502 HANDLE h;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
503 gint retval;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
504 int errorid;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
505
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
506 memset(&qs, 0, sizeof(WSAQUERYSET));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
507 qs.dwSize = sizeof(WSAQUERYSET);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
508 qs.dwNameSpace = NS_NLA;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
509
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
510 retval = WSALookupServiceBegin(&qs, LUP_RETURN_ALL, &h);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
511 if (retval != ERROR_SUCCESS) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
512 gchar *msg;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
513 errorid = WSAGetLastError();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
514 msg = g_win32_error_message(errorid);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
515 purple_debug_warning("network", "Couldn't retrieve NLA SP lookup handle. "
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
516 "NLA service is probably not running. Message: %s (%d).\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
517 msg, errorid);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
518 g_free(msg);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
519
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
520 return -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
521 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
522 char buf[4096];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
523 WSAQUERYSET *res = (LPWSAQUERYSET) buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
524 DWORD size = sizeof(buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
525 while ((retval = WSALookupServiceNext(h, 0, &size, res)) == ERROR_SUCCESS) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
526 net_cnt++;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
527 purple_debug_info("network", "found network '%s'\n",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
528 res->lpszServiceInstanceName ? res->lpszServiceInstanceName : "(NULL)");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
529 size = sizeof(buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
530 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
531
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
532 errorid = WSAGetLastError();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
533 if (!(errorid == WSA_E_NO_MORE || errorid == WSAENOMORE)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
534 gchar *msg = g_win32_error_message(errorid);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
535 purple_debug_error("network", "got unexpected NLA response %s (%d)\n", msg, errorid);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
536 g_free(msg);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
537
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
538 net_cnt = -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
539 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
540
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
541 retval = WSALookupServiceEnd(h);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
542 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
543
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
544 return net_cnt;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
545
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
546 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
547
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
548 static gboolean wpurple_network_change_thread_cb(gpointer data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
549 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
550 gint new_count;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
551 PurpleConnectionUiOps *ui_ops = purple_connections_get_ui_ops();
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
552
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
553 new_count = wpurple_get_connected_network_count();
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
554
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
555 if (new_count < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
556 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
557
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
558 purple_debug_info("network", "Received Network Change Notification. Current network count is %d, previous count was %d.\n", new_count, current_network_count);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
559
15974
1a12ce76c4f4 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 <evan.s@dreskin.net>
parents: 15949
diff changeset
560 purple_signal_emit(purple_network_get_handle(), "network-configuration-changed", NULL);
1a12ce76c4f4 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 <evan.s@dreskin.net>
parents: 15949
diff changeset
561
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
562 if (new_count > 0 && ui_ops != NULL && ui_ops->network_connected != NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
563 ui_ops->network_connected();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
564 } else if (new_count == 0 && current_network_count > 0 &&
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
565 ui_ops != NULL && ui_ops->network_disconnected != NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
566 ui_ops->network_disconnected();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
567 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
568
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
569 current_network_count = new_count;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
570
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
571 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
572 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
573
25401
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
574 static gboolean _print_debug_msg(gpointer data) {
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
575 gchar *msg = data;
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
576 purple_debug_warning("network", msg);
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
577 g_free(msg);
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
578 return FALSE;
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
579 }
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
580
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
581 static gpointer wpurple_network_change_thread(gpointer data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
582 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
583 WSAQUERYSET qs;
24888
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
584 WSAEVENT *nla_event;
25401
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
585 time_t last_trigger = time(NULL) - 31;
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
586 char buf[4096];
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
587 WSAQUERYSET *res = (LPWSAQUERYSET) buf;
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
588 DWORD size;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
589
24888
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
590 if ((nla_event = WSACreateEvent()) == WSA_INVALID_EVENT) {
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
591 int errorid = WSAGetLastError();
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
592 gchar *msg = g_win32_error_message(errorid);
25401
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
593 purple_timeout_add(0, _print_debug_msg,
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
594 g_strdup_printf("Couldn't create WSA event. "
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
595 "Message: %s (%d).\n", msg, errorid));
24888
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
596 g_free(msg);
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
597 g_thread_exit(NULL);
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
598 return NULL;
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
599 }
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
600
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
601 while (TRUE) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
602 int retval;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
603 DWORD retLen = 0;
24888
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
604 WSACOMPLETION completion;
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
605 WSAOVERLAPPED overlapped;
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
606
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
607 g_static_mutex_lock(&mutex);
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
608 if (network_initialized == FALSE) {
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
609 /* purple_network_uninit has been called */
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
610 WSACloseEvent(nla_event);
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
611 g_static_mutex_unlock(&mutex);
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
612 g_thread_exit(NULL);
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
613 return NULL;
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
614 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
615
25401
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
616 if (network_change_handle == NULL) {
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
617 memset(&qs, 0, sizeof(WSAQUERYSET));
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
618 qs.dwSize = sizeof(WSAQUERYSET);
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
619 qs.dwNameSpace = NS_NLA;
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
620 if (WSALookupServiceBegin(&qs, 0, &network_change_handle) == SOCKET_ERROR) {
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
621 int errorid = WSAGetLastError();
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
622 gchar *msg = g_win32_error_message(errorid);
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
623 purple_timeout_add(0, _print_debug_msg,
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
624 g_strdup_printf("Couldn't retrieve NLA SP lookup handle. "
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
625 "NLA service is probably not running. Message: %s (%d).\n",
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
626 msg, errorid));
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
627 g_free(msg);
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
628 WSACloseEvent(nla_event);
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
629 g_static_mutex_unlock(&mutex);
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
630 g_thread_exit(NULL);
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
631 return NULL;
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
632 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
633 }
24888
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
634 g_static_mutex_unlock(&mutex);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
635
24888
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
636 memset(&completion, 0, sizeof(WSACOMPLETION));
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
637 completion.Type = NSP_NOTIFY_EVENT;
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
638 overlapped.hEvent = nla_event;
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
639 completion.Parameters.Event.lpOverlapped = &overlapped;
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
640
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
641 if (MyWSANSPIoctl(network_change_handle, SIO_NSP_NOTIFY_CHANGE, NULL, 0, NULL, 0, &retLen, &completion) == SOCKET_ERROR) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
642 int errorid = WSAGetLastError();
25401
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
643 if (errorid == WSA_INVALID_HANDLE) {
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
644 purple_timeout_add(0, _print_debug_msg,
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
645 g_strdup("Invalid NLA handle; resetting.\n"));
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
646 g_static_mutex_lock(&mutex);
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
647 retval = WSALookupServiceEnd(network_change_handle);
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
648 network_change_handle = NULL;
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
649 g_static_mutex_unlock(&mutex);
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
650 continue;
24888
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
651 /* WSA_IO_PENDING indicates successful async notification will happen */
25401
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
652 } else if (errorid != WSA_IO_PENDING) {
24888
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
653 gchar *msg = g_win32_error_message(errorid);
25401
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
654 purple_timeout_add(0, _print_debug_msg,
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
655 g_strdup_printf("Unable to wait for changes. Message: %s (%d).\n",
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
656 msg, errorid));
24888
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
657 g_free(msg);
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
658 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
659 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
660
25401
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
661 /* Make sure at least 30 seconds have elapsed since the last
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
662 * notification so we don't peg the cpu if this keeps changing. */
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
663 if ((time(NULL) - last_trigger) < 30)
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
664 Sleep(30000);
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
665
24888
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
666 /* This will block until NLA notifies us */
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
667 retval = WaitForSingleObjectEx(nla_event, WSA_INFINITE, TRUE);
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
668
25401
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
669 last_trigger = time(NULL);
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
670
24888
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
671 g_static_mutex_lock(&mutex);
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
672 if (network_initialized == FALSE) {
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
673 /* Time to die */
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
674 WSACloseEvent(nla_event);
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
675 g_static_mutex_unlock(&mutex);
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
676 g_thread_exit(NULL);
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
677 return NULL;
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
678 }
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
679
25401
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
680 size = sizeof(buf);
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
681 while ((retval = WSALookupServiceNext(network_change_handle, 0, &size, res)) == ERROR_SUCCESS) {
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
682 /*purple_timeout_add(0, _print_debug_msg,
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
683 g_strdup_printf("thread found network '%s'\n",
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
684 res->lpszServiceInstanceName ? res->lpszServiceInstanceName : "(NULL)"));*/
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
685 size = sizeof(buf);
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
686 }
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
687
24888
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
688 WSAResetEvent(nla_event);
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
689 g_static_mutex_unlock(&mutex);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
690
21466
7a05b6f84545 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 <daniel.atallah@gmail.com>
parents: 21121
diff changeset
691 purple_timeout_add(0, wpurple_network_change_thread_cb, NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
692 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
693
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
694 g_thread_exit(NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
695 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
696 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
697 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
698
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
699 gboolean
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
700 purple_network_is_available(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
701 {
22895
0bd86dae2734 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@wiktel.com>
parents: 22889
diff changeset
702 #ifdef HAVE_NETWORKMANAGER
25852
b38cbefca6ad Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@wiktel.com>
parents: 24301
diff changeset
703 if (force_online)
b38cbefca6ad Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@wiktel.com>
parents: 24301
diff changeset
704 return TRUE;
b38cbefca6ad Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@wiktel.com>
parents: 24301
diff changeset
705
24301
785db7300ef2 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@wiktel.com>
parents: 23712
diff changeset
706 if (!have_nm_state)
22882
6421d275c85e Fix some whitespace as noticed by QuLogic.
Richard Laager <rlaager@wiktel.com>
parents: 22876
diff changeset
707 {
24301
785db7300ef2 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@wiktel.com>
parents: 23712
diff changeset
708 have_nm_state = TRUE;
785db7300ef2 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@wiktel.com>
parents: 23712
diff changeset
709 nm_state = nm_get_network_state();
785db7300ef2 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@wiktel.com>
parents: 23712
diff changeset
710 if (nm_state == NM_STATE_UNKNOWN)
785db7300ef2 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@wiktel.com>
parents: 23712
diff changeset
711 purple_debug_warning("network", "NetworkManager not active. Assuming connection exists.\n");
22876
e6674df4cbf1 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@wiktel.com>
parents: 22875
diff changeset
712 }
24301
785db7300ef2 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@wiktel.com>
parents: 23712
diff changeset
713
785db7300ef2 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@wiktel.com>
parents: 23712
diff changeset
714 if (nm_state == NM_STATE_UNKNOWN || nm_state == NM_STATE_CONNECTED)
22875
4f6040bb6f7a Update configure.ac to properly detect Network Manager (via NetworkManager.h instead of libnm_glib). Also, change the code so that if NetworkManager is dead, we'll assume we're connected to the network and try anyway.
Richard Laager <rlaager@wiktel.com>
parents: 22874
diff changeset
715 return TRUE;
22876
e6674df4cbf1 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@wiktel.com>
parents: 22875
diff changeset
716
e6674df4cbf1 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@wiktel.com>
parents: 22875
diff changeset
717 return FALSE;
e6674df4cbf1 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@wiktel.com>
parents: 22875
diff changeset
718
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
719 #elif defined _WIN32
25852
b38cbefca6ad Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@wiktel.com>
parents: 24301
diff changeset
720 return (current_network_count > 0 || force_online);
22876
e6674df4cbf1 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@wiktel.com>
parents: 22875
diff changeset
721 #else
e6674df4cbf1 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@wiktel.com>
parents: 22875
diff changeset
722 return TRUE;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
723 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
724 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
725
25852
b38cbefca6ad Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@wiktel.com>
parents: 24301
diff changeset
726 void
b38cbefca6ad Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@wiktel.com>
parents: 24301
diff changeset
727 purple_network_force_online()
b38cbefca6ad Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@wiktel.com>
parents: 24301
diff changeset
728 {
b38cbefca6ad Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@wiktel.com>
parents: 24301
diff changeset
729 #if defined(HAVE_NETWORKMANAGER) || defined(_WIN32)
b38cbefca6ad Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@wiktel.com>
parents: 24301
diff changeset
730 force_online = TRUE;
b38cbefca6ad Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@wiktel.com>
parents: 24301
diff changeset
731 #endif
b38cbefca6ad Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@wiktel.com>
parents: 24301
diff changeset
732 }
b38cbefca6ad Add a -f/--force-online option to Pidgin which tells libpurple to claim the
Richard Laager <rlaager@wiktel.com>
parents: 24301
diff changeset
733
22895
0bd86dae2734 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@wiktel.com>
parents: 22889
diff changeset
734 #ifdef HAVE_NETWORKMANAGER
22594
0e426ad6cc87 Make some more things static
Stu Tomlinson <stu@nosnilmot.com>
parents: 21862
diff changeset
735 static void
22874
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
736 nm_update_state(NMState state)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
737 {
24301
785db7300ef2 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@wiktel.com>
parents: 23712
diff changeset
738 NMState prev = nm_state;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
739 PurpleConnectionUiOps *ui_ops = purple_connections_get_ui_ops();
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
740
24301
785db7300ef2 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@wiktel.com>
parents: 23712
diff changeset
741 have_nm_state = TRUE;
785db7300ef2 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@wiktel.com>
parents: 23712
diff changeset
742 nm_state = state;
785db7300ef2 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@wiktel.com>
parents: 23712
diff changeset
743
15974
1a12ce76c4f4 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 <evan.s@dreskin.net>
parents: 15949
diff changeset
744 purple_signal_emit(purple_network_get_handle(), "network-configuration-changed", NULL);
1a12ce76c4f4 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 <evan.s@dreskin.net>
parents: 15949
diff changeset
745
22874
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
746 switch(state)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
747 {
22874
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
748 case NM_STATE_CONNECTED:
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
749 /* Call res_init in case DNS servers have changed */
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
750 res_init();
26050
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
751 /* update STUN IP in case we it changed (theoretically we could
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
752 have gone from IPv4 to IPv6, f.ex. or we were previously
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
753 offline */
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
754 purple_network_set_stun_server(
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
755 purple_prefs_get_string("/purple/network/stun_server"));
26055
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
756 purple_network_set_turn_server(
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
757 purple_prefs_get_string("/purple/network/turn_server"));
26050
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
758
22874
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
759 if (ui_ops != NULL && ui_ops->network_connected != NULL)
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
760 ui_ops->network_connected();
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
761 break;
22874
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
762 case NM_STATE_ASLEEP:
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
763 case NM_STATE_CONNECTING:
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
764 case NM_STATE_DISCONNECTED:
24301
785db7300ef2 Improve our NetworkManager support in a couple of ways:
Richard Laager <rlaager@wiktel.com>
parents: 23712
diff changeset
765 if (prev != NM_STATE_CONNECTED && prev != NM_STATE_UNKNOWN)
22874
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
766 break;
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
767 if (ui_ops != NULL && ui_ops->network_disconnected != NULL)
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
768 ui_ops->network_disconnected();
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
769 break;
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
770 case NM_STATE_UNKNOWN:
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
771 default:
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
772 break;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
773 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
774 }
22874
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
775
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
776 static void
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
777 nm_state_change_cb(DBusGProxy *proxy, NMState state, gpointer user_data)
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
778 {
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
779 purple_debug_info("network", "Got StateChange from NetworkManager: %d.\n", state);
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
780 nm_update_state(state);
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
781 }
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
782
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
783 static NMState
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
784 nm_get_network_state(void)
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
785 {
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
786 GError *err = NULL;
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
787 NMState state = NM_STATE_UNKNOWN;
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
788
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
789 if (!nm_proxy)
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
790 return NM_STATE_UNKNOWN;
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
791
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
792 if (!dbus_g_proxy_call(nm_proxy, "state", &err, G_TYPE_INVALID, G_TYPE_UINT, &state, G_TYPE_INVALID)) {
23043
Stu Tomlinson <stu@nosnilmot.com>
parents: 22895
diff changeset
793 g_error_free(err);
22874
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
794 return NM_STATE_UNKNOWN;
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
795 }
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
796
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
797 return state;
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
798 }
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
799
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
800 static void
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
801 nm_dbus_name_owner_changed_cb(DBusGProxy *proxy, char *service, char *old_owner, char *new_owner, gpointer user_data)
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
802 {
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
803 if (g_str_equal(service, NM_DBUS_SERVICE)) {
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
804 gboolean old_owner_good = old_owner && (old_owner[0] != '\0');
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
805 gboolean new_owner_good = new_owner && (new_owner[0] != '\0');
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
806
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
807 purple_debug_info("network", "Got NameOwnerChanged signal, service = '%s', old_owner = '%s', new_owner = '%s'\n", service, old_owner, new_owner);
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
808 if (!old_owner_good && new_owner_good) { /* Equivalent to old ServiceCreated signal */
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
809 purple_debug_info("network", "NetworkManager has started.\n");
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
810 nm_update_state(nm_get_network_state());
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
811 } else if (old_owner_good && !new_owner_good) { /* Equivalent to old ServiceDeleted signal */
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
812 purple_debug_info("network", "NetworkManager has gone away.\n");
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
813 nm_update_state(NM_STATE_UNKNOWN);
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
814 }
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
815 }
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
816 }
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
817
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
818 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
819
26050
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
820 static void
26055
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
821 purple_network_ip_lookup_cb(GSList *hosts, gpointer data,
26050
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
822 const char *error_message)
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
823 {
26055
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
824 const gchar **ip = (const gchar **) data;
26056
4f0aec6d4ad7 Removed some extra tabs on blank lines
Marcus Lundblad <ml@update.uu.se>
parents: 26055
diff changeset
825
26050
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
826 if (error_message) {
26055
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
827 purple_debug_error("network", "lookup of IP address failed: %s\n",
26050
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
828 error_message);
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
829 g_slist_free(hosts);
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
830 return;
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
831 }
26056
4f0aec6d4ad7 Removed some extra tabs on blank lines
Marcus Lundblad <ml@update.uu.se>
parents: 26055
diff changeset
832
26050
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
833 if (hosts && g_slist_next(hosts)) {
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
834 struct sockaddr *addr = g_slist_next(hosts)->data;
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
835 char dst[INET6_ADDRSTRLEN];
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
836
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
837 if (addr->sa_family == AF_INET6) {
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
838 inet_ntop(addr->sa_family, &((struct sockaddr_in6 *) addr)->sin6_addr,
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
839 dst, sizeof(dst));
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
840 } else {
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
841 inet_ntop(addr->sa_family, &((struct sockaddr_in *) addr)->sin_addr,
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
842 dst, sizeof(dst));
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
843 }
26056
4f0aec6d4ad7 Removed some extra tabs on blank lines
Marcus Lundblad <ml@update.uu.se>
parents: 26055
diff changeset
844
26055
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
845 *ip = g_strdup(dst);
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
846 purple_debug_info("network", "set IP address: %s\n", *ip);
26050
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
847 }
26551
5d1140b0b10a Don't leak the struct sockaddr* from purple_dnsquery_a.
Paul Aurich <paul@darkrain42.org>
parents: 26131
diff changeset
848
5d1140b0b10a Don't leak the struct sockaddr* from purple_dnsquery_a.
Paul Aurich <paul@darkrain42.org>
parents: 26131
diff changeset
849 while (hosts != NULL) {
5d1140b0b10a Don't leak the struct sockaddr* from purple_dnsquery_a.
Paul Aurich <paul@darkrain42.org>
parents: 26131
diff changeset
850 hosts = g_slist_delete_link(hosts, hosts);
5d1140b0b10a Don't leak the struct sockaddr* from purple_dnsquery_a.
Paul Aurich <paul@darkrain42.org>
parents: 26131
diff changeset
851 /* Free the address */
5d1140b0b10a Don't leak the struct sockaddr* from purple_dnsquery_a.
Paul Aurich <paul@darkrain42.org>
parents: 26131
diff changeset
852 g_free(hosts->data);
5d1140b0b10a Don't leak the struct sockaddr* from purple_dnsquery_a.
Paul Aurich <paul@darkrain42.org>
parents: 26131
diff changeset
853 hosts = g_slist_delete_link(hosts, hosts);
5d1140b0b10a Don't leak the struct sockaddr* from purple_dnsquery_a.
Paul Aurich <paul@darkrain42.org>
parents: 26131
diff changeset
854 }
26050
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
855 }
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
856
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
857 void
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
858 purple_network_set_stun_server(const gchar *stun_server)
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
859 {
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
860 if (stun_server && stun_server[0] != '\0') {
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
861 if (purple_network_is_available()) {
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
862 purple_debug_info("network", "running DNS query for STUN server\n");
26055
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
863 purple_dnsquery_a(stun_server, 3478, purple_network_ip_lookup_cb,
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
864 &stun_ip);
26050
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
865 } else {
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
866 purple_debug_info("network",
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
867 "network is unavailable, don't try to update STUN IP");
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
868 }
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
869 } else if (stun_ip) {
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
870 g_free(stun_ip);
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
871 stun_ip = NULL;
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
872 }
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
873 }
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
874
26055
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
875 void
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
876 purple_network_set_turn_server(const gchar *turn_server)
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
877 {
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
878 if (turn_server && turn_server[0] != '\0') {
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
879 if (purple_network_is_available()) {
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
880 purple_debug_info("network", "running DNS query for TURN server\n");
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
881 purple_dnsquery_a(turn_server,
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
882 purple_prefs_get_int("/purple/network/turn_port"),
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
883 purple_network_ip_lookup_cb, &turn_ip);
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
884 } else {
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
885 purple_debug_info("network",
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
886 "network is unavailable, don't try to update TURN IP");
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
887 }
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
888 } else if (turn_ip) {
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
889 g_free(turn_ip);
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
890 turn_ip = NULL;
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
891 }
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
892 }
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
893
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
894
26050
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
895 const gchar *
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
896 purple_network_get_stun_ip(void)
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
897 {
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
898 return stun_ip;
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
899 }
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
900
26055
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
901 const gchar *
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
902 purple_network_get_turn_ip(void)
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
903 {
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
904 return turn_ip;
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
905 }
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
906
15974
1a12ce76c4f4 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 <evan.s@dreskin.net>
parents: 15949
diff changeset
907 void *
1a12ce76c4f4 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 <evan.s@dreskin.net>
parents: 15949
diff changeset
908 purple_network_get_handle(void)
1a12ce76c4f4 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 <evan.s@dreskin.net>
parents: 15949
diff changeset
909 {
1a12ce76c4f4 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 <evan.s@dreskin.net>
parents: 15949
diff changeset
910 static int handle;
19408
cc36a5aac908 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 <daniel.atallah@gmail.com>
parents: 18401
diff changeset
911
15974
1a12ce76c4f4 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 <evan.s@dreskin.net>
parents: 15949
diff changeset
912 return &handle;
1a12ce76c4f4 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 <evan.s@dreskin.net>
parents: 15949
diff changeset
913 }
1a12ce76c4f4 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 <evan.s@dreskin.net>
parents: 15949
diff changeset
914
27108
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
915 static void
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
916 purple_network_upnp_mapping_remove_cb(gboolean sucess, gpointer data)
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
917 {
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
918 purple_debug_info("network", "done removing UPnP port mapping\n");
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
919 }
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
920
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
921 /* the reason for these functions to have these signatures is to be able to
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
922 use them for g_hash_table_foreach to clean remaining port mappings, which is
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
923 not yet done */
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
924 static void
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
925 purple_network_upnp_mapping_remove(gpointer key, gpointer value,
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
926 gpointer user_data)
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
927 {
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
928 gint port = (gint) *((gint *) key);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
929 gint protocol = (gint) *((gint *) value);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
930 purple_debug_info("network", "removing UPnP port mapping for port %d\n",
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
931 port);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
932 purple_upnp_remove_port_mapping(port,
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
933 protocol == SOCK_STREAM ? "TCP" : "UDP",
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
934 purple_network_upnp_mapping_remove_cb, NULL);
27110
455e679ea0db Remove port mappings from the hash tables when removing them.
Marcus Lundblad <ml@update.uu.se>
parents: 27108
diff changeset
935 g_hash_table_remove(upnp_port_mappings, key);
27108
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
936 }
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
937
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
938 static void
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
939 purple_network_nat_pmp_mapping_remove(gpointer key, gpointer value,
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
940 gpointer user_data)
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
941 {
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
942 gint port = (gint) *((gint *) key);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
943 gint protocol = (gint) *((gint *) value);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
944 purple_debug_info("network", "removing NAT-PMP port mapping for port %d\n",
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
945 port);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
946 purple_pmp_destroy_map(
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
947 protocol == SOCK_STREAM ? PURPLE_PMP_TYPE_TCP : PURPLE_PMP_TYPE_UDP,
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
948 port);
27110
455e679ea0db Remove port mappings from the hash tables when removing them.
Marcus Lundblad <ml@update.uu.se>
parents: 27108
diff changeset
949 g_hash_table_remove(nat_pmp_port_mappings, key);
27108
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
950 }
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
951
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
952 void
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
953 purple_network_remove_port_mapping(gint fd)
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
954 {
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
955 int port = purple_network_get_port_from_fd(fd);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
956 gint *protocol = g_hash_table_lookup(upnp_port_mappings, &port);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
957
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
958 if (protocol) {
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
959 purple_network_upnp_mapping_remove(&port, protocol, NULL);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
960 g_hash_table_remove(upnp_port_mappings, protocol);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
961 } else {
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
962 protocol = g_hash_table_lookup(nat_pmp_port_mappings, &port);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
963 if (protocol) {
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
964 purple_network_nat_pmp_mapping_remove(&port, protocol, NULL);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
965 g_hash_table_remove(nat_pmp_port_mappings, protocol);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
966 }
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
967 }
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
968 }
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
969
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
970 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
971 purple_network_init(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
972 {
22895
0bd86dae2734 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@wiktel.com>
parents: 22889
diff changeset
973 #ifdef HAVE_NETWORKMANAGER
22874
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
974 GError *error = NULL;
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
975 #endif
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
976 #ifdef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
977 GError *err = NULL;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
978 gint cnt = wpurple_get_connected_network_count();
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
979
24888
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
980 network_initialized = TRUE;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
981 if (cnt < 0) /* Assume there is a network */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
982 current_network_count = 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
983 /* Don't listen for network changes if we can't tell anyway */
25401
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
984 else {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
985 current_network_count = cnt;
25401
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
986 if ((MyWSANSPIoctl = (void*) wpurple_find_and_loadproc("ws2_32.dll", "WSANSPIoctl"))) {
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
987 if (!g_thread_create(wpurple_network_change_thread, NULL, FALSE, &err))
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
988 purple_debug_error("network", "Couldn't create Network Monitor thread: %s\n", err ? err->message : "");
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
989 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
990 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
991 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
992
16424
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15974
diff changeset
993 purple_prefs_add_none ("/purple/network");
26050
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
994 purple_prefs_add_string("/purple/network/stun_server", "");
26055
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
995 purple_prefs_add_string("/purple/network/turn_server", "");
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
996 purple_prefs_add_int ("/purple/network/turn_port", 3478);
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
997 purple_prefs_add_string("/purple/network/turn_username", "");
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
998 purple_prefs_add_string("/purple/network/turn_password", "");
16424
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15974
diff changeset
999 purple_prefs_add_bool ("/purple/network/auto_ip", TRUE);
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15974
diff changeset
1000 purple_prefs_add_string("/purple/network/public_ip", "");
21697
65ef019c000b 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 <daniel.atallah@gmail.com>
parents: 21466
diff changeset
1001 purple_prefs_add_bool ("/purple/network/map_ports", TRUE);
16424
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15974
diff changeset
1002 purple_prefs_add_bool ("/purple/network/ports_range_use", FALSE);
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15974
diff changeset
1003 purple_prefs_add_int ("/purple/network/ports_range_start", 1024);
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15974
diff changeset
1004 purple_prefs_add_int ("/purple/network/ports_range_end", 2048);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1005
21697
65ef019c000b 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 <daniel.atallah@gmail.com>
parents: 21466
diff changeset
1006 if(purple_prefs_get_bool("/purple/network/map_ports") || purple_prefs_get_bool("/purple/network/auto_ip"))
65ef019c000b 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 <daniel.atallah@gmail.com>
parents: 21466
diff changeset
1007 purple_upnp_discover(NULL, NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1008
22895
0bd86dae2734 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@wiktel.com>
parents: 22889
diff changeset
1009 #ifdef HAVE_NETWORKMANAGER
22874
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1010 nm_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1011 if (!nm_conn) {
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1012 purple_debug_warning("network", "Error connecting to DBus System service: %s.\n", error->message);
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1013 } else {
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1014 nm_proxy = dbus_g_proxy_new_for_name(nm_conn,
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1015 NM_DBUS_SERVICE,
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1016 NM_DBUS_PATH,
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1017 NM_DBUS_INTERFACE);
22889
f5d39c44465a Modify the NetworkManager support to use "StateChange" directly, instead of
Richard Laager <rlaager@wiktel.com>
parents: 22882
diff changeset
1018 dbus_g_proxy_add_signal(nm_proxy, "StateChange", G_TYPE_UINT, G_TYPE_INVALID);
f5d39c44465a Modify the NetworkManager support to use "StateChange" directly, instead of
Richard Laager <rlaager@wiktel.com>
parents: 22882
diff changeset
1019 dbus_g_proxy_connect_signal(nm_proxy, "StateChange",
22874
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1020 G_CALLBACK(nm_state_change_cb), NULL, NULL);
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1021
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1022 dbus_proxy = dbus_g_proxy_new_for_name(nm_conn,
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1023 DBUS_SERVICE_DBUS,
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1024 DBUS_PATH_DBUS,
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1025 DBUS_INTERFACE_DBUS);
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1026 dbus_g_proxy_add_signal(dbus_proxy, "NameOwnerChanged", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1027 dbus_g_proxy_connect_signal(dbus_proxy, "NameOwnerChanged",
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1028 G_CALLBACK(nm_dbus_name_owner_changed_cb), NULL, NULL);
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1029 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1030 #endif
15974
1a12ce76c4f4 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 <evan.s@dreskin.net>
parents: 15949
diff changeset
1031
1a12ce76c4f4 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 <evan.s@dreskin.net>
parents: 15949
diff changeset
1032 purple_signal_register(purple_network_get_handle(), "network-configuration-changed",
1a12ce76c4f4 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 <evan.s@dreskin.net>
parents: 15949
diff changeset
1033 purple_marshal_VOID, NULL, 0);
19408
cc36a5aac908 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 <daniel.atallah@gmail.com>
parents: 18401
diff changeset
1034
15974
1a12ce76c4f4 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 <evan.s@dreskin.net>
parents: 15949
diff changeset
1035 purple_pmp_init();
1a12ce76c4f4 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 <evan.s@dreskin.net>
parents: 15949
diff changeset
1036 purple_upnp_init();
26050
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
1037
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
1038 purple_network_set_stun_server(
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
1039 purple_prefs_get_string("/purple/network/stun_server"));
26055
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
1040 purple_network_set_turn_server(
c56e8826fed0 Added support to generate relayed candidates (TURN).
Marcus Lundblad <ml@update.uu.se>
parents: 26050
diff changeset
1041 purple_prefs_get_string("/purple/network/turn_server"));
27108
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
1042
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
1043 upnp_port_mappings =
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
1044 g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
1045 nat_pmp_port_mappings =
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
1046 g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1047 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1048
27108
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
1049
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
1050
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1051 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15646
diff changeset
1052 purple_network_uninit(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1053 {
22895
0bd86dae2734 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@wiktel.com>
parents: 22889
diff changeset
1054 #ifdef HAVE_NETWORKMANAGER
22874
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1055 if (nm_proxy) {
22889
f5d39c44465a Modify the NetworkManager support to use "StateChange" directly, instead of
Richard Laager <rlaager@wiktel.com>
parents: 22882
diff changeset
1056 dbus_g_proxy_disconnect_signal(nm_proxy, "StateChange", G_CALLBACK(nm_state_change_cb), NULL);
22874
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1057 g_object_unref(G_OBJECT(nm_proxy));
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1058 }
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1059 if (dbus_proxy) {
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1060 dbus_g_proxy_disconnect_signal(dbus_proxy, "NameOwnerChanged", G_CALLBACK(nm_dbus_name_owner_changed_cb), NULL);
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1061 g_object_unref(G_OBJECT(dbus_proxy));
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1062 }
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1063 if (nm_conn)
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22594
diff changeset
1064 dbus_g_connection_unref(nm_conn);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1065 #endif
21067
96929e7acb86 Make purple_xfers_uninit, purple_network_uninit, and purple_plugins_uninit
Etan Reisner <pidgin@unreliablesource.net>
parents: 20347
diff changeset
1066
24888
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1067 #ifdef _WIN32
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1068 g_static_mutex_lock(&mutex);
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1069 network_initialized = FALSE;
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1070 if (network_change_handle != NULL) {
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1071 int retval;
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1072 /* Trigger the NLA thread to stop waiting for network changes. Not
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1073 * doing this can cause hangs on WSACleanup. */
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1074 purple_debug_warning("network", "Terminating the NLA thread\n");
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1075 if ((retval = WSALookupServiceEnd(network_change_handle)) == SOCKET_ERROR) {
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1076 int errorid = WSAGetLastError();
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1077 gchar *msg = g_win32_error_message(errorid);
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1078 purple_debug_warning("network", "Unable to kill NLA thread. Message: %s (%d).\n",
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1079 msg, errorid);
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1080 g_free(msg);
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1081 }
25401
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
1082 network_change_handle = NULL;
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
1083
24888
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1084 }
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1085 g_static_mutex_unlock(&mutex);
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1086
a6742d9eadf3 Adjust the NLA code to prevent hang on exit for Windows XP and Windows Vista.
Paul Aurich <paul@darkrain42.org>
parents: 24301
diff changeset
1087 #endif
21067
96929e7acb86 Make purple_xfers_uninit, purple_network_uninit, and purple_plugins_uninit
Etan Reisner <pidgin@unreliablesource.net>
parents: 20347
diff changeset
1088 purple_signal_unregister(purple_network_get_handle(),
25401
75f72178e361 Fix 3 different race conditions in the win32 network management functionality.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24888
diff changeset
1089 "network-configuration-changed");
26050
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
1090
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
1091 if (stun_ip)
ae3d25465d0f Run an asynchronous DNS lookup for the STUN server IP (to set as a property
Marcus Lundblad <ml@update.uu.se>
parents: 24888
diff changeset
1092 g_free(stun_ip);
27108
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
1093
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
1094 g_hash_table_destroy(upnp_port_mappings);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
1095 g_hash_table_destroy(nat_pmp_port_mappings);
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
1096
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
1097 /* TODO: clean up remaining port mappings, note calling
38c4973b5222 Add a function to remove a port mapping (UPnP or NAT-PMP) given a file
Marcus Lundblad <ml@update.uu.se>
parents: 26885
diff changeset
1098 purple_upnp_remove_port_mapping from here doesn't quite work... */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1099 }