mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-03 08:10:17 +01:00
config: optionally let nm_config_get_plugins() return compile time default
Instead of having the caller do the fallback to the compile time default plugins, let it be handled by nm_config_get_plugins(). The knowledge of fallback to a compile time default (and how to do that properly) should be inside NMConfig/NMConfigData alone. Also, as this function is only called once, let NMConfig not cache the string list but create it once as needed.
This commit is contained in:
parent
544f7d3683
commit
6689d0bf71
6 changed files with 34 additions and 38 deletions
|
|
@ -217,6 +217,27 @@ nm_config_data_get_value_boolean (const NMConfigData *self, const char *group, c
|
|||
return value;
|
||||
}
|
||||
|
||||
char **
|
||||
nm_config_data_get_plugins (const NMConfigData *self, gboolean allow_default)
|
||||
{
|
||||
const NMConfigDataPrivate *priv;
|
||||
char **list;
|
||||
|
||||
g_return_val_if_fail (self, NULL);
|
||||
|
||||
priv = NM_CONFIG_DATA_GET_PRIVATE (self);
|
||||
|
||||
list = g_key_file_get_string_list (priv->keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", NULL, NULL);
|
||||
if (!list && allow_default) {
|
||||
gs_unref_keyfile GKeyFile *kf = nm_config_create_keyfile ();
|
||||
|
||||
/* let keyfile split the default string according to it's own escaping rules. */
|
||||
g_key_file_set_value (kf, NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", NM_CONFIG_PLUGINS_DEFAULT);
|
||||
list = g_key_file_get_string_list (kf, NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", NULL, NULL);
|
||||
}
|
||||
return _nm_utils_strv_cleanup (list, TRUE, TRUE, TRUE);
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_config_data_get_connectivity_uri (const NMConfigData *self)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -158,6 +158,7 @@ char *nm_config_data_get_value (const NMConfigData *config_data, const char *gro
|
|||
const char *nm_config_data_get_value_cached (const NMConfigData *config_data, const char *group, const char *key, NMConfigGetValueFlags flags);
|
||||
gint nm_config_data_get_value_boolean (const NMConfigData *self, const char *group, const char *key, gint default_value);
|
||||
|
||||
char **nm_config_data_get_plugins (const NMConfigData *config_data, gboolean allow_default);
|
||||
const char *nm_config_data_get_connectivity_uri (const NMConfigData *config_data);
|
||||
const guint nm_config_data_get_connectivity_interval (const NMConfigData *config_data);
|
||||
const char *nm_config_data_get_connectivity_response (const NMConfigData *config_data);
|
||||
|
|
|
|||
|
|
@ -91,7 +91,6 @@ typedef struct {
|
|||
char *no_auto_default_file;
|
||||
char *intern_config_file;
|
||||
|
||||
char **plugins;
|
||||
gboolean monitor_connection_files;
|
||||
gboolean auth_polkit;
|
||||
char *dhcp_client;
|
||||
|
|
@ -260,14 +259,6 @@ nm_config_get_data_orig (NMConfig *config)
|
|||
return NM_CONFIG_GET_PRIVATE (config)->config_data_orig;
|
||||
}
|
||||
|
||||
const char **
|
||||
nm_config_get_plugins (NMConfig *config)
|
||||
{
|
||||
g_return_val_if_fail (config != NULL, NULL);
|
||||
|
||||
return (const char **) NM_CONFIG_GET_PRIVATE (config)->plugins;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_config_get_monitor_connection_files (NMConfig *config)
|
||||
{
|
||||
|
|
@ -2331,9 +2322,6 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
|
|||
else
|
||||
priv->no_auto_default_file = g_strdup (DEFAULT_NO_AUTO_DEFAULT_FILE);
|
||||
|
||||
priv->plugins = _nm_utils_strv_cleanup (g_key_file_get_string_list (keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", NULL, NULL),
|
||||
TRUE, TRUE, TRUE);
|
||||
|
||||
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, NM_CONFIG_KEYFILE_GROUP_MAIN, "auth-polkit", NM_CONFIG_DEFAULT_AUTH_POLKIT_BOOL);
|
||||
|
|
@ -2402,7 +2390,6 @@ finalize (GObject *gobject)
|
|||
g_free (priv->system_config_dir);
|
||||
g_free (priv->no_auto_default_file);
|
||||
g_free (priv->intern_config_file);
|
||||
g_strfreev (priv->plugins);
|
||||
g_free (priv->dhcp_client);
|
||||
g_free (priv->log_level);
|
||||
g_free (priv->log_domains);
|
||||
|
|
|
|||
|
|
@ -114,7 +114,6 @@ NMConfigData *nm_config_get_data_orig (NMConfig *config);
|
|||
#define NM_CONFIG_GET_DATA (nm_config_get_data (nm_config_get ()))
|
||||
#define NM_CONFIG_GET_DATA_ORIG (nm_config_get_data_orig (nm_config_get ()))
|
||||
|
||||
const char **nm_config_get_plugins (NMConfig *config);
|
||||
gboolean nm_config_get_monitor_connection_files (NMConfig *config);
|
||||
gboolean nm_config_get_auth_polkit (NMConfig *config);
|
||||
const char *nm_config_get_dhcp_client (NMConfig *config);
|
||||
|
|
|
|||
|
|
@ -2284,19 +2284,14 @@ nm_settings_start (NMSettings *self, GError **error)
|
|||
GDBusProxy *proxy;
|
||||
GVariant *variant;
|
||||
GError *local_error = NULL;
|
||||
const char **plugins;
|
||||
gs_strfreev char **plugins_default = NULL;
|
||||
gs_strfreev char **plugins = NULL;
|
||||
|
||||
priv = NM_SETTINGS_GET_PRIVATE (self);
|
||||
|
||||
/* Load the plugins; fail if a plugin is not found. */
|
||||
plugins = nm_config_get_plugins (priv->config);
|
||||
if (!plugins) {
|
||||
plugins_default = g_strsplit (NM_CONFIG_PLUGINS_DEFAULT, ",", -1);
|
||||
plugins = (const char **) plugins_default;
|
||||
}
|
||||
plugins = nm_config_data_get_plugins (nm_config_get_data_orig (priv->config), TRUE);
|
||||
|
||||
if (!load_plugins (self, plugins, error)) {
|
||||
if (!load_plugins (self, (const char **) plugins, error)) {
|
||||
g_object_unref (self);
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,8 +114,8 @@ setup_config (GError **error, const char *config_file, const char *intern_config
|
|||
static void
|
||||
test_config_simple (void)
|
||||
{
|
||||
NMConfig *config;
|
||||
const char **plugins;
|
||||
gs_unref_object NMConfig *config = NULL;
|
||||
gs_strfreev char **plugins = NULL;
|
||||
char *value;
|
||||
gs_unref_object NMDevice *dev50 = nm_test_device_new ("00:00:00:00:00:50");
|
||||
gs_unref_object NMDevice *dev51 = nm_test_device_new ("00:00:00:00:00:51");
|
||||
|
|
@ -128,7 +128,7 @@ test_config_simple (void)
|
|||
g_assert_cmpstr (nm_config_get_log_level (config), ==, "INFO");
|
||||
g_assert_cmpint (nm_config_data_get_connectivity_interval (nm_config_get_data_orig (config)), ==, 100);
|
||||
|
||||
plugins = nm_config_get_plugins (config);
|
||||
plugins = nm_config_data_get_plugins (nm_config_get_data_orig (config), FALSE);
|
||||
g_assert_cmpint (g_strv_length ((char **)plugins), ==, 3);
|
||||
g_assert_cmpstr (plugins[0], ==, "foo");
|
||||
g_assert_cmpstr (plugins[1], ==, "bar");
|
||||
|
|
@ -190,9 +190,6 @@ test_config_simple (void)
|
|||
value = nm_config_data_get_connection_default (nm_config_get_data_orig (config), "dummy.test2", dev50);
|
||||
g_assert_cmpstr (value, ==, "no");
|
||||
g_free (value);
|
||||
|
||||
|
||||
g_object_unref (config);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -218,8 +215,8 @@ test_config_parse_error (void)
|
|||
static void
|
||||
test_config_override (void)
|
||||
{
|
||||
NMConfig *config;
|
||||
const char **plugins;
|
||||
gs_unref_object NMConfig *config = NULL;
|
||||
gs_strfreev char **plugins = NULL;
|
||||
|
||||
config = setup_config (NULL, SRCDIR "/NetworkManager.conf", "", NULL, "/no/such/dir", "",
|
||||
"--plugins", "alpha,beta,gamma,delta",
|
||||
|
|
@ -231,14 +228,12 @@ test_config_override (void)
|
|||
g_assert_cmpstr (nm_config_get_log_level (config), ==, "INFO");
|
||||
g_assert_cmpint (nm_config_data_get_connectivity_interval (nm_config_get_data_orig (config)), ==, 12);
|
||||
|
||||
plugins = nm_config_get_plugins (config);
|
||||
plugins = nm_config_data_get_plugins (nm_config_get_data_orig (config), FALSE);
|
||||
g_assert_cmpint (g_strv_length ((char **)plugins), ==, 4);
|
||||
g_assert_cmpstr (plugins[0], ==, "alpha");
|
||||
g_assert_cmpstr (plugins[1], ==, "beta");
|
||||
g_assert_cmpstr (plugins[2], ==, "gamma");
|
||||
g_assert_cmpstr (plugins[3], ==, "delta");
|
||||
|
||||
g_object_unref (config);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -374,8 +369,8 @@ test_config_no_auto_default (void)
|
|||
static void
|
||||
test_config_confdir (void)
|
||||
{
|
||||
NMConfig *config;
|
||||
const char **plugins;
|
||||
gs_unref_object NMConfig *config = NULL;
|
||||
gs_strfreev char **plugins = NULL;
|
||||
char *value;
|
||||
GSList *specs;
|
||||
|
||||
|
|
@ -388,7 +383,7 @@ test_config_confdir (void)
|
|||
g_assert_cmpstr (nm_config_data_get_connectivity_uri (nm_config_get_data_orig (config)), ==, "http://example.net");
|
||||
g_assert_cmpint (nm_config_data_get_connectivity_interval (nm_config_get_data_orig (config)), ==, 100);
|
||||
|
||||
plugins = nm_config_get_plugins (config);
|
||||
plugins = nm_config_data_get_plugins (nm_config_get_data_orig (config), FALSE);
|
||||
g_assert_cmpint (g_strv_length ((char **)plugins), ==, 5);
|
||||
g_assert_cmpstr (plugins[0], ==, "foo");
|
||||
g_assert_cmpstr (plugins[1], ==, "bar");
|
||||
|
|
@ -475,8 +470,6 @@ test_config_confdir (void)
|
|||
g_free (value);
|
||||
|
||||
nm_config_data_log (nm_config_get_data_orig (config), ">>> TEST: ", " ", NULL);
|
||||
|
||||
g_object_unref (config);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue