Re: patches for openrc

2011-12-12 Thread Dan Williams
On Mon, 2011-12-12 at 14:25 +0800, Mu Qiao wrote:
> Hi, Dan
> 
> The old baselayout-1 has been removed from Gentoo and openrc has been
> stabilized for months. Some configuration style has been changed since
> then. These patches add support for the new style. To be compatible,
> the code for the old style is kept. But we will remove it in future.

Pushed to git master, thanks!

Dan

___
networkmanager-list mailing list
networkmanager-list@gnome.org
http://mail.gnome.org/mailman/listinfo/networkmanager-list


patches for openrc

2011-12-11 Thread Mu Qiao
Hi, Dan

The old baselayout-1 has been removed from Gentoo and openrc has been
stabilized for months. Some configuration style has been changed since
then. These patches add support for the new style. To be compatible,
the code for the old style is kept. But we will remove it in future.

Thanks
-- 
Best wishes,
Mu Qiao
GnuPG fingerprint: 92B1 B0C4 8D14 F8C4 EFA5  3ACC 30B3 0DE4 17B1 57E9
From c5f080923f0c52084a929b4125e8fbe19f6e7279 Mon Sep 17 00:00:00 2001
From: Mu Qiao 
Date: Tue, 6 Dec 2011 14:55:03 +0800
Subject: [PATCH 1/2] ifnet: support reading openrc style

IP configuration like 192.168.1.{2..4} is not supported anymore.
---
 src/settings/plugins/ifnet/connection_parser.c |   14 +-
 src/settings/plugins/ifnet/net_parser.c|   84 ++
 src/settings/plugins/ifnet/net_utils.c |  144 ++--
 src/settings/plugins/ifnet/tests/net   |   11 ++-
 src/settings/plugins/ifnet/tests/test_all.c|   30 -
 5 files changed, 163 insertions(+), 120 deletions(-)

diff --git a/src/settings/plugins/ifnet/connection_parser.c b/src/settings/plugins/ifnet/connection_parser.c
index b4aaa8d..66ce318 100644
--- a/src/settings/plugins/ifnet/connection_parser.c
+++ b/src/settings/plugins/ifnet/connection_parser.c
@@ -567,7 +567,7 @@ make_wired_connection_setting (NMConnection *connection,
 		nm_connection_add_setting (connection, NM_SETTING (s_wired));
 }
 
-/* add NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, 
+/* add NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME,
  * NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID in future*/
 static void
 make_ip4_setting (NMConnection *connection,
@@ -596,19 +596,19 @@ make_ip4_setting (NMConnection *connection,
 			g_object_unref (ip4_setting);
 			return;
 		}
-		if (!strcmp (method, "dhcp"))
+		if (strstr (method, "dhcp"))
 			g_object_set (ip4_setting,
 		  NM_SETTING_IP4_CONFIG_METHOD,
 		  NM_SETTING_IP4_CONFIG_METHOD_AUTO,
 		  NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
-		else if (!strcmp (method, "autoip")){
+		else if (strstr (method, "autoip")){
 			g_object_set (ip4_setting,
 		  NM_SETTING_IP4_CONFIG_METHOD,
 		  NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL,
 		  NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
 			nm_connection_add_setting (connection, NM_SETTING (ip4_setting));
 			return;
-		} else if (!strcmp (method, "shared")){
+		} else if (strstr (method, "shared")){
 			g_object_set (ip4_setting,
 		  NM_SETTING_IP4_CONFIG_METHOD,
 		  NM_SETTING_IP4_CONFIG_METHOD_SHARED,
@@ -663,7 +663,7 @@ make_ip4_setting (NMConnection *connection,
 	}
 
 	/* add dhcp hostname and client id */
-	if (!is_static_block && !strcmp (method, "dhcp")) {
+	if (!is_static_block && strstr (method, "dhcp")) {
 		gchar *dhcp_hostname, *client_id;
 
 		get_dhcp_hostname_and_client_id (&dhcp_hostname, &client_id);
@@ -868,7 +868,7 @@ make_ip6_setting (NMConnection *connection,
 		nm_ip6_route_set_dest (route, iblock->ip);
 		nm_ip6_route_set_next_hop (route, iblock->next_hop);
 		nm_ip6_route_set_prefix (route, iblock->prefix);
-		/* metric is not per routes configuration right now 
+		/* metric is not per routes configuration right now
 		 * global metric is also supported (metric="x") */
 		if ((metric_str = ifnet_get_data (conn_name, "metric")) != NULL) {
 			metric = strtol (metric_str, NULL, 10);
@@ -995,7 +995,7 @@ make_wireless_connection_setting (const char *conn_name,
 		goto error;
 	}
 
-	/* mode=0: infrastructure 
+	/* mode=0: infrastructure
 	 * mode=1: adhoc */
 	value = wpa_get_value (conn_name, "mode");
 	if (value)
diff --git a/src/settings/plugins/ifnet/net_parser.c b/src/settings/plugins/ifnet/net_parser.c
index a48103d..4befc37 100644
--- a/src/settings/plugins/ifnet/net_parser.c
+++ b/src/settings/plugins/ifnet/net_parser.c
@@ -169,12 +169,10 @@ init_block_by_line (gchar * buf)
 			conn = add_new_connection_config ("wireless", pos);
 	}
 	data = g_strdup (key_value[1]);
-	tmp = strip_string (data, '(');
-	tmp = strip_string (tmp, ')');
-	strip_string (tmp, '"');
+	tmp = strip_string (data, '"');
 	strip_string (tmp, '\'');
 	if (conn)
-		g_hash_table_insert (conn, g_strdup (key_value[0]),
+		g_hash_table_insert (conn, strip_string (g_strdup (key_value[0]), ' '),
  g_strdup (tmp));
 	g_free (data);
 	g_strfreev (key_value);
@@ -283,6 +281,22 @@ is_function (gchar * line)
 	return FALSE;
 }
 
+static void
+append_line (GString *buf, gchar* line)
+{
+	gchar *pos = NULL;
+
+	if ((pos = strchr (line, '#')) != NULL)
+		*pos = '\0';
+	g_strstrip (line);
+
+	if (line[0] != '\0') {
+		g_string_append_printf (buf,
+	" %s", line);
+	}
+	g_free (line);
+}
+
 gboolean
 ifnet_init (gchar * config_file)
 {
@@ -292,6 +306,8 @@ ifnet_init (gchar * config_file)
 	/* Handle multiple lines with brackets */
 	gboolean complete = TRUE;
 
+	gboolean openrc_style = TRUE;
+
 	/* line buffer */
 	GString *buf;
 
@@ -319,36 +335,60 @@ ifnet_init (gchar * config_file)
 			strip_function (channel, line);
 			continue;
 		}
-		if