/pidgin/main: d45200b32287: Merged in rw_grim/pidgin/replace-nm-...

Gary Kramlich grim at reaperworld.com
Thu Dec 31 11:59:27 EST 2015


Changeset: d45200b32287ad51923be354761b2976c8ecf869
Author:	 Gary Kramlich <grim at reaperworld.com>
Date:	 2015-12-30 19:55 -0600
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/d45200b32287

Description:

Merged in rw_grim/pidgin/replace-nm-with-gio (pull request #4)

Replace nm with gio

diffstat:

 ChangeLog.API              |    1 +
 configure.ac               |   24 --
 libpurple/nat-pmp.c        |   11 +-
 libpurple/network.c        |  513 +--------------------------------------------
 libpurple/upnp.c           |   19 +-
 pidgin/gtkdialogs.c        |    8 -
 pidgin/win32/gtkwin32dep.c |   22 +-
 7 files changed, 26 insertions(+), 572 deletions(-)

diffs (truncated from 776 to 300 lines):

diff --git a/ChangeLog.API b/ChangeLog.API
--- a/ChangeLog.API
+++ b/ChangeLog.API
@@ -412,6 +412,7 @@ version 3.0.0 (??/??/????):
 		* _PurpleSoundEventID
 		* _XMLNodeType
 		* account-authorization-requested-with-message signal
+		* network-configuration-changed signal
 		* purple_account_add_buddies_with_invite
 		* purple_account_add_buddy_with_invite
 		* purple_account_set_current_error
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -1513,9 +1513,6 @@ dnl ####################################
 AC_ARG_ENABLE(dbus,
 	[AS_HELP_STRING([--disable-dbus], [disable D-Bus support])], ,
 	enable_dbus="$is_not_win32")
-AC_ARG_ENABLE(nm,
-	[AS_HELP_STRING([--disable-nm], [disable NetworkManager support (requires D-Bus)])],
-	enable_nm=$enableval, enable_nm="$is_not_win32")
 
 if test "x$enable_dbus" = "xyes" ; then
 	AC_CHECK_PROG(enable_dbus, dbus-binding-tool, yes, no)
@@ -1536,26 +1533,6 @@ Use --disable-dbus if you do not need D-
 	fi])
 fi
 
-dnl Check for NetworkManager.h; if we don't have it, oh well
-if test "x$enable_dbus" = "xyes" ; then
-	if test "x$enable_nm" = "xyes" ; then
-		PKG_CHECK_MODULES(NETWORKMANAGER, [NetworkManager >= 0.5.0], [
-			AC_SUBST(NETWORKMANAGER_CFLAGS)
-			AC_SUBST(NETWORKMANAGER_LIBS)
-			AC_DEFINE(HAVE_NETWORKMANAGER, 1, [Define if we have NetworkManager.])
-		], [
-			enable_nm=no
-			if test "x$force_deps" = "xyes" ; then
-				AC_MSG_ERROR([
-NetworkManager development headers not found.
-Use --disable-nm if you do not need NetworkManager support.
-])
-			fi])
-	fi
-else
-	enable_nm=no
-fi
-
 dnl #######################################################################
 dnl # Check for Unity and Messaging Menu
 dnl #######################################################################
@@ -2336,7 +2313,6 @@ if test "x$enable_dbus" = "xyes" ; then
 	eval eval echo D-Bus services directory...... : $DBUS_SERVICES_DIR
 fi
 echo Build with GNU Libidn......... : $enable_idn
-echo Build with NetworkManager..... : $enable_nm
 echo SSL Library/Libraries......... : $msg_ssl
 if test "x$SSL_CERTIFICATES_DIR" != "x" ; then
 	eval eval echo SSL CA certificates directory. : $SSL_CERTIFICATES_DIR
diff --git a/libpurple/nat-pmp.c b/libpurple/nat-pmp.c
--- a/libpurple/nat-pmp.c
+++ b/libpurple/nat-pmp.c
@@ -24,6 +24,8 @@
  * OF SUCH DAMAGE.
  */
 
+#include <gio/gio.h>
+
 #include "internal.h"
 #include "nat-pmp.h"
 #include "debug.h"
@@ -514,7 +516,7 @@ purple_pmp_destroy_map(PurplePmpType typ
 }
 
 static void
-purple_pmp_network_config_changed_cb(void *data)
+purple_pmp_network_config_changed_cb(GNetworkMonitor *monitor, gboolean avialable, gpointer data)
 {
 	pmp_info.status = PURPLE_PMP_STATUS_UNDISCOVERED;
 	g_free(pmp_info.publicip);
@@ -532,9 +534,10 @@ purple_pmp_get_handle(void)
 void
 purple_pmp_init()
 {
-	purple_signal_connect(purple_network_get_handle(), "network-configuration-changed",
-		  purple_pmp_get_handle(), PURPLE_CALLBACK(purple_pmp_network_config_changed_cb),
-		  GINT_TO_POINTER(0));
+	g_signal_connect(g_network_monitor_get_default(),
+	                 "network-changed",
+	                 G_CALLBACK(purple_pmp_network_config_changed_cb),
+	                 NULL);
 }
 #else /* #ifdef NET_RT_DUMP */
 char *
diff --git a/libpurple/network.c b/libpurple/network.c
--- a/libpurple/network.c
+++ b/libpurple/network.c
@@ -63,38 +63,6 @@
 #  define HX_SIZE_OF_IFREQ(a) sizeof(a)
 #endif
 
-#ifdef HAVE_NETWORKMANAGER
-#include <dbus/dbus-glib.h>
-#include <NetworkManager.h>
-
-#if !defined(NM_CHECK_VERSION)
-#define NM_CHECK_VERSION(x,y,z) 0
-#endif
-
-static DBusGConnection *nm_conn = NULL;
-static DBusGProxy *nm_proxy = NULL;
-static DBusGProxy *dbus_proxy = NULL;
-static NMState nm_state = NM_STATE_UNKNOWN;
-static gboolean have_nm_state = FALSE;
-
-#elif defined _WIN32
-static int current_network_count;
-
-/* Mutex for the other global vars */
-#if GLIB_CHECK_VERSION(2, 32, 0)
-static GMutex mutex;
-#else
-static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
-#endif
-
-static gboolean network_initialized = FALSE;
-static HANDLE network_change_handle = NULL;
-static int (WSAAPI *MyWSANSPIoctl) (
-		HANDLE hLookup, DWORD dwControlCode, LPVOID lpvInBuffer,
-		DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer,
-		LPDWORD lpcbBytesReturned, LPWSACOMPLETION lpCompletion) = NULL;
-#endif
-
 struct _PurpleNetworkListenData {
 	int listenfd;
 	int socket_type;
@@ -106,13 +74,7 @@ struct _PurpleNetworkListenData {
 	int timer;
 };
 
-#ifdef HAVE_NETWORKMANAGER
-static NMState nm_get_network_state(void);
-#endif
-
-#if defined(HAVE_NETWORKMANAGER) || defined(_WIN32)
-static gboolean force_online;
-#endif
+static gboolean force_online = FALSE;
 
 /* Cached IP addresses for STUN and TURN servers (set globally in prefs) */
 static gchar *stun_ip = NULL;
@@ -592,391 +554,22 @@ purple_network_get_port_from_fd(int fd)
 	return ntohs(addr.sin_port);
 }
 
-#ifdef _WIN32
-#ifndef NS_NLA
-#define NS_NLA 15
-#endif
-static gint
-wpurple_get_connected_network_count(void)
-{
-	gint net_cnt = 0;
-
-	WSAQUERYSET qs;
-	HANDLE h;
-	gint retval;
-	int errorid;
-
-	memset(&qs, 0, sizeof(WSAQUERYSET));
-	qs.dwSize = sizeof(WSAQUERYSET);
-	qs.dwNameSpace = NS_NLA;
-
-	retval = WSALookupServiceBegin(&qs, LUP_RETURN_ALL, &h);
-	if (retval != ERROR_SUCCESS) {
-		gchar *msg;
-		errorid = WSAGetLastError();
-		msg = g_win32_error_message(errorid);
-		purple_debug_warning("network", "Couldn't retrieve NLA SP lookup handle. "
-						"NLA service is probably not running. Message: %s (%d).\n",
-						msg, errorid);
-		g_free(msg);
-
-		return -1;
-	} else {
-		char buf[4096];
-		WSAQUERYSET *res = (LPWSAQUERYSET) buf;
-		DWORD size = sizeof(buf);
-		while ((retval = WSALookupServiceNext(h, 0, &size, res)) == ERROR_SUCCESS) {
-			net_cnt++;
-			purple_debug_info("network", "found network '%s'\n",
-					res->lpszServiceInstanceName ? res->lpszServiceInstanceName : "(NULL)");
-			size = sizeof(buf);
-		}
-
-		errorid = WSAGetLastError();
-		if (!(errorid == WSA_E_NO_MORE || errorid == WSAENOMORE)) {
-			gchar *msg = g_win32_error_message(errorid);
-			purple_debug_error("network", "got unexpected NLA response %s (%d)\n", msg, errorid);
-			g_free(msg);
-
-			net_cnt = -1;
-		}
-
-		retval = WSALookupServiceEnd(h);
-	}
-
-	return net_cnt;
-
-}
-
-static gboolean wpurple_network_change_thread_cb(gpointer data)
-{
-	gint new_count;
-	PurpleConnectionUiOps *ui_ops = purple_connections_get_ui_ops();
-
-	new_count = wpurple_get_connected_network_count();
-
-	if (new_count < 0)
-		return FALSE;
-
-	purple_debug_info("network", "Received Network Change Notification. Current network count is %d, previous count was %d.\n", new_count, current_network_count);
-
-	purple_signal_emit(purple_network_get_handle(), "network-configuration-changed", NULL);
-
-	if (new_count > 0 && ui_ops != NULL && ui_ops->network_connected != NULL) {
-		ui_ops->network_connected();
-	} else if (new_count == 0 && current_network_count > 0 &&
-			   ui_ops != NULL && ui_ops->network_disconnected != NULL) {
-		ui_ops->network_disconnected();
-	}
-
-	current_network_count = new_count;
-
-	return FALSE;
-}
-
-static gboolean _print_debug_msg(gpointer data) {
-	gchar *msg = data;
-	purple_debug_warning("network", "%s", msg);
-	g_free(msg);
-	return FALSE;
-}
-
-static gpointer wpurple_network_change_thread(gpointer data)
-{
-	WSAQUERYSET qs;
-	WSAEVENT *nla_event;
-	time_t last_trigger = time(NULL) - 31;
-	char buf[4096];
-	WSAQUERYSET *res = (LPWSAQUERYSET) buf;
-	DWORD size;
-
-	if ((nla_event = WSACreateEvent()) == WSA_INVALID_EVENT) {
-		int errorid = WSAGetLastError();
-		gchar *msg = g_win32_error_message(errorid);
-		purple_timeout_add(0, _print_debug_msg,
-						   g_strdup_printf("Couldn't create WSA event. "
-										   "Message: %s (%d).\n", msg, errorid));
-		g_free(msg);
-		g_thread_exit(NULL);
-		return NULL;
-	}
-
-	while (TRUE) {
-		int retval;
-		DWORD retLen = 0;
-		WSACOMPLETION completion;
-		WSAOVERLAPPED overlapped;
-
-#if GLIB_CHECK_VERSION(2, 32, 0)
-		g_mutex_lock(&mutex);
-#else
-		g_static_mutex_lock(&mutex);
-#endif
-		if (network_initialized == FALSE) {
-			/* purple_network_uninit has been called */
-			WSACloseEvent(nla_event);
-#if GLIB_CHECK_VERSION(2, 32, 0)
-			g_mutex_unlock(&mutex);
-#else
-			g_static_mutex_unlock(&mutex);
-#endif
-			g_thread_exit(NULL);
-			return NULL;
-		}
-
-		if (network_change_handle == NULL) {
-			memset(&qs, 0, sizeof(WSAQUERYSET));
-			qs.dwSize = sizeof(WSAQUERYSET);
-			qs.dwNameSpace = NS_NLA;
-			if (WSALookupServiceBegin(&qs, 0, &network_change_handle) == SOCKET_ERROR) {
-				int errorid = WSAGetLastError();
-				gchar *msg = g_win32_error_message(errorid);
-				purple_timeout_add(0, _print_debug_msg,
-								   g_strdup_printf("Couldn't retrieve NLA SP lookup handle. "
-												   "NLA service is probably not running. Message: %s (%d).\n",
-													msg, errorid));
-				g_free(msg);
-				WSACloseEvent(nla_event);



More information about the Commits mailing list