mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-15 06:50:35 +01:00
config: use NMConfigData in NMConfig
(cherry picked from commit 50fce5a860)
This commit is contained in:
parent
5a7506a405
commit
a56fe5ae0c
4 changed files with 50 additions and 44 deletions
|
|
@ -55,6 +55,9 @@ struct NMConfigCmdLineOptions {
|
|||
typedef struct {
|
||||
NMConfigCmdLineOptions cli;
|
||||
|
||||
NMConfigData *config_data;
|
||||
NMConfigData *config_data_orig;
|
||||
|
||||
char *nm_conf_path;
|
||||
char *config_dir;
|
||||
char *config_description;
|
||||
|
|
@ -72,10 +75,6 @@ typedef struct {
|
|||
|
||||
char *debug;
|
||||
|
||||
char *connectivity_uri;
|
||||
guint connectivity_interval;
|
||||
char *connectivity_response;
|
||||
|
||||
char **no_auto_default;
|
||||
char **ignore_carrier;
|
||||
|
||||
|
|
@ -123,6 +122,25 @@ _get_bool_value (GKeyFile *keyfile,
|
|||
|
||||
/************************************************************************/
|
||||
|
||||
NMConfigData *
|
||||
nm_config_get_data (NMConfig *config)
|
||||
{
|
||||
g_return_val_if_fail (config != NULL, NULL);
|
||||
|
||||
return NM_CONFIG_GET_PRIVATE (config)->config_data;
|
||||
}
|
||||
|
||||
/* The NMConfigData instance is reloadable and will be swapped on reload.
|
||||
* nm_config_get_data_orig() returns the original configuration, when the NMConfig
|
||||
* instance was created. */
|
||||
NMConfigData *
|
||||
nm_config_get_data_orig (NMConfig *config)
|
||||
{
|
||||
g_return_val_if_fail (config != NULL, NULL);
|
||||
|
||||
return NM_CONFIG_GET_PRIVATE (config)->config_data_orig;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_config_get_path (NMConfig *config)
|
||||
{
|
||||
|
|
@ -203,30 +221,6 @@ nm_config_get_debug (NMConfig *config)
|
|||
return NM_CONFIG_GET_PRIVATE (config)->debug;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_config_get_connectivity_uri (NMConfig *config)
|
||||
{
|
||||
g_return_val_if_fail (config != NULL, NULL);
|
||||
|
||||
return NM_CONFIG_GET_PRIVATE (config)->connectivity_uri;
|
||||
}
|
||||
|
||||
guint
|
||||
nm_config_get_connectivity_interval (NMConfig *config)
|
||||
{
|
||||
g_return_val_if_fail (config != NULL, 0);
|
||||
|
||||
return NM_CONFIG_GET_PRIVATE (config)->connectivity_interval;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_config_get_connectivity_response (NMConfig *config)
|
||||
{
|
||||
g_return_val_if_fail (config != NULL, NULL);
|
||||
|
||||
return NM_CONFIG_GET_PRIVATE (config)->connectivity_response;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_config_get_configure_and_quit (NMConfig *config)
|
||||
{
|
||||
|
|
@ -601,6 +595,8 @@ nm_config_new (const NMConfigCmdLineOptions *cli, GError **error)
|
|||
int i;
|
||||
GString *config_description;
|
||||
NMConfig *self;
|
||||
char *connectivity_uri, *connectivity_response;
|
||||
guint connectivity_interval;
|
||||
|
||||
self = NM_CONFIG (g_object_new (NM_TYPE_CONFIG, NULL));
|
||||
priv = NM_CONFIG_GET_PRIVATE (self);
|
||||
|
|
@ -685,20 +681,29 @@ nm_config_new (const NMConfigCmdLineOptions *cli, GError **error)
|
|||
|
||||
if (priv->cli.connectivity_uri && priv->cli.connectivity_uri[0])
|
||||
g_key_file_set_value (priv->keyfile, "connectivity", "uri", priv->cli.connectivity_uri);
|
||||
priv->connectivity_uri = g_key_file_get_value (priv->keyfile, "connectivity", "uri", NULL);
|
||||
connectivity_uri = g_key_file_get_value (priv->keyfile, "connectivity", "uri", NULL);
|
||||
|
||||
if (priv->cli.connectivity_interval >= 0)
|
||||
g_key_file_set_integer (priv->keyfile, "connectivity", "interval", priv->cli.connectivity_interval);
|
||||
priv->connectivity_interval = g_key_file_get_integer (priv->keyfile, "connectivity", "interval", NULL);
|
||||
connectivity_interval = g_key_file_get_integer (priv->keyfile, "connectivity", "interval", NULL);
|
||||
|
||||
if (priv->cli.connectivity_response && priv->cli.connectivity_response[0])
|
||||
g_key_file_set_value (priv->keyfile, "connectivity", "response", priv->cli.connectivity_response);
|
||||
priv->connectivity_response = g_key_file_get_value (priv->keyfile, "connectivity", "response", NULL);
|
||||
connectivity_response = g_key_file_get_value (priv->keyfile, "connectivity", "response", NULL);
|
||||
|
||||
priv->ignore_carrier = g_key_file_get_string_list (priv->keyfile, "main", "ignore-carrier", NULL, NULL);
|
||||
|
||||
priv->configure_and_quit = _get_bool_value (priv->keyfile, "main", "configure-and-quit", FALSE);
|
||||
|
||||
priv->config_data = g_object_new (NM_TYPE_CONFIG_DATA,
|
||||
NM_CONFIG_DATA_CONNECTIVITY_URI, connectivity_uri,
|
||||
NM_CONFIG_DATA_CONNECTIVITY_INTERVAL, connectivity_interval,
|
||||
NM_CONFIG_DATA_CONNECTIVITY_RESPONSE, connectivity_response,
|
||||
NULL);
|
||||
priv->config_data_orig = g_object_ref (priv->config_data);
|
||||
g_free (connectivity_uri);
|
||||
g_free (connectivity_response);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
@ -729,13 +734,14 @@ finalize (GObject *gobject)
|
|||
g_free (priv->log_level);
|
||||
g_free (priv->log_domains);
|
||||
g_free (priv->debug);
|
||||
g_free (priv->connectivity_uri);
|
||||
g_free (priv->connectivity_response);
|
||||
g_strfreev (priv->no_auto_default);
|
||||
g_strfreev (priv->ignore_carrier);
|
||||
|
||||
_nm_config_cmd_line_options_clear (&priv->cli);
|
||||
|
||||
g_clear_object (&priv->config_data);
|
||||
g_clear_object (&priv->config_data_orig);
|
||||
|
||||
G_OBJECT_CLASS (nm_config_parent_class)->finalize (gobject);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#include <glib-object.h>
|
||||
|
||||
#include "nm-types.h"
|
||||
#include "nm-config-data.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
@ -50,6 +51,8 @@ GType nm_config_get_type (void);
|
|||
|
||||
NMConfig *nm_config_get (void);
|
||||
|
||||
NMConfigData *nm_config_get_data (NMConfig *config);
|
||||
NMConfigData *nm_config_get_data_orig (NMConfig *config);
|
||||
const char *nm_config_get_path (NMConfig *config);
|
||||
const char *nm_config_get_description (NMConfig *config);
|
||||
const char **nm_config_get_plugins (NMConfig *config);
|
||||
|
|
@ -60,9 +63,6 @@ const char *nm_config_get_dns_mode (NMConfig *config);
|
|||
const char *nm_config_get_log_level (NMConfig *config);
|
||||
const char *nm_config_get_log_domains (NMConfig *config);
|
||||
const char *nm_config_get_debug (NMConfig *config);
|
||||
const char *nm_config_get_connectivity_uri (NMConfig *config);
|
||||
guint nm_config_get_connectivity_interval (NMConfig *config);
|
||||
const char *nm_config_get_connectivity_response (NMConfig *config);
|
||||
gboolean nm_config_get_configure_and_quit (NMConfig *config);
|
||||
|
||||
gboolean nm_config_get_ethernet_can_auto_default (NMConfig *config, NMDevice *device);
|
||||
|
|
|
|||
|
|
@ -348,15 +348,15 @@ nm_connectivity_check_finish (NMConnectivity *self,
|
|||
NMConnectivity *
|
||||
nm_connectivity_new (void)
|
||||
{
|
||||
NMConfig *config = nm_config_get ();
|
||||
NMConfigData *config_data = nm_config_get_data (nm_config_get ());
|
||||
|
||||
/* NMConnectivity is (almost) independent from NMConfig and works
|
||||
* fine without it. As convenience, the default constructor nm_connectivity_new()
|
||||
* uses the parameters from NMConfig to create an instance. */
|
||||
return g_object_new (NM_TYPE_CONNECTIVITY,
|
||||
NM_CONNECTIVITY_URI, nm_config_get_connectivity_uri (config),
|
||||
NM_CONNECTIVITY_INTERVAL, nm_config_get_connectivity_interval (config),
|
||||
NM_CONNECTIVITY_RESPONSE, nm_config_get_connectivity_response (config),
|
||||
NM_CONNECTIVITY_URI, nm_config_data_get_connectivity_uri (config_data),
|
||||
NM_CONNECTIVITY_INTERVAL, nm_config_data_get_connectivity_interval (config_data),
|
||||
NM_CONNECTIVITY_RESPONSE, nm_config_data_get_connectivity_response (config_data),
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ test_config_simple (void)
|
|||
g_assert_cmpstr (nm_config_get_path (config), ==, SRCDIR "/NetworkManager.conf");
|
||||
g_assert_cmpstr (nm_config_get_dhcp_client (config), ==, "dhclient");
|
||||
g_assert_cmpstr (nm_config_get_log_level (config), ==, "INFO");
|
||||
g_assert_cmpint (nm_config_get_connectivity_interval (config), ==, 100);
|
||||
g_assert_cmpint (nm_config_data_get_connectivity_interval (nm_config_get_data_orig (config)), ==, 100);
|
||||
|
||||
plugins = nm_config_get_plugins (config);
|
||||
g_assert_cmpint (g_strv_length ((char **)plugins), ==, 3);
|
||||
|
|
@ -159,7 +159,7 @@ test_config_override (void)
|
|||
g_assert_cmpstr (nm_config_get_path (config), ==, SRCDIR "/NetworkManager.conf");
|
||||
g_assert_cmpstr (nm_config_get_dhcp_client (config), ==, "dhclient");
|
||||
g_assert_cmpstr (nm_config_get_log_level (config), ==, "INFO");
|
||||
g_assert_cmpint (nm_config_get_connectivity_interval (config), ==, 12);
|
||||
g_assert_cmpint (nm_config_data_get_connectivity_interval (nm_config_get_data_orig (config)), ==, 12);
|
||||
|
||||
plugins = nm_config_get_plugins (config);
|
||||
g_assert_cmpint (g_strv_length ((char **)plugins), ==, 4);
|
||||
|
|
@ -241,8 +241,8 @@ test_config_confdir (void)
|
|||
g_assert_cmpstr (nm_config_get_dhcp_client (config), ==, "dhcpcd");
|
||||
g_assert_cmpstr (nm_config_get_log_level (config), ==, "INFO");
|
||||
g_assert_cmpstr (nm_config_get_log_domains (config), ==, "PLATFORM,DNS,WIFI");
|
||||
g_assert_cmpstr (nm_config_get_connectivity_uri (config), ==, "http://example.net");
|
||||
g_assert_cmpint (nm_config_get_connectivity_interval (config), ==, 100);
|
||||
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);
|
||||
g_assert_cmpint (g_strv_length ((char **)plugins), ==, 5);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue