network-manager-applet r1252 - in trunk: . src/wireless-security



Author: dcbw
Date: Sat Apr  4 15:31:42 2009
New Revision: 1252
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=1252&view=rev

Log:
2009-04-04  Dan Williams  <dcbw redhat com>

	* src/connection-editor/helpers.c
	  src/connection-editor/helpers.h
		- Small helper to fill UI widgets from connection secrets

	* src/connection-editor/Makefile.am
	  src/connection-editor/Makefile.am
	  src/connection-editor/eap-method-leap.c
	  src/connection-editor/eap-method-simple.c
	  src/connection-editor/eap-method-tls.c
	  src/connection-editor/ws-leap.c
	  src/connection-editor/ws-wep-key.c
	  src/connection-editor/ws-wpa-psk.c
		- Handle system connection secrets too



Added:
   trunk/src/wireless-security/helpers.c
   trunk/src/wireless-security/helpers.h
Modified:
   trunk/ChangeLog
   trunk/src/wireless-security/Makefile.am
   trunk/src/wireless-security/eap-method-leap.c
   trunk/src/wireless-security/eap-method-simple.c
   trunk/src/wireless-security/eap-method-tls.c
   trunk/src/wireless-security/ws-leap.c
   trunk/src/wireless-security/ws-wep-key.c
   trunk/src/wireless-security/ws-wpa-psk.c

Modified: trunk/src/wireless-security/Makefile.am
==============================================================================
--- trunk/src/wireless-security/Makefile.am	(original)
+++ trunk/src/wireless-security/Makefile.am	Sat Apr  4 15:31:42 2009
@@ -26,7 +26,9 @@
 	eap-method-peap.h \
 	eap-method-peap.c \
 	eap-method-simple.h \
-	eap-method-simple.c
+	eap-method-simple.c \
+	helpers.h \
+	helpers.c
 
 libwireless_security_la_CPPFLAGS = \
 	$(NMA_CFLAGS) \

Modified: trunk/src/wireless-security/eap-method-leap.c
==============================================================================
--- trunk/src/wireless-security/eap-method-leap.c	(original)
+++ trunk/src/wireless-security/eap-method-leap.c	Sat Apr  4 15:31:42 2009
@@ -27,6 +27,7 @@
 #include "eap-method.h"
 #include "wireless-security.h"
 #include "gconf-helpers.h"
+#include "helpers.h"
 
 static void
 show_toggled_cb (GtkCheckButton *button, EAPMethod *method)
@@ -158,23 +159,15 @@
 	g_signal_connect (G_OBJECT (widget), "changed",
 	                  (GCallback) wireless_security_changed_cb,
 	                  parent);
+
 	/* Fill secrets, if any */
 	if (connection) {
-		GHashTable *secrets;
-		GError *error = NULL;
-		GValue *value;
-
-		secrets = nm_gconf_get_keyring_items (connection,
-		                                      NM_SETTING_802_1X_SETTING_NAME,
-		                                      TRUE,
-		                                      &error);
-		if (secrets) {
-			value = g_hash_table_lookup (secrets, NM_SETTING_802_1X_PASSWORD);
-			if (value)
-				gtk_entry_set_text (GTK_ENTRY (widget), g_value_get_string (value));
-			g_hash_table_destroy (secrets);
-		} else if (error)
-			g_error_free (error);
+		helper_fill_secret_entry (connection,
+		                          GTK_ENTRY (widget),
+		                          NM_TYPE_SETTING_802_1X,
+		                          (HelperSecretFunc) nm_setting_802_1x_get_password,
+		                          NM_SETTING_802_1X_SETTING_NAME,
+		                          NM_SETTING_802_1X_PASSWORD);
 	}
 
 	widget = glade_xml_get_widget (xml, "show_checkbutton");

Modified: trunk/src/wireless-security/eap-method-simple.c
==============================================================================
--- trunk/src/wireless-security/eap-method-simple.c	(original)
+++ trunk/src/wireless-security/eap-method-simple.c	Sat Apr  4 15:31:42 2009
@@ -27,6 +27,7 @@
 #include "eap-method.h"
 #include "wireless-security.h"
 #include "gconf-helpers.h"
+#include "helpers.h"
 
 static void
 show_toggled_cb (GtkCheckButton *button, EAPMethod *method)
@@ -181,23 +182,15 @@
 	g_signal_connect (G_OBJECT (widget), "changed",
 	                  (GCallback) wireless_security_changed_cb,
 	                  parent);
+
 	/* Fill secrets, if any */
 	if (connection) {
-		GHashTable *secrets;
-		GError *error = NULL;
-		GValue *value;
-
-		secrets = nm_gconf_get_keyring_items (connection,
-		                                      NM_SETTING_802_1X_SETTING_NAME,
-		                                      TRUE,
-		                                      &error);
-		if (secrets) {
-			value = g_hash_table_lookup (secrets, NM_SETTING_802_1X_PASSWORD);
-			if (value)
-				gtk_entry_set_text (GTK_ENTRY (widget), g_value_get_string (value));
-			g_hash_table_destroy (secrets);
-		} else if (error)
-			g_error_free (error);
+		helper_fill_secret_entry (connection,
+		                          GTK_ENTRY (widget),
+		                          NM_TYPE_SETTING_802_1X,
+		                          (HelperSecretFunc) nm_setting_802_1x_get_password,
+		                          NM_SETTING_802_1X_SETTING_NAME,
+		                          NM_SETTING_802_1X_PASSWORD);
 	}
 
 	widget = glade_xml_get_widget (xml, "show_checkbutton");

Modified: trunk/src/wireless-security/eap-method-tls.c
==============================================================================
--- trunk/src/wireless-security/eap-method-tls.c	(original)
+++ trunk/src/wireless-security/eap-method-tls.c	Sat Apr  4 15:31:42 2009
@@ -31,6 +31,7 @@
 #include "eap-method.h"
 #include "wireless-security.h"
 #include "utils.h"
+#include "helpers.h"
 
 static void
 show_toggled_cb (GtkCheckButton *button, EAPMethod *method)
@@ -390,27 +391,20 @@
 		gtk_entry_set_text (GTK_ENTRY (widget), nm_setting_802_1x_get_identity (s_8021x));
 
 	widget = glade_xml_get_widget (xml, "eap_tls_private_key_password_entry");
+	g_assert (widget);
+
 	/* Fill secrets, if any */
 	if (connection) {
-		GHashTable *secrets;
-		GError *error = NULL;
-		GValue *value;
-		const char *pw_secret_name = phase2 ? NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD :
-		                                      NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD;
-
-		secrets = nm_gconf_get_keyring_items (connection,
-		                                      NM_SETTING_802_1X_SETTING_NAME,
-		                                      TRUE,
-		                                      &error);
-		if (secrets) {
-			value = g_hash_table_lookup (secrets, pw_secret_name);
-			if (value)
-				gtk_entry_set_text (GTK_ENTRY (widget), g_value_get_string (value));
-			g_hash_table_destroy (secrets);
-		}
-		g_clear_error (&error);
+		helper_fill_secret_entry (connection,
+		                          GTK_ENTRY (widget),
+		                          NM_TYPE_SETTING_802_1X,
+		                          phase2 ? (HelperSecretFunc) nm_setting_802_1x_get_phase2_private_key_password :
+		                                   (HelperSecretFunc) nm_setting_802_1x_get_private_key_password,
+		                          NM_SETTING_802_1X_SETTING_NAME,
+		                          phase2 ? NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD :
+		                                   NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD);
 	}
-	g_assert (widget);
+
 	g_signal_connect (G_OBJECT (widget), "changed",
 	                  (GCallback) wireless_security_changed_cb,
 	                  parent);

Added: trunk/src/wireless-security/helpers.c
==============================================================================
--- (empty file)
+++ trunk/src/wireless-security/helpers.c	Sat Apr  4 15:31:42 2009
@@ -0,0 +1,66 @@
+/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
+ *
+ * Dan Williams <dcbw redhat com>
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * (C) Copyright 2009 Red Hat, Inc.
+ */
+
+#include "helpers.h"
+#include "gconf-helpers.h"
+
+void
+helper_fill_secret_entry (NMConnection *connection,
+                          GtkEntry *entry,
+                          GType setting_type,
+                          HelperSecretFunc func,
+                          const char *setting_name,
+                          const char *secret_name)
+{
+	NMSetting *setting;
+	GHashTable *secrets;
+	GError *error = NULL;
+	GValue *value;
+	const char *tmp;
+
+	g_return_if_fail (connection != NULL);
+	g_return_if_fail (entry != NULL);
+	g_return_if_fail (func != NULL);
+	g_return_if_fail (setting_name != NULL);
+	g_return_if_fail (secret_name != NULL);
+
+	setting = nm_connection_get_setting (connection, setting_type);
+
+	if (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM) {
+		if (setting) {
+			tmp = (*func) (setting);
+			if (tmp)
+				gtk_entry_set_text (entry, tmp);
+		}
+	} else {
+		secrets = nm_gconf_get_keyring_items (connection, setting_name, FALSE, &error);
+		if (!secrets) {
+			g_clear_error (&error);
+			return;
+		}
+
+		value = g_hash_table_lookup (secrets, secret_name);
+		if (value)
+			gtk_entry_set_text (entry, g_value_get_string (value));
+		g_hash_table_destroy (secrets);
+	}
+}
+

Added: trunk/src/wireless-security/helpers.h
==============================================================================
--- (empty file)
+++ trunk/src/wireless-security/helpers.h	Sat Apr  4 15:31:42 2009
@@ -0,0 +1,40 @@
+/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
+ *
+ * Dan Williams <dcbw redhat com>
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * (C) Copyright 2009 Red Hat, Inc.
+ */
+
+#ifndef _HELPERS_H_
+#define _HELPERS_H_
+
+#include <glib.h>
+#include <gtk/gtk.h>
+#include <nm-connection.h>
+#include <nm-setting.h>
+
+typedef const char * (*HelperSecretFunc)(NMSetting *);
+
+void helper_fill_secret_entry (NMConnection *connection,
+                               GtkEntry *entry,
+                               GType setting_type,
+                               HelperSecretFunc func,
+                               const char *setting_name,
+                               const char *secret_name);
+
+#endif  /* _HELPERS_H_ */
+

Modified: trunk/src/wireless-security/ws-leap.c
==============================================================================
--- trunk/src/wireless-security/ws-leap.c	(original)
+++ trunk/src/wireless-security/ws-leap.c	Sat Apr  4 15:31:42 2009
@@ -26,6 +26,7 @@
 #include "wireless-security.h"
 #include "utils.h"
 #include "gconf-helpers.h"
+#include "helpers.h"
 
 
 static void
@@ -166,21 +167,12 @@
 	                  (GCallback) wireless_security_changed_cb,
 	                  sec);
 	if (wsec) {
-		GHashTable *secrets;
-		GError *error = NULL;
-		GValue *value;
-
-		secrets = nm_gconf_get_keyring_items (connection,
-		                                      NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
-		                                      FALSE,
-		                                      &error);
-		if (secrets) {
-			value = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD);
-			if (value)
-				gtk_entry_set_text (GTK_ENTRY (widget), g_value_get_string (value));
-			g_hash_table_destroy (secrets);
-		} else if (error)
-			g_error_free (error);
+		helper_fill_secret_entry (connection,
+		                          GTK_ENTRY (widget),
+		                          NM_TYPE_SETTING_WIRELESS_SECURITY,
+		                          (HelperSecretFunc) nm_setting_wireless_security_get_leap_password,
+		                          NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
+		                          NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD);
 	}
 
 	widget = glade_xml_get_widget (xml, "leap_username_entry");

Modified: trunk/src/wireless-security/ws-wep-key.c
==============================================================================
--- trunk/src/wireless-security/ws-wep-key.c	(original)
+++ trunk/src/wireless-security/ws-wep-key.c	Sat Apr  4 15:31:42 2009
@@ -251,6 +251,57 @@
 	g_free (result);
 }
 
+static void
+fill_secrets (WirelessSecurityWEPKey *sec, NMConnection *connection)
+{
+	NMSettingWirelessSecurity *s_wsec;
+	GHashTable *secrets;
+	GError *error = NULL;
+	GValue *value;
+	const char *tmp;
+	int i;
+
+	g_return_if_fail (sec != NULL);
+	g_return_if_fail (connection != NULL);
+
+	s_wsec = (NMSettingWirelessSecurity *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY);
+
+	if (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM) {
+		for (i = 0; s_wsec && i < 4; i++) {
+			tmp = nm_setting_wireless_security_get_wep_key (s_wsec, i);
+			if (tmp)
+				strcpy (sec->keys[i], tmp);
+		}
+	} else {
+		secrets = nm_gconf_get_keyring_items (connection,
+		                                      NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
+		                                      FALSE,
+		                                      &error);
+		if (!secrets) {
+			g_clear_error (&error);
+			return;
+		}
+
+		value = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0);
+		if (value)
+			strcpy (sec->keys[0], g_value_get_string (value));
+
+		value = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY1);
+		if (value)
+			strcpy (sec->keys[1], g_value_get_string (value));
+
+		value = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY2);
+		if (value)
+			strcpy (sec->keys[2], g_value_get_string (value));
+
+		value = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY3);
+		if (value)
+			strcpy (sec->keys[3], g_value_get_string (value));
+
+		g_hash_table_destroy (secrets);
+	}
+}
+
 WirelessSecurityWEPKey *
 ws_wep_key_new (const char *glade_file,
                 NMConnection *connection,
@@ -296,42 +347,13 @@
 	widget = glade_xml_get_widget (xml, "wep_key_entry");
 	g_assert (widget);
 
-	/* Fill secrets, if any */
-	if (connection) {
-		GHashTable *secrets;
-		GError *error = NULL;
-		GValue *value;
-
-		secrets = nm_gconf_get_keyring_items (connection,
-		                                      NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
-		                                      FALSE,
-		                                      &error);
-		if (secrets) {
-			value = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0);
-			if (value)
-				strcpy (sec->keys[0], g_value_get_string (value));
-
-			value = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY1);
-			if (value)
-				strcpy (sec->keys[1], g_value_get_string (value));
-
-			value = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY2);
-			if (value)
-				strcpy (sec->keys[2], g_value_get_string (value));
-
-			value = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY3);
-			if (value)
-				strcpy (sec->keys[3], g_value_get_string (value));
-
-			g_hash_table_destroy (secrets);
-		} else if (error)
-			g_error_free (error);
-	}
-
 	if (connection) {
 		NMSettingWireless *s_wireless;
 		const char *mode, *auth_alg;
 
+		/* Fill secrets, if any */
+		fill_secrets (sec, connection);
+
 		s_wireless = (NMSettingWireless *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS);
 		mode = s_wireless ? nm_setting_wireless_get_mode (s_wireless) : NULL;
 		if (mode && !strcmp (mode, "adhoc"))

Modified: trunk/src/wireless-security/ws-wpa-psk.c
==============================================================================
--- trunk/src/wireless-security/ws-wpa-psk.c	(original)
+++ trunk/src/wireless-security/ws-wpa-psk.c	Sat Apr  4 15:31:42 2009
@@ -28,6 +28,7 @@
 #include "utils.h"
 #include "sha1.h"
 #include "gconf-helpers.h"
+#include "helpers.h"
 
 #define WPA_PMK_LEN 32
 
@@ -200,21 +201,12 @@
 
 	/* Fill secrets, if any */
 	if (connection) {
-		GHashTable *secrets;
-		GError *error = NULL;
-		GValue *value;
-
-		secrets = nm_gconf_get_keyring_items (connection,
-		                                      NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
-		                                      FALSE,
-		                                      &error);
-		if (secrets) {
-			value = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_PSK);
-			if (value)
-				gtk_entry_set_text (GTK_ENTRY (widget), g_value_get_string (value));
-			g_hash_table_destroy (secrets);
-		} else if (error)
-			g_error_free (error);
+		helper_fill_secret_entry (connection,
+		                          GTK_ENTRY (widget),
+		                          NM_TYPE_SETTING_WIRELESS_SECURITY,
+		                          (HelperSecretFunc) nm_setting_wireless_security_get_psk,
+		                          NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
+		                          NM_SETTING_WIRELESS_SECURITY_PSK);
 	}
 
 	widget = glade_xml_get_widget (xml, "show_checkbutton");



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]