summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-06-09 09:24:28 +0200
committerThomas Haller <thaller@redhat.com>2015-07-02 15:50:04 +0200
commit6d6ab20be01cdda8d3126df78504edabc27bf8bd (patch)
treef198dd988ccf37cc2a514a172526932b9fbbe513
parent1b0ab2129c2789c476b2376da4c8e3d45c05b548 (diff)
downloadNetworkManager-6d6ab20be01cdda8d3126df78504edabc27bf8bd.tar.gz
config: add defines for keyfile groups to "nm-config.h"
Some plugins had their local defines for the name of the sections and keys in NMConfig. Move those defines to "nm-config.h". Usually plugins make use of code in core, but not the other way round. Defining the names inside "nm-config.h" is no violation of that because the config section names are anyway not local to the plugin, but global in the shared name-space with other settings. For example, another plugins shouldn't reuse the section "ifnet". For that reason, it is correct and consistent to move these defines to "nm-config.h". We don't use those names in core, we merely signal their existance.
-rw-r--r--src/nm-config-data.c20
-rw-r--r--src/nm-config.c34
-rw-r--r--src/nm-config.h14
-rw-r--r--src/settings/plugins/ifnet/net_parser.h1
-rw-r--r--src/settings/plugins/ifnet/plugin.c5
-rw-r--r--src/settings/plugins/ifupdown/plugin.c6
-rw-r--r--src/settings/plugins/keyfile/plugin.c8
7 files changed, 49 insertions, 39 deletions
diff --git a/src/nm-config-data.c b/src/nm-config-data.c
index 0b94fecc2e..6e51c05251 100644
--- a/src/nm-config-data.c
+++ b/src/nm-config-data.c
@@ -284,8 +284,8 @@ _get_connection_infos (GKeyFile *keyfile)
ngroups = 0;
else if (ngroups > 0) {
for (i = 0, j = 0; i < ngroups; i++) {
- if (g_str_has_prefix (groups[i], "connection")) {
- if (groups[i][STRLEN ("connection")] == '\0')
+ if (g_str_has_prefix (groups[i], NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION)) {
+ if (groups[i][STRLEN (NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION)] == '\0')
connection_tag = groups[i];
else
groups[j++] = groups[i];
@@ -492,24 +492,24 @@ constructed (GObject *object)
priv->connection_infos = _get_connection_infos (priv->keyfile);
- priv->connectivity.uri = g_key_file_get_value (priv->keyfile, "connectivity", "uri", NULL);
- priv->connectivity.response = g_key_file_get_value (priv->keyfile, "connectivity", "response", NULL);
+ priv->connectivity.uri = g_key_file_get_value (priv->keyfile, NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY, "uri", NULL);
+ priv->connectivity.response = g_key_file_get_value (priv->keyfile, NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY, "response", NULL);
/* On missing config value, fallback to 300. On invalid value, disable connectivity checking by setting
* the interval to zero. */
- interval = g_key_file_get_value (priv->keyfile, "connectivity", "interval", NULL);
+ interval = g_key_file_get_value (priv->keyfile, NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY, "interval", NULL);
priv->connectivity.interval = interval
? _nm_utils_ascii_str_to_int64 (interval, 10, 0, G_MAXUINT, 0)
: NM_CONFIG_DEFAULT_CONNECTIVITY_INTERVAL;
g_free (interval);
- priv->dns_mode = g_key_file_get_value (priv->keyfile, "main", "dns", NULL);
- priv->rc_manager = g_key_file_get_value (priv->keyfile, "main", "rc-manager", NULL);
+ priv->dns_mode = g_key_file_get_value (priv->keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "dns", NULL);
+ priv->rc_manager = g_key_file_get_value (priv->keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "rc-manager", NULL);
- priv->ignore_carrier = nm_config_get_device_match_spec (priv->keyfile, "main", "ignore-carrier");
- priv->assume_ipv6ll_only = nm_config_get_device_match_spec (priv->keyfile, "main", "assume-ipv6ll-only");
+ priv->ignore_carrier = nm_config_get_device_match_spec (priv->keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "ignore-carrier");
+ priv->assume_ipv6ll_only = nm_config_get_device_match_spec (priv->keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "assume-ipv6ll-only");
- priv->no_auto_default.specs_config = nm_config_get_device_match_spec (priv->keyfile, "main", "no-auto-default");
+ priv->no_auto_default.specs_config = nm_config_get_device_match_spec (priv->keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "no-auto-default");
G_OBJECT_CLASS (nm_config_data_parent_class)->constructed (object);
}
diff --git a/src/nm-config.c b/src/nm-config.c
index d92d4628ec..8a948f64a9 100644
--- a/src/nm-config.c
+++ b/src/nm-config.c
@@ -478,8 +478,8 @@ _sort_groups_cmp (const char **pa, const char **pb, gpointer dummy)
a = *pa;
b = *pb;
- a_is_connection = g_str_has_prefix (a, "connection");
- b_is_connection = g_str_has_prefix (b, "connection");
+ a_is_connection = g_str_has_prefix (a, NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION);
+ b_is_connection = g_str_has_prefix (b, NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION);
if (a_is_connection != b_is_connection) {
/* one is a [connection*] entry, the other not. We sort [connection*] entires
@@ -771,23 +771,23 @@ read_entire_config (const NMConfigCmdLineOptions *cli,
* config files. */
if (cli && cli->plugins && cli->plugins[0])
- g_key_file_set_value (keyfile, "main", "plugins", cli->plugins);
- plugins_tmp = g_key_file_get_string_list (keyfile, "main", "plugins", NULL, NULL);
+ g_key_file_set_value (keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", cli->plugins);
+ plugins_tmp = g_key_file_get_string_list (keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", NULL, NULL);
if (!plugins_tmp) {
if (STRLEN (CONFIG_PLUGINS_DEFAULT) > 0)
- g_key_file_set_value (keyfile, "main", "plugins", CONFIG_PLUGINS_DEFAULT);
+ g_key_file_set_value (keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", CONFIG_PLUGINS_DEFAULT);
} else
g_strfreev (plugins_tmp);
if (cli && cli->configure_and_quit)
- g_key_file_set_value (keyfile, "main", "configure-and-quit", "true");
+ g_key_file_set_value (keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "configure-and-quit", "true");
if (cli && cli->connectivity_uri && cli->connectivity_uri[0])
- g_key_file_set_value (keyfile, "connectivity", "uri", cli->connectivity_uri);
+ g_key_file_set_value (keyfile, NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY, "uri", cli->connectivity_uri);
if (cli && cli->connectivity_interval >= 0)
- g_key_file_set_integer (keyfile, "connectivity", "interval", cli->connectivity_interval);
+ g_key_file_set_integer (keyfile, NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY, "interval", cli->connectivity_interval);
if (cli && cli->connectivity_response && cli->connectivity_response[0])
- g_key_file_set_value (keyfile, "connectivity", "response", cli->connectivity_response);
+ g_key_file_set_value (keyfile, NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY, "response", cli->connectivity_response);
*out_config_main_file = o_config_main_file;
*out_config_description = o_config_description;
@@ -1004,22 +1004,22 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
else
priv->no_auto_default_file = g_strdup (DEFAULT_NO_AUTO_DEFAULT_FILE);
- priv->plugins = g_key_file_get_string_list (keyfile, "main", "plugins", NULL, NULL);
+ priv->plugins = g_key_file_get_string_list (keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", NULL, NULL);
if (!priv->plugins)
priv->plugins = g_new0 (char *, 1);
- priv->monitor_connection_files = nm_config_keyfile_get_boolean (keyfile, "main", "monitor-connection-files", FALSE);
+ priv->monitor_connection_files = nm_config_keyfile_get_boolean (keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "monitor-connection-files", FALSE);
- priv->auth_polkit = nm_config_keyfile_get_boolean (keyfile, "main", "auth-polkit", NM_CONFIG_DEFAULT_AUTH_POLKIT);
+ priv->auth_polkit = nm_config_keyfile_get_boolean (keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "auth-polkit", NM_CONFIG_DEFAULT_AUTH_POLKIT);
- priv->dhcp_client = g_key_file_get_value (keyfile, "main", "dhcp", NULL);
+ priv->dhcp_client = g_key_file_get_value (keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "dhcp", NULL);
- priv->log_level = g_key_file_get_value (keyfile, "logging", "level", NULL);
- priv->log_domains = g_key_file_get_value (keyfile, "logging", "domains", NULL);
+ priv->log_level = g_key_file_get_value (keyfile, NM_CONFIG_KEYFILE_GROUP_LOGGING, "level", NULL);
+ priv->log_domains = g_key_file_get_value (keyfile, NM_CONFIG_KEYFILE_GROUP_LOGGING, "domains", NULL);
- priv->debug = g_key_file_get_value (keyfile, "main", "debug", NULL);
+ priv->debug = g_key_file_get_value (keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "debug", NULL);
- priv->configure_and_quit = nm_config_keyfile_get_boolean (keyfile, "main", "configure-and-quit", FALSE);
+ priv->configure_and_quit = nm_config_keyfile_get_boolean (keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "configure-and-quit", FALSE);
no_auto_default = no_auto_default_from_file (priv->no_auto_default_file);
diff --git a/src/nm-config.h b/src/nm-config.h
index 13c4eeca18..67d375c141 100644
--- a/src/nm-config.h
+++ b/src/nm-config.h
@@ -48,6 +48,20 @@ G_BEGIN_DECLS
#define NM_CONFIG_KEYFILE_LIST_SEPARATOR ','
+#define NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION "connection"
+
+#define NM_CONFIG_KEYFILE_GROUP_MAIN "main"
+#define NM_CONFIG_KEYFILE_GROUP_LOGGING "logging"
+#define NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY "connectivity"
+
+#define NM_CONFIG_KEYFILE_GROUP_KEYFILE "keyfile"
+#define NM_CONFIG_KEYFILE_GROUP_IFUPDOWN "ifupdown"
+#define NM_CONFIG_KEYFILE_GROUP_IFNET "ifnet"
+
+#define NM_CONFIG_KEYFILE_KEY_IFNET_AUTO_REFRESH "auto_refresh"
+#define NM_CONFIG_KEYFILE_KEY_IFNET_MANAGED "managed"
+#define NM_CONFIG_KEYFILE_KEY_IFUPDOWN_MANAGED "managed"
+
typedef struct NMConfigCmdLineOptions NMConfigCmdLineOptions;
struct _NMConfig {
diff --git a/src/settings/plugins/ifnet/net_parser.h b/src/settings/plugins/ifnet/net_parser.h
index 005207adfe..d10979cca6 100644
--- a/src/settings/plugins/ifnet/net_parser.h
+++ b/src/settings/plugins/ifnet/net_parser.h
@@ -25,7 +25,6 @@
#include <glib.h>
#define CONF_NET_FILE SYSCONFDIR "/conf.d/net"
-#define IFNET_KEY_FILE_GROUP "ifnet"
gboolean ifnet_init (gchar * config_file);
void ifnet_destroy (void);
diff --git a/src/settings/plugins/ifnet/plugin.c b/src/settings/plugins/ifnet/plugin.c
index 552a480994..550f31a5fc 100644
--- a/src/settings/plugins/ifnet/plugin.c
+++ b/src/settings/plugins/ifnet/plugin.c
@@ -46,7 +46,6 @@
#define IFNET_PLUGIN_NAME_PRINT "ifnet"
#define IFNET_PLUGIN_INFO "(C) 1999-2010 Gentoo Foundation, Inc. To report bugs please use bugs.gentoo.org with [networkmanager] or [qiaomuf] prefix."
#define IFNET_MANAGE_WELL_KNOWN_DEFAULT TRUE
-#define IFNET_KEY_FILE_KEY_MANAGED "managed"
typedef struct {
GHashTable *connections; /* uuid::connection */
@@ -83,7 +82,7 @@ static gboolean
is_managed_plugin (void)
{
return nm_config_data_get_value_boolean (NM_CONFIG_GET_DATA_ORIG,
- IFNET_KEY_FILE_GROUP, IFNET_KEY_FILE_KEY_MANAGED,
+ NM_CONFIG_KEYFILE_GROUP_IFNET, NM_CONFIG_KEYFILE_KEY_IFNET_MANAGED,
IFNET_MANAGE_WELL_KNOWN_DEFAULT);
}
@@ -210,7 +209,7 @@ reload_connections (NMSystemConfigInterface *config)
nm_log_info (LOGD_SETTINGS, "Loading connections");
auto_refresh = nm_config_data_get_value_boolean (NM_CONFIG_GET_DATA_ORIG,
- IFNET_KEY_FILE_GROUP, "auto_refresh",
+ NM_CONFIG_KEYFILE_GROUP_IFNET, NM_CONFIG_KEYFILE_KEY_IFNET_AUTO_REFRESH,
FALSE);
new_connections = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
diff --git a/src/settings/plugins/ifupdown/plugin.c b/src/settings/plugins/ifupdown/plugin.c
index 0252a1ba47..c3cb180b58 100644
--- a/src/settings/plugins/ifupdown/plugin.c
+++ b/src/settings/plugins/ifupdown/plugin.c
@@ -59,8 +59,6 @@
#define IFUPDOWN_PLUGIN_NAME "ifupdown"
#define IFUPDOWN_PLUGIN_INFO "(C) 2008 Canonical Ltd. To report bugs please use the NetworkManager mailing list."
-#define IFUPDOWN_KEY_FILE_GROUP "ifupdown"
-#define IFUPDOWN_KEY_FILE_KEY_MANAGED "managed"
#define IFUPDOWN_UNMANAGE_WELL_KNOWN_DEFAULT TRUE
/* #define ALWAYS_UNMANAGE TRUE */
@@ -417,8 +415,8 @@ SCPluginIfupdown_init (NMSystemConfigInterface *config)
/* Check the config file to find out whether to manage interfaces */
priv->unmanage_well_known = !nm_config_data_get_value_boolean (NM_CONFIG_GET_DATA_ORIG,
- IFUPDOWN_KEY_FILE_GROUP,
- IFUPDOWN_KEY_FILE_KEY_MANAGED,
+ NM_CONFIG_KEYFILE_GROUP_IFUPDOWN,
+ NM_CONFIG_KEYFILE_KEY_IFUPDOWN_MANAGED,
!IFUPDOWN_UNMANAGE_WELL_KNOWN_DEFAULT);
nm_log_info (LOGD_SETTINGS, "management mode: %s", priv->unmanage_well_known ? "unmanaged" : "managed");
diff --git a/src/settings/plugins/keyfile/plugin.c b/src/settings/plugins/keyfile/plugin.c
index 5ca0374b3d..f12ffd90e1 100644
--- a/src/settings/plugins/keyfile/plugin.c
+++ b/src/settings/plugins/keyfile/plugin.c
@@ -323,8 +323,8 @@ config_changed_cb (NMConfig *config,
{
gs_free char *old_value = NULL, *new_value = NULL;
- old_value = nm_config_data_get_value (old_data, "keyfile", "unmanaged-devices");
- new_value = nm_config_data_get_value (config_data, "keyfile", "unmanaged-devices");
+ old_value = nm_config_data_get_value (old_data, NM_CONFIG_KEYFILE_GROUP_KEYFILE, "unmanaged-devices");
+ new_value = nm_config_data_get_value (config_data, NM_CONFIG_KEYFILE_GROUP_KEYFILE, "unmanaged-devices");
if (g_strcmp0 (old_value, new_value) != 0)
g_signal_emit_by_name (self, NM_SYSTEM_CONFIG_INTERFACE_UNMANAGED_SPECS_CHANGED);
@@ -526,7 +526,7 @@ get_unmanaged_specs (NMSystemConfigInterface *config)
SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (config);
gs_free char *value = NULL;
- value = nm_config_data_get_value (nm_config_get_data (priv->config), "keyfile", "unmanaged-devices");
+ value = nm_config_data_get_value (nm_config_get_data (priv->config), NM_CONFIG_KEYFILE_GROUP_KEYFILE, "unmanaged-devices");
return nm_match_spec_split (value);
}
@@ -647,7 +647,7 @@ nm_settings_keyfile_plugin_new (void)
priv->config = g_object_ref (nm_config_get ());
value = nm_config_data_get_value (nm_config_get_data (priv->config),
- "keyfile", "hostname");
+ NM_CONFIG_KEYFILE_GROUP_KEYFILE, "hostname");
if (value) {
nm_log_warn (LOGD_SETTINGS, "keyfile: 'hostname' option is deprecated and has no effect");
g_free (value);