From a5dd14c305dd7bc386ca5abb3aa65e7630892090 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 27 Apr 2005 18:05:16 +0000 Subject: [PATCH] 2005-04-27 Dan Williams * Merge the applet and the info-daemon, and move the converged applet under gnome/applet * Move libnm_glib to gnome/libnm_glib * Convert most dbus calls between the applet, info-daemon, and NM into async calls * Fix a few things valgrind noticed * Make NM broadcast state more reliably git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@586 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 10 + Makefile.am | 2 +- NetworkManager.h | 36 +- configure.in | 17 +- gnome/Makefile.am | 1 + gnome/applet/Makefile.am | 89 + gnome/applet/applet-dbus-devices.c | 1476 ++++++++++++ gnome/applet/applet-dbus-devices.h | 50 + .../applet/applet-dbus-info.c | 561 ++--- .../applet/applet-dbus-info.h | 20 +- gnome/applet/applet-dbus-vpn.c | 504 ++++ gnome/applet/applet-dbus-vpn.h | 39 + gnome/applet/applet-dbus.c | 755 ++++++ gnome/applet/applet-dbus.h | 66 + .../applet/applet.c | 1026 ++++---- gnome/applet/applet.h | 158 ++ {panel-applet => gnome/applet}/eggtrayicon.c | 0 {panel-applet => gnome/applet}/eggtrayicon.h | 0 .../applet}/gtkcellrendererprogress.c | 0 .../applet}/gtkcellrendererprogress.h | 0 {panel-applet => gnome/applet}/gtkcellview.c | 0 {panel-applet => gnome/applet}/gtkcellview.h | 0 .../applet}/icons/Makefile.am | 0 .../applet}/icons/nm-adhoc.png | Bin .../applet}/icons/nm-connecting01.png | Bin .../applet}/icons/nm-connecting02.png | Bin .../applet}/icons/nm-connecting03.png | Bin .../applet}/icons/nm-connecting04.png | Bin .../applet}/icons/nm-connecting05.png | Bin .../applet}/icons/nm-connecting06.png | Bin .../applet}/icons/nm-connecting07.png | Bin .../applet}/icons/nm-connecting08.png | Bin .../applet}/icons/nm-connecting09.png | Bin .../applet}/icons/nm-connecting10.png | Bin .../applet}/icons/nm-connecting11.png | Bin .../applet}/icons/nm-detect01.png | Bin .../applet}/icons/nm-detect02.png | Bin .../applet}/icons/nm-detect03.png | Bin .../applet}/icons/nm-detect04.png | Bin .../applet}/icons/nm-detect05.png | Bin .../applet}/icons/nm-detect06.png | Bin .../applet}/icons/nm-detect07.png | Bin .../applet}/icons/nm-detect08.png | Bin .../applet}/icons/nm-detect09.png | Bin .../applet}/icons/nm-detect10.png | Bin .../applet}/icons/nm-detect11.png | Bin .../applet}/icons/nm-detect12.png | Bin .../applet}/icons/nm-detect13.png | Bin .../applet}/icons/nm-detect14.png | Bin .../applet}/icons/nm-detect15.png | Bin .../applet}/icons/nm-detect16.png | Bin .../applet}/icons/nm-device-wired.png | Bin .../applet}/icons/nm-device-wireless.png | Bin .../applet}/icons/nm-no-connection.png | Bin .../applet}/icons/nm-signal-00.png | Bin .../applet}/icons/nm-signal-100.png | Bin .../applet}/icons/nm-signal-25.png | Bin .../applet}/icons/nm-signal-50.png | Bin .../applet}/icons/nm-signal-75.png | Bin .../applet}/icons/nm-vpn-lock.png | Bin {info-daemon => gnome/applet}/keyring.png | Bin gnome/applet/main.c | 71 + .../menu-info.c => gnome/applet/menu-items.c | 30 +- .../menu-info.h => gnome/applet/menu-items.h | 6 +- .../applet/nm-applet.conf | 0 gnome/applet/nm-device.c | 493 ++++ gnome/applet/nm-device.h | 79 + .../applet/other-network-dialog.c | 83 +- .../applet/other-network-dialog.h | 6 +- gnome/applet/passphrase-dialog.c | 430 ++++ .../applet/passphrase-dialog.h | 42 +- .../applet/vpn-connection.c | 10 +- .../applet/vpn-connection.h | 14 +- .../applet/vpn-password-dialog.c | 4 +- .../applet/vpn-password-dialog.h | 6 +- .../applet}/wireless-applet.glade | 237 ++ gnome/applet/wireless-network.c | 195 ++ gnome/applet/wireless-network.h | 47 + {libnm_glib => gnome/libnm_glib}/.cvsignore | 0 {libnm_glib => gnome/libnm_glib}/Makefile.am | 0 {libnm_glib => gnome/libnm_glib}/libnm_glib.c | 150 +- {libnm_glib => gnome/libnm_glib}/libnm_glib.h | 6 +- .../libnm_glib}/libnm_glib.pc.in | 0 info-daemon/.cvsignore | 6 - info-daemon/Makefile.am | 57 - info-daemon/NetworkManagerInfo.c | 336 --- info-daemon/NetworkManagerInfo.h | 63 - info-daemon/NetworkManagerInfoDbus.h | 48 - .../NetworkManagerInfoNetworksDialog.c | 86 - .../NetworkManagerInfoNetworksDialog.h | 30 - .../NetworkManagerInfoPassphraseDialog.c | 352 --- info-daemon/NetworkManagerInfoVPN.c | 188 -- info-daemon/NetworkManagerInfoVPN.h | 34 - info-daemon/networks.glade | 226 -- info-daemon/passphrase.glade | 243 -- panel-applet/.cvsignore | 3 - panel-applet/Makefile.am | 84 - panel-applet/NMWirelessApplet.h | 194 -- panel-applet/NMWirelessApplet.server.in | 36 - panel-applet/NMWirelessApplet.xml | 8 - panel-applet/NMWirelessAppletDbus.c | 2102 ----------------- panel-applet/NMWirelessAppletDbus.h | 65 - panel-applet/essid.glade | 408 ---- panel-applet/icons/.cvsignore | 2 - src/Makefile.am | 2 - src/NetworkManager.c | 18 +- src/NetworkManagerAPList.c | 121 +- src/NetworkManagerAPList.h | 7 +- src/NetworkManagerDbus.c | 880 ++++--- src/NetworkManagerDbus.h | 21 +- src/NetworkManagerDevice.c | 130 +- src/NetworkManagerDevice.h | 8 +- src/NetworkManagerMain.h | 8 +- src/NetworkManagerPolicy.c | 95 +- src/NetworkManagerPolicy.h | 1 + src/nm-dbus-device.c | 106 +- src/nm-dbus-net.c | 40 + src/nm-dbus-nm.c | 138 +- src/vpn-manager/nm-dbus-vpn.c | 251 +- src/vpn-manager/nm-dbus-vpn.h | 4 +- src/vpn-manager/nm-vpn-manager.c | 118 +- src/vpn-manager/nm-vpn-manager.h | 1 + src/vpn-manager/nm-vpn-service.c | 24 +- src/vpn-manager/nm-vpn-service.h | 23 +- test/Makefile.am | 4 +- test/libnm_glib_test.c | 6 +- test/nmtest.c | 25 +- vpn-daemons/vpnc/nm-vpnc-service.name | 1 + 128 files changed, 6764 insertions(+), 6558 deletions(-) create mode 100644 gnome/Makefile.am create mode 100644 gnome/applet/Makefile.am create mode 100644 gnome/applet/applet-dbus-devices.c create mode 100644 gnome/applet/applet-dbus-devices.h rename info-daemon/NetworkManagerInfoDbus.c => gnome/applet/applet-dbus-info.c (54%) rename info-daemon/NetworkManagerInfoPassphraseDialog.h => gnome/applet/applet-dbus-info.h (56%) create mode 100644 gnome/applet/applet-dbus-vpn.c create mode 100644 gnome/applet/applet-dbus-vpn.h create mode 100644 gnome/applet/applet-dbus.c create mode 100644 gnome/applet/applet-dbus.h rename panel-applet/NMWirelessApplet.c => gnome/applet/applet.c (68%) create mode 100644 gnome/applet/applet.h rename {panel-applet => gnome/applet}/eggtrayicon.c (100%) rename {panel-applet => gnome/applet}/eggtrayicon.h (100%) rename {panel-applet => gnome/applet}/gtkcellrendererprogress.c (100%) rename {panel-applet => gnome/applet}/gtkcellrendererprogress.h (100%) rename {panel-applet => gnome/applet}/gtkcellview.c (100%) rename {panel-applet => gnome/applet}/gtkcellview.h (100%) rename {panel-applet => gnome/applet}/icons/Makefile.am (100%) rename {panel-applet => gnome/applet}/icons/nm-adhoc.png (100%) rename {panel-applet => gnome/applet}/icons/nm-connecting01.png (100%) rename {panel-applet => gnome/applet}/icons/nm-connecting02.png (100%) rename {panel-applet => gnome/applet}/icons/nm-connecting03.png (100%) rename {panel-applet => gnome/applet}/icons/nm-connecting04.png (100%) rename {panel-applet => gnome/applet}/icons/nm-connecting05.png (100%) rename {panel-applet => gnome/applet}/icons/nm-connecting06.png (100%) rename {panel-applet => gnome/applet}/icons/nm-connecting07.png (100%) rename {panel-applet => gnome/applet}/icons/nm-connecting08.png (100%) rename {panel-applet => gnome/applet}/icons/nm-connecting09.png (100%) rename {panel-applet => gnome/applet}/icons/nm-connecting10.png (100%) rename {panel-applet => gnome/applet}/icons/nm-connecting11.png (100%) rename {panel-applet => gnome/applet}/icons/nm-detect01.png (100%) rename {panel-applet => gnome/applet}/icons/nm-detect02.png (100%) rename {panel-applet => gnome/applet}/icons/nm-detect03.png (100%) rename {panel-applet => gnome/applet}/icons/nm-detect04.png (100%) rename {panel-applet => gnome/applet}/icons/nm-detect05.png (100%) rename {panel-applet => gnome/applet}/icons/nm-detect06.png (100%) rename {panel-applet => gnome/applet}/icons/nm-detect07.png (100%) rename {panel-applet => gnome/applet}/icons/nm-detect08.png (100%) rename {panel-applet => gnome/applet}/icons/nm-detect09.png (100%) rename {panel-applet => gnome/applet}/icons/nm-detect10.png (100%) rename {panel-applet => gnome/applet}/icons/nm-detect11.png (100%) rename {panel-applet => gnome/applet}/icons/nm-detect12.png (100%) rename {panel-applet => gnome/applet}/icons/nm-detect13.png (100%) rename {panel-applet => gnome/applet}/icons/nm-detect14.png (100%) rename {panel-applet => gnome/applet}/icons/nm-detect15.png (100%) rename {panel-applet => gnome/applet}/icons/nm-detect16.png (100%) rename {panel-applet => gnome/applet}/icons/nm-device-wired.png (100%) rename {panel-applet => gnome/applet}/icons/nm-device-wireless.png (100%) rename {panel-applet => gnome/applet}/icons/nm-no-connection.png (100%) rename {panel-applet => gnome/applet}/icons/nm-signal-00.png (100%) rename {panel-applet => gnome/applet}/icons/nm-signal-100.png (100%) rename {panel-applet => gnome/applet}/icons/nm-signal-25.png (100%) rename {panel-applet => gnome/applet}/icons/nm-signal-50.png (100%) rename {panel-applet => gnome/applet}/icons/nm-signal-75.png (100%) rename {panel-applet => gnome/applet}/icons/nm-vpn-lock.png (100%) rename {info-daemon => gnome/applet}/keyring.png (100%) create mode 100644 gnome/applet/main.c rename panel-applet/menu-info.c => gnome/applet/menu-items.c (90%) rename panel-applet/menu-info.h => gnome/applet/menu-items.h (96%) rename info-daemon/NetworkManagerInfo.conf => gnome/applet/nm-applet.conf (100%) create mode 100644 gnome/applet/nm-device.c create mode 100644 gnome/applet/nm-device.h rename panel-applet/NMWirelessAppletOtherNetworkDialog.c => gnome/applet/other-network-dialog.c (86%) rename panel-applet/NMWirelessAppletOtherNetworkDialog.h => gnome/applet/other-network-dialog.h (88%) create mode 100644 gnome/applet/passphrase-dialog.c rename panel-applet/main.c => gnome/applet/passphrase-dialog.h (65%) rename panel-applet/nmwa-vpn-connection.c => gnome/applet/vpn-connection.c (89%) rename panel-applet/nmwa-vpn-connection.h => gnome/applet/vpn-connection.h (75%) rename panel-applet/nmwa-vpn-password-dialog.c => gnome/applet/vpn-password-dialog.c (98%) rename panel-applet/nmwa-vpn-password-dialog.h => gnome/applet/vpn-password-dialog.h (91%) rename {panel-applet => gnome/applet}/wireless-applet.glade (74%) create mode 100644 gnome/applet/wireless-network.c create mode 100644 gnome/applet/wireless-network.h rename {libnm_glib => gnome/libnm_glib}/.cvsignore (100%) rename {libnm_glib => gnome/libnm_glib}/Makefile.am (100%) rename {libnm_glib => gnome/libnm_glib}/libnm_glib.c (80%) rename {libnm_glib => gnome/libnm_glib}/libnm_glib.h (92%) rename {libnm_glib => gnome/libnm_glib}/libnm_glib.pc.in (100%) delete mode 100644 info-daemon/.cvsignore delete mode 100644 info-daemon/Makefile.am delete mode 100644 info-daemon/NetworkManagerInfo.c delete mode 100644 info-daemon/NetworkManagerInfo.h delete mode 100644 info-daemon/NetworkManagerInfoDbus.h delete mode 100644 info-daemon/NetworkManagerInfoNetworksDialog.c delete mode 100644 info-daemon/NetworkManagerInfoNetworksDialog.h delete mode 100644 info-daemon/NetworkManagerInfoPassphraseDialog.c delete mode 100644 info-daemon/NetworkManagerInfoVPN.c delete mode 100644 info-daemon/NetworkManagerInfoVPN.h delete mode 100644 info-daemon/networks.glade delete mode 100644 info-daemon/passphrase.glade delete mode 100644 panel-applet/.cvsignore delete mode 100644 panel-applet/Makefile.am delete mode 100644 panel-applet/NMWirelessApplet.h delete mode 100644 panel-applet/NMWirelessApplet.server.in delete mode 100644 panel-applet/NMWirelessApplet.xml delete mode 100644 panel-applet/NMWirelessAppletDbus.c delete mode 100644 panel-applet/NMWirelessAppletDbus.h delete mode 100644 panel-applet/essid.glade delete mode 100644 panel-applet/icons/.cvsignore diff --git a/ChangeLog b/ChangeLog index 5faf1929b..318b2479a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-04-27 Dan Williams + + * Merge the applet and the info-daemon, and move the converged + applet under gnome/applet + * Move libnm_glib to gnome/libnm_glib + * Convert most dbus calls between the applet, info-daemon, and NM + into async calls + * Fix a few things valgrind noticed + * Make NM broadcast state more reliably + 2005-04-22 Pawan chitrakar * configure.in: Added ne in ALL_LINGUAS diff --git a/Makefile.am b/Makefile.am index 15231ac48..f161a9afb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = utils dhcpcd src libnm_glib dispatcher-daemon $(notification_icon_dir) info-daemon vpn-daemons initscript test po +SUBDIRS = utils dhcpcd src dispatcher-daemon gnome vpn-daemons initscript test po EXTRA_DIST = CONTRIBUTING NetworkManager.pc.in NetworkManager.h diff --git a/NetworkManager.h b/NetworkManager.h index 66aa3797b..fa2961431 100644 --- a/NetworkManager.h +++ b/NetworkManager.h @@ -44,12 +44,14 @@ /* * Some common errors */ -#define NM_DBUS_NO_ACTIVE_NET_ERROR "org.freedesktop.NetworkManager.NoActiveNetwork" -#define NM_DBUS_NO_ACTIVE_DEVICE_ERROR "org.freedesktop.NetworkManager.NoActiveDevice" +#define NM_DBUS_NO_DEVICES_ERROR "org.freedesktop.NetworkManager.NoDevices" #define NM_DBUS_NO_NETWORKS_ERROR "org.freedesktop.NetworkManager.NoNetworks" +#define NM_DBUS_NO_ACTIVE_DEVICE_ERROR "org.freedesktop.NetworkManager.NoActiveDevice" +#define NM_DBUS_NO_ACTIVE_NET_ERROR "org.freedesktop.NetworkManager.NoActiveNetwork" #define NM_DBUS_NO_ACTIVE_VPN_CONNECTION "org.freedesktop.NetworkManager.VPNConnections.NoActiveVPNConnection" #define NM_DBUS_NO_VPN_CONNECTIONS "org.freedesktop.NetworkManager.VPNConnections.NoVPNConnections" +#define NM_DBUS_INVALID_VPN_CONNECTION "org.freedesktop.NetworkManager.VPNConnections.InvalidVPNConnection" #define NM_DBUS_VPN_STARTING_IN_PROGRESS "StartingInProgress" #define NM_DBUS_VPN_ALREADY_STARTED "AlreadyStarted" @@ -58,12 +60,36 @@ #define NM_DBUS_VPN_WRONG_STATE "WrongState" #define NM_DBUS_VPN_BAD_ARGUMENTS "BadArguments" + +/* + * VPN daemon signals + */ #define NM_DBUS_VPN_SIGNAL_LOGIN_FAILED "LoginFailed" #define NM_DBUS_VPN_SIGNAL_CONFIG_BAD "ConfigurationBad" #define NM_DBUS_VPN_SIGNAL_STATE_CHANGE "StateChange" #define NM_DBUS_VPN_SIGNAL_IP4_CONFIG "IP4Config" +/* + * NetworkManager signals + */ +#define NM_DBUS_SIGNAL_STATE_CHANGE "StateChange" + + +/* + * Types of NetworkManager devices + */ +typedef enum NMState +{ + NM_STATE_UNKNOWN = 0, + NM_STATE_ASLEEP, + NM_STATE_SCANNING, + NM_STATE_CONNECTING, + NM_STATE_CONNECTED, + NM_STATE_DISCONNECTED +} NMState; + + /* * Types of NetworkManager devices */ @@ -161,10 +187,4 @@ typedef enum NMVPNState NM_VPN_STATE_STOPPED } NMVPNState; - -/* - * Info-daemon specific preference locations - */ -#define NMI_GCONF_WIRELESS_NETWORKS_PATH "/system/networking/wireless/networks" - #endif diff --git a/configure.in b/configure.in index 350a1d743..eb236a522 100644 --- a/configure.in +++ b/configure.in @@ -193,15 +193,6 @@ AC_DEFINE_UNQUOTED(NM_NAMED_BINARY_PATH, "$with_named", [Define to path of named AC_DEFINE_UNQUOTED(NM_NAMED_DATA_DIR, "$with_named_dir", [Define to path of named data directory]) AC_DEFINE_UNQUOTED(NM_NAMED_USER, "$with_named_user", [Define to named username]) -AC_ARG_ENABLE(notification-icon, AC_HELP_STRING([--enable-notification-icon], [builds the wireless applet as a notification icon]), enable_notification_icon=$enableval, enable_notification_icon=yes) - -AM_CONDITIONAL(BUILD_NOTIFICATION_ICON, test x$enable_notification_icon = xyes) -if test x$enable_notification_icon == xyes ; then - AC_DEFINE_UNQUOTED(BUILD_NOTIFICATION_ICON, "$BUILD_NOTIFICATION_ICON", [Should we build the notification icon instead of the applet]) - notification_icon_dir="panel-applet" - AC_SUBST(notification_icon_dir) -fi - #### find the actual value for $prefix that we'll end up with ## (I know this is broken and should be done in the Makefile, but ## that's a major pain and almost nobody actually seems to care) @@ -274,11 +265,14 @@ src/named-manager/Makefile src/vpn-manager/Makefile src/backends/Makefile dispatcher-daemon/Makefile -info-daemon/Makefile +gnome/Makefile +gnome/applet/Makefile +gnome/applet/icons/Makefile +gnome/libnm_glib/libnm_glib.pc +gnome/libnm_glib/Makefile panel-applet/Makefile panel-applet/icons/Makefile dhcpcd/Makefile -libnm_glib/Makefile test/Makefile initscript/Makefile initscript/RedHat/Makefile @@ -287,7 +281,6 @@ initscript/Debian/Makefile initscript/Slackware/Makefile po/Makefile.in NetworkManager.pc -libnm_glib/libnm_glib.pc vpn-daemons/Makefile vpn-daemons/vpnc/Makefile ]) diff --git a/gnome/Makefile.am b/gnome/Makefile.am new file mode 100644 index 000000000..123897358 --- /dev/null +++ b/gnome/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = applet libnm_glib diff --git a/gnome/applet/Makefile.am b/gnome/applet/Makefile.am new file mode 100644 index 000000000..f3debf597 --- /dev/null +++ b/gnome/applet/Makefile.am @@ -0,0 +1,89 @@ +SUBDIRS=icons + +NULL= + +INCLUDES = -I${top_srcdir} -I${top_srcdir}/utils + +libexec_PROGRAMS = nm-applet + +nm_applet_CFLAGS = \ + $(DBUS_CFLAGS) \ + $(GTHREAD_CFLAGS) \ + $(HAL_CFLAGS) \ + $(DBUS_GLIB_CFLAGS) \ + $(GLADE_CFLAGS) \ + $(GTK_CFLAGS) \ + $(GCONF_CFLAGS) \ + $(LIBGNOMEUI_CFLAGS) \ + $(PANEL_APPLET_CFLAGS) \ + $(GNOMEKEYRING_CFLAGS) \ + -DICONDIR=\""$(datadir)/pixmaps"\" \ + -DGLADEDIR=\""$(gladedir)"\" \ + -DDBUS_API_SUBJECT_TO_CHANGE \ + -DG_DISABLE_DEPRECATED \ + -DGDK_DISABLE_DEPRECATED \ + -DGNOME_DISABLE_DEPRECATED \ + -DGNOMELOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \ + -DVERSION=\"$(VERSION)\" \ + $(NULL) + +nm_applet_SOURCES = \ + main.c \ + applet.c \ + applet.h \ + applet-dbus.c \ + applet-dbus.h \ + applet-dbus-devices.c \ + applet-dbus-devices.h \ + applet-dbus-vpn.c \ + applet-dbus-vpn.h \ + applet-dbus-info.c \ + applet-dbus-info.h \ + wireless-network.c \ + wireless-network.h \ + nm-device.c \ + nm-device.h \ + other-network-dialog.c \ + other-network-dialog.h \ + passphrase-dialog.c \ + passphrase-dialog.h \ + menu-items.c \ + menu-items.h \ + gtkcellview.c \ + gtkcellview.h \ + gtkcellrendererprogress.c \ + gtkcellrendererprogress.h \ + eggtrayicon.c \ + eggtrayicon.h \ + vpn-password-dialog.c \ + vpn-password-dialog.h \ + vpn-connection.c \ + vpn-connection.h \ + $(NULL) + +nm_applet_LDADD = \ + $(DBUS_LIBS) \ + $(HAL_LIBS) \ + $(GTHREAD_LIBS) \ + $(GLADE_LIBS) \ + $(DBUS_GLIB_LIBS) \ + $(PANEL_APPLET_LIBS) \ + $(GTK_LIBS) \ + $(GCONF_LIBS) \ + $(LIBGNOMEUI_LIBS) \ + $(GNOMEKEYRING_LIBS) \ + $(top_builddir)/utils/libnmutils.la \ + $(NULL) + + +gladedir = $(datadir)/NetworkManagerNotification +glade_DATA = wireless-applet.glade keyring.png + +dbusservicedir = $(DBUS_SYS_DIR) +dbusservice_DATA = nm-applet.conf + +CLEANFILES = $(server_DATA) *.bak *.gladep + +EXTRA_DIST = \ + $(glade_DATA) \ + $(NULL) diff --git a/gnome/applet/applet-dbus-devices.c b/gnome/applet/applet-dbus-devices.c new file mode 100644 index 000000000..87867b538 --- /dev/null +++ b/gnome/applet/applet-dbus-devices.c @@ -0,0 +1,1476 @@ +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ +/* NetworkManager Wireless Applet -- Display wireless access points and allow user control + * + * Dan Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * (C) Copyright 2004-2005 Red Hat, Inc. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include "applet-dbus-devices.h" +#include "applet-dbus.h" +#include "applet.h" +#include "vpn-connection.h" +#include "nm-utils.h" + +void nmwa_dbus_devices_schedule_copy (NMWirelessApplet *applet); + + +/* + * nmwa_dbus_get_active_device_cb + * + * Callback from nmwa_dbus_get_active_device + * + */ +void nmwa_dbus_get_active_device_cb (DBusPendingCall *pcall, void *user_data) +{ + DBusMessage * reply; + NMWirelessApplet * applet = (NMWirelessApplet *) user_data; + const char * act_dev; + + g_return_if_fail (pcall != NULL); + g_return_if_fail (applet != NULL); + + dbus_pending_call_ref (pcall); + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (dbus_message_is_error (reply, NM_DBUS_NO_ACTIVE_DEVICE_ERROR)) + { + dbus_message_unref (reply); + goto out; + } + + if (dbus_message_get_args (reply, NULL, DBUS_TYPE_OBJECT_PATH, &act_dev, DBUS_TYPE_INVALID)) + { + g_free (applet->dbus_active_device_path); + applet->dbus_active_device_path = g_strdup (act_dev); + } + dbus_message_unref (reply); + +out: + applet->dev_pending_call_list = g_slist_remove (applet->dev_pending_call_list, pcall); + nmwa_dbus_devices_schedule_copy (applet); + + dbus_pending_call_unref (pcall); +} + + +/* + * nmwa_dbus_get_active_device + * + * Get the active device from NetworkManager + * + */ +void nmwa_dbus_get_active_device (NMWirelessApplet *applet) +{ + DBusMessage * message; + DBusPendingCall * pcall = NULL; + + g_return_if_fail (applet != NULL); + + if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getActiveDevice"))) + { + dbus_connection_send_with_reply (applet->connection, message, &pcall, -1); + dbus_message_unref (message); + if (pcall) + { + dbus_pending_call_set_notify (pcall, nmwa_dbus_get_active_device_cb, applet, NULL); + applet->dev_pending_call_list = g_slist_append (applet->dev_pending_call_list, pcall); + } + } +} + + +/* + * nmwa_dbus_nm_state_cb + * + * Callback from nmwa_dbus_update_nm_state + * + */ +void nmwa_dbus_nm_state_cb (DBusPendingCall *pcall, void *user_data) +{ + DBusMessage * reply; + NMWirelessApplet * applet = (NMWirelessApplet *) user_data; + NMState nm_state; + + g_return_if_fail (pcall != NULL); + g_return_if_fail (applet != NULL); + + dbus_pending_call_ref (pcall); + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (message_is_error (reply)) + { + dbus_message_unref (reply); + goto out; + } + + if (dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &nm_state, DBUS_TYPE_INVALID)) + { + applet->dbus_nm_state = nm_state; + applet->gui_nm_state = nm_state; + } + dbus_message_unref (reply); + +out: + applet->dev_pending_call_list = g_slist_remove (applet->dev_pending_call_list, pcall); + nmwa_dbus_devices_schedule_copy (applet); + + dbus_pending_call_unref (pcall); +} + + +/* + * nmwa_dbus_update_nm_state + * + * Update internal applet state from NetworkManager state + * + */ +void nmwa_dbus_update_nm_state (NMWirelessApplet *applet) +{ + DBusMessage * message; + DBusPendingCall * pcall = NULL; + + g_return_if_fail (applet != NULL); + + if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "state"))) + { + dbus_connection_send_with_reply (applet->connection, message, &pcall, -1); + dbus_message_unref (message); + if (pcall) + { + dbus_pending_call_set_notify (pcall, nmwa_dbus_nm_state_cb, applet, NULL); + applet->dev_pending_call_list = g_slist_append (applet->dev_pending_call_list, pcall); + } + } +} + + +/* + * nmwa_dbus_update_scanning_enabled_cb + * + * Callback from nmwa_dbus_update_scanning_enabled + * + */ +void nmwa_dbus_update_scanning_enabled_cb (DBusPendingCall *pcall, void *user_data) +{ + DBusMessage * reply; + NMWirelessApplet * applet = (NMWirelessApplet *) user_data; + gboolean scanning_enabled; + + g_return_if_fail (pcall != NULL); + g_return_if_fail (applet != NULL); + + dbus_pending_call_ref (pcall); + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (message_is_error (reply)) + { + dbus_message_unref (reply); + goto out; + } + + if (dbus_message_get_args (reply, NULL, DBUS_TYPE_BOOLEAN, &scanning_enabled, DBUS_TYPE_INVALID)) + applet->scanning_enabled = scanning_enabled; + dbus_message_unref (reply); + +out: + dbus_pending_call_unref (pcall); +} + + +/* + * nmwa_dbus_update_scanning_enabled + * + * Get the scanning_enabled value from NetworkManager + * + */ +void nmwa_dbus_update_scanning_enabled (NMWirelessApplet *applet) +{ + DBusMessage * message; + DBusPendingCall * pcall = NULL; + + g_return_if_fail (applet != NULL); + + if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getScanningEnabled"))) + { + dbus_connection_send_with_reply (applet->connection, message, &pcall, -1); + dbus_message_unref (message); + if (pcall) + dbus_pending_call_set_notify (pcall, nmwa_dbus_update_scanning_enabled_cb, applet, NULL); + } +} + + +/* + * nmwa_dbus_update_wireless_enabled_cb + * + * Callback from nmwa_dbus_update_wireless_enabled + * + */ +void nmwa_dbus_update_wireless_enabled_cb (DBusPendingCall *pcall, void *user_data) +{ + DBusMessage * reply; + NMWirelessApplet * applet = (NMWirelessApplet *) user_data; + gboolean wireless_enabled; + + g_return_if_fail (pcall != NULL); + g_return_if_fail (applet != NULL); + + dbus_pending_call_ref (pcall); + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (message_is_error (reply)) + { + dbus_message_unref (reply); + goto out; + } + + if (dbus_message_get_args (reply, NULL, DBUS_TYPE_BOOLEAN, &wireless_enabled, DBUS_TYPE_INVALID)) + applet->wireless_enabled = wireless_enabled; + dbus_message_unref (reply); + +out: + dbus_pending_call_unref (pcall); +} + + +/* + * nmwa_dbus_update_wireless_enabled + * + * Get the wireless_enabled value from NetworkManager + * + */ +void nmwa_dbus_update_wireless_enabled (NMWirelessApplet *applet) +{ + DBusMessage * message; + DBusPendingCall * pcall = NULL; + + g_return_if_fail (applet != NULL); + + if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getWirelessEnabled"))) + { + dbus_connection_send_with_reply (applet->connection, message, &pcall, -1); + dbus_message_unref (message); + if (pcall) + dbus_pending_call_set_notify (pcall, nmwa_dbus_update_wireless_enabled_cb, applet, NULL); + } +} + + +/* + * nmwa_dbus_get_hal_device_string_property + * + * Get a string property from a device + * + */ +static char *nmwa_dbus_get_hal_device_string_property (DBusConnection *connection, const char *udi, const char *property_name) +{ + DBusError error; + DBusMessage *message; + DBusMessage *reply; + char *dbus_property = NULL; + char *property = NULL; + + g_return_val_if_fail (connection != NULL, NULL); + g_return_val_if_fail (udi != NULL, NULL); + + if (!(message = dbus_message_new_method_call ("org.freedesktop.Hal", udi, "org.freedesktop.Hal.Device", "GetPropertyString"))) + return (NULL); + + dbus_error_init (&error); + dbus_message_append_args (message, DBUS_TYPE_STRING, &property_name, DBUS_TYPE_INVALID); + reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error); + dbus_message_unref (message); + if (dbus_error_is_set (&error)) + { + nm_warning ("nmwa_dbus_get_hal_device_string_property(): %s raised:\n %s\n\n", error.name, error.message); + dbus_error_free (&error); + return (NULL); + } + if (reply == NULL) + { + nm_warning ("nmwa_dbus_get_hal_device_string_property(): dbus reply message was NULL\n" ); + return (NULL); + } + + dbus_error_init (&error); + if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &dbus_property, DBUS_TYPE_INVALID)) + { + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + } + else + property = g_strdup (dbus_property); + + dbus_message_unref (reply); + return (property); +} + + +typedef struct HalInfoCBData +{ + NMWirelessApplet * applet; + NetworkDevice * dev; + char * parent_op; + char * vendor; +} HalInfoCBData; + +void free_hal_info_cb_data (HalInfoCBData *cb_data) +{ + if (cb_data) + { + network_device_unref (cb_data->dev); + g_free (cb_data->parent_op); + g_free (cb_data->vendor); + memset (cb_data, 0, sizeof (HalInfoCBData)); + g_free (cb_data); + } +} + + +/* + * hal_info_product_cb + * + * hal_info_vendor callback + * + */ +static void hal_info_product_cb (DBusPendingCall *pcall, void *user_data) +{ + DBusMessage * reply; + HalInfoCBData * cb_data = (HalInfoCBData *) user_data; + char * info_product; + + g_return_if_fail (pcall != NULL); + g_return_if_fail (cb_data != NULL); + g_return_if_fail (cb_data->applet != NULL); + g_return_if_fail (cb_data->dev != NULL); + g_return_if_fail (cb_data->parent_op != NULL); + g_return_if_fail (cb_data->vendor != NULL); + + dbus_pending_call_ref (pcall); + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (message_is_error (reply)) + { + dbus_message_unref (reply); + goto out; + } + + if (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &info_product, DBUS_TYPE_INVALID)) + { + char *desc = g_strdup_printf ("%s %s", cb_data->vendor, info_product); + + network_device_set_desc (cb_data->dev, desc); + } + dbus_message_unref (reply); + +out: + cb_data->applet->dev_pending_call_list = g_slist_remove (cb_data->applet->dev_pending_call_list, pcall); + nmwa_dbus_devices_schedule_copy (cb_data->applet); + + dbus_pending_call_unref (pcall); +} + + +/* + * hal_info_vendor_cb + * + * hal_info_parent callback + * + */ +static void hal_info_vendor_cb (DBusPendingCall *pcall, void *user_data) +{ + DBusMessage * reply; + HalInfoCBData * cb_data = (HalInfoCBData *) user_data; + char * info_vendor; + + g_return_if_fail (pcall != NULL); + g_return_if_fail (cb_data != NULL); + g_return_if_fail (cb_data->applet != NULL); + g_return_if_fail (cb_data->dev != NULL); + g_return_if_fail (cb_data->parent_op != NULL); + + dbus_pending_call_ref (pcall); + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (message_is_error (reply)) + { + dbus_message_unref (reply); + goto out; + } + + if (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &info_vendor, DBUS_TYPE_INVALID)) + { + DBusMessage * message; + DBusPendingCall * product_pcall = NULL; + + if ((message = dbus_message_new_method_call ("org.freedesktop.Hal", cb_data->parent_op, + "org.freedesktop.Hal.Device", "GetPropertyString"))) + { + const char * prop = "info.product"; + + dbus_message_append_args (message, DBUS_TYPE_STRING, &prop, DBUS_TYPE_INVALID); + dbus_connection_send_with_reply (cb_data->applet->connection, message, &product_pcall, -1); + dbus_message_unref (message); + if (product_pcall) + { + HalInfoCBData * product_cb_data = g_malloc0 (sizeof (HalInfoCBData)); + + product_cb_data->applet = cb_data->applet; + network_device_ref (cb_data->dev); + product_cb_data->dev = cb_data->dev; + product_cb_data->parent_op = g_strdup (cb_data->parent_op); + product_cb_data->vendor = g_strdup (info_vendor); + dbus_pending_call_set_notify (product_pcall, hal_info_product_cb, product_cb_data, (DBusFreeFunction) free_hal_info_cb_data); + cb_data->applet->dev_pending_call_list = g_slist_append (cb_data->applet->dev_pending_call_list, product_pcall); + } + } + } + dbus_message_unref (reply); + +out: + cb_data->applet->dev_pending_call_list = g_slist_remove (cb_data->applet->dev_pending_call_list, pcall); + nmwa_dbus_devices_schedule_copy (cb_data->applet); + + dbus_pending_call_unref (pcall); +} + + +/* + * hal_info_parent_cb + * + * nmwa_dbus_update_device_info_from_hal callback + * + */ +static void hal_info_parent_cb (DBusPendingCall *pcall, void *user_data) +{ + DBusMessage * reply; + HalInfoCBData * cb_data = (HalInfoCBData *) user_data; + char * op; + + g_return_if_fail (pcall != NULL); + g_return_if_fail (cb_data != NULL); + g_return_if_fail (cb_data->applet != NULL); + g_return_if_fail (cb_data->dev != NULL); + + dbus_pending_call_ref (pcall); + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (message_is_error (reply)) + { + dbus_message_unref (reply); + goto out; + } + + /* Grab the object path of the parent item of this "Network Interface" */ + if (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &op, DBUS_TYPE_INVALID)) + { + DBusMessage * message; + DBusPendingCall * vendor_pcall = NULL; + + if ((message = dbus_message_new_method_call ("org.freedesktop.Hal", op, + "org.freedesktop.Hal.Device", "GetPropertyString"))) + { + const char * prop = "info.vendor"; + + dbus_message_append_args (message, DBUS_TYPE_STRING, &prop, DBUS_TYPE_INVALID); + dbus_connection_send_with_reply (cb_data->applet->connection, message, &vendor_pcall, -1); + dbus_message_unref (message); + if (vendor_pcall) + { + HalInfoCBData * vendor_cb_data = g_malloc0 (sizeof (HalInfoCBData)); + + vendor_cb_data->applet = cb_data->applet; + network_device_ref (cb_data->dev); + vendor_cb_data->dev = cb_data->dev; + vendor_cb_data->parent_op = g_strdup (op); + dbus_pending_call_set_notify (vendor_pcall, hal_info_vendor_cb, vendor_cb_data, (DBusFreeFunction) free_hal_info_cb_data); + cb_data->applet->dev_pending_call_list = g_slist_append (cb_data->applet->dev_pending_call_list, vendor_pcall); + } + } + } + dbus_message_unref (reply); + +out: + cb_data->applet->dev_pending_call_list = g_slist_remove (cb_data->applet->dev_pending_call_list, pcall); + nmwa_dbus_devices_schedule_copy (cb_data->applet); + + dbus_pending_call_unref (pcall); +} + + +/* + * nmwa_dbus_update_device_info_from_hal + * + * Grab the info.product tag from hal for a specific UDI + * + */ +static void nmwa_dbus_update_device_info_from_hal (NetworkDevice *dev, NMWirelessApplet *applet) +{ + DBusMessage * message; + DBusPendingCall * pcall = NULL; + + g_return_if_fail (applet != NULL); + g_return_if_fail (applet->connection != NULL); + g_return_if_fail (dev != NULL); + + if ((message = dbus_message_new_method_call ("org.freedesktop.Hal", network_device_get_hal_udi (dev), + "org.freedesktop.Hal.Device", "GetPropertyString"))) + { + const char * prop = "info.parent"; + + dbus_message_append_args (message, DBUS_TYPE_STRING, &prop, DBUS_TYPE_INVALID); + dbus_connection_send_with_reply (applet->connection, message, &pcall, -1); + dbus_message_unref (message); + if (pcall) + { + HalInfoCBData * cb_data = g_malloc0 (sizeof (HalInfoCBData)); + + cb_data->applet = applet; + network_device_ref (dev); + cb_data->dev = dev; + dbus_pending_call_set_notify (pcall, hal_info_parent_cb, cb_data, (DBusFreeFunction) free_hal_info_cb_data); + applet->dev_pending_call_list = g_slist_append (applet->dev_pending_call_list, pcall); + } + } +} + + +void nmwa_free_gui_data_model (NMWirelessApplet *applet) +{ + g_return_if_fail (applet != NULL); + + if (applet->gui_device_list) + { + g_slist_foreach (applet->gui_device_list, (GFunc) network_device_unref, NULL); + g_slist_free (applet->gui_device_list); + applet->gui_device_list = NULL; + } + if (applet->gui_active_device) + { + network_device_unref (applet->gui_active_device); + applet->gui_active_device = NULL; + } +} + + +void nmwa_free_dbus_data_model (NMWirelessApplet *applet) +{ + GSList *elt; + + g_return_if_fail (applet != NULL); + + if (applet->dbus_device_list) + { + g_slist_foreach (applet->dbus_device_list, (GFunc) network_device_unref, NULL); + g_slist_free (applet->dbus_device_list); + applet->dbus_device_list = NULL; + } + if (applet->dbus_active_device) + { + network_device_unref (applet->dbus_active_device); + applet->dbus_active_device = NULL; + } + g_free (applet->dbus_active_device_path); + applet->dbus_active_device_path = NULL; +} + + +/* + * nmwa_copy_data_model + * + * Copy the dbus data model over to the gui data model + * + */ +void nmwa_copy_data_model (NMWirelessApplet *applet) +{ + GSList *elt; + NetworkDevice *act_dev = NULL; + + g_return_if_fail (applet != NULL); + + /* Free the existing GUI data model. */ + nmwa_free_gui_data_model (applet); + + /* Deep-copy network devices to GUI data model */ + for (elt = applet->dbus_device_list; elt; elt = g_slist_next (elt)) + { + NetworkDevice *src = (NetworkDevice *)(elt->data); + NetworkDevice *dst = network_device_copy (src); + + if (dst) + { + /* Transfer ownership of device to list, don't need to unref it */ + applet->gui_device_list = g_slist_append (applet->gui_device_list, dst); + + /* Make sure we get the right active device for the gui data model */ + if (applet->dbus_active_device == src) + { + network_device_ref (dst); + act_dev = dst; + } + } + } + + /* active_device is just a pointer into the device list, no need to deep-copy it */ + applet->gui_active_device = act_dev; + applet->gui_nm_state = applet->dbus_nm_state; +} + + +/* + * nmwa_dbus_schedule_driver_notification + * + * Schedule the driver notification routine to run in the main loop. + * + */ +void nmwa_dbus_schedule_driver_notification (NMWirelessApplet *applet, NetworkDevice *dev) +{ + DriverNotifyCBData *cb_data; + + g_return_if_fail (applet != NULL); + g_return_if_fail (dev != NULL); + + cb_data = g_malloc0 (sizeof (DriverNotifyCBData)); + cb_data->applet = applet; + network_device_ref (dev); + cb_data->dev = dev; + + g_idle_add (nmwa_driver_notify, (gpointer)cb_data); +} + + +/* + * nmwa_dbus_check_drivers + * + * If a device got added, we notify the user if the device's driver + * has any problems (no carrier detect, no wireless scanning, etc). + * + */ +void nmwa_dbus_check_drivers (NMWirelessApplet *applet) +{ + GSList *elt; + + g_return_if_fail (applet != NULL); + + /* For every device that's in the dbus data model but not in + * the gui data model, signal the user. + */ + for (elt = applet->dbus_device_list; elt; elt = g_slist_next (elt)) + { + NetworkDevice *dbus_dev = (NetworkDevice *)(elt->data); + GSList *elt2; + gboolean found = FALSE; + + for (elt2 = applet->gui_device_list; elt2; elt2 = g_slist_next (elt2)) + { + NetworkDevice *gui_dev = (NetworkDevice *)(elt2->data); + + if ( !nm_null_safe_strcmp (network_device_get_iface (dbus_dev), network_device_get_iface (gui_dev)) + && !nm_null_safe_strcmp (network_device_get_address (dbus_dev), network_device_get_address (gui_dev)) + && !nm_null_safe_strcmp (network_device_get_hal_udi (dbus_dev), network_device_get_hal_udi (gui_dev))) + { + found = TRUE; + break; + } + } + + if ( !found + && ( (network_device_get_driver_support_level (dbus_dev) == NM_DRIVER_NO_CARRIER_DETECT) + || (network_device_get_driver_support_level (dbus_dev) == NM_DRIVER_NO_WIRELESS_SCAN))) + nmwa_dbus_schedule_driver_notification (applet, dbus_dev); + } +} + + +typedef struct NetPropCBData +{ + char * dev_op; + char * act_net; + NMWirelessApplet * applet; +} NetPropCBData; + +void free_net_prop_cb_data (NetPropCBData *data) +{ + if (data) + { + g_free (data->dev_op); + g_free (data->act_net); + } + g_free (data); +} + + +/* + * nmwa_dbus_net_properties_cb + * + * Callback for each network we called "getProperties" on in nmwa_dbus_device_properties_cb(). + * + */ +void nmwa_dbus_net_properties_cb (DBusPendingCall *pcall, void *user_data) +{ + DBusMessage * reply; + NetPropCBData * cb_data = (NetPropCBData *) user_data; + NMWirelessApplet * applet; + const char * op = NULL; + const char * essid = NULL; + const char * hw_addr = NULL; + dbus_int32_t strength = -1; + double freq = 0; + dbus_int32_t rate = 0; + dbus_bool_t enc = FALSE; + dbus_uint32_t mode = 0; + + g_return_if_fail (pcall != NULL); + g_return_if_fail (cb_data != NULL); + g_return_if_fail (cb_data->applet != NULL); + g_return_if_fail (cb_data->dev_op != NULL); + + applet = cb_data->applet; + + dbus_pending_call_ref (pcall); + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (dbus_message_is_error (reply, NM_DBUS_NO_NETWORKS_ERROR)) + { + dbus_message_unref (reply); + goto out; + } + + if (dbus_message_get_args (reply, NULL, DBUS_TYPE_OBJECT_PATH, &op, + DBUS_TYPE_STRING, &essid, + DBUS_TYPE_STRING, &hw_addr, + DBUS_TYPE_INT32, &strength, + DBUS_TYPE_DOUBLE, &freq, + DBUS_TYPE_INT32, &rate, + DBUS_TYPE_BOOLEAN,&enc, + DBUS_TYPE_UINT32, &mode, + DBUS_TYPE_INVALID)) + { + NetworkDevice * dev; + + if ((dev = nmwa_get_device_for_nm_device (applet->dbus_device_list, cb_data->dev_op))) + { + WirelessNetwork * net = wireless_network_new (essid, op); + WirelessNetwork * tmp_net; + char * act_net = cb_data->act_net ? g_strdup (cb_data->act_net) : NULL; + + /* Remove any existing wireless network with this object path */ + if ((tmp_net = network_device_get_wireless_network_by_nm_path (dev, op))) + { + if (!act_net && wireless_network_get_active (tmp_net)) + act_net = g_strdup (wireless_network_get_nm_path (tmp_net)); + network_device_remove_wireless_network (dev, tmp_net); + } + + wireless_network_set_encrypted (net, enc); + wireless_network_set_strength (net, strength); + if (act_net && strlen (act_net) && (strcmp (act_net, op) == 0)) + wireless_network_set_active (net, TRUE); + + network_device_add_wireless_network (dev, net); + g_free (act_net); + } + } + dbus_message_unref (reply); + +out: + applet->dev_pending_call_list = g_slist_remove (applet->dev_pending_call_list, pcall); + nmwa_dbus_devices_schedule_copy (applet); + + dbus_pending_call_unref (pcall); +} + + +/* + * nmwa_dbus_device_update_one_network + * + * Get properties on just one wireless network. + * + */ +void nmwa_dbus_device_update_one_network (NMWirelessApplet *applet, const char *dev_path, const char *net_path, const char *active_net_path) +{ + DBusMessage * message; + DBusPendingCall * pcall = NULL; + + g_return_if_fail (applet != NULL); + g_return_if_fail (dev_path != NULL); + g_return_if_fail (net_path != NULL); + + if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, net_path, NM_DBUS_INTERFACE_DEVICES, "getProperties"))) + { + dbus_connection_send_with_reply (applet->connection, message, &pcall, -1); + dbus_message_unref (message); + if (pcall) + { + NetPropCBData * cb_data = g_malloc0 (sizeof (NetPropCBData)); + + cb_data->dev_op = g_strdup (dev_path); + cb_data->act_net = (active_net_path && strlen (active_net_path)) ? g_strdup (active_net_path) : NULL; + cb_data->applet = applet; + dbus_pending_call_set_notify (pcall, nmwa_dbus_net_properties_cb, cb_data, (DBusFreeFunction) free_net_prop_cb_data); + applet->dev_pending_call_list = g_slist_append (applet->dev_pending_call_list, pcall); + } + } +} + + +/* + * nmwa_dbus_device_remove_one_network + * + * Remove a wireless network from a device. + * + */ +void nmwa_dbus_device_remove_one_network (NMWirelessApplet *applet, const char *dev_path, const char *net_path) +{ + NetworkDevice * dev; + + g_return_if_fail (applet != NULL); + g_return_if_fail (dev_path != NULL); + g_return_if_fail (net_path != NULL); + + if ((dev = nmwa_get_device_for_nm_device (applet->dbus_device_list, dev_path))) + { + WirelessNetwork * net; + + if ((net = network_device_get_wireless_network_by_nm_path (dev, net_path))) + { + network_device_remove_wireless_network (dev, net); + nmwa_dbus_devices_schedule_copy (applet); + } + } +} + + +/* + * nmwa_dbus_device_properties_cb + * + * Callback for each device we called "getProperties" on in nmwa_dbus_update_devices_cb(). + * + */ +void nmwa_dbus_device_properties_cb (DBusPendingCall *pcall, void *user_data) +{ + DBusMessage * reply; + NMWirelessApplet * applet = (NMWirelessApplet *) user_data; + char * op = NULL; + const char * iface = NULL; + dbus_uint32_t type = 0; + const char * udi = NULL; + dbus_uint32_t ip4_address = 0; + const char * hw_addr = NULL; + dbus_uint32_t mode = 0; + dbus_int32_t strength = -1; + char * active_network_path = NULL; + dbus_bool_t link_active = FALSE; + dbus_uint32_t driver_support_level = 0; + char ** networks = NULL; + int num_networks = 0; + + g_return_if_fail (pcall != NULL); + g_return_if_fail (applet != NULL); + + dbus_pending_call_ref (pcall); + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) + { + dbus_message_unref (reply); + goto out; + } + + if (dbus_message_get_args (reply, NULL, DBUS_TYPE_OBJECT_PATH, &op, + DBUS_TYPE_STRING, &iface, + DBUS_TYPE_UINT32, &type, + DBUS_TYPE_STRING, &udi, + DBUS_TYPE_UINT32, &ip4_address, + DBUS_TYPE_STRING, &hw_addr, + DBUS_TYPE_UINT32, &mode, + DBUS_TYPE_INT32, &strength, + DBUS_TYPE_BOOLEAN,&link_active, + DBUS_TYPE_UINT32, &driver_support_level, + DBUS_TYPE_STRING, &active_network_path, + DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &networks, &num_networks, + DBUS_TYPE_INVALID)) + { + NetworkDevice *dev = network_device_new (iface, type, op); + NetworkDevice *tmp_dev = nmwa_get_device_for_nm_device (applet->dbus_device_list, op); + + network_device_set_hal_udi (dev, udi); + network_device_set_address (dev, hw_addr); + network_device_set_link (dev, link_active); + network_device_set_driver_support_level (dev, driver_support_level); + + /* If the device already exists in our list for some reason, remove it so we + * can add the new one with updated data. + */ + if (tmp_dev) + { + applet->dbus_device_list = g_slist_remove (applet->dbus_device_list, tmp_dev); + network_device_unref (tmp_dev); + } + + applet->dbus_device_list = g_slist_append (applet->dbus_device_list, dev); + + nmwa_dbus_update_device_info_from_hal (dev, applet); + + if (type == DEVICE_TYPE_WIRELESS_ETHERNET) + { + network_device_set_strength (dev, strength); + + /* Call the "getProperties" method on each wireless network the device may have. */ + if (num_networks > 0) + { + char ** item; + + for (item = networks; *item; item++) + nmwa_dbus_device_update_one_network (applet, op, *item, active_network_path); + } + } + + dbus_free_string_array (networks); + } + dbus_message_unref (reply); + +out: + applet->dev_pending_call_list = g_slist_remove (applet->dev_pending_call_list, pcall); + nmwa_dbus_devices_schedule_copy (applet); + + dbus_pending_call_unref (pcall); +} + + +/* + * nmwa_dbus_device_update_one_device + * + * Get properties on just one device. + * + */ +void nmwa_dbus_device_update_one_device (NMWirelessApplet *applet, const char *dev_path) +{ + DBusMessage * message; + DBusPendingCall * pcall = NULL; + + g_return_if_fail (applet != NULL); + g_return_if_fail (dev_path != NULL); + + nmwa_dbus_get_active_device (applet); + + if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, dev_path, NM_DBUS_INTERFACE_DEVICES, "getProperties"))) + { + dbus_connection_send_with_reply (applet->connection, message, &pcall, -1); + dbus_message_unref (message); + if (pcall) + { + dbus_pending_call_set_notify (pcall, nmwa_dbus_device_properties_cb, applet, NULL); + applet->dev_pending_call_list = g_slist_append (applet->dev_pending_call_list, pcall); + } + } +} + + +/* + * nmwa_dbus_update_devices_cb + * + * nmwa_dbus_update_devices callback. + * + */ +void nmwa_dbus_update_devices_cb (DBusPendingCall *pcall, void *user_data) +{ + DBusMessage * reply; + NMWirelessApplet * applet = (NMWirelessApplet *) user_data; + char ** devices; + int num_devices; + + g_return_if_fail (pcall != NULL); + g_return_if_fail (applet != NULL); + + dbus_pending_call_ref (pcall); + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (dbus_message_is_error (reply, NM_DBUS_NO_DEVICES_ERROR)) + { + dbus_message_unref (reply); + goto out; + } + + if (dbus_message_get_args (reply, NULL, DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &devices, &num_devices, DBUS_TYPE_INVALID)) + { + char ** item; + + /* For each device, fire off a "getProperties" call */ + for (item = devices; *item; item++) + nmwa_dbus_device_update_one_device (applet, *item); + + dbus_free_string_array (devices); + } + dbus_message_unref (reply); + +out: + dbus_pending_call_unref (pcall); +} + + +/* + * nmwa_dbus_update_devices + * + * Do a full update of network devices and wireless networks. + * + */ +void nmwa_dbus_update_devices (NMWirelessApplet *applet) +{ + DBusMessage * message; + DBusPendingCall * pcall; + + g_return_if_fail (applet->data_mutex != NULL); + + nmwa_free_dbus_data_model (applet); + + nmwa_dbus_get_active_device (applet); + + if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getDevices"))) + { + dbus_connection_send_with_reply (applet->connection, message, &pcall, -1); + dbus_message_unref (message); + if (pcall) + dbus_pending_call_set_notify (pcall, nmwa_dbus_update_devices_cb, applet, NULL); + } + + nmwa_dbus_update_scanning_enabled (applet); + nmwa_dbus_update_wireless_enabled (applet); +} + + +/* + * nmwa_dbus_device_remove_one_device + * + * Remove a device from our list. + * + */ +void nmwa_dbus_device_remove_one_device (NMWirelessApplet *applet, const char *dev_path) +{ + NetworkDevice * dev; + + g_return_if_fail (applet != NULL); + + if ((dev = nmwa_get_device_for_nm_device (applet->dbus_device_list, dev_path))) + { + applet->dbus_device_list = g_slist_remove (applet->dbus_device_list, dev); + network_device_unref (dev); + nmwa_dbus_devices_schedule_copy (applet); + } +} + + +/* + * nmwa_dbus_set_device + * + * Tell NetworkManager to use a specific network device that the user picked, and + * possibly a specific wireless network too. + * + */ +void nmwa_dbus_set_device (DBusConnection *connection, NetworkDevice *dev, WirelessNetwork *net, + NMEncKeyType key_type, const char *passphrase) +{ + DBusMessage *message; + + g_return_if_fail (connection != NULL); + g_return_if_fail (dev != NULL); + + if ((network_device_get_type (dev) == DEVICE_TYPE_WIRED_ETHERNET) && !passphrase && (key_type != -1)) + return; + + if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "setActiveDevice"))) + { + const char *dev_path = network_device_get_nm_path (dev); + const char *net_path = net ? wireless_network_get_nm_path (net) : NULL; + + if ((network_device_get_type (dev) == DEVICE_TYPE_WIRELESS_ETHERNET) && net && net_path) + { + nm_info ("Forcing device '%s' and network '%s' %s passphrase\n", dev_path, wireless_network_get_essid (net), passphrase ? "with" : "without"); + + if (passphrase == NULL) + passphrase = ""; + + dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev_path, + DBUS_TYPE_OBJECT_PATH, &net_path, + DBUS_TYPE_STRING, &passphrase, + DBUS_TYPE_INT32, &key_type, + DBUS_TYPE_INVALID); + } + else + { + nm_info ("Forcing device '%s'\n", network_device_get_nm_path (dev)); + dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_INVALID); + } + dbus_connection_send (connection, message, NULL); + } + else + nm_warning ("nmwa_dbus_set_device(): Couldn't allocate the dbus message\n"); +} + + +/* + * nmwa_dbus_create_network + * + * Tell NetworkManager to create an Ad-Hoc wireless network + * + */ +void nmwa_dbus_create_network (DBusConnection *connection, NetworkDevice *dev, const char *essid, + NMEncKeyType key_type, const char *passphrase) +{ + DBusMessage *message; + + g_return_if_fail (connection != NULL); + g_return_if_fail (dev != NULL); + g_return_if_fail (essid != NULL); + g_return_if_fail (network_device_get_type (dev) == DEVICE_TYPE_WIRELESS_ETHERNET); + + if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "createWirelessNetwork"))) + { + const char *dev_path = network_device_get_nm_path (dev); + + if (dev_path) + { + nm_info ("Creating network '%s' %s passphrase on device '%s'.\n", essid, passphrase ? "with" : "without", dev_path); + if (passphrase == NULL) + passphrase = ""; + dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev_path, + DBUS_TYPE_STRING, &essid, + DBUS_TYPE_STRING, &passphrase, + DBUS_TYPE_INT32, &key_type, + DBUS_TYPE_INVALID); + dbus_connection_send (connection, message, NULL); + } + } + else + nm_warning ("nmwa_dbus_set_device(): Couldn't allocate the dbus message\n"); +} + + +/* + * nmwa_dbus_enable_scanning + * + * Tell NetworkManager to start/stop scanning. + * + */ +void nmwa_dbus_enable_scanning (NMWirelessApplet *applet, gboolean enabled) +{ + DBusMessage *message; + + g_return_if_fail (applet != NULL); + g_return_if_fail (applet->connection != NULL); + + if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "setScanningEnabled"))) + { + dbus_message_append_args (message, DBUS_TYPE_BOOLEAN, &enabled, DBUS_TYPE_INVALID); + dbus_connection_send (applet->connection, message, NULL); + nmwa_dbus_update_scanning_enabled (applet); + } +} + + +/* + * nmwa_dbus_enable_wireless + * + * Tell NetworkManager to enabled or disable all wireless devices. + * + */ +void nmwa_dbus_enable_wireless (NMWirelessApplet *applet, gboolean enabled) +{ + DBusMessage *message; + + g_return_if_fail (applet != NULL); + g_return_if_fail (applet->connection != NULL); + + if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "setWirelessEnabled"))) + { + dbus_message_append_args (message, DBUS_TYPE_BOOLEAN, &enabled, DBUS_TYPE_INVALID); + dbus_connection_send (applet->connection, message, NULL); + nmwa_dbus_update_wireless_enabled (applet); + } +} + + +typedef struct StrengthCBData +{ + NMWirelessApplet * applet; + char * dev_path; +} StrengthCBData; + + +void free_strength_cb_data (StrengthCBData *data) +{ + if (data) + g_free (data->dev_path); + g_free (data); +} + + +/* + * nmwa_dbus_update_device_strength_cb + * + * nmwa_dbus_update_active_device_strength callback. + * + */ +void nmwa_dbus_update_device_strength_cb (DBusPendingCall *pcall, void *user_data) +{ + DBusMessage * reply; + StrengthCBData * cb_data = user_data; + NMWirelessApplet * applet; + int strength; + + g_return_if_fail (pcall != NULL); + g_return_if_fail (cb_data != NULL); + + applet = cb_data->applet; + g_return_if_fail (applet != NULL); + + dbus_pending_call_ref (pcall); + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (message_is_error (reply)) + { + dbus_message_unref (reply); + goto out; + } + + if (dbus_message_get_args (reply, NULL, DBUS_TYPE_INT32, &strength, DBUS_TYPE_INVALID)) + { + /* Update strength on dbus active device */ + if ( cb_data->dev_path + && applet->dbus_active_device + && !strcmp (cb_data->dev_path, network_device_get_nm_path (applet->dbus_active_device))) + network_device_set_strength (applet->dbus_active_device, strength); + + /* Update strength on gui active device too */ + if ( cb_data->dev_path + && applet->gui_active_device + && !strcmp (cb_data->dev_path, network_device_get_nm_path (applet->gui_active_device))) + network_device_set_strength (applet->gui_active_device, strength); + } + dbus_message_unref (reply); + +out: + dbus_pending_call_unref (pcall); +} + + +/* + * nmwa_dbus_update_active_device_strength + * + * Update the active device's strength. + * + */ +gboolean nmwa_dbus_update_active_device_strength (NMWirelessApplet *applet) +{ + NetworkDevice * dev; + DBusMessage * message; + DBusPendingCall * pcall; + + g_return_val_if_fail (applet != NULL, TRUE); + + if (!(dev = applet->dbus_active_device)) + return TRUE; + + if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, network_device_get_nm_path (dev), NM_DBUS_INTERFACE_DEVICES, "getStrength"))) + { + dbus_connection_send_with_reply (applet->connection, message, &pcall, -1); + dbus_message_unref (message); + if (pcall) + { + StrengthCBData * cb_data = g_malloc0 (sizeof (StrengthCBData)); + + cb_data->applet = applet; + cb_data->dev_path = g_strdup (network_device_get_nm_path (dev)); + dbus_pending_call_set_notify (pcall, nmwa_dbus_update_device_strength_cb, cb_data, (DBusFreeFunction) free_strength_cb_data); + } + } + + return TRUE; +} + + +/* + * sort_devices_function + * + * Sort the devices for display... Wired devices at the top. + * + */ +static int +sort_devices_function (gconstpointer a, gconstpointer b) +{ + NetworkDevice *dev_a = (NetworkDevice *) a; + NetworkDevice *dev_b = (NetworkDevice *) b; + const char *name_a; + const char *name_b; + + if (network_device_get_desc (dev_a)) + name_a = network_device_get_desc (dev_a); + else if (network_device_get_nm_path (dev_a)) + name_a = network_device_get_nm_path (dev_a); + else + name_a = ""; + + if (network_device_get_desc (dev_b)) + name_b = network_device_get_desc (dev_b); + else if (network_device_get_nm_path (dev_b)) + name_b = network_device_get_nm_path (dev_b); + else + name_b = ""; + + if (network_device_get_type (dev_a) == network_device_get_type (dev_b)) + { + return strcmp (name_a, name_b); + } + if (network_device_get_type (dev_a) == DEVICE_TYPE_WIRED_ETHERNET) + return -1; + if (network_device_get_type (dev_b) == DEVICE_TYPE_WIRED_ETHERNET) + return 1; + if (network_device_get_type (dev_a) == DEVICE_TYPE_WIRELESS_ETHERNET) + return -1; + if (network_device_get_type (dev_b) == DEVICE_TYPE_WIRELESS_ETHERNET) + return 1; + + /* Unknown device types. Sort by name only at this point. */ + return strcmp (name_a, name_b); +} + + +static int devices_copy_idle_id = 0; + +/* + * nmwa_dbus_devices_lock_and_copy + * + * Copy our network model over to the GUI thread. + * + */ +static gboolean nmwa_dbus_devices_lock_and_copy (NMWirelessApplet *applet) +{ + devices_copy_idle_id = 0; + + g_return_val_if_fail (applet != NULL, FALSE); + + /* Only copy over if we have a complete data model */ + if (g_slist_length (applet->dev_pending_call_list) == 0) + { + nmwa_dbus_check_drivers (applet); + + /* Sort the devices for display */ + applet->dbus_device_list = g_slist_sort (applet->dbus_device_list, sort_devices_function); + + /* Match up the active device path with a device in the list */ + if (applet->dbus_active_device_path && + (applet->dbus_active_device = nmwa_get_device_for_nm_device (applet->dbus_device_list, applet->dbus_active_device_path))) + network_device_ref (applet->dbus_active_device); + + /* Now copy the data over to the GUI side */ + g_mutex_lock (applet->data_mutex); + nmwa_copy_data_model (applet); + g_mutex_unlock (applet->data_mutex); + + nmwa_dbus_update_active_device_strength (applet); + } + + return FALSE; +} + +/* + * nmwa_dbus_devices_schedule_copy + * + * Schedule a copy of our model over to the gui thread, batching copy requests. + * + */ +void nmwa_dbus_devices_schedule_copy (NMWirelessApplet *applet) +{ + g_return_if_fail (applet != NULL); + + if (devices_copy_idle_id == 0) + { + GSource *source = g_idle_source_new (); + + /* We want this idle source to run before any other idle source */ + g_source_set_priority (source, G_PRIORITY_HIGH_IDLE); + g_source_set_callback (source, (GSourceFunc) nmwa_dbus_devices_lock_and_copy, applet, NULL); + devices_copy_idle_id = g_source_attach (source, applet->thread_context); + g_source_unref (source); + } +} + diff --git a/gnome/applet/applet-dbus-devices.h b/gnome/applet/applet-dbus-devices.h new file mode 100644 index 000000000..09150b87f --- /dev/null +++ b/gnome/applet/applet-dbus-devices.h @@ -0,0 +1,50 @@ +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ +/* NetworkManager Wireless Applet -- Display wireless access points and allow user control + * + * Dan Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * (C) Copyright 2004-2005 Red Hat, Inc. + */ + +#ifndef APPLET_DBUS_DEVICES_H +#define APPLET_DBUS_DEVICES_H + +#include +#include +#include "NetworkManager.h" +#include "applet.h" +#include "nm-device.h" +#include "wireless-network.h" + +void nmwa_dbus_update_one_vpn_connection (DBusConnection *connection, const char *name, NMWirelessApplet *applet, gboolean is_active); +void nmwa_dbus_update_vpn_connections (NMWirelessApplet *applet); +gboolean nmwa_dbus_update_active_device_strength (NMWirelessApplet *applet); + +void nmwa_dbus_update_nm_state (NMWirelessApplet *applet); + +void nmwa_dbus_get_active_device (NMWirelessApplet *applet); +void nmwa_dbus_update_devices (NMWirelessApplet *applet); +void nmwa_dbus_device_update_one_device (NMWirelessApplet *applet, const char *dev_path); +void nmwa_dbus_device_remove_one_device (NMWirelessApplet *applet, const char *dev_path); + +void nmwa_dbus_device_update_one_network (NMWirelessApplet *applet, const char *dev_path, const char *net_path, const char *active_net_path); +void nmwa_dbus_device_remove_one_network (NMWirelessApplet *applet, const char *dev_path, const char *net_path); + +void nmwa_dbus_set_device (DBusConnection *connection, NetworkDevice *dev, WirelessNetwork *net, NMEncKeyType key_type, const char *passphrase); +void nmwa_dbus_create_network (DBusConnection *connection, NetworkDevice *dev, const char *essid, NMEncKeyType key_type, const char *passphrase); + +#endif diff --git a/info-daemon/NetworkManagerInfoDbus.c b/gnome/applet/applet-dbus-info.c similarity index 54% rename from info-daemon/NetworkManagerInfoDbus.c rename to gnome/applet/applet-dbus-info.c index ae82e8621..d8fd3464d 100644 --- a/info-daemon/NetworkManagerInfoDbus.c +++ b/gnome/applet/applet-dbus-info.c @@ -1,5 +1,5 @@ -/* NetworkManagerInfo -- Manage allowed access points and provide a UI - * for WEP key entry +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ +/* NetworkManager Wireless Applet -- Display wireless access points and allow user control * * Dan Williams * @@ -17,46 +17,25 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * (C) Copyright 2004 Red Hat, Inc. + * (C) Copyright 2004-2005 Red Hat, Inc. */ -#include -#include -#include -#include -#include + #include +#include #include -#include - -#include "NetworkManagerInfo.h" -#include "NetworkManagerInfoDbus.h" -#include "NetworkManagerInfoPassphraseDialog.h" -#include "NetworkManagerInfoVPN.h" +#include +#include +#include +#include +#include +#include "NetworkManager.h" +#include "applet.h" +#include "applet-dbus.h" +#include "applet-dbus-info.h" +#include "passphrase-dialog.h" #include "nm-utils.h" -/* - * nmi_show_warning_dialog - * - * pop up a warning or error dialog with certain text - * - */ -static void nmi_show_warning_dialog (gboolean error, gchar *mesg, ...) -{ - GtkWidget *dialog; - char *tmp; - va_list ap; - - va_start (ap,mesg); - tmp = g_strdup_vprintf (mesg,ap); - dialog = gtk_message_dialog_new (NULL, 0, error ? GTK_MESSAGE_ERROR : GTK_MESSAGE_WARNING, - GTK_BUTTONS_OK, mesg, NULL); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - g_free (tmp); - va_end (ap); -} - /* * nmi_network_type_valid @@ -70,83 +49,42 @@ inline gboolean nmi_network_type_valid (NMNetworkType type) } -/* - * nmi_dbus_create_error_message - * - * Make a DBus error message - * - */ -static DBusMessage *nmi_dbus_create_error_message (DBusMessage *message, const char *exception_namespace, - const char *exception, const char *format, ...) -{ - char *exception_text; - DBusMessage *reply_message; - va_list args; - char error_text[512]; - - - va_start (args, format); - vsnprintf (error_text, 512, format, args); - va_end (args); - - exception_text = g_strdup_printf ("%s.%s", exception_namespace, exception); - reply_message = dbus_message_new_error (message, exception_text, error_text); - g_free (exception_text); - - return (reply_message); -} - - /* * nmi_dbus_get_key_for_network * * Throw up the user key dialog * */ -static void nmi_dbus_get_key_for_network (NMIAppInfo *info, DBusMessage *message) +static DBusMessage * nmi_dbus_get_key_for_network (NMWirelessApplet *applet, DBusMessage *message) { - DBusError error; - char *device = NULL; - char *network = NULL; - int attempt = 0; + char * dev_path = NULL; + char * net_path = NULL; + int attempt = 0; + gboolean success = FALSE; - dbus_error_init (&error); - if (dbus_message_get_args (message, &error, - DBUS_TYPE_STRING, &device, - DBUS_TYPE_STRING, &network, + if (dbus_message_get_args (message, NULL, + DBUS_TYPE_OBJECT_PATH, &dev_path, + DBUS_TYPE_OBJECT_PATH, &net_path, DBUS_TYPE_INT32, &attempt, DBUS_TYPE_INVALID)) { - nmi_passphrase_dialog_show (device, network, info); - } -} + NetworkDevice *dev = NULL; + WirelessNetwork *net = NULL; -/* - * nmi_dbus_get_user_pass - * - * Request a username/password for VPN login - * - */ -static void nmi_dbus_get_vpn_userpass (NMIAppInfo *info, DBusMessage *message) -{ - DBusError error; - char *vpn; - char *username; - dbus_bool_t retry; - - - dbus_error_init (&error); - if (dbus_message_get_args (message, &error, - DBUS_TYPE_STRING, &vpn, - DBUS_TYPE_STRING, &username, - DBUS_TYPE_BOOLEAN, &retry, - DBUS_TYPE_INVALID)) - { - if (username[0] == '\0') { - username = NULL; + if ((dev = nmwa_get_device_for_nm_device (applet->gui_device_list, dev_path))) + { + if ((net = network_device_get_wireless_network_by_nm_path (dev, net_path))) + { + nmi_passphrase_dialog_show (applet->passphrase_dialog, dev, net, message); + success = TRUE; + } } - nmi_vpn_request_password (info, message, vpn, username, retry); } + + if (!success) + return dbus_message_new_error (message, "GetKeyError", "Could not get user key for network."); + + return NULL; } @@ -156,66 +94,27 @@ static void nmi_dbus_get_vpn_userpass (NMIAppInfo *info, DBusMessage *message) * Alert NetworkManager of the new user key * */ -void nmi_dbus_return_user_key (DBusConnection *connection, const char *device, - const char *network, const char *passphrase, const int key_type) +void nmi_dbus_return_user_key (DBusConnection *connection, DBusMessage *message, const char *passphrase, const int key_type) { - DBusMessage *message; + DBusMessage * reply; + const char * dev_path; + const char * net_path; g_return_if_fail (connection != NULL); - g_return_if_fail (device != NULL); - g_return_if_fail (network != NULL); g_return_if_fail (passphrase != NULL); - if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "setKeyForNetwork"))) + if (!(reply = dbus_message_new_method_return (message))) { nm_warning ("nmi_dbus_return_user_key(): Couldn't allocate the dbus message"); return; } - /* Add network name and passphrase */ - if (dbus_message_append_args (message, DBUS_TYPE_STRING, &device, - DBUS_TYPE_STRING, &network, - DBUS_TYPE_STRING, &passphrase, - DBUS_TYPE_INT32, &key_type, - DBUS_TYPE_INVALID)) - { - if (!dbus_connection_send (connection, message, NULL)) - nm_warning ("nmi_dbus_return_user_key(): dbus could not send the message"); - } - - dbus_message_unref (message); -} - -/* - * nmi_dbus_return_userpass - * - * Alert caller of the username/password - * - */ -void nmi_dbus_return_vpn_password (DBusConnection *connection, DBusMessage *message, const char *password) -{ - DBusMessage *reply; - - g_return_if_fail (connection != NULL); - g_return_if_fail (message != NULL); - g_return_if_fail (password != NULL); - - if (password == NULL) - { - reply = dbus_message_new_error (message, NMI_DBUS_INTERFACE ".Cancelled", "Operation cancelled by user"); - } - else - { - reply = dbus_message_new_method_return (message); - dbus_message_append_args (reply, - DBUS_TYPE_STRING, &password, - DBUS_TYPE_INVALID); - } + dbus_message_append_args (reply, DBUS_TYPE_STRING, &passphrase, DBUS_TYPE_INT32, &key_type, DBUS_TYPE_INVALID); dbus_connection_send (connection, reply, NULL); dbus_message_unref (reply); - dbus_message_unref (message); } + /* * nmi_dbus_signal_update_network * @@ -255,7 +154,7 @@ void nmi_dbus_signal_update_network (DBusConnection *connection, const char *net * of a string array in a dbus message. * */ -static DBusMessage *nmi_dbus_get_networks (NMIAppInfo *info, DBusMessage *message) +static DBusMessage *nmi_dbus_get_networks (NMWirelessApplet *applet, DBusMessage *message) { GSList *dir_list = NULL; GSList *element = NULL; @@ -265,23 +164,23 @@ static DBusMessage *nmi_dbus_get_networks (NMIAppInfo *info, DBusMessage *messag DBusMessageIter iter_array; NMNetworkType type; - g_return_val_if_fail (info != NULL, NULL); + g_return_val_if_fail (applet != NULL, NULL); g_return_val_if_fail (message != NULL, NULL); dbus_error_init (&error); if ( !dbus_message_get_args (message, &error, DBUS_TYPE_INT32, &type, DBUS_TYPE_INVALID) || !nmi_network_type_valid (type)) { - reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments", + reply_message = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments", "NetworkManagerInfo::getNetworks called with invalid arguments."); return (reply_message); } /* List all allowed access points that gconf knows about */ - element = dir_list = gconf_client_all_dirs (info->gconf_client, NMI_GCONF_WIRELESS_NETWORKS_PATH, NULL); + element = dir_list = gconf_client_all_dirs (applet->gconf_client, GCONF_PATH_WIRELESS_NETWORKS, NULL); if (!dir_list) { - reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "NoNetworks", + reply_message = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "NoNetworks", "There were are no wireless networks stored."); } else @@ -301,7 +200,7 @@ static DBusMessage *nmi_dbus_get_networks (NMIAppInfo *info, DBusMessage *messag GConfValue *value; g_snprintf (&key[0], 99, "%s/essid", (char *)(element->data)); - value = gconf_client_get (info->gconf_client, key, NULL); + value = gconf_client_get (applet->gconf_client, key, NULL); if (value && gconf_value_get_string (value)) { const gchar *essid; @@ -321,7 +220,7 @@ static DBusMessage *nmi_dbus_get_networks (NMIAppInfo *info, DBusMessage *messag if (!value_added) { dbus_message_unref (reply_message); - reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "NoNetworks", + reply_message = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "NoNetworks", "There were are no wireless networks stored."); } } @@ -336,7 +235,7 @@ static DBusMessage *nmi_dbus_get_networks (NMIAppInfo *info, DBusMessage *messag * Returns the properties of a specific wireless network from gconf * */ -static DBusMessage *nmi_dbus_get_network_properties (NMIAppInfo *info, DBusMessage *message) +static DBusMessage *nmi_dbus_get_network_properties (NMWirelessApplet *applet, DBusMessage *message) { DBusMessage *reply = NULL; gchar *gconf_key = NULL; @@ -355,7 +254,7 @@ static DBusMessage *nmi_dbus_get_network_properties (NMIAppInfo *info, DBusMessa gboolean trusted = FALSE; NMDeviceAuthMethod auth_method = NM_DEVICE_AUTH_METHOD_UNKNOWN; - g_return_val_if_fail (info != NULL, NULL); + g_return_val_if_fail (applet != NULL, NULL); g_return_val_if_fail (message != NULL, NULL); dbus_error_init (&error); @@ -363,7 +262,7 @@ static DBusMessage *nmi_dbus_get_network_properties (NMIAppInfo *info, DBusMessa || !nmi_network_type_valid (type) || (strlen (network) <= 0)) { - reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments", + reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments", "NetworkManagerInfo::getNetworkProperties called with invalid arguments."); return (reply); } @@ -371,8 +270,8 @@ static DBusMessage *nmi_dbus_get_network_properties (NMIAppInfo *info, DBusMessa escaped_network = gconf_escape_key (network, strlen (network)); /* Grab essid key for our access point from GConf */ - gconf_key = g_strdup_printf ("%s/%s/essid", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); - if ((value = gconf_client_get (info->gconf_client, gconf_key, NULL))) + gconf_key = g_strdup_printf ("%s/%s/essid", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); + if ((value = gconf_client_get (applet->gconf_client, gconf_key, NULL))) { essid = g_strdup (gconf_value_get_string (value)); gconf_value_free (value); @@ -380,8 +279,8 @@ static DBusMessage *nmi_dbus_get_network_properties (NMIAppInfo *info, DBusMessa g_free (gconf_key); /* Grab timestamp key for our access point from GConf */ - gconf_key = g_strdup_printf ("%s/%s/timestamp", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); - if ((value = gconf_client_get (info->gconf_client, gconf_key, NULL))) + gconf_key = g_strdup_printf ("%s/%s/timestamp", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); + if ((value = gconf_client_get (applet->gconf_client, gconf_key, NULL))) { timestamp = gconf_value_get_int (value); gconf_value_free (value); @@ -389,8 +288,8 @@ static DBusMessage *nmi_dbus_get_network_properties (NMIAppInfo *info, DBusMessa g_free (gconf_key); /* Grab user-key key for our access point from GConf */ - gconf_key = g_strdup_printf ("%s/%s/key", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); - if ((value = gconf_client_get (info->gconf_client, gconf_key, NULL))) + gconf_key = g_strdup_printf ("%s/%s/key", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); + if ((value = gconf_client_get (applet->gconf_client, gconf_key, NULL))) { key = g_strdup (gconf_value_get_string (value)); gconf_value_free (value); @@ -399,8 +298,8 @@ static DBusMessage *nmi_dbus_get_network_properties (NMIAppInfo *info, DBusMessa key = g_strdup (""); g_free (gconf_key); - gconf_key = g_strdup_printf ("%s/%s/key_type", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); - if ((value = gconf_client_get (info->gconf_client, gconf_key, NULL))) + gconf_key = g_strdup_printf ("%s/%s/key_type", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); + if ((value = gconf_client_get (applet->gconf_client, gconf_key, NULL))) { key_type = gconf_value_get_int (value); gconf_value_free (value); @@ -408,8 +307,8 @@ static DBusMessage *nmi_dbus_get_network_properties (NMIAppInfo *info, DBusMessa g_free (gconf_key); /* Grab the network's last authentication mode, if known */ - gconf_key = g_strdup_printf ("%s/%s/auth_method", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); - if ((value = gconf_client_get (info->gconf_client, gconf_key, NULL))) + gconf_key = g_strdup_printf ("%s/%s/auth_method", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); + if ((value = gconf_client_get (applet->gconf_client, gconf_key, NULL))) { auth_method = gconf_value_get_int (value); gconf_value_free (value); @@ -417,8 +316,8 @@ static DBusMessage *nmi_dbus_get_network_properties (NMIAppInfo *info, DBusMessa g_free (gconf_key); /* Grab the network's trusted status */ - gconf_key = g_strdup_printf ("%s/%s/trusted", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); - if ((value = gconf_client_get (info->gconf_client, gconf_key, NULL))) + gconf_key = g_strdup_printf ("%s/%s/trusted", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); + if ((value = gconf_client_get (applet->gconf_client, gconf_key, NULL))) { trusted = gconf_value_get_bool (value); gconf_value_free (value); @@ -426,25 +325,25 @@ static DBusMessage *nmi_dbus_get_network_properties (NMIAppInfo *info, DBusMessa g_free (gconf_key); /* Grab the list of stored AP MAC addresses */ - gconf_key = g_strdup_printf ("%s/%s/addresses", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); - ap_addrs_value = gconf_client_get (info->gconf_client, gconf_key, NULL); + gconf_key = g_strdup_printf ("%s/%s/addresses", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); + ap_addrs_value = gconf_client_get (applet->gconf_client, gconf_key, NULL); g_free (gconf_key); if (!essid || (timestamp < 0) || (key_type < 0)) { if (!essid) { - reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadNetworkData", + reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadNetworkData", "NetworkManagerInfo::getNetworkProperties could not access essid for network '%s'", network); } else if (timestamp < 0) { - reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadNetworkData", + reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadNetworkData", "NetworkManagerInfo::getNetworkProperties could not access timestamp for network '%s'", network); } else if (key_type < 0) { - reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadNetworkData", + reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadNetworkData", "NetworkManagerInfo::getNetworkProperties could not access key_type for network '%s'", network); } } @@ -533,33 +432,33 @@ void nmi_dbus_signal_update_vpn_connection (DBusConnection *connection, const ch * of a string array in a dbus message. * */ -static DBusMessage *nmi_dbus_get_vpn_connections (NMIAppInfo *info, DBusMessage *message) +static DBusMessage *nmi_dbus_get_vpn_connections (NMWirelessApplet *applet, DBusMessage *message) { GSList *dir_list = NULL; GSList *element = NULL; DBusError error; - DBusMessage *reply_message = NULL; + DBusMessage *reply = NULL; DBusMessageIter iter; DBusMessageIter iter_array; - g_return_val_if_fail (info != NULL, NULL); + g_return_val_if_fail (applet != NULL, NULL); g_return_val_if_fail (message != NULL, NULL); dbus_error_init (&error); /* List all VPN connections that gconf knows about */ - element = dir_list = gconf_client_all_dirs (info->gconf_client, NMI_GCONF_VPN_CONNECTIONS_PATH, NULL); + element = dir_list = gconf_client_all_dirs (applet->gconf_client, GCONF_PATH_VPN_CONNECTIONS, NULL); if (!dir_list) { - reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "NoVPNConnections", + reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "NoVPNConnections", "There are no VPN connections stored."); } else { gboolean value_added = FALSE; - reply_message = dbus_message_new_method_return (message); - dbus_message_iter_init_append (reply_message, &iter); + reply = dbus_message_new_method_return (message); + dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &iter_array); /* Append the essid of every allowed or ignored access point we know of @@ -571,7 +470,7 @@ static DBusMessage *nmi_dbus_get_vpn_connections (NMIAppInfo *info, DBusMessage GConfValue *value; g_snprintf (&key[0], 99, "%s/name", (char *)(element->data)); - value = gconf_client_get (info->gconf_client, key, NULL); + value = gconf_client_get (applet->gconf_client, key, NULL); if (value && gconf_value_get_string (value)) { const gchar *essid; @@ -590,13 +489,13 @@ static DBusMessage *nmi_dbus_get_vpn_connections (NMIAppInfo *info, DBusMessage if (!value_added) { - dbus_message_unref (reply_message); - reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "NoVPNConnections", + dbus_message_unref (reply); + reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "NoVPNConnections", "There are no VPN connections stored."); } } - return (reply_message); + return (reply); } @@ -606,7 +505,7 @@ static DBusMessage *nmi_dbus_get_vpn_connections (NMIAppInfo *info, DBusMessage * Returns the properties of a specific VPN connection from gconf * */ -static DBusMessage *nmi_dbus_get_vpn_connection_properties (NMIAppInfo *info, DBusMessage *message) +static DBusMessage *nmi_dbus_get_vpn_connection_properties (NMWirelessApplet *applet, DBusMessage *message) { DBusMessage *reply = NULL; gchar *gconf_key = NULL; @@ -618,14 +517,14 @@ static DBusMessage *nmi_dbus_get_vpn_connection_properties (NMIAppInfo *info, DB char *service_name = NULL; char *user_name = NULL; - g_return_val_if_fail (info != NULL, NULL); + g_return_val_if_fail (applet != NULL, NULL); g_return_val_if_fail (message != NULL, NULL); dbus_error_init (&error); if ( !dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &vpn_connection, DBUS_TYPE_INVALID) || (strlen (vpn_connection) <= 0)) { - reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments", + reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments", "NetworkManagerInfo::getVPNConnectionProperties called with invalid arguments."); return (reply); } @@ -633,8 +532,8 @@ static DBusMessage *nmi_dbus_get_vpn_connection_properties (NMIAppInfo *info, DB escaped_name = gconf_escape_key (vpn_connection, strlen (vpn_connection)); /* User-visible name of connection */ - gconf_key = g_strdup_printf ("%s/%s/name", NMI_GCONF_VPN_CONNECTIONS_PATH, escaped_name); - if ((value = gconf_client_get (info->gconf_client, gconf_key, NULL))) + gconf_key = g_strdup_printf ("%s/%s/name", GCONF_PATH_VPN_CONNECTIONS, escaped_name); + if ((value = gconf_client_get (applet->gconf_client, gconf_key, NULL))) { name = g_strdup (gconf_value_get_string (value)); gconf_value_free (value); @@ -642,8 +541,8 @@ static DBusMessage *nmi_dbus_get_vpn_connection_properties (NMIAppInfo *info, DB g_free (gconf_key); /* Service name of connection */ - gconf_key = g_strdup_printf ("%s/%s/service_name", NMI_GCONF_VPN_CONNECTIONS_PATH, escaped_name); - if ((value = gconf_client_get (info->gconf_client, gconf_key, NULL))) + gconf_key = g_strdup_printf ("%s/%s/service_name", GCONF_PATH_VPN_CONNECTIONS, escaped_name); + if ((value = gconf_client_get (applet->gconf_client, gconf_key, NULL))) { service_name = g_strdup (gconf_value_get_string (value)); gconf_value_free (value); @@ -651,8 +550,8 @@ static DBusMessage *nmi_dbus_get_vpn_connection_properties (NMIAppInfo *info, DB g_free (gconf_key); /* User name of connection */ - gconf_key = g_strdup_printf ("%s/%s/user_name", NMI_GCONF_VPN_CONNECTIONS_PATH, escaped_name); - if ((value = gconf_client_get (info->gconf_client, gconf_key, NULL))) + gconf_key = g_strdup_printf ("%s/%s/user_name", GCONF_PATH_VPN_CONNECTIONS, escaped_name); + if ((value = gconf_client_get (applet->gconf_client, gconf_key, NULL))) { user_name = g_strdup (gconf_value_get_string (value)); gconf_value_free (value); @@ -661,17 +560,17 @@ static DBusMessage *nmi_dbus_get_vpn_connection_properties (NMIAppInfo *info, DB if (!name) { - reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData", + reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData", "NetworkManagerInfo::getVPNConnectionProperties could not access the name for connection '%s'", vpn_connection); } else if (!service_name) { - reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData", + reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData", "NetworkManagerInfo::getVPNConnectionProperties could not access the service name for connection '%s'", vpn_connection); } else if (!user_name) { - reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData", + reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData", "NetworkManagerInfo::getVPNConnectionProperties could not access the user name for connection '%s'", vpn_connection); } else @@ -700,7 +599,7 @@ static DBusMessage *nmi_dbus_get_vpn_connection_properties (NMIAppInfo *info, DB * Returns vpn-daemon specific properties for a particular VPN connection. * */ -static DBusMessage *nmi_dbus_get_vpn_connection_vpn_data (NMIAppInfo *info, DBusMessage *message) +static DBusMessage *nmi_dbus_get_vpn_connection_vpn_data (NMWirelessApplet *applet, DBusMessage *message) { DBusMessage *reply = NULL; gchar *gconf_key = NULL; @@ -712,14 +611,14 @@ static DBusMessage *nmi_dbus_get_vpn_connection_vpn_data (NMIAppInfo *info, DBus DBusMessageIter iter, array_iter; GSList *elt; - g_return_val_if_fail (info != NULL, NULL); + g_return_val_if_fail (applet != NULL, NULL); g_return_val_if_fail (message != NULL, NULL); dbus_error_init (&error); if ( !dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID) || (strlen (name) <= 0)) { - reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments", + reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments", "NetworkManagerInfo::getVPNConnectionVPNData called with invalid arguments."); return reply; } @@ -727,10 +626,10 @@ static DBusMessage *nmi_dbus_get_vpn_connection_vpn_data (NMIAppInfo *info, DBus escaped_name = gconf_escape_key (name, strlen (name)); /* User-visible name of connection */ - gconf_key = g_strdup_printf ("%s/%s/name", NMI_GCONF_VPN_CONNECTIONS_PATH, escaped_name); - if (!(value = gconf_client_get (info->gconf_client, gconf_key, NULL))) + gconf_key = g_strdup_printf ("%s/%s/name", GCONF_PATH_VPN_CONNECTIONS, escaped_name); + if (!(value = gconf_client_get (applet->gconf_client, gconf_key, NULL))) { - reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData", + reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData", "NetworkManagerInfo::getVPNConnectionVPNData could not access the name for connection '%s'", name); return reply; } @@ -738,12 +637,12 @@ static DBusMessage *nmi_dbus_get_vpn_connection_vpn_data (NMIAppInfo *info, DBus g_free (gconf_key); /* Grab vpn-daemon specific data */ - gconf_key = g_strdup_printf ("%s/%s/vpn_data", NMI_GCONF_VPN_CONNECTIONS_PATH, escaped_name); - if (!(vpn_data_value = gconf_client_get (info->gconf_client, gconf_key, NULL)) + gconf_key = g_strdup_printf ("%s/%s/vpn_data", GCONF_PATH_VPN_CONNECTIONS, escaped_name); + if (!(vpn_data_value = gconf_client_get (applet->gconf_client, gconf_key, NULL)) || !(vpn_data_value->type == GCONF_VALUE_LIST) || !(gconf_value_get_list_type (vpn_data_value) == GCONF_VALUE_STRING)) { - reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData", + reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData", "NetworkManagerInfo::getVPNConnectionVPNData could not access the VPN data for connection '%s'", name); if (vpn_data_value) gconf_value_free (vpn_data_value); @@ -777,7 +676,7 @@ static DBusMessage *nmi_dbus_get_vpn_connection_vpn_data (NMIAppInfo *info, DBus * Update a network's authentication method entry in gconf * */ -static DBusMessage *nmi_dbus_update_network_auth_method (NMIAppInfo *info, DBusMessage *message) +static DBusMessage *nmi_dbus_update_network_auth_method (NMWirelessApplet *applet, DBusMessage *message) { DBusMessage *reply_message = NULL; char *network = NULL; @@ -787,7 +686,7 @@ static DBusMessage *nmi_dbus_update_network_auth_method (NMIAppInfo *info, DBusM DBusError error; char *escaped_network; - g_return_val_if_fail (info != NULL, NULL); + g_return_val_if_fail (applet != NULL, NULL); g_return_val_if_fail (message != NULL, NULL); dbus_error_init (&error); @@ -795,21 +694,21 @@ static DBusMessage *nmi_dbus_update_network_auth_method (NMIAppInfo *info, DBusM || (strlen (network) <= 0) || (auth_method == NM_DEVICE_AUTH_METHOD_UNKNOWN)) { - reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments", + reply_message = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments", "NetworkManagerInfo::updateNetworkAuthMethod called with invalid arguments."); return (reply_message); } /* Ensure the access point exists in GConf */ escaped_network = gconf_escape_key (network, strlen (network)); - key = g_strdup_printf ("%s/%s/essid", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); - value = gconf_client_get (info->gconf_client, key, NULL); + key = g_strdup_printf ("%s/%s/essid", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); + value = gconf_client_get (applet->gconf_client, key, NULL); g_free (key); if (value && (value->type == GCONF_VALUE_STRING)) { - key = g_strdup_printf ("%s/%s/auth_method", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); - gconf_client_set_int (info->gconf_client, key, auth_method, NULL); + key = g_strdup_printf ("%s/%s/auth_method", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); + gconf_client_set_int (applet->gconf_client, key, auth_method, NULL); g_free (key); } if (value) @@ -827,7 +726,7 @@ static DBusMessage *nmi_dbus_update_network_auth_method (NMIAppInfo *info, DBusM * Add an AP's MAC address to a wireless network entry in gconf * */ -static DBusMessage *nmi_dbus_add_network_address (NMIAppInfo *info, DBusMessage *message) +static DBusMessage *nmi_dbus_add_network_address (NMWirelessApplet *applet, DBusMessage *message) { DBusMessage *reply_message = NULL; char *network = NULL; @@ -840,7 +739,7 @@ static DBusMessage *nmi_dbus_add_network_address (NMIAppInfo *info, DBusMessage GSList *new_mac_list = NULL; gboolean found = FALSE; - g_return_val_if_fail (info != NULL, NULL); + g_return_val_if_fail (applet != NULL, NULL); g_return_val_if_fail (message != NULL, NULL); dbus_error_init (&error); @@ -850,39 +749,39 @@ static DBusMessage *nmi_dbus_add_network_address (NMIAppInfo *info, DBusMessage || !addr || (strlen (addr) < 11)) { - reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments", + reply_message = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments", "NetworkManagerInfo::addNetworkAddress called with invalid arguments."); return (reply_message); } /* Force-set the essid too so that we have a semi-complete network entry */ escaped_network = gconf_escape_key (network, strlen (network)); - key = g_strdup_printf ("%s/%s/essid", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); - value = gconf_client_get (info->gconf_client, key, NULL); + key = g_strdup_printf ("%s/%s/essid", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); + value = gconf_client_get (applet->gconf_client, key, NULL); /* If the network doesn't already exist in GConf, add it and set its timestamp to now. */ if (!value || (!value && (value->type == GCONF_VALUE_STRING))) { /* Set the essid of the network. */ - gconf_client_set_string (info->gconf_client, key, network, NULL); + gconf_client_set_string (applet->gconf_client, key, network, NULL); g_free (key); /* Update timestamp on network */ - key = g_strdup_printf ("%s/%s/timestamp", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); - gconf_client_set_int (info->gconf_client, key, time (NULL), NULL); + key = g_strdup_printf ("%s/%s/timestamp", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); + gconf_client_set_int (applet->gconf_client, key, time (NULL), NULL); } g_free (key); /* Get current list of access point MAC addresses for this AP from GConf */ - key = g_strdup_printf ("%s/%s/addresses", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); - value = gconf_client_get (info->gconf_client, key, NULL); + key = g_strdup_printf ("%s/%s/addresses", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); + value = gconf_client_get (applet->gconf_client, key, NULL); g_free (escaped_network); if (value && (value->type == GCONF_VALUE_LIST) && (gconf_value_get_list_type (value) == GCONF_VALUE_STRING)) { GSList *elem; - new_mac_list = gconf_client_get_list (info->gconf_client, key, GCONF_VALUE_STRING, NULL); + new_mac_list = gconf_client_get_list (applet->gconf_client, key, GCONF_VALUE_STRING, NULL); gconf_value_free (value); /* Ensure that the MAC isn't already in the list */ @@ -902,7 +801,7 @@ static DBusMessage *nmi_dbus_add_network_address (NMIAppInfo *info, DBusMessage if (!found) { new_mac_list = g_slist_append (new_mac_list, g_strdup (addr)); - gconf_client_set_list (info->gconf_client, key, GCONF_VALUE_STRING, new_mac_list, NULL); + gconf_client_set_list (applet->gconf_client, key, GCONF_VALUE_STRING, new_mac_list, NULL); } /* Free the list, since gconf_client_set_list deep-copies it */ @@ -916,45 +815,33 @@ static DBusMessage *nmi_dbus_add_network_address (NMIAppInfo *info, DBusMessage /* - * nmi_dbus_nmi_message_handler + * nmi_dbus_info_message_handler * - * Responds to requests for our services + * Respond to requests against the NetworkManagerInfo object * */ -static DBusHandlerResult nmi_dbus_nmi_message_handler (DBusConnection *connection, DBusMessage *message, void *user_data) +DBusHandlerResult nmi_dbus_info_message_handler (DBusConnection *connection, DBusMessage *message, void *user_data) { - const char *method; - const char *path; - NMIAppInfo *info = (NMIAppInfo *)user_data; - DBusMessage *reply_message = NULL; + const char * method; + const char * path; + NMWirelessApplet * applet = (NMWirelessApplet *)user_data; + DBusMessage * reply = NULL; - g_return_val_if_fail (info != NULL, DBUS_HANDLER_RESULT_HANDLED); + g_return_val_if_fail (applet != NULL, DBUS_HANDLER_RESULT_HANDLED); method = dbus_message_get_member (message); path = dbus_message_get_path (message); -/* nm_warning ("nmi_dbus_nmi_message_handler() got method %s for path %s", method, path);*/ +/* nm_warning ("nmi_dbus_nmi_message_handler() got method %s for path %s", method, path); */ if (strcmp ("getKeyForNetwork", method) == 0) - { - GtkWidget *dialog = glade_xml_get_widget (info->passphrase_dialog, "passphrase_dialog"); - if (dialog && !GTK_WIDGET_VISIBLE (dialog)) - nmi_dbus_get_key_for_network (info, message); - } + reply = nmi_dbus_get_key_for_network (applet, message); else if (strcmp ("cancelGetKeyForNetwork", method) == 0) - { - GtkWidget *dialog = glade_xml_get_widget (info->passphrase_dialog, "passphrase_dialog"); - if (dialog && GTK_WIDGET_VISIBLE (dialog)) - nmi_passphrase_dialog_cancel (info); - } - else if (strcmp ("getVPNUserPass", method) == 0) - { - nmi_dbus_get_vpn_userpass (info, message); - } + nmi_passphrase_dialog_cancel (applet->passphrase_dialog); else if (strcmp ("networkNotFound", method) == 0) { - const char *network; - DBusError error; + const char * network; + DBusError error; dbus_error_init (&error); if (dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &network, DBUS_TYPE_INVALID)) @@ -963,8 +850,8 @@ static DBusHandlerResult nmi_dbus_nmi_message_handler (DBusConnection *connectio char *text; dbus_error_free (&error); - text = g_strdup_printf ( "The requested wireless network '%s' does not appear to be in range. " - "A different wireless network will be used if any are available.", network); + text = g_strdup_printf (_("The requested wireless network '%s' does not appear to be in range. " + "A different wireless network will be used if any are available."), network); dialog = GTK_DIALOG (gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, text, NULL)); gtk_dialog_run (dialog); @@ -972,180 +859,26 @@ static DBusHandlerResult nmi_dbus_nmi_message_handler (DBusConnection *connectio } } else if (strcmp ("getNetworks", method) == 0) - reply_message = nmi_dbus_get_networks (info, message); + reply = nmi_dbus_get_networks (applet, message); else if (strcmp ("getNetworkProperties", method) == 0) - reply_message = nmi_dbus_get_network_properties (info, message); + reply = nmi_dbus_get_network_properties (applet, message); else if (strcmp ("updateNetworkAuthMethod", method) == 0) - nmi_dbus_update_network_auth_method (info, message); + nmi_dbus_update_network_auth_method (applet, message); else if (strcmp ("addNetworkAddress", method) == 0) - nmi_dbus_add_network_address (info, message); + nmi_dbus_add_network_address (applet, message); else if (strcmp ("getVPNConnections", method) == 0) - reply_message = nmi_dbus_get_vpn_connections (info, message); + reply = nmi_dbus_get_vpn_connections (applet, message); else if (strcmp ("getVPNConnectionProperties", method) == 0) - reply_message = nmi_dbus_get_vpn_connection_properties (info, message); + reply = nmi_dbus_get_vpn_connection_properties (applet, message); else if (strcmp ("getVPNConnectionVPNData", method) == 0) - reply_message = nmi_dbus_get_vpn_connection_vpn_data (info, message); - else - { - reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "UnknownMethod", - "NetworkManagerInfo knows nothing about the method %s for object %s", method, path); - } + reply = nmi_dbus_get_vpn_connection_vpn_data (applet, message); - if (reply_message) + if (reply) { - dbus_connection_send (connection, reply_message, NULL); - dbus_message_unref (reply_message); + dbus_connection_send (connection, reply, NULL); + dbus_message_unref (reply); } return (DBUS_HANDLER_RESULT_HANDLED); } - -/* - * nmi_dbus_nmi_unregister_handler - * - * Nothing happens here. - * - */ -void nmi_dbus_nmi_unregister_handler (DBusConnection *connection, void *user_data) -{ - /* do nothing */ -} - -gboolean shutdown_callback (gpointer data) -{ - gtk_main_quit (); - return FALSE; -} - -static DBusHandlerResult nmi_dbus_filter (DBusConnection *connection, DBusMessage *message, void *user_data) -{ - gboolean handled = FALSE; - NMIAppInfo *info = (NMIAppInfo *) user_data; - gboolean appeared = FALSE; - gboolean disappeared = FALSE; - - g_return_val_if_fail (info != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); - - if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "WirelessNetworkAppeared")) - appeared = TRUE; - else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "WirelessNetworkDisappeared")) - disappeared = TRUE; - else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceActivationFailed")) - { - char *dev = NULL; - char *net = NULL; - DBusError error; - - dbus_error_init (&error); - if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &dev, DBUS_TYPE_STRING, &net, DBUS_TYPE_INVALID)) - { - if (dbus_error_is_set (&error)) - dbus_error_free (&error); - dbus_error_init (&error); - dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &dev, DBUS_TYPE_INVALID); - } - if (dbus_error_is_set (&error)) - dbus_error_free (&error); - if (dev && net) - { - char *string = g_strdup_printf ("Connection to the wireless network '%s' failed.\n", net); - nmi_show_warning_dialog (TRUE, string); - g_free (string); - } - else if (dev) - nmi_show_warning_dialog (TRUE, "Connection to the wired network failed.\n"); - - } - - return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED); -} - -#if 0 -/* - * nmi_dbus_nm_is_running - * - * Ask dbus whether or not NetworkManager is running - * - */ -static gboolean nmi_dbus_nm_is_running (DBusConnection *connection) -{ - DBusError error; - gboolean exists; - - g_return_val_if_fail (connection != NULL, FALSE); - - dbus_error_init (&error); - exists = dbus_bus_name_has_owner (connection, NM_DBUS_SERVICE, &error); - if (dbus_error_is_set (&error)) - dbus_error_free (&error); - return (exists); -} -#endif - - -/* - * nmi_dbus_service_init - * - * Connect to the system messagebus and register ourselves as a service. - * - */ -int nmi_dbus_service_init (DBusConnection *dbus_connection, NMIAppInfo *info) -{ - DBusError dbus_error; - DBusObjectPathVTable nmi_vtable = { &nmi_dbus_nmi_unregister_handler, &nmi_dbus_nmi_message_handler, NULL, NULL, NULL, NULL }; - int acquisition; - - dbus_error_init (&dbus_error); - acquisition = dbus_bus_request_name (dbus_connection, NMI_DBUS_SERVICE, - DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT, - &dbus_error); - if (dbus_error_is_set (&dbus_error)) - { - nm_warning ("nmi_dbus_service_init() could not acquire its service. dbus_bus_acquire_service() says: '%s'", dbus_error.message); - dbus_error_free (&dbus_error); - return (-1); - } - if (acquisition == DBUS_REQUEST_NAME_REPLY_EXISTS) { - exit (0); - } - -#if 0 - if (!nmi_dbus_nm_is_running (dbus_connection)) - return (-1); -#endif - - if (!dbus_connection_register_object_path (dbus_connection, NMI_DBUS_PATH, &nmi_vtable, info)) - { - nm_warning ("nmi_dbus_service_init() could not register a handler for NetworkManagerInfo. Not enough memory?"); - return (-1); - } - - if (!dbus_connection_add_filter (dbus_connection, nmi_dbus_filter, info, NULL)) - return (-1); - - dbus_error_init (&dbus_error); - dbus_bus_add_match (dbus_connection, - "type='signal'," - "interface='" NM_DBUS_INTERFACE "'," - "sender='" NM_DBUS_SERVICE "'," - "path='" NM_DBUS_PATH "'", &dbus_error); - if (dbus_error_is_set (&dbus_error)) - { - dbus_error_free (&dbus_error); - return (-1); - } - - dbus_bus_add_match(dbus_connection, - "type='signal'," - "interface='" DBUS_INTERFACE_DBUS "'," - "sender='" DBUS_SERVICE_DBUS "'", - &dbus_error); - if (dbus_error_is_set (&dbus_error)) - { - dbus_error_free (&dbus_error); - return (-1); - } - - return (0); -} diff --git a/info-daemon/NetworkManagerInfoPassphraseDialog.h b/gnome/applet/applet-dbus-info.h similarity index 56% rename from info-daemon/NetworkManagerInfoPassphraseDialog.h rename to gnome/applet/applet-dbus-info.h index 9d13f7d62..34a08ea6c 100644 --- a/info-daemon/NetworkManagerInfoPassphraseDialog.h +++ b/gnome/applet/applet-dbus-info.h @@ -1,5 +1,5 @@ -/* NetworkManagerInfo -- Manage allowed access points and provide a UI - * for WEP key entry +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ +/* NetworkManager Wireless Applet -- Display wireless access points and allow user control * * Dan Williams * @@ -17,18 +17,18 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * (C) Copyright 2004 Red Hat, Inc. + * (C) Copyright 2004-2005 Red Hat, Inc. */ -#ifndef NETWORK_MANAGER_INFO_PASSPHRASE_DIALOG_H -#define NETWORK_MANAGER_INFO_PASSPHRASE_DIALOG_H +#ifndef APPLET_DBUS_INFO_H +#define APPLET_DBUS_INFO_H -#include "NetworkManagerInfo.h" +#include +#include "nm-device.h" +#include "wireless-network.h" -int nmi_passphrase_dialog_init (NMIAppInfo *info); +DBusHandlerResult nmi_dbus_info_message_handler (DBusConnection *connection, DBusMessage *message, void *user_data); -void nmi_passphrase_dialog_show (const char *device, const char *network, NMIAppInfo *info); - -void nmi_passphrase_dialog_cancel (NMIAppInfo *info); +void nmi_dbus_return_user_key (DBusConnection *connection, DBusMessage *message, const char *passphrase, const int key_type); #endif diff --git a/gnome/applet/applet-dbus-vpn.c b/gnome/applet/applet-dbus-vpn.c new file mode 100644 index 000000000..10c62e192 --- /dev/null +++ b/gnome/applet/applet-dbus-vpn.c @@ -0,0 +1,504 @@ +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ +/* NetworkManager Wireless Applet -- Display wireless access points and allow user control + * + * Dan Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * (C) Copyright 2004-2005 Red Hat, Inc. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include "applet-dbus-vpn.h" +#include "applet-dbus.h" +#include "applet.h" +#include "vpn-connection.h" +#include "nm-utils.h" + +static void nmwa_free_gui_vpn_connections (NMWirelessApplet *applet); +static void nmwa_free_dbus_vpn_connections (NMWirelessApplet *applet); +static void nmwa_dbus_vpn_schedule_copy (NMWirelessApplet *applet); + +/* + * nmwa_dbus_vpn_get_active_vpn_connection_cb + * + * Callback from nmwa_dbus_vpn_get_active_vpn_connection + * + */ +void nmwa_dbus_vpn_get_active_vpn_connection_cb (DBusPendingCall *pcall, void *user_data) +{ + DBusMessage * reply; + NMWirelessApplet * applet = (NMWirelessApplet *) user_data; + const char * act_vpn; + + g_return_if_fail (pcall != NULL); + g_return_if_fail (applet != NULL); + + dbus_pending_call_ref (pcall); + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if ( dbus_message_is_error (reply, NM_DBUS_NO_ACTIVE_VPN_CONNECTION) + || dbus_message_is_error (reply, NM_DBUS_NO_VPN_CONNECTIONS)) + { + dbus_message_unref (reply); + goto out; + } + + if (dbus_message_get_args (reply, NULL, DBUS_TYPE_OBJECT_PATH, &act_vpn, DBUS_TYPE_INVALID)) + { + g_free (applet->dbus_active_vpn_name); + applet->dbus_active_vpn_name = g_strdup (act_vpn); + } + dbus_message_unref (reply); + +out: + applet->vpn_pending_call_list = g_slist_remove (applet->vpn_pending_call_list, pcall); + nmwa_dbus_vpn_schedule_copy (applet); + + dbus_pending_call_unref (pcall); +} + + +/* + * nmwa_dbus_vpn_get_active_vpn_connection + * + * Get the active VPN connection from NetworkManager + * + */ +void nmwa_dbus_vpn_get_active_vpn_connection (NMWirelessApplet *applet) +{ + DBusMessage * message; + DBusPendingCall * pcall = NULL; + + g_return_if_fail (applet != NULL); + + if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH_VPN, NM_DBUS_INTERFACE_VPN, "getActiveVPNConnection"))) + { + dbus_connection_send_with_reply (applet->connection, message, &pcall, -1); + dbus_message_unref (message); + if (pcall) + { + dbus_pending_call_set_notify (pcall, nmwa_dbus_vpn_get_active_vpn_connection_cb, applet, NULL); + applet->vpn_pending_call_list = g_slist_append (applet->vpn_pending_call_list, pcall); + } + } +} + + +typedef struct VpnPropsCBData +{ + NMWirelessApplet * applet; + char * name; +} VpnPropsCBData; + +void free_vpn_props_cb_data (VpnPropsCBData *data) +{ + if (data) + { + g_free (data->name); + memset (data, 0, sizeof (VpnPropsCBData)); + g_free (data); + } +} + +/* + * nmwa_dbus_vpn_properties_cb + * + * Callback for each VPN connection we called "getVPNConnectionProperties" on. + * + */ +void nmwa_dbus_vpn_properties_cb (DBusPendingCall *pcall, void *user_data) +{ + DBusMessage * reply; + VpnPropsCBData * cb_data = user_data; + NMWirelessApplet * applet; + const char * name; + const char * user_name; + + g_return_if_fail (pcall != NULL); + g_return_if_fail (cb_data != NULL); + g_return_if_fail (cb_data->applet != NULL); + g_return_if_fail (cb_data->name != NULL); + + dbus_pending_call_ref (pcall); + + applet = cb_data->applet; + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) + { + if (dbus_message_is_error (reply, NM_DBUS_INVALID_VPN_CONNECTION)) + { + VPNConnection * vpn; + + if ((vpn = nmwa_vpn_connection_find_by_name (applet->dbus_vpn_connections, cb_data->name))) + { + applet->dbus_vpn_connections = g_slist_remove (applet->dbus_vpn_connections, vpn); + nmwa_vpn_connection_unref (vpn); + if (applet->dbus_active_vpn == vpn); + { + nmwa_vpn_connection_unref (vpn); + applet->dbus_active_vpn = NULL; + } + } + } + + dbus_message_unref (reply); + goto out; + } + + if (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &user_name, DBUS_TYPE_INVALID)) + { + VPNConnection * vpn; + + /* If its already there, update the user_name, otherwise add it to the list */ + if ((vpn = nmwa_vpn_connection_find_by_name (applet->dbus_vpn_connections, name))) + nmwa_vpn_connection_set_user_name (vpn, user_name); + else + { + vpn = nmwa_vpn_connection_new (name); + nmwa_vpn_connection_set_user_name (vpn, user_name); + applet->dbus_vpn_connections = g_slist_append (applet->dbus_vpn_connections, vpn); + } + } + dbus_message_unref (reply); + +out: + applet->vpn_pending_call_list = g_slist_remove (applet->vpn_pending_call_list, pcall); + nmwa_dbus_vpn_schedule_copy (applet); + + dbus_pending_call_unref (pcall); +} + + +/* + * nmwa_dbus_vpn_update_one_vpn_connection + * + * Get properties on one VPN connection + * + */ +void nmwa_dbus_vpn_update_one_vpn_connection (NMWirelessApplet *applet, const char *vpn_name) +{ + DBusMessage * message; + DBusPendingCall * pcall = NULL; + + g_return_if_fail (applet != NULL); + g_return_if_fail (vpn_name != NULL); + + nmwa_dbus_vpn_get_active_vpn_connection (applet); + + if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH_VPN, NM_DBUS_INTERFACE_VPN, "getVPNConnectionProperties"))) + { + dbus_message_append_args (message, DBUS_TYPE_STRING, &vpn_name, DBUS_TYPE_INVALID); + dbus_connection_send_with_reply (applet->connection, message, &pcall, -1); + dbus_message_unref (message); + if (pcall) + { + VpnPropsCBData * cb_data = g_malloc0 (sizeof (VpnPropsCBData)); + + cb_data->applet = applet; + cb_data->name = g_strdup (vpn_name); + dbus_pending_call_set_notify (pcall, nmwa_dbus_vpn_properties_cb, cb_data, (DBusFreeFunction) free_vpn_props_cb_data); + applet->vpn_pending_call_list = g_slist_append (applet->vpn_pending_call_list, pcall); + } + } +} + + +/* + * nmwa_dbus_vpn_update_vpn_connections_cb + * + * nmwa_dbus_vpn_update_vpn_connections callback. + * + */ +void nmwa_dbus_vpn_update_vpn_connections_cb (DBusPendingCall *pcall, void *user_data) +{ + DBusMessage * reply; + NMWirelessApplet * applet = (NMWirelessApplet *) user_data; + char ** vpn_names; + int num_vpn_names; + + g_return_if_fail (pcall != NULL); + g_return_if_fail (applet != NULL); + + dbus_pending_call_ref (pcall); + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (dbus_message_is_error (reply, NM_DBUS_NO_VPN_CONNECTIONS)) + { + dbus_message_unref (reply); + goto out; + } + + if (dbus_message_get_args (reply, NULL, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &vpn_names, &num_vpn_names, DBUS_TYPE_INVALID)) + { + char ** item; + + /* For each connection, fire off a "getVPNConnectionProperties" call */ + for (item = vpn_names; *item; item++) + nmwa_dbus_vpn_update_one_vpn_connection (applet, *item); + + dbus_free_string_array (vpn_names); + } + dbus_message_unref (reply); + +out: + applet->vpn_pending_call_list = g_slist_remove (applet->vpn_pending_call_list, pcall); + nmwa_dbus_vpn_schedule_copy (applet); + + dbus_pending_call_unref (pcall); +} + + +/* + * nmwa_dbus_vpn_update_vpn_connections + * + * Do a full update of vpn connections from NetworkManager + * + */ +void nmwa_dbus_vpn_update_vpn_connections (NMWirelessApplet *applet) +{ + DBusMessage * message; + DBusPendingCall * pcall; + + nmwa_free_dbus_vpn_connections (applet); + + nmwa_dbus_vpn_get_active_vpn_connection (applet); + + if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH_VPN, NM_DBUS_INTERFACE_VPN, "getVPNConnections"))) + { + dbus_connection_send_with_reply (applet->connection, message, &pcall, -1); + dbus_message_unref (message); + if (pcall) + { + dbus_pending_call_set_notify (pcall, nmwa_dbus_vpn_update_vpn_connections_cb, applet, NULL); + applet->vpn_pending_call_list = g_slist_append (applet->vpn_pending_call_list, pcall); + } + } +} + + +/* + * nmwa_dbus_vpn_remove_one_vpn_connection + * + * Remove one vpn connection from the list + * + */ +void nmwa_dbus_vpn_remove_one_vpn_connection (NMWirelessApplet *applet, const char *vpn_name) +{ + VPNConnection * vpn; + + g_return_if_fail (applet != NULL); + g_return_if_fail (vpn_name != NULL); + + if ((vpn = nmwa_vpn_connection_find_by_name (applet->dbus_vpn_connections, vpn_name))) + { + applet->dbus_vpn_connections = g_slist_remove (applet->dbus_vpn_connections, vpn); + nmwa_vpn_connection_unref (vpn); + if (applet->dbus_active_vpn == vpn) + { + nmwa_vpn_connection_unref (vpn); + applet->dbus_active_vpn = NULL; + } + nmwa_dbus_vpn_schedule_copy (applet); + } +} + + +static int vpn_copy_idle_id = 0; + +/* + * nmwa_dbus_vpn_connections_lock_and_copy + * + * Copy VPN connections over to gui side. + * + */ +static gboolean nmwa_dbus_vpn_connections_lock_and_copy (NMWirelessApplet *applet) +{ + vpn_copy_idle_id = 0; + + g_return_val_if_fail (applet != NULL, FALSE); + + /* Only copy over if we have a complete data model */ + if (g_slist_length (applet->vpn_pending_call_list) == 0) + { + GSList * elt; + + /* Match up the active vpn with a device in the list */ + if (applet->dbus_active_vpn_name && + (applet->dbus_active_vpn = nmwa_vpn_connection_find_by_name (applet->dbus_vpn_connections, applet->dbus_active_vpn_name))) + nmwa_vpn_connection_ref (applet->dbus_active_vpn); + + /* Now copy the data over to the GUI side */ + g_mutex_lock (applet->data_mutex); + + nmwa_free_gui_vpn_connections (applet); + + /* Deep-copy VPN connections to GUI data model */ + for (elt = applet->dbus_vpn_connections; elt; elt = g_slist_next (elt)) + { + VPNConnection *src_vpn = elt->data; + VPNConnection *new_vpn; + + new_vpn = nmwa_vpn_connection_copy (src_vpn); + if (new_vpn) + { + applet->gui_vpn_connections = g_slist_append (applet->gui_vpn_connections, new_vpn); + if (applet->dbus_active_vpn == src_vpn) + { + nmwa_vpn_connection_ref (new_vpn); + applet->gui_active_vpn = new_vpn; + } + } + } + + g_mutex_unlock (applet->data_mutex); + } + + return FALSE; +} + +/* + * nmwa_dbus_vpn_schedule_copy + * + * Schedule a copy VPN connections over to gui side, batching requests. + * + */ +static void nmwa_dbus_vpn_schedule_copy (NMWirelessApplet *applet) +{ + g_return_if_fail (applet != NULL); + + if (vpn_copy_idle_id == 0) + { + GSource *source = g_idle_source_new (); + + /* We want this idle source to run before any other idle source */ + g_source_set_priority (source, G_PRIORITY_HIGH_IDLE); + g_source_set_callback (source, (GSourceFunc) nmwa_dbus_vpn_connections_lock_and_copy, applet, NULL); + vpn_copy_idle_id = g_source_attach (source, applet->thread_context); + g_source_unref (source); + } +} + + +static void nmwa_free_gui_vpn_connections (NMWirelessApplet *applet) +{ + g_return_if_fail (applet != NULL); + + if (applet->gui_active_vpn) + nmwa_vpn_connection_unref (applet->gui_active_vpn); + applet->gui_active_vpn = NULL; + + if (applet->gui_vpn_connections) + { + g_slist_foreach (applet->gui_vpn_connections, (GFunc) nmwa_vpn_connection_unref, NULL); + g_slist_free (applet->gui_vpn_connections); + applet->gui_vpn_connections = NULL; + } +} + + +static void nmwa_free_dbus_vpn_connections (NMWirelessApplet *applet) +{ + GSList *elt; + + g_return_if_fail (applet != NULL); + + if (applet->dbus_active_vpn) + nmwa_vpn_connection_unref (applet->dbus_active_vpn); + applet->dbus_active_vpn = NULL; + + g_free (applet->dbus_active_vpn_name); + applet->dbus_active_vpn_name = NULL; + + if (applet->dbus_vpn_connections) + { + g_slist_foreach (applet->dbus_vpn_connections, (GFunc) nmwa_vpn_connection_unref, NULL); + g_slist_free (applet->dbus_vpn_connections); + applet->dbus_vpn_connections = NULL; + } +} + + +/* + * nmwa_dbus_vpn_activate_connection + * + * Tell NetworkManager to activate a particular VPN connection. + * + */ +void nmwa_dbus_vpn_activate_connection (DBusConnection *connection, const char *name, const char *password) +{ + DBusMessage *message; + + g_return_if_fail (connection != NULL); + g_return_if_fail (name != NULL); + g_return_if_fail (password != NULL); + + if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH_VPN, NM_DBUS_INTERFACE_VPN, "activateVPNConnection"))) + { + nm_info ("Activating VPN connection '%s'.\n", name); + + dbus_message_append_args (message, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &password, DBUS_TYPE_INVALID); + dbus_connection_send (connection, message, NULL); + } + else + nm_warning ("nmwa_dbus_activate_vpn_connection(): Couldn't allocate the dbus message\n"); +} + + +/* + * nmwa_dbus_deactivate_vpn_connection + * + * Tell NetworkManager to deactivate the currently active VPN connection. + * + */ +void nmwa_dbus_vpn_deactivate_connection (DBusConnection *connection) +{ + DBusMessage *message; + + g_return_if_fail (connection != NULL); + + if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH_VPN, NM_DBUS_INTERFACE_VPN, "deactivateVPNConnection"))) + { + nm_info ("Deactivating the current VPN connection.\n"); + dbus_connection_send (connection, message, NULL); + } + else + nm_warning ("nmwa_dbus_activate_vpn_connection(): Couldn't allocate the dbus message\n"); +} + + diff --git a/gnome/applet/applet-dbus-vpn.h b/gnome/applet/applet-dbus-vpn.h new file mode 100644 index 000000000..30e4cfe21 --- /dev/null +++ b/gnome/applet/applet-dbus-vpn.h @@ -0,0 +1,39 @@ +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ +/* NetworkManager Wireless Applet -- Display wireless access points and allow user control + * + * Dan Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * (C) Copyright 2004-2005 Red Hat, Inc. + */ + +#ifndef APPLET_DBUS_VPN_H +#define APPLET_DBUS_VPN_H + +#include +#include +#include "vpn-connection.h" + +void nmwa_dbus_vpn_update_one_vpn_connection (NMWirelessApplet *applet, const char *vpn_name); +void nmwa_dbus_vpn_update_vpn_connections (NMWirelessApplet *applet); +void nmwa_dbus_vpn_remove_one_vpn_connection (NMWirelessApplet *applet, const char *vpn_name); +void nmwa_dbus_vpn_get_active_vpn_connection (NMWirelessApplet *applet); + +void nmwa_dbus_vpn_activate_connection (DBusConnection *connection, const char *name, const char *password); +void nmwa_dbus_vpn_deactivate_connection (DBusConnection *connection); + + +#endif diff --git a/gnome/applet/applet-dbus.c b/gnome/applet/applet-dbus.c new file mode 100644 index 000000000..a335422b9 --- /dev/null +++ b/gnome/applet/applet-dbus.c @@ -0,0 +1,755 @@ +/* NetworkManager Wireless Applet -- Display wireless access points and allow user control + * + * Dan Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * (C) Copyright 2004 Red Hat, Inc. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include "applet.h" +#include "applet-dbus.h" +#include "applet-dbus-devices.h" +#include "applet-dbus-vpn.h" +#include "applet-dbus-info.h" +#include "vpn-connection.h" +#include "nm-utils.h" + +#define DBUS_NO_SERVICE_ERROR "org.freedesktop.DBus.Error.ServiceDoesNotExist" + + +/* + * nmi_dbus_create_error_message + * + * Convenience function to make a DBus error message + * + */ +DBusMessage *nmwa_dbus_create_error_message (DBusMessage *message, const char *exception_namespace, const char *exception, const char *format, ...) +{ + char * exception_text; + DBusMessage * reply_message; + va_list args; + char error_text[512]; + + + va_start (args, format); + vsnprintf (error_text, 512, format, args); + va_end (args); + + exception_text = g_strdup_printf ("%s.%s", exception_namespace, exception); + reply_message = dbus_message_new_error (message, exception_text, error_text); + g_free (exception_text); + + return (reply_message); +} + + +/* + * deal_with_dbus_error + * + * Ignore some common dbus errors + * + */ +static int deal_with_dbus_error (const char *function, const char *method, DBusError *error) +{ + int ret = RETURN_FAILURE; + + if (!strcmp (error->name, DBUS_NO_SERVICE_ERROR)) + ret = RETURN_NO_NM; + else if (!strcmp (error->name, NM_DBUS_NO_ACTIVE_NET_ERROR)) + ret = RETURN_SUCCESS; + else if (!strcmp (error->name, NM_DBUS_NO_ACTIVE_DEVICE_ERROR)) + ret = RETURN_SUCCESS; + else if (!strcmp (error->name, NM_DBUS_NO_NETWORKS_ERROR)) + ret = RETURN_SUCCESS; + else if (!strcmp (error->name, NM_DBUS_NO_ACTIVE_VPN_CONNECTION)) + ret = RETURN_SUCCESS; + else if (!strcmp (error->name, NM_DBUS_NO_VPN_CONNECTIONS)) + ret = RETURN_SUCCESS; + + if ((ret != RETURN_SUCCESS) && (ret != RETURN_NO_NM)) + nm_warning ("%s(): %s raised on method '%s':\n %s\n\n", function, error->name, method, error->message); + + return ret; +} + +/* + * nmwa_dbus_call_method_string + * + * Do a method call on NetworkManager that returns a string. + * + * Returns: RETURN_SUCCESS on success + * RETURN_FAILURE on failure + * RETURN_NO_NM if NetworkManager service no longer exists + */ +int nmwa_dbus_call_method_string (DBusConnection *con, const char *path, const char *interface, const char *method, gboolean is_obj_path, char **string) +{ + DBusMessage * message; + DBusMessage * reply; + DBusError error; + char * dbus_string = NULL; + + g_return_val_if_fail (con != NULL, RETURN_FAILURE); + g_return_val_if_fail (path != NULL, RETURN_FAILURE); + g_return_val_if_fail (method != NULL, RETURN_FAILURE); + g_return_val_if_fail (string != NULL, RETURN_FAILURE); + g_return_val_if_fail (*string == NULL, RETURN_FAILURE); + + if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, interface, method))) + { + nm_warning ("nmwa_dbus_call_method_string(): Couldn't allocate the dbus message\n"); + return (RETURN_FAILURE); + } + + dbus_error_init (&error); + reply = dbus_connection_send_with_reply_and_block (con, message, -1, &error); + dbus_message_unref (message); + if (dbus_error_is_set (&error)) + { + int ret = deal_with_dbus_error (__FUNCTION__, method, &error); + dbus_error_free (&error); + return (ret); + } + + if (reply == NULL) + { + nm_warning ("nmwa_dbus_call_method_string(): dbus reply message was NULL\n" ); + return (RETURN_FAILURE); + } + + dbus_error_init (&error); + dbus_message_get_args (reply, &error, is_obj_path ? DBUS_TYPE_OBJECT_PATH : DBUS_TYPE_STRING, &dbus_string, DBUS_TYPE_INVALID); + if (dbus_error_is_set (&error)) + { + nm_warning ("nmwa_dbus_call_method_string(): error while getting args: name='%s' message='%s'\n", error.name, error.message); + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + dbus_message_unref (reply); + return (RETURN_FAILURE); + } + + *string = g_strdup (dbus_string); + + dbus_message_unref (reply); + return (RETURN_SUCCESS); +} + +/* + * nmwa_dbus_call_method_uint32 + * + * Do a method call on NetworkManager that returns a DBUS_TYPE_UINT32. + * + * Returns: RETURN_SUCCESS on success + * RETURN_FAILURE on failure + * RETURN_NO_NM if NetworkManager service no longer exists + */ +int nmwa_dbus_call_method_uint32 (DBusConnection *con, const char *path, const char *interface, const char *method, guint32 *num) +{ + DBusMessage * message; + DBusMessage * reply; + DBusError error; + + g_return_val_if_fail (con != NULL, RETURN_FAILURE); + g_return_val_if_fail (path != NULL, RETURN_FAILURE); + g_return_val_if_fail (method != NULL, RETURN_FAILURE); + g_return_val_if_fail (num != NULL, RETURN_FAILURE); + + if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, interface, method))) + { + nm_warning ("nmwa_dbus_call_method_uint32(): Couldn't allocate the dbus message\n"); + return (RETURN_FAILURE); + } + + dbus_error_init (&error); + reply = dbus_connection_send_with_reply_and_block (con, message, -1, &error); + dbus_message_unref (message); + if (dbus_error_is_set (&error)) + { + int ret = deal_with_dbus_error (__FUNCTION__, method, &error); + dbus_error_free (&error); + return (ret); + } + + if (reply == NULL) + { + nm_warning ("nmwa_dbus_call_method_uint32(): dbus reply message was NULL\n" ); + return (RETURN_FAILURE); + } + + dbus_error_init (&error); + dbus_message_get_args (reply, &error, DBUS_TYPE_UINT32, num, DBUS_TYPE_INVALID); + dbus_message_unref (reply); + if (dbus_error_is_set (&error)) + { + nm_warning ("nnmwa_dbus_call_method_uint32(): error while getting args: name='%s' message='%s'\n", error.name, error.message); + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + return (RETURN_FAILURE); + } + + return (RETURN_SUCCESS); +} + +/* + * nmwa_dbus_call_method_int32 + * + * Do a method call on NetworkManager that returns a DBUS_TYPE_INT32. + * + * Returns: RETURN_SUCCESS on success + * RETURN_FAILURE on failure + * RETURN_NO_NM if NetworkManager service no longer exists + */ +int nmwa_dbus_call_method_int32 (DBusConnection *con, const char *path, const char *interface, const char *method, gint32 *num) +{ + DBusMessage * message; + DBusMessage * reply; + DBusError error; + + g_return_val_if_fail (con != NULL, RETURN_FAILURE); + g_return_val_if_fail (path != NULL, RETURN_FAILURE); + g_return_val_if_fail (method != NULL, RETURN_FAILURE); + g_return_val_if_fail (num != NULL, RETURN_FAILURE); + + if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, interface, method))) + { + nm_warning ("nmwa_dbus_call_method_int32(): Couldn't allocate the dbus message\n"); + return (RETURN_FAILURE); + } + + dbus_error_init (&error); + reply = dbus_connection_send_with_reply_and_block (con, message, -1, &error); + dbus_message_unref (message); + if (dbus_error_is_set (&error)) + { + int ret = deal_with_dbus_error (__FUNCTION__, method, &error); + dbus_error_free (&error); + return (ret); + } + + if (reply == NULL) + { + nm_warning ("nmwa_dbus_call_method_int32(): dbus reply message was NULL\n" ); + return (RETURN_FAILURE); + } + + dbus_error_init (&error); + dbus_message_get_args (reply, &error, DBUS_TYPE_INT32, num, DBUS_TYPE_INVALID); + dbus_message_unref (reply); + if (dbus_error_is_set (&error)) + { + nm_warning ("nnmwa_dbus_call_method_int32(): error while getting args: name='%s' message='%s'\n", error.name, error.message); + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + return (RETURN_FAILURE); + } + + return (RETURN_SUCCESS); +} + + +/* + * nmwa_dbus_call_method_boolean + * + * Do a method call on NetworkManager that returns a DBUS_TYPE_BOOLEAN. + * + * Returns: RETURN_SUCCESS on success + * RETURN_FAILURE on failure + * RETURN_NO_NM if NetworkManager service no longer exists + */ +int nmwa_dbus_call_method_boolean (DBusConnection *con, const char *path, const char *interface, const char *method, gboolean *num) +{ + DBusMessage * message; + DBusMessage * reply; + DBusError error; + + g_return_val_if_fail (con != NULL, RETURN_FAILURE); + g_return_val_if_fail (path != NULL, RETURN_FAILURE); + g_return_val_if_fail (method != NULL, RETURN_FAILURE); + g_return_val_if_fail (num != NULL, RETURN_FAILURE); + + if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, interface, method))) + { + nm_warning ("nmwa_dbus_call_method_boolean(): Couldn't allocate the dbus message\n"); + return (RETURN_FAILURE); + } + + dbus_error_init (&error); + reply = dbus_connection_send_with_reply_and_block (con, message, -1, &error); + dbus_message_unref (message); + if (dbus_error_is_set (&error)) + { + int ret = deal_with_dbus_error (__FUNCTION__, method, &error); + dbus_error_free (&error); + return (ret); + } + + if (reply == NULL) + { + nm_warning ("nmwa_dbus_call_method_boolean(): dbus reply message was NULL\n" ); + return (RETURN_FAILURE); + } + + dbus_error_init (&error); + dbus_message_get_args (reply, &error, DBUS_TYPE_BOOLEAN, num, DBUS_TYPE_INVALID); + dbus_message_unref (reply); + if (dbus_error_is_set (&error)) + { + nm_warning ("nnmwa_dbus_call_method_boolean(): error while getting args: name='%s' message='%s'\n", error.name, error.message); + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + return (RETURN_FAILURE); + } + + return (RETURN_SUCCESS); +} + + +/* + * nmwa_dbus_call_method_string_array + * + * Do a method call on NetworkManager that returns a string array. + * + * Returns: RETURN_SUCCESS on success + * RETURN_FAILURE on failure + * RETURN_NO_NM if NetworkManager service no longer exists + */ +int nmwa_dbus_call_method_string_array (DBusConnection *con, const char *path, const char *interface, const char *method, + gboolean is_obj_path, char ***array, guint32 *array_len) +{ + DBusMessage * message; + DBusMessage * reply; + DBusError error; + char ** dbus_array; + int dbus_array_len; + + g_return_val_if_fail (con != NULL, RETURN_FAILURE); + g_return_val_if_fail (path != NULL, RETURN_FAILURE); + g_return_val_if_fail (method != NULL, RETURN_FAILURE); + g_return_val_if_fail (array != NULL, RETURN_FAILURE); + g_return_val_if_fail (*array == NULL, RETURN_FAILURE); + g_return_val_if_fail (array_len != NULL, RETURN_FAILURE); + + if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, interface, method))) + { + nm_warning ("nmwa_dbus_call_method_string_array(): Couldn't allocate the dbus message\n"); + return (RETURN_FAILURE); + } + + dbus_error_init (&error); + reply = dbus_connection_send_with_reply_and_block (con, message, -1, &error); + dbus_message_unref (message); + if (dbus_error_is_set (&error)) + { + int ret = deal_with_dbus_error (__FUNCTION__, method, &error); + dbus_error_free (&error); + return (ret); + } + + if (reply == NULL) + { + nm_warning ("nmwa_dbus_call_method_string_array(): dbus reply message was NULL\n" ); + return (RETURN_FAILURE); + } + + dbus_error_init (&error); + dbus_message_get_args (reply, &error, DBUS_TYPE_ARRAY, is_obj_path ? DBUS_TYPE_OBJECT_PATH : DBUS_TYPE_STRING, &dbus_array, &dbus_array_len, DBUS_TYPE_INVALID); + if (dbus_error_is_set (&error)) + { + nm_warning ("nnmwa_dbus_call_method_string_array(): error while getting args: name='%s' message='%s'\n", error.name, error.message); + dbus_message_unref (reply); + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + return (RETURN_FAILURE); + } + + *array = g_strdupv (dbus_array); + *array_len = dbus_array_len; + dbus_free_string_array (dbus_array); + + dbus_message_unref (reply); + return (RETURN_SUCCESS); +} + + + +/* + * nmwa_dbus_filter + * + */ +static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessage *message, void *user_data) +{ + NMWirelessApplet *applet = (NMWirelessApplet *)user_data; + gboolean handled = TRUE; + DBusError error; + + g_return_val_if_fail (applet != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); + g_return_val_if_fail (connection != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); + g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); + + dbus_error_init (&error); + + if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) + { + char *service; + char *old_owner; + char *new_owner; + + if (dbus_message_get_args (message, &error, + DBUS_TYPE_STRING, &service, + DBUS_TYPE_STRING, &old_owner, + DBUS_TYPE_STRING, &new_owner, + DBUS_TYPE_INVALID)) + { + if (strcmp (service, NM_DBUS_SERVICE) == 0) + { + gboolean old_owner_good = (old_owner && (strlen (old_owner) > 0)); + gboolean new_owner_good = (new_owner && (strlen (new_owner) > 0)); + + if (!old_owner_good && new_owner_good && !applet->nm_running) + { + /* NetworkManager started up */ + applet->nm_running = TRUE; + applet->gui_nm_state = NM_STATE_DISCONNECTED; + applet->dbus_nm_state = NM_STATE_DISCONNECTED; + nmwa_dbus_update_nm_state (applet); + nmwa_dbus_update_devices (applet); + nmwa_dbus_vpn_update_vpn_connections (applet); + } + else if (old_owner_good && !new_owner_good) + applet->nm_running = FALSE; + } + } + } + else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, NM_DBUS_SIGNAL_STATE_CHANGE)) + { + NMState state = NM_STATE_UNKNOWN; + + if (dbus_message_get_args (message, NULL, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID)) + { + /* If we've switched to connecting, update the active device to ensure that we have + * valid wireless network information for it. + */ + if ( (state == NM_STATE_CONNECTING) + && applet->dbus_active_device + && (network_device_get_type (applet->dbus_active_device) == DEVICE_TYPE_WIRELESS_ETHERNET)) + { + nmwa_dbus_device_update_one_device (applet, network_device_get_nm_path (applet->dbus_active_device)); + } + applet->dbus_nm_state = state; + applet->gui_nm_state = state; + } + } + else if ( dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceAdded") + || dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNowActive") + || dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNoLongerActive") + || dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceActivating")) + { + char *path = NULL; + + if (dbus_message_get_args (message, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) + nmwa_dbus_device_update_one_device (applet, path); + } + else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceRemoved")) + { + char *path = NULL; + + if (dbus_message_get_args (message, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) + nmwa_dbus_device_remove_one_device (applet, path); + } + else if ( dbus_message_is_signal (message, NM_DBUS_INTERFACE_VPN, "VPNConnectionAdded") + || dbus_message_is_signal (message, NM_DBUS_INTERFACE_VPN, "VPNConnectionUpdate")) /* VPN connection properties changed */ + { + char *name = NULL; + + if (dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) + nmwa_dbus_vpn_update_one_vpn_connection (applet, name); + } + else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE_VPN, "VPNConnectionChange")) /* Active VPN connection changed */ + { + nmwa_dbus_vpn_get_active_vpn_connection (applet); + } + else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE_VPN, "VPNConnectionRemoved")) + { + char *name = NULL; + + if (dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) + nmwa_dbus_vpn_remove_one_vpn_connection (applet, name); + } + else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "WirelessNetworkAppeared")) + { + char *dev_path = NULL; + char *net_path = NULL; + + if (dbus_message_get_args (message, NULL, DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_OBJECT_PATH, &net_path, DBUS_TYPE_INVALID)) + nmwa_dbus_device_update_one_network (applet, dev_path, net_path, NULL); + } + else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "WirelessNetworkDisappeared")) + { + char *dev_path = NULL; + char *net_path = NULL; + + if (dbus_message_get_args (message, NULL, DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_OBJECT_PATH, &net_path, DBUS_TYPE_INVALID)) + nmwa_dbus_device_remove_one_network (applet, dev_path, net_path); + } + else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "WirelessNetworkStrengthChanged")) + { + char * dev_path = NULL; + char * net_path = NULL; + int strength = -1; + + if (dbus_message_get_args (message, NULL, DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_OBJECT_PATH, &net_path, DBUS_TYPE_INT32, &strength, DBUS_TYPE_INVALID)) + { + /* FIXME actually use strength rather than querying all network properties */ + nmwa_dbus_device_update_one_network (applet, dev_path, net_path, NULL); + } + } + else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE_VPN, "VPNLoginFailed")) + { + char *vpn_name; + char *error_msg; + + if (dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &vpn_name, DBUS_TYPE_STRING, &error_msg, DBUS_TYPE_INVALID)) + nmwa_schedule_vpn_login_failure_dialog (applet, vpn_name, error_msg); + } + else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE_VPN, "VPNLoginBanner")) + { + char *vpn_name; + char *banner; + + if (dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &vpn_name, DBUS_TYPE_STRING, &banner, DBUS_TYPE_INVALID)) + nmwa_schedule_vpn_login_banner_dialog (applet, vpn_name, banner); + } + else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceActivationFailed")) + { + char *dev = NULL; + char *net = NULL; + DBusError error; + + dbus_error_init (&error); + if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &dev, DBUS_TYPE_STRING, &net, DBUS_TYPE_INVALID)) + { + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + dbus_error_init (&error); + dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &dev, DBUS_TYPE_INVALID); + } + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + if (dev && net) + { + char *string = g_strdup_printf (_("Connection to the wireless network '%s' failed.\n"), net); + nmwa_schedule_warning_dialog (applet, string); + g_free (string); + } + else if (dev) + nmwa_schedule_warning_dialog (applet, _("Connection to the wired network failed.\n")); + } + else + handled = FALSE; + + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + + return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED); +} + + +/* + * nmwa_dbus_nm_is_running + * + * Ask dbus whether or not NetworkManager is running + * + */ +static gboolean nmwa_dbus_nm_is_running (DBusConnection *connection) +{ + DBusError error; + gboolean exists; + + g_return_val_if_fail (connection != NULL, FALSE); + + dbus_error_init (&error); + exists = dbus_bus_name_has_owner (connection, NM_DBUS_SERVICE, &error); + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + return (exists); +} + + +/* + * nmwa_dbus_init + * + * Initialize a connection to NetworkManager if we can get one + * + */ +static DBusConnection * nmwa_dbus_init (NMWirelessApplet *applet, GMainContext *context) +{ + DBusConnection * connection = NULL; + DBusError error; + DBusObjectPathVTable vtable = { NULL, &nmi_dbus_info_message_handler, NULL, NULL, NULL, NULL }; + int acquisition; + + g_return_val_if_fail (applet != NULL, NULL); + g_return_val_if_fail (context != NULL, NULL); + + dbus_error_init (&error); + connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error); + if (dbus_error_is_set (&error)) + { + nm_warning ("%s raised:\n %s\n\n", error.name, error.message); + dbus_error_free (&error); + return NULL; + } + + dbus_error_init (&error); + acquisition = dbus_bus_request_name (connection, NMI_DBUS_SERVICE, DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT, &error); + if (dbus_error_is_set (&error)) + { + nm_warning ("nmwa_dbus_init() could not acquire its service. dbus_bus_acquire_service() says: '%s'", error.message); + dbus_error_free (&error); + return NULL; + } + if (acquisition == DBUS_REQUEST_NAME_REPLY_EXISTS) + return NULL; + + if (!dbus_connection_register_object_path (connection, NMI_DBUS_PATH, &vtable, applet)) + { + nm_warning ("nmwa_dbus_init() could not register a handler for NetworkManagerInfo. Not enough memory?"); + return NULL; + } + + if (!dbus_connection_add_filter (connection, nmwa_dbus_filter, applet, NULL)) + return NULL; + + dbus_connection_set_exit_on_disconnect (connection, FALSE); + dbus_connection_setup_with_g_main (connection, context); + + dbus_bus_add_match(connection, + "type='signal'," + "interface='" DBUS_INTERFACE_DBUS "'," + "sender='" DBUS_SERVICE_DBUS "'", + &error); + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + + dbus_bus_add_match(connection, + "type='signal'," + "interface='" NM_DBUS_INTERFACE "'," + "path='" NM_DBUS_PATH "'," + "sender='" NM_DBUS_SERVICE "'", + &error); + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + + dbus_bus_add_match(connection, + "type='signal'," + "interface='" NM_DBUS_INTERFACE_VPN "'," + "path='" NM_DBUS_PATH_VPN "'," + "sender='" NM_DBUS_SERVICE "'", + &error); + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + + return (connection); +} + + +/* + * nmwa_dbus_connection_watcher + * + * Try to reconnect if we ever get disconnected from the bus + * + */ +static gboolean nmwa_dbus_connection_watcher (gpointer user_data) +{ + NMWirelessApplet *applet = (NMWirelessApplet *)user_data; + + g_return_val_if_fail (applet != NULL, TRUE); + + if (!applet->connection) + { + if ((applet->connection = nmwa_dbus_init (applet, applet->thread_context))) + { + applet->nm_running = nmwa_dbus_nm_is_running (applet->connection); + applet->dbus_nm_state = NM_STATE_DISCONNECTED; + nmwa_dbus_update_nm_state (applet); + nmwa_dbus_update_devices (applet); + nmwa_dbus_vpn_update_vpn_connections (applet); + } + } + + return (TRUE); +} + + +/* + * nmwa_dbus_worker + * + * Thread worker function that periodically grabs the NetworkManager state + * and updates our local applet state to reflect that. + * + */ +gpointer nmwa_dbus_worker (gpointer user_data) +{ + NMWirelessApplet * applet = (NMWirelessApplet *)user_data; + GSource * timeout_source; + GSource * strength_source; + + g_return_val_if_fail (applet != NULL, NULL); + + dbus_g_thread_init (); + + if (!(applet->thread_context = g_main_context_new ())) + return (NULL); + if (!(applet->thread_loop = g_main_loop_new (applet->thread_context, FALSE))) + return (NULL); + + applet->connection = nmwa_dbus_init (applet, applet->thread_context); + + timeout_source = g_timeout_source_new (2000); + g_source_set_callback (timeout_source, nmwa_dbus_connection_watcher, applet, NULL); + g_source_attach (timeout_source, applet->thread_context); + + strength_source = g_timeout_source_new (2000); + g_source_set_callback (strength_source, (GSourceFunc) nmwa_dbus_update_active_device_strength, applet, NULL); + g_source_attach (strength_source, applet->thread_context); + + if (applet->connection && nmwa_dbus_nm_is_running (applet->connection)) + { + applet->nm_running = TRUE; + nmwa_dbus_update_nm_state (applet); + nmwa_dbus_update_devices (applet); + nmwa_dbus_vpn_update_vpn_connections (applet); + } + + g_main_loop_run (applet->thread_loop); + + g_source_destroy (timeout_source); +#if 0 + g_source_destroy (strength_source); +#endif + + return NULL; +} diff --git a/gnome/applet/applet-dbus.h b/gnome/applet/applet-dbus.h new file mode 100644 index 000000000..bda9b39dc --- /dev/null +++ b/gnome/applet/applet-dbus.h @@ -0,0 +1,66 @@ +/* NetworkManager Wireless Applet -- Display wireless access points and allow user control + * + * Dan Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * (C) Copyright 2004 Red Hat, Inc. + */ + +#ifndef APPLET_DBUS_H +#define APPLET_DBUS_H + +#include +#include +#include "NetworkManager.h" +#include "applet.h" + +/* Return codes for functions that use dbus */ +enum +{ + RETURN_SUCCESS = 1, + RETURN_FAILURE = 0, + RETURN_NO_NM = -1 +}; + +static inline gboolean message_is_error (DBusMessage *msg) +{ + g_return_val_if_fail (msg != NULL, FALSE); + + return (dbus_message_get_type (msg) == DBUS_MESSAGE_TYPE_ERROR); +} + +int nmwa_dbus_call_method_string (DBusConnection *con, const char *path, const char *interface, const char *method, gboolean is_obj_path, char **string); +int nmwa_dbus_call_method_uint32 (DBusConnection *con, const char *path, const char *interface, const char *method, guint32 *num); +int nmwa_dbus_call_method_int32 (DBusConnection *con, const char *path, const char *interface, const char *method, gint32 *num); +int nmwa_dbus_call_method_boolean (DBusConnection *con, const char *path, const char *interface, const char *method, gboolean *num); +int nmwa_dbus_call_method_string_array (DBusConnection *con, const char *path, const char *interface, const char *method, + gboolean is_obj_path, char ***array, guint32 *array_len); + +DBusMessage * nmwa_dbus_create_error_message (DBusMessage *message, const char *exception_namespace, const char *exception, const char *format, ...); + +gpointer nmwa_dbus_worker (gpointer user_data); + +void nmwa_dbus_enable_scanning (NMWirelessApplet *applet, gboolean enabled); + +void nmwa_dbus_enable_wireless (NMWirelessApplet *applet, gboolean enabled); + +void nmwa_free_gui_data_model (NMWirelessApplet *applet); +void nmwa_free_dbus_data_model (NMWirelessApplet *applet); + +void nmwa_dbus_vpn_activate_connection (DBusConnection *connection, const char *name, const char *password); +void nmwa_dbus_vpn_deactivate_connection (DBusConnection *connection); + +#endif diff --git a/panel-applet/NMWirelessApplet.c b/gnome/applet/applet.c similarity index 68% rename from panel-applet/NMWirelessApplet.c rename to gnome/applet/applet.c index 6b04dd691..2acad32ff 100644 --- a/panel-applet/NMWirelessApplet.c +++ b/gnome/applet/applet.c @@ -52,15 +52,15 @@ #include #include -#include "NMWirelessApplet.h" -#include "NMWirelessAppletDbus.h" -#include "NMWirelessAppletOtherNetworkDialog.h" -#include "menu-info.h" -#include "nmwa-vpn-password-dialog.h" -#include "nmwa-vpn-connection.h" - -#define CFG_UPDATE_INTERVAL 1 -#define NMWA_GCONF_PATH "/apps/NetworkManagerNotification" +#include "applet.h" +#include "applet-dbus.h" +#include "applet-dbus-devices.h" +#include "applet-dbus-vpn.h" +#include "other-network-dialog.h" +#include "passphrase-dialog.h" +#include "menu-items.h" +#include "vpn-password-dialog.h" +#include "vpn-connection.h" /* Compat for GTK 2.4 and lower... */ #if (GTK_MAJOR_VERSION <= 2 && GTK_MINOR_VERSION < 6) @@ -73,21 +73,42 @@ static GObject * nmwa_constructor (GType type, guint n_props, GObjectConstructPa static void setup_stock (void); static void nmwa_icons_init (NMWirelessApplet *applet); static void nmwa_icons_free (NMWirelessApplet *applet); -static gboolean nmwa_fill (NMWirelessApplet *applet); static void nmwa_about_cb (NMWirelessApplet *applet); static void nmwa_context_menu_update (NMWirelessApplet *applet); +static GtkWidget * nmwa_get_instance (NMWirelessApplet *applet); G_DEFINE_TYPE(NMWirelessApplet, nmwa, EGG_TYPE_TRAY_ICON) -static void -nmwa_init (NMWirelessApplet *applet) +/* + * nm_null_safe_strcmp + * + * Doesn't freaking segfault if s1/s2 are NULL + * + */ +int nm_null_safe_strcmp (const char *s1, const char *s2) +{ + if (!s1 && !s2) + return 0; + if (!s1 && s2) + return -1; + if (s1 && !s2) + return 1; + + return (strcmp (s1, s2)); +} + + +static void nmwa_init (NMWirelessApplet *applet) { applet->animation_id = 0; applet->animation_step = 0; + glade_gnome_init (); setup_stock (); nmwa_icons_init (applet); - nmwa_fill (applet); + +/* gtk_window_set_default_icon_from_file (ICONDIR"/NMWirelessApplet/wireless-applet.png", NULL); */ + gtk_widget_show (nmwa_get_instance (applet)); } static void nmwa_class_init (NMWirelessAppletClass *klass) @@ -95,13 +116,10 @@ static void nmwa_class_init (NMWirelessAppletClass *klass) GObjectClass *gobject_class; gobject_class = G_OBJECT_CLASS (klass); - gobject_class->constructor = nmwa_constructor; } -static GObject *nmwa_constructor (GType type, - guint n_props, - GObjectConstructParam *construct_props) +static GObject *nmwa_constructor (GType type, guint n_props, GObjectConstructParam *construct_props) { GObject *obj; NMWirelessApplet *applet; @@ -308,7 +326,7 @@ GSList *nmwa_driver_notify_get_ignored_list (NMWirelessApplet *applet) g_return_val_if_fail (applet->gconf_client != NULL, NULL); /* Get current list of access point MAC addresses for this AP from GConf */ - key = g_strdup_printf ("%s/non_notify_cards", NMWA_GCONF_PATH); + key = g_strdup_printf ("%s/non_notify_cards", GCONF_PATH_PREFS); value = gconf_client_get (applet->gconf_client, key, NULL); if (value && (value->type == GCONF_VALUE_LIST) && (gconf_value_get_list_type (value) == GCONF_VALUE_STRING)) @@ -331,22 +349,25 @@ GSList *nmwa_driver_notify_get_ignored_list (NMWirelessApplet *applet) */ gboolean nmwa_driver_notify_is_device_ignored (NMWirelessApplet *applet, NetworkDevice *dev) { - gboolean found = FALSE; - GSList *mac_list = NULL; - GSList *elt; + gboolean found = FALSE; + GSList * mac_list = NULL; + GSList * elt; + const char * dev_addr; g_return_val_if_fail (applet != NULL, TRUE); g_return_val_if_fail (applet->gconf_client != NULL, TRUE); g_return_val_if_fail (dev != NULL, TRUE); - g_return_val_if_fail (dev->addr != NULL, TRUE); - g_return_val_if_fail (strlen (dev->addr) > 0, TRUE); + + dev_addr = network_device_get_address (dev); + g_return_val_if_fail (dev_addr != NULL, TRUE); + g_return_val_if_fail (strlen (dev_addr) > 0, TRUE); mac_list = nmwa_driver_notify_get_ignored_list (applet); /* Ensure that the MAC isn't already in the list */ for (elt = mac_list; elt; elt = g_slist_next (elt)) { - if (elt->data && !strcmp (dev->addr, elt->data)) + if (elt->data && !strcmp (dev_addr, elt->data)) { found = TRUE; break; @@ -370,22 +391,25 @@ gboolean nmwa_driver_notify_is_device_ignored (NMWirelessApplet *applet, Network */ void nmwa_driver_notify_ignore_device (NMWirelessApplet *applet, NetworkDevice *dev) { - gboolean found = FALSE; - GSList *new_mac_list = NULL; - GSList *elt; + gboolean found = FALSE; + GSList * new_mac_list = NULL; + GSList * elt; + const char * dev_addr; g_return_if_fail (applet != NULL); g_return_if_fail (applet->gconf_client != NULL); g_return_if_fail (dev != NULL); - g_return_if_fail (dev->addr != NULL); - g_return_if_fail (strlen (dev->addr) > 0); + + dev_addr = network_device_get_address (dev); + g_return_if_fail (dev_addr != NULL); + g_return_if_fail (strlen (dev_addr) > 0); new_mac_list = nmwa_driver_notify_get_ignored_list (applet); /* Ensure that the MAC isn't already in the list */ for (elt = new_mac_list; elt; elt = g_slist_next (elt)) { - if (elt->data && !strcmp (dev->addr, elt->data)) + if (elt->data && !strcmp (dev_addr, elt->data)) { found = TRUE; break; @@ -395,9 +419,9 @@ void nmwa_driver_notify_ignore_device (NMWirelessApplet *applet, NetworkDevice * /* Add the new MAC address to the end of the list */ if (!found) { - char *key = g_strdup_printf ("%s/non_notify_cards", NMWA_GCONF_PATH); + char *key = g_strdup_printf ("%s/non_notify_cards", GCONF_PATH_PREFS); - new_mac_list = g_slist_append (new_mac_list, g_strdup (dev->addr)); + new_mac_list = g_slist_append (new_mac_list, g_strdup (dev_addr)); gconf_client_set_list (applet->gconf_client, key, GCONF_VALUE_STRING, new_mac_list, NULL); g_free (key); } @@ -470,34 +494,34 @@ gboolean nmwa_driver_notify_ok_cb (GtkButton *button, gpointer user_data) */ gboolean nmwa_driver_notify (gpointer user_data) { - DriverNotifyCBData *cb_data = (DriverNotifyCBData *)(user_data); - NetworkDevice *dev; - NMWirelessApplet *applet; - GtkDialog *dialog; - GtkLabel *label; - char *label_text = NULL; - GtkButton *button; + DriverNotifyCBData * cb_data = (DriverNotifyCBData *)(user_data); + NetworkDevice * dev; + NMWirelessApplet * applet; + GtkDialog * dialog; + GtkLabel * label; + char * label_text = NULL; + char * temp = NULL; + GtkButton * button; + NMDriverSupportLevel support_level; g_return_val_if_fail (cb_data != NULL, FALSE); dev = cb_data->dev; g_return_val_if_fail (dev != NULL, FALSE); - applet = cb_data->applet; - g_return_val_if_fail (applet != NULL, FALSE); - g_return_val_if_fail (applet->glade_file != NULL, FALSE); + if (!(applet = cb_data->applet) || !applet->glade_file) + goto out; /* If the user has already requested that we ignore notifications for * this device, don't do anything. */ if (nmwa_driver_notify_is_device_ignored (applet, dev)) - return FALSE; + goto out; - cb_data->xml = glade_xml_new (applet->glade_file, "driver_sucks_dialog", NULL); - if (cb_data->xml == NULL) + if (!(cb_data->xml = glade_xml_new (applet->glade_file, "driver_sucks_dialog", NULL))) { - show_warning_dialog (TRUE, _("The NetworkManager Applet could not find some required resources (the glade file was not found).")); - return FALSE; + nmwa_schedule_warning_dialog (applet, _("The NetworkManager Applet could not find some required resources (the glade file was not found).")); + goto out; } dialog = GTK_DIALOG (glade_xml_get_widget (cb_data->xml, "driver_sucks_dialog")); @@ -505,22 +529,27 @@ gboolean nmwa_driver_notify (gpointer user_data) g_signal_connect (G_OBJECT (dialog), "delete-event", GTK_SIGNAL_FUNC (nmwa_driver_notify_dialog_delete_cb), cb_data); label = GTK_LABEL (glade_xml_get_widget (cb_data->xml, "driver_sucks_label")); - if (dev->driver_support_level == NM_DRIVER_NO_WIRELESS_SCAN) - { - char *temp = g_strdup_printf (_("The network device \"%s (%s)\" does not support wireless scanning."), - dev->hal_name, dev->nm_name); - label_text = g_strdup_printf (gtk_label_get_label (label), temp); - g_free (temp); - } - if (dev->driver_support_level == NM_DRIVER_NO_CARRIER_DETECT) + switch (network_device_get_driver_support_level (dev)) { - char *temp = g_strdup_printf (_("The network device \"%s (%s)\" does not support link detection."), - dev->hal_name, dev->nm_name); + case NM_DRIVER_NO_WIRELESS_SCAN: + temp = g_strdup_printf (_("The network device \"%s (%s)\" does not support wireless scanning."), + network_device_get_desc (dev), network_device_get_iface (dev)); + label_text = g_strdup_printf (gtk_label_get_label (label), temp); + g_free (temp); + break; - label_text = g_strdup_printf (gtk_label_get_label (label), temp); - g_free (temp); + case NM_DRIVER_NO_CARRIER_DETECT: + temp = g_strdup_printf (_("The network device \"%s (%s)\" does not support link detection."), + network_device_get_desc (dev), network_device_get_iface (dev)); + label_text = g_strdup_printf (gtk_label_get_label (label), temp); + g_free (temp); + break; + + default: + break; } + if (label_text) gtk_label_set_markup (label, label_text); @@ -529,90 +558,9 @@ gboolean nmwa_driver_notify (gpointer user_data) gtk_widget_show_all (GTK_WIDGET (dialog)); - return (FALSE); -} - - -/* - * nmwa_update_network_state - * - * Update our state based on what NetworkManager's network state is - * - */ -static void nmwa_update_network_state (NMWirelessApplet *applet) -{ - static AppletState old_state = 0; - - g_return_if_fail (applet != NULL); - - if (!applet->connection) - { - applet->applet_state = APPLET_STATE_NO_NM; - goto out; - } - - if (applet->applet_state == APPLET_STATE_NO_NM) - goto out; - - if (!applet->gui_nm_status) - { - applet->applet_state = APPLET_STATE_NO_CONNECTION; - goto out; - } - - if (strcmp (applet->gui_nm_status, "scanning") == 0) - { - applet->applet_state = APPLET_STATE_WIRELESS_SCANNING; - goto out; - } - - if (strcmp (applet->gui_nm_status, "disconnected") == 0) - { - applet->applet_state = APPLET_STATE_NO_CONNECTION; - goto out; - } - - if (!applet->gui_active_device) - { - applet->applet_state = APPLET_STATE_NO_CONNECTION; - goto out; - } - - /* If the device is not 802.x, we don't show state for it (yet) */ - if ( (applet->gui_active_device->type != DEVICE_TYPE_WIRED_ETHERNET) - && (applet->gui_active_device->type != DEVICE_TYPE_WIRELESS_ETHERNET)) - { - applet->applet_state = APPLET_STATE_NO_CONNECTION; - } - else if (applet->gui_active_device->type == DEVICE_TYPE_WIRED_ETHERNET) - { - if (strcmp (applet->gui_nm_status, "connecting") == 0) - applet->applet_state = APPLET_STATE_WIRED_CONNECTING; - else if (strcmp (applet->gui_nm_status, "connected") == 0) - applet->applet_state = APPLET_STATE_WIRED; - } - else if (applet->gui_active_device->type == DEVICE_TYPE_WIRELESS_ETHERNET) - { - if (strcmp (applet->gui_nm_status, "connecting") == 0) - applet->applet_state = APPLET_STATE_WIRELESS_CONNECTING; - else if (strcmp (applet->gui_nm_status, "connected") == 0) - applet->applet_state = APPLET_STATE_WIRELESS; - } - out: - if (applet->applet_state != old_state) - { - applet->animation_step = 0; - if (applet->applet_state == APPLET_STATE_NO_NM) - { - /* We can only do this because we are called with - * the applet->data_mutex locked. - */ - g_free (applet->gui_nm_status); - applet->gui_nm_status = NULL; - } - old_state = applet->applet_state; - } + network_device_unref (cb_data->dev); + return (FALSE); } @@ -639,30 +587,40 @@ static void nmwa_set_icon (NMWirelessApplet *applet, GdkPixbuf *new_icon) } -static gboolean -animation_timeout (NMWirelessApplet *applet) +/* + * animation_timeout + * + * Jump to the next frame of the applets icon if the icon + * is supposed to be animated. + * + */ +static gboolean animation_timeout (NMWirelessApplet *applet) { - switch (applet->applet_state) + if (!applet->nm_running) { - case (APPLET_STATE_WIRED_CONNECTING): - if (applet->animation_step >= NUM_WIRED_CONNECTING_FRAMES) - applet->animation_step = 0; - nmwa_set_icon (applet, applet->wired_connecting_icons[applet->animation_step]); + applet->animation_step = 0; + return TRUE; + } + + switch (applet->gui_nm_state) + { + case (NM_STATE_CONNECTING): + if (network_device_get_type (applet->gui_active_device) == DEVICE_TYPE_WIRELESS_ETHERNET) + { + if (applet->animation_step >= NUM_WIRELESS_CONNECTING_FRAMES) + applet->animation_step = 0; + nmwa_set_icon (applet, applet->wireless_connecting_icons[applet->animation_step]); + } + else + { + if (applet->animation_step >= NUM_WIRED_CONNECTING_FRAMES) + applet->animation_step = 0; + nmwa_set_icon (applet, applet->wired_connecting_icons[applet->animation_step]); + } applet->animation_step ++; break; - case (APPLET_STATE_WIRELESS_CONNECTING): - if (applet->animation_step >= NUM_WIRELESS_CONNECTING_FRAMES) - applet->animation_step = 0; - nmwa_set_icon (applet, applet->wireless_connecting_icons[applet->animation_step]); - applet->animation_step ++; - break; - - case (APPLET_STATE_NO_NM): - applet->animation_step = 0; - break; - - case (APPLET_STATE_WIRELESS_SCANNING): + case (NM_STATE_SCANNING): if (applet->animation_step >= NUM_WIRELESS_SCANNING_FRAMES) applet->animation_step = 0; nmwa_set_icon (applet, applet->wireless_scanning_icons[applet->animation_step]); @@ -672,42 +630,11 @@ animation_timeout (NMWirelessApplet *applet) default: break; } + return TRUE; } -inline void print_state (AppletState state) -{ - switch (state) - { - case (APPLET_STATE_NO_NM): - g_print ("State: APPLET_STATE_NO_NM\n"); - break; - case (APPLET_STATE_NO_CONNECTION): - g_print ("State: APPLET_STATE_NO_CONNECTION\n"); - break; - case (APPLET_STATE_WIRED): - g_print ("State: APPLET_STATE_WIRED\n"); - break; - case (APPLET_STATE_WIRED_CONNECTING): - g_print ("State: APPLET_STATE_WIRED_CONNECTING\n"); - break; - case (APPLET_STATE_WIRELESS): - g_print ("State: APPLET_STATE_WIRELESS\n"); - break; - case (APPLET_STATE_WIRELESS_CONNECTING): - g_print ("State: APPLET_STATE_WIRELESS_CONNECTING\n"); - break; - case (APPLET_STATE_WIRELESS_SCANNING): - g_print ("State: APPLET_STATE_WIRELESS_SCANNING\n"); - break; - default: - g_print ("State: UNKNOWN\n"); - break; - } -} - - /* * nmwa_update_state * @@ -717,63 +644,46 @@ inline void print_state (AppletState state) */ static void nmwa_update_state (NMWirelessApplet *applet) { - gboolean show_applet = TRUE; - gboolean need_animation = FALSE; - gboolean active_vpn = FALSE; - GdkPixbuf *pixbuf = NULL; - gint strength = -1; - char *tip = NULL; - WirelessNetwork *active_network = NULL; + gboolean show_applet = TRUE; + gboolean need_animation = FALSE; + gboolean active_vpn = FALSE; + GdkPixbuf * pixbuf = NULL; + gint strength = -1; + char * tip = NULL; + WirelessNetwork * active_network = NULL; g_mutex_lock (applet->data_mutex); - if (applet->gui_active_device - && (applet->gui_active_device->type == DEVICE_TYPE_WIRELESS_ETHERNET)) + + if (applet->gui_active_device && (network_device_get_type (applet->gui_active_device) == DEVICE_TYPE_WIRELESS_ETHERNET)) { - GSList *list; - - /* Grab a pointer the active network (for ESSID) */ - for (list = applet->gui_active_device->networks; list; list = list->next) - { - WirelessNetwork *network = (WirelessNetwork *) list->data; - - if (network->active) - active_network = network; - } - - strength = CLAMP ((int)applet->gui_active_device->strength, 0, 100); + active_network = network_device_get_active_wireless_network (applet->gui_active_device); + strength = CLAMP ((int)network_device_get_strength (applet->gui_active_device), 0, 100); } -#if 0 - /* Only show icon if there's more than one device and at least one is wireless */ - if (g_slist_length (applet->gui_device_list) == 1 && applet->applet_state != APPLET_STATE_NO_NM) + if (!applet->nm_running) { - if (((NetworkDevice *)applet->gui_device_list->data)->type == DEVICE_TYPE_WIRED_ETHERNET) - show_applet = FALSE; + show_applet = FALSE; + tip = g_strdup (_("NetworkManager is not running")); + goto done; } -#endif - nmwa_update_network_state (applet); + if (!applet->gui_active_device) + applet->gui_nm_state = NM_STATE_DISCONNECTED; - /* print_state (applet->applet_state); */ - switch (applet->applet_state) + switch (applet->gui_nm_state) { - case (APPLET_STATE_NO_CONNECTION): + case NM_STATE_DISCONNECTED: pixbuf = applet->no_connection_icon; tip = g_strdup (_("No network connection")); break; - case (APPLET_STATE_WIRED): - pixbuf = applet->wired_icon; - tip = g_strdup (_("Wired network connection")); - break; - - case (APPLET_STATE_WIRED_CONNECTING): - need_animation = TRUE; - tip = g_strdup (_("Connecting to a wired network...")); - break; - - case (APPLET_STATE_WIRELESS): - if (applet->gui_active_device) + case NM_STATE_CONNECTED: + if (network_device_get_type (applet->gui_active_device) == DEVICE_TYPE_WIRED_ETHERNET) + { + pixbuf = applet->wired_icon; + tip = g_strdup (_("Wired network connection")); + } + else if (network_device_get_type (applet->gui_active_device) == DEVICE_TYPE_WIRELESS_ETHERNET) { if (applet->is_adhoc) { @@ -793,25 +703,21 @@ static void nmwa_update_state (NMWirelessApplet *applet) else pixbuf = applet->wireless_00_icon; tip = g_strdup_printf (_("Wireless network connection to '%s' (%d%%)"), - active_network ? active_network->essid : "(unknown)", strength); + active_network ? wireless_network_get_essid (active_network) : "(unknown)", strength); } } - else - tip = g_strdup (_("Wireless network connection")); break; - case (APPLET_STATE_WIRELESS_CONNECTING): + case NM_STATE_CONNECTING: + if (network_device_get_type (applet->gui_active_device) == DEVICE_TYPE_WIRED_ETHERNET) + tip = g_strdup (_("Connecting to a wired network...")); + else if (network_device_get_type (applet->gui_active_device) == DEVICE_TYPE_WIRELESS_ETHERNET) + tip = g_strdup_printf (_("Connecting to wireless network '%s'..."), + active_network ? wireless_network_get_essid (active_network) : "(unknown)"); need_animation = TRUE; - tip = g_strdup_printf (_("Connecting to wireless network '%s'..."), - active_network ? active_network->essid : "(unknown)"); break; - case (APPLET_STATE_NO_NM): - show_applet = FALSE; - tip = g_strdup (_("NetworkManager is not running")); - break; - - case (APPLET_STATE_WIRELESS_SCANNING): + case NM_STATE_SCANNING: need_animation = TRUE; tip = g_strdup (_("Scanning for wireless networks...")); break; @@ -819,6 +725,8 @@ static void nmwa_update_state (NMWirelessApplet *applet) default: break; } + +done: g_mutex_unlock (applet->data_mutex); if (!applet->tooltips) @@ -826,18 +734,23 @@ static void nmwa_update_state (NMWirelessApplet *applet) gtk_tooltips_set_tip (applet->tooltips, applet->event_box, tip, NULL); g_free (tip); - /*determine if we should hide the notification icon*/ + if (applet->animation_id) + g_source_remove (applet->animation_id); + if (need_animation) + applet->animation_id = g_timeout_add (100, (GSourceFunc) animation_timeout, applet); + else + { + if (pixbuf) + nmwa_set_icon (applet, pixbuf); + else + show_applet = FALSE; + } + + /* determine if we should hide the notification icon */ if (show_applet) gtk_widget_show (GTK_WIDGET (applet)); else gtk_widget_hide (GTK_WIDGET (applet)); - - if (applet->animation_id) - g_source_remove (applet->animation_id); - if (need_animation) - applet->animation_id = g_timeout_add (100, (GSourceFunc) (animation_timeout), applet); - else - nmwa_set_icon (applet, pixbuf); } @@ -856,8 +769,7 @@ static int nmwa_redraw_timeout (NMWirelessApplet *applet) static void nmwa_start_redraw_timeout (NMWirelessApplet *applet) { - applet->redraw_timeout_id = - g_timeout_add (CFG_UPDATE_INTERVAL * 1000, (GtkFunction) nmwa_redraw_timeout, applet); + applet->redraw_timeout_id = g_timeout_add (1000, (GtkFunction) nmwa_redraw_timeout, applet); } @@ -867,20 +779,33 @@ static void nmwa_start_redraw_timeout (NMWirelessApplet *applet) * pop up a warning or error dialog with certain text * */ -void show_warning_dialog (gboolean error, gchar *mesg, ...) +gboolean show_warning_dialog (gchar *mesg) { - GtkWidget *dialog; - char *tmp; - va_list ap; + GtkWidget * dialog; - va_start (ap,mesg); - tmp = g_strdup_vprintf (mesg,ap); - dialog = gtk_message_dialog_new (NULL, 0, error ? GTK_MESSAGE_ERROR : GTK_MESSAGE_WARNING, - GTK_BUTTONS_OK, mesg, NULL); + dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, mesg, NULL); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); - g_free (tmp); - va_end (ap); + + return FALSE; +} + + +/* + * nmwa_schedule_warning_dialog + * + * Run a warning dialog in the main event loop. + * + */ +void nmwa_schedule_warning_dialog (NMWirelessApplet *applet, const char *msg) +{ + char *lcl_msg; + + g_return_if_fail (applet != NULL); + g_return_if_fail (msg != NULL); + + lcl_msg = g_strdup (msg); + g_idle_add ((GSourceFunc) nmwa_show_vpn_login_failure_dialog, lcl_msg); } @@ -890,67 +815,35 @@ void show_warning_dialog (gboolean error, gchar *mesg, ...) * Update the timestamp of a network in GConf. * */ -static void nmwa_update_network_timestamp (NMWirelessApplet *applet, const WirelessNetwork *network) +static void nmwa_update_network_timestamp (NMWirelessApplet *applet, WirelessNetwork *network) { - char *key; - char *escaped_network; + char * key; + char * escaped_network; + const char * net_essid; g_return_if_fail (applet != NULL); g_return_if_fail (network != NULL); + net_essid = wireless_network_get_essid (network); + /* Update GConf to set timestamp for this network, or add it if * it doesn't already exist. */ /* Update timestamp on network */ - escaped_network = gconf_escape_key (network->essid, strlen (network->essid)); - key = g_strdup_printf ("%s/%s/timestamp", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); + escaped_network = gconf_escape_key (net_essid, strlen (net_essid)); + key = g_strdup_printf ("%s/%s/timestamp", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); gconf_client_set_int (applet->gconf_client, key, time (NULL), NULL); g_free (key); /* Force-set the essid too so that we have a semi-complete network entry */ - key = g_strdup_printf ("%s/%s/essid", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); - gconf_client_set_string (applet->gconf_client, key, network->essid, NULL); + key = g_strdup_printf ("%s/%s/essid", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); + gconf_client_set_string (applet->gconf_client, key, net_essid, NULL); g_free (key); g_free (escaped_network); } -/* - * nmwa_get_device_network_for_essid - * - * Searches the network list for a given network device and returns the - * Wireless Network structure corresponding to it. - * - */ -WirelessNetwork *nmwa_get_device_network_for_essid (NMWirelessApplet *applet, NetworkDevice *dev, const char *essid) -{ - WirelessNetwork *found_network = NULL; - GSList *element; - - g_return_val_if_fail (applet != NULL, NULL); - g_return_val_if_fail (dev != NULL, NULL); - g_return_val_if_fail (essid != NULL, NULL); - g_return_val_if_fail (strlen (essid), NULL); - - g_mutex_lock (applet->data_mutex); - element = dev->networks; - while (element) - { - WirelessNetwork *network = (WirelessNetwork *)(element->data); - if (network && (strcmp (network->essid, essid) == 0)) - { - found_network = network; - break; - } - element = g_slist_next (element); - } - g_mutex_unlock (applet->data_mutex); - - return (found_network); -} - - /* * nmwa_get_device_for_nm_device * @@ -969,7 +862,7 @@ NetworkDevice *nmwa_get_device_for_nm_device (GSList *dev_list, const char *nm_d for (elt = dev_list; elt; elt = g_slist_next (elt)) { NetworkDevice *dev = (NetworkDevice *)(elt->data); - if (dev && (strcmp (dev->nm_device, nm_dev) == 0)) + if (dev && (strcmp (network_device_get_nm_path (dev), nm_dev) == 0)) { found_dev = dev; break; @@ -980,64 +873,6 @@ NetworkDevice *nmwa_get_device_for_nm_device (GSList *dev_list, const char *nm_d } -/* - * nmwa_get_net_for_nm_net - * - * Searches the network list of a device for a particular network - * - */ -WirelessNetwork *nmwa_get_net_for_nm_net (NetworkDevice *dev, const char *net_path) -{ - WirelessNetwork *found_net = NULL; - GSList *elt; - - g_return_val_if_fail (dev != NULL, NULL); - g_return_val_if_fail (net_path != NULL, NULL); - g_return_val_if_fail (strlen (net_path), NULL); - - for (elt = dev->networks; elt; elt = g_slist_next (elt)) - { - WirelessNetwork *net = (WirelessNetwork *)(elt->data); - if (net && (strcmp (net->nm_name, net_path) == 0)) - { - found_net = net; - break; - } - } - - return (found_net); -} - - -/* - * nmwa_get_net_by_essid - * - * Searches the network list of a device for a particular network - * - */ -WirelessNetwork *nmwa_get_net_by_essid (NetworkDevice *dev, const char *essid) -{ - WirelessNetwork *found_net = NULL; - GSList *elt; - - g_return_val_if_fail (dev != NULL, NULL); - g_return_val_if_fail (essid != NULL, NULL); - g_return_val_if_fail (strlen (essid), NULL); - - for (elt = dev->networks; elt; elt = g_slist_next (elt)) - { - WirelessNetwork *net = (WirelessNetwork *)(elt->data); - if (net && (strcmp (net->essid, essid) == 0)) - { - found_net = net; - break; - } - } - - return (found_net); -} - - /* * nmwa_menu_item_activate * @@ -1063,7 +898,7 @@ static void nmwa_menu_item_activate (GtkMenuItem *item, gpointer user_data) { network_device_ref (dev); g_mutex_unlock (applet->data_mutex); - if ((net = nmwa_get_device_network_for_essid (applet, dev, tag))) + if ((net = network_device_get_wireless_network_by_essid (dev, tag))) nmwa_update_network_timestamp (applet, net); } else @@ -1176,41 +1011,48 @@ static void nmwa_menu_add_text_item (GtkWidget *menu, char *text) */ static void nmwa_menu_add_device_item (GtkWidget *menu, NetworkDevice *device, gboolean current, gint n_devices, NMWirelessApplet *applet) { - GtkWidget *menu_item; + GtkWidget * menu_item; g_return_if_fail (menu != NULL); + g_return_if_fail (device != NULL); + g_return_if_fail (applet != NULL); - if (device->type == DEVICE_TYPE_WIRED_ETHERNET) + switch (network_device_get_type (device)) { - NMWiredMenuItem *item = wired_menu_item_new (); - GtkCheckMenuItem *gtk_item; + case DEVICE_TYPE_WIRED_ETHERNET: + { + NMWiredMenuItem *item = wired_menu_item_new (); + GtkCheckMenuItem *gtk_item = wired_menu_item_get_check_item (item); + wired_menu_item_update (item, device, n_devices); + if (applet->gui_active_device == device) + gtk_check_menu_item_set_active (gtk_item, TRUE); - gtk_item = wired_menu_item_get_check_item (item); - wired_menu_item_update (item, device, n_devices); - if (applet->gui_active_device == device) - gtk_check_menu_item_set_active (gtk_item, TRUE); + g_object_set_data (G_OBJECT (gtk_item), "device", g_strdup (network_device_get_iface (device))); + g_object_set_data (G_OBJECT (gtk_item), "nm-item-data", item); + g_signal_connect(G_OBJECT (gtk_item), "activate", G_CALLBACK (nmwa_menu_item_activate), applet); - g_object_set_data (G_OBJECT (gtk_item), "device", g_strdup (device->nm_device)); - g_object_set_data (G_OBJECT (gtk_item), "nm-item-data", item); - g_signal_connect(G_OBJECT (gtk_item), "activate", G_CALLBACK (nmwa_menu_item_activate), applet); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (gtk_item)); + gtk_widget_show (GTK_WIDGET (gtk_item)); + break; + } - gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (gtk_item)); - gtk_widget_show (GTK_WIDGET (gtk_item)); - } - else - { - NMWirelessMenuItem *item = wireless_menu_item_new (); - GtkMenuItem *gtk_item; + case DEVICE_TYPE_WIRELESS_ETHERNET: + { + NMWirelessMenuItem *item = wireless_menu_item_new (); + GtkMenuItem *gtk_item = wireless_menu_item_get_item (item); + wireless_menu_item_update (item, device, n_devices); - gtk_item = wireless_menu_item_get_item (item); - wireless_menu_item_update (item, device, n_devices); + g_object_set_data (G_OBJECT (gtk_item), "device", g_strdup (network_device_get_iface (device))); + g_object_set_data (G_OBJECT (gtk_item), "nm-item-data", item); + g_signal_connect(G_OBJECT (gtk_item), "activate", G_CALLBACK (nmwa_menu_item_activate), applet); - g_object_set_data (G_OBJECT (gtk_item), "device", g_strdup (device->nm_device)); - g_object_set_data (G_OBJECT (gtk_item), "nm-item-data", item); - g_signal_connect(G_OBJECT (gtk_item), "activate", G_CALLBACK (nmwa_menu_item_activate), applet); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (gtk_item)); + gtk_widget_show (GTK_WIDGET (gtk_item)); + break; + } - gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (gtk_item)); - gtk_widget_show (GTK_WIDGET (gtk_item)); + default: + break; } } @@ -1256,55 +1098,94 @@ static void nmwa_menu_add_create_network_item (GtkWidget *menu, NMWirelessApplet g_signal_connect (menu_item, "activate", G_CALLBACK (new_network_item_selected), applet); } + +typedef struct AddNetworksCB +{ + NMWirelessApplet * applet; + gboolean has_encrypted; + GtkWidget * menu; +} AddNetworksCB; + + +/* + * nmwa_add_networks_helper + * + */ +void nmwa_add_networks_helper (NetworkDevice *dev, WirelessNetwork *net, gpointer user_data) +{ + AddNetworksCB * cb_data = (AddNetworksCB *)user_data; + NMNetworkMenuItem * item; + GtkCheckMenuItem * gtk_item; + + g_return_if_fail (dev != NULL); + g_return_if_fail (net != NULL); + g_return_if_fail (cb_data != NULL); + g_return_if_fail (cb_data->menu != NULL); + g_return_if_fail (cb_data->applet != NULL); + + item = network_menu_item_new (cb_data->applet->encryption_size_group); + gtk_item = network_menu_item_get_check_item (item); + + gtk_menu_shell_append (GTK_MENU_SHELL (cb_data->menu), GTK_WIDGET (gtk_item)); + if (cb_data->applet->gui_active_device == dev && wireless_network_get_active (net)) + gtk_check_menu_item_set_active (gtk_item, TRUE); + network_menu_item_update (item, net, cb_data->has_encrypted); + + g_object_set_data (G_OBJECT (gtk_item), "network", g_strdup (wireless_network_get_essid (net))); + g_object_set_data (G_OBJECT (gtk_item), "nm_device", g_strdup (network_device_get_nm_path (dev))); + g_object_set_data (G_OBJECT (gtk_item), "nm-item-data", item); + g_signal_connect (G_OBJECT (gtk_item), "activate", G_CALLBACK (nmwa_menu_item_activate), cb_data->applet); + + gtk_widget_show (GTK_WIDGET (gtk_item)); +} + + +/* + * nmwa_has_encrypted_networks_helper + * + */ +void nmwa_has_encrypted_networks_helper (NetworkDevice *dev, WirelessNetwork *net, gpointer user_data) +{ + gboolean * has_encrypted = user_data; + + g_return_if_fail (dev != NULL); + g_return_if_fail (net != NULL); + g_return_if_fail (has_encrypted != NULL); + + if (wireless_network_get_encrypted (net)) + *has_encrypted = TRUE; +} + + /* * nmwa_menu_device_add_networks * */ static void nmwa_menu_device_add_networks (GtkWidget *menu, NetworkDevice *dev, NMWirelessApplet *applet) { - GSList *list; - gboolean has_encrypted = FALSE; + GSList * list; + gboolean has_encrypted = FALSE; + AddNetworksCB * add_networks_cb = NULL; g_return_if_fail (menu != NULL); g_return_if_fail (applet != NULL); g_return_if_fail (dev != NULL); - if (dev->type != DEVICE_TYPE_WIRELESS_ETHERNET) + if (network_device_get_type (dev) != DEVICE_TYPE_WIRELESS_ETHERNET) return; /* Check for any security */ - for (list = dev->networks; list; list = list->next) - { - WirelessNetwork *network = list->data; + network_device_foreach_wireless_network (dev, nmwa_has_encrypted_networks_helper, &has_encrypted); - if (network->encrypted) - has_encrypted = TRUE; - } + add_networks_cb = g_malloc0 (sizeof (AddNetworksCB)); + add_networks_cb->applet = applet; + add_networks_cb->has_encrypted = has_encrypted; + add_networks_cb->menu = menu; /* Add all networks in our network list to the menu */ - for (list = dev->networks; list; list = list->next) - { - NMNetworkMenuItem *item; - GtkCheckMenuItem *gtk_item; - WirelessNetwork *net; + network_device_foreach_wireless_network (dev, nmwa_add_networks_helper, add_networks_cb); - net = (WirelessNetwork *) list->data; - - item = network_menu_item_new (applet->encryption_size_group); - gtk_item = network_menu_item_get_check_item (item); - - gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (gtk_item)); - if (applet->gui_active_device == dev && net->active) - gtk_check_menu_item_set_active (gtk_item, TRUE); - network_menu_item_update (item, net, has_encrypted); - - g_object_set_data (G_OBJECT (gtk_item), "network", g_strdup (net->essid)); - g_object_set_data (G_OBJECT (gtk_item), "nm_device", g_strdup (dev->nm_device)); - g_object_set_data (G_OBJECT (gtk_item), "nm-item-data", item); - g_signal_connect (G_OBJECT (gtk_item), "activate", G_CALLBACK (nmwa_menu_item_activate), applet); - - gtk_widget_show (GTK_WIDGET (gtk_item)); - } + g_free (add_networks_cb); } @@ -1332,7 +1213,7 @@ static void nmwa_menu_add_vpn_menu (GtkWidget *menu, NMWirelessApplet *applet) const char *vpn_name = nmwa_vpn_connection_get_name (vpn); vpn_item = GTK_CHECK_MENU_ITEM (gtk_check_menu_item_new_with_label (vpn_name)); - nmwa_vpn_connection_ref (vpn, __FUNCTION__); + nmwa_vpn_connection_ref (vpn); g_object_set_data (G_OBJECT (vpn_item), "vpn", vpn); if (applet->gui_active_vpn && (strcmp (vpn_name, nmwa_vpn_connection_get_name (applet->gui_active_vpn)) == 0)) @@ -1384,16 +1265,16 @@ static void nmwa_menu_add_devices (GtkWidget *menu, NMWirelessApplet *applet) g_assert (dev); - switch (dev->type) + switch (network_device_get_type (dev)) { - case DEVICE_TYPE_WIRELESS_ETHERNET: - n_wireless_interfaces++; - break; - case DEVICE_TYPE_WIRED_ETHERNET: - n_wired_interfaces++; - break; - default: - break; + case DEVICE_TYPE_WIRELESS_ETHERNET: + n_wireless_interfaces++; + break; + case DEVICE_TYPE_WIRED_ETHERNET: + n_wired_interfaces++; + break; + default: + break; } } @@ -1402,18 +1283,30 @@ static void nmwa_menu_add_devices (GtkWidget *menu, NMWirelessApplet *applet) { NetworkDevice *dev = (NetworkDevice *)(element->data); - if (dev && ((dev->type == DEVICE_TYPE_WIRED_ETHERNET) || (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET))) + if (dev) { gboolean current = (dev == applet->gui_active_device); gint n_devices = 0; - if (dev->type == DEVICE_TYPE_WIRED_ETHERNET) - n_devices = n_wired_interfaces; - else if (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET) - n_devices = n_wireless_interfaces; + switch (network_device_get_type (dev)) + { + case DEVICE_TYPE_WIRED_ETHERNET: + n_devices = n_wired_interfaces; + break; - nmwa_menu_add_device_item (menu, dev, current, n_devices, applet); - nmwa_menu_device_add_networks (menu, dev, applet); + case DEVICE_TYPE_WIRELESS_ETHERNET: + n_devices = n_wireless_interfaces; + break; + + default: + break; + } + + if (n_devices >= 0) + { + nmwa_menu_add_device_item (menu, dev, current, n_devices, applet); + nmwa_menu_device_add_networks (menu, dev, applet); + } } } @@ -1488,7 +1381,7 @@ static void nmwa_menu_item_data_free (GtkWidget *menu_item, gpointer data) if ((tag = g_object_get_data (G_OBJECT (menu_item), "vpn"))) { g_object_set_data (G_OBJECT (menu_item), "vpn", NULL); - nmwa_vpn_connection_unref ((VPNConnection *)tag, __FUNCTION__); + nmwa_vpn_connection_unref ((VPNConnection *)tag); } if ((tag = g_object_get_data (G_OBJECT (menu_item), "disconnect"))) @@ -1530,7 +1423,7 @@ static void nmwa_dropdown_menu_populate (GtkWidget *menu, NMWirelessApplet *appl g_return_if_fail (menu != NULL); g_return_if_fail (applet != NULL); - if (applet->applet_state == APPLET_STATE_NO_NM) + if (!applet->nm_running) nmwa_menu_add_text_item (menu, _("NetworkManager is not running...")); else nmwa_menu_add_devices (menu, applet); @@ -1765,13 +1658,84 @@ static void nmwa_setup_widgets (NMWirelessApplet *applet) applet->context_menu = nmwa_context_menu_create (applet); applet->encryption_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); +} - applet->glade_file = g_build_filename (GLADEDIR, "wireless-applet.glade", NULL); - if (!applet->glade_file || !g_file_test (applet->glade_file, G_FILE_TEST_IS_REGULAR)) +/* + * nmwa_gconf_networks_notify_callback + * + * Callback from gconf when wireless networking key/values have changed. + * + */ +static void nmwa_gconf_networks_notify_callback (GConfClient *client, guint connection_id, GConfEntry *entry, gpointer user_data) +{ + NMWirelessApplet * applet = (NMWirelessApplet *)user_data; + const char * key = NULL; + + g_return_if_fail (client != NULL); + g_return_if_fail (entry != NULL); + g_return_if_fail (applet != NULL); + + if ((key = gconf_entry_get_key (entry))) { - show_warning_dialog (TRUE, _("The NetworkManager Applet could not find some required resources (the glade file was not found).")); - g_free (applet->glade_file); - applet->glade_file = NULL; + int path_len = strlen (GCONF_PATH_WIRELESS_NETWORKS) + 1; + + if (strncmp (GCONF_PATH_WIRELESS_NETWORKS"/", key, path_len) == 0) + { + char *network = g_strdup ((key + path_len)); + char *slash_pos; + char *unescaped_network; + + /* If its a key under the network name, zero out the slash so we + * are left with only the network name. + */ + unescaped_network = gconf_unescape_key (network, strlen (network)); + if ((slash_pos = strchr (unescaped_network, '/'))) + *slash_pos = '\0'; + +// nmi_dbus_signal_update_network (applet->connection, unescaped_network, NETWORK_TYPE_ALLOWED); + g_free (unescaped_network); + g_free (network); + } + } +} + + +/* + * nmwa_gconf_vpn_connections_notify_callback + * + * Callback from gconf when VPN connection values have changed. + * + */ +static void nmwa_gconf_vpn_connections_notify_callback (GConfClient *client, guint connection_id, GConfEntry *entry, gpointer user_data) +{ + NMWirelessApplet * applet = (NMWirelessApplet *)user_data; + const char * key = NULL; + + g_return_if_fail (client != NULL); + g_return_if_fail (entry != NULL); + g_return_if_fail (applet != NULL); + + if ((key = gconf_entry_get_key (entry))) + { + int path_len = strlen (GCONF_PATH_VPN_CONNECTIONS) + 1; + + if (strncmp (GCONF_PATH_VPN_CONNECTIONS"/", key, path_len) == 0) + { + char *name = g_strdup ((key + path_len)); + char *slash_pos; + char *unescaped_name; + + /* If its a key under the the VPN name, zero out the slash so we + * are left with only the VPN name. + */ + unescaped_name = gconf_unescape_key (name, strlen (name)); + if ((slash_pos = strchr (unescaped_name, '/'))) + *slash_pos = '\0'; + +// nmi_dbus_signal_update_vpn_connection (info->connection, unescaped_name); + g_free (unescaped_name); + g_free (name); + } } } @@ -1791,6 +1755,8 @@ static void nmwa_destroy (NMWirelessApplet *applet, gpointer user_data) nmwa_icons_free (applet); + nmi_passphrase_dialog_destroy (applet->passphrase_dialog); + if (applet->redraw_timeout_id > 0) { gtk_timeout_remove (applet->redraw_timeout_id); @@ -1798,8 +1764,7 @@ static void nmwa_destroy (NMWirelessApplet *applet, gpointer user_data) } g_main_loop_quit (applet->thread_loop); - while (applet->thread_done != TRUE) - g_usleep (G_USEC_PER_SEC / 4); + g_thread_join (applet->dbus_thread); if (applet->gconf_client) g_object_unref (G_OBJECT (applet->gconf_client)); @@ -1808,6 +1773,10 @@ static void nmwa_destroy (NMWirelessApplet *applet, gpointer user_data) nmwa_free_dbus_data_model (applet); g_free (applet->glade_file); + + gconf_client_notify_remove (applet->gconf_client, applet->gconf_net_notify_id); + gconf_client_notify_remove (applet->gconf_client, applet->gconf_vpn_notify_id); + g_object_unref (G_OBJECT (applet->gconf_client)); } @@ -1819,34 +1788,64 @@ static void nmwa_destroy (NMWirelessApplet *applet, gpointer user_data) */ static GtkWidget * nmwa_get_instance (NMWirelessApplet *applet) { - GError *error = NULL; + GError * error = NULL; - gtk_widget_hide(GTK_WIDGET(applet)); + gtk_widget_hide (GTK_WIDGET (applet)); - applet->gconf_client = gconf_client_get_default (); - if (!applet->gconf_client) - return (NULL); - - applet->applet_state = APPLET_STATE_NO_NM; + applet->nm_running = FALSE; + applet->dev_pending_call_list = NULL; + applet->dbus_device_list = NULL; + applet->dbus_active_device = NULL; + applet->dbus_active_device_path = NULL; + applet->dbus_active_vpn_name = NULL; + applet->dbus_active_vpn = NULL; + applet->dbus_vpn_connections = NULL; + applet->dbus_nm_state = NM_STATE_DISCONNECTED; + applet->vpn_pending_call_list = NULL; applet->gui_device_list = NULL; applet->gui_active_device = NULL; - applet->gui_nm_status = NULL; + applet->gui_active_vpn = NULL; + applet->gui_vpn_connections = NULL; + applet->gui_nm_state = NM_STATE_DISCONNECTED; applet->tooltips = NULL; applet->thread_context = NULL; applet->thread_loop = NULL; applet->thread_done = FALSE; + applet->glade_file = g_build_filename (GLADEDIR, "wireless-applet.glade", NULL); + if (!applet->glade_file || !g_file_test (applet->glade_file, G_FILE_TEST_IS_REGULAR)) + { + show_warning_dialog (_("The NetworkManager Applet could not find some required resources (the glade file was not found).")); + g_free (applet->glade_file); + applet->glade_file = NULL; + return NULL; + } + + applet->passphrase_dialog = nmi_passphrase_dialog_init (applet); + + applet->gconf_client = gconf_client_get_default (); + if (!applet->gconf_client) + return NULL; + + gconf_client_add_dir (applet->gconf_client, GCONF_PATH_WIRELESS_NETWORKS, GCONF_CLIENT_PRELOAD_NONE, NULL); + applet->gconf_net_notify_id = gconf_client_notify_add (applet->gconf_client, GCONF_PATH_WIRELESS_NETWORKS, + nmwa_gconf_networks_notify_callback, applet, NULL, NULL); + + gconf_client_add_dir (applet->gconf_client, GCONF_PATH_VPN_CONNECTIONS, GCONF_CLIENT_PRELOAD_NONE, NULL); + applet->gconf_vpn_notify_id = gconf_client_notify_add (applet->gconf_client, GCONF_PATH_VPN_CONNECTIONS, + nmwa_gconf_vpn_connections_notify_callback, applet, NULL, NULL); + /* Start our dbus thread */ if (!(applet->data_mutex = g_mutex_new ())) { g_object_unref (G_OBJECT (applet->gconf_client)); - return (NULL); + return NULL; } if (!(applet->dbus_thread = g_thread_create (nmwa_dbus_worker, applet, FALSE, &error))) { g_mutex_free (applet->data_mutex); g_object_unref (G_OBJECT (applet->gconf_client)); - return (NULL); + return NULL; } /* Load pixmaps and create applet widgets */ @@ -1858,20 +1857,10 @@ static GtkWidget * nmwa_get_instance (NMWirelessApplet *applet) /* Start redraw timeout */ nmwa_start_redraw_timeout (applet); - return (GTK_WIDGET (applet)); + return GTK_WIDGET (applet); } -static gboolean nmwa_fill (NMWirelessApplet *applet) -{ -/* gtk_window_set_default_icon_from_file (ICONDIR"/NMWirelessApplet/wireless-applet.png", NULL); */ - - glade_gnome_init (); - gtk_widget_show (nmwa_get_instance (applet)); - return (TRUE); -} - -static void -setup_stock (void) +static void setup_stock (void) { GtkIconFactory *ifactory; GtkIconSet *iset; @@ -1894,8 +1883,7 @@ setup_stock (void) initted = TRUE; } -static void -nmwa_icons_free (NMWirelessApplet *applet) +static void nmwa_icons_free (NMWirelessApplet *applet) { gint i; @@ -1903,23 +1891,30 @@ nmwa_icons_free (NMWirelessApplet *applet) g_object_unref (applet->no_connection_icon); g_object_unref (applet->wired_icon); g_object_unref (applet->adhoc_icon); - for (i = 0; i < NUM_WIRED_CONNECTING_FRAMES; i++) - g_object_unref (applet->wired_connecting_icons[i]); + g_object_unref (applet->vpn_lock_icon); + g_object_unref (applet->wireless_00_icon); g_object_unref (applet->wireless_25_icon); g_object_unref (applet->wireless_50_icon); g_object_unref (applet->wireless_75_icon); g_object_unref (applet->wireless_100_icon); + + for (i = 0; i < NUM_WIRED_CONNECTING_FRAMES; i++) + g_object_unref (applet->wired_connecting_icons[i]); + for (i = 0; i < NUM_WIRELESS_CONNECTING_FRAMES; i++) g_object_unref (applet->wireless_connecting_icons[i]); + for (i = 0; i < NUM_WIRELESS_SCANNING_FRAMES; i++) g_object_unref (applet->wireless_scanning_icons[i]); - g_object_unref (applet->vpn_lock_icon); } static void nmwa_icons_load_from_disk (NMWirelessApplet *applet, GtkIconTheme *icon_theme) { + char * name; + int i; + /* Assume icons are square */ gint icon_size = 22; @@ -1927,60 +1922,43 @@ nmwa_icons_load_from_disk (NMWirelessApplet *applet, GtkIconTheme *icon_theme) applet->no_connection_icon = gtk_icon_theme_load_icon (icon_theme, "nm-no-connection", icon_size, 0, NULL); applet->wired_icon = gtk_icon_theme_load_icon (icon_theme, "nm-device-wired", icon_size, 0, NULL); applet->adhoc_icon = gtk_icon_theme_load_icon (icon_theme, "nm-adhoc", icon_size, 0, NULL); - applet->wired_connecting_icons[0] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting01", icon_size, 0, NULL); - applet->wired_connecting_icons[1] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting02", icon_size, 0, NULL); - applet->wired_connecting_icons[2] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting03", icon_size, 0, NULL); - applet->wired_connecting_icons[3] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting04", icon_size, 0, NULL); - applet->wired_connecting_icons[4] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting05", icon_size, 0, NULL); - applet->wired_connecting_icons[5] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting06", icon_size, 0, NULL); - applet->wired_connecting_icons[6] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting07", icon_size, 0, NULL); - applet->wired_connecting_icons[7] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting08", icon_size, 0, NULL); - applet->wired_connecting_icons[8] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting09", icon_size, 0, NULL); - applet->wired_connecting_icons[9] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting10", icon_size, 0, NULL); - applet->wired_connecting_icons[10] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting11", icon_size, 0, NULL); + applet->vpn_lock_icon = gtk_icon_theme_load_icon (icon_theme, "nm-vpn-lock", icon_size, 0, NULL); + applet->wireless_00_icon = gtk_icon_theme_load_icon (icon_theme, "nm-signal-00", icon_size, 0, NULL); applet->wireless_25_icon = gtk_icon_theme_load_icon (icon_theme, "nm-signal-25", icon_size, 0, NULL); applet->wireless_50_icon = gtk_icon_theme_load_icon (icon_theme, "nm-signal-50", icon_size, 0, NULL); applet->wireless_75_icon = gtk_icon_theme_load_icon (icon_theme, "nm-signal-75", icon_size, 0, NULL); applet->wireless_100_icon = gtk_icon_theme_load_icon (icon_theme, "nm-signal-100", icon_size, 0, NULL); - applet->wireless_connecting_icons[0] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting01", icon_size, 0, NULL); - applet->wireless_connecting_icons[1] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting02", icon_size, 0, NULL); - applet->wireless_connecting_icons[2] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting03", icon_size, 0, NULL); - applet->wireless_connecting_icons[3] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting04", icon_size, 0, NULL); - applet->wireless_connecting_icons[4] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting05", icon_size, 0, NULL); - applet->wireless_connecting_icons[5] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting06", icon_size, 0, NULL); - applet->wireless_connecting_icons[6] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting07", icon_size, 0, NULL); - applet->wireless_connecting_icons[7] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting08", icon_size, 0, NULL); - applet->wireless_connecting_icons[8] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting09", icon_size, 0, NULL); - applet->wireless_connecting_icons[9] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting10", icon_size, 0, NULL); - applet->wireless_connecting_icons[10] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting11", icon_size, 0, NULL); - applet->wireless_scanning_icons[0] = gtk_icon_theme_load_icon (icon_theme, "nm-detect01", icon_size, 0, NULL); - applet->wireless_scanning_icons[1] = gtk_icon_theme_load_icon (icon_theme, "nm-detect02", icon_size, 0, NULL); - applet->wireless_scanning_icons[2] = gtk_icon_theme_load_icon (icon_theme, "nm-detect03", icon_size, 0, NULL); - applet->wireless_scanning_icons[3] = gtk_icon_theme_load_icon (icon_theme, "nm-detect04", icon_size, 0, NULL); - applet->wireless_scanning_icons[4] = gtk_icon_theme_load_icon (icon_theme, "nm-detect05", icon_size, 0, NULL); - applet->wireless_scanning_icons[5] = gtk_icon_theme_load_icon (icon_theme, "nm-detect06", icon_size, 0, NULL); - applet->wireless_scanning_icons[6] = gtk_icon_theme_load_icon (icon_theme, "nm-detect07", icon_size, 0, NULL); - applet->wireless_scanning_icons[7] = gtk_icon_theme_load_icon (icon_theme, "nm-detect08", icon_size, 0, NULL); - applet->wireless_scanning_icons[8] = gtk_icon_theme_load_icon (icon_theme, "nm-detect09", icon_size, 0, NULL); - applet->wireless_scanning_icons[9] = gtk_icon_theme_load_icon (icon_theme, "nm-detect10", icon_size, 0, NULL); - applet->wireless_scanning_icons[10] = gtk_icon_theme_load_icon (icon_theme, "nm-detect11", icon_size, 0, NULL); - applet->wireless_scanning_icons[11] = gtk_icon_theme_load_icon (icon_theme, "nm-detect12", icon_size, 0, NULL); - applet->wireless_scanning_icons[12] = gtk_icon_theme_load_icon (icon_theme, "nm-detect13", icon_size, 0, NULL); - applet->wireless_scanning_icons[13] = gtk_icon_theme_load_icon (icon_theme, "nm-detect14", icon_size, 0, NULL); - applet->wireless_scanning_icons[14] = gtk_icon_theme_load_icon (icon_theme, "nm-detect15", icon_size, 0, NULL); - applet->wireless_scanning_icons[15] = gtk_icon_theme_load_icon (icon_theme, "nm-detect16", icon_size, 0, NULL); - applet->vpn_lock_icon = gtk_icon_theme_load_icon (icon_theme, "nm-vpn-lock", icon_size, 0, NULL); + + for (i = 0; i < NUM_WIRED_CONNECTING_FRAMES; i++) + { + name = g_strdup_printf ("nm-connecting%02d", i+1); + applet->wired_connecting_icons[i] = gtk_icon_theme_load_icon (icon_theme, name, icon_size, 0, NULL); + g_free (name); + } + + for (i = 0; i < NUM_WIRELESS_CONNECTING_FRAMES; i++) + { + name = g_strdup_printf ("nm-connecting%02d", i+1); + applet->wireless_connecting_icons[i] = gtk_icon_theme_load_icon (icon_theme, name, icon_size, 0, NULL); + g_free (name); + } + + for (i = 0; i < NUM_WIRELESS_SCANNING_FRAMES; i++) + { + name = g_strdup_printf ("nm-detect%02d", i+1); + applet->wireless_scanning_icons[i] = gtk_icon_theme_load_icon (icon_theme, name, icon_size, 0, NULL); + g_free (name); + } } -static void -nmwa_icon_theme_changed (GtkIconTheme *icon_theme, - NMWirelessApplet *applet) +static void nmwa_icon_theme_changed (GtkIconTheme *icon_theme, NMWirelessApplet *applet) { nmwa_icons_free (applet); nmwa_icons_load_from_disk (applet, icon_theme); /* FIXME: force redraw */ } + const gchar *style = " \ style \"MenuBar\" \ { \ @@ -1996,8 +1974,7 @@ class \"GtkMenuBar\" style \"MenuBar\"\ widget \"*ToplevelMenu*\" style \"MenuItem\"\ "; -static void -nmwa_icons_init (NMWirelessApplet *applet) +static void nmwa_icons_init (NMWirelessApplet *applet) { GtkIconTheme *icon_theme; @@ -2010,8 +1987,7 @@ nmwa_icons_init (NMWirelessApplet *applet) } -NMWirelessApplet * -nmwa_new () +NMWirelessApplet *nmwa_new () { return g_object_new (NM_TYPE_WIRELESS_APPLET, "title", "NetworkManager", NULL); } diff --git a/gnome/applet/applet.h b/gnome/applet/applet.h new file mode 100644 index 000000000..c35da35ce --- /dev/null +++ b/gnome/applet/applet.h @@ -0,0 +1,158 @@ +/* NetworkManager Wireless Applet -- Display wireless access points and allow user control + * + * Dan Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * (C) Copyright 2004 Red Hat, Inc. + */ + +#ifndef APPLET_H +#define APPLET_H +#include +#include +#include +#include +#include +#include "eggtrayicon.h" +#include + +#include "nm-device.h" +#include "wireless-network.h" + + +/* + * Preference locations + */ +#define GCONF_PATH_WIRELESS_NETWORKS "/system/networking/wireless/networks" +#define GCONF_PATH_VPN_CONNECTIONS "/system/networking/vpn_connections" +#define GCONF_PATH_PREFS "/apps/NetworkManagerApplet" + + +typedef struct VPNConnection VPNConnection; + + +#define NM_TYPE_WIRELESS_APPLET (nmwa_get_type()) +#define NM_WIRELESS_APPLET(object) (G_TYPE_CHECK_INSTANCE_CAST((object), NM_TYPE_WIRELESS_APPLET, NMWirelessApplet)) +#define NM_WIRELESS_APPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_WIRELESS_APPLET, NMWirelessAppletClass)) +#define NM_IS_WIRELESS_APPLET(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), NM_TYPE_WIRELESS_APPLET)) +#define NM_IS_WIRELESS_APPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_WIRELESS_APPLET)) +#define NM_WIRELESS_APPLET_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), NM_TYPE_WIRELESS_APPLET, NMWirelessAppletClass)) + +typedef struct +{ + EggTrayIconClass parent_class; +} NMWirelessAppletClass; + +/* + * Applet instance data + * + */ +typedef struct +{ + EggTrayIcon parent; + + DBusConnection * connection; + GConfClient * gconf_client; + guint gconf_net_notify_id; + guint gconf_vpn_notify_id; + char * glade_file; + guint redraw_timeout_id; + + /* dbus thread stuff */ + GThread * dbus_thread; + GMainContext * thread_context; + GMainLoop * thread_loop; + gboolean thread_done; + + /* Data model elements */ + GMutex * data_mutex; + gboolean is_adhoc; + gboolean scanning_enabled; + gboolean wireless_enabled; + gboolean nm_running; + + GSList * gui_device_list; + NetworkDevice * gui_active_device; + NMState gui_nm_state; + + GSList * dev_pending_call_list; + GSList * dbus_device_list; + NetworkDevice * dbus_active_device; + char * dbus_active_device_path; + NMState dbus_nm_state; + + GSList * gui_vpn_connections; + VPNConnection * gui_active_vpn; + + GSList * vpn_pending_call_list; + char * dbus_active_vpn_name; + GSList * dbus_vpn_connections; + VPNConnection * dbus_active_vpn; + + GdkPixbuf * no_nm_icon; + GdkPixbuf * no_connection_icon; + GdkPixbuf * wired_icon; + GdkPixbuf * adhoc_icon; +#define NUM_WIRED_CONNECTING_FRAMES 11 + GdkPixbuf * wired_connecting_icons[NUM_WIRED_CONNECTING_FRAMES]; + GdkPixbuf * wireless_00_icon; + GdkPixbuf * wireless_25_icon; + GdkPixbuf * wireless_50_icon; + GdkPixbuf * wireless_75_icon; + GdkPixbuf * wireless_100_icon; +#define NUM_WIRELESS_CONNECTING_FRAMES 11 + GdkPixbuf * wireless_connecting_icons[NUM_WIRELESS_CONNECTING_FRAMES]; +#define NUM_WIRELESS_SCANNING_FRAMES 16 + GdkPixbuf * wireless_scanning_icons[NUM_WIRELESS_SCANNING_FRAMES]; + GdkPixbuf * vpn_lock_icon; + + /* Animation stuff */ + int animation_step; + guint animation_id; + + /* Direct UI elements */ + GtkWidget * pixmap; + GtkWidget * top_menu_item; + GtkWidget * dropdown_menu; + GtkWidget * vpn_menu; + GtkWidget * event_box; + GtkSizeGroup * encryption_size_group; + GtkTooltips * tooltips; + + GtkWidget * context_menu; + GtkWidget * pause_scanning_item; + GtkWidget * stop_wireless_item; + + GtkWidget * passphrase_dialog; +} NMWirelessApplet; + +typedef struct +{ + NMWirelessApplet * applet; + NetworkDevice * dev; + GladeXML * xml; +} DriverNotifyCBData; + +NetworkDevice * nmwa_get_device_for_nm_device (GSList *dev_list, const char *nm_dev); +NMWirelessApplet * nmwa_new (void); +void nmwa_schedule_warning_dialog (NMWirelessApplet *applet, const char *msg); +gboolean nmwa_driver_notify (gpointer user_data); +void nmwa_schedule_vpn_login_failure_dialog (NMWirelessApplet *applet, const char *vpn_name, const char *error_msg); +void nmwa_schedule_vpn_login_banner_dialog (NMWirelessApplet *applet, const char *vpn_name, const char *banner); + +int nm_null_safe_strcmp (const char *s1, const char *s2); + +#endif diff --git a/panel-applet/eggtrayicon.c b/gnome/applet/eggtrayicon.c similarity index 100% rename from panel-applet/eggtrayicon.c rename to gnome/applet/eggtrayicon.c diff --git a/panel-applet/eggtrayicon.h b/gnome/applet/eggtrayicon.h similarity index 100% rename from panel-applet/eggtrayicon.h rename to gnome/applet/eggtrayicon.h diff --git a/panel-applet/gtkcellrendererprogress.c b/gnome/applet/gtkcellrendererprogress.c similarity index 100% rename from panel-applet/gtkcellrendererprogress.c rename to gnome/applet/gtkcellrendererprogress.c diff --git a/panel-applet/gtkcellrendererprogress.h b/gnome/applet/gtkcellrendererprogress.h similarity index 100% rename from panel-applet/gtkcellrendererprogress.h rename to gnome/applet/gtkcellrendererprogress.h diff --git a/panel-applet/gtkcellview.c b/gnome/applet/gtkcellview.c similarity index 100% rename from panel-applet/gtkcellview.c rename to gnome/applet/gtkcellview.c diff --git a/panel-applet/gtkcellview.h b/gnome/applet/gtkcellview.h similarity index 100% rename from panel-applet/gtkcellview.h rename to gnome/applet/gtkcellview.h diff --git a/panel-applet/icons/Makefile.am b/gnome/applet/icons/Makefile.am similarity index 100% rename from panel-applet/icons/Makefile.am rename to gnome/applet/icons/Makefile.am diff --git a/panel-applet/icons/nm-adhoc.png b/gnome/applet/icons/nm-adhoc.png similarity index 100% rename from panel-applet/icons/nm-adhoc.png rename to gnome/applet/icons/nm-adhoc.png diff --git a/panel-applet/icons/nm-connecting01.png b/gnome/applet/icons/nm-connecting01.png similarity index 100% rename from panel-applet/icons/nm-connecting01.png rename to gnome/applet/icons/nm-connecting01.png diff --git a/panel-applet/icons/nm-connecting02.png b/gnome/applet/icons/nm-connecting02.png similarity index 100% rename from panel-applet/icons/nm-connecting02.png rename to gnome/applet/icons/nm-connecting02.png diff --git a/panel-applet/icons/nm-connecting03.png b/gnome/applet/icons/nm-connecting03.png similarity index 100% rename from panel-applet/icons/nm-connecting03.png rename to gnome/applet/icons/nm-connecting03.png diff --git a/panel-applet/icons/nm-connecting04.png b/gnome/applet/icons/nm-connecting04.png similarity index 100% rename from panel-applet/icons/nm-connecting04.png rename to gnome/applet/icons/nm-connecting04.png diff --git a/panel-applet/icons/nm-connecting05.png b/gnome/applet/icons/nm-connecting05.png similarity index 100% rename from panel-applet/icons/nm-connecting05.png rename to gnome/applet/icons/nm-connecting05.png diff --git a/panel-applet/icons/nm-connecting06.png b/gnome/applet/icons/nm-connecting06.png similarity index 100% rename from panel-applet/icons/nm-connecting06.png rename to gnome/applet/icons/nm-connecting06.png diff --git a/panel-applet/icons/nm-connecting07.png b/gnome/applet/icons/nm-connecting07.png similarity index 100% rename from panel-applet/icons/nm-connecting07.png rename to gnome/applet/icons/nm-connecting07.png diff --git a/panel-applet/icons/nm-connecting08.png b/gnome/applet/icons/nm-connecting08.png similarity index 100% rename from panel-applet/icons/nm-connecting08.png rename to gnome/applet/icons/nm-connecting08.png diff --git a/panel-applet/icons/nm-connecting09.png b/gnome/applet/icons/nm-connecting09.png similarity index 100% rename from panel-applet/icons/nm-connecting09.png rename to gnome/applet/icons/nm-connecting09.png diff --git a/panel-applet/icons/nm-connecting10.png b/gnome/applet/icons/nm-connecting10.png similarity index 100% rename from panel-applet/icons/nm-connecting10.png rename to gnome/applet/icons/nm-connecting10.png diff --git a/panel-applet/icons/nm-connecting11.png b/gnome/applet/icons/nm-connecting11.png similarity index 100% rename from panel-applet/icons/nm-connecting11.png rename to gnome/applet/icons/nm-connecting11.png diff --git a/panel-applet/icons/nm-detect01.png b/gnome/applet/icons/nm-detect01.png similarity index 100% rename from panel-applet/icons/nm-detect01.png rename to gnome/applet/icons/nm-detect01.png diff --git a/panel-applet/icons/nm-detect02.png b/gnome/applet/icons/nm-detect02.png similarity index 100% rename from panel-applet/icons/nm-detect02.png rename to gnome/applet/icons/nm-detect02.png diff --git a/panel-applet/icons/nm-detect03.png b/gnome/applet/icons/nm-detect03.png similarity index 100% rename from panel-applet/icons/nm-detect03.png rename to gnome/applet/icons/nm-detect03.png diff --git a/panel-applet/icons/nm-detect04.png b/gnome/applet/icons/nm-detect04.png similarity index 100% rename from panel-applet/icons/nm-detect04.png rename to gnome/applet/icons/nm-detect04.png diff --git a/panel-applet/icons/nm-detect05.png b/gnome/applet/icons/nm-detect05.png similarity index 100% rename from panel-applet/icons/nm-detect05.png rename to gnome/applet/icons/nm-detect05.png diff --git a/panel-applet/icons/nm-detect06.png b/gnome/applet/icons/nm-detect06.png similarity index 100% rename from panel-applet/icons/nm-detect06.png rename to gnome/applet/icons/nm-detect06.png diff --git a/panel-applet/icons/nm-detect07.png b/gnome/applet/icons/nm-detect07.png similarity index 100% rename from panel-applet/icons/nm-detect07.png rename to gnome/applet/icons/nm-detect07.png diff --git a/panel-applet/icons/nm-detect08.png b/gnome/applet/icons/nm-detect08.png similarity index 100% rename from panel-applet/icons/nm-detect08.png rename to gnome/applet/icons/nm-detect08.png diff --git a/panel-applet/icons/nm-detect09.png b/gnome/applet/icons/nm-detect09.png similarity index 100% rename from panel-applet/icons/nm-detect09.png rename to gnome/applet/icons/nm-detect09.png diff --git a/panel-applet/icons/nm-detect10.png b/gnome/applet/icons/nm-detect10.png similarity index 100% rename from panel-applet/icons/nm-detect10.png rename to gnome/applet/icons/nm-detect10.png diff --git a/panel-applet/icons/nm-detect11.png b/gnome/applet/icons/nm-detect11.png similarity index 100% rename from panel-applet/icons/nm-detect11.png rename to gnome/applet/icons/nm-detect11.png diff --git a/panel-applet/icons/nm-detect12.png b/gnome/applet/icons/nm-detect12.png similarity index 100% rename from panel-applet/icons/nm-detect12.png rename to gnome/applet/icons/nm-detect12.png diff --git a/panel-applet/icons/nm-detect13.png b/gnome/applet/icons/nm-detect13.png similarity index 100% rename from panel-applet/icons/nm-detect13.png rename to gnome/applet/icons/nm-detect13.png diff --git a/panel-applet/icons/nm-detect14.png b/gnome/applet/icons/nm-detect14.png similarity index 100% rename from panel-applet/icons/nm-detect14.png rename to gnome/applet/icons/nm-detect14.png diff --git a/panel-applet/icons/nm-detect15.png b/gnome/applet/icons/nm-detect15.png similarity index 100% rename from panel-applet/icons/nm-detect15.png rename to gnome/applet/icons/nm-detect15.png diff --git a/panel-applet/icons/nm-detect16.png b/gnome/applet/icons/nm-detect16.png similarity index 100% rename from panel-applet/icons/nm-detect16.png rename to gnome/applet/icons/nm-detect16.png diff --git a/panel-applet/icons/nm-device-wired.png b/gnome/applet/icons/nm-device-wired.png similarity index 100% rename from panel-applet/icons/nm-device-wired.png rename to gnome/applet/icons/nm-device-wired.png diff --git a/panel-applet/icons/nm-device-wireless.png b/gnome/applet/icons/nm-device-wireless.png similarity index 100% rename from panel-applet/icons/nm-device-wireless.png rename to gnome/applet/icons/nm-device-wireless.png diff --git a/panel-applet/icons/nm-no-connection.png b/gnome/applet/icons/nm-no-connection.png similarity index 100% rename from panel-applet/icons/nm-no-connection.png rename to gnome/applet/icons/nm-no-connection.png diff --git a/panel-applet/icons/nm-signal-00.png b/gnome/applet/icons/nm-signal-00.png similarity index 100% rename from panel-applet/icons/nm-signal-00.png rename to gnome/applet/icons/nm-signal-00.png diff --git a/panel-applet/icons/nm-signal-100.png b/gnome/applet/icons/nm-signal-100.png similarity index 100% rename from panel-applet/icons/nm-signal-100.png rename to gnome/applet/icons/nm-signal-100.png diff --git a/panel-applet/icons/nm-signal-25.png b/gnome/applet/icons/nm-signal-25.png similarity index 100% rename from panel-applet/icons/nm-signal-25.png rename to gnome/applet/icons/nm-signal-25.png diff --git a/panel-applet/icons/nm-signal-50.png b/gnome/applet/icons/nm-signal-50.png similarity index 100% rename from panel-applet/icons/nm-signal-50.png rename to gnome/applet/icons/nm-signal-50.png diff --git a/panel-applet/icons/nm-signal-75.png b/gnome/applet/icons/nm-signal-75.png similarity index 100% rename from panel-applet/icons/nm-signal-75.png rename to gnome/applet/icons/nm-signal-75.png diff --git a/panel-applet/icons/nm-vpn-lock.png b/gnome/applet/icons/nm-vpn-lock.png similarity index 100% rename from panel-applet/icons/nm-vpn-lock.png rename to gnome/applet/icons/nm-vpn-lock.png diff --git a/info-daemon/keyring.png b/gnome/applet/keyring.png similarity index 100% rename from info-daemon/keyring.png rename to gnome/applet/keyring.png diff --git a/gnome/applet/main.c b/gnome/applet/main.c new file mode 100644 index 000000000..4f32500f4 --- /dev/null +++ b/gnome/applet/main.c @@ -0,0 +1,71 @@ +/* NetworkManager Wireless Applet -- Display wireless access points and allow user control + * + * Dan Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * This applet used the GNOME Wireless Applet as a skeleton to build from. + * + * (C) Copyright 2005 Red Hat, Inc. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include "applet.h" + +static void session_die (GnomeClient *client, gpointer client_data) +{ + gtk_main_quit (); +} + +static gboolean session_save (GnomeClient *client, gpointer client_data) +{ + return TRUE; +} + +int main (int argc, char *argv[]) +{ + NMWirelessApplet * nmwa; + GnomeClient * client; + GPtrArray * restart_argv; + + gnome_program_init ("nm-applet", VERSION, LIBGNOMEUI_MODULE, + argc, argv, + GNOME_PARAM_NONE); + + client = gnome_master_client (); + restart_argv = g_ptr_array_new (); + g_ptr_array_add (restart_argv, g_get_prgname ()); + gnome_client_set_restart_command (client, restart_argv->len, (char**) restart_argv->pdata); + g_ptr_array_free (restart_argv, TRUE); + gnome_client_set_restart_style (client, GNOME_RESTART_IMMEDIATELY); + + g_signal_connect (client, "save_yourself", G_CALLBACK (session_save), NULL); + g_signal_connect (client, "die", G_CALLBACK (session_die), NULL); + + nmwa = nmwa_new (); + + gtk_widget_show_all (GTK_WIDGET (nmwa)); + + gtk_main (); + + gnome_client_set_restart_style (client, GNOME_RESTART_ANYWAY); + + return 0; +} diff --git a/panel-applet/menu-info.c b/gnome/applet/menu-items.c similarity index 90% rename from panel-applet/menu-info.c rename to gnome/applet/menu-items.c index 65f593451..f4ccf47a1 100644 --- a/panel-applet/menu-info.c +++ b/gnome/applet/menu-items.c @@ -33,14 +33,14 @@ #include #include #include -#include "menu-info.h" +#include "menu-items.h" #if (GTK_MAJOR_VERSION <= 2 && GTK_MINOR_VERSION < 6) #include "gtkcellview.h" #include "gtkcellrendererprogress.h" #endif -#include "NMWirelessAppletDbus.h" +#include "applet-dbus.h" /**************************************************************** @@ -78,14 +78,14 @@ GtkCheckMenuItem *wired_menu_item_get_check_item (NMWiredMenuItem *item) void wired_menu_item_update (NMWiredMenuItem *item, NetworkDevice *dev, const gint n_devices) { - gchar *text; - gchar *dev_name; + char *text; + const char *dev_name; g_return_if_fail (dev != NULL); g_return_if_fail (item != NULL); - g_assert (dev->type == DEVICE_TYPE_WIRED_ETHERNET); + g_assert (network_device_get_type (dev) == DEVICE_TYPE_WIRED_ETHERNET); - dev_name = dev->hal_name ? dev->hal_name : dev->nm_name; + dev_name = network_device_get_desc (dev) ? network_device_get_desc (dev) : network_device_get_iface (dev); if (n_devices > 1) text = g_strdup_printf (_("Wired Network (%s)"), dev_name); @@ -97,8 +97,8 @@ void wired_menu_item_update (NMWiredMenuItem *item, NetworkDevice *dev, const gi /* Only dim the item if the device supports carrier detection AND * we know it doesn't have a link. */ - if (dev->driver_support_level != NM_DRIVER_NO_CARRIER_DETECT) - gtk_widget_set_sensitive (GTK_WIDGET (item->check_item), dev->link); + if (network_device_get_driver_support_level (dev) != NM_DRIVER_NO_CARRIER_DETECT) + gtk_widget_set_sensitive (GTK_WIDGET (item->check_item), network_device_get_link (dev)); } @@ -155,12 +155,12 @@ void wireless_menu_item_update (NMWirelessMenuItem *item, NetworkDevice *dev, co const char *dev_name; gint n_essids; - n_essids = g_slist_length (dev->networks); - dev_name = dev->hal_name ? dev->hal_name : dev->nm_name; - g_return_if_fail (dev != NULL); g_return_if_fail (item != NULL); - g_assert (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET); + g_assert (network_device_get_type (dev) == DEVICE_TYPE_WIRELESS_ETHERNET); + + n_essids = network_device_get_num_wireless_networks (dev); + dev_name = network_device_get_desc (dev) ? network_device_get_desc (dev) : network_device_get_iface (dev); if (n_devices > 1) text = g_strdup_printf (ngettext ("Wireless Network (%s)", "Wireless Networks (%s)", n_essids), dev_name); @@ -236,16 +236,16 @@ void network_menu_item_update (NMNetworkMenuItem *item, WirelessNetwork *network g_return_if_fail (item != NULL); g_return_if_fail (network != NULL); - display_essid = nm_menu_network_escape_essid_for_display (network->essid); + display_essid = nm_menu_network_escape_essid_for_display (wireless_network_get_essid (network)); gtk_label_set_text (GTK_LABEL (item->label), display_essid); g_free (display_essid); - g_object_set (G_OBJECT (item->progress_bar), "value", CLAMP ((int) network->strength, 0, 100), NULL); + g_object_set (G_OBJECT (item->progress_bar), "value", CLAMP ((int) wireless_network_get_strength (network), 0, 100), NULL); /* Deal with the encrypted icon */ g_object_set (item->security_image, "visible", is_encrypted, NULL); - if (network->encrypted) + if (wireless_network_get_encrypted (network)) gtk_image_set_from_stock (GTK_IMAGE (item->security_image), "gnome-lockscreen", GTK_ICON_SIZE_MENU); else gtk_image_set_from_stock (GTK_IMAGE (item->security_image), NULL, GTK_ICON_SIZE_MENU); diff --git a/panel-applet/menu-info.h b/gnome/applet/menu-items.h similarity index 96% rename from panel-applet/menu-info.h rename to gnome/applet/menu-items.h index 9141e8693..1b1a27818 100644 --- a/panel-applet/menu-info.h +++ b/gnome/applet/menu-items.h @@ -19,11 +19,11 @@ * (C) Copyright 2004 Red Hat, Inc. */ -#ifndef MENU_INFO_H -#define MENU_INFO_H +#ifndef MENU_ITEMS_H +#define MENU_ITEMS_H #include -#include "NMWirelessApplet.h" +#include "applet.h" typedef struct NMWiredMenuItem NMWiredMenuItem; diff --git a/info-daemon/NetworkManagerInfo.conf b/gnome/applet/nm-applet.conf similarity index 100% rename from info-daemon/NetworkManagerInfo.conf rename to gnome/applet/nm-applet.conf diff --git a/gnome/applet/nm-device.c b/gnome/applet/nm-device.c new file mode 100644 index 000000000..e819972ab --- /dev/null +++ b/gnome/applet/nm-device.c @@ -0,0 +1,493 @@ +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ +/* NetworkManager Wireless Applet -- Display wireless access points and allow user control + * + * Dan Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * (C) Copyright 2004-2005 Red Hat, Inc. + */ + + +#include +#include +#include "nm-device.h" + + +/* + * Representation of network device + * + */ +struct NetworkDevice +{ + int refcount; + char * iface; + char * desc; + char * nm_path; + NMDeviceType type; + gboolean link; + NMDriverSupportLevel driver_support_level; + char * addr; + char * udi; + gint strength; + GSList * networks; +}; + + +/* + * network_device_new + * + * Create a new network device representation + * + */ +NetworkDevice *network_device_new (const char *iface, NMDeviceType type, const char *nm_path) +{ + NetworkDevice *dev = NULL; + + if ((dev = g_malloc0 (sizeof (NetworkDevice)))) + { + dev->refcount = 1; + dev->iface = g_strdup (iface); + dev->type = type; + dev->nm_path = g_strdup (nm_path); + } + + return (dev); +} + + +/* + * network_device_copy + * + * Create a new network device representation, filling its + * data in from an already existing one. Deep-copies the + * wireless networks too. + * + */ +NetworkDevice *network_device_copy (NetworkDevice *src) +{ + NetworkDevice *dev = NULL; + + g_return_val_if_fail (src != NULL, NULL); + + if ((dev = g_malloc0 (sizeof (NetworkDevice)))) + { + GSList *elt; + + network_device_ref (dev); + dev->nm_path = g_strdup (src->nm_path); + dev->type = src->type; + dev->link = src->link; + dev->addr = g_strdup (src->addr); + dev->driver_support_level = src->driver_support_level; + dev->iface = g_strdup (src->iface); + dev->desc = g_strdup (src->desc); + dev->udi = g_strdup (src->udi); + dev->strength = src->strength; + + for (elt = src->networks; elt; elt = g_slist_next (elt)) + { + WirelessNetwork *net = (WirelessNetwork *)elt->data; + if (net) + { + WirelessNetwork *copy = wireless_network_copy (net); + dev->networks = g_slist_append (dev->networks, copy); + } + } + } + + return (dev); +} + + +/* + * network_device_ref + * + * Increment the reference count of the network device + * + */ +void network_device_ref (NetworkDevice *dev) +{ + g_return_if_fail (dev != NULL); + + dev->refcount++; +} + + +/* + * network_device_unref + * + * Unrefs (and possibly frees) the representation of a network device + * + */ +void network_device_unref (NetworkDevice *dev) +{ + g_return_if_fail (dev != NULL); + + dev->refcount--; + if (dev->refcount < 1) + { + if (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET) + network_device_clear_wireless_networks (dev); + g_free (dev->nm_path); + g_free (dev->iface); + g_free (dev->udi); + g_free (dev->desc); + g_free (dev->addr); + g_free (dev); + memset (dev, 0, sizeof (NetworkDevice)); + } +} + + +/* + * network_device_get_active_wireless_network + * + * Return the active wireless network. + * + */ +WirelessNetwork *network_device_get_active_wireless_network (NetworkDevice *dev) +{ + GSList * list; + WirelessNetwork * active = NULL; + + g_return_val_if_fail (dev != NULL, NULL); + g_return_val_if_fail (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET, NULL); + + for (list = dev->networks; list; list = list->next) + { + WirelessNetwork *net = (WirelessNetwork *) list->data; + + if (wireless_network_get_active (net)) + { + active = net; + break; + } + } + + return active; +} + + +/* + * network_device_get_wireless_network_by_essid + * + * Return the wireless network with the specified essid. + * + */ +WirelessNetwork *network_device_get_wireless_network_by_essid (NetworkDevice *dev, const char *essid) +{ + GSList * list; + WirelessNetwork * return_net = NULL; + + g_return_val_if_fail (dev != NULL, NULL); + g_return_val_if_fail (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET, NULL); + g_return_val_if_fail (essid != NULL, NULL); + + for (list = dev->networks; list; list = list->next) + { + WirelessNetwork *net = (WirelessNetwork *) list->data; + + if (!strcmp (wireless_network_get_essid (net), essid)) + { + return_net = net; + break; + } + } + + return return_net; +} + + +/* + * network_device_get_wireless_network_by_nm_path + * + * Return the wireless network with the specified NetworkManager object path. + * + */ +WirelessNetwork *network_device_get_wireless_network_by_nm_path (NetworkDevice *dev, const char *nm_path) +{ + GSList * list; + WirelessNetwork * return_net = NULL; + + g_return_val_if_fail (dev != NULL, NULL); + g_return_val_if_fail (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET, NULL); + g_return_val_if_fail (nm_path != NULL, NULL); + + for (list = dev->networks; list; list = list->next) + { + WirelessNetwork *net = (WirelessNetwork *) list->data; + + if (!strcmp (wireless_network_get_nm_path (net), nm_path)) + { + return_net = net; + break; + } + } + + return return_net; +} + + +/* + * network_device_get_wireless_network_by_nm_path + * + * Return the wireless network with the specified NetworkManager object path. + * + */ +void network_device_foreach_wireless_network (NetworkDevice *dev, WirelessNetworkForeach func, gpointer user_data) +{ + GSList * list; + + g_return_if_fail (dev != NULL); + g_return_if_fail (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET); + g_return_if_fail (func != NULL); + + for (list = dev->networks; list; list = list->next) + { + WirelessNetwork *net = (WirelessNetwork *) list->data; + + if (net) + (*func)(dev, net, user_data); + } +} + + +/* + * network_device_add_wireless_network + * + * Adds a wireless network to the network device's network list + * + */ +void network_device_add_wireless_network (NetworkDevice *dev, WirelessNetwork *net) +{ + g_return_if_fail (dev != NULL); + g_return_if_fail (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET); + g_return_if_fail (net != NULL); + + wireless_network_ref (net); + dev->networks = g_slist_append (dev->networks, net); +} + + +/* + * network_device_clear_wireless_networks + * + */ +void network_device_clear_wireless_networks (NetworkDevice *dev) +{ + g_return_if_fail (dev != NULL); + g_return_if_fail (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET); + + g_slist_foreach (dev->networks, (GFunc) wireless_network_unref, NULL); + g_slist_free (dev->networks); + dev->networks = NULL; +} + + +/* + * network_device_remove_wireless_network + * + * Remove one wireless network from the wireless network list + * + */ +void network_device_remove_wireless_network (NetworkDevice *dev, WirelessNetwork *net) +{ + GSList *elt; + + g_return_if_fail (dev != NULL); + g_return_if_fail (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET); + g_return_if_fail (net != NULL); + + for (elt = dev->networks; elt; elt = g_slist_next (elt)) + { + if (elt->data == net) + { + dev->networks = g_slist_remove_link (dev->networks, elt); + wireless_network_unref ((WirelessNetwork *)elt->data); + g_slist_free (elt); + break; + } + } +} + + +/* + * network_device_get_num_wireless_networks + * + * Return the number of wireless networks this device knows about. + * + */ +guint network_device_get_num_wireless_networks (NetworkDevice *dev) +{ + g_return_val_if_fail (dev != NULL, 0); + g_return_val_if_fail (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET, 0); + + return g_slist_length (dev->networks); +} + + +/* + * Accessors for hardware address + */ +const char *network_device_get_address (NetworkDevice *dev) +{ + g_return_val_if_fail (dev != NULL, NULL); + + return (dev->addr); +} + +void network_device_set_address (NetworkDevice *dev, const char *addr) +{ + g_return_if_fail (dev != NULL); + + if (dev->addr) + { + g_free (dev->addr); + dev->addr = NULL; + } + if (addr) + dev->addr = g_strdup (addr); +} + +/* + * Accessors for driver support level + */ +NMDriverSupportLevel network_device_get_driver_support_level (NetworkDevice *dev) +{ + g_return_val_if_fail (dev != NULL, NM_DRIVER_UNSUPPORTED); + + return (dev->driver_support_level); +} + +void network_device_set_driver_support_level (NetworkDevice *dev, NMDriverSupportLevel level) +{ + g_return_if_fail (dev != NULL); + + dev->driver_support_level = level; +} + +/* + * Accessors for NM object path + */ +const char *network_device_get_nm_path (NetworkDevice *dev) +{ + g_return_val_if_fail (dev != NULL, NULL); + + return (dev->nm_path); +} + +/* + * Accessors for device type + */ +NMDeviceType network_device_get_type (NetworkDevice *dev) +{ + g_return_val_if_fail (dev != NULL, DEVICE_TYPE_DONT_KNOW); + + return (dev->type); +} + +/* + * Accessors for strength + */ +gint network_device_get_strength (NetworkDevice *dev) +{ + g_return_val_if_fail (dev != NULL, -1); + g_return_val_if_fail (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET, -1); + + return (dev->strength); +} + +void network_device_set_strength (NetworkDevice *dev, gint strength) +{ + g_return_if_fail (dev != NULL); + g_return_if_fail (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET); + + dev->strength = strength; +} + +/* + * Accessors for device's interface name + */ +const char *network_device_get_iface (NetworkDevice *dev) +{ + g_return_val_if_fail (dev != NULL, NULL); + + return (dev->iface); +} + +/* + * Accessors for HAL udi + */ +const char *network_device_get_hal_udi (NetworkDevice *dev) +{ + g_return_val_if_fail (dev != NULL, NULL); + + return (dev->udi); +} + +void network_device_set_hal_udi (NetworkDevice *dev, const char *hal_udi) +{ + g_return_if_fail (dev != NULL); + + if (dev->udi) + { + g_free (dev->udi); + dev->udi = NULL; + } + if (hal_udi) + dev->udi = g_strdup (hal_udi); +} + +/* + * Accessors for link + */ +gboolean network_device_get_link (NetworkDevice *dev) +{ + g_return_val_if_fail (dev != NULL, FALSE); + + return (dev->link); +} + +void network_device_set_link (NetworkDevice *dev, gboolean link) +{ + g_return_if_fail (dev != NULL); + + dev->link = link; +} + +/* + * Accessors for desc + */ +const char *network_device_get_desc (NetworkDevice *dev) +{ + g_return_val_if_fail (dev != NULL, NULL); + + return (dev->desc); +} + +void network_device_set_desc (NetworkDevice *dev, const char *desc) +{ + g_return_if_fail (dev != NULL); + + if (dev->desc) + { + g_free (dev->desc); + dev->desc = NULL; + } + if (desc) + dev->desc = g_strdup (desc); +} + diff --git a/gnome/applet/nm-device.h b/gnome/applet/nm-device.h new file mode 100644 index 000000000..0dee77387 --- /dev/null +++ b/gnome/applet/nm-device.h @@ -0,0 +1,79 @@ +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ +/* NetworkManager Wireless Applet -- Display wireless access points and allow user control + * + * Dan Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * (C) Copyright 2004-2005 Red Hat, Inc. + */ + + +#ifndef NM_DEVICE_H +#define NM_DEVICE_H + +#include "NetworkManager.h" +#include "wireless-network.h" + +typedef struct NetworkDevice NetworkDevice; +typedef void (*WirelessNetworkForeach) (NetworkDevice *dev, WirelessNetwork *net, gpointer user_data); + + +NetworkDevice * network_device_new (const char *iface, NMDeviceType type, const char *nm_path); +NetworkDevice * network_device_copy (NetworkDevice *src); + +void network_device_ref (NetworkDevice *dev); +void network_device_unref (NetworkDevice *dev); + +NMDeviceType network_device_get_type (NetworkDevice *dev); + +WirelessNetwork * network_device_get_wireless_network_by_essid (NetworkDevice *dev, const char *essid); +WirelessNetwork * network_device_get_wireless_network_by_nm_path(NetworkDevice *dev, const char *essid); + +WirelessNetwork * network_device_get_active_wireless_network (NetworkDevice *dev); + +void network_device_foreach_wireless_network (NetworkDevice *dev, WirelessNetworkForeach func, gpointer user_data); + +void network_device_add_wireless_network (NetworkDevice *dev, WirelessNetwork *net); +void network_device_remove_wireless_network (NetworkDevice *dev, WirelessNetwork *net); +void network_device_clear_wireless_networks (NetworkDevice *dev); + +guint network_device_get_num_wireless_networks (NetworkDevice *dev); + +const char * network_device_get_address (NetworkDevice *dev); +void network_device_set_address (NetworkDevice *dev, const char *addr); + +NMDriverSupportLevel network_device_get_driver_support_level (NetworkDevice *dev); +void network_device_set_driver_support_level (NetworkDevice *dev, NMDriverSupportLevel level); + +const char * network_device_get_iface (NetworkDevice *dev); + +const char * network_device_get_nm_path (NetworkDevice *dev); + +gint network_device_get_strength (NetworkDevice *dev); +void network_device_set_strength (NetworkDevice *dev, gint strength); + +const char * network_device_get_iface (NetworkDevice *dev); + +const char * network_device_get_hal_udi (NetworkDevice *dev); +void network_device_set_hal_udi (NetworkDevice *dev, const char *hal_udi); + +gboolean network_device_get_link (NetworkDevice *dev); +void network_device_set_link (NetworkDevice *dev, gboolean link); + +const char * network_device_get_desc (NetworkDevice *dev); +void network_device_set_desc (NetworkDevice *dev, const char *desc); + +#endif diff --git a/panel-applet/NMWirelessAppletOtherNetworkDialog.c b/gnome/applet/other-network-dialog.c similarity index 86% rename from panel-applet/NMWirelessAppletOtherNetworkDialog.c rename to gnome/applet/other-network-dialog.c index 3b440c57e..85ae332ee 100644 --- a/panel-applet/NMWirelessAppletOtherNetworkDialog.c +++ b/gnome/applet/other-network-dialog.c @@ -38,9 +38,10 @@ #include #include "NetworkManager.h" -#include "NMWirelessApplet.h" -#include "NMWirelessAppletDbus.h" -#include "NMWirelessAppletOtherNetworkDialog.h" +#include "applet.h" +#include "applet-dbus.h" +#include "applet-dbus-devices.h" +#include "other-network-dialog.h" enum NMWAEncryptionKeyTypes { @@ -107,21 +108,18 @@ static GtkTreeModel *create_wireless_adapter_model (NMWirelessApplet *applet) /* We should have already locked applet->data_mutex */ for (element = applet->gui_device_list; element; element = element->next) { - NetworkDevice *network = (NetworkDevice *)(element->data); + NetworkDevice *dev = (NetworkDevice *)(element->data); - g_assert (network); - if (network->type == DEVICE_TYPE_WIRELESS_ETHERNET) + g_assert (dev); + if (network_device_get_type (dev) == DEVICE_TYPE_WIRELESS_ETHERNET) { GtkTreeIter iter; - const char *network_name; + const char *dev_name; - network_name = network->hal_name ? network->hal_name : network->nm_name; + dev_name = network_device_get_desc (dev) ? network_device_get_desc (dev) : network_device_get_iface (dev); gtk_list_store_append (retval, &iter); - gtk_list_store_set (retval, &iter, - 0, network_name, - 1, network, - -1); + gtk_list_store_set (retval, &iter, 0, dev_name, 1, dev, -1); } } return GTK_TREE_MODEL (retval); @@ -214,8 +212,7 @@ static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApple g_return_val_if_fail (*def_dev == NULL, NULL); /* Set up the dialog */ - dialog = GTK_DIALOG (glade_xml_get_widget (xml, "custom_essid_dialog")); - if (!dialog) + if (!(dialog = GTK_DIALOG (glade_xml_get_widget (xml, "custom_essid_dialog")))) return NULL; essid_entry = glade_xml_get_widget (xml, "essid_entry"); @@ -247,7 +244,7 @@ static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApple NetworkDevice *dev = (NetworkDevice *)(element->data); g_assert (dev); - if (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET) + if (network_device_get_type (dev) == DEVICE_TYPE_WIRELESS_ETHERNET) { if (!*def_dev) { @@ -291,7 +288,7 @@ static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApple /* Set initial passphrase entry label and key type combo box item */ key_type_combo = GTK_COMBO_BOX (glade_xml_get_widget (xml, "key_type_combo")); - gtk_combo_box_set_active (key_type_combo, 0); + gtk_combo_box_set_active (key_type_combo, KEY_TYPE_128_BIT_PASSPHRASE); g_signal_connect (G_OBJECT (key_type_combo), "changed", GTK_SIGNAL_FUNC (nmwa_other_network_dialog_key_type_combo_changed), xml); nmwa_other_network_dialog_key_type_combo_changed (GTK_WIDGET (key_type_combo), xml); @@ -313,10 +310,9 @@ void nmwa_other_network_dialog_run (NMWirelessApplet *applet, gboolean create_ne g_return_if_fail (applet != NULL); g_return_if_fail (applet->glade_file != NULL); - xml = glade_xml_new (applet->glade_file, NULL, NULL); - if (xml == NULL) + if (!(xml = glade_xml_new (applet->glade_file, "custom_essid_dialog", NULL))) { - show_warning_dialog (TRUE, _("The NetworkManager Applet could not find some required resources (the glade file was not found).")); + nmwa_schedule_warning_dialog (applet, _("The NetworkManager Applet could not find some required resources (the glade file was not found).")); return; } @@ -351,7 +347,8 @@ void nmwa_other_network_dialog_run (NMWirelessApplet *applet, gboolean create_ne if (essid[0] != '\000') { - WirelessNetwork *net = wireless_network_new_with_essid (essid); + NMEncKeyType nm_key_type; + WirelessNetwork * net = network_device_get_wireless_network_by_essid (def_dev, essid); /* FIXME: allow picking of the wireless device, we currently just * use the first one found in our device list. @@ -359,32 +356,30 @@ void nmwa_other_network_dialog_run (NMWirelessApplet *applet, gboolean create_ne * FIXME: default_dev might have gone away by the time the dialog * gets dismissed and we get here... */ - if (net) + switch (key_type) { - NMEncKeyType nm_key_type; - - switch (key_type) - { - case KEY_TYPE_128_BIT_PASSPHRASE: - nm_key_type = NM_ENC_TYPE_128_BIT_PASSPHRASE; - break; - case KEY_TYPE_ASCII_KEY: - nm_key_type = NM_ENC_TYPE_ASCII_KEY; - break; - case KEY_TYPE_HEX_KEY: - nm_key_type = NM_ENC_TYPE_HEX_KEY; - break; - default: - nm_key_type = NM_ENC_TYPE_UNKNOWN; - break; - } - if (create_network) - nmwa_dbus_create_network (applet->connection, def_dev, net, nm_key_type, passphrase); - else - nmwa_dbus_set_device (applet->connection, def_dev, net, nm_key_type, passphrase); - network_device_unref (def_dev); - wireless_network_unref (net); + case KEY_TYPE_128_BIT_PASSPHRASE: + nm_key_type = NM_ENC_TYPE_128_BIT_PASSPHRASE; + break; + case KEY_TYPE_ASCII_KEY: + nm_key_type = NM_ENC_TYPE_ASCII_KEY; + break; + case KEY_TYPE_HEX_KEY: + nm_key_type = NM_ENC_TYPE_HEX_KEY; + break; + default: + nm_key_type = NM_ENC_TYPE_UNKNOWN; + break; } + + if (create_network) + nmwa_dbus_create_network (applet->connection, def_dev, essid, nm_key_type, passphrase); + else + nmwa_dbus_set_device (applet->connection, def_dev, net, nm_key_type, passphrase); + + if (net) + wireless_network_unref (net); + network_device_unref (def_dev); } } diff --git a/panel-applet/NMWirelessAppletOtherNetworkDialog.h b/gnome/applet/other-network-dialog.h similarity index 88% rename from panel-applet/NMWirelessAppletOtherNetworkDialog.h rename to gnome/applet/other-network-dialog.h index e7eb19622..8dc55f534 100644 --- a/panel-applet/NMWirelessAppletOtherNetworkDialog.h +++ b/gnome/applet/other-network-dialog.h @@ -19,11 +19,11 @@ * (C) Copyright 2004 Red Hat, Inc. */ -#include "NMWirelessApplet.h" +#include "applet.h" -#ifndef NM_WIRELESS_APPLET_OTHER_NETWORK_DIALOG_H -#define NM_WIRELESS_APPLET_OTHER_NETWORK_DIALOG_H +#ifndef OTHER_NETWORK_DIALOG_H +#define OTHER_NETWORK_DIALOG_H void nmwa_other_network_dialog_run (NMWirelessApplet *applet, gboolean create_network); diff --git a/gnome/applet/passphrase-dialog.c b/gnome/applet/passphrase-dialog.c new file mode 100644 index 000000000..6d134c41d --- /dev/null +++ b/gnome/applet/passphrase-dialog.c @@ -0,0 +1,430 @@ +/* NetworkManager Wireless Applet -- Display wireless access points and allow user control + * + * Dan Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * (C) Copyright 2005 Red Hat, Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "applet.h" +#include "applet-dbus-info.h" +#include "passphrase-dialog.h" +#include "nm-utils.h" + +enum NMIPassphraseDialogKeyTypes +{ + KEY_TYPE_128_BIT_PASSPHRASE = 0, + KEY_TYPE_ASCII_KEY = 1, + KEY_TYPE_HEX_KEY = 2 +}; + + +static GladeXML *get_dialog_xml (GtkWidget *dialog) +{ + char *data; + + g_return_val_if_fail (dialog != NULL, NULL); + + if ((data = g_object_get_data (G_OBJECT (dialog), "glade-xml"))) + return (GladeXML *)data; + + return NULL; +} + + +static void update_button_cb (GtkWidget *widget, GladeXML *xml) +{ + GtkButton *button; + GtkComboBox *combo; + GtkEntry *passphrase_entry; + const char *passphrase_text; + gboolean enable = TRUE; + + g_return_if_fail (xml != NULL); + + button = GTK_BUTTON (glade_xml_get_widget (xml, "login_button")); + combo = GTK_COMBO_BOX (glade_xml_get_widget (xml, "key_type_combo")); + passphrase_entry = GTK_ENTRY (glade_xml_get_widget (xml, "passphrase_entry")); + passphrase_text = gtk_entry_get_text (passphrase_entry); + + if (passphrase_text[0] == '\000') + enable = FALSE; + else + { + int combo_choice = gtk_combo_box_get_active (combo); + switch (combo_choice) + { + case KEY_TYPE_ASCII_KEY: + if ((strlen (passphrase_text) != 5) && (strlen (passphrase_text) != 13)) + enable = FALSE; + break; + case KEY_TYPE_HEX_KEY: + if ((strlen (passphrase_text) != 10) && (strlen (passphrase_text) != 26)) + enable = FALSE; + break; + default: + break; + } + } + + gtk_widget_set_sensitive (GTK_WIDGET (button), enable); +} + +/* + * nmi_passphrase_dialog_clear + * + * Return dialog to its original state; clear out any network or device qdatas, + * clear the passphrase entry, and hide the dialog. + * + */ +void nmi_passphrase_dialog_clear (GtkWidget *dialog) +{ + char * data; + GtkWidget * entry = NULL; + GladeXML * xml = NULL; + + g_return_if_fail (dialog != NULL); + + if ((data = g_object_get_data (G_OBJECT (dialog), "device"))) + { + network_device_unref ((NetworkDevice *)data); + g_object_set_data (G_OBJECT (dialog), "device", NULL); + } + + if ((data = g_object_get_data (G_OBJECT (dialog), "network"))) + { + wireless_network_unref ((WirelessNetwork *)data); + g_object_set_data (G_OBJECT (dialog), "network", NULL); + } + + if ((data = g_object_get_data (G_OBJECT (dialog), "dbus-message"))) + { + dbus_message_unref ((DBusMessage *) data); + g_object_set_data (G_OBJECT (dialog), "dbus-message", NULL); + } + + if ((xml = (GladeXML *)g_object_get_data (G_OBJECT (dialog), "glade-xml"))) + { + entry = glade_xml_get_widget (xml, "passphrase_entry"); + gtk_entry_set_text (GTK_ENTRY (entry), ""); + } + + gtk_widget_hide (dialog); +} + + +/* + * nmi_passphrase_dialog_key_type_combo_changed + * + * Change the text of the passphrase entry label to match the selected + * key type. + * + */ +void nmi_passphrase_dialog_key_type_combo_changed (GtkWidget *key_type_combo, gpointer user_data) +{ + GtkWidget * dialog = gtk_widget_get_toplevel (key_type_combo); + + if (GTK_WIDGET_TOPLEVEL (dialog)) + { + GtkLabel * entry_label; + int combo_choice; + GladeXML * dialog_xml; + + g_return_if_fail ((dialog_xml = get_dialog_xml (dialog)) != NULL); + + entry_label = GTK_LABEL (glade_xml_get_widget (dialog_xml, "passphrase_entry_label")); + switch ((combo_choice = gtk_combo_box_get_active (GTK_COMBO_BOX (key_type_combo)))) + { + case KEY_TYPE_128_BIT_PASSPHRASE: + gtk_label_set_label (entry_label, _("Passphrase:")); + break; + case KEY_TYPE_ASCII_KEY: + gtk_label_set_label (entry_label, _("Ascii Key:")); + break; + case KEY_TYPE_HEX_KEY: + gtk_label_set_label (entry_label, _("Hex Key:")); + break; + default: + break; + } + } +} + + +/* + * nmi_passphrase_dialog_ok_clicked + * + * OK button handler; grab the passphrase and send it back + * to NetworkManager. Get rid of the dialog. + * + */ +void nmi_passphrase_dialog_ok_clicked (GtkWidget *ok_button, gpointer user_data) +{ + GtkWidget * dialog = gtk_widget_get_toplevel (ok_button); + NMWirelessApplet * applet = (NMWirelessApplet *)user_data; + + g_return_if_fail (applet != NULL); + + if (GTK_WIDGET_TOPLEVEL (dialog)) + { + GladeXML * dialog_xml; + GtkEntry * entry; + GtkComboBox * key_type_combo; + int key_type; + const char * passphrase; + NetworkDevice * dev = g_object_get_data (G_OBJECT (dialog), "device"); + WirelessNetwork * net = g_object_get_data (G_OBJECT (dialog), "network"); + DBusMessage * message = g_object_get_data (G_OBJECT (dialog), "dbus-message"); + char * key = NULL; + int key_type_return = NM_ENC_TYPE_UNKNOWN; + GConfEntry * gconf_entry; + char * escaped_network; + + g_return_if_fail ((dialog_xml = get_dialog_xml (dialog)) != NULL); + + entry = GTK_ENTRY (glade_xml_get_widget (dialog_xml, "passphrase_entry")); + key_type_combo = GTK_COMBO_BOX (glade_xml_get_widget (dialog_xml, "key_type_combo")); + key_type = gtk_combo_box_get_active (key_type_combo); + passphrase = gtk_entry_get_text (entry); + + switch (key_type) + { + case KEY_TYPE_128_BIT_PASSPHRASE: + key_type_return = NM_ENC_TYPE_128_BIT_PASSPHRASE; + break; + case KEY_TYPE_ASCII_KEY: + key_type_return = NM_ENC_TYPE_ASCII_KEY; + break; + case KEY_TYPE_HEX_KEY: + key_type_return = NM_ENC_TYPE_HEX_KEY; + break; + default: + key_type_return = NM_ENC_TYPE_UNKNOWN; + break; + } + + /* Tell NetworkManager about the key the user typed in */ + nmi_dbus_return_user_key (applet->connection, message, passphrase, key_type_return); + + /* Update GConf with the new user key */ + escaped_network = gconf_escape_key (wireless_network_get_essid (net), strlen (wireless_network_get_essid (net))); + key = g_strdup_printf ("%s/%s", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); + gconf_entry = gconf_client_get_entry (applet->gconf_client, key, NULL, TRUE, NULL); + g_free (key); + if (gconf_entry) + { + gconf_entry_unref (gconf_entry); + key = g_strdup_printf ("%s/%s/key", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); + gconf_client_set_string (applet->gconf_client, key, passphrase, NULL); + g_free (key); + key = g_strdup_printf ("%s/%s/essid", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); + gconf_client_set_string (applet->gconf_client, key, wireless_network_get_essid (net), NULL); + g_free (key); + key = g_strdup_printf ("%s/%s/key_type", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); + gconf_client_set_int (applet->gconf_client, key, key_type_return, NULL); + g_free (key); + } + g_free (escaped_network); + + nmi_passphrase_dialog_clear (dialog); + } +} + + +/* + * nmi_passphrase_dialog_cancel_clicked + * + * Cancel button handler; return a cancellation message to NetworkManager + * and get rid of the dialog. + * + */ +void nmi_passphrase_dialog_cancel_clicked (GtkWidget *cancel_button, gpointer user_data) +{ + GtkWidget * dialog = gtk_widget_get_toplevel (cancel_button); + NMWirelessApplet * applet = (NMWirelessApplet *)user_data; + + g_return_if_fail (applet != NULL); + + if (GTK_WIDGET_TOPLEVEL (dialog)) + { + NetworkDevice * dev = g_object_get_data (G_OBJECT (dialog), "device"); + WirelessNetwork * net = g_object_get_data (G_OBJECT (dialog), "network"); + DBusMessage * message = g_object_get_data (G_OBJECT (dialog), "dbus-message"); + + nmi_dbus_return_user_key (applet->connection, message, "***canceled***", NM_ENC_TYPE_UNKNOWN); + nmi_passphrase_dialog_clear (dialog); + } +} + + +/* + * nmi_passphrase_dialog_show + * + * Pop up the user key dialog in response to a dbus message + * + */ +void nmi_passphrase_dialog_show (GtkWidget *dialog, NetworkDevice *dev, WirelessNetwork *net, DBusMessage *message) +{ + GladeXML * dialog_xml; + const char * orig_label_text; + + g_return_if_fail (dialog != NULL); + g_return_if_fail (dev != NULL); + g_return_if_fail (net != NULL); + g_return_if_fail ((dialog_xml = get_dialog_xml (dialog)) != NULL); + + if (GTK_WIDGET_VISIBLE (dialog)) + return; + + if (!(orig_label_text = g_object_get_data (G_OBJECT (dialog), "orig-label-text"))) + return; + + network_device_ref (dev); + wireless_network_ref (net); + + nmi_passphrase_dialog_clear (dialog); + + /* Insert the Network name into the dialog text */ + if (orig_label_text) + { + GtkWidget * label = glade_xml_get_widget (dialog_xml, "label1"); + char * new_label_text = g_strdup_printf (orig_label_text, wireless_network_get_essid (net)); + + gtk_label_set_label (GTK_LABEL (label), new_label_text); + } + + g_object_set_data (G_OBJECT (dialog), "device", dev); + g_object_set_data (G_OBJECT (dialog), "network", net); + dbus_message_ref (message); + g_object_set_data (G_OBJECT (dialog), "dbus-message", message); + + gtk_widget_show (dialog); +} + + +/* + * nmi_passphrase_dialog_cancel + * + * Cancel and hide any user key dialog that might be up + * + */ +void nmi_passphrase_dialog_cancel (GtkWidget *dialog) +{ + g_return_if_fail (dialog != NULL); + + if (GTK_WIDGET_VISIBLE (dialog)) + nmi_passphrase_dialog_clear (dialog); +} + + +/* + * nmi_passphrase_dialog_init + * + * Initialize the passphrase dialog + * + * Returns: TRUE on success + * FALSE on failure + */ +GtkWidget *nmi_passphrase_dialog_init (NMWirelessApplet *applet) +{ + GtkWidget * dialog; + GtkButton * ok_button; + GtkButton * cancel_button; + GtkEntry * entry; + GtkComboBox * key_type_combo; + GtkLabel * label; + GladeXML * dialog_xml; + char * orig_label_text; + + if (!(dialog_xml = glade_xml_new (applet->glade_file, "passphrase_dialog", NULL))) + { + nmwa_schedule_warning_dialog (applet, _("The NetworkManager Applet could not find some required resources (the glade file was not found).")); + return NULL; + } + + dialog = glade_xml_get_widget (dialog_xml, "passphrase_dialog"); + gtk_widget_hide (dialog); + + g_object_set_data (G_OBJECT (dialog), "glade-xml", dialog_xml); + + /* Save original label text to preserve the '%s' and other formatting that gets overwritten + * when the dialog is first shown. + */ + label = GTK_LABEL (glade_xml_get_widget (dialog_xml, "label1")); + orig_label_text = g_strdup (gtk_label_get_label (label)); + + g_object_set_data (G_OBJECT (dialog), "orig-label-text", orig_label_text); + + ok_button = GTK_BUTTON (glade_xml_get_widget (dialog_xml, "login_button")); + g_signal_connect (G_OBJECT (ok_button), "clicked", GTK_SIGNAL_FUNC (nmi_passphrase_dialog_ok_clicked), applet); + gtk_widget_grab_default (GTK_WIDGET (ok_button)); + cancel_button = GTK_BUTTON (glade_xml_get_widget (dialog_xml, "cancel_button")); + g_signal_connect (G_OBJECT (cancel_button), "clicked", GTK_SIGNAL_FUNC (nmi_passphrase_dialog_cancel_clicked), applet); + + entry = GTK_ENTRY (glade_xml_get_widget (dialog_xml, "passphrase_entry")); + nmi_passphrase_dialog_clear (dialog); + gtk_widget_set_sensitive (GTK_WIDGET (ok_button), FALSE); + g_signal_connect (entry, "changed", G_CALLBACK (update_button_cb), dialog_xml); + + key_type_combo = GTK_COMBO_BOX (glade_xml_get_widget (dialog_xml, "key_type_combo")); + gtk_combo_box_set_active (key_type_combo, 0); + g_signal_connect (G_OBJECT (key_type_combo), "changed", GTK_SIGNAL_FUNC (nmi_passphrase_dialog_key_type_combo_changed), applet); + nmi_passphrase_dialog_key_type_combo_changed (GTK_WIDGET (key_type_combo), applet); + + return dialog; +} + + +/* + * nmi_passphrase_dialog_destroy + * + * Dispose of the passphrase dialog and its data + * + */ +void nmi_passphrase_dialog_destroy (GtkWidget *dialog) +{ + char *data; + + g_return_if_fail (dialog != NULL); + + nmi_passphrase_dialog_clear (dialog); + + if ((data = g_object_get_data (G_OBJECT (dialog), "glade-xml"))) + { + g_object_unref (G_OBJECT (data)); + g_object_set_data (G_OBJECT (dialog), "glade-xml", NULL); + } + + if ((data = g_object_get_data (G_OBJECT (dialog), "orig-label-text"))) + { + g_free (data); + g_object_set_data (G_OBJECT (dialog), "orig-label-text", NULL); + } + + gtk_widget_destroy (dialog); +} diff --git a/panel-applet/main.c b/gnome/applet/passphrase-dialog.h similarity index 65% rename from panel-applet/main.c rename to gnome/applet/passphrase-dialog.h index d54d36205..92b51ce29 100644 --- a/panel-applet/main.c +++ b/gnome/applet/passphrase-dialog.h @@ -16,34 +16,22 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * This applet used the GNOME Wireless Applet as a skeleton to build from. - * * (C) Copyright 2005 Red Hat, Inc. */ -#ifdef HAVE_CONFIG_H -#include +#ifndef PASSPHRASE_DIALOG_H +#define PASSPHRASE_DIALOG_H + +#include "applet.h" +#include "nm-device.h" +#include "wireless-network.h" + +GtkWidget * nmi_passphrase_dialog_init (NMWirelessApplet *applet); + +void nmi_passphrase_dialog_destroy (GtkWidget *dialog); + +void nmi_passphrase_dialog_show (GtkWidget *dialog, NetworkDevice *dev, WirelessNetwork *net, DBusMessage *message); + +void nmi_passphrase_dialog_cancel (GtkWidget *dialog); + #endif - -#include -#include -#include "NMWirelessApplet.h" - - -int -main (int argc, char *argv[]) -{ - NMWirelessApplet *nmwa; - - gnome_program_init ("NMWirelessApplet", VERSION, LIBGNOMEUI_MODULE, - argc, argv, - GNOME_PARAM_NONE); - - nmwa = nmwa_new (); - - gtk_widget_show_all (GTK_WIDGET (nmwa)); - - gtk_main (); - - return 0; -} diff --git a/panel-applet/nmwa-vpn-connection.c b/gnome/applet/vpn-connection.c similarity index 89% rename from panel-applet/nmwa-vpn-connection.c rename to gnome/applet/vpn-connection.c index 02563b712..3ce47fec4 100644 --- a/panel-applet/nmwa-vpn-connection.c +++ b/gnome/applet/vpn-connection.c @@ -20,7 +20,7 @@ */ #include -#include "nmwa-vpn-connection.h" +#include "vpn-connection.h" struct VPNConnection @@ -31,7 +31,7 @@ struct VPNConnection }; -VPNConnection *nmwa_vpn_connection_new (const char *name, const char *func) +VPNConnection *nmwa_vpn_connection_new (const char *name) { VPNConnection *vpn; @@ -45,7 +45,7 @@ VPNConnection *nmwa_vpn_connection_new (const char *name, const char *func) } -VPNConnection *nmwa_vpn_connection_copy (VPNConnection *src_vpn, const char *func) +VPNConnection *nmwa_vpn_connection_copy (VPNConnection *src_vpn) { VPNConnection *dst_vpn; @@ -60,7 +60,7 @@ VPNConnection *nmwa_vpn_connection_copy (VPNConnection *src_vpn, const char *fun } -void nmwa_vpn_connection_ref (VPNConnection *vpn, const char *func) +void nmwa_vpn_connection_ref (VPNConnection *vpn) { g_return_if_fail (vpn != NULL); @@ -68,7 +68,7 @@ void nmwa_vpn_connection_ref (VPNConnection *vpn, const char *func) } -void nmwa_vpn_connection_unref (VPNConnection *vpn, const char *func) +void nmwa_vpn_connection_unref (VPNConnection *vpn) { g_return_if_fail (vpn != NULL); diff --git a/panel-applet/nmwa-vpn-connection.h b/gnome/applet/vpn-connection.h similarity index 75% rename from panel-applet/nmwa-vpn-connection.h rename to gnome/applet/vpn-connection.h index 88fe2def3..862d0d348 100644 --- a/panel-applet/nmwa-vpn-connection.h +++ b/gnome/applet/vpn-connection.h @@ -19,15 +19,15 @@ * (C) Copyright 2004 Red Hat, Inc. */ -#ifndef NMWA_VPN_CONNECTION_H -#define NMWA_VPN_CONNECTION_H +#ifndef VPN_CONNECTION_H +#define VPN_CONNECTION_H -#include "NMWirelessApplet.h" +#include "applet.h" -VPNConnection * nmwa_vpn_connection_new (const char *name, const char *func); -VPNConnection * nmwa_vpn_connection_copy (VPNConnection *vpn, const char *func); -void nmwa_vpn_connection_ref (VPNConnection *vpn, const char *func); -void nmwa_vpn_connection_unref (VPNConnection *vpn, const char *func); +VPNConnection * nmwa_vpn_connection_new (const char *name); +VPNConnection * nmwa_vpn_connection_copy (VPNConnection *vpn); +void nmwa_vpn_connection_ref (VPNConnection *vpn); +void nmwa_vpn_connection_unref (VPNConnection *vpn); const char * nmwa_vpn_connection_get_name (VPNConnection *vpn); diff --git a/panel-applet/nmwa-vpn-password-dialog.c b/gnome/applet/vpn-password-dialog.c similarity index 98% rename from panel-applet/nmwa-vpn-password-dialog.c rename to gnome/applet/vpn-password-dialog.c index dcb09b28b..ea26d4655 100644 --- a/panel-applet/nmwa-vpn-password-dialog.c +++ b/gnome/applet/vpn-password-dialog.c @@ -37,8 +37,8 @@ #define N_(x) x #endif -#include "NMWirelessApplet.h" -#include "nmwa-vpn-password-dialog.h" +#include "applet.h" +#include "vpn-password-dialog.h" #include "nm-utils.h" static gboolean lookup_pass (const char *vpn, const char *username, char **password) diff --git a/panel-applet/nmwa-vpn-password-dialog.h b/gnome/applet/vpn-password-dialog.h similarity index 91% rename from panel-applet/nmwa-vpn-password-dialog.h rename to gnome/applet/vpn-password-dialog.h index 5ded52aef..81b09184a 100644 --- a/panel-applet/nmwa-vpn-password-dialog.h +++ b/gnome/applet/vpn-password-dialog.h @@ -19,10 +19,10 @@ * (C) Copyright 2004 Red Hat, Inc. */ -#ifndef NMWA_VPN_PASSWORD_DIALOG_H -#define NMWA_VPN_PASSWORD_DIALOG_H +#ifndef VPN_PASSWORD_DIALOG_H +#define VPN_PASSWORD_DIALOG_H -#include "NMWirelessApplet.h" +#include "applet.h" char *nmwa_vpn_request_password (NMWirelessApplet *applet, const char *vpn, const char *username, gboolean retry); diff --git a/panel-applet/wireless-applet.glade b/gnome/applet/wireless-applet.glade similarity index 74% rename from panel-applet/wireless-applet.glade rename to gnome/applet/wireless-applet.glade index f06f48204..664b70e1c 100644 --- a/panel-applet/wireless-applet.glade +++ b/gnome/applet/wireless-applet.glade @@ -667,4 +667,241 @@ Hex key (WEP) + + 6 + True + Wireless Network Key Required + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER_ALWAYS + False + False + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + False + + + + True + False + 12 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + True + _Login to Network + True + GTK_RELIEF_NORMAL + True + 0 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 6 + True + False + 12 + + + + True + keyring.png + 0.5 + 0 + 0 + 0 + + + 0 + False + True + + + + + + True + False + 12 + + + + True + <span weight="bold" size="larger">Passphrase Required by Wireless Network</span> + +A passphrase or encryption key is required to access the wireless network '%s'. + False + True + GTK_JUSTIFY_LEFT + True + False + 0 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + False + 6 + + + + True + Key Type: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + 128-bit Passphrase (WEP) +Ascii Key (WEP) +Hex Key (WEP) + + + 0 + True + True + + + + + + + + + 0 + True + True + + + + + + True + False + 6 + + + + True + Passphrase: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + True + True + True + True + 0 + + True + * + True + + + 0 + True + True + + + + + 0 + True + True + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + diff --git a/gnome/applet/wireless-network.c b/gnome/applet/wireless-network.c new file mode 100644 index 000000000..1807667f5 --- /dev/null +++ b/gnome/applet/wireless-network.c @@ -0,0 +1,195 @@ +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ +/* NetworkManager Wireless Applet -- Display wireless access points and allow user control + * + * Dan Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * (C) Copyright 2004-2005 Red Hat, Inc. + */ + + +#include +#include "wireless-network.h" + +/* + * Representation of a wireless network + * + */ +struct WirelessNetwork +{ + int refcount; + char * nm_path; + char * essid; + gboolean encrypted; + gboolean active; + gint8 strength; +}; + + +/* + * wireless_network_new + * + * Create a new wireless network structure + * + */ +WirelessNetwork *wireless_network_new (const char *essid, const char *nm_path) +{ + WirelessNetwork *net = NULL; + + g_return_val_if_fail (essid != NULL, NULL); + g_return_val_if_fail (nm_path != NULL, NULL); + + if ((net = g_malloc0 (sizeof (WirelessNetwork)))) + { + net->essid = g_strdup (essid); + net->nm_path = g_strdup (nm_path); + } + + return (net); +} + + +/* + * wireless_network_copy + * + * Create a new wireless network structure from an existing one + * + */ +WirelessNetwork *wireless_network_copy (WirelessNetwork *src) +{ + WirelessNetwork *net = NULL; + + g_return_val_if_fail (src != NULL, NULL); + + if ((net = g_malloc0 (sizeof (WirelessNetwork)))) + { + net->refcount = 1; + net->nm_path = g_strdup (src->nm_path); + net->essid = g_strdup (src->essid); + net->active = src->active; + net->encrypted = src->encrypted; + net->strength = src->strength; + } + + return (net); +} + + +/* + * wireless_network_ref + * + * Increment the reference count of the wireless network + * + */ +void wireless_network_ref (WirelessNetwork *net) +{ + g_return_if_fail (net != NULL); + + net->refcount++; +} + + +/* + * wireless_network_unref + * + * Unrefs (and possibly frees) the representation of a wireless network + * + */ +void wireless_network_unref (WirelessNetwork *net) +{ + g_return_if_fail (net != NULL); + + net->refcount--; + if (net->refcount < 1) + { + g_free (net->nm_path); + g_free (net->essid); + g_free (net); + } +} + + +/* + * Accessors for active + */ +gboolean wireless_network_get_active (WirelessNetwork *net) +{ + g_return_val_if_fail (net != NULL, FALSE); + + return net->active; +} + +void wireless_network_set_active (WirelessNetwork *net, gboolean active) +{ + g_return_if_fail (net != NULL); + + net->active = active; +} + +/* + * Accessors for essid + */ +const char *wireless_network_get_essid (WirelessNetwork *net) +{ + g_return_val_if_fail (net != NULL, FALSE); + + return net->essid; +} + +/* + * Accessors for nm_path + */ +const char *wireless_network_get_nm_path (WirelessNetwork *net) +{ + g_return_val_if_fail (net != NULL, FALSE); + + return net->nm_path; +} + +/* + * Accessors for encrypted + */ +gboolean wireless_network_get_encrypted (WirelessNetwork *net) +{ + g_return_val_if_fail (net != NULL, FALSE); + + return net->encrypted; +} + +void wireless_network_set_encrypted (WirelessNetwork *net, gboolean encrypted) +{ + g_return_if_fail (net != NULL); + + net->encrypted = encrypted; +} + +/* + * Accessors for strength + */ +gint8 wireless_network_get_strength (WirelessNetwork *net) +{ + g_return_val_if_fail (net != NULL, FALSE); + + return net->strength; +} + +void wireless_network_set_strength (WirelessNetwork *net, gint8 strength) +{ + g_return_if_fail (net != NULL); + + net->strength = strength; +} + diff --git a/gnome/applet/wireless-network.h b/gnome/applet/wireless-network.h new file mode 100644 index 000000000..4f636f44b --- /dev/null +++ b/gnome/applet/wireless-network.h @@ -0,0 +1,47 @@ +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ +/* NetworkManager Wireless Applet -- Display wireless access points and allow user control + * + * Dan Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * (C) Copyright 2004-2005 Red Hat, Inc. + */ + +#ifndef WIRELESS_NETWORK_H +#define WIRELESS_NETWORK_H + +typedef struct WirelessNetwork WirelessNetwork; + +WirelessNetwork * wireless_network_new (const char *essid, const char *nm_path); +WirelessNetwork * wireless_network_copy (WirelessNetwork *src); + +void wireless_network_ref (WirelessNetwork *net); +void wireless_network_unref (WirelessNetwork *net); + +gboolean wireless_network_get_active (WirelessNetwork *net); +void wireless_network_set_active (WirelessNetwork *net, gboolean active); + +const char * wireless_network_get_essid (WirelessNetwork *net); + +const char * wireless_network_get_nm_path (WirelessNetwork *net); + +gboolean wireless_network_get_encrypted (WirelessNetwork *net); +void wireless_network_set_encrypted (WirelessNetwork *net, gboolean encrypted); + +gint8 wireless_network_get_strength (WirelessNetwork *net); +void wireless_network_set_strength (WirelessNetwork *net, gint8 strength); + +#endif diff --git a/libnm_glib/.cvsignore b/gnome/libnm_glib/.cvsignore similarity index 100% rename from libnm_glib/.cvsignore rename to gnome/libnm_glib/.cvsignore diff --git a/libnm_glib/Makefile.am b/gnome/libnm_glib/Makefile.am similarity index 100% rename from libnm_glib/Makefile.am rename to gnome/libnm_glib/Makefile.am diff --git a/libnm_glib/libnm_glib.c b/gnome/libnm_glib/libnm_glib.c similarity index 80% rename from libnm_glib/libnm_glib.c rename to gnome/libnm_glib/libnm_glib.c index abaf83c5f..b99eafc01 100644 --- a/libnm_glib/libnm_glib.c +++ b/gnome/libnm_glib/libnm_glib.c @@ -33,29 +33,29 @@ struct libnm_glib_ctx { - unsigned char check; + unsigned char check; - GMainContext *g_main_ctx; - GMainLoop *g_main_loop; - DBusConnection *dbus_con; - guint dbus_watcher; - gboolean thread_done; - gboolean thread_inited; + GMainContext * g_main_ctx; + GMainLoop * g_main_loop; + DBusConnection * dbus_con; + guint dbus_watcher; + gboolean thread_done; + gboolean thread_inited; - GSList *callbacks; - GMutex *callbacks_lock; - gint callback_id_last; + GSList * callbacks; + GMutex * callbacks_lock; + gint callback_id_last; - libnm_glib_status nm_status; + libnm_glib_state nm_state; }; typedef struct libnm_glib_callback { - gint id; - GMainContext *gmain_ctx; - libnm_glib_ctx *libnm_glib_ctx; - libnm_glib_callback_func func; - gpointer user_data; + gint id; + GMainContext * gmain_ctx; + libnm_glib_ctx * libnm_glib_ctx; + libnm_glib_callback_func func; + gpointer user_data; } libnm_glib_callback; @@ -64,20 +64,19 @@ static DBusConnection * libnm_glib_dbus_init (gpointer *user_data, GMainContext -static char *libnm_glib_get_nm_status (DBusConnection *con) +static NMState libnm_glib_get_nm_state (DBusConnection *con) { - DBusMessage *message; - DBusMessage *reply; - DBusError error; - char *status = NULL; - char *ret = NULL; + DBusMessage * message; + DBusMessage * reply; + DBusError error; + NMState state = NM_STATE_UNKNOWN; - g_return_val_if_fail (con != NULL, NULL); + g_return_val_if_fail (con != NULL, NM_STATE_UNKNOWN); - if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "status"))) + if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "state"))) { - fprintf (stderr, "libnm_glib_get_nm_status(): Couldn't allocate the dbus message\n"); - return NULL; + fprintf (stderr, "libnm_glib_get_nm_state(): Couldn't allocate the dbus message\n"); + return NM_STATE_UNKNOWN; } dbus_error_init (&error); @@ -85,30 +84,25 @@ static char *libnm_glib_get_nm_status (DBusConnection *con) dbus_message_unref (message); if (dbus_error_is_set (&error)) { - fprintf (stderr, "libnm_glib_get_nm_status(): %s raised:\n %s\n\n", error.name, error.message); - dbus_error_free (&error); - return NULL; + fprintf (stderr, "libnm_glib_get_nm_state(): %s raised:\n %s\n\n", error.name, error.message); + goto out; } if (!reply) { - fprintf (stderr, "libnm_glib_get_nm_status(): dbus reply message was NULL\n" ); - return NULL; + fprintf (stderr, "libnm_glib_get_nm_state(): dbus reply message was NULL\n" ); + goto out; } dbus_error_init (&error); - if (!(dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &status, DBUS_TYPE_INVALID))) - { - fprintf (stderr, "libnm_glib_get_nm_status(): error while getting args: name='%s' message='%s'\n", error.name, error.message); - if (dbus_error_is_set (&error)) - dbus_error_free (&error); - dbus_message_unref (reply); - return g_strdup ("error"); - } - ret = g_strdup (status); + if (!(dbus_message_get_args (reply, &error, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID))) + fprintf (stderr, "libnm_glib_get_nm_state(): error while getting args: name='%s' message='%s'\n", error.name, error.message); dbus_message_unref (reply); - return ret; +out: + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + return state; } @@ -158,21 +152,31 @@ static void libnm_glib_call_callbacks (libnm_glib_ctx *ctx) } -static void libnm_glib_update_status (libnm_glib_ctx *ctx, char *status) +static void libnm_glib_update_state (libnm_glib_ctx *ctx, NMState state) { - libnm_glib_status old_status; + libnm_glib_state old_state; g_return_if_fail (ctx != NULL); - old_status = ctx->nm_status; - if (!status) - ctx->nm_status = LIBNM_NO_NETWORKMANAGER; - else if (strcmp (status, "connected") == 0) - ctx->nm_status = LIBNM_ACTIVE_NETWORK_CONNECTION; - else - ctx->nm_status = LIBNM_NO_NETWORK_CONNECTION; + old_state = ctx->nm_state; + switch (state) + { + case NM_STATE_CONNECTED: + ctx->nm_state = LIBNM_ACTIVE_NETWORK_CONNECTION; + break; - if (old_status != ctx->nm_status) + case NM_STATE_SCANNING: + case NM_STATE_DISCONNECTED: + ctx->nm_state = LIBNM_NO_NETWORK_CONNECTION; + break; + + case NM_STATE_UNKNOWN: + default: + ctx->nm_state = LIBNM_NO_NETWORKMANAGER; + break; + } + + if (old_state != ctx->nm_state) libnm_glib_call_callbacks (ctx); } @@ -191,7 +195,7 @@ static DBusHandlerResult libnm_glib_dbus_filter (DBusConnection *connection, DBu if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected")) { /* Try to reactivate our connection to dbus on the next pass through the event loop */ - ctx->nm_status = LIBNM_NO_DBUS; + ctx->nm_state = LIBNM_NO_DBUS; dbus_connection_disconnect (ctx->dbus_con); libnm_glib_schedule_dbus_watcher (ctx); } @@ -215,13 +219,9 @@ static DBusHandlerResult libnm_glib_dbus_filter (DBusConnection *connection, DBu gboolean new_owner_good = (new_owner && (strlen (new_owner) > 0)); if (!old_owner_good && new_owner_good) /* Equivalent to old ServiceCreated signal */ - { - char *status_string = libnm_glib_get_nm_status (ctx->dbus_con); - libnm_glib_update_status (ctx, status_string); - g_free (status_string); - } + libnm_glib_update_state (ctx, libnm_glib_get_nm_state (ctx->dbus_con)); else if (old_owner_good && !new_owner_good) /* Equivalent to old ServiceDeleted signal */ - ctx->nm_status = LIBNM_NO_NETWORKMANAGER; + ctx->nm_state = LIBNM_NO_NETWORKMANAGER; } } } @@ -234,21 +234,14 @@ static DBusHandlerResult libnm_glib_dbus_filter (DBusConnection *connection, DBu || dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceActivating") || dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DevicesChanged")) { - char *status_string = libnm_glib_get_nm_status (ctx->dbus_con); - libnm_glib_update_status (ctx, status_string); - g_free (status_string); + libnm_glib_update_state (ctx, libnm_glib_get_nm_state (ctx->dbus_con)); } - else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "NetworkStatusChange")) + else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, NM_DBUS_SIGNAL_STATE_CHANGE)) { - char *status_string = NULL; + NMState state = NM_STATE_UNKNOWN; - if (!(dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &status_string, DBUS_TYPE_INVALID))) - status_string = g_strdup ("error"); - else - status_string = g_strdup (status_string); - - libnm_glib_update_status (ctx, status_string); - g_free (status_string); + dbus_message_get_args (message, &error, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID); + libnm_glib_update_state (ctx, state); } else handled = FALSE; @@ -374,13 +367,10 @@ static gpointer libnm_glib_dbus_worker (gpointer user_data) */ if (!ctx->dbus_con) libnm_glib_schedule_dbus_watcher (ctx); + else { - char *status_string = NULL; - /* Get initial status */ - status_string = libnm_glib_get_nm_status (ctx->dbus_con); - libnm_glib_update_status (ctx, status_string); - g_free (status_string); + libnm_glib_update_state (ctx, libnm_glib_get_nm_state (ctx->dbus_con)); } ctx->thread_inited = TRUE; @@ -463,11 +453,7 @@ libnm_glib_ctx *libnm_glib_init (void) */ ctx->dbus_con = libnm_glib_dbus_init ((gpointer)ctx, ctx->g_main_ctx); if (ctx->dbus_con) - { - char *status_string = libnm_glib_get_nm_status (ctx->dbus_con); - libnm_glib_update_status (ctx, status_string); - g_free (status_string); - } + libnm_glib_update_state (ctx, libnm_glib_get_nm_state (ctx->dbus_con)); if (!g_thread_create (libnm_glib_dbus_worker, ctx, FALSE, &error)) { @@ -501,12 +487,12 @@ void libnm_glib_shutdown (libnm_glib_ctx *ctx) } -libnm_glib_status libnm_glib_get_network_status (const libnm_glib_ctx *ctx) +libnm_glib_state libnm_glib_get_network_state (const libnm_glib_ctx *ctx) { if (!ctx) return LIBNM_INVALID_CONTEXT; - return ctx->nm_status; + return ctx->nm_state; } diff --git a/libnm_glib/libnm_glib.h b/gnome/libnm_glib/libnm_glib.h similarity index 92% rename from libnm_glib/libnm_glib.h rename to gnome/libnm_glib/libnm_glib.h index 97b988a9b..76e1fa602 100644 --- a/libnm_glib/libnm_glib.h +++ b/gnome/libnm_glib/libnm_glib.h @@ -28,14 +28,14 @@ extern "C" { #endif -typedef enum libnm_glib_status +typedef enum libnm_glib_state { LIBNM_NO_DBUS = 0, LIBNM_NO_NETWORKMANAGER, LIBNM_NO_NETWORK_CONNECTION, LIBNM_ACTIVE_NETWORK_CONNECTION, LIBNM_INVALID_CONTEXT -} libnm_glib_status; +} libnm_glib_state; typedef struct libnm_glib_ctx libnm_glib_ctx; @@ -46,7 +46,7 @@ typedef void (*libnm_glib_callback_func) (libnm_glib_ctx *libnm_ctx, gpointer us libnm_glib_ctx *libnm_glib_init (void); void libnm_glib_shutdown (libnm_glib_ctx *ctx); -libnm_glib_status libnm_glib_get_network_status (const libnm_glib_ctx *ctx); +libnm_glib_state libnm_glib_get_network_state (const libnm_glib_ctx *ctx); gint libnm_glib_register_callback (libnm_glib_ctx *ctx, libnm_glib_callback_func func, gpointer user_data, GMainContext *g_main_ctx); void libnm_glib_unregister_callback (libnm_glib_ctx *ctx, gint id); diff --git a/libnm_glib/libnm_glib.pc.in b/gnome/libnm_glib/libnm_glib.pc.in similarity index 100% rename from libnm_glib/libnm_glib.pc.in rename to gnome/libnm_glib/libnm_glib.pc.in diff --git a/info-daemon/.cvsignore b/info-daemon/.cvsignore deleted file mode 100644 index 83241dc6a..000000000 --- a/info-daemon/.cvsignore +++ /dev/null @@ -1,6 +0,0 @@ -Makefile -Makefile.in -NetworkManagerInfo -passphrase.glade.bak -passphrase.gladep -passphrase.gladep.bak diff --git a/info-daemon/Makefile.am b/info-daemon/Makefile.am deleted file mode 100644 index 9c9da583d..000000000 --- a/info-daemon/Makefile.am +++ /dev/null @@ -1,57 +0,0 @@ -INCLUDES = -I${top_srcdir} -I${top_srcdir}/utils - -AM_CPPFLAGS = \ - $(DBUS_CFLAGS) \ - $(GTHREAD_CFLAGS) \ - $(GTK_CFLAGS) \ - $(GDK_PIXBUF_CFLAGS) \ - $(GLADE_CFLAGS) \ - $(GCONF_CFLAGS) \ - $(LIBGNOMEUI_CFLAGS) \ - $(GNOME_KEYRING_CFLAGS) \ - -Wall \ - -DDBUS_API_SUBJECT_TO_CHANGE \ - -DG_DISABLE_DEPRECATED \ - -DGTK_DISABLE_DEPRECATED \ - -DGLADEDIR=\""$(datadir)/NetworkManagerInfo/glade"\" \ - -DBINDIR=\"$(bindir)\" \ - -DPREFIX=\""$(prefix)"\" \ - -DSYSCONFDIR=\""$(sysconfdir)"\" \ - -DVERSION="\"$(VERSION)\"" \ - -DLIBDIR=\""$(libdir)"\" \ - -DLIBEXECDIR=\""$(libexecdir)"\" \ - -DDATADIR=\"$(datadir)\" - -bin_PROGRAMS = NetworkManagerInfo - -NetworkManagerInfo_SOURCES = NetworkManagerInfo.h \ - NetworkManagerInfo.c \ - NetworkManagerInfoDbus.h \ - NetworkManagerInfoDbus.c \ - NetworkManagerInfoPassphraseDialog.c \ - NetworkManagerInfoPassphraseDialog.h \ - NetworkManagerInfoVPN.c \ - NetworkManagerInfoVPN.h \ - NetworkManagerInfoNetworksDialog.c \ - NetworkManagerInfoNetworksDialog.h - -NetworkManagerInfo_LDADD = \ - $(DBUS_LIBS) \ - $(GTHREAD_LIBS) \ - $(GLADE_LIBS) \ - $(GCONF_LIBS) \ - $(GTK_LIBS) \ - $(GDK_PIXBUF_LIBS) \ - $(GNOME_KEYRING_LIBS) \ - $(LIBGNOMEUI_LIBS) \ - $(top_builddir)/utils/libnmutils.la - - -gladedir = $(datadir)/NetworkManagerInfo/glade -glade_DATA = passphrase.glade keyring.png networks.glade - -dbusservicedir=$(DBUS_SYS_DIR) -dbusservice_DATA = NetworkManagerInfo.conf - -EXTRA_DIST = $(glade_DATA) $(dbusservice_DATA) - diff --git a/info-daemon/NetworkManagerInfo.c b/info-daemon/NetworkManagerInfo.c deleted file mode 100644 index d8778201d..000000000 --- a/info-daemon/NetworkManagerInfo.c +++ /dev/null @@ -1,336 +0,0 @@ -/* NetworkManagerInfo -- Manage allowed access points and provide a UI - * for WEP key entry - * - * Dan Williams - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2004 Red Hat, Inc. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "config.h" -#include "NetworkManagerInfoDbus.h" -#include "NetworkManagerInfo.h" -#include "NetworkManagerInfoPassphraseDialog.h" -#include "nm-utils.h" - -static void nmi_spawn_notification_icon (NMIAppInfo *info); - - -/* - * nmi_gconf_networks_notify_callback - * - * Callback from gconf when wireless networking key/values have changed. - * - */ -static void nmi_gconf_networks_notify_callback (GConfClient *client, guint connection_id, GConfEntry *entry, gpointer user_data) -{ - NMIAppInfo *info = (NMIAppInfo *)user_data; - const char *key = NULL; - - g_return_if_fail (client != NULL); - g_return_if_fail (entry != NULL); - g_return_if_fail (info != NULL); - - if ((key = gconf_entry_get_key (entry))) - { - int path_len = strlen (NMI_GCONF_WIRELESS_NETWORKS_PATH) + 1; - - if (strncmp (NMI_GCONF_WIRELESS_NETWORKS_PATH"/", key, path_len) == 0) - { - char *network = g_strdup ((key + path_len)); - char *slash_pos; - char *unescaped_network; - - /* If its a key under the network name, zero out the slash so we - * are left with only the network name. - */ - unescaped_network = gconf_unescape_key (network, strlen (network)); - if ((slash_pos = strchr (unescaped_network, '/'))) - *slash_pos = '\0'; - - nmi_dbus_signal_update_network (info->connection, unescaped_network, NETWORK_TYPE_ALLOWED); - g_free (unescaped_network); - g_free (network); - } - } -} - - -/* - * nmi_gconf_vpn_connections_notify_callback - * - * Callback from gconf when VPN connection values have changed. - * - */ -static void nmi_gconf_vpn_connections_notify_callback (GConfClient *client, guint connection_id, GConfEntry *entry, gpointer user_data) -{ - NMIAppInfo *info = (NMIAppInfo *)user_data; - const char *key = NULL; - - g_return_if_fail (client != NULL); - g_return_if_fail (entry != NULL); - g_return_if_fail (info != NULL); - - if ((key = gconf_entry_get_key (entry))) - { - int path_len = strlen (NMI_GCONF_VPN_CONNECTIONS_PATH) + 1; - - if (strncmp (NMI_GCONF_VPN_CONNECTIONS_PATH"/", key, path_len) == 0) - { - char *name = g_strdup ((key + path_len)); - char *slash_pos; - char *unescaped_name; - - /* If its a key under the the VPN name, zero out the slash so we - * are left with only the VPN name. - */ - unescaped_name = gconf_unescape_key (name, strlen (name)); - if ((slash_pos = strchr (unescaped_name, '/'))) - *slash_pos = '\0'; - - nmi_dbus_signal_update_vpn_connection (info->connection, unescaped_name); - g_free (unescaped_name); - g_free (name); - } - } -} - - -#ifdef BUILD_NOTIFICATION_ICON -static void -on_icon_exit_callback (GPid pid, int status, gpointer data) -{ - NMIAppInfo *info; - info = (NMIAppInfo *) data; - - nmi_spawn_notification_icon (info); -} - -static void -nmi_spawn_notification_icon (NMIAppInfo *info) -{ - GError *error; - - gchar *notification_icon_cmd[] = {LIBEXECDIR"/NetworkManagerNotification", NULL}; - - if (info->notification_icon_pid > 0) - g_spawn_close_pid (info->notification_icon_pid); - - if (info->notification_icon_watch != 0) - g_source_remove (info->notification_icon_watch); - - if (info->notification_icon_respawn_timer == NULL) - info->notification_icon_respawn_timer = g_timer_new(); - else - { - gdouble elapsed_time; - gulong dummy; - - elapsed_time = g_timer_elapsed (info->notification_icon_respawn_timer, &dummy); - - /*5 seconds between respawns*/ - if (elapsed_time > 5) - info->notification_icon_respawn_counter = 0; - else - info->notification_icon_respawn_counter++; - - } - - g_timer_start (info->notification_icon_respawn_timer); - - /*spawn the panel notification icon unless it has crashed numerous times within a time frame*/ - if (info->notification_icon_respawn_counter < 5) - { - if (!g_spawn_async (NULL, - notification_icon_cmd, - NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, - &(info->notification_icon_pid), - &error)) - { - g_warning ("Could not spawn NetworkManager's notification icon (%s)", error->message); - g_error_free (error); - } - else - { - info->notification_icon_watch = g_child_watch_add (info->notification_icon_pid, on_icon_exit_callback, info); - } - } else { - g_timer_destroy (info->notification_icon_respawn_timer); - info->notification_icon_respawn_timer = NULL; - } -} - -#endif - -static void session_die (GnomeClient *client, gpointer client_data) -{ - gtk_main_quit (); -} - -static gboolean session_save (GnomeClient *client, gpointer client_data) -{ - return TRUE; -} - - -/* - * main - * - */ -int main( int argc, char *argv[] ) -{ - GnomeProgram *program; - GnomeClient *client; - GPtrArray *restart_argv; - gboolean no_daemon; - DBusError dbus_error; - DBusConnection *dbus_connection; - int err; - NMIAppInfo *app_info = NULL; - guint notify_id; - - struct poptOption options[] = - { - { "no-daemon", 'n', POPT_ARG_NONE, NULL, 0, - "Don't detatch from the console and run in the background.", NULL }, - { NULL, '\0', 0, NULL, 0, NULL, NULL } - }; - - options[0].arg = &no_daemon; - - program = gnome_program_init ("NetworkManagerInfo", VERSION, - LIBGNOMEUI_MODULE, argc, argv, - GNOME_PROGRAM_STANDARD_PROPERTIES, - GNOME_PARAM_POPT_TABLE, options, - GNOME_PARAM_HUMAN_READABLE_NAME, "Network Manager User Info Service", - NULL); - - client = gnome_master_client (); - - openlog("NetworkManagerInfo", (no_daemon) ? LOG_CONS | LOG_PERROR : LOG_CONS, (no_daemon) ? LOG_USER : LOG_DAEMON); - - if (!no_daemon && daemon (FALSE, FALSE) < 0) - { - nm_warning ("NetworkManagerInfo could not daemonize. errno = %d", errno ); - exit (1); - } - - app_info = g_new0 (NMIAppInfo, 1); - if (!app_info) - { - nm_error ("Not enough memory for application data."); - exit (1); - } - - g_type_init (); - if (!g_thread_supported ()) - g_thread_init (NULL); - - /* Set up our connection to the message bus */ - dbus_error_init (&dbus_error); - dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error); - if (dbus_connection == NULL) - { - nm_error ("NetworkManagerInfo could not get the system bus. Make sure the message bus daemon is running?"); - exit (1); - } - dbus_connection_set_change_sigpipe (TRUE); - dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE); - dbus_connection_setup_with_g_main (dbus_connection, NULL); - app_info->connection = dbus_connection; - - /* Grab a connection to the GConf daemon. We also want to - * get change notifications for our wireless networking data. - */ - app_info->gconf_client = gconf_client_get_default (); - gconf_client_add_dir (app_info->gconf_client, NMI_GCONF_WIRELESS_NETWORKS_PATH, - GCONF_CLIENT_PRELOAD_NONE, NULL); - notify_id = gconf_client_notify_add (app_info->gconf_client, NMI_GCONF_WIRELESS_NETWORKS_PATH, - nmi_gconf_networks_notify_callback, app_info, NULL, NULL); - notify_id = gconf_client_notify_add (app_info->gconf_client, NMI_GCONF_VPN_CONNECTIONS_PATH, - nmi_gconf_vpn_connections_notify_callback, app_info, NULL, NULL); - - /* Create our own dbus service */ - err = nmi_dbus_service_init (dbus_connection, app_info); - if (err == -1) - exit (1); - - gnome_program_init ("NetworkManagerInfo", VERSION, LIBGNOMEUI_MODULE, - argc, argv, - GNOME_PARAM_NONE); - - - app_info->notification_icon_pid = 0; - -#ifdef BUILD_NOTIFICATION_ICON - nmi_spawn_notification_icon (app_info); -#endif - - restart_argv = g_ptr_array_new (); - g_ptr_array_add (restart_argv, g_get_prgname ()); - gnome_client_set_restart_command (client, restart_argv->len, (char**) restart_argv->pdata); - g_ptr_array_free (restart_argv, TRUE); - gnome_client_set_restart_style (client, GNOME_RESTART_IMMEDIATELY); - - if (nmi_passphrase_dialog_init (app_info) != 0) - { - gnome_client_set_restart_style (client, GNOME_RESTART_ANYWAY); - exit (1); - } - - g_signal_connect (client, - "save_yourself", - G_CALLBACK (session_save), - NULL); - - g_signal_connect (client, - "die", - G_CALLBACK (session_die), - NULL); - - gtk_main (); - - if (app_info->notification_icon_pid > 0) - kill (app_info->notification_icon_pid, SIGTERM); - - gnome_client_set_restart_style (client, GNOME_RESTART_ANYWAY); - - gconf_client_notify_remove (app_info->gconf_client, notify_id); - g_object_unref (G_OBJECT (app_info->gconf_client)); - /*g_object_unref (app_info->notification_icon);*/ - g_free (app_info); - - return 0; -} diff --git a/info-daemon/NetworkManagerInfo.h b/info-daemon/NetworkManagerInfo.h deleted file mode 100644 index 3c3be1fbb..000000000 --- a/info-daemon/NetworkManagerInfo.h +++ /dev/null @@ -1,63 +0,0 @@ -/* NetworkManagerInfo -- Manage allowed access points and provide a UI - * for WEP key entry - * - * Dan Williams - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2004 Red Hat, Inc. - */ - -#ifndef NETWORK_MANAGER_INFO_H -#define NETWORK_MANAGER_INFO_H - -#include -#include -#include -#include -#include -#include -#include -#include - -#define NMI_GCONF_VPN_CONNECTIONS_PATH "/system/networking/vpn_connections" - -struct NMIAppInfo -{ - GladeXML *passphrase_dialog; - GtkWidget *vpn_password_dialog; - DBusMessage *vpn_password_message; - char *orig_label_text; - DBusConnection *connection; - GConfClient *gconf_client; - - GladeXML *networks_dialog; - GtkListStore *networks_list_store; - - GdkPixbuf *padlock_pixbuf; - - /* - GtkWidget *notification_icon; - */ - GPid notification_icon_pid; - guint notification_icon_watch; - guint notification_icon_respawn_counter; - GTimer *notification_icon_respawn_timer; - - GSource *shutdown_timeout; -}; -typedef struct NMIAppInfo NMIAppInfo; - -#endif diff --git a/info-daemon/NetworkManagerInfoDbus.h b/info-daemon/NetworkManagerInfoDbus.h deleted file mode 100644 index 2de90e35a..000000000 --- a/info-daemon/NetworkManagerInfoDbus.h +++ /dev/null @@ -1,48 +0,0 @@ -/* NetworkManagerInfo -- Manage allowed access points and provide a UI - * for WEP key entry - * - * Dan Williams - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2004 Red Hat, Inc. - */ - -#ifndef NETWORK_MANAGER_INFO_DBUS_SERVICE_H -#define NETWORK_MANAGER_INFO_DBUS_SERVICE_H - -#include -#include -#include -#include "NetworkManager.h" -#include "NetworkManagerInfo.h" - - -int nmi_dbus_service_init (DBusConnection *dbus_connection, NMIAppInfo *info); - -const char * nmi_dbus_nm_get_network_essid (DBusConnection *connection, const char *ap_path); - -gboolean nmi_dbus_nm_get_network_encrypted (DBusConnection *connection, const char *ap_path); - -void nmi_dbus_return_user_key (DBusConnection *connection, const char *device, - const char *network, const char *passphrase, const int key_type); - -void nmi_dbus_return_vpn_password (DBusConnection *connection, DBusMessage *message, const char *password); - -void nmi_dbus_signal_update_network (DBusConnection *connection, const char *network, NMNetworkType type); - -void nmi_dbus_signal_update_vpn_connection (DBusConnection *connection, const char *name); - -#endif diff --git a/info-daemon/NetworkManagerInfoNetworksDialog.c b/info-daemon/NetworkManagerInfoNetworksDialog.c deleted file mode 100644 index 0d97c7ec3..000000000 --- a/info-daemon/NetworkManagerInfoNetworksDialog.c +++ /dev/null @@ -1,86 +0,0 @@ -/* NetworkManagerInfo -- Manage allowed access points and provide a UI - * for WEP key entry - * - * Dan Williams - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2004 Red Hat, Inc. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "NetworkManagerInfo.h" -#include "NetworkManagerInfoNetworksDialog.h" - - -/* - * nmi_networks_dialog_init - * - * Initialize the networks modification dialog - * - * Returns: 0 on success - * -1 on failure - */ -int nmi_networks_dialog_init (NMIAppInfo *info) -{ - GtkWidget *dialog; - - info->networks_dialog = glade_xml_new(GLADEDIR"/networks.glade", NULL, NULL); - if (!info->networks_dialog) - { - fprintf (stderr, "Could not open the networks dialog glade file!\n"); - return (-1); - } - - dialog = glade_xml_get_widget (info->networks_dialog, "networks_dialog"); - gtk_widget_hide (dialog); - -#if 0 - save_button = GTK_BUTTON (glade_xml_get_widget (info->networks_dialog, "save_button")); - g_signal_connect (G_OBJECT (save_button), "clicked", GTK_SIGNAL_FUNC (nmi_networks_dialog_save_clicked), info); - cancel_button = GTK_BUTTON (glade_xml_get_widget (info->networks_dialog, "cancel_button")); - g_signal_connect (G_OBJECT (cancel_button), "clicked", GTK_SIGNAL_FUNC (nmi_networks_dialog_cancel_clicked), info); - - /* Create data store for our networks list */ - info->networks_list_store = gtk_list_store_new (N_COLUMNS, G_TYPE_INT, G_TYPE_STRING, G_TYPE_BOOLEAN); - if (!info->networks_list_store) - return (-1); - - /* Tell the list to use our data store */ - list_view = glade_xml_get_widget (info->networks_dialog, "networks_list"); - gtk_tree_view_set_model (GTK_TREE_VIEW (list_view), GTK_TREE_MODEL (info->networks_list_store)); - - /* Set up the columns and renderers for our list */ - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new (); - gtk_tree_view_column_set_expand (column, TRUE); - gtk_tree_view_column_pack_start (column, renderer, TRUE); - gtk_tree_view_column_set_attributes (column, renderer, "markup", TEXT_COLUMN, NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), column); - - info->padlock_pixbuf = gdk_pixbuf_new_from_file_at_size (GLADEDIR"/keyring.png", 16, 16, &error); - if (!info->padlock_pixbuf) - fprintf (stderr, "nmi_new_networks_dialog_init(): could not load padlock image\n"); -#endif - - return (0); -} diff --git a/info-daemon/NetworkManagerInfoNetworksDialog.h b/info-daemon/NetworkManagerInfoNetworksDialog.h deleted file mode 100644 index d7655a3ae..000000000 --- a/info-daemon/NetworkManagerInfoNetworksDialog.h +++ /dev/null @@ -1,30 +0,0 @@ -/* NetworkManagerInfo -- Manage allowed access points and provide a UI - * for WEP key entry - * - * Dan Williams - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2004 Red Hat, Inc. - */ - -#ifndef NETWORK_MANAGER_INFO_NETWORKS_DIALOG_H -#define NETWORK_MANAGER_INFO_NETWORKS_DIALOG_H - -#include "NetworkManagerInfo.h" - -int nmi_networks_dialog_init (NMIAppInfo *info); - -#endif diff --git a/info-daemon/NetworkManagerInfoPassphraseDialog.c b/info-daemon/NetworkManagerInfoPassphraseDialog.c deleted file mode 100644 index 7a8ff5ea2..000000000 --- a/info-daemon/NetworkManagerInfoPassphraseDialog.c +++ /dev/null @@ -1,352 +0,0 @@ -/* NetworkManagerInfo -- Manage allowed access points and provide a UI - * for WEP key entry - * - * Dan Williams - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2004 Red Hat, Inc. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef _ -#define _(x) dgettext (GETTEXT_PACKAGE, x) -#define N_(x) x -#endif - -#include "NetworkManagerInfoDbus.h" -#include "NetworkManagerInfoPassphraseDialog.h" -#include "nm-utils.h" - -enum NMIPassphraseDialogKeyTypes -{ - KEY_TYPE_128_BIT_PASSPHRASE = 0, - KEY_TYPE_ASCII_KEY = 1, - KEY_TYPE_HEX_KEY = 2 -}; - -static void update_button_cb (GtkWidget *widget, GladeXML *xml) -{ - GtkButton *button; - GtkComboBox *combo; - GtkEntry *passphrase_entry; - const char *passphrase_text; - gboolean enable = TRUE; - - g_return_if_fail (xml != NULL); - - button = GTK_BUTTON (glade_xml_get_widget (xml, "login_button")); - combo = GTK_COMBO_BOX (glade_xml_get_widget (xml, "key_type_combo")); - passphrase_entry = GTK_ENTRY (glade_xml_get_widget (xml, "passphrase_entry")); - passphrase_text = gtk_entry_get_text (passphrase_entry); - - if (passphrase_text[0] == '\000') - enable = FALSE; - else - { - int combo_choice = gtk_combo_box_get_active (combo); - switch (combo_choice) - { - case KEY_TYPE_ASCII_KEY: - if ((strlen (passphrase_text) != 5) && (strlen (passphrase_text) != 13)) - enable = FALSE; - break; - case KEY_TYPE_HEX_KEY: - if ((strlen (passphrase_text) != 10) && (strlen (passphrase_text) != 26)) - enable = FALSE; - break; - default: - break; - } - } - - gtk_widget_set_sensitive (GTK_WIDGET (button), enable); -} - -/* - * nmi_passphrase_dialog_clear - * - * Return dialog to its original state; clear out any network or device qdatas, - * clear the passphrase entry, and hide the dialog. - * - */ -void nmi_passphrase_dialog_clear (GtkWidget *dialog, GtkWidget *entry) -{ - char *data; - - g_return_if_fail (dialog != NULL); - g_return_if_fail (entry != NULL); - - data = g_object_get_data (G_OBJECT (dialog), "device"); - if (data) - { - g_free (data); - g_object_set_data (G_OBJECT (dialog), "device", NULL); - } - - data = g_object_get_data (G_OBJECT (dialog), "network"); - if (data) - { - g_free (data); - g_object_set_data (G_OBJECT (dialog), "network", NULL); - } - - gtk_entry_set_text (GTK_ENTRY (entry), ""); - gtk_widget_hide (dialog); -} - - -/* - * nmi_passphrase_dialog_key_type_combo_changed - * - * Change the text of the passphrase entry label to match the selected - * key type. - * - */ -void nmi_passphrase_dialog_key_type_combo_changed (GtkWidget *key_type_combo, gpointer user_data) -{ - GtkLabel *entry_label; - int combo_choice; - NMIAppInfo *info = (NMIAppInfo *)user_data; - - g_return_if_fail (info != NULL); - - entry_label = GTK_LABEL (glade_xml_get_widget (info->passphrase_dialog, "passphrase_entry_label")); - switch ((combo_choice = gtk_combo_box_get_active (GTK_COMBO_BOX (key_type_combo)))) - { - case KEY_TYPE_128_BIT_PASSPHRASE: - gtk_label_set_label (entry_label, _("Passphrase:")); - break; - case KEY_TYPE_ASCII_KEY: - gtk_label_set_label (entry_label, _("Ascii Key:")); - break; - case KEY_TYPE_HEX_KEY: - gtk_label_set_label (entry_label, _("Hex Key:")); - break; - default: - break; - } -} - - -/* - * nmi_passphrase_dialog_ok_clicked - * - * OK button handler; grab the passphrase and send it back - * to NetworkManager. Get rid of the dialog. - * - */ -void nmi_passphrase_dialog_ok_clicked (GtkWidget *ok_button, gpointer user_data) -{ - GtkWidget *dialog = gtk_widget_get_toplevel (ok_button); - NMIAppInfo *info = (NMIAppInfo *)user_data; - - g_return_if_fail (info != NULL); - - if (GTK_WIDGET_TOPLEVEL (dialog)) - { - GtkEntry *entry = GTK_ENTRY (glade_xml_get_widget (info->passphrase_dialog, "passphrase_entry")); - GtkComboBox *key_type_combo = GTK_COMBO_BOX (glade_xml_get_widget (info->passphrase_dialog, "key_type_combo")); - int key_type = gtk_combo_box_get_active (key_type_combo); - const char *passphrase = gtk_entry_get_text (entry); - const char *device = g_object_get_data (G_OBJECT (dialog), "device"); - const char *network = g_object_get_data (G_OBJECT (dialog), "network"); - char *key = NULL; - int key_type_return = NM_ENC_TYPE_UNKNOWN; - GConfEntry *gconf_entry; - char *escaped_network; - - switch (key_type) - { - case KEY_TYPE_128_BIT_PASSPHRASE: - key_type_return = NM_ENC_TYPE_128_BIT_PASSPHRASE; - break; - case KEY_TYPE_ASCII_KEY: - key_type_return = NM_ENC_TYPE_ASCII_KEY; - break; - case KEY_TYPE_HEX_KEY: - key_type_return = NM_ENC_TYPE_HEX_KEY; - break; - default: - key_type_return = NM_ENC_TYPE_UNKNOWN; - break; - } - - /* Tell NetworkManager about the key the user typed in */ - nmi_dbus_return_user_key (info->connection, device, network, passphrase, key_type_return); - - /* Update GConf with the new user key */ - escaped_network = gconf_escape_key (network, strlen (network)); - key = g_strdup_printf ("%s/%s", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); - gconf_entry = gconf_client_get_entry (info->gconf_client, key, NULL, TRUE, NULL); - g_free (key); - if (gconf_entry) - { - gconf_entry_unref (gconf_entry); - key = g_strdup_printf ("%s/%s/key", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); - gconf_client_set_string (info->gconf_client, key, passphrase, NULL); - g_free (key); - key = g_strdup_printf ("%s/%s/essid", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); - gconf_client_set_string (info->gconf_client, key, network, NULL); - g_free (key); - key = g_strdup_printf ("%s/%s/key_type", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); - gconf_client_set_int (info->gconf_client, key, key_type_return, NULL); - g_free (key); - } - g_free (escaped_network); - - nmi_passphrase_dialog_clear (dialog, GTK_WIDGET (entry)); - } -} - - -/* - * nmi_passphrase_dialog_cancel_clicked - * - * Cancel button handler; return a cancellation message to NetworkManager - * and get rid of the dialog. - * - */ -void nmi_passphrase_dialog_cancel_clicked (GtkWidget *cancel_button, gpointer user_data) -{ - GtkWidget *dialog = gtk_widget_get_toplevel (cancel_button); - NMIAppInfo *info = (NMIAppInfo *)user_data; - - g_return_if_fail (info != NULL); - - if (GTK_WIDGET_TOPLEVEL (dialog)) - { - const char *device = g_object_get_data (G_OBJECT (dialog), "device"); - const char *network = g_object_get_data (G_OBJECT (dialog), "network"); - - nmi_dbus_return_user_key (info->connection, device, network, "***canceled***", NM_ENC_TYPE_UNKNOWN); - nmi_passphrase_dialog_clear (dialog, glade_xml_get_widget (info->passphrase_dialog, "passphrase_entry")); - } -} - - -/* - * nmi_passphrase_dialog_show - * - * Pop up the user key dialog in response to a dbus message - * - */ -void nmi_passphrase_dialog_show (const char *device, const char *network, NMIAppInfo *info) -{ - GtkWidget *dialog; - - g_return_if_fail (info != NULL); - g_return_if_fail (device != NULL); - g_return_if_fail (network != NULL); - - dialog = glade_xml_get_widget (info->passphrase_dialog, "passphrase_dialog"); - nmi_passphrase_dialog_clear (dialog, glade_xml_get_widget (info->passphrase_dialog, "passphrase_entry")); - - /* Insert the Network name into the dialog text */ - if (info->orig_label_text) - { - GtkWidget *label = glade_xml_get_widget (info->passphrase_dialog, "label1"); - char *new_label_text = g_strdup_printf (info->orig_label_text, network); - - gtk_label_set_label (GTK_LABEL (label), new_label_text); - } - - g_object_set_data (G_OBJECT (dialog), "device", g_strdup (device)); - g_object_set_data (G_OBJECT (dialog), "network", g_strdup (network)); - - gtk_widget_show (dialog); -} - - -/* - * nmi_passphrase_dialog_cancel - * - * Cancel and hide any user key dialog that might be up - * - */ -void nmi_passphrase_dialog_cancel (NMIAppInfo *info) -{ - GtkWidget *dialog; - GtkWidget *entry; - - g_return_if_fail (info != NULL); - - dialog = glade_xml_get_widget (info->passphrase_dialog, "passphrase_dialog"); - entry = glade_xml_get_widget (info->passphrase_dialog, "passphrase_entry"); - nmi_passphrase_dialog_clear (dialog, entry); -} - - -/* - * nmi_passphrase_dialog_init - * - * Initialize the passphrase dialog - * - * Returns: 0 on success - * -1 on failure - */ -int nmi_passphrase_dialog_init (NMIAppInfo *info) -{ - GtkWidget *dialog; - GtkButton *ok_button; - GtkButton *cancel_button; - GtkEntry *entry; - GtkComboBox *key_type_combo; - GtkLabel *label; - - info->passphrase_dialog = glade_xml_new(GLADEDIR"/passphrase.glade", NULL, NULL); - if (!info->passphrase_dialog) - { - nm_warning ("Could not open the passphrase dialog glade file!"); - return (-1); - } - - dialog = glade_xml_get_widget (info->passphrase_dialog, "passphrase_dialog"); - gtk_widget_hide (dialog); - - ok_button = GTK_BUTTON (glade_xml_get_widget (info->passphrase_dialog, "login_button")); - g_signal_connect (G_OBJECT (ok_button), "clicked", GTK_SIGNAL_FUNC (nmi_passphrase_dialog_ok_clicked), info); - gtk_widget_grab_default (GTK_WIDGET (ok_button)); - cancel_button = GTK_BUTTON (glade_xml_get_widget (info->passphrase_dialog, "cancel_button")); - g_signal_connect (G_OBJECT (cancel_button), "clicked", GTK_SIGNAL_FUNC (nmi_passphrase_dialog_cancel_clicked), info); - - entry = GTK_ENTRY (glade_xml_get_widget (info->passphrase_dialog, "passphrase_entry")); - nmi_passphrase_dialog_clear (dialog, GTK_WIDGET (entry)); - gtk_widget_set_sensitive (GTK_WIDGET (ok_button), FALSE); - g_signal_connect (entry, "changed", G_CALLBACK (update_button_cb), info->passphrase_dialog); - - key_type_combo = GTK_COMBO_BOX (glade_xml_get_widget (info->passphrase_dialog, "key_type_combo")); - gtk_combo_box_set_active (key_type_combo, 0); - g_signal_connect (G_OBJECT (key_type_combo), "changed", GTK_SIGNAL_FUNC (nmi_passphrase_dialog_key_type_combo_changed), info); - nmi_passphrase_dialog_key_type_combo_changed (GTK_WIDGET (key_type_combo), info); - - /* Save original label text to preserve the '%s' and other formatting that gets overwritten - * when the dialog is first shown. - */ - label = GTK_LABEL (glade_xml_get_widget (info->passphrase_dialog, "label1")); - info->orig_label_text = g_strdup (gtk_label_get_label (label)); - - return (0); -} diff --git a/info-daemon/NetworkManagerInfoVPN.c b/info-daemon/NetworkManagerInfoVPN.c deleted file mode 100644 index 6caba1ea0..000000000 --- a/info-daemon/NetworkManagerInfoVPN.c +++ /dev/null @@ -1,188 +0,0 @@ -/* NetworkManagerInfo -- Manage allowed access points and provide a UI - * for WEP key entry - * - * Colin Walters - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2004 Red Hat, Inc. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef _ -#define _(x) dgettext (GETTEXT_PACKAGE, x) -#define N_(x) x -#endif - -#include "NetworkManagerInfoDbus.h" -#include "NetworkManagerInfoVPN.h" -#include "nm-utils.h" - -int nmi_vpn_init (NMIAppInfo *info) -{ - info->vpn_password_dialog = NULL; - info->vpn_password_message = NULL; - return 0; -} - -static gboolean lookup_pass (const char *vpn, const char *username, char **password) -{ - GList *result; - - if (gnome_keyring_find_network_password_sync (username, - NULL, - vpn, - NULL, - "vpn", - NULL, - 0, - &result) != GNOME_KEYRING_RESULT_OK) - return FALSE; - - if (result) - { - GnomeKeyringNetworkPasswordData *data = result->data; - *password = g_strdup (data->password); - gnome_keyring_network_password_list_free (result); - return TRUE; - } - return FALSE; -} - -static void save_vpn_password (const char *vpn, const char *keyring, const char *username, const char *password) -{ - guint32 item_id; - GnomeKeyringResult keyring_result; - - keyring_result = gnome_keyring_set_network_password_sync (NULL, - username, - NULL, - vpn, - NULL, - "vpn", - NULL, - 0, - password, - &item_id); - - if (keyring_result != GNOME_KEYRING_RESULT_OK) - { - nm_warning ("Couldn't store password in keyring, code %d", - (int) keyring_result); - } -} - -static void close_cb (GtkWidget *dialog, gpointer user_data) -{ - NMIAppInfo *info = user_data; - nmi_dbus_return_vpn_password (info->connection, info->vpn_password_message, NULL); - gtk_widget_destroy (dialog); - info->vpn_password_dialog = NULL; -} - -static void response_cb (GtkWidget *dialog, int response, gpointer user_data) -{ - NMIAppInfo *info = user_data; - GnomePasswordDialog *passwd_dialog; - char *password; - const char *vpn, *username; - - if (response != GTK_RESPONSE_OK) - { - close_cb (dialog, user_data); - return; - } - - passwd_dialog = GNOME_PASSWORD_DIALOG (dialog); - username = g_object_get_data (G_OBJECT (passwd_dialog), "NetworkManagerInfoVPN-username"); - vpn = g_object_get_data (G_OBJECT (passwd_dialog), "NetworkManagerInfoVPN-vpn"); - password = gnome_password_dialog_get_password (passwd_dialog); - nm_warning ("returning VPN vpn_password for %s@%s: %s", username, vpn, password); - nmi_dbus_return_vpn_password (info->connection, info->vpn_password_message, password); - switch (gnome_password_dialog_get_remember (passwd_dialog)) - { - case GNOME_PASSWORD_DIALOG_REMEMBER_SESSION: - save_vpn_password (vpn, "session", username, password); - break; - case GNOME_PASSWORD_DIALOG_REMEMBER_FOREVER: - save_vpn_password (vpn, NULL, username, password); - break; - default: - break; - } - - g_free (password); - gtk_widget_destroy (dialog); - info->vpn_password_dialog = NULL; -} - -void nmi_vpn_request_password (NMIAppInfo *info, DBusMessage *message, const char *vpn, const char *username, gboolean retry) -{ - char *prompt; - char *password; - - if (!username) - username = g_get_user_name (); - - if (!retry && lookup_pass (vpn, username, &password)) - { - nmi_dbus_return_vpn_password (info->connection, message, password); - g_free (password); - return; - } - - prompt = g_strdup_printf (_("You must log in to access the private network %s"), vpn); - - info->vpn_password_dialog = gnome_password_dialog_new ("", - prompt, - username, - NULL, - FALSE); - g_free (prompt); - info->vpn_password_message = message; - dbus_message_ref (info->vpn_password_message); - gnome_password_dialog_set_show_username (GNOME_PASSWORD_DIALOG (info->vpn_password_dialog), TRUE); - gnome_password_dialog_set_readonly_username (GNOME_PASSWORD_DIALOG (info->vpn_password_dialog), TRUE); - gnome_password_dialog_set_show_userpass_buttons (GNOME_PASSWORD_DIALOG (info->vpn_password_dialog), FALSE); - gnome_password_dialog_set_show_domain (GNOME_PASSWORD_DIALOG (info->vpn_password_dialog), FALSE); - gnome_password_dialog_set_show_remember (GNOME_PASSWORD_DIALOG (info->vpn_password_dialog), TRUE); - g_object_set_data_full (G_OBJECT (info->vpn_password_dialog), "NetworkManagerInfoVPN-username", g_strdup (username), (GDestroyNotify) g_free); - g_object_set_data_full (G_OBJECT (info->vpn_password_dialog), "NetworkManagerInfoVPN-vpn", g_strdup (vpn), (GDestroyNotify) g_free); - g_signal_connect (info->vpn_password_dialog, "response", G_CALLBACK (response_cb), info); - g_signal_connect (info->vpn_password_dialog, "close", G_CALLBACK (close_cb), info); - gtk_widget_show (info->vpn_password_dialog); -} - -void nmi_vpn_cancel_request_password (NMIAppInfo *info) -{ - if (info->vpn_password_dialog) - { - gtk_widget_destroy (info->vpn_password_dialog); - dbus_message_unref (info->vpn_password_message); - info->vpn_password_message = NULL; - } -} diff --git a/info-daemon/NetworkManagerInfoVPN.h b/info-daemon/NetworkManagerInfoVPN.h deleted file mode 100644 index 6f0bf968c..000000000 --- a/info-daemon/NetworkManagerInfoVPN.h +++ /dev/null @@ -1,34 +0,0 @@ -/* NetworkManagerInfo -- Manage allowed access points and provide a UI - * for WEP key entry - * - * Colin Walters - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2004 Red Hat, Inc. - */ - -#ifndef NETWORK_MANAGER_INFO_VPN_H -#define NETWORK_MANAGER_INFO_VPN_H - -#include "NetworkManagerInfo.h" - -int nmi_vpn_init (NMIAppInfo *info); - -void nmi_vpn_request_password (NMIAppInfo *info, DBusMessage *message, const char *vpn, const char *username, gboolean retry); - -void nmi_vpn_cancel_request_password (NMIAppInfo *info); - -#endif diff --git a/info-daemon/networks.glade b/info-daemon/networks.glade deleted file mode 100644 index e44d931af..000000000 --- a/info-daemon/networks.glade +++ /dev/null @@ -1,226 +0,0 @@ - - - - - - - - 6 - 400 - 400 - Modify Wireless Networks - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_CENTER - False - True - False - True - False - False - GDK_WINDOW_TYPE_HINT_DIALOG - GDK_GRAVITY_NORTH_WEST - True - - - - True - False - 12 - - - - True - GTK_BUTTONBOX_END - - - - True - True - True - gtk-help - True - GTK_RELIEF_NORMAL - True - -11 - - - - - - True - True - True - gtk-cancel - True - GTK_RELIEF_NORMAL - True - -6 - - - - - - True - True - True - gtk-save - True - GTK_RELIEF_NORMAL - True - -5 - - - - - 0 - False - True - GTK_PACK_END - - - - - - 6 - True - False - 6 - - - - True - <span weight="bold">Wireless Networks:</span> - False - True - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - False - 12 - - - - True - True - GTK_POLICY_NEVER - GTK_POLICY_AUTOMATIC - GTK_SHADOW_NONE - GTK_CORNER_TOP_LEFT - - - - True - True - True - False - False - True - - - - - 0 - True - True - - - - - - True - False - 67 - - - - True - GTK_BUTTONBOX_SPREAD - 0 - - - - True - True - True - gtk-go-up - True - GTK_RELIEF_NORMAL - False - - - - - - True - True - True - gtk-go-down - True - GTK_RELIEF_NORMAL - True - - - - - 28 - True - True - - - - - - True - True - gtk-delete - True - GTK_RELIEF_NORMAL - True - - - 0 - False - False - - - - - 0 - False - False - - - - - 0 - True - True - - - - - 0 - True - True - - - - - - - diff --git a/info-daemon/passphrase.glade b/info-daemon/passphrase.glade deleted file mode 100644 index e505edbe3..000000000 --- a/info-daemon/passphrase.glade +++ /dev/null @@ -1,243 +0,0 @@ - - - - - - - 6 - True - Wireless Network Key Required - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_CENTER_ALWAYS - False - False - False - True - False - False - GDK_WINDOW_TYPE_HINT_DIALOG - GDK_GRAVITY_NORTH_WEST - False - - - - True - False - 12 - - - - True - GTK_BUTTONBOX_END - - - - True - True - True - gtk-cancel - True - GTK_RELIEF_NORMAL - True - -6 - - - - - - True - True - True - True - _Login to Network - True - GTK_RELIEF_NORMAL - True - 0 - - - - - 0 - False - True - GTK_PACK_END - - - - - - 6 - True - False - 12 - - - - True - keyring.png - 0.5 - 0 - 0 - 0 - - - 0 - False - True - - - - - - True - False - 12 - - - - True - <span weight="bold" size="larger">Passphrase Required by Wireless Network</span> - -A passphrase or encryption key is required to access the wireless network '%s'. - False - True - GTK_JUSTIFY_LEFT - True - False - 0 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - False - 6 - - - - True - Key Type: - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - 128-bit Passphrase (WEP) -Ascii Key (WEP) -Hex Key (WEP) - - - 0 - True - True - - - - - - - - - 0 - True - True - - - - - - True - False - 6 - - - - True - Passphrase: - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - True - True - True - True - 0 - - True - * - True - - - 0 - True - True - - - - - 0 - True - True - - - - - 0 - True - True - - - - - 0 - True - True - - - - - - - diff --git a/panel-applet/.cvsignore b/panel-applet/.cvsignore deleted file mode 100644 index c55f9e7f0..000000000 --- a/panel-applet/.cvsignore +++ /dev/null @@ -1,3 +0,0 @@ -Makefile -Makefile.in -NetworkManagerNotification diff --git a/panel-applet/Makefile.am b/panel-applet/Makefile.am deleted file mode 100644 index b396f91b6..000000000 --- a/panel-applet/Makefile.am +++ /dev/null @@ -1,84 +0,0 @@ -SUBDIRS=icons - -NULL= -NOTIFICATION_ICON_SOURCE=@NOTIFICATION_ICON_SRC@ - -INCLUDES = -I${top_srcdir} -I${top_srcdir}/utils - -noinst_LTLIBRARIES = libnm_notification_applet.la - -gladedir = $(datadir)/NetworkManagerNotification -glade_DATA = wireless-applet.glade - -libnm_notification_applet_la_CPPFLAGS = \ - $(DBUS_CFLAGS) \ - $(GTHREAD_CFLAGS) \ - $(HAL_CFLAGS) \ - $(DBUS_GLIB_CFLAGS) \ - $(GLADE_CFLAGS) \ - $(GTK_CFLAGS) \ - $(GCONF_CFLAGS) \ - $(LIBGNOMEUI_CFLAGS) \ - $(PANEL_APPLET_CFLAGS) \ - $(GNOMEKEYRING_CFLAGS) \ - -DICONDIR=\""$(datadir)/pixmaps"\" \ - -DGLADEDIR=\""$(gladedir)"\" \ - -DDBUS_API_SUBJECT_TO_CHANGE \ - -DG_DISABLE_DEPRECATED \ - -DGDK_DISABLE_DEPRECATED \ - -DGNOME_DISABLE_DEPRECATED \ - -DGNOMELOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \ - -DVERSION=\"$(VERSION)\" \ - $(NULL) - -libnm_notification_applet_la_SOURCES = \ - NMWirelessApplet.c \ - NMWirelessApplet.h \ - NMWirelessAppletDbus.c \ - NMWirelessAppletDbus.h \ - NMWirelessAppletOtherNetworkDialog.c \ - NMWirelessAppletOtherNetworkDialog.h \ - menu-info.c \ - menu-info.h \ - gtkcellview.c \ - gtkcellview.h \ - gtkcellrendererprogress.c \ - gtkcellrendererprogress.h \ - nmwa-vpn-password-dialog.c \ - nmwa-vpn-password-dialog.h \ - nmwa-vpn-connection.c \ - nmwa-vpn-connection.h \ - $(NULL) - -libnm_notification_applet_la_SOURCES += \ - eggtrayicon.c \ - eggtrayicon.h - -libnm_notification_applet_la_LIBADD = \ - $(DBUS_LIBS) \ - $(HAL_LIBS) \ - $(GTHREAD_LIBS) \ - $(GLADE_LIBS) \ - $(DBUS_GLIB_LIBS) \ - $(PANEL_APPLET_LIBS) \ - $(GTK_LIBS) \ - $(GCONF_LIBS) \ - $(LIBGNOMEUI_LIBS) \ - $(GNOMEKEYRING_LIBS) \ - $(NULL) - -libexec_PROGRAMS = NetworkManagerNotification - -NetworkManagerNotification_CFLAGS = $(libnm_notification_applet_la_CPPFLAGS) -NetworkManagerNotification_SOURCES = main.c -NetworkManagerNotification_LDADD = \ - ./libnm_notification_applet.la \ - $(top_builddir)/utils/libnmutils.la - - -CLEANFILES = $(server_DATA) *.bak *.gladep - -EXTRA_DIST = \ - $(glade_DATA) \ - $(NULL) - diff --git a/panel-applet/NMWirelessApplet.h b/panel-applet/NMWirelessApplet.h deleted file mode 100644 index ad51ca2e8..000000000 --- a/panel-applet/NMWirelessApplet.h +++ /dev/null @@ -1,194 +0,0 @@ -/* NetworkManager Wireless Applet -- Display wireless access points and allow user control - * - * Dan Williams - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2004 Red Hat, Inc. - */ - -#ifndef NM_WIRELESS_APPLET_H -#define NM_WIRELESS_APPLET_H -#include -#include -#include -#include -#include -#ifndef BUILD_NOTIFICATION_ICON -#include -#include -#else -#include "eggtrayicon.h" -#endif -#include - -typedef enum -{ - APPLET_STATE_NO_NM, - APPLET_STATE_NO_CONNECTION, - APPLET_STATE_WIRED, - APPLET_STATE_WIRED_CONNECTING, - APPLET_STATE_WIRELESS, - APPLET_STATE_WIRELESS_CONNECTING, - APPLET_STATE_WIRELESS_SCANNING, - APPLET_STATE_IGNORE -} AppletState; - - -/* - * Representation of a wireless network - * - */ -typedef struct -{ - int refcount; - char *nm_name; - char *essid; - gboolean encrypted; - gboolean active; - gint8 strength; -} WirelessNetwork; - -/* - * Representation of network device - * - */ -typedef struct -{ - int refcount; - char *nm_device; - int type; - gboolean link; - guint32 driver_support_level; - char *addr; - char *nm_name; - char *hal_name; - char *udi; - gint strength; - GSList *networks; -} NetworkDevice; - - -typedef struct VPNConnection VPNConnection; - - -#ifdef BUILD_NOTIFICATION_ICON - -#define NM_TYPE_WIRELESS_APPLET (nmwa_get_type()) -#define NM_WIRELESS_APPLET(object) (G_TYPE_CHECK_INSTANCE_CAST((object), NM_TYPE_WIRELESS_APPLET, NMWirelessApplet)) -#define NM_WIRELESS_APPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_WIRELESS_APPLET, NMWirelessAppletClass)) -#define NM_IS_WIRELESS_APPLET(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), NM_TYPE_WIRELESS_APPLET)) -#define NM_IS_WIRELESS_APPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_WIRELESS_APPLET)) -#define NM_WIRELESS_APPLET_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), NM_TYPE_WIRELESS_APPLET, NMWirelessAppletClass)) - -typedef struct -{ - EggTrayIconClass parent_class; -} NMWirelessAppletClass; -#endif - -/* - * Applet instance data - * - */ -typedef struct -{ -#ifdef BUILD_NOTIFICATION_ICON - EggTrayIcon parent; -#endif - - DBusConnection *connection; - GConfClient *gconf_client; - char *glade_file; - guint redraw_timeout_id; - - /* dbus thread stuff */ - GThread *dbus_thread; - GMainContext *thread_context; - GMainLoop *thread_loop; - gboolean thread_done; - - /* Data model elements */ - GMutex *data_mutex; - AppletState applet_state; - gboolean is_adhoc; - gboolean scanning_enabled; - gboolean wireless_enabled; - - GSList *gui_device_list; - NetworkDevice *gui_active_device; - char *gui_nm_status; - GSList *gui_vpn_connections; - VPNConnection *gui_active_vpn; - - GSList *dbus_device_list; - NetworkDevice *dbus_active_device; - char *dbus_nm_status; - GSList *dbus_vpn_connections; - VPNConnection *dbus_active_vpn; - - GdkPixbuf *no_nm_icon; - GdkPixbuf *no_connection_icon; - GdkPixbuf *wired_icon; - GdkPixbuf *adhoc_icon; -#define NUM_WIRED_CONNECTING_FRAMES 11 - GdkPixbuf *wired_connecting_icons[NUM_WIRED_CONNECTING_FRAMES]; - GdkPixbuf *wireless_00_icon; - GdkPixbuf *wireless_25_icon; - GdkPixbuf *wireless_50_icon; - GdkPixbuf *wireless_75_icon; - GdkPixbuf *wireless_100_icon; -#define NUM_WIRELESS_CONNECTING_FRAMES 11 - GdkPixbuf *wireless_connecting_icons[NUM_WIRELESS_CONNECTING_FRAMES]; -#define NUM_WIRELESS_SCANNING_FRAMES 16 - GdkPixbuf *wireless_scanning_icons[NUM_WIRELESS_SCANNING_FRAMES]; - GdkPixbuf *vpn_lock_icon; - - /* Animation stuff */ - int animation_step; - guint animation_id; - - /* Direct UI elements */ - GtkWidget *pixmap; - GtkWidget *top_menu_item; - GtkWidget *dropdown_menu; - GtkWidget *vpn_menu; - GtkWidget *event_box; - GtkSizeGroup *encryption_size_group; - GtkTooltips *tooltips; - - GtkWidget *context_menu; - GtkWidget *pause_scanning_item; - GtkWidget *stop_wireless_item; - -} NMWirelessApplet; - -typedef struct -{ - NMWirelessApplet *applet; - NetworkDevice *dev; - GladeXML *xml; -} DriverNotifyCBData; - -NetworkDevice * nmwa_get_device_for_nm_device (GSList *dev_list, const char *nm_dev); -WirelessNetwork * nmwa_get_net_for_nm_net (NetworkDevice *dev, const char *net_path); -WirelessNetwork * nmwa_get_net_by_essid (NetworkDevice *dev, const char *essid); -NMWirelessApplet * nmwa_new (void); -void show_warning_dialog (gboolean error, gchar *mesg, ...); -gboolean nmwa_driver_notify (gpointer user_data); -void nmwa_schedule_vpn_login_failure_dialog (NMWirelessApplet *applet, const char *vpn_name, const char *error_msg); -void nmwa_schedule_vpn_login_banner_dialog (NMWirelessApplet *applet, const char *vpn_name, const char *banner); - -#endif diff --git a/panel-applet/NMWirelessApplet.server.in b/panel-applet/NMWirelessApplet.server.in deleted file mode 100644 index d389ed2f4..000000000 --- a/panel-applet/NMWirelessApplet.server.in +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/panel-applet/NMWirelessApplet.xml b/panel-applet/NMWirelessApplet.xml deleted file mode 100644 index 1efd885d9..000000000 --- a/panel-applet/NMWirelessApplet.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - diff --git a/panel-applet/NMWirelessAppletDbus.c b/panel-applet/NMWirelessAppletDbus.c deleted file mode 100644 index cb2ee75b1..000000000 --- a/panel-applet/NMWirelessAppletDbus.c +++ /dev/null @@ -1,2102 +0,0 @@ -/* NetworkManager Wireless Applet -- Display wireless access points and allow user control - * - * Dan Williams - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2004 Red Hat, Inc. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include "NMWirelessAppletDbus.h" -#include "NMWirelessApplet.h" -#include "nmwa-vpn-connection.h" - -#include "nm-utils.h" - -#define DBUS_NO_SERVICE_ERROR "org.freedesktop.DBus.Error.ServiceDoesNotExist" - -/* - * nm_null_safe_strcmp - * - * Doesn't freaking segfault if s1/s2 are NULL - * - */ -int nm_null_safe_strcmp (const char *s1, const char *s2) -{ - if (!s1 && !s2) - return 0; - if (!s1 && s2) - return -1; - if (s1 && !s2) - return 1; - - return (strcmp (s1, s2)); -} - - -/* FIXME: This just seems like a bad idea. The call_nm_method function - * interface should just be changed to handle arrays better. - */ -#define NM_DBUS_TYPE_STRING_ARRAY ((DBUS_TYPE_STRING << 8) | DBUS_TYPE_ARRAY) -#define NM_DBUS_TYPE_OBJECT_PATH_ARRAY ((DBUS_TYPE_OBJECT_PATH << 8) | DBUS_TYPE_ARRAY) - -/* - * nmwa_dbus_call_nm_method - * - * Do a method call on NetworkManager. - * - * Returns: RETURN_SUCCESS on success - * RETURN_FAILURE on failure - * RETURN_NO_NM if NetworkManager service no longer exists - */ -static int nmwa_dbus_call_nm_method (DBusConnection *con, const char *path, const char *method, int arg_type, void **arg, int *item_count) -{ - DBusMessage *message; - DBusMessage *reply; - DBusError error; - char *dbus_string = NULL; - int dbus_int = 0; - gboolean dbus_bool = FALSE; - char **dbus_array = NULL; - int num_items = 0; - dbus_bool_t ret = TRUE; - - g_return_val_if_fail (con != NULL, RETURN_FAILURE); - g_return_val_if_fail (path != NULL, RETURN_FAILURE); - g_return_val_if_fail (method != NULL, RETURN_FAILURE); - g_return_val_if_fail (((arg_type == DBUS_TYPE_OBJECT_PATH) || (arg_type == DBUS_TYPE_STRING) || (arg_type == DBUS_TYPE_INT32) || (arg_type == DBUS_TYPE_UINT32) || (arg_type == DBUS_TYPE_BOOLEAN) || (arg_type == NM_DBUS_TYPE_STRING_ARRAY) || (arg_type == NM_DBUS_TYPE_OBJECT_PATH_ARRAY)), RETURN_FAILURE); - g_return_val_if_fail (arg != NULL, RETURN_FAILURE); - - if ((arg_type == DBUS_TYPE_STRING) || (arg_type == NM_DBUS_TYPE_STRING_ARRAY) || (arg_type == DBUS_TYPE_OBJECT_PATH) || (arg_type == NM_DBUS_TYPE_OBJECT_PATH_ARRAY)) - g_return_val_if_fail (*arg == NULL, RETURN_FAILURE); - - if ((arg_type == NM_DBUS_TYPE_STRING_ARRAY) || - (arg_type == NM_DBUS_TYPE_OBJECT_PATH_ARRAY)) - { - g_return_val_if_fail (item_count != NULL, RETURN_FAILURE); - *item_count = 0; - *((char **)arg) = NULL; - } - - if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE, method))) - { - fprintf (stderr, "nmwa_dbus_call_nm_method(): Couldn't allocate the dbus message\n"); - return (RETURN_FAILURE); - } - - dbus_error_init (&error); - reply = dbus_connection_send_with_reply_and_block (con, message, -1, &error); - dbus_message_unref (message); - if (dbus_error_is_set (&error)) - { - int ret = RETURN_FAILURE; - - if (!strcmp (error.name, DBUS_NO_SERVICE_ERROR)) - ret = RETURN_NO_NM; - else if (!strcmp (error.name, NM_DBUS_NO_ACTIVE_NET_ERROR)) - ret = RETURN_SUCCESS; - else if (!strcmp (error.name, NM_DBUS_NO_ACTIVE_DEVICE_ERROR)) - ret = RETURN_SUCCESS; - else if (!strcmp (error.name, NM_DBUS_NO_NETWORKS_ERROR)) - ret = RETURN_SUCCESS; - else if (!strcmp (error.name, NM_DBUS_NO_ACTIVE_VPN_CONNECTION)) - ret = RETURN_SUCCESS; - else if (!strcmp (error.name, NM_DBUS_NO_VPN_CONNECTIONS)) - ret = RETURN_SUCCESS; - - if ((ret != RETURN_SUCCESS) && (ret != RETURN_NO_NM)) - fprintf (stderr, "nmwa_dbus_call_nm_method(): %s raised on method '%s':\n %s\n\n", error.name, method, error.message); - - dbus_error_free (&error); - return (ret); - } - - if (reply == NULL) - { - fprintf (stderr, "nmwa_dbus_call_nm_method(): dbus reply message was NULL\n" ); - return (RETURN_FAILURE); - } - - dbus_error_init (&error); - switch (arg_type) - { - case DBUS_TYPE_OBJECT_PATH: - ret = dbus_message_get_args (reply, &error, DBUS_TYPE_OBJECT_PATH, &dbus_string, DBUS_TYPE_INVALID); - break; - case DBUS_TYPE_STRING: - ret = dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &dbus_string, DBUS_TYPE_INVALID); - break; - case NM_DBUS_TYPE_OBJECT_PATH_ARRAY: - ret = dbus_message_get_args (reply, &error, DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &dbus_array, &num_items, DBUS_TYPE_INVALID); - break; - case NM_DBUS_TYPE_STRING_ARRAY: - ret = dbus_message_get_args (reply, &error, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &dbus_array, &num_items, DBUS_TYPE_INVALID); - break; - case DBUS_TYPE_INT32: - ret = dbus_message_get_args (reply, &error, DBUS_TYPE_INT32, &dbus_int, DBUS_TYPE_INVALID); - break; - case DBUS_TYPE_UINT32: - ret = dbus_message_get_args (reply, &error, DBUS_TYPE_UINT32, &dbus_int, DBUS_TYPE_INVALID); - break; - case DBUS_TYPE_BOOLEAN: - ret = dbus_message_get_args (reply, &error, DBUS_TYPE_BOOLEAN, &dbus_bool, DBUS_TYPE_INVALID); - break; - default: - fprintf (stderr, "nmwa_dbus_call_nm_method(): Unknown argument type!\n"); - ret = FALSE; - break; - } - - if (!ret) - { - fprintf (stderr, "nmwa_dbus_call_nm_method(): error while getting args: name='%s' message='%s'\n", error.name, error.message); - if (dbus_error_is_set (&error)) - dbus_error_free (&error); - dbus_message_unref (reply); - return (RETURN_FAILURE); - } - - switch (arg_type) - { - case DBUS_TYPE_OBJECT_PATH: - case DBUS_TYPE_STRING: - *((char **)(arg)) = g_strdup (dbus_string); - break; - case NM_DBUS_TYPE_OBJECT_PATH_ARRAY: - case NM_DBUS_TYPE_STRING_ARRAY: - *((char ***)(arg)) = g_strdupv (dbus_array); - *item_count = num_items; - g_strfreev (dbus_array); - break; - case DBUS_TYPE_INT32: - case DBUS_TYPE_UINT32: - *((int *)(arg)) = dbus_int; - break; - case DBUS_TYPE_BOOLEAN: - *((gboolean *)(arg)) = dbus_bool; - break; - default: - g_assert_not_reached (); - break; - } - - dbus_message_unref (reply); - return (RETURN_SUCCESS); -} - - -/* - * nmwa_dbus_get_active_device - * - * Returns the object_path of the currently active device, if any. - * - */ -static char * nmwa_dbus_get_active_device (NMWirelessApplet *applet, AppletState failure_state) -{ - char *active_device = NULL; - - switch (nmwa_dbus_call_nm_method (applet->connection, NM_DBUS_PATH, "getActiveDevice", DBUS_TYPE_OBJECT_PATH, (void **)(&active_device), NULL)) - { - case (RETURN_NO_NM): - applet->applet_state = APPLET_STATE_NO_NM; - break; - - case (RETURN_FAILURE): - if (failure_state != APPLET_STATE_IGNORE) - applet->applet_state = failure_state; - break; - - default: - break; - } - - return (active_device); -} - - -/* - * nmwa_dbus_get_active_network - * - * Returns the object_path of the currently active network of the active device. - * - */ -static char * nmwa_dbus_get_active_network (NMWirelessApplet *applet, char *dev_path, AppletState failure_state) -{ - char *network = NULL; - - switch (nmwa_dbus_call_nm_method (applet->connection, dev_path, "getActiveNetwork", DBUS_TYPE_OBJECT_PATH, (void **)(&network), NULL)) - { - case (RETURN_NO_NM): - applet->applet_state = APPLET_STATE_NO_NM; - break; - - case (RETURN_FAILURE): - if (failure_state != APPLET_STATE_IGNORE) - applet->applet_state = failure_state; - break; - - default: - break; - } - - return (network); -} - - -/* - * nmwa_dbus_get_active_vpn_connection - * - * Return the name of the currently active VPN connection. - * - */ -static char * nmwa_dbus_get_active_vpn_connection (NMWirelessApplet *applet) -{ - char *name = NULL; - - switch (nmwa_dbus_call_nm_method (applet->connection, NM_DBUS_PATH_VPN, "getActiveVPNConnection", DBUS_TYPE_STRING, (void **)(&name), NULL)) - { - case (RETURN_NO_NM): - applet->applet_state = APPLET_STATE_NO_NM; - break; - - default: - break; - } - - return (name); -} - - -/* - * nmwa_dbus_get_device_type - * - * Returns the device type of the specified device. - * - */ -static int nmwa_dbus_get_device_type (NMWirelessApplet *applet, char *path, AppletState failure_state) -{ - int type = -1; - - switch (nmwa_dbus_call_nm_method (applet->connection, path, "getType", DBUS_TYPE_INT32, (void **)(&type), NULL)) - { - case (RETURN_NO_NM): - applet->applet_state = APPLET_STATE_NO_NM; - break; - - case (RETURN_FAILURE): - applet->applet_state = failure_state; - break; - - default: - break; - } - - return (type); -} - - -/* - * nmwa_dbus_get_device_link_active - * - * Returns the device's link status - * - */ -static gboolean nmwa_dbus_get_device_link_active (NMWirelessApplet *applet, char *net_path) -{ - gboolean link = FALSE; - - switch (nmwa_dbus_call_nm_method (applet->connection, net_path, "getLinkActive", DBUS_TYPE_BOOLEAN, (void **)(&link), NULL)) - { - case (RETURN_NO_NM): - applet->applet_state = APPLET_STATE_NO_NM; - break; - - default: - break; - } - - return (link); -} - - -/* - * nmwa_dbus_get_device_driver_support_level - * - * Returns whether or not the device supports carrier detection. - * - */ -static gboolean nmwa_dbus_get_device_driver_support_level (NMWirelessApplet *applet, char *net_path) -{ - guint32 driver_support_level = FALSE; - - switch (nmwa_dbus_call_nm_method (applet->connection, net_path, "getDriverSupportLevel", - DBUS_TYPE_UINT32, (void **)(&driver_support_level), NULL)) - { - case (RETURN_NO_NM): - applet->applet_state = APPLET_STATE_NO_NM; - break; - - default: - break; - } - - return (driver_support_level); -} - - -/* - * nmwa_dbus_get_hw_addr - * - * Return the hardware address of a given device - * - */ -static char * nmwa_dbus_get_hw_addr (NMWirelessApplet *applet, char *dev_path) -{ - char *addr = NULL; - - switch (nmwa_dbus_call_nm_method (applet->connection, dev_path, "getHWAddress", DBUS_TYPE_STRING, (void **)(&addr), NULL)) - { - case (RETURN_NO_NM): - applet->applet_state = APPLET_STATE_NO_NM; - break; - - default: - break; - } - - return (addr); -} - - -/* - * nmwa_dbus_get_object_strength - * - * Returns the strength of a given object (device or wireless network) - * - */ -static gint8 nmwa_dbus_get_object_strength (NMWirelessApplet *applet, char *path) -{ - int strength = -1; - - switch (nmwa_dbus_call_nm_method (applet->connection, path, "getStrength", DBUS_TYPE_INT32, (void **)(&strength), NULL)) - { - case (RETURN_NO_NM): - applet->applet_state = APPLET_STATE_NO_NM; - break; - - default: - break; - } - - return (strength); -} - - -/* - * nmwa_dbus_get_nm_status - * - * Returns NetworkManager's status - * - */ -static char * nmwa_dbus_get_nm_status (NMWirelessApplet *applet, AppletState failure_state) -{ - char *status = NULL; - - switch (nmwa_dbus_call_nm_method (applet->connection, NM_DBUS_PATH, "status", DBUS_TYPE_STRING, (void **)(&status), NULL)) - { - case (RETURN_NO_NM): - applet->applet_state = APPLET_STATE_NO_NM; - break; - - case (RETURN_FAILURE): - applet->applet_state = failure_state; - break; - - default: - break; - } - return (status); -} - - -/* - * nmwa_dbus_get_object_name - * - * Returns the name of a specified object (wireless network, device, etc) - * - */ -static char * nmwa_dbus_get_object_name (NMWirelessApplet *applet, const char *path) -{ - char *name = NULL; - - switch (nmwa_dbus_call_nm_method (applet->connection, path, "getName", DBUS_TYPE_STRING, (void **)(&name), NULL)) - { - case (RETURN_NO_NM): - applet->applet_state = APPLET_STATE_NO_NM; - break; - - default: - break; - } - - return (name); -} - - -/* - * nmwa_dbus_get_object_mode - * - * Returns the mode (ie Ad-Hoc, Infrastructure) of a specified object (wireless network, device, etc) - * - */ -static NMNetworkMode nmwa_dbus_get_object_mode (NMWirelessApplet *applet, char *path) -{ - NMNetworkMode mode = NETWORK_MODE_INFRA; - - switch (nmwa_dbus_call_nm_method (applet->connection, path, "getMode", DBUS_TYPE_UINT32, (void **)(&mode), NULL)) - { - case (RETURN_NO_NM): - applet->applet_state = APPLET_STATE_NO_NM; - break; - - default: - break; - } - - return (mode); -} - - -/* - * nmwa_dbus_get_device_udi - * - * Returns the HAL udi of a network device - * - */ -static char * nmwa_dbus_get_device_udi (NMWirelessApplet *applet, char *dev_path) -{ - char *udi = NULL; - - switch (nmwa_dbus_call_nm_method (applet->connection, dev_path, "getHalUdi", DBUS_TYPE_STRING, (void **)(&udi), NULL)) - { - case (RETURN_NO_NM): - applet->applet_state = APPLET_STATE_NO_NM; - break; - - default: - break; - } - - return (udi); -} - - -/* - * nmwa_dbus_get_network_encrypted - * - * Returns whether or not the specified network is encrypted - * - */ -static gboolean nmwa_dbus_get_network_encrypted (NMWirelessApplet *applet, char *net_path) -{ - gboolean enc = FALSE; - - switch (nmwa_dbus_call_nm_method (applet->connection, net_path, "getEncrypted", DBUS_TYPE_BOOLEAN, (void **)(&enc), NULL)) - { - case (RETURN_NO_NM): - applet->applet_state = APPLET_STATE_NO_NM; - break; - - default: - break; - } - - return (enc); -} - - -/* - * nmwa_dbus_get_scanning_enabled - */ -static gboolean nmwa_dbus_get_scanning_enabled (NMWirelessApplet *applet) -{ - gboolean enabled = FALSE; - - switch (nmwa_dbus_call_nm_method (applet->connection, NM_DBUS_PATH, "getScanningEnabled", DBUS_TYPE_BOOLEAN, (void **)(&enabled), NULL)) - { - case (RETURN_NO_NM): - applet->applet_state = APPLET_STATE_NO_NM; - break; - - default: - break; - } - - return (enabled); -} - -/* - * nmwa_dbus_get_wireless_enabled - */ -static gboolean nmwa_dbus_get_wireless_enabled (NMWirelessApplet *applet) -{ - gboolean enabled = FALSE; - - switch (nmwa_dbus_call_nm_method (applet->connection, NM_DBUS_PATH, "getWirelessEnabled", DBUS_TYPE_BOOLEAN, (void **)(&enabled), NULL)) - { - case (RETURN_NO_NM): - applet->applet_state = APPLET_STATE_NO_NM; - break; - - default: - break; - } - - return (enabled); -} - - -/* - * nmwa_dbus_get_device_networks - * - * Returns an array of wireless networks that the specified device knows about. - * - */ -static char **nmwa_dbus_get_device_networks (NMWirelessApplet *applet, char *path, int *num_items, AppletState failure_state) -{ - char **array = NULL; - int items; - - switch (nmwa_dbus_call_nm_method (applet->connection, path, "getNetworks", NM_DBUS_TYPE_OBJECT_PATH_ARRAY, (void **)(&array), &items)) - { - case (RETURN_NO_NM): - applet->applet_state = APPLET_STATE_NO_NM; - break; - - case (RETURN_FAILURE): - applet->applet_state = failure_state; - break; - - case (RETURN_SUCCESS): - *num_items = items; - break; - - default: - break; - } - - return (array); -} - - -/* - * nmwa_dbus_get_vpn_connections - * - * Returns an array of wireless networks that the specified device knows about. - * - */ -static char **nmwa_dbus_get_vpn_connections (NMWirelessApplet *applet, int *num_items) -{ - char **array = NULL; - int items; - - switch (nmwa_dbus_call_nm_method (applet->connection, NM_DBUS_PATH_VPN, "getVPNConnections", NM_DBUS_TYPE_STRING_ARRAY, (void **)(&array), &items)) - { - case (RETURN_NO_NM): - applet->applet_state = APPLET_STATE_NO_NM; - break; - - case (RETURN_SUCCESS): - *num_items = items; - break; - - default: - break; - } - - return (array); -} - - -/* - * nmwa_dbus_get_hal_device_string_property - * - * Get a string property from a device - * - */ -static char *nmwa_dbus_get_hal_device_string_property (DBusConnection *connection, const char *udi, const char *property_name) -{ - DBusError error; - DBusMessage *message; - DBusMessage *reply; - char *dbus_property = NULL; - char *property = NULL; - - g_return_val_if_fail (connection != NULL, NULL); - g_return_val_if_fail (udi != NULL, NULL); - - message = dbus_message_new_method_call ("org.freedesktop.Hal", udi, "org.freedesktop.Hal.Device", "GetPropertyString"); - if (!message) - return (NULL); - - dbus_error_init (&error); - dbus_message_append_args (message, DBUS_TYPE_STRING, &property_name, DBUS_TYPE_INVALID); - reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error); - dbus_message_unref (message); - if (dbus_error_is_set (&error)) - { - fprintf (stderr, "nmwa_dbus_get_hal_device_string_property(): %s raised:\n %s\n\n", error.name, error.message); - dbus_error_free (&error); - return (NULL); - } - if (reply == NULL) - { - fprintf (stderr, "nmwa_dbus_get_hal_device_string_property(): dbus reply message was NULL\n" ); - return (NULL); - } - - dbus_error_init (&error); - if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &dbus_property, DBUS_TYPE_INVALID)) - { - if (dbus_error_is_set (&error)) - dbus_error_free (&error); - } - else - property = g_strdup (dbus_property); - - dbus_message_unref (reply); - return (property); -} - - -/* - * nmwa_dbus_get_hal_device_info - * - * Grab the info.product tag from hal for a specific UDI - * - */ -static char *nmwa_dbus_get_hal_device_info (DBusConnection *connection, const char *udi) -{ - DBusError error; - DBusMessage *message; - DBusMessage *reply; - gboolean exists = FALSE; - char *parent = NULL; - char *info = NULL; - - g_return_val_if_fail (connection != NULL, NULL); - g_return_val_if_fail (udi != NULL, NULL); - - if ((parent = nmwa_dbus_get_hal_device_string_property (connection, udi, "info.parent"))) - { - info = nmwa_dbus_get_hal_device_string_property (connection, parent, "info.product"); - g_free (parent); - } - - return (info); -} - - -/* - * nmwa_dbus_set_device - * - * Tell NetworkManager to use a specific network device that the user picked, and - * possibly a specific wireless network too. - * - */ -void nmwa_dbus_set_device (DBusConnection *connection, const NetworkDevice *dev, const WirelessNetwork *network, - NMEncKeyType key_type, const char *passphrase) -{ - DBusMessage *message; - - g_return_if_fail (connection != NULL); - g_return_if_fail (dev != NULL); - - if ((dev->type == DEVICE_TYPE_WIRED_ETHERNET) && !passphrase && (key_type != -1)) - return; - - if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "setActiveDevice"))) - { - if ((dev->type == DEVICE_TYPE_WIRELESS_ETHERNET) && network && network->essid) - { - fprintf (stderr, "Forcing device '%s' and network '%s' %s passphrase\n", dev->nm_device, network->essid, passphrase ? "with" : "without"); - - if (passphrase == NULL) - passphrase = ""; - - dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev->nm_device, - DBUS_TYPE_STRING, &network->essid, - DBUS_TYPE_STRING, &passphrase, - DBUS_TYPE_INT32, &key_type, - DBUS_TYPE_INVALID); - } - else - { - fprintf (stderr, "Forcing device '%s'\n", dev->nm_device); - dbus_message_append_args (message, DBUS_TYPE_STRING, &dev->nm_device, DBUS_TYPE_INVALID); - } - dbus_connection_send (connection, message, NULL); - } - else - fprintf (stderr, "nm_dbus_set_device(): Couldn't allocate the dbus message\n"); -} - - -/* - * nmwa_dbus_vpn_activate_connection - * - * Tell NetworkManager to activate a particular VPN connection. - * - */ -void nmwa_dbus_vpn_activate_connection (DBusConnection *connection, const char *name, const char *password) -{ - DBusMessage *message; - - g_return_if_fail (connection != NULL); - g_return_if_fail (name != NULL); - g_return_if_fail (password != NULL); - - if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH_VPN, NM_DBUS_INTERFACE_VPN, "activateVPNConnection"))) - { - fprintf (stderr, "Activating VPN connection '%s'.\n", name); - - dbus_message_append_args (message, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &password, DBUS_TYPE_INVALID); - dbus_connection_send (connection, message, NULL); - } - else - fprintf (stderr, "nmwa_dbus_activate_vpn_connection(): Couldn't allocate the dbus message\n"); -} - - -/* - * nmwa_dbus_deactivate_vpn_connection - * - * Tell NetworkManager to deactivate the currently active VPN connection. - * - */ -void nmwa_dbus_vpn_deactivate_connection (DBusConnection *connection) -{ - DBusMessage *message; - - g_return_if_fail (connection != NULL); - - if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH_VPN, NM_DBUS_INTERFACE_VPN, "deactivateVPNConnection"))) - { - fprintf (stderr, "Deactivating the current VPN connection.\n"); - dbus_connection_send (connection, message, NULL); - } - else - fprintf (stderr, "nmwa_dbus_activate_vpn_connection(): Couldn't allocate the dbus message\n"); -} - - -/* - * nmwa_dbus_create_network - * - * Tell NetworkManager to create an Ad-Hoc wireless network - * - */ -void nmwa_dbus_create_network (DBusConnection *connection, const NetworkDevice *dev, const WirelessNetwork *network, - NMEncKeyType key_type, const char *passphrase) -{ - DBusMessage *message; - - g_return_if_fail (connection != NULL); - g_return_if_fail (dev != NULL); - g_return_if_fail (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET); - - if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "createWirelessNetwork"))) - { - if (network && network->essid) - { - fprintf (stderr, "Creating network '%s' %s passphrase on device '%s'.\n", network->essid, passphrase ? "with" : "without", dev->nm_device); - if (passphrase == NULL) - passphrase = ""; - dbus_message_append_args (message, DBUS_TYPE_STRING, &dev->nm_device, - DBUS_TYPE_STRING, &network->essid, - DBUS_TYPE_STRING, &passphrase, - DBUS_TYPE_INT32, &key_type, - DBUS_TYPE_INVALID); - } - dbus_connection_send (connection, message, NULL); - } - else - fprintf (stderr, "nm_dbus_set_device(): Couldn't allocate the dbus message\n"); -} - - -/* - * nmwa_dbus_enable_scanning - * - * Tell NetworkManager to start/stop scanning. - * - */ -void nmwa_dbus_enable_scanning (NMWirelessApplet *applet, gboolean enabled) -{ - DBusMessage *message; - - g_return_if_fail (applet != NULL); - g_return_if_fail (applet->connection != NULL); - - if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "setScanningEnabled"))) - { - dbus_message_append_args (message, DBUS_TYPE_BOOLEAN, &enabled, DBUS_TYPE_INVALID); - dbus_connection_send (applet->connection, message, NULL); - applet->scanning_enabled = nmwa_dbus_get_scanning_enabled (applet); - } -} - - -/* - * nmwa_dbus_enable_wireless - * - * Tell NetworkManager to enabled or disable all wireless devices. - * - */ -void nmwa_dbus_enable_wireless (NMWirelessApplet *applet, gboolean enabled) -{ - DBusMessage *message; - - g_return_if_fail (applet != NULL); - g_return_if_fail (applet->connection != NULL); - - if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "setWirelessEnabled"))) - { - dbus_message_append_args (message, DBUS_TYPE_BOOLEAN, &enabled, DBUS_TYPE_INVALID); - dbus_connection_send (applet->connection, message, NULL); - applet->wireless_enabled = nmwa_dbus_get_wireless_enabled (applet); - } -} - - -/* - * wireless_network_ref - * - * Increment the reference count of the wireless network - * - */ -void wireless_network_ref (WirelessNetwork *net) -{ - g_return_if_fail (net != NULL); - - net->refcount++; -} - - -/* - * wireless_network_unref - * - * Unrefs (and possibly frees) the representation of a wireless network - * - */ -void wireless_network_unref (WirelessNetwork *net) -{ - g_return_if_fail (net != NULL); - - net->refcount--; - if (net->refcount < 1) - { - g_free (net->nm_name); - g_free (net->essid); - g_free (net); - } -} - - -/* - * wireless_network_new - * - * Create a new wireless network structure - * - */ -WirelessNetwork *wireless_network_new (void) -{ - WirelessNetwork *net = NULL; - - if ((net = g_new0 (WirelessNetwork, 1))) - wireless_network_ref (net); - - return (net); -} - - -/* - * wireless_network_new_with_essid - * - * Create a new wireless network structure - * - */ -WirelessNetwork *wireless_network_new_with_essid (const char *essid) -{ - WirelessNetwork *net = NULL; - - g_return_val_if_fail (essid != NULL, NULL); - - if ((net = wireless_network_new())) - net->essid = g_strdup (essid); - - return (net); -} - - -/* - * wireless_network_copy - * - * Create a new wireless network structure from an existing one - * - */ -WirelessNetwork *wireless_network_copy (WirelessNetwork *src) -{ - WirelessNetwork *net = NULL; - - g_return_val_if_fail (src != NULL, NULL); - - if ((net = g_new0 (WirelessNetwork, 1))) - { - wireless_network_ref (net); - net->nm_name = g_strdup (src->nm_name); - net->essid = g_strdup (src->essid); - net->active = src->active; - net->encrypted = src->encrypted; - net->strength = src->strength; - } - - return (net); -} - - -/* - * network_device_free_wireless_network_list - * - */ -static void network_device_free_wireless_network_list (NetworkDevice *dev) -{ - g_return_if_fail (dev != NULL); - - g_slist_foreach (dev->networks, (GFunc) wireless_network_unref, NULL); - g_slist_free (dev->networks); - dev->networks = NULL; -} - - -/* - * network_device_remove_wireless_network - * - * Remove one wireless network from the wireless network list - * - */ -void network_device_remove_wireless_network (NetworkDevice *dev, WirelessNetwork *net) -{ - GSList *elt; - - g_return_if_fail (dev != NULL); - g_return_if_fail (net != NULL); - - for (elt = dev->networks; elt; elt = g_slist_next (elt)) - { - if (elt->data == net) - { - dev->networks = g_slist_remove_link (dev->networks, elt); - wireless_network_unref ((WirelessNetwork *)elt->data); - g_slist_free (elt); - break; - } - } -} - -/* - * network_device_ref - * - * Increment the reference count of the network device - * - */ -void network_device_ref (NetworkDevice *dev) -{ - g_return_if_fail (dev != NULL); - - dev->refcount++; -} - - -/* - * network_device_unref - * - * Unrefs (and possibly frees) the representation of a network device - * - */ -void network_device_unref (NetworkDevice *dev) -{ - g_return_if_fail (dev != NULL); - - dev->refcount--; - if (dev->refcount < 1) - { - network_device_free_wireless_network_list (dev); - g_free (dev->nm_device); - g_free (dev->nm_name); - g_free (dev->udi); - g_free (dev->hal_name); - g_free (dev->addr); - g_free (dev); - memset (dev, 0, sizeof (NetworkDevice)); - } -} - - -/* - * network_device_new - * - * Create a new network device representation - * - */ -NetworkDevice *network_device_new (void) -{ - NetworkDevice *dev = NULL; - - if ((dev = g_malloc0 (sizeof (NetworkDevice)))) - network_device_ref (dev); - - return (dev); -} - - -/* - * network_device_copy - * - * Create a new network device representation, filling its - * data in from an already existing one. Deep-copies the - * wireless networks too. - * - */ -NetworkDevice *network_device_copy (NetworkDevice *src) -{ - NetworkDevice *dev = NULL; - - g_return_val_if_fail (src != NULL, NULL); - - if ((dev = g_malloc0 (sizeof (NetworkDevice)))) - { - GSList *elt; - - network_device_ref (dev); - dev->nm_device = g_strdup (src->nm_device); - dev->type = src->type; - dev->link = src->link; - dev->addr = g_strdup (src->addr); - dev->driver_support_level = src->driver_support_level; - dev->nm_name = g_strdup (src->nm_name); - dev->hal_name = g_strdup (src->hal_name); - dev->udi = g_strdup (src->udi); - dev->strength = src->strength; - - for (elt = src->networks; elt; elt = g_slist_next (elt)) - { - WirelessNetwork *net = (WirelessNetwork *)elt->data; - if (net) - { - WirelessNetwork *copy = wireless_network_copy (net); - dev->networks = g_slist_append (dev->networks, copy); - } - } - } - - return (dev); -} - - -/* - * network_device_add_wireless_network - * - * Adds a wireless network to the network device's network list - * - */ -void network_device_add_wireless_network (NetworkDevice *dev, WirelessNetwork *net) -{ - g_return_if_fail (dev != NULL); - g_return_if_fail (net != NULL); - - wireless_network_ref (net); - dev->networks = g_slist_append (dev->networks, net); -} - - -/* - * nmwa_dbus_get_one_wireless_network - * - * Returns a new wireless network filled with info from NM - * - */ -WirelessNetwork *nmwa_dbus_get_one_wireless_network (NMWirelessApplet *applet, NetworkDevice *dev, - const char *net_path, const char *active_network) -{ - char *name = NULL; - WirelessNetwork *net = NULL; - - g_return_val_if_fail (applet != NULL, NULL); - g_return_val_if_fail (dev != NULL, NULL); - g_return_val_if_fail (net_path != NULL, NULL); - - if (!(name = nmwa_dbus_get_object_name (applet, net_path))) - goto out; - - if (strlen (name)) - { - if (!(net = wireless_network_new ())) - goto out; - net->nm_name = g_strdup (net_path); - net->essid = g_strdup (name); - net->active = active_network ? (strcmp (net->nm_name, active_network) == 0) : FALSE; - net->encrypted = nmwa_dbus_get_network_encrypted (applet, net->nm_name); - net->strength = nmwa_dbus_get_object_strength (applet, net->nm_name); - } - -out: - g_free (name); - return net; -} - - -/* - * nmwa_dbus_device_update_all_networks - * - * Query NetworkManager for the wireless networks a particular device - * knows about, if the active device is wireless. - * - * NOTE: caller must lock device list if necessary - * - */ -static void nmwa_dbus_device_update_all_networks (NetworkDevice *dev, NMWirelessApplet *applet) -{ - char *active_network = NULL; - char **networks = NULL; - int num_items = 0; - int i; - g_return_if_fail (dev != NULL); - - /* Clear out existing entries in the list */ - if (dev->networks) - network_device_free_wireless_network_list (dev); - - if (dev->type != DEVICE_TYPE_WIRELESS_ETHERNET) - goto out; - - if (dev == applet->dbus_active_device) - active_network = nmwa_dbus_get_active_network (applet, dev->nm_device, APPLET_STATE_IGNORE); - if (applet->applet_state == APPLET_STATE_NO_NM) - goto out; /* Don't proceed if NetworkManager died during the call to get the active network */ - - networks = nmwa_dbus_get_device_networks (applet, dev->nm_device, &num_items, APPLET_STATE_NO_CONNECTION); - if (!networks || (applet->applet_state == APPLET_STATE_NO_NM)) - goto out; - - for (i = 0; i < num_items; i++) - { - WirelessNetwork *tmp_net = nmwa_get_net_for_nm_net (dev, networks[i]); - - /* Only add the network if its not already in the device's network list. We - * don't want duplicates. - */ - if (!tmp_net) - { - WirelessNetwork *net; - - if ((net = nmwa_dbus_get_one_wireless_network (applet, dev, networks[i], active_network))) - { - network_device_add_wireless_network (dev, net); - wireless_network_unref (net); - } - } - } - -out: - g_free (active_network); - g_strfreev (networks); -} - - - -void nmwa_free_gui_data_model (NMWirelessApplet *applet) -{ - g_return_if_fail (applet != NULL); - - if (applet->gui_device_list) - { - g_slist_foreach (applet->gui_device_list, (GFunc) network_device_unref, NULL); - g_slist_free (applet->gui_device_list); - applet->gui_device_list = NULL; - } - if (applet->gui_active_device) - { - network_device_unref (applet->gui_active_device); - applet->gui_active_device = NULL; - } - if (applet->gui_nm_status) - { - g_free (applet->gui_nm_status); - applet->gui_nm_status = NULL; - } - - if (applet->gui_active_vpn) - nmwa_vpn_connection_unref (applet->gui_active_vpn, __FUNCTION__); - applet->gui_active_vpn = NULL; - - if (applet->gui_vpn_connections) - { - g_slist_foreach (applet->gui_vpn_connections, (GFunc) nmwa_vpn_connection_unref, (gpointer)__FUNCTION__); - g_slist_free (applet->gui_vpn_connections); - applet->gui_vpn_connections = NULL; - } -} - - -void nmwa_free_dbus_data_model (NMWirelessApplet *applet) -{ - g_return_if_fail (applet != NULL); - - if (applet->dbus_device_list) - { - g_slist_foreach (applet->dbus_device_list, (GFunc) network_device_unref, NULL); - g_slist_free (applet->dbus_device_list); - applet->dbus_device_list = NULL; - } - if (applet->dbus_active_device) - { - network_device_unref (applet->dbus_active_device); - applet->dbus_active_device = NULL; - } - if (applet->dbus_nm_status) - { - g_free (applet->dbus_nm_status); - applet->dbus_nm_status = NULL; - } - - if (applet->dbus_active_vpn) - nmwa_vpn_connection_unref (applet->dbus_active_vpn, __FUNCTION__); - applet->dbus_active_vpn = NULL; - - if (applet->dbus_vpn_connections) - { - g_slist_foreach (applet->dbus_vpn_connections, (GFunc) nmwa_vpn_connection_unref, (gpointer)__FUNCTION__); - g_slist_free (applet->dbus_vpn_connections); - applet->dbus_vpn_connections = NULL; - } -} - - -/* - * nmwa_copy_data_model - * - * Copy the dbus data model over to the gui data model - * - */ -void nmwa_copy_data_model (NMWirelessApplet *applet) -{ - GSList *elt; - NetworkDevice *act_dev = NULL; - - g_return_if_fail (applet != NULL); - - /* Free the existing GUI data model. */ - nmwa_free_gui_data_model (applet); - - /* Deep-copy network devices to GUI data model */ - for (elt = applet->dbus_device_list; elt; elt = g_slist_next (elt)) - { - NetworkDevice *src = (NetworkDevice *)(elt->data); - NetworkDevice *dst = network_device_copy (src); - - if (dst) - { - /* Transfer ownership of device to list, don't need to unref it */ - applet->gui_device_list = g_slist_append (applet->gui_device_list, dst); - - /* Make sure we get the right active device for the gui data model */ - if (applet->dbus_active_device == src) - { - network_device_ref (dst); - act_dev = dst; - } - } - } - - /* active_device is just a pointer into the device list, no need to deep-copy it */ - applet->gui_active_device = act_dev; - applet->gui_nm_status = g_strdup (applet->dbus_nm_status); - - /* Deep-copy VPN connections to GUI data model */ - for (elt = applet->dbus_vpn_connections; elt; elt = g_slist_next (elt)) - { - VPNConnection *src_vpn = elt->data; - VPNConnection *new_vpn = nmwa_vpn_connection_copy (src_vpn, __FUNCTION__); - - if (new_vpn) - { - applet->gui_vpn_connections = g_slist_append (applet->gui_vpn_connections, new_vpn); - if (applet->dbus_active_vpn == src_vpn) - { - nmwa_vpn_connection_ref (new_vpn, __FUNCTION__); - applet->gui_active_vpn = new_vpn; - } - } - } -} - - -/* - * nmwa_dbus_update_active_device_strength - * - * Update the active device's current wireless network strength - * - */ -static gboolean nmwa_dbus_update_active_device_strength (gpointer user_data) -{ - NMWirelessApplet *applet; - - g_return_val_if_fail (user_data != NULL, FALSE); - - applet = (NMWirelessApplet *)user_data; - - if (applet->applet_state == APPLET_STATE_NO_NM) - return TRUE; - - if (applet->gui_active_device && (applet->gui_active_device->type == DEVICE_TYPE_WIRELESS_ETHERNET)) - { - guint8 strength = nmwa_dbus_get_object_strength (applet, applet->gui_active_device->nm_device); - - applet->gui_active_device->strength = strength; - if (applet->gui_active_device == applet->dbus_active_device) - applet->dbus_active_device->strength = strength; - } - - return (TRUE); -} - - -/* - * nmwa_dbus_device_update_one_network - * - * Update one wireless network - * - */ -static void nmwa_dbus_device_update_one_network (NMWirelessApplet *applet, DBusMessage *message) -{ - char *dev_path = NULL; - char *net_path = NULL; - NMNetworkStatus status; - guint8 strength = -1; - DBusError error; - gboolean success = TRUE; - - g_return_if_fail (applet != NULL); - g_return_if_fail (message != NULL); - - dbus_error_init (&error); - /* Try first time with strength, which is only passed for NETWORK_STATUS_STRENGTH_CHANGED */ - if (!dbus_message_get_args (message, &error, - DBUS_TYPE_OBJECT_PATH, &dev_path, - DBUS_TYPE_OBJECT_PATH, &net_path, - DBUS_TYPE_UINT32, &status, - DBUS_TYPE_INT32, &strength, - DBUS_TYPE_INVALID)) - { - if (dbus_error_is_set (&error)) - dbus_error_free (&error); - dbus_error_init (&error); - - /* Try without strength */ - if (!dbus_message_get_args (message, &error, - DBUS_TYPE_OBJECT_PATH, &dev_path, - DBUS_TYPE_OBJECT_PATH, &net_path, - DBUS_TYPE_UINT32, &status, - DBUS_TYPE_INVALID)) - { - if (dbus_error_is_set (&error)) - dbus_error_free (&error); - success = FALSE; - } - /* If the signal is NETWORK_STATUS_STRENGTH_CHANGED but we didn't get passed - * a strength in the arguments, we can't use the signal. - */ - if (status == NETWORK_STATUS_STRENGTH_CHANGED) - success = FALSE; - } - - if (success) - { - NetworkDevice *dev = nmwa_get_device_for_nm_device (applet->dbus_device_list, dev_path); - WirelessNetwork *net = dev ? nmwa_get_net_for_nm_net (dev, net_path) : NULL; - gboolean changed = FALSE; - - switch (status) - { - case NETWORK_STATUS_DISAPPEARED: - if (!dev || !net) - break; - network_device_remove_wireless_network (dev, net); - changed = TRUE; - break; - - case NETWORK_STATUS_APPEARED: - if (!dev) - break; - /* Add it if it doesn't already exist in the device's network list */ - if (!net) - { - WirelessNetwork *tmp_net; - char *active_network = NULL; - - if (dev == applet->dbus_active_device) - active_network = nmwa_dbus_get_active_network (applet, dev->nm_device, APPLET_STATE_IGNORE); - if (applet->applet_state == APPLET_STATE_NO_NM) - break; - - if ((tmp_net = nmwa_dbus_get_one_wireless_network (applet, dev, net_path, active_network))) - { - network_device_add_wireless_network (dev, tmp_net); - wireless_network_unref (tmp_net); - changed = TRUE; - } - g_free (active_network); - } - break; - - case NETWORK_STATUS_STRENGTH_CHANGED: - g_return_if_fail (net != NULL); - net->strength = strength; - changed = TRUE; - break; - - default: - break; - } - - if (changed) - { - /* Now move the data over to the GUI side */ - g_mutex_lock (applet->data_mutex); - nmwa_copy_data_model (applet); - g_mutex_unlock (applet->data_mutex); - nmwa_dbus_update_active_device_strength (applet); - } - } -} - - -/* - * nmwa_dbus_schedule_driver_notification - * - * Schedule the driver notification routine to run in the main loop. - * - */ -void nmwa_dbus_schedule_driver_notification (NMWirelessApplet *applet, NetworkDevice *dev) -{ - DriverNotifyCBData *cb_data; - - g_return_if_fail (applet != NULL); - g_return_if_fail (dev != NULL); - - cb_data = g_malloc0 (sizeof (DriverNotifyCBData)); - cb_data->applet = applet; - cb_data->dev = dev; - - g_idle_add (nmwa_driver_notify, (gpointer)cb_data); -} - - -/* - * nmwa_dbus_check_drivers - * - * If a device got added, we notify the user if the device's driver - * has any problems (no carrier detect, no wireless scanning, etc). - * - */ -void nmwa_dbus_check_drivers (NMWirelessApplet *applet) -{ - GSList *elt; - - g_return_if_fail (applet != NULL); - - /* For every device that's in the dbus data model but not in - * the gui data model, signal the user. - */ - for (elt = applet->dbus_device_list; elt; elt = g_slist_next (elt)) - { - NetworkDevice *dbus_dev = (NetworkDevice *)(elt->data); - GSList *elt2; - gboolean found = FALSE; - - for (elt2 = applet->gui_device_list; elt2; elt2 = g_slist_next (elt2)) - { - NetworkDevice *gui_dev = (NetworkDevice *)(elt2->data); - - if ( !nm_null_safe_strcmp (dbus_dev->nm_device, gui_dev->nm_device) - && !nm_null_safe_strcmp (dbus_dev->addr, gui_dev->addr) - && !nm_null_safe_strcmp (dbus_dev->udi, gui_dev->udi)) - { - found = TRUE; - break; - } - } - - if ( !found - && ( (dbus_dev->driver_support_level == NM_DRIVER_NO_CARRIER_DETECT) - || (dbus_dev->driver_support_level == NM_DRIVER_NO_WIRELESS_SCAN))) - { - network_device_ref (dbus_dev); - nmwa_dbus_schedule_driver_notification (applet, dbus_dev); - } - } -} - - -/* - * sort_devices_function - * - * Sort the devices for display... Wired devices at the top. - * - */ -static int -sort_devices_function (gconstpointer a, gconstpointer b) -{ - NetworkDevice *dev_a = (NetworkDevice *) a; - NetworkDevice *dev_b = (NetworkDevice *) b; - char *name_a; - char *name_b; - - if (dev_a->hal_name) - name_a = dev_a->hal_name; - else if (dev_a->nm_name) - name_a = dev_a->nm_name; - else - name_a = ""; - - if (dev_b->hal_name) - name_b = dev_b->hal_name; - else if (dev_b->nm_name) - name_b = dev_b->nm_name; - else - name_b = ""; - - if (dev_a->type == dev_b->type) - { - return strcmp (name_a, name_b); - } - if (dev_a->type == DEVICE_TYPE_WIRED_ETHERNET) - return -1; - if (dev_b->type == DEVICE_TYPE_WIRED_ETHERNET) - return 1; - if (dev_a->type == DEVICE_TYPE_WIRELESS_ETHERNET) - return -1; - if (dev_b->type == DEVICE_TYPE_WIRELESS_ETHERNET) - return 1; - - /* Unknown device types. Sort by name only at this point. */ - return strcmp (name_a, name_b); -} - - -static void nmwa_dbus_lock_and_copy_data_model (NMWirelessApplet *applet) -{ - g_return_if_fail (applet != NULL); - - /* Now copy the data over to the GUI side */ - g_mutex_lock (applet->data_mutex); - nmwa_copy_data_model (applet); - g_mutex_unlock (applet->data_mutex); -} - - -/* - * nmwa_dbus_update_devices - * - * Get a device list from NetworkManager - * - */ -static void nmwa_dbus_update_devices (NMWirelessApplet *applet) -{ - char **devices = NULL; - int num_items = 0; - int i; - gboolean adhoc = FALSE; - char *nm_act_dev; - char *nm_status; - gboolean scanning_enabled; - gboolean wireless_enabled; - - g_return_if_fail (applet->data_mutex != NULL); - - if (!(nm_status = nmwa_dbus_get_nm_status (applet, APPLET_STATE_NO_CONNECTION))) - return; - - switch (nmwa_dbus_call_nm_method (applet->connection, NM_DBUS_PATH, "getDevices", NM_DBUS_TYPE_OBJECT_PATH_ARRAY, - (void **)(&devices), &num_items)) - { - case (RETURN_NO_NM): - applet->applet_state = APPLET_STATE_NO_NM; - break; - - default: - break; - } - - if (!devices) - { - g_free (nm_status); - return; - } - - nmwa_free_dbus_data_model (applet); - applet->dbus_nm_status = nm_status; - - nm_act_dev = nmwa_dbus_get_active_device (applet, APPLET_STATE_IGNORE); - - for (i = 0; i < num_items; i++) - { - char *name = nmwa_dbus_get_object_name (applet, devices [i]); - - if (name && strlen (name)) - { - NetworkDevice *dev; - - if ((dev = network_device_new ())) - { - dev->nm_device = g_strdup (devices[i]); - dev->type = nmwa_dbus_get_device_type (applet, devices[i], APPLET_STATE_NO_CONNECTION); - dev->driver_support_level = nmwa_dbus_get_device_driver_support_level (applet, devices[i]); - dev->addr = nmwa_dbus_get_hw_addr (applet, devices[i]); - dev->link = nmwa_dbus_get_device_link_active (applet, devices[i]); - dev->nm_name = g_strdup (name); - dev->udi = nmwa_dbus_get_device_udi (applet, devices[i]); - dev->hal_name = nmwa_dbus_get_hal_device_info (applet->connection, dev->udi); - - /* Ensure valid device information */ - if (!dev->nm_device || !dev->nm_name || !dev->udi || (dev->type == -1)) - network_device_unref (dev); - else - { - applet->dbus_device_list = g_slist_append (applet->dbus_device_list, dev); - if (nm_act_dev && (strcmp (nm_act_dev, devices[i]) == 0)) - { - /* ref the current active device */ - network_device_ref (dev); - applet->dbus_active_device = dev; - if (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET) - adhoc = (nmwa_dbus_get_object_mode (applet, nm_act_dev) == NETWORK_MODE_ADHOC); - } - nmwa_dbus_device_update_all_networks (dev, applet); - } - } - } - g_free (name); - } - g_free (nm_act_dev); - g_strfreev (devices); - - /* Sort the devices for display */ - applet->dbus_device_list = g_slist_sort (applet->dbus_device_list, sort_devices_function); - - /* Notify user of issues with certain cards/drivers */ - nmwa_dbus_check_drivers (applet); - - applet->is_adhoc = adhoc; - applet->scanning_enabled = nmwa_dbus_get_scanning_enabled (applet); - applet->wireless_enabled = nmwa_dbus_get_wireless_enabled (applet); -} - - -/* - * nmwa_dbus_update_one_vpn_connection - * - * Grab properties of one VPN connection from NetworkManager. - * - */ -void nmwa_dbus_update_one_vpn_connection (DBusConnection *connection, const char *name, NMWirelessApplet *applet, gboolean is_active) -{ - DBusMessage *message; - DBusError error; - DBusMessage *reply; - const char *user_name = NULL; - DBusMessageIter iter; - - g_return_if_fail (connection != NULL); - g_return_if_fail (applet != NULL); - g_return_if_fail (name != NULL); - - if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH_VPN, NM_DBUS_INTERFACE_VPN, "getVPNConnectionProperties"))) - { - nm_warning ("Couldn't allocate the dbus message"); - return; - } - - dbus_message_append_args (message, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID); - - /* Send message and get properties back from NetworkManager */ - dbus_error_init (&error); - reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error); - dbus_message_unref (message); - if (dbus_error_is_set (&error)) - { - nm_warning ("nmwa_dbus_update_one_vpn_connection(): %s raised %s", error.name, error.message); - goto out; - } - else if (!reply) - goto out; - else - { - VPNConnection *vpn; - - dbus_message_iter_init (reply, &iter); - - /* Skip name, we already know it */ - dbus_message_iter_next (&iter); - - if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) - { - nm_warning ("Reply had wrong arguments: " - "(expected %u, got %u)\n", DBUS_TYPE_STRING, - dbus_message_iter_get_arg_type (&iter)); - goto out; - } - dbus_message_iter_get_basic (&iter, &user_name); - - if (!(vpn = nmwa_vpn_connection_find_by_name (applet->dbus_vpn_connections, name))) - { - vpn = nmwa_vpn_connection_new (name, __FUNCTION__); - nmwa_vpn_connection_set_user_name (vpn, user_name); - applet->dbus_vpn_connections = g_slist_append (applet->dbus_vpn_connections, vpn); - } - else - nmwa_vpn_connection_set_user_name (vpn, user_name); - - if (is_active) - { - nmwa_vpn_connection_ref (vpn, __FUNCTION__); - applet->dbus_active_vpn = vpn; - } - } - -out: - if (reply) - dbus_message_unref (reply); -} - - -/* - * nmwa_dbus_update_vpn_connections - * - * Grab a list of all VPN connections from NetworkManager. - * - */ -static void nmwa_dbus_update_vpn_connections (NMWirelessApplet *applet) -{ - char **names; - int num_items = 0; - char *active; - - g_return_if_fail (applet != NULL); - - g_slist_foreach (applet->dbus_vpn_connections, (GFunc) nmwa_vpn_connection_unref, (gpointer)__FUNCTION__); - g_slist_free (applet->dbus_vpn_connections); - applet->dbus_vpn_connections = NULL; - - if (applet->dbus_active_vpn) - nmwa_vpn_connection_unref (applet->dbus_active_vpn, __FUNCTION__); - applet->dbus_active_vpn = NULL; - - active = nmwa_dbus_get_active_vpn_connection (applet); - if ((names = nmwa_dbus_get_vpn_connections (applet, &num_items))) - { - int i; - - for (i = 0; i < num_items; i++) - { - gboolean is_active = active ? (strcmp (active, names[i]) == 0) : FALSE; - nmwa_dbus_update_one_vpn_connection (applet->connection, names[i], applet, is_active); - } - g_strfreev (names); - } - g_free (active); -} - - -/* - * nmwa_dbus_filter - * - */ -static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessage *message, void *user_data) -{ - NMWirelessApplet *applet = (NMWirelessApplet *)user_data; - gboolean handled = TRUE; - DBusError error; - - g_return_val_if_fail (applet != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); - g_return_val_if_fail (connection != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); - g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); - - dbus_error_init (&error); - - if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) - { - char *service; - char *old_owner; - char *new_owner; - - if (dbus_message_get_args (message, &error, - DBUS_TYPE_STRING, &service, - DBUS_TYPE_STRING, &old_owner, - DBUS_TYPE_STRING, &new_owner, - DBUS_TYPE_INVALID)) - { - gboolean old_owner_good = (old_owner && (strlen (old_owner) > 0)); - gboolean new_owner_good = (new_owner && (strlen (new_owner) > 0)); - - if ( (strcmp (service, NM_DBUS_SERVICE) == 0) - && (!old_owner_good && new_owner_good) /* Equivalent to old ServiceCreated signal */ - && (applet->applet_state == APPLET_STATE_NO_NM)) - { - /* NetworkManager started up */ - applet->applet_state = APPLET_STATE_NO_CONNECTION; - } - else if (old_owner_good && !new_owner_good) /* Equivalent to old ServiceDeleted signal */ - { - if (strcmp (service, NM_DBUS_SERVICE) == 0) - applet->applet_state = APPLET_STATE_NO_NM; - else if (strcmp (service, NMI_DBUS_SERVICE) == 0) - gtk_main_quit (); /* Die if NetworkManagerInfo dies */ - } - } - } - else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "WirelessNetworkUpdate")) - nmwa_dbus_device_update_one_network (applet, message); - else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE_VPN, "VPNConnectionUpdate")) - { - char *name; - - if (dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) - { - nmwa_dbus_update_one_vpn_connection (applet->connection, name, applet, FALSE); - nmwa_dbus_lock_and_copy_data_model (applet); - } - } - else if ( dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNowActive") - || dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNoLongerActive") - || dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceActivating") - || dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceStatusChanged") - || dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DevicesChanged")) - { - nmwa_dbus_update_devices (applet); - nmwa_dbus_update_vpn_connections (applet); - nmwa_dbus_lock_and_copy_data_model (applet); - } - else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE_VPN, "VPNConnectionChange")) - { - nmwa_dbus_update_vpn_connections (applet); - nmwa_dbus_lock_and_copy_data_model (applet); - } - else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE_VPN, "VPNLoginFailed")) - { - char *vpn_name; - char *error_msg; - - if (dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &vpn_name, DBUS_TYPE_STRING, &error_msg, DBUS_TYPE_INVALID)) - nmwa_schedule_vpn_login_failure_dialog (applet, vpn_name, error_msg); - } - else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE_VPN, "VPNLoginBanner")) - { - char *vpn_name; - char *banner; - - if (dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &vpn_name, DBUS_TYPE_STRING, &banner, DBUS_TYPE_INVALID)) - nmwa_schedule_vpn_login_banner_dialog (applet, vpn_name, banner); - } - else - handled = FALSE; - - if (dbus_error_is_set (&error)) - dbus_error_free (&error); - - return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED); -} - - -/* - * nmwa_dbus_nm_is_running - * - * Ask dbus whether or not NetworkManager is running - * - */ -static gboolean nmwa_dbus_nm_is_running (DBusConnection *connection) -{ - DBusError error; - gboolean exists; - - g_return_val_if_fail (connection != NULL, FALSE); - - dbus_error_init (&error); - exists = dbus_bus_name_has_owner (connection, NM_DBUS_SERVICE, &error); - if (dbus_error_is_set (&error)) - dbus_error_free (&error); - return (exists); -} - - -/* - * nmwa_dbus_init - * - * Initialize a connection to NetworkManager if we can get one - * - */ -static DBusConnection * nmwa_dbus_init (NMWirelessApplet *applet, GMainContext *context) -{ - DBusConnection *connection = NULL; - DBusError error; - - g_return_val_if_fail (applet != NULL, NULL); - - dbus_error_init (&error); - connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error); - - if (dbus_error_is_set (&error)) - { - fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message); - dbus_error_free (&error); - return (NULL); - } - - if (!dbus_connection_add_filter (connection, nmwa_dbus_filter, applet, NULL)) - return (NULL); - - dbus_connection_set_exit_on_disconnect (connection, FALSE); - dbus_connection_setup_with_g_main (connection, context); - - dbus_bus_add_match(connection, - "type='signal'," - "interface='" DBUS_INTERFACE_DBUS "'," - "sender='" DBUS_SERVICE_DBUS "'", - &error); - if (dbus_error_is_set (&error)) - dbus_error_free (&error); - - dbus_bus_add_match(connection, - "type='signal'," - "interface='" NM_DBUS_INTERFACE "'," - "path='" NM_DBUS_PATH "'," - "sender='" NM_DBUS_SERVICE "'", - &error); - if (dbus_error_is_set (&error)) - dbus_error_free (&error); - - dbus_bus_add_match(connection, - "type='signal'," - "interface='" NM_DBUS_INTERFACE_VPN "'," - "path='" NM_DBUS_PATH_VPN "'," - "sender='" NM_DBUS_SERVICE "'", - &error); - if (dbus_error_is_set (&error)) - dbus_error_free (&error); - - return (connection); -} - - -/* - * nmwa_dbus_timeout_worker - * - * Timer to update our state from NetworkManager - * - */ -static gboolean nmwa_dbus_timeout_worker (gpointer user_data) -{ - NMWirelessApplet *applet = (NMWirelessApplet *)user_data; - - g_return_val_if_fail (applet != NULL, TRUE); - - if (!applet->connection) - { - /* After our first connection, update the state. After that, we listen - * for signals from NetworkManager to trigger state updates. - */ - if ((applet->connection = nmwa_dbus_init (applet, applet->thread_context))) - { - applet->applet_state = APPLET_STATE_NO_CONNECTION; - nmwa_dbus_update_devices (applet); - nmwa_dbus_update_vpn_connections (applet); - nmwa_dbus_lock_and_copy_data_model (applet); - } - } - - return (TRUE); -} - - -/* - * nmwa_dbus_worker - * - * Thread worker function that periodically grabs the NetworkManager state - * and updates our local applet state to reflect that. - * - */ -gpointer nmwa_dbus_worker (gpointer user_data) -{ - NMWirelessApplet *applet = (NMWirelessApplet *)user_data; - guint timeout_id; - GSource *timeout_source; - guint strength_id; - GSource *strength_source; - - g_return_val_if_fail (applet != NULL, NULL); - - dbus_g_thread_init (); - - if (!(applet->thread_context = g_main_context_new ())) - return (NULL); - if (!(applet->thread_loop = g_main_loop_new (applet->thread_context, FALSE))) - return (NULL); - - applet->connection = nmwa_dbus_init (applet, applet->thread_context); - - timeout_source = g_timeout_source_new (2000); - g_source_set_callback (timeout_source, nmwa_dbus_timeout_worker, applet, NULL); - timeout_id = g_source_attach (timeout_source, applet->thread_context); - - strength_source = g_timeout_source_new (2000); - g_source_set_callback (strength_source, nmwa_dbus_update_active_device_strength, applet, NULL); - strength_id = g_source_attach (strength_source, applet->thread_context); - - if (applet->connection && nmwa_dbus_nm_is_running (applet->connection)) - { - applet->applet_state = APPLET_STATE_NO_CONNECTION; - nmwa_dbus_update_devices (applet); - nmwa_dbus_update_vpn_connections (applet); - nmwa_dbus_lock_and_copy_data_model (applet); - } - else - applet->applet_state = APPLET_STATE_NO_NM; - - g_main_loop_run (applet->thread_loop); - - g_source_destroy (timeout_source); - g_source_destroy (strength_source); - - return NULL; -} diff --git a/panel-applet/NMWirelessAppletDbus.h b/panel-applet/NMWirelessAppletDbus.h deleted file mode 100644 index 445f342d5..000000000 --- a/panel-applet/NMWirelessAppletDbus.h +++ /dev/null @@ -1,65 +0,0 @@ -/* NetworkManager Wireless Applet -- Display wireless access points and allow user control - * - * Dan Williams - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2004 Red Hat, Inc. - */ - -#ifndef NM_WIRELESS_APPLET_DBUS_H -#define NM_WIRELESS_APPLET_DBUS_H - -#include -#include -#include "NetworkManager.h" -#include "NMWirelessApplet.h" - -/* Return codes for functions that use dbus */ -enum -{ - RETURN_SUCCESS = 1, - RETURN_FAILURE = 0, - RETURN_NO_NM = -1 -}; - - -gpointer nmwa_dbus_worker (gpointer user_data); - -void nmwa_dbus_set_device (DBusConnection *connection, const NetworkDevice *dev, - const WirelessNetwork *network, NMEncKeyType key_type, - const char *passphrase); - -void nmwa_dbus_create_network (DBusConnection *connection, const NetworkDevice *dev, - const WirelessNetwork *network, NMEncKeyType key_type, - const char *passphrase); - -void nmwa_dbus_enable_scanning (NMWirelessApplet *applet, gboolean enabled); - -void nmwa_dbus_enable_wireless (NMWirelessApplet *applet, gboolean enabled); - -WirelessNetwork * wireless_network_new_with_essid (const char *essid); -void wireless_network_unref (WirelessNetwork *net); - -void network_device_ref (NetworkDevice *dev); -void network_device_unref (NetworkDevice *dev); - -void nmwa_free_gui_data_model (NMWirelessApplet *applet); -void nmwa_free_dbus_data_model (NMWirelessApplet *applet); - -void nmwa_dbus_vpn_activate_connection (DBusConnection *connection, const char *name, const char *password); -void nmwa_dbus_vpn_deactivate_connection(DBusConnection *connection); - -#endif diff --git a/panel-applet/essid.glade b/panel-applet/essid.glade deleted file mode 100644 index 1d21eae50..000000000 --- a/panel-applet/essid.glade +++ /dev/null @@ -1,408 +0,0 @@ - - - - - - - 6 - True - - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - 488 - False - False - True - False - False - GDK_WINDOW_TYPE_HINT_DIALOG - GDK_GRAVITY_NORTH_WEST - True - False - - - - True - False - 4 - - - - True - GTK_BUTTONBOX_END - - - - True - True - True - gtk-cancel - True - GTK_RELIEF_NORMAL - True - -6 - - - - - - True - True - True - True - C_onnect - True - GTK_RELIEF_NORMAL - True - -5 - - - - - 0 - False - True - GTK_PACK_END - - - - - - 6 - True - False - 12 - - - - True - gtk-dialog-question - 6 - 0.5 - 0 - 0 - 0 - - - 0 - False - True - - - - - - True - False - 12 - - - - True - - False - True - GTK_JUSTIFY_LEFT - True - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - True - True - - - - - - True - 3 - 2 - False - 12 - 6 - - - - True - Wireless _adapter: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - wireless_adapter_combo - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 0 - 1 - fill - - - - - - - True - - False - True - - - 1 - 2 - 0 - 1 - fill - fill - - - - - - True - Wireless _network: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - essid_entry - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 1 - 2 - fill - - - - - - - True - True - True - True - 0 - - True - * - True - - - 1 - 2 - 1 - 2 - - - - - - - True - 0 - 0.5 - GTK_SHADOW_ETCHED_IN - - - - True - 0.5 - 0.5 - 1 - 1 - 3 - 6 - 6 - 6 - - - - True - 2 - 3 - False - 12 - 6 - - - - True - Key type: - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 0 - 1 - fill - - - - - - - True - Passphrase: - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 1 - 2 - fill - - - - - - - True - True - True - True - 0 - - True - * - False - - - 1 - 3 - 1 - 2 - - - - - - - True - 128-bit passphrase (WEP) -Ascii key (WEP) -Hex key (WEP) - False - True - - - 1 - 2 - 0 - 1 - fill - fill - - - - - - - - - - True - True - Connect with encryption enabled - True - GTK_RELIEF_NORMAL - True - False - False - True - - - label_item - - - - - 0 - 2 - 2 - 3 - fill - - - - - 0 - True - True - - - - - 0 - True - True - - - - - 0 - True - True - - - - - - - diff --git a/panel-applet/icons/.cvsignore b/panel-applet/icons/.cvsignore deleted file mode 100644 index 3dda72986..000000000 --- a/panel-applet/icons/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -Makefile.in -Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 571dfd418..2a15949ee 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -49,8 +49,6 @@ NetworkManager_CPPFLAGS = \ $(GTHREAD_CFLAGS) \ $(HAL_CFLAGS) \ $(OPENSSL_CFLAGS) \ - -g \ - -Wall \ -DDBUS_API_SUBJECT_TO_CHANGE \ -DG_DISABLE_DEPRECATED \ -DBINDIR=\"$(bindir)\" \ diff --git a/src/NetworkManager.c b/src/NetworkManager.c index d7b5b34a0..3edfb8c34 100644 --- a/src/NetworkManager.c +++ b/src/NetworkManager.c @@ -137,7 +137,7 @@ NMDevice * nm_create_device_and_add_to_list (NMData *data, const char *udi, cons nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__); nm_policy_schedule_state_update (data); - nm_dbus_signal_device_status_change (data->dbus_connection, dev, DEVICE_LIST_CHANGE); + nm_dbus_signal_device_status_change (data->dbus_connection, dev, DEVICE_ADDED); } else { @@ -185,7 +185,7 @@ void nm_remove_device_from_list (NMData *data, const char *udi) nm_device_set_removed (dev, TRUE); nm_device_deactivate (dev, FALSE); nm_device_worker_thread_stop (dev); - nm_dbus_signal_device_status_change (data->dbus_connection, dev, DEVICE_LIST_CHANGE); + nm_dbus_signal_device_status_change (data->dbus_connection, dev, DEVICE_REMOVED); nm_device_unref (dev); /* Remove the device entry from the device list and free its data */ @@ -334,25 +334,25 @@ static void nm_add_initial_devices (NMData *data) /* - * nm_status_signal_broadcast + * nm_state_change_signal_broadcast * */ -static gboolean nm_status_signal_broadcast (gpointer user_data) +static gboolean nm_state_change_signal_broadcast (gpointer user_data) { NMData *data = (NMData *)user_data; g_return_val_if_fail (data != NULL, FALSE); - nm_dbus_signal_network_status_change (data->dbus_connection, data); + nm_dbus_signal_state_change (data->dbus_connection, data); return FALSE; } /* - * nm_schedule_status_signal_broadcast + * nm_schedule_state_change_signal_broadcast * */ -void nm_schedule_status_signal_broadcast (NMData *data) +void nm_schedule_state_change_signal_broadcast (NMData *data) { guint id = 0; GSource *source; @@ -360,7 +360,7 @@ void nm_schedule_status_signal_broadcast (NMData *data) g_return_if_fail (data != NULL); source = g_idle_source_new (); - g_source_set_callback (source, nm_status_signal_broadcast, data, NULL); + g_source_set_callback (source, nm_state_change_signal_broadcast, data, NULL); id = g_source_attach (source, data->main_context); g_source_unref (source); } @@ -931,6 +931,8 @@ int main( int argc, char *argv[] ) exit (EXIT_FAILURE); } + nm_schedule_state_change_signal_broadcast (nm_data); + /* Wheeee!!! */ g_main_loop_run (nm_data->main_loop); diff --git a/src/NetworkManagerAPList.c b/src/NetworkManagerAPList.c index 89423d0ff..a05ae186c 100644 --- a/src/NetworkManagerAPList.c +++ b/src/NetworkManagerAPList.c @@ -121,6 +121,31 @@ void nm_ap_list_unref (NMAccessPointList *list) } +/* + * nm_ap_list_size + * + * Return size of the access point list + * + */ +guint nm_ap_list_size (NMAccessPointList *list) +{ + guint size; + + g_return_val_if_fail (list != NULL, 0); + + if (!nm_ap_list_lock (list)) + { + nm_warning ("nm_ap_list_size() could not acquire AP list mutex." ); + return 0; + } + + size = g_slist_length (list->ap_list); + nm_ap_list_unlock (list); + + return size; +} + + /* * nm_ap_list_is_empty * @@ -293,9 +318,7 @@ void nm_ap_list_remove_duplicate_essids (NMAccessPointList *list) for (elt = removal_list; elt; elt = g_slist_next (elt)) { if ((removal_ap = (NMAccessPoint *)(elt->data))) - { nm_ap_list_remove_ap (list, removal_ap); - } } g_slist_free (removal_list); @@ -400,82 +423,6 @@ NMAccessPoint *nm_ap_list_get_ap_by_address (NMAccessPointList *list, const stru } -/* - * nm_ap_list_update_network_from_nmi - * - * Given a network ID, get its information from NetworkManagerInfo - * - */ -void nm_ap_list_update_network_from_nmi (NMAccessPointList *list, const char *network, NMData *data) -{ - NMAccessPoint *ap = NULL; - NMAccessPoint *list_ap = NULL; - - g_return_if_fail (list != NULL); - g_return_if_fail (network != NULL); - g_return_if_fail (list->type == NETWORK_TYPE_ALLOWED); - - if ((ap = nm_dbus_get_network_object (data->dbus_connection, list->type, network))) - { - if ((list_ap = nm_ap_list_get_ap_by_essid (list, network))) - { - nm_ap_set_essid (list_ap, nm_ap_get_essid (ap)); - nm_ap_set_timestamp (list_ap, nm_ap_get_timestamp (ap)); - nm_ap_set_trusted (list_ap, nm_ap_get_trusted (ap)); - nm_ap_set_enc_key_source (list_ap, nm_ap_get_enc_key_source (ap), nm_ap_get_enc_type (ap)); - nm_ap_set_auth_method (list_ap, nm_ap_get_auth_method (ap)); - nm_ap_set_user_addresses (list_ap, nm_ap_get_user_addresses (ap)); - } - else - { - /* New AP, just add it to the list */ - nm_ap_list_append_ap (list, ap); - } - nm_ap_unref (ap); - } - else - { - /* AP got deleted, remove it from our list */ - if ((list_ap = nm_ap_list_get_ap_by_essid (list, network))) - nm_ap_list_remove_ap (list, list_ap); - } -} - - -/* - * nm_ap_list_populate_from_nmi - * - * Populate an initial list of allowed access points - * - */ -void nm_ap_list_populate_from_nmi (NMAccessPointList *list, NMData *data) -{ - char **networks; - int num_networks; - - g_return_if_fail (list != NULL); - g_return_if_fail (data != NULL); - g_return_if_fail (list->type == NETWORK_TYPE_ALLOWED); - - /* If NMI isn't running, don't try to talk to it. */ - if (!nm_dbus_nmi_is_running (data->dbus_connection)) - return; - - networks = nm_dbus_get_networks (data->dbus_connection, list->type, &num_networks); - if (networks && (num_networks > 0)) - { - int i; - for (i = 0; i < num_networks; i++) - { - if (networks[i] && (strlen (networks[i]) > 0)) - nm_ap_list_update_network_from_nmi (list, networks[i], data); - } - - g_strfreev (networks); - } -} - - /* * nm_ap_list_merge_scanned_ap * @@ -517,7 +464,7 @@ gboolean nm_ap_list_merge_scanned_ap (NMAccessPointList *list, NMAccessPoint *me if (nm_ap_get_strength (merge_ap) != nm_ap_get_strength (list_ap_addr)) { nm_ap_set_strength (list_ap_addr, nm_ap_get_strength (merge_ap)); - *strength_changed = TRUE; + *strength_changed = TRUE; } nm_ap_set_last_seen (list_ap_addr, merge_ap_seen); } @@ -525,7 +472,7 @@ gboolean nm_ap_list_merge_scanned_ap (NMAccessPointList *list, NMAccessPoint *me { /* Second, we check for an ESSID match. In this case, - * a list AP has the same non-NULL ESSID as the merge AP. Update the + * a list AP has the same non-NULL ESSID as the merge AP. Update the * encryption and authentication method. Update the strength and address * except when the time_last_seen of the list AP is the same as the * time_last_seen of the merge AP and the strength of the list AP is greater @@ -713,6 +660,20 @@ void nm_ap_list_diff (NMData *data, NMDevice *dev, NMAccessPointList *old, NMAcc } +/* + * nm_ap_list_get_type + * + * Return the type of an AP list + * + */ +NMNetworkType nm_ap_list_get_type (NMAccessPointList *list) +{ + g_return_val_if_fail (list != NULL, NETWORK_TYPE_UNKNOWN); + + return (list->type); +} + + /* * nm_ap_list_lock * diff --git a/src/NetworkManagerAPList.h b/src/NetworkManagerAPList.h index fa68275ca..301160674 100644 --- a/src/NetworkManagerAPList.h +++ b/src/NetworkManagerAPList.h @@ -34,6 +34,7 @@ NMAccessPointList * nm_ap_list_new (NMNetworkType type); void nm_ap_list_ref (NMAccessPointList *list); void nm_ap_list_unref (NMAccessPointList *list); +guint nm_ap_list_size (NMAccessPointList *list); gboolean nm_ap_list_is_empty (NMAccessPointList *list); void nm_ap_list_append_ap (NMAccessPointList *list, NMAccessPoint *ap); @@ -44,10 +45,6 @@ void nm_ap_list_remove_duplicate_essids (NMAccessPointList *list); NMAccessPoint * nm_ap_list_get_ap_by_essid (NMAccessPointList *list, const char *network); NMAccessPoint * nm_ap_list_get_ap_by_address (NMAccessPointList *list, const struct ether_addr *addr); -void nm_ap_list_update_network_from_nmi (NMAccessPointList *list, const char *network, NMData *data); - -void nm_ap_list_populate_from_nmi (NMAccessPointList *list, NMData *data); - void nm_ap_list_copy_properties (NMAccessPointList *dest, NMAccessPointList *source); void nm_ap_list_copy_essids_by_address (NMAccessPointList *dest, NMAccessPointList *source); void nm_ap_list_copy_one_essid_by_address (NMAccessPoint *ap, NMAccessPointList *search_list); @@ -55,6 +52,8 @@ void nm_ap_list_copy_one_essid_by_address (NMAccessPoint *ap, NMAccessPointLi void nm_ap_list_diff (NMData *data, NMDevice *dev, NMAccessPointList *old, NMAccessPointList *new); gboolean nm_ap_list_merge_scanned_ap (NMAccessPointList *list, NMAccessPoint *merge_ap, gboolean *new, gboolean *strength_changed); +NMNetworkType nm_ap_list_get_type (NMAccessPointList *list); + gboolean nm_ap_list_lock (NMAccessPointList *list); void nm_ap_list_unlock (NMAccessPointList *list); diff --git a/src/NetworkManagerDbus.c b/src/NetworkManagerDbus.c index 923c3feb1..427176083 100644 --- a/src/NetworkManagerDbus.c +++ b/src/NetworkManagerDbus.c @@ -71,12 +71,12 @@ DBusMessage *nm_dbus_create_error_message (DBusMessage *message, const char *exc /* - * nm_dbus_get_object_path_from_device + * nm_dbus_get_object_path_for_device * * Copies the object path for a device object. Caller must free returned string. * */ -static gchar * nm_dbus_get_object_path_from_device (NMDevice *dev) +char * nm_dbus_get_object_path_for_device (NMDevice *dev) { char *object_path, *escaped_object_path; @@ -90,6 +90,30 @@ static gchar * nm_dbus_get_object_path_from_device (NMDevice *dev) } +/* + * nm_dbus_get_object_path_for_network + * + * Copies the object path for a network object. Caller must free returned string. + * + */ +char * nm_dbus_get_object_path_for_network (NMDevice *dev, NMAccessPoint *ap) +{ + char *object_path, *escaped_object_path; + + g_return_val_if_fail (dev != NULL, NULL); + g_return_val_if_fail (ap != NULL, NULL); + + if (!nm_ap_get_essid (ap)) + return NULL; + + object_path = g_strdup_printf ("%s/%s/Networks/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (dev), nm_ap_get_essid (ap)); + escaped_object_path = nm_dbus_escape_object_path (object_path); + g_free (object_path); + + return escaped_object_path; +} + + /* * nm_dbus_get_device_from_object_path * @@ -271,7 +295,7 @@ void nm_dbus_signal_device_status_change (DBusConnection *connection, NMDevice * g_return_if_fail (connection != NULL); g_return_if_fail (dev != NULL); - if (!(dev_path = nm_dbus_get_object_path_from_device (dev))) + if (!(dev_path = nm_dbus_get_object_path_for_device (dev))) return; switch (status) @@ -285,14 +309,16 @@ void nm_dbus_signal_device_status_change (DBusConnection *connection, NMDevice * case (DEVICE_ACTIVATING): signal = "DeviceActivating"; break; - case (DEVICE_LIST_CHANGE): - signal = "DevicesChanged"; - break; - case (DEVICE_STATUS_CHANGE): - signal = "DeviceStatusChanged"; - break; case (DEVICE_ACTIVATION_FAILED): signal = "DeviceActivationFailed"; + if (nm_device_is_wireless (dev)) + ap = nm_device_get_best_ap (dev); + break; + case (DEVICE_ADDED): + signal = "DeviceAdded"; + break; + case (DEVICE_REMOVED): + signal = "DeviceRemoved"; break; default: nm_warning ("nm_dbus_signal_device_status_change(): got a bad signal name"); @@ -306,20 +332,18 @@ void nm_dbus_signal_device_status_change (DBusConnection *connection, NMDevice * return; } - if ((status == DEVICE_ACTIVATION_FAILED) && nm_device_is_wireless (dev)) - ap = nm_device_get_best_ap (dev); /* If the device was wireless, attach the name of the wireless network that failed to activate */ - if (ap && nm_ap_get_essid (ap)) { - const char *essid; - essid = nm_ap_get_essid (ap); - dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev_path, - DBUS_TYPE_STRING, &essid, - DBUS_TYPE_INVALID); - } else + if (ap && nm_ap_get_essid (ap)) + { + const char *essid = nm_ap_get_essid (ap); + dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_STRING, &essid, DBUS_TYPE_INVALID); + } + else dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_INVALID); if (ap) nm_ap_unref (ap); + g_free (dev_path); if (!dbus_connection_send (connection, message, NULL)) @@ -337,60 +361,58 @@ void nm_dbus_signal_device_status_change (DBusConnection *connection, NMDevice * * Caller MUST free returned value * */ -char *nm_dbus_network_status_from_data (NMData *data) +NMState nm_get_app_state_from_data (NMData *data) { char *status = NULL; - g_return_val_if_fail (data != NULL, NULL); + g_return_val_if_fail (data != NULL, NM_STATE_DISCONNECTED); if (data->asleep == TRUE) - status = g_strdup ("asleep"); + return NM_STATE_ASLEEP; if (data->forcing_device) - status = g_strdup ("scanning"); + return NM_STATE_SCANNING; else if (data->active_device && nm_device_is_activating (data->active_device)) { if (nm_device_is_wireless (data->active_device) && nm_device_get_now_scanning (data->active_device)) - status = g_strdup ("scanning"); + return NM_STATE_SCANNING; else - status = g_strdup ("connecting"); + return NM_STATE_CONNECTING; } else if (data->active_device) - status = g_strdup ("connected"); + return NM_STATE_CONNECTED; else - status = g_strdup ("disconnected"); + return NM_STATE_DISCONNECTED; - return (status); + g_assert_not_reached (); + + return NM_STATE_UNKNOWN; } /* - * nm_dbus_signal_network_status_change + * nm_dbus_signal_state_change * - * Signal a change in general network status. + * Signal a change in state * */ -void nm_dbus_signal_network_status_change (DBusConnection *connection, NMData *data) +void nm_dbus_signal_state_change (DBusConnection *connection, NMData *data) { - DBusMessage *message; - char *status = NULL; + DBusMessage * message; + NMState state; g_return_if_fail (connection != NULL); g_return_if_fail (data != NULL); - if (!(message = dbus_message_new_signal (NM_DBUS_PATH, NM_DBUS_INTERFACE, "NetworkStatusChange"))) + if (!(message = dbus_message_new_signal (NM_DBUS_PATH, NM_DBUS_INTERFACE, NM_DBUS_SIGNAL_STATE_CHANGE))) { - nm_warning ("nm_dbus_signal_device_status_change(): Not enough memory for new dbus message!"); + nm_warning ("nm_dbus_signal_state_change(): Not enough memory for new dbus message!"); return; } - if ((status = nm_dbus_network_status_from_data (data))) - { - dbus_message_append_args (message, DBUS_TYPE_STRING, &status, DBUS_TYPE_INVALID); - - if (!dbus_connection_send (connection, message, NULL)) - nm_warning ("nm_dbus_signal_device_status_change(): Could not raise the signal!"); - g_free (status); - } + state = nm_get_app_state_from_data (data); + dbus_message_append_args (message, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID); + if (!dbus_connection_send (connection, message, NULL)) + nm_warning ("nm_dbus_signal_state_change(): Could not raise the signal!"); dbus_message_unref (message); } @@ -410,7 +432,7 @@ void nm_dbus_signal_device_ip4_address_change (DBusConnection *connection, NMDev g_return_if_fail (connection != NULL); g_return_if_fail (dev != NULL); - if (!(dev_path = nm_dbus_get_object_path_from_device (dev))) + if (!(dev_path = nm_dbus_get_object_path_for_device (dev))) return; message = dbus_message_new_signal (NM_DBUS_PATH, NM_DBUS_INTERFACE, "DeviceIP4AddressChange"); @@ -439,48 +461,135 @@ void nm_dbus_signal_device_ip4_address_change (DBusConnection *connection, NMDev */ void nm_dbus_signal_wireless_network_change (DBusConnection *connection, NMDevice *dev, NMAccessPoint *ap, NMNetworkStatus status, gint8 strength) { - DBusMessage *message; - char *dev_path; - char *ap_path; + DBusMessage * message; + char * dev_path = NULL; + char * net_path = NULL; + const char * signal = NULL; g_return_if_fail (connection != NULL); g_return_if_fail (dev != NULL); g_return_if_fail (ap != NULL); - if (!(dev_path = nm_dbus_get_object_path_from_device (dev))) - return; + if (!(dev_path = nm_dbus_get_object_path_for_device (dev))) + goto out; - if (!(ap_path = nm_device_get_path_for_ap (dev, ap))) + if (!(net_path = nm_dbus_get_object_path_for_network (dev, ap))) + goto out; + + switch (status) { - g_free (dev_path); - return; + case NETWORK_STATUS_DISAPPEARED: + signal = "WirelessNetworkDisappeared"; + break; + case NETWORK_STATUS_APPEARED: + signal = "WirelessNetworkAppeared"; + break; + case NETWORK_STATUS_STRENGTH_CHANGED: + signal = "WirelessNetworkStrengthChanged"; + break; + default: + break; } - message = dbus_message_new_signal (NM_DBUS_PATH, NM_DBUS_INTERFACE, "WirelessNetworkUpdate"); - if (!message) + if (!signal) + { + nm_warning ("nm_dbus_signal_wireless_network_change(): tried to broadcast unknown signal."); + goto out; + } + + if (!(message = dbus_message_new_signal (NM_DBUS_PATH, NM_DBUS_INTERFACE, signal))) { nm_warning ("nm_dbus_signal_wireless_network_change(): Not enough memory for new dbus message!"); - g_free (dev_path); - g_free (ap_path); - return; + goto out; } - dbus_message_append_args (message, - DBUS_TYPE_OBJECT_PATH, &dev_path, - DBUS_TYPE_OBJECT_PATH, &ap_path, - DBUS_TYPE_UINT32, &status, - DBUS_TYPE_INVALID); - g_free (ap_path); - g_free (dev_path); - - /* Append signal-specific data */ + dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_OBJECT_PATH, &net_path, DBUS_TYPE_INVALID); if (status == NETWORK_STATUS_STRENGTH_CHANGED) dbus_message_append_args (message, DBUS_TYPE_INT32, &strength, DBUS_TYPE_INVALID); if (!dbus_connection_send (connection, message, NULL)) - nm_warning ("nm_dbus_signal_wireless_network_change(): Could not raise the WirelessNetworkAppeared signal!"); + nm_warning ("nm_dbus_signal_wireless_network_change(): Could not raise the WirelessNetwork* signal!"); dbus_message_unref (message); + +out: + g_free (net_path); + g_free (dev_path); +} + + +typedef struct GetKeyForNetworkCBData +{ + NMData * data; + char * dev_path; + char * net_path; +} GetKeyForNetworkCBData; + + +void free_get_key_for_network_cb_data (GetKeyForNetworkCBData *data) +{ + if (data) + { + g_free (data->dev_path); + g_free (data->net_path); + memset (data, 0, sizeof (GetKeyForNetworkCBData)); + g_free (data); + } +} + +/* + * nm_dbus_get_user_key_for_network_cb + * + * Callback from nm_dbus_get_user_key_for_network when NetworkManagerInfo returns + * the new user key. + * + */ +static void nm_dbus_get_user_key_for_network_cb (DBusPendingCall *pcall, GetKeyForNetworkCBData *cb_data) +{ + DBusMessage * reply; + char * passphrase = NULL; + NMEncKeyType key_type = -1; + + g_return_if_fail (pcall != NULL); + g_return_if_fail (cb_data != NULL); + g_return_if_fail (cb_data->data != NULL); + g_return_if_fail (cb_data->dev_path != NULL); + g_return_if_fail (cb_data->net_path != NULL); + + dbus_pending_call_ref (pcall); + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) + { + dbus_message_unref (reply); + goto out; + } + + if (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &passphrase, DBUS_TYPE_INT32, &key_type, DBUS_TYPE_INVALID)) + { + char * dev_path = nm_dbus_unescape_object_path (cb_data->dev_path); + char * net_path = nm_dbus_unescape_object_path (cb_data->net_path); + NMDevice * dev; + NMAccessPoint * ap; + + if ((dev = nm_dbus_get_device_from_object_path (cb_data->data, dev_path))) + { + if ((ap = nm_device_ap_list_get_ap_by_obj_path (dev, net_path))) + nm_device_set_user_key_for_network (dev, cb_data->data->invalid_ap_list, ap, passphrase, key_type); + } + + g_free (dev_path); + g_free (net_path); + } + dbus_message_unref (reply); + +out: + dbus_pending_call_unref (pcall); } @@ -492,32 +601,47 @@ void nm_dbus_signal_wireless_network_change (DBusConnection *connection, NMDevic */ void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMDevice *dev, NMAccessPoint *ap, int attempt) { - DBusMessage *message; - const char *iface, *essid; + DBusMessage * message; + DBusPendingCall * pcall; + char * dev_path; + char * net_path; g_return_if_fail (connection != NULL); g_return_if_fail (dev != NULL); + g_return_if_fail (nm_device_get_app_data (dev) != NULL); g_return_if_fail (ap != NULL); g_return_if_fail (nm_ap_get_essid (ap) != NULL); g_return_if_fail (attempt > 0); - message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, - NMI_DBUS_INTERFACE, "getKeyForNetwork"); - if (message == NULL) + if (!(message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "getKeyForNetwork"))) { nm_warning ("nm_dbus_get_user_key_for_network(): Couldn't allocate the dbus message"); return; } - iface = nm_device_get_iface (dev); - essid = nm_ap_get_essid (ap); - dbus_message_append_args (message, DBUS_TYPE_STRING, &iface, - DBUS_TYPE_STRING, &essid, - DBUS_TYPE_INT32, &attempt, - DBUS_TYPE_INVALID); + dev_path = nm_dbus_get_object_path_for_device (dev); + net_path = nm_dbus_get_object_path_for_network (dev, ap); + if (dev_path && strlen (dev_path) && net_path && strlen (net_path)) + { + dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev_path, + DBUS_TYPE_OBJECT_PATH, &net_path, + DBUS_TYPE_INT32, &attempt, + DBUS_TYPE_INVALID); + if (dbus_connection_send_with_reply (connection, message, &pcall, INT_MAX) && pcall) + { + GetKeyForNetworkCBData * cb_data = g_malloc0 (sizeof (GetKeyForNetworkCBData)); - if (!dbus_connection_send (connection, message, NULL)) - nm_warning ("nm_dbus_get_user_key_for_network(): could not send dbus message"); + cb_data->data = nm_device_get_app_data (dev); + cb_data->dev_path = g_strdup (dev_path); + cb_data->net_path = g_strdup (net_path); + dbus_pending_call_set_notify (pcall, (DBusPendingCallNotifyFunction) nm_dbus_get_user_key_for_network_cb, + cb_data, (DBusFreeFunction) free_get_key_for_network_cb_data); + } + else + nm_warning ("nm_dbus_get_user_key_for_network(): could not send dbus message"); + } + g_free (net_path); + g_free (dev_path); dbus_message_unref (message); } @@ -531,13 +655,11 @@ void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMDevice *dev */ void nm_dbus_cancel_get_user_key_for_network (DBusConnection *connection) { - DBusMessage *message; + DBusMessage * message; g_return_if_fail (connection != NULL); - message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, - NMI_DBUS_INTERFACE, "cancelGetKeyForNetwork"); - if (message == NULL) + if (!(message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "cancelGetKeyForNetwork"))) { nm_warning ("nm_dbus_cancel_get_user_key_for_network(): Couldn't allocate the dbus message"); return; @@ -550,204 +672,6 @@ void nm_dbus_cancel_get_user_key_for_network (DBusConnection *connection) } -/* - * nm_dbus_get_network_properties - * - * Get a wireless network from NetworkManagerInfo - * - */ -NMAccessPoint *nm_dbus_get_network_object (DBusConnection *connection, NMNetworkType type, const char *network) -{ - DBusMessage *message; - DBusError error; - DBusMessage *reply; - NMAccessPoint *ap = NULL; - const char *essid = NULL; - gint timestamp_secs = -1; - gint32 i; - const char *key = NULL; - NMEncKeyType key_type = -1; - gboolean trusted = FALSE; - NMDeviceAuthMethod auth_method = NM_DEVICE_AUTH_METHOD_UNKNOWN; - DBusMessageIter iter; - dbus_int32_t type_as_int32; - - g_return_val_if_fail (connection != NULL, NULL); - g_return_val_if_fail (network != NULL, NULL); - g_return_val_if_fail (type != NETWORK_TYPE_UNKNOWN, NULL); - - if (!(message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "getNetworkProperties"))) - { - nm_warning ("Couldn't allocate the dbus message"); - return (NULL); - } - - type_as_int32 = (dbus_int32_t) type; - dbus_message_append_args (message, DBUS_TYPE_STRING, &network, - DBUS_TYPE_INT32, &type_as_int32, - DBUS_TYPE_INVALID); - - /* Send message and get properties back from NetworkManagerInfo */ - dbus_error_init (&error); - reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error); - dbus_message_unref (message); - - if (dbus_error_is_set (&error)) - { - nm_warning ("%s raised '%s'", error.name, error.message); - goto out; - } - - if (!reply) - { - nm_warning ("Reply was NULL."); - goto out; - } - - /* FIXME: These argument types need to be validated - */ - - dbus_message_iter_init (reply, &iter); - - if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) - { - nm_warning ("Reply had wrong arguments: " - "(expected %u, got %u)\n", DBUS_TYPE_STRING, - dbus_message_iter_get_arg_type (&iter)); - goto out; - } - dbus_message_iter_get_basic (&iter, &essid); - - dbus_message_iter_next (&iter); - if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) - { - nm_warning ("Reply had wrong arguments: " - "(expected %u, got %u)\n", DBUS_TYPE_INT32, - dbus_message_iter_get_arg_type (&iter)); - goto out; - } - dbus_message_iter_get_basic (&iter, &i); - - timestamp_secs = (gint32) i; - - dbus_message_iter_next (&iter); - if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) - { - nm_warning ("Reply had wrong arguments: " - "(expected %u, got %u)\n", DBUS_TYPE_STRING, - dbus_message_iter_get_arg_type (&iter)); - goto out; - } - dbus_message_iter_get_basic (&iter, &key); - - dbus_message_iter_next (&iter); - if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) - { - nm_warning ("Reply had wrong arguments: " - "(expected %u, got %u)\n", DBUS_TYPE_INT32, - dbus_message_iter_get_arg_type (&iter)); - goto out; - } - dbus_message_iter_get_basic (&iter, &i); - - key_type = (NMEncKeyType) i; - - dbus_message_iter_next (&iter); - if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) - { - nm_warning ("Reply had wrong arguments: " - "(expected %u, got %u)\n", DBUS_TYPE_INT32, - dbus_message_iter_get_arg_type (&iter)); - goto out; - } - dbus_message_iter_get_basic (&iter, &i); - - auth_method = (NMDeviceAuthMethod) i; - - dbus_message_iter_next (&iter); - if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_BOOLEAN) - { - nm_warning ("Reply had wrong arguments: " - "(expected %u, got %u)\n", DBUS_TYPE_BOOLEAN, - dbus_message_iter_get_arg_type (&iter)); - goto out; - } - dbus_message_iter_get_basic (&iter, &trusted); - - dbus_message_iter_next (&iter); - if (timestamp_secs > 0) - { - GTimeVal *timestamp = g_new0 (GTimeVal, 1); - - ap = nm_ap_new (); - nm_ap_set_essid (ap, essid); - - timestamp->tv_sec = timestamp_secs; - timestamp->tv_usec = 0; - nm_ap_set_timestamp (ap, timestamp); - g_free (timestamp); - - nm_ap_set_trusted (ap, trusted); - - if (key && strlen (key)) - nm_ap_set_enc_key_source (ap, key, key_type); - else - nm_ap_set_enc_key_source (ap, NULL, NM_ENC_TYPE_UNKNOWN); - nm_ap_set_auth_method (ap, auth_method); - - /* Get user addresses, form into a GSList, and stuff into the AP */ - if (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_ARRAY) - { - GSList *addr_list; - DBusMessageIter array_iter; - - dbus_message_iter_recurse (&iter, &array_iter); - - addr_list = NULL; - while (dbus_message_iter_get_arg_type (&array_iter) == DBUS_TYPE_STRING) - { - const gchar *addr; - - dbus_message_iter_get_basic (&array_iter, &addr); - - if ((addr != NULL) && (strlen (addr) >= 11)) - addr_list = g_slist_prepend (addr_list, g_strdup (addr)); - else - nm_warning ("Expected hardware address, got '%s'", - addr); - - dbus_message_iter_next (&array_iter); - } - - if (dbus_message_iter_get_arg_type (&array_iter) != DBUS_TYPE_INVALID) - { - nm_warning ("Reply had wrong arguments: " - "(expected %u, got %u)", DBUS_TYPE_INVALID, - dbus_message_iter_get_arg_type (&array_iter)); - - g_slist_foreach (addr_list, (GFunc) g_free, NULL); - g_slist_free (addr_list); - - goto out; - } - - addr_list = g_slist_reverse (addr_list); - nm_ap_set_user_addresses (ap, addr_list); - - g_slist_foreach (addr_list, (GFunc) g_free, NULL); - g_slist_free (addr_list); - } - } - -out: - - if (reply) - dbus_message_unref (reply); - - return (ap); -} - - /* * nm_dbus_update_network_auth_method * @@ -756,34 +680,23 @@ out: */ gboolean nm_dbus_update_network_auth_method (DBusConnection *connection, const char *network, const NMDeviceAuthMethod auth_method) { - DBusMessage *message; - DBusError error; - gboolean success = FALSE; - dbus_int32_t auth_method_as_int32; + DBusMessage * message; + gboolean success = FALSE; + dbus_int32_t auth_method_as_int32 = (dbus_int32_t) auth_method; g_return_val_if_fail (connection != NULL, FALSE); g_return_val_if_fail (network != NULL, FALSE); g_return_val_if_fail (auth_method != NM_DEVICE_AUTH_METHOD_UNKNOWN, FALSE); - message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "updateNetworkAuthMethod"); - if (!message) + if (!(message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "updateNetworkAuthMethod"))) { nm_warning ("nm_dbus_update_network_auth_method (): Couldn't allocate the dbus message"); return (FALSE); } - auth_method_as_int32 = (dbus_int32_t) auth_method; - dbus_message_append_args (message, DBUS_TYPE_STRING, &network, - DBUS_TYPE_INT32, &auth_method, - DBUS_TYPE_INVALID); - - /* Send message and get trusted status back from NetworkManagerInfo */ - dbus_error_init (&error); + dbus_message_append_args (message, DBUS_TYPE_STRING, &network, DBUS_TYPE_INT32, &auth_method, DBUS_TYPE_INVALID); if (!dbus_connection_send (connection, message, NULL)) - { nm_warning ("nm_dbus_update_network_auth_method (): failed to send dbus message."); - dbus_error_free (&error); - } else success = TRUE; @@ -803,20 +716,17 @@ gboolean nm_dbus_update_network_auth_method (DBusConnection *connection, const c */ gboolean nm_dbus_add_network_address (DBusConnection *connection, NMNetworkType type, const char *network, struct ether_addr *addr) { - DBusMessage *message; - DBusError error; - gboolean success = FALSE; - gchar *char_addr; - dbus_int32_t type_as_int32; + DBusMessage * message; + gboolean success = FALSE; + gchar * char_addr; + dbus_int32_t type_as_int32 = (dbus_int32_t) type; g_return_val_if_fail (connection != NULL, FALSE); g_return_val_if_fail (network != NULL, FALSE); g_return_val_if_fail (type != NETWORK_TYPE_UNKNOWN, FALSE); g_return_val_if_fail (addr != NULL, FALSE); - message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, - NMI_DBUS_INTERFACE, "addNetworkAddress"); - if (!message) + if (!(message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "addNetworkAddress"))) { nm_warning ("nm_dbus_add_network_ap_mac_address(): Couldn't allocate the dbus message"); return (FALSE); @@ -824,21 +734,14 @@ gboolean nm_dbus_add_network_address (DBusConnection *connection, NMNetworkType char_addr = g_new0 (gchar, 20); ether_ntoa_r (addr, char_addr); - - type_as_int32 = (dbus_int32_t) type; dbus_message_append_args (message, DBUS_TYPE_STRING, &network, DBUS_TYPE_INT32, &type_as_int32, DBUS_TYPE_STRING, &char_addr, DBUS_TYPE_INVALID); g_free (char_addr); - /* Send message and get trusted status back from NetworkManagerInfo */ - dbus_error_init (&error); if (!dbus_connection_send (connection, message, NULL)) - { nm_warning ("nm_dbus_add_network_ap_mac_address(): failed to send dbus message."); - dbus_error_free (&error); - } else success = TRUE; @@ -847,86 +750,288 @@ gboolean nm_dbus_add_network_address (DBusConnection *connection, NMNetworkType } +typedef struct GetOneNetworkCBData +{ + NMData * data; + char * network; + NMAccessPointList * list; +} GetOneNetworkCBData; + + +void free_get_one_network_cb_data (GetOneNetworkCBData *data) +{ + if (data) + { + nm_ap_list_unref (data->list); + g_free (data->network); + data->list = NULL; + data->network = NULL; + data->data = NULL; + g_free (data); + } +} + +typedef struct GetNetworksCBData +{ + NMData * data; + NMAccessPointList * list; +} GetNetworksCBData; + + +void free_get_networks_cb_data (GetNetworksCBData *data) +{ + if (data) + { + nm_ap_list_unref (data->list); + data->data = NULL; + data->list = NULL; + g_free (data); + } +} + /* - * nm_dbus_get_networks + * nm_dbus_get_network_data_cb * - * Get all networks of a specific type from NetworkManagerInfo - * - * NOTE: caller MUST free returned value using g_strfreev() + * Add a new NMAccessPoint to the allowed list with the correct properties * */ -char ** nm_dbus_get_networks (DBusConnection *connection, NMNetworkType type, int *num_networks) +void nm_dbus_get_network_data_cb (DBusPendingCall *pcall, void *user_data) { - DBusMessage *message; - DBusError error; - DBusMessage *reply; - char **networks = NULL; - dbus_int32_t type_as_int32; + GetOneNetworkCBData * cb_data = (GetOneNetworkCBData *)user_data; + DBusMessage * reply; + DBusError error; + const char * essid = NULL; + gint timestamp_secs = -1; + const char * key = NULL; + NMEncKeyType key_type = -1; + gboolean trusted = FALSE; + NMDeviceAuthMethod auth_method = NM_DEVICE_AUTH_METHOD_UNKNOWN; + char ** addresses; + int num_addresses; - *num_networks = 0; - g_return_val_if_fail (connection != NULL, NULL); - g_return_val_if_fail (type != NETWORK_TYPE_UNKNOWN, NULL); + g_return_if_fail (pcall != NULL); + g_return_if_fail (cb_data != NULL); + g_return_if_fail (cb_data->data != NULL); + g_return_if_fail (cb_data->network != NULL); + g_return_if_fail (cb_data->list != NULL); - message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, - NMI_DBUS_INTERFACE, "getNetworks"); - if (!message) + dbus_pending_call_ref (pcall); + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (dbus_message_is_error (reply, "BadNetworkData")) { - nm_warning ("nm_dbus_get_networks(): Couldn't allocate the dbus message"); - return (NULL); - } - - type_as_int32 = (dbus_int32_t) type; - dbus_message_append_args (message, DBUS_TYPE_INT32, &type_as_int32, DBUS_TYPE_INVALID); - - /* Send message and get essid back from NetworkManagerInfo */ - dbus_error_init (&error); - reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error); - dbus_message_unref (message); - if (dbus_error_is_set (&error)) - nm_warning ("nm_dbus_get_networks(): %s raised %s", error.name, error.message); - else if (!reply) - nm_info ("nm_dbus_get_networks(): reply was NULL."); - else - { - DBusMessageIter iter, array_iter; - GArray *buffer; - - dbus_message_iter_init (reply, &iter); - dbus_message_iter_recurse (&iter, &array_iter); - - buffer = g_array_new (TRUE, TRUE, sizeof (gchar *)); - - if (buffer == NULL) - return NULL; - - while (dbus_message_iter_get_arg_type (&array_iter) == DBUS_TYPE_STRING) - { - const char *value; - char *str; - - dbus_message_iter_get_basic (&array_iter, &value); - str = g_strdup (value); - - if (str == NULL) - { - g_array_free (buffer, TRUE); - return NULL; - } - - g_array_append_val (buffer, str); - - dbus_message_iter_next(&array_iter); - } - networks = (gchar **)(buffer->data); - if (num_networks != NULL) - *num_networks = buffer->len; - g_array_free (buffer, FALSE); - } - - if (reply) dbus_message_unref (reply); + nm_ap_list_remove_ap_by_essid (cb_data->list, cb_data->network); + goto out; + } - return (networks); + dbus_error_init (&error); + if (dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &essid, + DBUS_TYPE_INT32, ×tamp_secs, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_INT32, &key_type, + DBUS_TYPE_INT32, &auth_method, + DBUS_TYPE_BOOLEAN, &trusted, + DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &addresses, &num_addresses, + DBUS_TYPE_INVALID)) + { + if (timestamp_secs > 0) + { + NMAccessPoint * ap; + NMAccessPoint * list_ap; + GTimeVal * timestamp = g_new0 (GTimeVal, 1); + GSList * addr_list = NULL; + int i; + + ap = nm_ap_new (); + nm_ap_set_essid (ap, essid); + + timestamp->tv_sec = timestamp_secs; + timestamp->tv_usec = 0; + nm_ap_set_timestamp (ap, timestamp); + g_free (timestamp); + + nm_ap_set_trusted (ap, trusted); + + if (key && strlen (key)) + nm_ap_set_enc_key_source (ap, key, key_type); + else + nm_ap_set_enc_key_source (ap, NULL, NM_ENC_TYPE_UNKNOWN); + nm_ap_set_auth_method (ap, auth_method); + + for (i = 0; i < num_addresses; i++) + if (strlen (addresses[i]) >= 11) + addr_list = g_slist_append (addr_list, g_strdup (addresses[i])); + nm_ap_set_user_addresses (ap, addr_list); + + if ((list_ap = nm_ap_list_get_ap_by_essid (cb_data->list, essid))) + { + nm_ap_set_essid (list_ap, nm_ap_get_essid (ap)); + nm_ap_set_timestamp (list_ap, nm_ap_get_timestamp (ap)); + nm_ap_set_trusted (list_ap, nm_ap_get_trusted (ap)); + nm_ap_set_enc_key_source (list_ap, nm_ap_get_enc_key_source (ap), nm_ap_get_enc_type (ap)); + nm_ap_set_auth_method (list_ap, nm_ap_get_auth_method (ap)); + nm_ap_set_user_addresses (list_ap, nm_ap_get_user_addresses (ap)); + } + else + { + /* New AP, just add it to the list */ + nm_ap_list_append_ap (cb_data->list, ap); + } + nm_ap_unref (ap); + + /* Ensure all devices get new information copied into their device lists */ + nm_policy_schedule_device_ap_lists_update_from_allowed (cb_data->data); + } + dbus_free_string_array (addresses); + } + dbus_message_unref (reply); + +out: + dbus_pending_call_unref (pcall); +} + + +/* + * nm_dbus_get_networks_cb + * + * Async callback from nm_dbus_get_networks + * + */ +void nm_dbus_get_networks_cb (DBusPendingCall *pcall, void *user_data) +{ + DBusMessage * reply; + DBusMessageIter iter, array_iter; + GetNetworksCBData * cb_data = (GetNetworksCBData *)user_data; + + g_return_if_fail (pcall); + g_return_if_fail (cb_data != NULL); + g_return_if_fail (cb_data->list != NULL); + g_return_if_fail (cb_data->data != NULL); + + dbus_pending_call_ref (pcall); + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (message_is_error (reply)) + goto out; + + dbus_message_iter_init (reply, &iter); + dbus_message_iter_recurse (&iter, &array_iter); + while (dbus_message_iter_get_arg_type (&array_iter) == DBUS_TYPE_STRING) + { + const char * value; + DBusMessage * message; + + dbus_message_iter_get_basic (&array_iter, &value); + + /* Get properties on each network */ + if ((message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "getNetworkProperties"))) + { + dbus_int32_t type_as_int32 = (dbus_int32_t) nm_ap_list_get_type (cb_data->list); + DBusPendingCall * net_pcall = NULL; + + dbus_message_append_args (message, DBUS_TYPE_STRING, &value, DBUS_TYPE_INT32, &type_as_int32, DBUS_TYPE_INVALID); + dbus_connection_send_with_reply (cb_data->data->dbus_connection, message, &net_pcall, -1); + dbus_message_unref (message); + if (net_pcall) + { + GetOneNetworkCBData * net_cb_data = g_malloc0 (sizeof (GetOneNetworkCBData)); + + net_cb_data->data = cb_data->data; + net_cb_data->network = g_strdup (value); + nm_ap_list_ref (cb_data->list); + net_cb_data->list = cb_data->list; + + dbus_pending_call_set_notify (net_pcall, nm_dbus_get_network_data_cb, net_cb_data, (DBusFreeFunction) free_get_one_network_cb_data); + } + } + + dbus_message_iter_next(&array_iter); + } + dbus_message_unref (reply); + +out: + dbus_pending_call_unref (pcall); +} + + +/* + * nm_dbus_update_allowed_networks + * + * Update all allowed networks from NetworkManagerInfo + * + */ +void nm_dbus_update_allowed_networks (DBusConnection *connection, NMAccessPointList *list, NMData *data) +{ + DBusMessage * message; + dbus_int32_t type_as_int32 = (dbus_int32_t) nm_ap_list_get_type (list); + DBusPendingCall * pcall = NULL; + + g_return_if_fail (connection != NULL); + g_return_if_fail (list != NULL); + g_return_if_fail (data != NULL); + + if (!(message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "getNetworks"))) + return; + + dbus_message_append_args (message, DBUS_TYPE_INT32, &type_as_int32, DBUS_TYPE_INVALID); + dbus_connection_send_with_reply (connection, message, &pcall, -1); + dbus_message_unref (message); + if (pcall) + { + GetNetworksCBData * cb_data = g_malloc0 (sizeof (GetNetworksCBData)); + + cb_data->data = data; + nm_ap_list_ref (list); + cb_data->list = list; + dbus_pending_call_set_notify (pcall, nm_dbus_get_networks_cb, cb_data, (DBusFreeFunction) free_get_networks_cb_data); + } +} + + +/* + * nm_dbus_update_one_allowed_network + * + * Update all networks of a specific type from NetworkManagerInfo + * + */ +static void nm_dbus_update_one_allowed_network (DBusConnection *connection, const char *network, NMData *data) +{ + DBusMessage * message; + dbus_int32_t type_as_int32 = NETWORK_TYPE_ALLOWED; + DBusPendingCall * pcall = NULL; + GetOneNetworkCBData * cb_data = NULL; + + g_return_if_fail (connection != NULL); + g_return_if_fail (data != NULL); + + if (!(message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "getNetworkProperties"))) + { + nm_warning ("nm_dbus_update_one_allowed_network(): Couldn't allocate the dbus message"); + return; + } + + cb_data = g_malloc0 (sizeof (GetOneNetworkCBData)); + cb_data->data = data; + cb_data->network = g_strdup (network); + + dbus_message_append_args (message, DBUS_TYPE_STRING, &network, DBUS_TYPE_INT32, &type_as_int32, DBUS_TYPE_INVALID); + dbus_connection_send_with_reply (connection, message, &pcall, -1); + dbus_message_unref (message); + if (!pcall) + nm_warning ("nm_dbus_update_one_allowed_network(): pending call was NULL"); + else + dbus_pending_call_set_notify (pcall, nm_dbus_get_network_data_cb, cb_data, (DBusFreeFunction) free_get_one_network_cb_data); } @@ -986,7 +1091,7 @@ static DBusHandlerResult nm_dbus_signal_filter (DBusConnection *connection, DBus { /* Update a single wireless network's data */ nm_debug ("NetworkManagerInfo triggered update of wireless network '%s'", network); - nm_ap_list_update_network_from_nmi (data->allowed_ap_list, network, data); + nm_dbus_update_one_allowed_network (connection, network, data); handled = TRUE; } } @@ -997,13 +1102,8 @@ static DBusHandlerResult nm_dbus_signal_filter (DBusConnection *connection, DBus if (dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) { - NMVPNConnection *vpn; - - /* Update a single VPN connection's data */ nm_debug ("NetworkManagerInfo triggered update of VPN connection '%s'", name); - vpn = nm_dbus_vpn_add_one_connection (data->dbus_connection, name, data->vpn_manager); - if (vpn) - nm_dbus_vpn_signal_vpn_connection_update (data->dbus_connection, vpn); + nm_dbus_vpn_update_one_vpn_connection (data->dbus_connection, name, data); handled = TRUE; } } @@ -1242,7 +1342,7 @@ DBusConnection *nm_dbus_init (NMData *data) goto out; } - dbus_connection_set_exit_on_disconnect (connection, FALSE); +// dbus_connection_set_exit_on_disconnect (connection, FALSE); dbus_connection_setup_with_g_main (connection, data->main_context); data->nm_methods = nm_dbus_nm_methods_setup (); diff --git a/src/NetworkManagerDbus.h b/src/NetworkManagerDbus.h index 9df3a2313..e1ebb99d3 100644 --- a/src/NetworkManagerDbus.h +++ b/src/NetworkManagerDbus.h @@ -36,21 +36,32 @@ typedef enum DEVICE_ACTIVATING, DEVICE_ACTIVATION_FAILED, DEVICE_ACTIVATION_CANCELED, - DEVICE_LIST_CHANGE, - DEVICE_STATUS_CHANGE + DEVICE_ADDED, + DEVICE_REMOVED } DeviceStatus; +static inline gboolean message_is_error (DBusMessage *msg) +{ + g_return_val_if_fail (msg != NULL, FALSE); + + return (dbus_message_get_type (msg) == DBUS_MESSAGE_TYPE_ERROR); +} + + DBusConnection *nm_dbus_init (NMData *data); gboolean nm_dbus_is_info_daemon_running (DBusConnection *connection); +char * nm_dbus_get_object_path_for_device (NMDevice *dev); +char * nm_dbus_get_object_path_for_network (NMDevice *dev, NMAccessPoint *ap); + void nm_dbus_schedule_device_status_change (NMDevice *dev, DeviceStatus status); void nm_dbus_signal_device_status_change (DBusConnection *connection, NMDevice *dev, DeviceStatus status); void nm_dbus_schedule_network_not_found_signal (NMData *data, const char *network); -void nm_dbus_signal_network_status_change (DBusConnection *connection, NMData *data); +void nm_dbus_signal_state_change (DBusConnection *connection, NMData *data); void nm_dbus_signal_device_ip4_address_change(DBusConnection *connection, NMDevice *dev); @@ -68,14 +79,14 @@ gboolean nm_dbus_update_network_auth_method (DBusConnection *connection, const gboolean nm_dbus_nmi_is_running (DBusConnection *connection); -char ** nm_dbus_get_networks (DBusConnection *connection, NMNetworkType type, int *num_networks); +void nm_dbus_update_allowed_networks (DBusConnection *connection, NMAccessPointList *list, NMData *data); DBusMessage * nm_dbus_create_error_message (DBusMessage *message, const char *exception_namespace, const char *exception, const char *format, ...); NMDevice * nm_dbus_get_device_from_object_path (NMData *data, const char *path); -char * nm_dbus_network_status_from_data (NMData *data); +NMState nm_get_app_state_from_data (NMData *data); DBusMessage * nm_dbus_create_error_message (DBusMessage *message, const char *exception_namespace, const char *exception, const char *format, ...); diff --git a/src/NetworkManagerDevice.c b/src/NetworkManagerDevice.c index 3ec536b78..60b19adc9 100644 --- a/src/NetworkManagerDevice.c +++ b/src/NetworkManagerDevice.c @@ -152,8 +152,7 @@ NMDevice *nm_get_device_by_udi (NMData *data, const char *udi) for (elt = data->dev_list; elt; elt = g_slist_next (elt)) { - dev = (NMDevice *)(elt->data); - if (dev) + if ((dev = (NMDevice *)(elt->data))) { if (nm_null_safe_strcmp (nm_device_get_udi (dev), udi) == 0) break; @@ -674,8 +673,6 @@ void nm_device_set_link_active (NMDevice *dev, const gboolean link_active) if (dev->link_active != link_active) { dev->link_active = link_active; - - nm_dbus_schedule_device_status_change (dev, DEVICE_STATUS_CHANGE); nm_policy_schedule_state_update (dev->app_data); } } @@ -702,7 +699,7 @@ void nm_device_set_now_scanning (NMDevice *dev, const gboolean now_scanning) old_val = nm_device_get_now_scanning (dev); dev->options.wireless.now_scanning = now_scanning; if (old_val != now_scanning) - nm_dbus_schedule_device_status_change (dev, DEVICE_STATUS_CHANGE); + nm_schedule_state_change_signal_broadcast (dev->app_data); } @@ -757,6 +754,7 @@ static gboolean nm_device_wireless_is_associated (NMDevice *dev) /* Some cards, for example ipw2x00 cards, can short-circuit the MAC * address check using this check on IWNAME. Its faster. */ + memset (&wrq, 0, sizeof (struct iwreq)); if (iw_get_ext (nm_dev_sock_get_fd (sk), nm_device_get_iface (dev), SIOCGIWNAME, &wrq) >= 0) { if (!strcmp(wrq.u.name, "unassociated")) @@ -1372,6 +1370,8 @@ void nm_device_update_signal_strength (NMDevice *dev) if ((sk = nm_dev_sock_open (dev, DEV_WIRELESS, __FUNCTION__, NULL))) { + memset (&range, 0, sizeof (iwrange)); + memset (&stats, 0, sizeof (iwstats)); has_range = (iw_get_range_info (nm_dev_sock_get_fd (sk), nm_device_get_iface (dev), &range) >= 0); if (iw_get_stats (nm_dev_sock_get_fd (sk), nm_device_get_iface (dev), &stats, &range, has_range) == 0) { @@ -1575,11 +1575,11 @@ gboolean nm_completion_device_is_up_test(int tries, va_list args) gboolean *err = va_arg(args, gboolean *); gboolean cancelable = va_arg(args, gboolean); - g_return_val_if_fail(dev != NULL, TRUE); - g_return_val_if_fail(err != NULL, TRUE); + g_return_val_if_fail (dev != NULL, TRUE); + g_return_val_if_fail (err != NULL, TRUE); *err = FALSE; - if (cancelable && nm_device_activation_handle_cancel(dev)) { + if (cancelable && nm_device_activation_handle_cancel (dev)) { *err = TRUE; return TRUE; } @@ -1617,17 +1617,17 @@ void nm_device_bring_down (NMDevice *dev) nm_device_set_up_down (dev, FALSE); } -gboolean nm_completion_device_is_down_test(int tries, va_list args) +gboolean nm_completion_device_is_down_test (int tries, va_list args) { NMDevice *dev = va_arg(args, NMDevice *); gboolean *err = va_arg(args, gboolean *); gboolean cancelable = va_arg(args, gboolean); - g_return_val_if_fail(dev != NULL, TRUE); - g_return_val_if_fail(err != NULL, TRUE); + g_return_val_if_fail (dev != NULL, TRUE); + g_return_val_if_fail (err != NULL, TRUE); *err = FALSE; - if (cancelable && nm_device_activation_handle_cancel(dev)) { + if (cancelable && nm_device_activation_handle_cancel (dev)) { *err = TRUE; return TRUE; } @@ -1672,6 +1672,7 @@ NMNetworkMode nm_device_get_mode (NMDevice *dev) struct iwreq wrq; int err; + memset (&wrq, 0, sizeof (struct iwreq)); if (iw_get_ext (nm_dev_sock_get_fd (sk), nm_device_get_iface (dev), SIOCGIWMODE, &wrq) == 0) { switch (wrq.u.mode) @@ -1818,6 +1819,7 @@ gboolean nm_device_activation_schedule_start (NMDevice *dev) g_source_attach (source, dev->context); g_source_unref (source); + nm_schedule_state_change_signal_broadcast (data); nm_dbus_signal_device_status_change (data->dbus_connection, dev, DEVICE_ACTIVATING); return (TRUE); @@ -1835,7 +1837,7 @@ static gboolean nm_device_activation_handle_cancel (NMDevice *dev) { g_return_val_if_fail (dev != NULL, TRUE); - /* If we were told to quit activation, stop the thread and return */ + /* If we were told to quit activation, stop activation and return */ if (dev->quit_activation) { nm_debug ("activation of device '%s' canceled.", nm_device_get_iface (dev)); @@ -1943,8 +1945,8 @@ static gboolean nm_device_link_test(int tries, va_list args) NMDevice *dev = va_arg(args, NMDevice *); gboolean *err = va_arg(args, gboolean *); - g_return_val_if_fail(dev != NULL, TRUE); - g_return_val_if_fail(err != NULL, TRUE); + g_return_val_if_fail (dev != NULL, TRUE); + g_return_val_if_fail (err != NULL, TRUE); if (nm_device_wireless_is_associated (dev) && nm_device_get_essid (dev)) { @@ -2235,12 +2237,12 @@ static gboolean nm_wa_test (int tries, va_list args) NMAccessPoint **best_ap = va_arg (args, NMAccessPoint **); gboolean *err = va_arg (args, gboolean *); - g_return_val_if_fail(dev != NULL, TRUE); - g_return_val_if_fail(best_ap != NULL, TRUE); - g_return_val_if_fail(err != NULL, TRUE); + g_return_val_if_fail (dev != NULL, TRUE); + g_return_val_if_fail (best_ap != NULL, TRUE); + g_return_val_if_fail (err != NULL, TRUE); *err = TRUE; - if (nm_device_activation_handle_cancel(dev)) + if (nm_device_activation_handle_cancel (dev)) return TRUE; if (tries % 100 == 0) @@ -2249,11 +2251,9 @@ static gboolean nm_wa_test (int tries, va_list args) *best_ap = nm_device_get_best_ap(dev); if (*best_ap) { - /* Set ESSID early so that when we send out the - * DeviceStatusChanged signal below, we are able to - * respond correctly to queries for "getActiveNetwork" - * against our device. nm_device_get_path_for_ap() uses - * the /card's/ AP, not the best_ap. */ + /* Set ESSID early so that when we send out the DeviceStatusChanged signal below, we are able to + * respond correctly to queries for "getActiveNetwork" against our device. + */ nm_device_set_essid (dev, nm_ap_get_essid (*best_ap)); nm_device_set_now_scanning (dev, FALSE); *err = FALSE; @@ -2757,6 +2757,7 @@ void nm_device_activation_cancel (NMDevice *dev) nm_wait_for_completion(NM_COMPLETION_TRIES_INFINITY, G_USEC_PER_SEC / 20, nm_ac_test, NULL, dev); nm_debug ("Activation (%s/wireless): cancelled.", nm_device_get_iface(dev)); + nm_schedule_state_change_signal_broadcast (dev->app_data); } } @@ -2822,7 +2823,7 @@ gboolean nm_device_deactivate (NMDevice *dev, gboolean just_added) * */ void nm_device_set_user_key_for_network (NMDevice *dev, NMAccessPointList *invalid_list, - unsigned char *network, unsigned char *key, + NMAccessPoint *ap, unsigned char *key, NMEncKeyType enc_type) { NMAccessPoint *best_ap; @@ -2830,20 +2831,16 @@ void nm_device_set_user_key_for_network (NMDevice *dev, NMAccessPointList *inval g_return_if_fail (dev != NULL); g_return_if_fail (nm_device_is_wireless (dev)); - g_return_if_fail (network != NULL); + g_return_if_fail (ap != NULL); g_return_if_fail (key != NULL); /* If the user canceled, mark the ap as invalid */ if (strncmp (key, cancel_message, strlen (cancel_message)) == 0) { - NMAccessPoint *ap; + NMAccessPoint *invalid_ap = nm_ap_new_from_ap (ap); - if ((ap = nm_device_ap_list_get_ap_by_essid (dev, network))) - { - NMAccessPoint *invalid_ap = nm_ap_new_from_ap (ap); - if (invalid_list) - nm_ap_list_append_ap (invalid_list, invalid_ap); - } + if (invalid_list) + nm_ap_list_append_ap (invalid_list, invalid_ap); nm_device_update_best_ap (dev); } @@ -2852,7 +2849,7 @@ void nm_device_set_user_key_for_network (NMDevice *dev, NMAccessPointList *inval /* Make sure the "best" ap matches the essid we asked for the key of, * then set the new key on the access point. */ - if (nm_null_safe_strcmp (network, nm_ap_get_essid (best_ap)) == 0) + if (nm_null_safe_strcmp (nm_ap_get_essid (ap), nm_ap_get_essid (best_ap)) == 0) nm_ap_set_enc_key_source (best_ap, key, enc_type); nm_ap_unref (best_ap); @@ -2944,6 +2941,44 @@ NMAccessPoint *nm_device_ap_list_get_ap_by_address (NMDevice *dev, const struct } +/* + * nm_device_ap_list_get_ap_by_obj_path + * + * Get the access point for a dbus object path. Requires an _unescaped_ + * object path. + * + */ +NMAccessPoint *nm_device_ap_list_get_ap_by_obj_path (NMDevice *dev, const char *obj_path) +{ + NMAccessPoint * ret_ap = NULL; + char * built_path; + char * dev_path; + + g_return_val_if_fail (dev != NULL, NULL); + g_return_val_if_fail (nm_device_is_wireless (dev), NULL); + g_return_val_if_fail (obj_path != NULL, NULL); + + if (!dev->options.wireless.ap_list) + return (NULL); + + dev_path = nm_dbus_get_object_path_for_device (dev); + dev_path = nm_dbus_unescape_object_path (dev_path); + built_path = g_strdup_printf ("%s/Networks/", dev_path); + g_free (dev_path); + + if (strncmp (built_path, obj_path, strlen (built_path)) == 0) + { + char *essid = g_strdup (obj_path + strlen (built_path)); + + ret_ap = nm_ap_list_get_ap_by_essid (dev->options.wireless.ap_list, essid); + g_free (essid); + } + g_free (built_path); + + return (ret_ap); +} + + /* * nm_device_ap_list_get * @@ -3055,33 +3090,6 @@ void nm_device_set_dhcp_iface (NMDevice *dev, struct dhcp_interface *dhcp_iface) } -/* - * nm_device_get_path_for_ap - * - * Return the object path for an access point. - * - * NOTE: assumes the access point is actually in the device's access point list. - * - */ -char * nm_device_get_path_for_ap (NMDevice *dev, NMAccessPoint *ap) -{ - g_return_val_if_fail (dev != NULL, NULL); - g_return_val_if_fail (ap != NULL, NULL); - - if (nm_ap_get_essid (ap)) - { - char *path, *escaped_path; - - path = g_strdup_printf ("%s/%s/Networks/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (dev), nm_ap_get_essid (ap)); - escaped_path = nm_dbus_escape_object_path (path); - g_free (path); - - return (escaped_path); - } else - return (NULL); -} - - /* * nm_device_need_ap_switch * diff --git a/src/NetworkManagerDevice.h b/src/NetworkManagerDevice.h index 9369f5c6b..4e239b31e 100644 --- a/src/NetworkManagerDevice.h +++ b/src/NetworkManagerDevice.h @@ -96,8 +96,6 @@ void nm_device_unfreeze_best_ap (NMDevice *dev); gboolean nm_device_is_best_ap_frozen (NMDevice *dev); struct dhcp_interface *nm_device_get_dhcp_iface (NMDevice *dev); -char * nm_device_get_path_for_ap (NMDevice *dev, NMAccessPoint *ap); - /* There is no function to get the WEP key since that's a slight security risk */ void nm_device_set_enc_key (NMDevice *dev, const char *key, NMDeviceAuthMethod auth_method); @@ -111,9 +109,8 @@ gboolean nm_device_get_now_scanning (NMDevice *dev); void nm_device_schedule_force_use (NMDevice *dev, const char *network, const char *key, NMEncKeyType key_type); -void nm_device_set_user_key_for_network (NMDevice *dev, struct NMAccessPointList *invalid_list, - unsigned char *network, unsigned char *key, - NMEncKeyType enc_type); +void nm_device_set_user_key_for_network (NMDevice *dev, struct NMAccessPointList *invalid_list, NMAccessPoint *ap, + unsigned char *key, NMEncKeyType enc_type); void nm_device_bring_up (NMDevice *dev); void nm_device_bring_down (NMDevice *dev); @@ -123,6 +120,7 @@ void nm_device_ap_list_clear (NMDevice *dev); struct NMAccessPointList *nm_device_ap_list_get (NMDevice *dev); NMAccessPoint *nm_device_ap_list_get_ap_by_essid (NMDevice *dev, const char *essid); NMAccessPoint *nm_device_ap_list_get_ap_by_address(NMDevice *dev, const struct ether_addr *addr); +NMAccessPoint *nm_device_ap_list_get_ap_by_obj_path(NMDevice *dev, const char *obj_path); void nm_device_copy_allowed_to_dev_list (NMDevice *dev, struct NMAccessPointList *allowed_list); gboolean nm_device_get_use_dhcp (NMDevice *dev); diff --git a/src/NetworkManagerMain.h b/src/NetworkManagerMain.h index 76a9327f1..49ded8095 100644 --- a/src/NetworkManagerMain.h +++ b/src/NetworkManagerMain.h @@ -77,11 +77,11 @@ typedef struct NMData } NMData; -struct NMDevice *nm_create_device_and_add_to_list (NMData *data, const char *udi, const char *iface, - gboolean test_device, NMDeviceType test_device_type); +struct NMDevice *nm_create_device_and_add_to_list (NMData *data, const char *udi, const char *iface, + gboolean test_device, NMDeviceType test_device_type); -void nm_remove_device_from_list (NMData *data, const char *udi); +void nm_remove_device_from_list (NMData *data, const char *udi); -void nm_schedule_status_signal_broadcast (NMData *data); +void nm_schedule_state_change_signal_broadcast (NMData *data); #endif diff --git a/src/NetworkManagerPolicy.c b/src/NetworkManagerPolicy.c index 174292543..990054c9f 100644 --- a/src/NetworkManagerPolicy.c +++ b/src/NetworkManagerPolicy.c @@ -309,6 +309,7 @@ gboolean nm_policy_activation_finish (gpointer user_data) break; } + nm_schedule_state_change_signal_broadcast (data); nm_policy_schedule_state_update (data); out: @@ -325,7 +326,7 @@ typedef struct NMStateUpdateData /* - * nm_state_modification_monitor + * nm_policy_state_update * * Figures out which interface to switch the active * network connection to if our global network state has changed. @@ -475,6 +476,7 @@ void nm_policy_schedule_device_switch (NMDevice *switch_to_dev, NMData *app_data } +static gboolean allowed_list_update_pending = FALSE; /* * nm_policy_allowed_ap_list_update @@ -488,6 +490,8 @@ static gboolean nm_policy_allowed_ap_list_update (gpointer user_data) NMData *data = (NMData *)user_data; GSList *elt; + allowed_list_update_pending = FALSE; + g_return_val_if_fail (data != NULL, FALSE); nm_info ("Updating allowed wireless network lists."); @@ -495,9 +499,61 @@ static gboolean nm_policy_allowed_ap_list_update (gpointer user_data) /* Query info daemon for network lists if its now running */ if (data->allowed_ap_list) nm_ap_list_unref (data->allowed_ap_list); - data->allowed_ap_list = nm_ap_list_new (NETWORK_TYPE_ALLOWED); - if (data->allowed_ap_list) - nm_ap_list_populate_from_nmi (data->allowed_ap_list, data); + if ((data->allowed_ap_list = nm_ap_list_new (NETWORK_TYPE_ALLOWED))) + nm_dbus_update_allowed_networks (data->dbus_connection, data->allowed_ap_list, data); + + return (FALSE); +} + + +/* + * nm_policy_schedule_allowed_ap_list_update + * + * Schedule an update of the allowed AP list in the main thread. + * + */ +void nm_policy_schedule_allowed_ap_list_update (NMData *app_data) +{ + static GStaticMutex mutex = G_STATIC_MUTEX_INIT; + + g_return_if_fail (app_data != NULL); + g_return_if_fail (app_data->main_context != NULL); + + g_static_mutex_lock (&mutex); + + if (allowed_list_update_pending == FALSE) + { + GSource *source = g_idle_source_new (); + /* We want this idle source to run before any other idle source */ + g_source_set_priority (source, G_PRIORITY_HIGH_IDLE); + g_source_set_callback (source, nm_policy_allowed_ap_list_update, app_data, NULL); + g_source_attach (source, app_data->main_context); + g_source_unref (source); + + allowed_list_update_pending = TRUE; + } + + g_static_mutex_unlock (&mutex); +} + + +static gboolean device_list_update_pending = FALSE; + +/* + * nm_policy_device_list_update_from_allowed_list + * + * Requery NetworkManagerInfo for a list of updated + * allowed wireless networks. + * + */ +static gboolean nm_policy_device_list_update_from_allowed_list (gpointer user_data) +{ + NMData *data = (NMData *)user_data; + GSList *elt; + + device_list_update_pending = FALSE; + + g_return_val_if_fail (data != NULL, FALSE); for (elt = data->dev_list; elt != NULL; elt = g_slist_next (elt)) { @@ -541,22 +597,33 @@ static gboolean nm_policy_allowed_ap_list_update (gpointer user_data) /* - * nm_policy_schedule_allowed_ap_list_update + * nm_policy_schedule_device_ap_lists_update_from_allowed * - * Schedule an update of the allowed AP list in the main thread. + * Schedule an update of each wireless device's AP list from + * the allowed list, in the main thread. * */ -void nm_policy_schedule_allowed_ap_list_update (NMData *app_data) +void nm_policy_schedule_device_ap_lists_update_from_allowed (NMData *app_data) { - GSource *source = NULL; + static GStaticMutex mutex = G_STATIC_MUTEX_INIT; g_return_if_fail (app_data != NULL); g_return_if_fail (app_data->main_context != NULL); - source = g_idle_source_new (); - /* We want this idle source to run before any other idle source */ - g_source_set_priority (source, G_PRIORITY_HIGH_IDLE); - g_source_set_callback (source, nm_policy_allowed_ap_list_update, app_data, NULL); - g_source_attach (source, app_data->main_context); - g_source_unref (source); + g_static_mutex_lock (&mutex); + + if (device_list_update_pending == FALSE) + { + GSource *source = g_idle_source_new (); + + /* We want this idle source to run before any other idle source */ + g_source_set_priority (source, G_PRIORITY_HIGH_IDLE); + g_source_set_callback (source, nm_policy_allowed_ap_list_update, app_data, NULL); + g_source_attach (source, app_data->main_context); + g_source_unref (source); + + device_list_update_pending = TRUE; + } + + g_static_mutex_unlock (&mutex); } diff --git a/src/NetworkManagerPolicy.h b/src/NetworkManagerPolicy.h index c34781293..f87f9229f 100644 --- a/src/NetworkManagerPolicy.h +++ b/src/NetworkManagerPolicy.h @@ -39,6 +39,7 @@ void nm_policy_schedule_state_update (NMData *app_data); void nm_policy_schedule_device_switch (NMDevice *dev, NMData *app_data); void nm_policy_schedule_allowed_ap_list_update (NMData *app_data); +void nm_policy_schedule_device_ap_lists_update_from_allowed (NMData *app_data); gboolean nm_policy_activation_finish (gpointer user_data); diff --git a/src/nm-dbus-device.c b/src/nm-dbus-device.c index 8ccbc8f53..bc75908f7 100644 --- a/src/nm-dbus-device.c +++ b/src/nm-dbus-device.c @@ -34,6 +34,7 @@ #include "NetworkManagerPolicy.h" #include "nm-dbus-device.h" + static DBusMessage *nm_dbus_device_get_name (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data) { DBusMessage *reply = NULL; @@ -213,7 +214,7 @@ static DBusMessage *nm_dbus_device_get_active_network (DBusConnection *connectio char *object_path = NULL; if ( (tmp_ap = nm_device_ap_list_get_ap_by_essid (dev, nm_ap_get_essid (best_ap))) - && (object_path = nm_device_get_path_for_ap (dev, tmp_ap))) + && (object_path = nm_dbus_get_object_path_for_network (dev, tmp_ap))) { dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &object_path, DBUS_TYPE_INVALID); g_free (object_path); @@ -268,12 +269,8 @@ static DBusMessage *nm_dbus_device_get_networks (DBusConnection *connection, DBu { if (nm_ap_get_essid (ap)) { - object_path = g_strdup_printf ("%s/%s/Networks/%s", NM_DBUS_PATH_DEVICES, - nm_device_get_iface (dev), nm_ap_get_essid (ap)); - escaped_object_path = nm_dbus_escape_object_path (object_path); - g_free (object_path); - dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_OBJECT_PATH, - &escaped_object_path); + escaped_object_path = nm_dbus_get_object_path_for_network (dev, ap); + dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_OBJECT_PATH, &escaped_object_path); g_free (escaped_object_path); success = TRUE; } @@ -342,6 +339,99 @@ static DBusMessage *nm_dbus_device_set_link_active (DBusConnection *connection, return reply; } +static DBusMessage *nm_dbus_device_get_properties (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data) +{ + DBusMessage *reply = NULL; + NMDevice *dev; + + g_return_val_if_fail (data && data->data && data->dev && connection && message, NULL); + + dev = data->dev; + if ((reply = dbus_message_new_method_return (message))) + { + char * op = nm_dbus_get_object_path_for_device (dev); + const char * iface = nm_device_get_iface (dev); + dbus_uint32_t type = (dbus_uint32_t) nm_device_get_type (dev); + const char * udi = nm_device_get_udi (dev); + dbus_uint32_t ip4_address = (dbus_uint32_t) nm_device_get_ip4_address (dev); + struct ether_addr hw_addr; + char hw_addr_buf[20]; + char * hw_addr_buf_ptr = &hw_addr_buf[0]; + dbus_uint32_t mode = 0; + dbus_int32_t strength = -1; + NMAccessPoint * best_ap; + char * active_network_path = NULL; + dbus_bool_t link_active = (dbus_bool_t) nm_device_has_active_link (dev); + dbus_uint32_t driver_support_level = (dbus_uint32_t) nm_device_get_driver_support_level (dev); + char ** networks = NULL; + int num_networks = 0; + + nm_device_get_hw_address (dev, (unsigned char *)&(hw_addr.ether_addr_octet)); + memset (hw_addr_buf, 0, 20); + ether_ntoa_r (&hw_addr, &hw_addr_buf[0]); + + if (nm_device_is_wireless (dev)) + { + NMAccessPointList * ap_list; + NMAPListIter * iter; + + strength = (dbus_int32_t) nm_device_get_signal_strength (dev); + mode = (dbus_uint32_t) nm_device_get_mode (dev); + + if ((best_ap = nm_device_get_best_ap (dev))) + { + NMAccessPoint *tmp_ap; + + if ((tmp_ap = nm_device_ap_list_get_ap_by_essid (dev, nm_ap_get_essid (best_ap)))) + active_network_path = nm_dbus_get_object_path_for_network (dev, tmp_ap); + nm_ap_unref (best_ap); + } + + ap_list = nm_device_ap_list_get (dev); + if (ap_list && (num_networks = nm_ap_list_size (ap_list))) + { + if ((iter = nm_ap_list_iter_new (ap_list))) + { + int i = 0; + NMAccessPoint * ap; + + networks = g_malloc0 (sizeof (char *) * (num_networks + 1)); + while ((ap = nm_ap_list_iter_next (iter))) + { + char *ap_op = nm_dbus_get_object_path_for_network (dev, ap); + if (ap_op) + networks[i++] = ap_op; + } + num_networks = i; /* # actually added to array, since we can have NULL essid access points */ + + nm_ap_list_iter_free (iter); + } + } + } + if (!active_network_path) + active_network_path = g_strdup (""); + + dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &op, + DBUS_TYPE_STRING, &iface, + DBUS_TYPE_UINT32, &type, + DBUS_TYPE_STRING, &udi, + DBUS_TYPE_UINT32, &ip4_address, + DBUS_TYPE_STRING, &hw_addr_buf_ptr, + DBUS_TYPE_UINT32, &mode, + DBUS_TYPE_INT32, &strength, + DBUS_TYPE_BOOLEAN,&link_active, + DBUS_TYPE_UINT32, &driver_support_level, + DBUS_TYPE_STRING, &active_network_path, + DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &networks, num_networks, + DBUS_TYPE_INVALID); + g_free (op); + g_free (active_network_path); + g_strfreev (networks); + } + + return reply; +} + /* * nm_dbus_device_methods_setup @@ -353,6 +443,8 @@ NMDbusMethodList *nm_dbus_device_methods_setup (void) { NMDbusMethodList *list = nm_dbus_method_list_new (NULL); + nm_dbus_method_list_add_method (list, "getProperties", nm_dbus_device_get_properties); + nm_dbus_method_list_add_method (list, "getName", nm_dbus_device_get_name); nm_dbus_method_list_add_method (list, "getType", nm_dbus_device_get_type); nm_dbus_method_list_add_method (list, "getHalUdi", nm_dbus_device_get_hal_udi); diff --git a/src/nm-dbus-net.c b/src/nm-dbus-net.c index 623b50f8f..f3e1dcf6d 100644 --- a/src/nm-dbus-net.c +++ b/src/nm-dbus-net.c @@ -221,6 +221,44 @@ static DBusMessage *nm_dbus_net_get_mode (DBusConnection *connection, DBusMessag } +static DBusMessage *nm_dbus_net_get_properties (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data) +{ + DBusMessage *reply = NULL; + + g_return_val_if_fail (data && data->data && data->dev && data->ap && connection && message, NULL); + + if ((reply = dbus_message_new_method_return (message))) + { + char * op = nm_dbus_get_object_path_for_network (data->dev, data->ap); + const char * essid = nm_ap_get_essid (data->ap); + char hw_addr_buf[20]; + char * hw_addr_buf_ptr = &hw_addr_buf[0]; + dbus_int32_t strength = nm_ap_get_strength (data->ap); + double freq = nm_ap_get_freq (data->ap); + dbus_int32_t rate = nm_ap_get_rate (data->ap); + dbus_bool_t enc = nm_ap_get_encrypted (data->ap); + dbus_uint32_t mode = nm_ap_get_mode (data->ap); + + memset (&hw_addr_buf[0], 0, 20); + if (nm_ap_get_address (data->ap)) + iw_ether_ntop((const struct ether_addr *) (nm_ap_get_address (data->ap)), &hw_addr_buf[0]); + + dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &op, + DBUS_TYPE_STRING, &essid, + DBUS_TYPE_STRING, &hw_addr_buf_ptr, + DBUS_TYPE_INT32, &strength, + DBUS_TYPE_DOUBLE, &freq, + DBUS_TYPE_INT32, &rate, + DBUS_TYPE_BOOLEAN,&enc, + DBUS_TYPE_UINT32, &mode, + DBUS_TYPE_INVALID); + g_free (op); + } + + return reply; +} + + /* * nm_dbus_net_methods_setup * @@ -232,6 +270,8 @@ NMDbusMethodList *nm_dbus_net_methods_setup (void) { NMDbusMethodList *list = nm_dbus_method_list_new (nm_dbus_net_validate); + nm_dbus_method_list_add_method (list, "getProperties", nm_dbus_net_get_properties); + nm_dbus_method_list_add_method (list, "getName", nm_dbus_net_get_name); nm_dbus_method_list_add_method (list, "getAddress", nm_dbus_net_get_address); nm_dbus_method_list_add_method (list, "getStrength", nm_dbus_net_get_strength); diff --git a/src/nm-dbus-nm.c b/src/nm-dbus-nm.c index 6ba447f96..5d8645ab0 100644 --- a/src/nm-dbus-nm.c +++ b/src/nm-dbus-nm.c @@ -51,17 +51,14 @@ static DBusMessage *nm_dbus_nm_get_active_device (DBusConnection *connection, DB /* Construct object path of "active" device and return it */ if (data->data->active_device) { - char *object_path, *escaped_object_path; + char *op; - reply = dbus_message_new_method_return (message); - if (!reply) + if (!(reply = dbus_message_new_method_return (message))) return (NULL); - object_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (data->data->active_device)); - escaped_object_path = nm_dbus_escape_object_path (object_path); - dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &escaped_object_path, DBUS_TYPE_INVALID); - g_free (escaped_object_path); - g_free (object_path); + op = nm_dbus_get_object_path_for_device (data->data->active_device); + dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &op, DBUS_TYPE_INVALID); + g_free (op); } else { @@ -114,13 +111,10 @@ static DBusMessage *nm_dbus_nm_get_devices (DBusConnection *connection, DBusMess if (dev && (nm_device_get_driver_support_level (dev) != NM_DRIVER_UNSUPPORTED)) { - char *object_path, *escaped_object_path; - - object_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (dev)); - escaped_object_path = nm_dbus_escape_object_path (object_path); - g_free (object_path); - dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_OBJECT_PATH, &escaped_object_path); - g_free (escaped_object_path); + char *op = nm_dbus_get_object_path_for_device (dev); + + dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_OBJECT_PATH, &op); + g_free (op); appended = TRUE; } } @@ -154,13 +148,14 @@ static DBusMessage *nm_dbus_nm_get_devices (DBusConnection *connection, DBusMess */ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data) { - NMDevice *dev = NULL; - DBusMessage *reply = NULL; - char *dev_path = NULL; - char *network = NULL; - char *key = NULL; - int key_type = -1; - DBusError error; + NMDevice * dev = NULL; + DBusMessage * reply = NULL; + char * dev_path = NULL; + char * net_path = NULL; + const char * key = NULL; + const int key_type = -1; + DBusError error; + NMAccessPoint * ap = NULL; g_return_val_if_fail (connection != NULL, NULL); g_return_val_if_fail (message != NULL, NULL); @@ -169,14 +164,11 @@ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DB /* Try to grab both device _and_ network first, and if that fails then just the device. */ dbus_error_init (&error); - if (!dbus_message_get_args (message, &error, DBUS_TYPE_OBJECT_PATH, &dev_path, - DBUS_TYPE_STRING, &network, DBUS_TYPE_STRING, &key, - DBUS_TYPE_INT32, &key_type, DBUS_TYPE_INVALID)) + if (!dbus_message_get_args (message, &error, DBUS_TYPE_OBJECT_PATH, &dev_path, + DBUS_TYPE_OBJECT_PATH, &net_path, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_INT32, &key_type, DBUS_TYPE_INVALID)) { - network = NULL; - key = NULL; - key_type = -1; - if (dbus_error_is_set (&error)) dbus_error_free (&error); @@ -191,35 +183,43 @@ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DB "NetworkManager::setActiveDevice called with invalid arguments."); goto out; } else nm_info ("FORCE: device '%s'", dev_path); - } else nm_info ("FORCE: device '%s', network '%s'", dev_path, network); + } else nm_info ("FORCE: device '%s', network '%s'", dev_path, net_path); - dev_path = nm_dbus_unescape_object_path (dev_path); - /* So by now we have a valid device and possibly a network as well */ - + dev_path = nm_dbus_unescape_object_path (dev_path); dev = nm_dbus_get_device_from_object_path (data->data, dev_path); + g_free (dev_path); if (!dev || (nm_device_get_driver_support_level (dev) == NM_DRIVER_UNSUPPORTED)) { reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "DeviceNotFound", "The requested network device does not exist."); goto out; } - nm_device_ref (dev); + + if (net_path) + { + net_path = nm_dbus_unescape_object_path (net_path); + ap = nm_device_ap_list_get_ap_by_obj_path (dev, net_path); + g_free (net_path); + } /* Make sure network is valid and device is wireless */ - if (nm_device_is_wireless (dev) && !network) + if (nm_device_is_wireless (dev) && !ap) { reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "InvalidArguments", "NetworkManager::setActiveDevice called with invalid arguments."); goto out; } + nm_device_ref (dev); + data->data->forcing_device = TRUE; nm_device_deactivate (dev, FALSE); - nm_device_schedule_force_use (dev, network, key, key_type); + + nm_schedule_state_change_signal_broadcast (data->data); + nm_device_schedule_force_use (dev, nm_ap_get_essid (ap), key, key_type); out: - g_free (dev_path); return (reply); } @@ -249,8 +249,9 @@ static DBusMessage *nm_dbus_nm_create_wireless_network (DBusConnection *connecti /* Try to grab both device _and_ network first, and if that fails then just the device. */ dbus_error_init (&error); if (!dbus_message_get_args (message, &error, DBUS_TYPE_OBJECT_PATH, &dev_path, - DBUS_TYPE_STRING, &network, DBUS_TYPE_STRING, &key, - DBUS_TYPE_INT32, &key_type, DBUS_TYPE_INVALID)) + DBUS_TYPE_STRING, &network, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_INT32, &key_type, DBUS_TYPE_INVALID)) { reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "InvalidArguments", "NetworkManager::createWirelessNetwork called with invalid arguments."); @@ -385,45 +386,6 @@ static DBusMessage *nm_dbus_nm_remove_test_device (DBusConnection *connection, D } -/* - * nm_dbus_nm_set_user_key_for_network - * - * In response to a NetworkManagerInfo message, sets the WEP key - * for a particular wireless AP/network - * - */ -static DBusMessage * nm_dbus_nm_set_user_key_for_network (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data) -{ - DBusError error; - char *device; - char *network; - char *passphrase; - NMEncKeyType key_type; - - g_return_val_if_fail (data != NULL, NULL); - g_return_val_if_fail (data->data != NULL, NULL); - g_return_val_if_fail (connection != NULL, NULL); - g_return_val_if_fail (message != NULL, NULL); - - dbus_error_init (&error); - if (dbus_message_get_args (message, &error, - DBUS_TYPE_STRING, &device, - DBUS_TYPE_STRING, &network, - DBUS_TYPE_STRING, &passphrase, - DBUS_TYPE_INT32, &key_type, - DBUS_TYPE_INVALID)) - { - NMDevice *dev; - - if ((dev = nm_get_device_by_iface (data->data, device))) - nm_device_set_user_key_for_network (dev, data->data->invalid_ap_list, network, passphrase, key_type); - - } - - return (NULL); -} - - static DBusMessage *nm_dbus_nm_set_scanning_enabled (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data) { gboolean enabled = FALSE; @@ -518,6 +480,8 @@ static DBusMessage *nm_dbus_nm_sleep (DBusConnection *connection, DBusMessage *m nm_device_bring_down (dev); } nm_unlock_mutex (app_data->dev_list_mutex, __FUNCTION__); + + nm_schedule_state_change_signal_broadcast (app_data); nm_policy_schedule_state_update (app_data); } @@ -535,23 +499,24 @@ static DBusMessage *nm_dbus_nm_wake (DBusConnection *connection, DBusMessage *me if (app_data->asleep == TRUE) { app_data->asleep = FALSE; + + nm_schedule_state_change_signal_broadcast (app_data); nm_policy_schedule_state_update (app_data); } return NULL; } -static DBusMessage *nm_dbus_nm_get_status (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data) +static DBusMessage *nm_dbus_nm_get_state (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data) { - DBusMessage *reply = NULL; - char *status; + DBusMessage * reply = NULL; + NMState state; g_return_val_if_fail (data && data->data && connection && message, NULL); - status = nm_dbus_network_status_from_data (data->data); - if (status && (reply = dbus_message_new_method_return (message))) - dbus_message_append_args (reply, DBUS_TYPE_STRING, &status, DBUS_TYPE_INVALID); - g_free (status); + state = nm_get_app_state_from_data (data->data); + if ((reply = dbus_message_new_method_return (message))) + dbus_message_append_args (reply, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID); return reply; } @@ -571,14 +536,13 @@ NMDbusMethodList *nm_dbus_nm_methods_setup (void) nm_dbus_method_list_add_method (list, "getDevices", nm_dbus_nm_get_devices); nm_dbus_method_list_add_method (list, "setActiveDevice", nm_dbus_nm_set_active_device); nm_dbus_method_list_add_method (list, "createWirelessNetwork", nm_dbus_nm_create_wireless_network); - nm_dbus_method_list_add_method (list, "setKeyForNetwork", nm_dbus_nm_set_user_key_for_network); nm_dbus_method_list_add_method (list, "setScanningEnabled", nm_dbus_nm_set_scanning_enabled); nm_dbus_method_list_add_method (list, "getScanningEnabled", nm_dbus_nm_get_scanning_enabled); nm_dbus_method_list_add_method (list, "setWirelessEnabled", nm_dbus_nm_set_wireless_enabled); nm_dbus_method_list_add_method (list, "getWirelessEnabled", nm_dbus_nm_get_wireless_enabled); nm_dbus_method_list_add_method (list, "sleep", nm_dbus_nm_sleep); nm_dbus_method_list_add_method (list, "wake", nm_dbus_nm_wake); - nm_dbus_method_list_add_method (list, "status", nm_dbus_nm_get_status); + nm_dbus_method_list_add_method (list, "state", nm_dbus_nm_get_state); nm_dbus_method_list_add_method (list, "createTestDevice", nm_dbus_nm_create_test_device); nm_dbus_method_list_add_method (list, "removeTestDevice", nm_dbus_nm_remove_test_device); diff --git a/src/vpn-manager/nm-dbus-vpn.c b/src/vpn-manager/nm-dbus-vpn.c index 333b153de..ff5123b8e 100644 --- a/src/vpn-manager/nm-dbus-vpn.c +++ b/src/vpn-manager/nm-dbus-vpn.c @@ -34,11 +34,10 @@ /* * nm_dbus_vpn_signal_vpn_connection_update * - * Notifies the bus that a VPN connection has been added, deleted, or - * changed properties. + * Notifies the bus that a VPN connection's properties have changed. * */ -void nm_dbus_vpn_signal_vpn_connection_update (DBusConnection *con, NMVPNConnection *vpn) +void nm_dbus_vpn_signal_vpn_connection_update (DBusConnection *con, NMVPNConnection *vpn, const char *signal) { DBusMessage *message; const char *vpn_name; @@ -46,7 +45,7 @@ void nm_dbus_vpn_signal_vpn_connection_update (DBusConnection *con, NMVPNConnect g_return_if_fail (con != NULL); g_return_if_fail (vpn != NULL); - if (!(message = dbus_message_new_signal (NM_DBUS_PATH_VPN, NM_DBUS_INTERFACE_VPN, "VPNConnectionUpdate"))) + if (!(message = dbus_message_new_signal (NM_DBUS_PATH_VPN, NM_DBUS_INTERFACE_VPN, signal))) { nm_warning ("Not enough memory for new dbus message!"); return; @@ -55,7 +54,7 @@ void nm_dbus_vpn_signal_vpn_connection_update (DBusConnection *con, NMVPNConnect vpn_name = nm_vpn_connection_get_name (vpn); dbus_message_append_args (message, DBUS_TYPE_STRING, &vpn_name, DBUS_TYPE_INVALID); if (!dbus_connection_send (con, message, NULL)) - nm_warning ("Could not raise the VPNConnectionUpdate signal!"); + nm_warning ("Could not raise the %s signal!", signal); dbus_message_unref (message); } @@ -233,74 +232,187 @@ static char ** nm_dbus_vpn_get_vpn_data (DBusConnection *connection, NMVPNConnec } +typedef struct UpdateOneVPNCBData +{ + NMData * data; + char * vpn; +} UpdateOneVPNCBData; + + +void free_update_one_vpn_cb_data (UpdateOneVPNCBData *data) +{ + if (data) + g_free (data->vpn); + g_free (data); +} + /* - * nm_dbus_vpn_add_one_connection + * nm_dbus_vpn_update_one_connection_cb * * Retrieve and add to our VPN Manager one VPN connection from NMI. * */ -NMVPNConnection *nm_dbus_vpn_add_one_connection (DBusConnection *con, const char *name, NMVPNManager *vpn_manager) +void nm_dbus_vpn_update_one_connection_cb (DBusPendingCall *pcall, void *user_data) { - DBusMessage *message; - DBusError error; - DBusMessage *reply; - const char *con_name = NULL; - const char *service_name = NULL; - const char *user_name = NULL; - DBusMessageIter iter; - NMVPNConnection *vpn = NULL; + UpdateOneVPNCBData * cb_data = (UpdateOneVPNCBData *) user_data; + DBusMessage * reply; + const char * con_name = NULL; + const char * service_name = NULL; + const char * user_name = NULL; - g_return_val_if_fail (con != NULL, NULL); - g_return_val_if_fail (name != NULL, NULL); - g_return_val_if_fail (vpn_manager != NULL, NULL); + g_return_if_fail (pcall != NULL); + g_return_if_fail (cb_data != NULL); + g_return_if_fail (cb_data->data != NULL); + g_return_if_fail (cb_data->data->vpn_manager != NULL); - if (!(message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "getVPNConnectionProperties"))) - { - nm_warning ("Couldn't allocate the dbus message"); - return NULL; - } + dbus_pending_call_ref (pcall); - dbus_message_append_args (message, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID); - - /* Send message and get properties back from NetworkManagerInfo */ - dbus_error_init (&error); - reply = dbus_connection_send_with_reply_and_block (con, message, -1, &error); - dbus_message_unref (message); - if (dbus_error_is_set (&error)) - { - nm_warning ("nm_dbus_add_one_vpn_connections(): %s raised %s", error.name, error.message); - goto out; - } - if (!reply) + if (!dbus_pending_call_get_completed (pcall)) goto out; - dbus_error_init (&error); - if (dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &con_name, DBUS_TYPE_STRING, &service_name, + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (dbus_message_is_error (reply, "BadVPNConnectionData")) + { + NMVPNConnection *vpn = nm_vpn_manager_find_connection_by_name (cb_data->data->vpn_manager, cb_data->vpn); + + nm_vpn_connection_ref (vpn); + nm_vpn_manager_remove_connection (cb_data->data->vpn_manager, vpn); + nm_dbus_vpn_signal_vpn_connection_update (cb_data->data->dbus_connection, vpn, "VPNConnectionRemoved"); + nm_vpn_connection_unref (vpn); + goto out; + } + + if (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &con_name, DBUS_TYPE_STRING, &service_name, DBUS_TYPE_STRING, &user_name, DBUS_TYPE_INVALID)) { - vpn = nm_vpn_manager_add_connection (vpn_manager, con_name, service_name, user_name); + NMVPNConnection * vpn; + gboolean new = TRUE; + + if ((vpn = nm_vpn_manager_find_connection_by_name (cb_data->data->vpn_manager, con_name))) + { + nm_vpn_manager_remove_connection (cb_data->data->vpn_manager, vpn); + new = FALSE; + } + + vpn = nm_vpn_manager_add_connection (cb_data->data->vpn_manager, con_name, service_name, user_name); + nm_dbus_vpn_signal_vpn_connection_update (cb_data->data->dbus_connection, vpn, new ? "VPNConnectionAdded" : "VPNConnectionUpdate"); } dbus_message_unref (reply); out: - if (dbus_error_is_set (&error)) - dbus_error_free (&error); - - return vpn; + dbus_pending_call_unref (pcall); } /* - * nm_dbus_vpn_connections_update + * nm_dbus_vpn_connections_update_cb + * + * Async callback from nnm_dbus_vpn_connections_update + * + */ +static void nm_dbus_vpn_connections_update_cb (DBusPendingCall *pcall, void *user_data) +{ + NMData * data = (NMData *) user_data; + DBusMessage * reply; + DBusMessageIter iter, array_iter; + + g_return_if_fail (pcall); + g_return_if_fail (data != NULL); + + dbus_pending_call_ref (pcall); + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (message_is_error (reply)) + goto out; + + nm_info ("Updating VPN Connections..."); + + dbus_message_iter_init (reply, &iter); + dbus_message_iter_recurse (&iter, &array_iter); + while (dbus_message_iter_get_arg_type (&array_iter) == DBUS_TYPE_STRING) + { + DBusMessage * message; + const char * value; + + dbus_message_iter_get_basic (&array_iter, &value); + + if ((message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "getVPNConnectionProperties"))) + { + DBusPendingCall * vpn_pcall = NULL; + + dbus_message_append_args (message, DBUS_TYPE_STRING, &value, DBUS_TYPE_INVALID); + dbus_connection_send_with_reply (data->dbus_connection, message, &vpn_pcall, -1); + dbus_message_unref (message); + if (vpn_pcall) + { + UpdateOneVPNCBData * vpn_cb_data = g_malloc0 (sizeof (UpdateOneVPNCBData)); + + vpn_cb_data->data = data; + vpn_cb_data->vpn = g_strdup (value); + dbus_pending_call_set_notify (vpn_pcall, nm_dbus_vpn_update_one_connection_cb, vpn_cb_data, (DBusFreeFunction) free_update_one_vpn_cb_data); + } + } + dbus_message_iter_next (&array_iter); + } + dbus_message_unref (reply); + +out: + dbus_pending_call_unref (pcall); +} + + +/* + * nm_dbus_vpn_update_one_vpn_connection + * + * Update one VPN connection + * + */ +void nm_dbus_vpn_update_one_vpn_connection (DBusConnection *connection, const char *vpn, NMData *data) +{ + DBusMessage * message; + DBusPendingCall * pcall = NULL; + + g_return_if_fail (connection != NULL); + g_return_if_fail (vpn != NULL); + g_return_if_fail (data != NULL); + + if (!(message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "getVPNConnectionProperties"))) + { + nm_warning ("nm_dbus_update_one_vpn_connection(): Couldn't allocate the dbus message"); + return; + } + + dbus_message_append_args (message, DBUS_TYPE_STRING, &vpn, DBUS_TYPE_INVALID); + dbus_connection_send_with_reply (connection, message, &pcall, -1); + dbus_message_unref (message); + if (pcall) + { + UpdateOneVPNCBData * cb_data = g_malloc0 (sizeof (UpdateOneVPNCBData)); + + cb_data->data = data; + cb_data->vpn = g_strdup (vpn); + dbus_pending_call_set_notify (pcall, nm_dbus_vpn_update_one_connection_cb, cb_data, (DBusFreeFunction) free_update_one_vpn_cb_data); + } +} + + +/* + * nm_dbus_vpn_connections_update_from_nmi * * Update VPN connections from NetworkManagerInfo. * */ -gboolean nm_dbus_vpn_connections_update (NMData *data) +static gboolean nm_dbus_vpn_connections_update_from_nmi (NMData *data) { - DBusMessage *message; - DBusError error; - DBusMessage *reply; + DBusMessage * message; + DBusPendingCall * pcall; g_return_val_if_fail (data != NULL, FALSE); g_return_val_if_fail (data->dbus_connection != NULL, FALSE); @@ -315,34 +427,13 @@ gboolean nm_dbus_vpn_connections_update (NMData *data) return FALSE; } - /* Send message and get essid back from NetworkManagerInfo */ - dbus_error_init (&error); - reply = dbus_connection_send_with_reply_and_block (data->dbus_connection, message, -1, &error); + dbus_connection_send_with_reply (data->dbus_connection, message, &pcall, -1); dbus_message_unref (message); - if (dbus_error_is_set (&error)) - nm_warning ("nm_dbus_vpn_connections_update(): %s raised %s", error.name, error.message); - else if (!reply) - nm_info ("nm_dbus_vpn_connections_update(): reply was NULL."); - else + if (pcall) { - DBusMessageIter iter, array_iter; - - dbus_message_iter_init (reply, &iter); - dbus_message_iter_recurse (&iter, &array_iter); - while (dbus_message_iter_get_arg_type (&array_iter) == DBUS_TYPE_STRING) - { - const char *value; - NMVPNConnection *vpn; - - dbus_message_iter_get_basic (&array_iter, &value); - if ((vpn = nm_dbus_vpn_add_one_connection (data->dbus_connection, value, data->vpn_manager))) - nm_dbus_vpn_signal_vpn_connection_update (data->dbus_connection, vpn); - dbus_message_iter_next(&array_iter); - } + dbus_pending_call_set_notify (pcall, nm_dbus_vpn_connections_update_cb, data, NULL); + dbus_pending_call_block (pcall); } - - if (reply) - dbus_message_unref (reply); return FALSE; } @@ -364,7 +455,7 @@ void nm_dbus_vpn_schedule_vpn_connections_update (NMData *app_data) source = g_idle_source_new (); /* We want this idle source to run before any other idle source */ g_source_set_priority (source, G_PRIORITY_HIGH_IDLE); - g_source_set_callback (source, (GSourceFunc) nm_dbus_vpn_connections_update, app_data, NULL); + g_source_set_callback (source, (GSourceFunc) nm_dbus_vpn_connections_update_from_nmi, app_data, NULL); g_source_attach (source, app_data->main_context); g_source_unref (source); } @@ -407,15 +498,7 @@ static DBusMessage *nm_dbus_vpn_get_vpn_connections (DBusConnection *connection, if (!(reply = dbus_message_new_method_return (message))) goto out; - dbus_message_iter_init_append (reply, &iter); - dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &iter_array); - - for (i = 0; i < num_names; i++) - { - dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, &vpn_names[i]); - } - - dbus_message_iter_close_container (&iter, &iter_array); + dbus_message_append_args (reply, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &vpn_names, num_names, DBUS_TYPE_INVALID); out: if (vpn_names) @@ -465,7 +548,7 @@ static DBusMessage *nm_dbus_vpn_get_vpn_connection_properties (DBusConnection *c } if (!good) - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_VPN, "InvalidVPNConnections", "No VPN connection with that name was found."); + reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_VPN, "InvalidVPNConnection", "No VPN connection with that name was found."); return reply; } @@ -538,7 +621,7 @@ static DBusMessage *nm_dbus_vpn_activate_connection (DBusConnection *connection, NMVPNService *service = nm_vpn_connection_get_service (vpn);; nm_info ("Will activate VPN connection '%s', service '%s', user_name '%s', vpn_data '%s'.", - name, nm_vpn_service_get_name (service), nm_vpn_connection_get_user_name (vpn), joined_string); + name, nm_vpn_service_get_service_name (service), nm_vpn_connection_get_user_name (vpn), joined_string); nm_vpn_manager_activate_vpn_connection (data->data->vpn_manager, vpn, password, items, item_count); g_free (joined_string); diff --git a/src/vpn-manager/nm-dbus-vpn.h b/src/vpn-manager/nm-dbus-vpn.h index 084c37473..7868de669 100644 --- a/src/vpn-manager/nm-dbus-vpn.h +++ b/src/vpn-manager/nm-dbus-vpn.h @@ -27,10 +27,10 @@ #include "nm-vpn-connection.h" -NMVPNConnection * nm_dbus_vpn_add_one_connection (DBusConnection *con, const char *name, NMVPNManager *vpn_manager); void nm_dbus_vpn_schedule_vpn_connections_update (NMData *app_data); +void nm_dbus_vpn_update_one_vpn_connection (DBusConnection *connection, const char *vpn, NMData *data); -void nm_dbus_vpn_signal_vpn_connection_update (DBusConnection *con, NMVPNConnection *vpn); +void nm_dbus_vpn_signal_vpn_connection_update (DBusConnection *con, NMVPNConnection *vpn, const char *signal); void nm_dbus_vpn_signal_vpn_connection_change (DBusConnection *con, NMVPNConnection *vpn); void nm_dbus_vpn_signal_vpn_login_failed (DBusConnection *con, NMVPNConnection *vpn, const char *error_msg); void nm_dbus_vpn_signal_vpn_login_banner (DBusConnection *con, NMVPNConnection *vpn, const char *banner); diff --git a/src/vpn-manager/nm-vpn-manager.c b/src/vpn-manager/nm-vpn-manager.c index 71a5a1fe7..583f147d7 100644 --- a/src/vpn-manager/nm-vpn-manager.c +++ b/src/vpn-manager/nm-vpn-manager.c @@ -112,7 +112,9 @@ void nm_vpn_manager_clear_connections (NMVPNManager *manager) { g_return_if_fail (manager != NULL); - g_slist_foreach (manager->connections, (GFunc)nm_vpn_connection_unref, NULL); + g_slist_foreach (manager->connections, (GFunc) nm_vpn_connection_unref, NULL); + g_slist_free (manager->connections); + manager->connections = NULL; } @@ -134,7 +136,7 @@ static NMVPNService *find_service_by_name (NMVPNManager *manager, const char *se { if ((service = (NMVPNService *)(elt->data))) { - const char *search_name = nm_vpn_service_get_name (service); + const char *search_name = nm_vpn_service_get_service_name (service); if (search_name && (strcmp (service_name, search_name) == 0)) break; } @@ -193,7 +195,7 @@ static void nm_vpn_manager_set_active_vpn_connection (NMVPNManager *manager, NMV if ((active = nm_vpn_manager_get_active_vpn_connection (manager))) { service = nm_vpn_connection_get_service (active); - if (service && (service_name = nm_vpn_service_get_name (service))) + if (service && (service_name = nm_vpn_service_get_service_name (service))) { /* Remove any previous watch on this VPN connection's service name */ match_string = g_strdup_printf ("type='signal'," @@ -216,7 +218,6 @@ static void nm_vpn_manager_set_active_vpn_connection (NMVPNManager *manager, NMV if (manager->active_device) { -nm_info ("Clearing active VPN device '%s'.", manager->active_device); nm_system_device_set_up_down_with_iface (NULL, manager->active_device, FALSE); nm_system_device_flush_routes_with_iface (manager->active_device); nm_system_device_flush_addresses_with_iface (manager->active_device); @@ -231,7 +232,7 @@ nm_info ("Clearing active VPN device '%s'.", manager->active_device); return; service = nm_vpn_connection_get_service (con); - if (!service || !(service_name = nm_vpn_service_get_name (service))) + if (!service || !(service_name = nm_vpn_service_get_service_name (service))) { nm_warning ("VPN connection could not be set active because it didn't have a VPN service."); return; @@ -295,6 +296,24 @@ NMVPNConnection *nm_vpn_manager_add_connection (NMVPNManager *manager, const cha } +/* + * nm_vpn_manager_remove_connection + * + * Remove a VPN connection. + * + */ +void nm_vpn_manager_remove_connection (NMVPNManager *manager, NMVPNConnection *vpn) +{ + GSList * elt; + + g_return_if_fail (manager != NULL); + g_return_if_fail (vpn != NULL); + + manager->connections = g_slist_remove (manager->connections, vpn); + nm_vpn_connection_unref (vpn); +} + + /* * Prints config returned from vpnc-helper */ @@ -519,7 +538,7 @@ gboolean nm_vpn_manager_process_signal (NMVPNManager *manager, DBusMessage *mess return FALSE; service = nm_vpn_connection_get_service (active); - if (!service || !(service_name = nm_vpn_service_get_name (service))) + if (!service || !(service_name = nm_vpn_service_get_service_name (service))) return FALSE; temp_op = construct_op_from_service_name (service_name); @@ -588,7 +607,7 @@ gboolean nm_vpn_manager_process_name_owner_changed (NMVPNManager *manager, const } /* Can't handle the signal if its not from our active VPN service */ - if (strcmp (nm_vpn_service_get_name (service), changed_service_name) != 0) + if (strcmp (nm_vpn_service_get_service_name (service), changed_service_name) != 0) { nm_vpn_connection_unref (active); return FALSE; @@ -641,7 +660,7 @@ void nm_vpn_manager_activate_vpn_connection (NMVPNManager *manager, NMVPNConnect nm_vpn_manager_set_active_vpn_connection (manager, NULL); /* Construct a new method call with the correct service and object path */ - if (!(service = nm_vpn_connection_get_service (vpn)) || !(service_name = nm_vpn_service_get_name (service))) + if (!(service = nm_vpn_connection_get_service (vpn)) || !(service_name = nm_vpn_service_get_service_name (service))) return; nm_vpn_manager_set_active_vpn_connection (manager, vpn); @@ -716,7 +735,7 @@ void nm_vpn_manager_deactivate_vpn_connection (NMVPNManager *manager) /* Construct a new method call with the correct service and object path */ service = nm_vpn_connection_get_service (active); - service_name = nm_vpn_service_get_name (service); + service_name = nm_vpn_service_get_service_name (service); op = construct_op_from_service_name (service_name); message = dbus_message_new_method_call (service_name, op, service_name, "stopConnection"); g_free (op); @@ -763,16 +782,18 @@ static GSList *nm_vpn_manager_load_services (void) if (split_contents) { - int i, len; - NMVPNService *service = nm_vpn_service_new (); - gboolean have_name = FALSE; - gboolean have_program = FALSE; + int i, len; + NMVPNService * service = nm_vpn_service_new (); + gboolean have_name = FALSE; + gboolean have_service = FALSE; + gboolean have_program = FALSE; len = g_strv_length (split_contents); for (i = 0; i < len; i++) { char *line = split_contents[i]; + #define NAME_TAG "name=" #define SERVICE_TAG "service=" #define PROGRAM_TAG "program=" @@ -781,44 +802,61 @@ static GSList *nm_vpn_manager_load_services (void) /* Comment lines begin with # */ if (line[0] == '#') continue; - if (strlen (line) > 8) + if ((strncmp (line, NAME_TAG, strlen (NAME_TAG)) == 0) && !have_name) { - if ((strncmp (line, SERVICE_TAG, strlen (SERVICE_TAG)) == 0) && !have_name) - { - char *service_name = g_strdup (line+strlen (SERVICE_TAG)); + char * name = g_strdup (line+strlen (NAME_TAG)); + GSList * dup_elt; + gboolean found = FALSE; - /* Deny the load if the service name is NetworkManager or NetworkManagerInfo. */ - if (strcmp (service_name, NM_DBUS_SERVICE) && strcmp (service_name, NM_DBUS_SERVICE)) - nm_vpn_service_set_name (service, (const char *)service_name); - else - nm_warning ("VPN service name matched NetworkManager or NetworkManagerInfo service names, " - "which is not allowed and might be malicious."); - g_free (service_name); - have_name = TRUE; - } - else if ((strncmp (line, PROGRAM_TAG, strlen (PROGRAM_TAG)) == 0) && !have_program) + for (dup_elt = list; dup_elt; dup_elt = g_slist_next (dup_elt)) { - gboolean program_ok = FALSE; - if ((strlen (line) >= strlen (PROGRAM_TAG) + 1)) + NMVPNService *dup_svc = (NMVPNService *)(dup_elt->data); + if (dup_svc && nm_vpn_service_get_name (dup_svc) && !strcmp (nm_vpn_service_get_name (dup_svc), name)) { - if ((*(line+strlen (PROGRAM_TAG)) == '/') && (*(line+strlen (line)-1) != '/')) - { - nm_vpn_service_set_program (service, (const char *)(line+strlen (PROGRAM_TAG))); - program_ok = TRUE; - } + found = TRUE; + break; } - if (!program_ok) - nm_warning ("WARNING: VPN program '%s' invalid in file '%s'", line, file_path); - have_program = TRUE; } + if (!found) + nm_vpn_service_set_name (service, (const char *)name); + g_free (name); + have_name = TRUE; + } + else if ((strncmp (line, SERVICE_TAG, strlen (SERVICE_TAG)) == 0) && !have_service) + { + char *service_name = g_strdup (line+strlen (SERVICE_TAG)); + + /* Deny the load if the service name is NetworkManager or NetworkManagerInfo. */ + if (strcmp (service_name, NM_DBUS_SERVICE) && strcmp (service_name, NM_DBUS_SERVICE)) + nm_vpn_service_set_service_name (service, (const char *)service_name); + else + nm_warning ("VPN service name matched NetworkManager or NetworkManagerInfo service names, " + "which is not allowed and might be malicious."); + g_free (service_name); + have_service = TRUE; + } + else if ((strncmp (line, PROGRAM_TAG, strlen (PROGRAM_TAG)) == 0) && !have_program) + { + gboolean program_ok = FALSE; + if ((strlen (line) >= strlen (PROGRAM_TAG) + 1)) + { + if ((*(line+strlen (PROGRAM_TAG)) == '/') && (*(line+strlen (line)-1) != '/')) + { + nm_vpn_service_set_program (service, (const char *)(line+strlen (PROGRAM_TAG))); + program_ok = TRUE; + } + } + if (!program_ok) + nm_warning ("WARNING: VPN program '%s' invalid in file '%s'", line, file_path); + have_program = TRUE; } } g_strfreev (split_contents); - if (nm_vpn_service_get_name (service) && nm_vpn_service_get_program (service)) + if (nm_vpn_service_get_name (service) && nm_vpn_service_get_service_name (service) && nm_vpn_service_get_program (service)) { - nm_info ("Adding VPN service '%s' with program '%s'", nm_vpn_service_get_name (service), - nm_vpn_service_get_program (service)); + nm_info ("Adding VPN service '%s' with name '%s' and program '%s'", nm_vpn_service_get_service_name (service), + nm_vpn_service_get_name (service), nm_vpn_service_get_program (service)); list = g_slist_append (list, service); } else diff --git a/src/vpn-manager/nm-vpn-manager.h b/src/vpn-manager/nm-vpn-manager.h index 37e887e9f..f0e7c6c49 100644 --- a/src/vpn-manager/nm-vpn-manager.h +++ b/src/vpn-manager/nm-vpn-manager.h @@ -28,6 +28,7 @@ NMVPNManager * nm_vpn_manager_new (NMData *app_data); void nm_vpn_manager_clear_connections (NMVPNManager *manager); NMVPNConnection * nm_vpn_manager_add_connection (NMVPNManager *manager, const char *name, const char *service_name, const char *user_name); +void nm_vpn_manager_remove_connection (NMVPNManager *manager, NMVPNConnection *vpn); char ** nm_vpn_manager_get_connection_names (NMVPNManager *manager); void nm_vpn_manager_dispose (NMVPNManager *manager); diff --git a/src/vpn-manager/nm-vpn-service.c b/src/vpn-manager/nm-vpn-service.c index 5200fbfee..8b97e6f9e 100644 --- a/src/vpn-manager/nm-vpn-service.c +++ b/src/vpn-manager/nm-vpn-service.c @@ -30,6 +30,7 @@ struct NMVPNService { int refcount; char *name; + char *service; char *program; NMVPNState state; }; @@ -61,6 +62,7 @@ void nm_vpn_service_unref (NMVPNService *service) if (service->refcount <= 0) { g_free (service->name); + g_free (service->service); g_free (service->program); memset (service, 0, sizeof (NMVPNService)); g_free (service); @@ -86,6 +88,24 @@ void nm_vpn_service_set_name (NMVPNService *service, const char *name) } +const char *nm_vpn_service_get_service_name (NMVPNService *service) +{ + g_return_val_if_fail (service != NULL, NULL); + + return service->service; +} + + +void nm_vpn_service_set_service_name (NMVPNService *service, const char *name) +{ + g_return_if_fail (service != NULL); + + if (service->service) + g_free (service->service); + service->service = g_strdup (name); +} + + const char *nm_vpn_service_get_program (NMVPNService *service) { g_return_val_if_fail (service != NULL, NULL); @@ -138,12 +158,12 @@ gboolean nm_vpn_service_exec_daemon (NMVPNService *service) if (!g_spawn_async (NULL, (char **) vpn_argv->pdata, NULL, 0, NULL, NULL, &pid, &error)) { g_ptr_array_free (vpn_argv, TRUE); - nm_warning ("Could not activate the VPN service '%s'. error: '%s'.", nm_vpn_service_get_name (service), error->message); + nm_warning ("Could not activate the VPN service '%s'. error: '%s'.", nm_vpn_service_get_service_name (service), error->message); g_error_free (error); return FALSE; } g_ptr_array_free (vpn_argv, TRUE); - nm_info ("Activated the VPN service '%s' with PID %d.", nm_vpn_service_get_name (service), pid); + nm_info ("Activated the VPN service '%s' with PID %d.", nm_vpn_service_get_service_name (service), pid); /* Wait a bit for the daemon to start up */ /* FIXME: don't sleep, keep retrying dbus message or something */ diff --git a/src/vpn-manager/nm-vpn-service.h b/src/vpn-manager/nm-vpn-service.h index 0b221c5f0..70a9b1605 100644 --- a/src/vpn-manager/nm-vpn-service.h +++ b/src/vpn-manager/nm-vpn-service.h @@ -29,20 +29,23 @@ typedef struct NMVPNService NMVPNService; -NMVPNService * nm_vpn_service_new (void); +NMVPNService * nm_vpn_service_new (void); -void nm_vpn_service_ref (NMVPNService *service); -void nm_vpn_service_unref (NMVPNService *service); +void nm_vpn_service_ref (NMVPNService *service); +void nm_vpn_service_unref (NMVPNService *service); -const char * nm_vpn_service_get_name (NMVPNService *service); -void nm_vpn_service_set_name (NMVPNService *service, const char *name); +const char * nm_vpn_service_get_name (NMVPNService *service); +void nm_vpn_service_set_name (NMVPNService *service, const char *name); -const char * nm_vpn_service_get_program (NMVPNService *service); -void nm_vpn_service_set_program (NMVPNService *service, const char *program); +const char * nm_vpn_service_get_service_name (NMVPNService *service); +void nm_vpn_service_set_service_name (NMVPNService *service, const char *name); -NMVPNState nm_vpn_service_get_state (NMVPNService *service); -void nm_vpn_service_set_state (NMVPNService *service, const NMVPNState state); +const char * nm_vpn_service_get_program (NMVPNService *service); +void nm_vpn_service_set_program (NMVPNService *service, const char *program); -gboolean nm_vpn_service_exec_daemon (NMVPNService *service); +NMVPNState nm_vpn_service_get_state (NMVPNService *service); +void nm_vpn_service_set_state (NMVPNService *service, const NMVPNState state); + +gboolean nm_vpn_service_exec_daemon (NMVPNService *service); #endif diff --git a/test/Makefile.am b/test/Makefile.am index 6e04db838..2af339bea 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,4 +1,4 @@ -INCLUDES = -I${top_srcdir} -I${top_srcdir}/libnm_glib -I${top_srcdir}/utils +INCLUDES = -I${top_srcdir} -I${top_srcdir}/gnome/libnm_glib -I${top_srcdir}/utils AM_CPPFLAGS = \ $(DBUS_CFLAGS) \ @@ -26,7 +26,7 @@ nmtestdevices_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) \ libnm_glib_test_SOURCES = libnm_glib_test.c libnm_glib_test_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) \ $(top_builddir)/utils/libnmutils.la \ - ../libnm_glib/libnm_glib.la + ../gnome/libnm_glib/libnm_glib.la nm_dhcp_opt_test_SOURCES = nm-dhcp-opt-test.c diff --git a/test/libnm_glib_test.c b/test/libnm_glib_test.c index 7e7039c11..93ae67472 100644 --- a/test/libnm_glib_test.c +++ b/test/libnm_glib_test.c @@ -28,12 +28,12 @@ void status_printer (libnm_glib_ctx *ctx, gpointer user_data) { - libnm_glib_status status; + libnm_glib_state state; g_return_if_fail (ctx != NULL); - status = libnm_glib_get_network_status (ctx); - switch (status) + state = libnm_glib_get_network_state (ctx); + switch (state) { case LIBNM_NO_DBUS: fprintf (stderr, "Status: No DBUS\n"); diff --git a/test/nmtest.c b/test/nmtest.c index 720d352f0..3404c6f15 100644 --- a/test/nmtest.c +++ b/test/nmtest.c @@ -243,16 +243,16 @@ int get_object_signal_strength (DBusConnection *connection, char *path) } -char * get_nm_status (DBusConnection *connection) +NMState get_nm_state (DBusConnection *connection) { - int ret; - char *status = NULL; + int ret; + NMState state; - ret = nmwa_dbus_call_nm_method (connection, NM_DBUS_PATH, "status", DBUS_TYPE_STRING, (void *)(&status), NULL); + ret = nmwa_dbus_call_nm_method (connection, NM_DBUS_PATH, "state", DBUS_TYPE_UINT32, (void *)(&state), NULL); if (ret == RETURN_SUCCESS) - return (status); + return (state); - return (NULL); + return (NM_STATE_UNKNOWN); } @@ -383,8 +383,8 @@ int main( int argc, char *argv[] ) { DBusConnection *connection; DBusError error; - char *path; - char *status; + char * path; + NMState state; g_type_init (); @@ -397,14 +397,13 @@ int main( int argc, char *argv[] ) return 1; } - status = get_nm_status (connection); - if (!status) + state = get_nm_state (connection); + if (state == NM_STATE_UNKNOWN) { - fprintf (stderr, "NetworkManager appears not to be running (could not get its status). Will exit.\n"); + fprintf (stderr, "NetworkManager appears not to be running (could not get its state). Will exit.\n"); return (1); } - fprintf (stderr, "NM Status: '%s'\n", status); - g_free (status); + fprintf (stderr, "NM State: '%u'\n", state); path = get_active_device (connection); fprintf (stderr, "Active device: '%s'\n", path ? path : "(none)"); diff --git a/vpn-daemons/vpnc/nm-vpnc-service.name b/vpn-daemons/vpnc/nm-vpnc-service.name index 4d79390a2..625440c65 100644 --- a/vpn-daemons/vpnc/nm-vpnc-service.name +++ b/vpn-daemons/vpnc/nm-vpnc-service.name @@ -1,2 +1,3 @@ +name=vpnc service=org.freedesktop.vpnc program=/usr/bin/nm-vpnc-service