NetworkManager r4217 - in trunk: . libnm-util src src/ppp-manager



Author: dcbw
Date: Sun Oct 26 17:08:58 2008
New Revision: 4217
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=4217&view=rev

Log:
2008-10-26  Dan Williams  <dcbw redhat com>

	Patch from Tambet Ingo <tambet gmail com>

	* libnm-util/libnm-util.ver
	  libnm-util/nm-setting-pppoe.c
	  libnm-util/nm-setting-pppoe.h
		- Make properties private and add accessor functions

	* src/nm-device-ethernet.c
	  src/ppp-manager/nm-ppp-manager.c
		- Use those accesors



Modified:
   trunk/ChangeLog
   trunk/libnm-util/libnm-util.ver
   trunk/libnm-util/nm-setting-pppoe.c
   trunk/libnm-util/nm-setting-pppoe.h
   trunk/src/nm-device-ethernet.c
   trunk/src/ppp-manager/nm-ppp-manager.c

Modified: trunk/libnm-util/libnm-util.ver
==============================================================================
--- trunk/libnm-util/libnm-util.ver	(original)
+++ trunk/libnm-util/libnm-util.ver	Sun Oct 26 17:08:58 2008
@@ -72,6 +72,9 @@
 	nm_setting_pppoe_error_quark;
 	nm_setting_pppoe_get_type;
 	nm_setting_pppoe_new;
+	nm_setting_pppoe_get_service;
+	nm_setting_pppoe_get_username;
+	nm_setting_pppoe_get_password;
 	nm_setting_register;
 	nm_setting_serial_error_get_type;
 	nm_setting_serial_error_quark;

Modified: trunk/libnm-util/nm-setting-pppoe.c
==============================================================================
--- trunk/libnm-util/nm-setting-pppoe.c	(original)
+++ trunk/libnm-util/nm-setting-pppoe.c	Sun Oct 26 17:08:58 2008
@@ -65,6 +65,14 @@
 
 G_DEFINE_TYPE (NMSettingPPPOE, nm_setting_pppoe, NM_TYPE_SETTING)
 
+#define NM_SETTING_PPPOE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_PPPOE, NMSettingPPPOEPrivate))
+
+typedef struct {
+	char *service;
+	char *username;
+	char *password;
+} NMSettingPPPOEPrivate;
+
 enum {
 	PROP_0,
 	PROP_SERVICE,
@@ -80,6 +88,30 @@
 	return (NMSetting *) g_object_new (NM_TYPE_SETTING_PPPOE, NULL);
 }
 
+const char *
+nm_setting_pppoe_get_service  (NMSettingPPPOE *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_PPPOE (setting), NULL);
+
+	return NM_SETTING_PPPOE_GET_PRIVATE (setting)->service;
+}
+
+const char *
+nm_setting_pppoe_get_username (NMSettingPPPOE *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_PPPOE (setting), NULL);
+
+	return NM_SETTING_PPPOE_GET_PRIVATE (setting)->username;
+}
+
+const char *
+nm_setting_pppoe_get_password (NMSettingPPPOE *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_PPPOE (setting), NULL);
+
+	return NM_SETTING_PPPOE_GET_PRIVATE (setting)->password;
+}
+
 static gint
 find_setting_by_name (gconstpointer a, gconstpointer b)
 {
@@ -92,15 +124,15 @@
 static gboolean
 verify (NMSetting *setting, GSList *all_settings, GError **error)
 {
-	NMSettingPPPOE *self = NM_SETTING_PPPOE (setting);
+	NMSettingPPPOEPrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE (setting);
 
-	if (!self->username) {
+	if (!priv->username) {
 		g_set_error (error,
 		             NM_SETTING_PPPOE_ERROR,
 		             NM_SETTING_PPPOE_ERROR_MISSING_PROPERTY,
 		             NM_SETTING_PPPOE_USERNAME);
 		return FALSE;
-	} else if (!strlen (self->username)) {
+	} else if (!strlen (priv->username)) {
 		g_set_error (error,
 		             NM_SETTING_PPPOE_ERROR,
 		             NM_SETTING_PPPOE_ERROR_INVALID_PROPERTY,
@@ -108,7 +140,7 @@
 		return FALSE;
 	}
 
-	if (self->service && !strlen (self->service)) {
+	if (priv->service && !strlen (priv->service)) {
 		g_set_error (error,
 		             NM_SETTING_PPPOE_ERROR,
 		             NM_SETTING_PPPOE_ERROR_INVALID_PROPERTY,
@@ -130,10 +162,10 @@
 static GPtrArray *
 need_secrets (NMSetting *setting)
 {
-	NMSettingPPPOE *self = NM_SETTING_PPPOE (setting);
+	NMSettingPPPOEPrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE (setting);
 	GPtrArray *secrets;
 
-	if (self->password)
+	if (priv->password)
 		return NULL;
 
 	secrets = g_ptr_array_sized_new (1);
@@ -152,20 +184,20 @@
 set_property (GObject *object, guint prop_id,
 		    const GValue *value, GParamSpec *pspec)
 {
-	NMSettingPPPOE *setting = NM_SETTING_PPPOE (object);
+	NMSettingPPPOEPrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE (object);
 
 	switch (prop_id) {
 	case PROP_SERVICE:
-		g_free (setting->service);
-		setting->service = g_value_dup_string (value);
+		g_free (priv->service);
+		priv->service = g_value_dup_string (value);
 		break;
 	case PROP_USERNAME:
-		g_free (setting->username);
-		setting->username = g_value_dup_string (value);
+		g_free (priv->username);
+		priv->username = g_value_dup_string (value);
 		break;
 	case PROP_PASSWORD:
-		g_free (setting->password);
-		setting->password = g_value_dup_string (value);
+		g_free (priv->password);
+		priv->password = g_value_dup_string (value);
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -181,13 +213,13 @@
 
 	switch (prop_id) {
 	case PROP_SERVICE:
-		g_value_set_string (value, setting->service);
+		g_value_set_string (value, nm_setting_pppoe_get_service (setting));
 		break;
 	case PROP_USERNAME:
-		g_value_set_string (value, setting->username);
+		g_value_set_string (value, nm_setting_pppoe_get_username (setting));
 		break;
 	case PROP_PASSWORD:
-		g_value_set_string (value, setting->password);
+		g_value_set_string (value, nm_setting_pppoe_get_password (setting));
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -201,6 +233,8 @@
 	GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
 	NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
 
+	g_type_class_add_private (setting_class, sizeof (NMSettingPPPOEPrivate));
+
 	/* virtual methods */
 	object_class->set_property = set_property;
 	object_class->get_property = get_property;

Modified: trunk/libnm-util/nm-setting-pppoe.h
==============================================================================
--- trunk/libnm-util/nm-setting-pppoe.h	(original)
+++ trunk/libnm-util/nm-setting-pppoe.h	Sun Oct 26 17:08:58 2008
@@ -59,10 +59,6 @@
 
 typedef struct {
 	NMSetting parent;
-
-	char *service;
-	char *username;
-	char *password;
 } NMSettingPPPOE;
 
 typedef struct {
@@ -71,7 +67,10 @@
 
 GType nm_setting_pppoe_get_type (void);
 
-NMSetting *nm_setting_pppoe_new (void);
+NMSetting  *nm_setting_pppoe_new          (void);
+const char *nm_setting_pppoe_get_service  (NMSettingPPPOE *setting);
+const char *nm_setting_pppoe_get_username (NMSettingPPPOE *setting);
+const char *nm_setting_pppoe_get_password (NMSettingPPPOE *setting);
 
 G_END_DECLS
 

Modified: trunk/src/nm-device-ethernet.c
==============================================================================
--- trunk/src/nm-device-ethernet.c	(original)
+++ trunk/src/nm-device-ethernet.c	Sun Oct 26 17:08:58 2008
@@ -610,10 +610,13 @@
 			                               NULL,
 			                               "missing PPPoE setting; no secrets could be found.");
 		} else {
+			const char *pppoe_username = nm_setting_pppoe_get_username (s_pppoe);
+			const char *pppoe_password = nm_setting_pppoe_get_password (s_pppoe);
+
 			nm_ppp_manager_update_secrets (priv->ppp_manager,
 			                               nm_device_get_iface (dev),
-			                               s_pppoe->username ? s_pppoe->username : "",
-			                               s_pppoe->password ? s_pppoe->password : "",
+			                               pppoe_username ? pppoe_username : "",
+			                               pppoe_password ? pppoe_password : "",
 			                               NULL);
 		}
 		return;
@@ -1255,7 +1258,7 @@
 	g_assert (s_pppoe);
 
 	priv->ppp_manager = nm_ppp_manager_new (nm_device_get_iface (NM_DEVICE (self)));
-	if (nm_ppp_manager_start (priv->ppp_manager, req, s_pppoe->username, &err)) {
+	if (nm_ppp_manager_start (priv->ppp_manager, req, nm_setting_pppoe_get_username (s_pppoe), &err)) {
 		g_signal_connect (priv->ppp_manager, "state-changed",
 					   G_CALLBACK (ppp_state_changed),
 					   self);

Modified: trunk/src/ppp-manager/nm-ppp-manager.c
==============================================================================
--- trunk/src/ppp-manager/nm-ppp-manager.c	(original)
+++ trunk/src/ppp-manager/nm-ppp-manager.c	Sun Oct 26 17:08:58 2008
@@ -370,8 +370,8 @@
 
 			/* FIXME: push this down to the settings and keep PPP manager generic */
 			if (NM_IS_SETTING_PPPOE (setting)) {
-				username = NM_SETTING_PPPOE (setting)->username;
-				password = NM_SETTING_PPPOE (setting)->password;
+				username = nm_setting_pppoe_get_username (NM_SETTING_PPPOE (setting));
+				password = nm_setting_pppoe_get_password (NM_SETTING_PPPOE (setting));
 			} else if (NM_IS_SETTING_GSM (setting)) {
 				username = NM_SETTING_GSM (setting)->username;
 				password = NM_SETTING_GSM (setting)->password;
@@ -739,6 +739,7 @@
 
 	if (pppoe) {
 		char *dev_str;
+		const char *pppoe_service;
 
 		nm_cmd_line_add_string (cmd, "plugin");
 		nm_cmd_line_add_string (cmd, "rp-pppoe.so");
@@ -747,9 +748,10 @@
 		nm_cmd_line_add_string (cmd, dev_str);
 		g_free (dev_str);
 
-		if (pppoe->service) {
+		pppoe_service = nm_setting_pppoe_get_service (pppoe);
+		if (pppoe_service) {
 			nm_cmd_line_add_string (cmd, "rp_pppoe_service");
-			nm_cmd_line_add_string (cmd, pppoe->service);
+			nm_cmd_line_add_string (cmd, pppoe_service);
 		}
 	} else {
 		nm_cmd_line_add_string (cmd, priv->parent_iface);



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