annotate libpurple/network.c @ 23849:2f588ade5236

Oops, missed a bit of that patch there. References #3590.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Tue, 19 Aug 2008 00:24:53 +0000
parents 91169093449d
children 785db7300ef2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15374
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: 19680
diff changeset
4 */
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 19680
diff changeset
5
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 19680
diff changeset
6 /* purple
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
8 * Purple is the legal property of its developers, whose names are too numerous
15374
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
19680
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19653
diff changeset
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
15374
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
23203
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 23045
diff changeset
30 #include <arpa/nameser.h>
15374
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"
15374
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"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51
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 * 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
54 * Mac OS X (and maybe others).
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 #ifdef _SIZEOF_ADDR_IFREQ
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 # 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
58 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 # 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
60 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61
22867
0bd86dae2734 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@wiktel.com>
parents: 22862
diff changeset
62 #ifdef HAVE_NETWORKMANAGER
22847
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
63 #include <dbus/dbus-glib.h>
22867
0bd86dae2734 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@wiktel.com>
parents: 22862
diff changeset
64 #include <NetworkManager.h>
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65
22847
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
66 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: 22577
diff changeset
67 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: 22577
diff changeset
68 static DBusGProxy *dbus_proxy = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 #elif defined _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 static int current_network_count;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
74 struct _PurpleNetworkListenData {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75 int listenfd;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76 int socket_type;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 gboolean retry;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78 gboolean adding;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
79 PurpleNetworkListenCallback cb;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 gpointer cb_data;
15441
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: 15374
diff changeset
81 UPnPMappingAddRemove *mapping_data;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83
22867
0bd86dae2734 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@wiktel.com>
parents: 22862
diff changeset
84 #ifdef HAVE_NETWORKMANAGER
22847
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
85 static NMState nm_get_network_state(void);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88 const unsigned char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
89 purple_network_ip_atoi(const char *ip)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91 static unsigned char ret[4];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92 gchar *delimiter = ".";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93 gchar **split;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
94 int i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
95
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
96 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
97
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98 split = g_strsplit(ip, delimiter, 4);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99 for (i = 0; split[i] != NULL; i++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100 ret[i] = atoi(split[i]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101 g_strfreev(split);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
103 /* i should always be 4 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104 if (i != 4)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
111 purple_network_set_public_ip(const char *ip)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 g_return_if_fail(ip != NULL);
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 /* XXX - Ensure the IP address is valid */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116
16427
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
117 purple_prefs_set_string("/purple/network/public_ip", ip);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118 }
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 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
121 purple_network_get_public_ip(void)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122 {
16427
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
123 return purple_prefs_get_string("/purple/network/public_ip");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
127 purple_network_get_local_system_ip(int fd)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
129 char buffer[1024];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130 static char ip[16];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131 char *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 struct ifconf ifc;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133 struct ifreq *ifr;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134 struct sockaddr_in *sinptr;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135 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
136 long unsigned int add;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
137 int source = fd;
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 if (fd < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 source = socket(PF_INET,SOCK_STREAM, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142 ifc.ifc_len = sizeof(buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143 ifc.ifc_req = (struct ifreq *)buffer;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144 ioctl(source, SIOCGIFCONF, &ifc);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146 if (fd < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
147 close(source);
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 tmp = buffer;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150 while (tmp < buffer + ifc.ifc_len)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
151 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152 ifr = (struct ifreq *)tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153 tmp += HX_SIZE_OF_IFREQ(*ifr);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155 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
156 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157 sinptr = (struct sockaddr_in *)&ifr->ifr_addr;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 if (sinptr->sin_addr.s_addr != lhost)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160 add = ntohl(sinptr->sin_addr.s_addr);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161 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
162 ((add >> 24) & 255),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163 ((add >> 16) & 255),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
164 ((add >> 8) & 255),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165 add & 255);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167 return ip;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
168 }
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 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
171
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
172 return "0.0.0.0";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
176 purple_network_get_my_ip(int fd)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178 const char *ip = NULL;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
179 PurpleStunNatDiscovery *stun;
15374
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 /* Check if the user specified an IP manually */
16427
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
182 if (!purple_prefs_get_bool("/purple/network/auto_ip")) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
183 ip = purple_network_get_public_ip();
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184 /* Make sure the IP address entered by the user is valid */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
185 if ((ip != NULL) && (purple_network_ip_atoi(ip) != NULL))
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
186 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
187 } 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
188 /* 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
189 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
190 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
191 return stun->publicip;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
192
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
193 /* 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
194 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
195 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
196 return ip;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
197
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
198 /* 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
199 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
200 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
201 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
202 }
15647
552be3958d6a Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15441
diff changeset
203
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
204 /* Just fetch the IP of the local system */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
205 return purple_network_get_local_system_ip(fd);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
206 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
207
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
208
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
209 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
210 purple_network_set_upnp_port_mapping_cb(gboolean success, gpointer data)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
211 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
212 PurpleNetworkListenData *listen_data;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
213
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
214 listen_data = data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
215 /* 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
216 /* listen_data->pnp_data = NULL; */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
217
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
218 if (!success) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
219 purple_debug_info("network", "Couldn't create UPnP mapping\n");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
220 if (listen_data->retry) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
221 listen_data->retry = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
222 listen_data->adding = FALSE;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
223 listen_data->mapping_data = purple_upnp_remove_port_mapping(
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
224 purple_network_get_port_from_fd(listen_data->listenfd),
15441
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: 15374
diff changeset
225 (listen_data->socket_type == SOCK_STREAM) ? "TCP" : "UDP",
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
226 purple_network_set_upnp_port_mapping_cb, listen_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
227 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
228 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
229 } else if (!listen_data->adding) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
230 /* 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
231 * Try to add it again */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
232 listen_data->adding = TRUE;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
233 listen_data->mapping_data = purple_upnp_set_port_mapping(
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
234 purple_network_get_port_from_fd(listen_data->listenfd),
15441
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: 15374
diff changeset
235 (listen_data->socket_type == SOCK_STREAM) ? "TCP" : "UDP",
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
236 purple_network_set_upnp_port_mapping_cb, listen_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
237 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
238 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
239
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
240 if (listen_data->cb)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
241 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
242
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
243 /* Clear the UPnP mapping data, since it's complete and purple_netweork_listen_cancel() will try to cancel
15441
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: 15374
diff changeset
244 * 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: 15374
diff changeset
245 listen_data->mapping_data = NULL;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
246 purple_network_listen_cancel(listen_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
247 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
248
15856
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: 15823
diff changeset
249 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: 15823
diff changeset
250 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: 15823
diff changeset
251 {
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: 15823
diff changeset
252 PurpleNetworkListenData *listen_data;
15902
3a45be1c3281 Whitespace and make sure stuff is #defined to an actual value.
Mark Doliner <mark@kingant.net>
parents: 15895
diff changeset
253
15856
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: 15823
diff changeset
254 listen_data = data;
15902
3a45be1c3281 Whitespace and make sure stuff is #defined to an actual value.
Mark Doliner <mark@kingant.net>
parents: 15895
diff changeset
255
15856
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: 15823
diff changeset
256 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: 15823
diff changeset
257 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: 15823
diff changeset
258
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: 15823
diff changeset
259 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: 15823
diff changeset
260
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: 15823
diff changeset
261 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: 15823
diff changeset
262 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
263
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
264 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
265 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
266 {
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
267 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
268 }
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
269
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
270 static PurpleNetworkListenData *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
271 purple_network_do_listen(unsigned short port, int socket_type, PurpleNetworkListenCallback cb, gpointer cb_data)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
272 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
273 int listenfd = -1;
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
274 int flags;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
275 const int on = 1;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
276 PurpleNetworkListenData *listen_data;
15647
552be3958d6a Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15441
diff changeset
277 unsigned short actual_port;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
278 #ifdef HAVE_GETADDRINFO
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
279 int errnum;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
280 struct addrinfo hints, *res, *next;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
281 char serv[6];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
282
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
283 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
284 * 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
285 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
286 snprintf(serv, sizeof(serv), "%hu", port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
287 memset(&hints, 0, sizeof(struct addrinfo));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
288 hints.ai_flags = AI_PASSIVE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
289 hints.ai_family = AF_UNSPEC;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
290 hints.ai_socktype = socket_type;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
291 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
292 if (errnum != 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
293 #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
294 purple_debug_warning("network", "getaddrinfo: %s\n", purple_gai_strerror(errnum));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
295 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
296 purple_debug_warning("network", "getaddrinfo: system error: %s\n", g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
297 #else
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
298 purple_debug_warning("network", "getaddrinfo: Error Code = %d\n", errnum);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
299 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
300 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
301 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
302
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
303 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
304 * 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
305 * one of them.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
306 * XXX - Try IPv6 addresses first?
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
307 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
308 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
309 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
310 if (listenfd < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
311 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
312 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
313 purple_debug_warning("network", "setsockopt: %s\n", g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
314 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
315 break; /* success */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
316 /* 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
317 using a new socket each time */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
318 close(listenfd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
319 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
320
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
321 freeaddrinfo(res);
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 if (next == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
324 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
325 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
326 struct sockaddr_in sockin;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
327
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
328 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
329 purple_debug_warning("network", "socket: %s\n", g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
330 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
331 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
332
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
333 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
334 purple_debug_warning("network", "setsockopt: %s\n", g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
335
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
336 memset(&sockin, 0, sizeof(struct sockaddr_in));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
337 sockin.sin_family = PF_INET;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
338 sockin.sin_port = htons(port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
339
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
340 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
341 purple_debug_warning("network", "bind: %s\n", g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
342 close(listenfd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
343 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
344 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
345 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
346
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
347 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
348 purple_debug_warning("network", "listen: %s\n", g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
349 close(listenfd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
350 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
351 }
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
352 flags = fcntl(listenfd, F_GETFL);
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
353 fcntl(listenfd, F_SETFL, flags | O_NONBLOCK);
23774
91169093449d More leaks of fds to client processes.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23203
diff changeset
354 #ifndef _WIN32
91169093449d More leaks of fds to client processes.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23203
diff changeset
355 fcntl(listenfd, F_SETFD, FD_CLOEXEC);
91169093449d More leaks of fds to client processes.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23203
diff changeset
356 #endif
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
357 actual_port = purple_network_get_port_from_fd(listenfd);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
358
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
359 purple_debug_info("network", "Listening on port: %hu\n", actual_port);
15902
3a45be1c3281 Whitespace and make sure stuff is #defined to an actual value.
Mark Doliner <mark@kingant.net>
parents: 15895
diff changeset
360
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
361 listen_data = g_new0(PurpleNetworkListenData, 1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
362 listen_data->listenfd = listenfd;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
363 listen_data->adding = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
364 listen_data->retry = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
365 listen_data->cb = cb;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
366 listen_data->cb_data = cb_data;
19643
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
367 listen_data->socket_type = socket_type;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
368
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
369 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
370 {
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
371 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
372 /* 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
373 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
374 }
15647
552be3958d6a Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15441
diff changeset
375 /* 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
376 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: 15902
diff changeset
377 actual_port, actual_port, PURPLE_PMP_LIFETIME))
15856
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: 15823
diff changeset
378 {
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
379 purple_debug_info("network", "Created NAT-PMP mapping on port %i\n", actual_port);
15856
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: 15823
diff changeset
380 /* 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: 15823
diff changeset
381 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: 15823
diff changeset
382 }
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: 15823
diff changeset
383 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: 15823
diff changeset
384 {
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: 15823
diff changeset
385 /* 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: 15823
diff changeset
386 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: 15823
diff changeset
387 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: 15823
diff changeset
388 (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: 15823
diff changeset
389 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: 15823
diff changeset
390 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
391
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
392 return listen_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
393 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
394
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
395 PurpleNetworkListenData *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
396 purple_network_listen(unsigned short port, int socket_type,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
397 PurpleNetworkListenCallback cb, gpointer cb_data)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
398 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
399 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
400
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
401 return purple_network_do_listen(port, socket_type, cb, cb_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
402 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
403
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
404 PurpleNetworkListenData *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
405 purple_network_listen_range(unsigned short start, unsigned short end,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
406 int socket_type, PurpleNetworkListenCallback cb, gpointer cb_data)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
407 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
408 PurpleNetworkListenData *ret = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
409
16427
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
410 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
411 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
412 end = purple_prefs_get_int("/purple/network/ports_range_end");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
413 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
414 if (end < start)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
415 end = start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
416 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
417
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
418 for (; start <= end; start++) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
419 ret = purple_network_do_listen(start, socket_type, cb, cb_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
420 if (ret != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
421 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
422 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
423
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
424 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
425 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
426
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
427 void purple_network_listen_cancel(PurpleNetworkListenData *listen_data)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
428 {
15441
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: 15374
diff changeset
429 if (listen_data->mapping_data != NULL)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
430 purple_upnp_cancel_port_mapping(listen_data->mapping_data);
15441
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: 15374
diff changeset
431
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
432 g_free(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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
435 unsigned short
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
436 purple_network_get_port_from_fd(int fd)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
437 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
438 struct sockaddr_in addr;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
439 socklen_t len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
440
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
441 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
442
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
443 len = sizeof(addr);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
444 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
445 purple_debug_warning("network", "getsockname: %s\n", g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
446 return 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
447 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
448
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
449 return ntohs(addr.sin_port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
450 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
451
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
452 #ifdef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
453 #ifndef NS_NLA
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
454 #define NS_NLA 15
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
455 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
456 static gint
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
457 wpurple_get_connected_network_count(void)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
458 {
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
459 gint net_cnt = 0;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
460
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
461 WSAQUERYSET qs;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
462 HANDLE h;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
463 gint retval;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
464 int errorid;
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 memset(&qs, 0, sizeof(WSAQUERYSET));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
467 qs.dwSize = sizeof(WSAQUERYSET);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
468 qs.dwNameSpace = NS_NLA;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
469
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
470 retval = WSALookupServiceBegin(&qs, LUP_RETURN_ALL, &h);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
471 if (retval != ERROR_SUCCESS) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
472 gchar *msg;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
473 errorid = WSAGetLastError();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
474 msg = g_win32_error_message(errorid);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
475 purple_debug_warning("network", "Couldn't retrieve NLA SP lookup handle. "
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
476 "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
477 msg, errorid);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
478 g_free(msg);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
479
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
480 return -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
481 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
482 char buf[4096];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
483 WSAQUERYSET *res = (LPWSAQUERYSET) buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
484 DWORD size = sizeof(buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
485 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
486 net_cnt++;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
487 purple_debug_info("network", "found network '%s'\n",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
488 res->lpszServiceInstanceName ? res->lpszServiceInstanceName : "(NULL)");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
489 size = sizeof(buf);
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 errorid = WSAGetLastError();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
493 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
494 gchar *msg = g_win32_error_message(errorid);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
495 purple_debug_error("network", "got unexpected NLA response %s (%d)\n", msg, errorid);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
496 g_free(msg);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
497
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
498 net_cnt = -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
499 }
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 retval = WSALookupServiceEnd(h);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
502 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
503
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
504 return net_cnt;
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 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
507
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
508 static gboolean wpurple_network_change_thread_cb(gpointer data)
15374
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 gint new_count;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
511 PurpleConnectionUiOps *ui_ops = purple_connections_get_ui_ops();
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
512
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
513 new_count = wpurple_get_connected_network_count();
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
514
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
515 if (new_count < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
516 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
517
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
518 purple_debug_info("network", "Received Network Change Notification. Current network count is %d, previous count was %d.\n", new_count, current_network_count);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
519
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
520 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
521
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
522 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
523 ui_ops->network_connected();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
524 } 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
525 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
526 ui_ops->network_disconnected();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
527 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
528
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
529 current_network_count = new_count;
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 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
532 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
533
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
534 static gpointer wpurple_network_change_thread(gpointer data)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
535 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
536 HANDLE h;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
537 WSAQUERYSET qs;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
538 time_t last_trigger = time(NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
539
18401
3c6bc8785af9 Fix up some linkage to compile on Visual Studio. He claims this doesn't
Nick Hebner <hebnern@gmail.com>
parents: 17763
diff changeset
540 int (WSAAPI *MyWSANSPIoctl) (
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
541 HANDLE hLookup, DWORD dwControlCode, LPVOID lpvInBuffer,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
542 DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
543 LPDWORD lpcbBytesReturned, LPWSACOMPLETION lpCompletion) = NULL;
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
544
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
545 if (!(MyWSANSPIoctl = (void*) wpurple_find_and_loadproc("ws2_32.dll", "WSANSPIoctl"))) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
546 g_thread_exit(NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
547 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
548 }
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 while (TRUE) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
551 int retval;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
552 DWORD retLen = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
553
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
554 memset(&qs, 0, sizeof(WSAQUERYSET));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
555 qs.dwSize = sizeof(WSAQUERYSET);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
556 qs.dwNameSpace = NS_NLA;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
557 if (WSALookupServiceBegin(&qs, 0, &h) == SOCKET_ERROR) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
558 int errorid = WSAGetLastError();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
559 gchar *msg = g_win32_error_message(errorid);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
560 purple_debug_warning("network", "Couldn't retrieve NLA SP lookup handle. "
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
561 "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
562 msg, errorid);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
563 g_free(msg);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
564 g_thread_exit(NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
565 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
566 }
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 /* Make sure at least 30 seconds have elapsed since the last
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
569 * notification so we don't peg the cpu if this keeps changing. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
570 if ((time(NULL) - last_trigger) < 30)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
571 Sleep(30000);
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 last_trigger = time(NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
574
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
575 /* This will block until there is a network change */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
576 if (MyWSANSPIoctl(h, SIO_NSP_NOTIFY_CHANGE, NULL, 0, NULL, 0, &retLen, NULL) == SOCKET_ERROR) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
577 int errorid = WSAGetLastError();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
578 gchar *msg = g_win32_error_message(errorid);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
579 purple_debug_warning("network", "Unable to wait for changes. Message: %s (%d).\n",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
580 msg, errorid);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
581 g_free(msg);
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
584 retval = WSALookupServiceEnd(h);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
585
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
586 purple_timeout_add(0, wpurple_network_change_thread_cb, NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
587
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
588 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
589
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
590 g_thread_exit(NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
591 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
592 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
593 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
594
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
595 gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
596 purple_network_is_available(void)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
597 {
22867
0bd86dae2734 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@wiktel.com>
parents: 22862
diff changeset
598 #ifdef HAVE_NETWORKMANAGER
22849
e6674df4cbf1 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@wiktel.com>
parents: 22848
diff changeset
599 NMState state = nm_get_network_state();
e6674df4cbf1 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@wiktel.com>
parents: 22848
diff changeset
600 if (state == NM_STATE_UNKNOWN)
22855
6421d275c85e Fix some whitespace as noticed by QuLogic.
Richard Laager <rlaager@wiktel.com>
parents: 22849
diff changeset
601 {
22849
e6674df4cbf1 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@wiktel.com>
parents: 22848
diff changeset
602 purple_debug_warning("network", "NetworkManager not active. Assuming connection exists.\n");
22855
6421d275c85e Fix some whitespace as noticed by QuLogic.
Richard Laager <rlaager@wiktel.com>
parents: 22849
diff changeset
603 return TRUE;
22849
e6674df4cbf1 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@wiktel.com>
parents: 22848
diff changeset
604 }
e6674df4cbf1 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@wiktel.com>
parents: 22848
diff changeset
605 else if (state == NM_STATE_CONNECTED)
22848
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: 22847
diff changeset
606 return TRUE;
22849
e6674df4cbf1 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@wiktel.com>
parents: 22848
diff changeset
607
e6674df4cbf1 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@wiktel.com>
parents: 22848
diff changeset
608 return FALSE;
e6674df4cbf1 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@wiktel.com>
parents: 22848
diff changeset
609
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
610 #elif defined _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
611 return (current_network_count > 0);
22849
e6674df4cbf1 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@wiktel.com>
parents: 22848
diff changeset
612 #else
e6674df4cbf1 Changes suggested by QuLogic to fix my broken changes to the NetworkManager
Richard Laager <rlaager@wiktel.com>
parents: 22848
diff changeset
613 return TRUE;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
614 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
615 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
616
22867
0bd86dae2734 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@wiktel.com>
parents: 22862
diff changeset
617 #ifdef HAVE_NETWORKMANAGER
22577
0e426ad6cc87 Make some more things static
Stu Tomlinson <stu@nosnilmot.com>
parents: 21862
diff changeset
618 static void
22847
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
619 nm_update_state(NMState state)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
620 {
22847
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
621 static NMState prev = NM_STATE_UNKNOWN;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
622 PurpleConnectionUiOps *ui_ops = purple_connections_get_ui_ops();
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
623
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
624 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
625
22847
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
626 switch(state)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
627 {
22847
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
628 case NM_STATE_CONNECTED:
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
629 /* 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: 22577
diff changeset
630 res_init();
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
631 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: 22577
diff changeset
632 ui_ops->network_connected();
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
633 prev = state;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
634 break;
22847
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
635 case NM_STATE_ASLEEP:
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
636 case NM_STATE_CONNECTING:
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
637 case NM_STATE_DISCONNECTED:
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
638 if (prev != NM_STATE_CONNECTED)
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
639 break;
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
640 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: 22577
diff changeset
641 ui_ops->network_disconnected();
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
642 prev = state;
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
643 break;
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
644 case NM_STATE_UNKNOWN:
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
645 default:
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
646 break;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
647 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
648 }
22847
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
649
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
650 static void
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
651 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: 22577
diff changeset
652 {
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
653 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: 22577
diff changeset
654 nm_update_state(state);
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
655 }
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
656
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
657 static NMState
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
658 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: 22577
diff changeset
659 {
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
660 GError *err = NULL;
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
661 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: 22577
diff changeset
662
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
663 if (!nm_proxy)
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
664 return NM_STATE_UNKNOWN;
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
665
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
666 if (!dbus_g_proxy_call(nm_proxy, "state", &err, G_TYPE_INVALID, G_TYPE_UINT, &state, G_TYPE_INVALID)) {
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
667 /* XXX: Print an error? */
23045
Stu Tomlinson <stu@nosnilmot.com>
parents: 22867
diff changeset
668 g_error_free(err);
22847
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
669 return NM_STATE_UNKNOWN;
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
670 }
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
671
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
672 return state;
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
673 }
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
674
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
675 static void
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
676 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: 22577
diff changeset
677 {
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
678 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: 22577
diff changeset
679 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: 22577
diff changeset
680 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: 22577
diff changeset
681
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
682 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: 22577
diff changeset
683 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: 22577
diff changeset
684 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: 22577
diff changeset
685 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: 22577
diff changeset
686 } 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: 22577
diff changeset
687 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: 22577
diff changeset
688 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: 22577
diff changeset
689 }
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
690 }
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
691 }
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
692
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
693 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
694
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
695 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
696 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
697 {
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
698 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
699
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
700 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
701 }
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
702
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
703 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
704 purple_network_init(void)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
705 {
22867
0bd86dae2734 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@wiktel.com>
parents: 22862
diff changeset
706 #ifdef HAVE_NETWORKMANAGER
22847
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
707 GError *error = NULL;
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
708 #endif
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
709 #ifdef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
710 GError *err = NULL;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
711 gint cnt = wpurple_get_connected_network_count();
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
712
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
713 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
714 current_network_count = 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
715 /* Don't listen for network changes if we can't tell anyway */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
716 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
717 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
718 current_network_count = cnt;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
719 if (!g_thread_create(wpurple_network_change_thread, NULL, FALSE, &err))
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
720 purple_debug_error("network", "Couldn't create Network Monitor thread: %s\n", err ? err->message : "");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
721 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
722 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
723
16427
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
724 purple_prefs_add_none ("/purple/network");
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
725 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
726 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
727 purple_prefs_add_bool ("/purple/network/map_ports", TRUE);
16427
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
728 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
729 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
730 purple_prefs_add_int ("/purple/network/ports_range_end", 2048);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
731
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
732 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
733 purple_upnp_discover(NULL, NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
734
22867
0bd86dae2734 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@wiktel.com>
parents: 22862
diff changeset
735 #ifdef HAVE_NETWORKMANAGER
22847
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
736 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: 22577
diff changeset
737 if (!nm_conn) {
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
738 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: 22577
diff changeset
739 } else {
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
740 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: 22577
diff changeset
741 NM_DBUS_SERVICE,
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
742 NM_DBUS_PATH,
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
743 NM_DBUS_INTERFACE);
22862
f5d39c44465a Modify the NetworkManager support to use "StateChange" directly, instead of
Richard Laager <rlaager@wiktel.com>
parents: 22855
diff changeset
744 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: 22855
diff changeset
745 dbus_g_proxy_connect_signal(nm_proxy, "StateChange",
22847
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
746 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: 22577
diff changeset
747
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
748 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: 22577
diff changeset
749 DBUS_SERVICE_DBUS,
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
750 DBUS_PATH_DBUS,
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
751 DBUS_INTERFACE_DBUS);
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
752 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: 22577
diff changeset
753 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: 22577
diff changeset
754 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: 22577
diff changeset
755 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
756 #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
757
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
758 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
759 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
760
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
761 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
762 purple_upnp_init();
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
763 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
764
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
765 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15647
diff changeset
766 purple_network_uninit(void)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
767 {
22867
0bd86dae2734 Use pkg-config to detect NetworkManager. Also, fail if it isn't present,
Richard Laager <rlaager@wiktel.com>
parents: 22862
diff changeset
768 #ifdef HAVE_NETWORKMANAGER
22847
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
769 if (nm_proxy) {
22862
f5d39c44465a Modify the NetworkManager support to use "StateChange" directly, instead of
Richard Laager <rlaager@wiktel.com>
parents: 22855
diff changeset
770 dbus_g_proxy_disconnect_signal(nm_proxy, "StateChange", G_CALLBACK(nm_state_change_cb), NULL);
22847
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
771 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: 22577
diff changeset
772 }
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
773 if (dbus_proxy) {
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
774 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: 22577
diff changeset
775 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: 22577
diff changeset
776 }
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
777 if (nm_conn)
790c606ff8a9 A patch from QuLogic to replace the libnm_glib calls with straight DBus
Richard Laager <rlaager@wiktel.com>
parents: 22577
diff changeset
778 dbus_g_connection_unref(nm_conn);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
779 #endif
21067
96929e7acb86 Make purple_xfers_uninit, purple_network_uninit, and purple_plugins_uninit
Etan Reisner <pidgin@unreliablesource.net>
parents: 20347
diff changeset
780
96929e7acb86 Make purple_xfers_uninit, purple_network_uninit, and purple_plugins_uninit
Etan Reisner <pidgin@unreliablesource.net>
parents: 20347
diff changeset
781 purple_signal_unregister(purple_network_get_handle(),
96929e7acb86 Make purple_xfers_uninit, purple_network_uninit, and purple_plugins_uninit
Etan Reisner <pidgin@unreliablesource.net>
parents: 20347
diff changeset
782 "network-configuration-changed");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
783 }