NetworkManager r3829 - in trunk: . introspection src src/dhcp-manager



Author: dcbw
Date: Thu Jul 17 17:04:13 2008
New Revision: 3829
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3829&view=rev

Log:
2008-07-17  Dan Williams  <dcbw redhat com>

	* introspection/Makefile.am
	  introspection/nm-device.xml
	  introspection/nm-dhcp4-config.xml
		- Add bits for the DHCP4Config property of the device, and the DHCP4Config
			itself
	* src/nm-device-interface.c
	  src/nm-device-interface.h
		- Add the DHCP4Config property

	* src/nm-device.c
		- Keep track of DHCP4 options via a new DHCP4Config property and notify
			D-Bus clients when it changes

	* src/nm-dhcp4-config.c
	  src/nm-dhcp4-config.h
		- Simple object to store DHCP4 options, export them over D-Bus, and
			notify when they change

	* src/dhcp-manager/nm-dhcp-manager.c
	  src/dhcp-manager/nm-dhcp-manager.h
		- (nm_dhcp_manager_set_dhcp4_config, copy_dhcp4_config_option): copy and
			filter server-returned DHCP options into an NMDHCP4Config object



Added:
   trunk/introspection/nm-dhcp4-config.xml
   trunk/src/nm-dhcp4-config.c
   trunk/src/nm-dhcp4-config.h
Modified:
   trunk/ChangeLog
   trunk/introspection/Makefile.am
   trunk/introspection/nm-device.xml
   trunk/src/Makefile.am
   trunk/src/dhcp-manager/nm-dhcp-manager.c
   trunk/src/dhcp-manager/nm-dhcp-manager.h
   trunk/src/nm-device-interface.c
   trunk/src/nm-device-interface.h
   trunk/src/nm-device.c

Modified: trunk/introspection/Makefile.am
==============================================================================
--- trunk/introspection/Makefile.am	(original)
+++ trunk/introspection/Makefile.am	Thu Jul 17 17:04:13 2008
@@ -15,5 +15,6 @@
 	nm-vpn-plugin.xml				\
 	nm-vpn-connection.xml			\
 	nm-ppp-manager.xml \
-	nm-active-connection.xml
+	nm-active-connection.xml \
+	nm-dhcp4-config.xml
 

Modified: trunk/introspection/nm-device.xml
==============================================================================
--- trunk/introspection/nm-device.xml	(original)
+++ trunk/introspection/nm-device.xml	Thu Jul 17 17:04:13 2008
@@ -37,6 +37,11 @@
         Object path of the Ip4Config object describing the configuration of the device.  Only valid when the device is in the NM_DEVICE_STATE_ACTIVATED state.
       </tp:docstring>
     </property>
+    <property name="Dhcp4Config" type="o" access="read">
+      <tp:docstring>
+        Object path of the Dhcp4Config object describing the DHCP options returned by the DHCP server.  Only valid when the device is in the NM_DEVICE_STATE_ACTIVATED state.
+      </tp:docstring>
+    </property>
     <property name="Managed" type="b" access="read">
       <tp:docstring>
         Whether or not this device is managed by NetworkManager.

Added: trunk/introspection/nm-dhcp4-config.xml
==============================================================================
--- (empty file)
+++ trunk/introspection/nm-dhcp4-config.xml	Thu Jul 17 17:04:13 2008
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0";>
+    <interface name="org.freedesktop.NetworkManager.DHCP4Config">
+        <tp:docstring>
+            Options and configuration returned by the IPv4 DHCP server.
+        </tp:docstring>
+        <property name="Options" type="a{sv}" access="read">
+            <tp:docstring>Configuration options returned by a DHCP server, if any.</tp:docstring>
+        </property>
+
+        <signal name="PropertiesChanged">
+            <arg name="properties" type="a{sv}" tp:type="String_Variant_Map">
+                <tp:docstring>
+                    A dictionary mapping property names to variant boxed values
+                </tp:docstring>
+            </arg>
+        </signal>
+    </interface>
+</node>

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Thu Jul 17 17:04:13 2008
@@ -68,7 +68,9 @@
 		wpa.c				\
 		wpa.h				\
 		nm-netlink.c			\
-		nm-netlink.h
+		nm-netlink.h \
+		nm-dhcp4-config.c \
+		nm-dhcp4-config.h
 
 nm-access-point-glue.h: $(top_srcdir)/introspection/nm-access-point.xml
 	dbus-binding-tool --prefix=nm_access_point --mode=glib-server --output=$@ $<
@@ -100,6 +102,9 @@
 nm-active-connection-glue.h: $(top_srcdir)/introspection/nm-active-connection.xml
 	dbus-binding-tool --prefix=nm_active_connection --mode=glib-server --output=$@ $<
 
+nm-dhcp4-config-glue.h: $(top_srcdir)/introspection/nm-dhcp4-config.xml
+	dbus-binding-tool --prefix=nm_dhcp4_config --mode=glib-server --output=$@ $<
+
 BUILT_SOURCES = 					\
 	nm-access-point-glue.h				\
 	nm-manager-glue.h				\
@@ -110,7 +115,8 @@
 	nm-cdma-device-glue.h \
 	nm-gsm-device-glue.h \
 	nm-ip4-config-glue.h				\
-	nm-active-connection-glue.h
+	nm-active-connection-glue.h \
+	nm-dhcp4-config-glue.h
 
 NetworkManager_CPPFLAGS = 							\
 	$(DBUS_CFLAGS)									\

Modified: trunk/src/dhcp-manager/nm-dhcp-manager.c
==============================================================================
--- trunk/src/dhcp-manager/nm-dhcp-manager.c	(original)
+++ trunk/src/dhcp-manager/nm-dhcp-manager.c	Thu Jul 17 17:04:13 2008
@@ -881,3 +881,67 @@
 
 	return NULL;
 }
+
+#define NEW_TAG "new_"
+#define OLD_TAG "old_"
+
+static void
+copy_dhcp4_config_option (gpointer key,
+                          gpointer value,
+                          gpointer user_data)
+{
+	NMDHCP4Config *config = NM_DHCP4_CONFIG (user_data);
+	char *tmp_key = NULL;
+	const char **p;
+	static const char *filter_options[] = {
+		"interface", "pid", "reason", NULL
+	};
+	
+	/* Filter out stuff that's not actually new DHCP options */
+	for (p = filter_options; *p; p++) {
+		if (!strcmp (*p, (const char *) key))
+			return;
+		if (!strncmp ((const char *) key, OLD_TAG, strlen (OLD_TAG)))
+			return;
+	}
+
+	/* Remove the "new_" prefix that dhclient passes back */
+	if (!strncmp ((const char *) key, NEW_TAG, strlen (NEW_TAG)))
+		tmp_key = g_strdup ((const char *) (key + strlen (NEW_TAG)));
+	else
+		tmp_key = g_strdup ((const char *) key);
+
+	nm_dhcp4_config_add_option (config, tmp_key, (const char *) value);
+	g_free (tmp_key);
+}
+
+gboolean
+nm_dhcp_manager_set_dhcp4_config (NMDHCPManager *self,
+                                  const char *iface,
+                                  NMDHCP4Config *config)
+{
+	NMDHCPManagerPrivate *priv;
+	NMDHCPDevice *device;
+
+	g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), FALSE);
+	g_return_val_if_fail (iface != NULL, FALSE);
+	g_return_val_if_fail (config != NULL, FALSE);
+
+	priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
+
+	device = (NMDHCPDevice *) g_hash_table_lookup (priv->devices, iface);
+	if (!device) {
+		nm_warning ("Device '%s' transaction not started.", iface);
+		return FALSE;
+	}
+
+	if (!state_is_bound (device->state)) {
+		nm_warning ("%s: dhclient didn't bind to a lease.", device->iface);
+		return FALSE;
+	}
+
+	nm_dhcp4_config_reset (config);
+	g_hash_table_foreach (device->options, copy_dhcp4_config_option, config);
+	return TRUE;
+}
+

Modified: trunk/src/dhcp-manager/nm-dhcp-manager.h
==============================================================================
--- trunk/src/dhcp-manager/nm-dhcp-manager.h	(original)
+++ trunk/src/dhcp-manager/nm-dhcp-manager.h	Thu Jul 17 17:04:13 2008
@@ -27,6 +27,7 @@
 #include <nm-setting-ip4-config.h>
 
 #include "nm-ip4-config.h"
+#include "nm-dhcp4-config.h"
 
 #define NM_DHCP_MANAGER_RUN_DIR		LOCALSTATEDIR "/run"
 
@@ -94,6 +95,10 @@
 NMIP4Config *  nm_dhcp_manager_get_ip4_config       (NMDHCPManager *manager, const char *iface);
 NMDHCPState    nm_dhcp_manager_get_state_for_device (NMDHCPManager *manager, const char *iface);
 
+gboolean       nm_dhcp_manager_set_dhcp4_config     (NMDHCPManager *manager,
+                                                     const char *iface,
+                                                     NMDHCP4Config *config);
+
 gboolean       nm_dhcp_manager_process_signal       (NMDHCPManager *manager, DBusMessage *message);
 
 gboolean       nm_dhcp_client_start                 (NMDHCPDevice *device, NMSettingIP4Config *s_ip4);

Modified: trunk/src/nm-device-interface.c
==============================================================================
--- trunk/src/nm-device-interface.c	(original)
+++ trunk/src/nm-device-interface.c	Thu Jul 17 17:04:13 2008
@@ -3,7 +3,6 @@
 #include "nm-marshal.h"
 #include "nm-setting-connection.h"
 #include "nm-device-interface.h"
-#include "nm-ip4-config.h"
 #include "nm-utils.h"
 
 #include "nm-device-interface-glue.h"
@@ -99,6 +98,14 @@
 
 	g_object_interface_install_property
 		(g_iface,
+		 g_param_spec_object (NM_DEVICE_INTERFACE_DHCP4_CONFIG,
+							  "DHCP4 Config",
+							  "DHCP4 Config",
+							  G_TYPE_OBJECT,
+							  G_PARAM_READWRITE));
+
+	g_object_interface_install_property
+		(g_iface,
 		 g_param_spec_uint (NM_DEVICE_INTERFACE_STATE,
 							"State",
 							"State",

Modified: trunk/src/nm-device-interface.h
==============================================================================
--- trunk/src/nm-device-interface.h	(original)
+++ trunk/src/nm-device-interface.h	Thu Jul 17 17:04:13 2008
@@ -27,6 +27,7 @@
 #define NM_DEVICE_INTERFACE_CAPABILITIES "capabilities"
 #define NM_DEVICE_INTERFACE_IP4_ADDRESS "ip4-address"
 #define NM_DEVICE_INTERFACE_IP4_CONFIG "ip4-config"
+#define NM_DEVICE_INTERFACE_DHCP4_CONFIG "dhcp4-config"
 #define NM_DEVICE_INTERFACE_STATE "state"
 #define NM_DEVICE_INTERFACE_DEVICE_TYPE "device-type" /* ugh */
 #define NM_DEVICE_INTERFACE_MANAGED "managed"
@@ -40,6 +41,7 @@
 	NM_DEVICE_INTERFACE_PROP_CAPABILITIES,
 	NM_DEVICE_INTERFACE_PROP_IP4_ADDRESS,
 	NM_DEVICE_INTERFACE_PROP_IP4_CONFIG,
+	NM_DEVICE_INTERFACE_PROP_DHCP4_CONFIG,
 	NM_DEVICE_INTERFACE_PROP_STATE,
 	NM_DEVICE_INTERFACE_PROP_DEVICE_TYPE,
 	NM_DEVICE_INTERFACE_PROP_MANAGED,

Modified: trunk/src/nm-device.c
==============================================================================
--- trunk/src/nm-device.c	(original)
+++ trunk/src/nm-device.c	Thu Jul 17 17:04:13 2008
@@ -48,6 +48,7 @@
 #include "nm-setting-ip4-config.h"
 #include "nm-setting-connection.h"
 #include "nm-dnsmasq-manager.h"
+#include "nm-dhcp4-config.h"
 
 #define NM_ACT_REQUEST_IP4_CONFIG "nm-act-request-ip4-config"
 
@@ -90,6 +91,7 @@
 	NMDHCPManager *     dhcp_manager;
 	gulong              dhcp_state_sigid;
 	gulong              dhcp_timeout_sigid;
+	NMDHCP4Config *     dhcp4_config;
 
 	/* dnsmasq stuff for shared connections */
 	NMDnsMasqManager *  dnsmasq_manager;
@@ -995,22 +997,28 @@
 	NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE;
 	NMConnection *connection;
 	NMSettingIP4Config *s_ip4;
+	const char *iface;
 
 	g_return_val_if_fail (config != NULL, NM_ACT_STAGE_RETURN_FAILURE);
 	g_return_val_if_fail (*config == NULL, NM_ACT_STAGE_RETURN_FAILURE);
 	g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE);
 
+	iface = nm_device_get_iface (self);
+
 	connection = nm_act_request_get_connection (nm_device_get_act_request (self));
 	g_assert (connection);
 
 	s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
 
 	if (nm_device_get_use_dhcp (self)) {
-		*config = nm_dhcp_manager_get_ip4_config (NM_DEVICE_GET_PRIVATE (self)->dhcp_manager,
-											 nm_device_get_iface (self));
-		if (*config)
+		*config = nm_dhcp_manager_get_ip4_config (priv->dhcp_manager, iface);
+		if (*config) {
 			nm_utils_merge_ip4_config (*config, s_ip4);
-		else
+
+			nm_dhcp_manager_set_dhcp4_config (priv->dhcp_manager, iface, priv->dhcp4_config);
+			/* Notify of new DHCP4 config */
+			g_object_notify (G_OBJECT (self), NM_DEVICE_INTERFACE_DHCP4_CONFIG);
+		} else
 			*reason = NM_DEVICE_STATE_REASON_DHCP_ERROR;
 	} else {
 		g_assert (s_ip4);
@@ -1027,7 +1035,7 @@
 		} else if (!strcmp (s_ip4->method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) {
 			*config = nm_device_new_ip4_shared_config (self, reason);
 			if (*config)
-				priv->dnsmasq_manager = nm_dnsmasq_manager_new (nm_device_get_ip_iface (self));
+				priv->dnsmasq_manager = nm_dnsmasq_manager_new (iface);
 		}
 	}
 
@@ -1115,6 +1123,9 @@
 	g_return_val_if_fail (config != NULL, NM_ACT_STAGE_RETURN_FAILURE);
 	g_return_val_if_fail (*config == NULL, NM_ACT_STAGE_RETURN_FAILURE);
 
+	/* Notify of invalid DHCP4 config object */
+	g_object_notify (G_OBJECT (self), NM_DEVICE_INTERFACE_DHCP4_CONFIG);
+
 	/* DHCP failed; connection must fail */
 	*reason = NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE;
 	return NM_ACT_STAGE_RETURN_FAILURE;
@@ -1334,6 +1345,8 @@
 		if (nm_device_get_use_dhcp (self)) {
 			nm_dhcp_manager_cancel_transaction (priv->dhcp_manager, nm_device_get_iface (self));
 			nm_device_set_use_dhcp (self, FALSE);
+			/* Notify of invalid DHCP4 config */
+			g_object_notify (G_OBJECT (self), NM_DEVICE_INTERFACE_DHCP4_CONFIG);
 		} else if (priv->dnsmasq_manager) {
 			if (priv->dnsmasq_state_id) {
 				g_signal_handler_disconnect (priv->dnsmasq_manager, priv->dnsmasq_state_id);
@@ -1542,6 +1555,7 @@
 static void
 handle_dhcp_lease_change (NMDevice *device)
 {
+	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
 	NMIP4Config *config;
 	NMSettingIP4Config *s_ip4;
 	NMConnection *connection;
@@ -1575,6 +1589,8 @@
 		nm_warning ("Failed to update IP4 config in response to DHCP event.");
 		nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, reason);
 	}
+
+	nm_dhcp_manager_set_dhcp4_config (priv->dhcp_manager, nm_device_get_iface (device), priv->dhcp4_config);
 }
 
 static void
@@ -1584,6 +1600,7 @@
 					gpointer user_data)
 {
 	NMDevice *device = NM_DEVICE (user_data);
+	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
 	NMDeviceState dev_state;
 
 	if (strcmp (nm_device_get_iface (device), iface) != 0)
@@ -1605,12 +1622,16 @@
 			handle_dhcp_lease_change (device);
 		break;
 	case DHC_TIMEOUT: /* timed out contacting DHCP server */
+		nm_dhcp4_config_reset (priv->dhcp4_config);
+
 		if (nm_device_get_state (device) == NM_DEVICE_STATE_IP_CONFIG)
 			nm_device_activate_schedule_stage4_ip_config_timeout (device);
 		break;
 	case DHC_FAIL: /* all attempts to contact server timed out, sleeping */
 	case DHC_ABEND: /* dhclient exited abnormally */
 	case DHC_END: /* dhclient exited normally */
+		nm_dhcp4_config_reset (priv->dhcp4_config);
+
 		if (nm_device_get_state (device) == NM_DEVICE_STATE_IP_CONFIG) {
 			nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_DHCP_FAILED);
 		} else if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) {
@@ -1658,6 +1679,11 @@
 	priv = NM_DEVICE_GET_PRIVATE (self);
 
 	if (use_dhcp) {
+		/* New exported DHCP4 config */
+		if (priv->dhcp4_config)
+			g_object_unref (priv->dhcp4_config);
+		priv->dhcp4_config = nm_dhcp4_config_new ();
+
 		if (!priv->dhcp_manager) {
 			priv->dhcp_manager = nm_dhcp_manager_get ();
 			priv->dhcp_state_sigid = g_signal_connect (priv->dhcp_manager,
@@ -1669,13 +1695,21 @@
 			                                             G_CALLBACK (dhcp_timeout),
 			                                             self);
 		}
-	} else if (priv->dhcp_manager) {
-		g_signal_handler_disconnect (priv->dhcp_manager, priv->dhcp_state_sigid);
-		priv->dhcp_state_sigid = 0;
-		g_signal_handler_disconnect (priv->dhcp_manager, priv->dhcp_timeout_sigid);
-		priv->dhcp_timeout_sigid = 0;
-		g_object_unref (priv->dhcp_manager);
-		priv->dhcp_manager = NULL;
+	} else {
+		if (priv->dhcp4_config) {
+			g_object_notify (G_OBJECT (self), NM_DEVICE_INTERFACE_DHCP4_CONFIG);
+			g_object_unref (priv->dhcp4_config);
+			priv->dhcp4_config = NULL;
+		}
+
+		if (priv->dhcp_manager) {
+			g_signal_handler_disconnect (priv->dhcp_manager, priv->dhcp_state_sigid);
+			priv->dhcp_state_sigid = 0;
+			g_signal_handler_disconnect (priv->dhcp_manager, priv->dhcp_timeout_sigid);
+			priv->dhcp_timeout_sigid = 0;
+			g_object_unref (priv->dhcp_manager);
+			priv->dhcp_manager = NULL;
+		}
 	}
 }
 
@@ -1995,9 +2029,12 @@
 get_property (GObject *object, guint prop_id,
 			  GValue *value, GParamSpec *pspec)
 {
-	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
+	NMDevice *self = NM_DEVICE (object);
+	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
 	NMDeviceState state;
 
+	state = nm_device_get_state (self);
+
 	switch (prop_id) {
 	case NM_DEVICE_INTERFACE_PROP_UDI:
 		g_value_set_string (value, priv->udi);
@@ -2015,13 +2052,18 @@
 		g_value_set_uint (value, priv->ip4_address);
 		break;
 	case NM_DEVICE_INTERFACE_PROP_IP4_CONFIG:
-		state = nm_device_get_state (NM_DEVICE (object));
-		if (   (state == NM_DEVICE_STATE_ACTIVATED)
-		    || (state == NM_DEVICE_STATE_IP_CONFIG))
+		if ((state == NM_DEVICE_STATE_ACTIVATED) || (state == NM_DEVICE_STATE_IP_CONFIG))
 			g_value_set_object (value, priv->ip4_config);
 		else
 			g_value_set_object (value, NULL);
 		break;
+	case NM_DEVICE_INTERFACE_PROP_DHCP4_CONFIG:
+		if (   ((state == NM_DEVICE_STATE_ACTIVATED) || (state == NM_DEVICE_STATE_IP_CONFIG))
+		    && nm_device_get_use_dhcp (self))
+			g_value_set_object (value, priv->dhcp4_config);
+		else
+			g_value_set_object (value, NULL);
+		break;
 	case NM_DEVICE_INTERFACE_PROP_STATE:
 		g_value_set_uint (value, priv->state);
 		break;
@@ -2087,6 +2129,10 @@
 									  NM_DEVICE_INTERFACE_IP4_CONFIG);
 
 	g_object_class_override_property (object_class,
+									  NM_DEVICE_INTERFACE_PROP_DHCP4_CONFIG,
+									  NM_DEVICE_INTERFACE_DHCP4_CONFIG);
+
+	g_object_class_override_property (object_class,
 									  NM_DEVICE_INTERFACE_PROP_STATE,
 									  NM_DEVICE_INTERFACE_STATE);
 

Added: trunk/src/nm-dhcp4-config.c
==============================================================================
--- (empty file)
+++ trunk/src/nm-dhcp4-config.c	Thu Jul 17 17:04:13 2008
@@ -0,0 +1,186 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+/* NetworkManager -- Network link manager
+ *
+ * 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 2008 Red Hat, Inc.
+ */
+
+
+#include <glib.h>
+#include <string.h>
+
+#include "NetworkManager.h"
+#include "nm-dbus-manager.h"
+#include "nm-dhcp4-config.h"
+#include "nm-dhcp4-config-glue.h"
+#include "nm-dbus-glib-types.h"
+#include "nm-properties-changed-signal.h"
+#include "nm-utils.h"
+
+
+G_DEFINE_TYPE (NMDHCP4Config, nm_dhcp4_config, G_TYPE_OBJECT)
+
+#define NM_DHCP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP4_CONFIG, NMDHCP4ConfigPrivate))
+
+typedef struct {
+	char *dbus_path;
+	GHashTable *options;
+} NMDHCP4ConfigPrivate;
+
+
+enum {
+	PROP_0,
+	PROP_OPTIONS,
+
+	LAST_PROP
+};
+
+enum {
+	PROPERTIES_CHANGED,
+
+	LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+
+NMDHCP4Config *
+nm_dhcp4_config_new (void)
+{
+	return NM_DHCP4_CONFIG (g_object_new (NM_TYPE_DHCP4_CONFIG, NULL));
+}
+
+void
+nm_dhcp4_config_add_option (NMDHCP4Config *self,
+                            const char *key,
+                            const char *option)
+{
+	GValue *svalue;
+
+	g_return_if_fail (NM_IS_DHCP4_CONFIG (self));
+	g_return_if_fail (key != NULL);
+	g_return_if_fail (option != NULL);
+
+	svalue = g_slice_new0 (GValue);
+	g_value_init (svalue, G_TYPE_STRING);
+	g_value_set_string (svalue, option);
+	g_hash_table_insert (NM_DHCP4_CONFIG_GET_PRIVATE (self)->options, g_strdup (key), svalue);
+	g_object_notify (G_OBJECT (self), NM_DHCP4_CONFIG_OPTIONS);
+}
+
+void
+nm_dhcp4_config_reset (NMDHCP4Config *self)
+{
+	g_return_if_fail (NM_IS_DHCP4_CONFIG (self));
+
+	g_hash_table_remove_all (NM_DHCP4_CONFIG_GET_PRIVATE (self)->options);
+	g_object_notify (G_OBJECT (self), NM_DHCP4_CONFIG_OPTIONS);
+}
+
+const char *
+nm_dhcp4_config_get_option (NMDHCP4Config *self, const char *key)
+{
+	GValue *value;
+
+	g_return_val_if_fail (NM_IS_DHCP4_CONFIG (self), NULL);
+	g_return_val_if_fail (key != NULL, NULL);
+
+	value = g_hash_table_lookup (NM_DHCP4_CONFIG_GET_PRIVATE (self)->options, key);
+	return value ? g_value_get_string (value) : NULL;
+}
+
+static void
+nm_gvalue_destroy (gpointer data)
+{
+	GValue *value = (GValue *) data;
+
+	g_value_unset (value);
+	g_slice_free (GValue, value);
+}
+
+static void
+nm_dhcp4_config_init (NMDHCP4Config *self)
+{
+	NMDHCP4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (self);
+	static guint32 counter = 0;
+	DBusGConnection *connection;
+	NMDBusManager *dbus_mgr;
+
+	dbus_mgr = nm_dbus_manager_get ();
+	connection = nm_dbus_manager_get_connection (dbus_mgr);
+	priv->dbus_path = g_strdup_printf (NM_DBUS_PATH "/DHCP4Config/%d", counter++);
+	dbus_g_connection_register_g_object (connection, priv->dbus_path, G_OBJECT (self));
+	g_object_unref (dbus_mgr);
+
+	priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, nm_gvalue_destroy);
+}
+
+static void
+finalize (GObject *object)
+{
+	NMDHCP4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object);
+
+	g_free (priv->dbus_path);
+	g_hash_table_destroy (priv->options);
+}
+
+static void
+get_property (GObject *object, guint prop_id,
+			  GValue *value, GParamSpec *pspec)
+{
+	NMDHCP4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object);
+
+	switch (prop_id) {
+	case PROP_OPTIONS:
+		g_value_set_boxed (value, priv->options);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+nm_dhcp4_config_class_init (NMDHCP4ConfigClass *config_class)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (config_class);
+
+	g_type_class_add_private (config_class, sizeof (NMDHCP4ConfigPrivate));
+
+	/* virtual methods */
+	object_class->get_property = get_property;
+	object_class->finalize = finalize;
+
+	/* properties */
+	g_object_class_install_property
+		(object_class, PROP_OPTIONS,
+		 g_param_spec_boxed (NM_DHCP4_CONFIG_OPTIONS,
+		                     "Options",
+		                     "DHCP configuration options returned by the server",
+		                     DBUS_TYPE_G_MAP_OF_VARIANT,
+		                     G_PARAM_READABLE));
+
+	/* Signals */
+	signals[PROPERTIES_CHANGED] = 
+		nm_properties_changed_signal_new (object_class,
+								    G_STRUCT_OFFSET (NMDHCP4ConfigClass, properties_changed));
+
+	dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (config_class),
+									 &dbus_glib_nm_dhcp4_config_object_info);
+}

Added: trunk/src/nm-dhcp4-config.h
==============================================================================
--- (empty file)
+++ trunk/src/nm-dhcp4-config.h	Thu Jul 17 17:04:13 2008
@@ -0,0 +1,64 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+/* NetworkManager -- Network link manager
+ *
+ * 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 2008 Red Hat, Inc.
+ */
+
+#ifndef NM_DHCP4_CONFIG_H
+#define NM_DHCP4_CONFIG_H
+
+#include <glib/gtypes.h>
+#include <glib-object.h>
+
+#include "nm-dhcp4-config.h"
+
+#define NM_TYPE_DHCP4_CONFIG            (nm_dhcp4_config_get_type ())
+#define NM_DHCP4_CONFIG(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DHCP4_CONFIG, NMDHCP4Config))
+#define NM_DHCP4_CONFIG_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DHCP4_CONFIG, NMDHCP4ConfigClass))
+#define NM_IS_DHCP4_CONFIG(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP4_CONFIG))
+#define NM_IS_DHCP4_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_DHCP4_CONFIG))
+#define NM_DHCP4_CONFIG_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DHCP4_CONFIG, NMDHCP4ConfigClass))
+
+typedef struct {
+	GObject parent;
+} NMDHCP4Config;
+
+typedef struct {
+	GObjectClass parent;
+
+	/* Signals */
+	void (*properties_changed) (NMDHCP4Config *config, GHashTable *properties);
+} NMDHCP4ConfigClass;
+
+#define NM_DHCP4_CONFIG_OPTIONS "options"
+
+GType nm_dhcp4_config_get_type (void);
+
+NMDHCP4Config *nm_dhcp4_config_new (void);
+
+void nm_dhcp4_config_add_option (NMDHCP4Config *config,
+                                 const char *key,
+                                 const char *option);
+
+void nm_dhcp4_config_reset (NMDHCP4Config *config);
+
+const char *nm_dhcp4_config_get_option (NMDHCP4Config *config, const char *option);
+
+#endif /* NM_DHCP4_CONFIG_H */



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