NetworkManager r3923 - in trunk: libnm-util src/vpn-manager system-settings/plugins/keyfile



Author: dcbw
Date: Mon Aug 11 17:13:22 2008
New Revision: 3923
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3923&view=rev

Log:
2008-08-11  Dan Williams  <dcbw redhat com>

	Merge the vpn-properties setting with the vpn setting since it was pointless
	to keep both of them around.  Convert the vpn 'data' hash table to a hash
	of string:string (instead of string:variant) so that system settings plugins
	can have an easier time dealing with the arbitrary key/value pairs.



Removed:
   trunk/libnm-util/nm-setting-vpn-properties.c
   trunk/libnm-util/nm-setting-vpn-properties.h
Modified:
   trunk/libnm-util/Makefile.am
   trunk/libnm-util/nm-connection.c
   trunk/libnm-util/nm-setting-vpn.c
   trunk/libnm-util/nm-setting-vpn.h
   trunk/src/vpn-manager/nm-vpn-connection.c
   trunk/system-settings/plugins/keyfile/reader.c
   trunk/system-settings/plugins/keyfile/writer.c

Modified: trunk/libnm-util/Makefile.am
==============================================================================
--- trunk/libnm-util/Makefile.am	(original)
+++ trunk/libnm-util/Makefile.am	Mon Aug 11 17:13:22 2008
@@ -24,7 +24,6 @@
 	nm-setting-wireless.h		\
 	nm-setting-wireless-security.h	\
 	nm-setting-vpn.h		\
-	nm-setting-vpn-properties.h	\
 	nm-utils.h
 
 libnm_util_la_SOURCES=			\
@@ -47,7 +46,6 @@
 	nm-setting-wireless.c		\
 	nm-setting-wireless-security.c	\
 	nm-setting-vpn.c		\
-	nm-setting-vpn-properties.c	\
 	nm-utils.c			\
 	$(libnm_util_include_HEADERS)
 

Modified: trunk/libnm-util/nm-connection.c
==============================================================================
--- trunk/libnm-util/nm-connection.c	(original)
+++ trunk/libnm-util/nm-connection.c	Mon Aug 11 17:13:22 2008
@@ -39,7 +39,6 @@
 #include "nm-setting-wireless.h"
 #include "nm-setting-wireless-security.h"
 #include "nm-setting-vpn.h"
-#include "nm-setting-vpn-properties.h"
 
 #include "nm-setting-serial.h"
 #include "nm-setting-gsm.h"
@@ -197,11 +196,6 @@
 	                      NM_SETTING_VPN_ERROR,
 	                      4);
 
-	register_one_setting (NM_SETTING_VPN_PROPERTIES_SETTING_NAME,
-	                      NM_TYPE_SETTING_VPN_PROPERTIES,
-	                      NM_SETTING_VPN_PROPERTIES_ERROR,
-	                      5);
-
 	register_one_setting (NM_SETTING_IP4_CONFIG_SETTING_NAME,
 	                      NM_TYPE_SETTING_IP4_CONFIG,
 	                      NM_SETTING_IP4_CONFIG_ERROR,

Modified: trunk/libnm-util/nm-setting-vpn.c
==============================================================================
--- trunk/libnm-util/nm-setting-vpn.c	(original)
+++ trunk/libnm-util/nm-setting-vpn.c	Mon Aug 11 17:13:22 2008
@@ -70,6 +70,7 @@
 	PROP_0,
 	PROP_SERVICE_TYPE,
 	PROP_USER_NAME,
+	PROP_DATA,
 
 	LAST_PROP
 };
@@ -114,9 +115,24 @@
 }
 
 static void
+update_one_secret (NMSetting *setting, const char *key, GValue *value)
+{
+	NMSettingVPN *self = NM_SETTING_VPN (setting);
+
+	g_return_if_fail (key != NULL);
+	g_return_if_fail (value != NULL);
+	g_return_if_fail (G_VALUE_HOLDS_STRING (value));
+
+	/* Secrets are really only known to the VPNs themselves. */
+	g_hash_table_insert (self->data, g_strdup (key), g_value_dup_string (value));
+}
+
+static void
 nm_setting_vpn_init (NMSettingVPN *setting)
 {
-	((NMSetting *) setting)->name = g_strdup (NM_SETTING_VPN_SETTING_NAME);
+	NM_SETTING (setting)->name = g_strdup (NM_SETTING_VPN_SETTING_NAME);
+
+	setting->data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
 }
 
 static void
@@ -126,11 +142,18 @@
 
 	g_free (self->service_type);
 	g_free (self->user_name);
+	g_hash_table_destroy (self->data);
 
 	G_OBJECT_CLASS (nm_setting_vpn_parent_class)->finalize (object);
 }
 
 static void
+copy_hash (gpointer key, gpointer value, gpointer user_data)
+{
+	g_hash_table_insert ((GHashTable *) user_data, g_strdup (key), g_strdup (value));
+}
+
+static void
 set_property (GObject *object, guint prop_id,
 		    const GValue *value, GParamSpec *pspec)
 {
@@ -145,6 +168,11 @@
 		g_free (setting->user_name);
 		setting->user_name = g_value_dup_string (value);
 		break;
+	case PROP_DATA:
+		/* Must make a deep copy of the hash table here... */
+		g_hash_table_remove_all (setting->data);
+		g_hash_table_foreach (g_value_get_boxed (value), copy_hash, setting->data);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -164,6 +192,9 @@
 	case PROP_USER_NAME:
 		g_value_set_string (value, setting->user_name);
 		break;
+	case PROP_DATA:
+		g_value_set_boxed (value, setting->data);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -181,6 +212,7 @@
 	object_class->get_property = get_property;
 	object_class->finalize     = finalize;
 	parent_class->verify       = verify;
+	parent_class->update_one_secret = update_one_secret;
 
 	/* Properties */
 	g_object_class_install_property
@@ -198,4 +230,12 @@
 						  "User name",
 						  NULL,
 						  G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+
+	g_object_class_install_property
+		(object_class, PROP_DATA,
+		 nm_param_spec_specialized (NM_SETTING_VPN_DATA,
+							   "Data",
+							   "VPN Service specific data",
+							   DBUS_TYPE_G_MAP_OF_STRING,
+							   G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
 }

Modified: trunk/libnm-util/nm-setting-vpn.h
==============================================================================
--- trunk/libnm-util/nm-setting-vpn.h	(original)
+++ trunk/libnm-util/nm-setting-vpn.h	Mon Aug 11 17:13:22 2008
@@ -54,12 +54,27 @@
 
 #define NM_SETTING_VPN_SERVICE_TYPE "service-type"
 #define NM_SETTING_VPN_USER_NAME    "user-name"
+#define NM_SETTING_VPN_DATA         "data"
 
 typedef struct {
 	NMSetting parent;
 
 	char *service_type;
+
+	/* username of the user requesting this connection, thus
+	 * it's really only valid for user connections, and it also
+	 * should never be saved out to persistent config.
+	 */
 	char *user_name;
+
+	/* The hash table is created at setting object
+	 * init time and should not be replaced.  It is
+	 * a char * -> char * mapping, and both the key
+	 * and value are owned by the hash table, and should
+	 * be allocated with functions whose value can be
+	 * freed with g_free()
+	 */
+	GHashTable *data;
 } NMSettingVPN;
 
 typedef struct {

Modified: trunk/src/vpn-manager/nm-vpn-connection.c
==============================================================================
--- trunk/src/vpn-manager/nm-vpn-connection.c	(original)
+++ trunk/src/vpn-manager/nm-vpn-connection.c	Mon Aug 11 17:13:22 2008
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
 
 /* NetworkManager -- Network link manager
  *
@@ -35,7 +35,6 @@
 #include "nm-vpn-connection.h"
 #include "nm-setting-connection.h"
 #include "nm-setting-vpn.h"
-#include "nm-setting-vpn-properties.h"
 #include "nm-setting-ip4-config.h"
 #include "nm-dbus-manager.h"
 #include "nm-manager.h"
@@ -477,7 +476,7 @@
 		    nm_vpn_connection_get_name (connection));
 
 	if (err) {
-		nm_warning ("(VPN connection '%s' could not start.  dbus says: '%s'.", 
+		nm_warning ("(VPN connection '%s' failed to connect: '%s'.", 
 				  nm_vpn_connection_get_name (connection), err->message);
 		nm_vpn_connection_set_vpn_state (connection,
 		                                 NM_VPN_CONNECTION_STATE_FAILED,
@@ -660,11 +659,11 @@
 {
 	NMConnection *connection = NM_CONNECTION (user_data);
 
-	if (strcmp (key, NM_SETTING_VPN_PROPERTIES_SETTING_NAME))
+	if (strcmp (key, NM_SETTING_VPN_SETTING_NAME))
 		return;
 
 	nm_connection_update_secrets (connection,
-	                              NM_SETTING_VPN_PROPERTIES_SETTING_NAME,
+	                              NM_SETTING_VPN_SETTING_NAME,
 	                              (GHashTable *) data);
 }
 
@@ -802,9 +801,9 @@
 }
 
 static void
-connection_vpn_state_changed (NMVPNConnection *connection,
-                              NMVPNConnectionState state,
-                              NMVPNConnectionStateReason reason)
+connection_state_changed (NMVPNConnection *connection,
+                          NMVPNConnectionState state,
+                          NMVPNConnectionStateReason reason)
 {
 	NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
 
@@ -977,7 +976,7 @@
 	g_type_class_add_private (connection_class, sizeof (NMVPNConnectionPrivate));
 
 	/* virtual methods */
-	connection_class->vpn_state_changed = connection_vpn_state_changed;
+	connection_class->vpn_state_changed = connection_state_changed;
 	object_class->get_property = get_property;
 	object_class->dispose = dispose;
 	object_class->finalize = finalize;

Modified: trunk/system-settings/plugins/keyfile/reader.c
==============================================================================
--- trunk/system-settings/plugins/keyfile/reader.c	(original)
+++ trunk/system-settings/plugins/keyfile/reader.c	Mon Aug 11 17:13:22 2008
@@ -8,6 +8,7 @@
 #include <dbus/dbus-glib.h>
 #include <nm-setting.h>
 #include <nm-setting-ip4-config.h>
+#include <nm-setting-vpn.h>
 #include <arpa/inet.h>
 #include <string.h>
 
@@ -289,6 +290,32 @@
 }
 
 static void
+read_hash_of_string (GKeyFile *file, NMSetting *setting, const char *key)
+{
+	char **keys, **iter;
+	char *value;
+
+	keys = g_key_file_get_keys (file, setting->name, NULL, NULL);
+	if (!keys || !*keys)
+		return;
+
+	for (iter = keys; *iter; iter++) {
+		value = g_key_file_get_string (file, setting->name, *iter, NULL);
+		if (!value)
+			continue;
+
+		if (NM_IS_SETTING_VPN (setting)) {
+			NMSettingVPN *s_vpn = NM_SETTING_VPN (setting);
+
+			if (strcmp (*iter, NM_SETTING_VPN_SERVICE_TYPE))
+				g_hash_table_insert (s_vpn->data, g_strdup (*iter), g_strdup (value));
+		}
+		g_free (value);
+	}
+	g_strfreev (keys);
+}
+
+static void
 read_one_setting_value (NMSetting *setting,
 				    const char *key,
 				    const GValue *value,
@@ -395,9 +422,8 @@
 
 		g_slist_free (list);
 		g_strfreev (sa);
-	} else if (type == dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE)) {
-		/* FIXME */
-		g_warning ("Implement me");
+	} else if (type == dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING)) {
+		read_hash_of_string (file, setting, key);
 	} else if (type == DBUS_TYPE_G_UINT_ARRAY) {
 		if (!read_array_of_uint (file, setting, key)) {
 			g_warning ("Unhandled setting property type (read): '%s/%s' : '%s'",

Modified: trunk/system-settings/plugins/keyfile/writer.c
==============================================================================
--- trunk/system-settings/plugins/keyfile/writer.c	(original)
+++ trunk/system-settings/plugins/keyfile/writer.c	Mon Aug 11 17:13:22 2008
@@ -7,6 +7,7 @@
 #include <nm-setting.h>
 #include <nm-setting-connection.h>
 #include <nm-setting-ip4-config.h>
+#include <nm-setting-vpn.h>
 #include <nm-utils.h>
 #include <string.h>
 #include <arpa/inet.h>
@@ -141,6 +142,42 @@
 	return TRUE;
 }
 
+typedef struct {
+	GKeyFile *file;
+	const char *setting_name;
+} WriteStringHashInfo;
+
+static void
+write_hash_of_string_helper (gpointer key, gpointer data, gpointer user_data)
+{
+	WriteStringHashInfo *info = (WriteStringHashInfo *) user_data;
+	const char *property = (const char *) key;
+	const char *value = (const char *) data;
+
+	if (   !strcmp (info->setting_name, NM_SETTING_VPN_SETTING_NAME)
+	    && !strcmp (property, NM_SETTING_VPN_SERVICE_TYPE))
+		return;
+
+	g_key_file_set_string (info->file,
+	                       info->setting_name,
+	                       property,
+	                       value);
+}
+
+static void
+write_hash_of_string (GKeyFile *file,
+                      NMSetting *setting,
+                      const char *key,
+                      const GValue *value)
+{
+	GHashTable *hash = g_value_get_boxed (value);
+	WriteStringHashInfo info;
+
+	info.file = file;
+	info.setting_name = setting->name;
+	g_hash_table_foreach (hash, write_hash_of_string_helper, &info);
+}
+
 static void
 write_setting_value (NMSetting *setting,
 				 const char *key,
@@ -208,9 +245,8 @@
 			g_key_file_set_string_list (file, setting->name, key, (const gchar **const) array, i);
 			g_free (array);
 		}
-	} else if (type == dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE)) {
-		/* FIXME */
-		g_warning ("Implement me");
+	} else if (type == dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING)) {
+		write_hash_of_string (file, setting, key, value);
 	} else if (type == DBUS_TYPE_G_UINT_ARRAY) {
 		if (!write_array_of_uint (file, setting, key, value)) {
 			g_warning ("Unhandled setting property type (write) '%s/%s' : '%s'", 



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