From 593f87514484aa82c9f1b39c96ee859671186831 Mon Sep 17 00:00:00 2001 From: Mu Qiao Date: Thu, 5 Apr 2012 10:12:37 +0800 Subject: [PATCH] ifnet: fix quote handling for global data --- src/settings/plugins/ifnet/net_parser.c | 13 +++++++------ src/settings/plugins/ifnet/tests/net | 2 ++ src/settings/plugins/ifnet/tests/test_all.c | 3 +++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/settings/plugins/ifnet/net_parser.c b/src/settings/plugins/ifnet/net_parser.c index 38765f5..c230138 100644 --- a/src/settings/plugins/ifnet/net_parser.c +++ b/src/settings/plugins/ifnet/net_parser.c @@ -143,12 +143,13 @@ init_block_by_line (gchar * buf) pos = g_strrstr (key_value[0], "_"); if (pos == NULL || is_global_setting (key_value[0])) { /* global data */ - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "global:%s-%s\n", key_value[0], - key_value[1]); - g_hash_table_insert (global_settings_table, - g_strdup (key_value[0]), - g_strdup (key_value[1])); + data = g_strdup (key_value[1]); + tmp = strip_string (data, '"'); + strip_string (tmp, '\''); + PLUGIN_PRINT (IFNET_PLUGIN_NAME, "global:%s-%s\n", key_value[0], tmp); + g_hash_table_insert (global_settings_table, g_strdup (key_value[0]), g_strdup (tmp)); g_strfreev (key_value); + g_free (data); return; } *pos++ = '\0'; @@ -593,7 +594,7 @@ ifnet_flush_to_file (const char *config_file) /* Writing global data */ while (g_hash_table_iter_next (&iter, &key, &value)) { out_line = - g_strdup_printf ("%s=%s\n", (gchar *) key, (gchar *) value); + g_strdup_printf ("%s=\"%s\"\n", (gchar *) key, (gchar *) value); g_io_channel_write_chars (channel, out_line, -1, &bytes_written, error); if (bytes_written == 0 || (error && *error)) diff --git a/src/settings/plugins/ifnet/tests/net b/src/settings/plugins/ifnet/tests/net index 27d39f4..a5ac9ca 100644 --- a/src/settings/plugins/ifnet/tests/net +++ b/src/settings/plugins/ifnet/tests/net @@ -3,6 +3,8 @@ # please review /etc/conf.d/net.example and save your configuration # in /etc/conf.d/net (this file :]!). +modules="!wpa_supplicant" + config_eth0=( "202.117.16.121 netmask 255.255.255.0 brd 202.117.16.255" "192.168.4.121/24" diff --git a/src/settings/plugins/ifnet/tests/test_all.c b/src/settings/plugins/ifnet/tests/test_all.c index 50441d4..974258b 100644 --- a/src/settings/plugins/ifnet/tests/test_all.c +++ b/src/settings/plugins/ifnet/tests/test_all.c @@ -56,6 +56,9 @@ test_getdata () && strcmp (ifnet_get_data ("ppp0", "password"), "password") == 0, "get data", "config_ppp0 password is not correctly read"); + ASSERT (ifnet_get_global_data ("modules") + && strcmp ("!wpa_supplicant", ifnet_get_global_data ("modules")) == 0, + "get data", "config_eth1 is not correct"); } static void -- 1.7.3.4