mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-11 16:50:19 +01:00
2008-09-24 Tambet Ingo <tambet@gmail.com>
* system-settings/plugins/keyfile/plugin.c: Implement unmanaged_devices method and get/set hostname property. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4094 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
6ac525267b
commit
7faa88681b
4 changed files with 192 additions and 5 deletions
|
|
@ -1,3 +1,8 @@
|
|||
2008-09-24 Tambet Ingo <tambet@gmail.com>
|
||||
|
||||
* system-settings/plugins/keyfile/plugin.c: Implement unmanaged_devices
|
||||
method and get/set hostname property.
|
||||
|
||||
2008-09-24 Tambet Ingo <tambet@gmail.com>
|
||||
|
||||
* src/supplicant-manager/nm-supplicant-interface.c
|
||||
|
|
|
|||
|
|
@ -638,10 +638,9 @@ set_property (GObject *object, guint prop_id,
|
|||
switch (prop_id) {
|
||||
case NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME:
|
||||
hostname = g_value_get_string (value);
|
||||
if (!strlen (hostname))
|
||||
if (hostname && strlen (hostname) < 1)
|
||||
hostname = NULL;
|
||||
plugin_set_hostname (SC_PLUGIN_IFCFG (object),
|
||||
(hostname && strlen (hostname)) ? hostname : NULL);
|
||||
plugin_set_hostname (SC_PLUGIN_IFCFG (object), hostname);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ libnm_settings_plugin_keyfile_la_CPPFLAGS = \
|
|||
$(GLIB_CFLAGS) \
|
||||
$(GMODULE_CFLAGS) \
|
||||
$(DBUS_CFLAGS) \
|
||||
-DSYSCONFDIR=\"$(sysconfdir)\" \
|
||||
-DG_DISABLE_DEPRECATED \
|
||||
-I${top_srcdir}/system-settings/src \
|
||||
-I$(top_srcdir)/include \
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@
|
|||
#define KEYFILE_PLUGIN_NAME "keyfile"
|
||||
#define KEYFILE_PLUGIN_INFO "(c) 2007 - 2008 Red Hat, Inc. To report bugs please use the NetworkManager mailing list."
|
||||
|
||||
#define CONF_FILE SYSCONFDIR "/NetworkManager/nm-system-settings.conf"
|
||||
|
||||
static char *plugin_get_hostname (SCPluginKeyfile *plugin);
|
||||
static void system_config_interface_init (NMSystemConfigInterface *system_config_interface_class);
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED (SCPluginKeyfile, sc_plugin_keyfile, G_TYPE_OBJECT, 0,
|
||||
|
|
@ -40,6 +43,11 @@ typedef struct {
|
|||
GFileMonitor *monitor;
|
||||
guint monitor_id;
|
||||
|
||||
GFileMonitor *conf_file_monitor;
|
||||
guint conf_file_monitor_id;
|
||||
|
||||
char *hostname;
|
||||
|
||||
gboolean disposed;
|
||||
} SCPluginKeyfilePrivate;
|
||||
|
||||
|
|
@ -212,6 +220,43 @@ dir_changed (GFileMonitor *monitor,
|
|||
g_free (name);
|
||||
}
|
||||
|
||||
static void
|
||||
conf_file_changed (GFileMonitor *monitor,
|
||||
GFile *file,
|
||||
GFile *other_file,
|
||||
GFileMonitorEvent event_type,
|
||||
gpointer data)
|
||||
{
|
||||
SCPluginKeyfile *self = SC_PLUGIN_KEYFILE (data);
|
||||
SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (self);
|
||||
char *tmp;
|
||||
|
||||
switch (event_type) {
|
||||
case G_FILE_MONITOR_EVENT_DELETED:
|
||||
case G_FILE_MONITOR_EVENT_CREATED:
|
||||
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
|
||||
g_signal_emit_by_name (self, "unmanaged-devices-changed");
|
||||
|
||||
/* hostname */
|
||||
tmp = plugin_get_hostname (self);
|
||||
if ((tmp && !priv->hostname)
|
||||
|| (!tmp && priv->hostname)
|
||||
|| (priv->hostname && tmp && strcmp (priv->hostname, tmp))) {
|
||||
|
||||
g_free (priv->hostname);
|
||||
priv->hostname = tmp;
|
||||
tmp = NULL;
|
||||
g_object_notify (G_OBJECT (self), NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME);
|
||||
}
|
||||
|
||||
g_free (tmp);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
setup_monitoring (NMSystemConfigInterface *config)
|
||||
{
|
||||
|
|
@ -229,6 +274,15 @@ setup_monitoring (NMSystemConfigInterface *config)
|
|||
priv->monitor_id = g_signal_connect (monitor, "changed", G_CALLBACK (dir_changed), config);
|
||||
priv->monitor = monitor;
|
||||
}
|
||||
|
||||
file = g_file_new_for_path (CONF_FILE);
|
||||
monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL);
|
||||
g_object_unref (file);
|
||||
|
||||
if (monitor) {
|
||||
priv->conf_file_monitor_id = g_signal_connect (monitor, "changed", G_CALLBACK (conf_file_changed), config);
|
||||
priv->conf_file_monitor = monitor;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -265,11 +319,107 @@ add_connection (NMSystemConfigInterface *config,
|
|||
return write_connection (connection, NULL, error);
|
||||
}
|
||||
|
||||
static GSList *
|
||||
get_unmanaged_devices (NMSystemConfigInterface *config)
|
||||
{
|
||||
GKeyFile *key_file;
|
||||
GSList *unmanaged_devices = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
key_file = g_key_file_new ();
|
||||
if (g_key_file_load_from_file (key_file, CONF_FILE, G_KEY_FILE_NONE, &error)) {
|
||||
char *str;
|
||||
|
||||
str = g_key_file_get_value (key_file, "keyfile", "unmanaged-devices", NULL);
|
||||
if (str) {
|
||||
char **udis;
|
||||
int i;
|
||||
|
||||
udis = g_strsplit (str, ";", -1);
|
||||
g_free (str);
|
||||
|
||||
for (i = 0; udis[i] != NULL; i++)
|
||||
unmanaged_devices = g_slist_append (unmanaged_devices, udis[i]);
|
||||
|
||||
g_free (udis); /* Yes, g_free, not g_strfreev because we need the strings in the list */
|
||||
}
|
||||
} else {
|
||||
g_warning ("Error parsing file '%s': %s", CONF_FILE, error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
g_key_file_free (key_file);
|
||||
|
||||
return unmanaged_devices;
|
||||
}
|
||||
|
||||
static char *
|
||||
plugin_get_hostname (SCPluginKeyfile *plugin)
|
||||
{
|
||||
GKeyFile *key_file;
|
||||
char *hostname;
|
||||
GError *error = NULL;
|
||||
|
||||
key_file = g_key_file_new ();
|
||||
if (g_key_file_load_from_file (key_file, CONF_FILE, G_KEY_FILE_NONE, &error))
|
||||
hostname = g_key_file_get_value (key_file, "keyfile", "hostname", NULL);
|
||||
else {
|
||||
g_warning ("Error parsing file '%s': %s", CONF_FILE, error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
g_key_file_free (key_file);
|
||||
|
||||
return hostname;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
plugin_set_hostname (SCPluginKeyfile *plugin, const char *hostname)
|
||||
{
|
||||
SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (plugin);
|
||||
GKeyFile *key_file;
|
||||
GError *error = NULL;
|
||||
gboolean result = FALSE;
|
||||
|
||||
key_file = g_key_file_new ();
|
||||
if (g_key_file_load_from_file (key_file, CONF_FILE, G_KEY_FILE_NONE, &error)) {
|
||||
char *data;
|
||||
gsize len;
|
||||
|
||||
g_key_file_set_string (key_file, "keyfile", "hostname", hostname);
|
||||
|
||||
data = g_key_file_to_data (key_file, &len, &error);
|
||||
if (data) {
|
||||
g_file_set_contents (CONF_FILE, data, len, &error);
|
||||
g_free (data);
|
||||
|
||||
g_free (priv->hostname);
|
||||
priv->hostname = hostname ? g_strdup (hostname) : NULL;
|
||||
result = TRUE;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
g_warning ("Error saving hostname: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
} else {
|
||||
g_warning ("Error parsing file '%s': %s", CONF_FILE, error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
g_key_file_free (key_file);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* GObject */
|
||||
|
||||
static void
|
||||
sc_plugin_keyfile_init (SCPluginKeyfile *plugin)
|
||||
{
|
||||
SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (plugin);
|
||||
|
||||
priv->hostname = plugin_get_hostname (plugin);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -284,10 +434,30 @@ get_property (GObject *object, guint prop_id,
|
|||
g_value_set_string (value, KEYFILE_PLUGIN_INFO);
|
||||
break;
|
||||
case NM_SYSTEM_CONFIG_INTERFACE_PROP_CAPABILITIES:
|
||||
g_value_set_uint (value, NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_CONNECTIONS);
|
||||
g_value_set_uint (value, NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_CONNECTIONS |
|
||||
NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_HOSTNAME);
|
||||
break;
|
||||
case NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME:
|
||||
g_value_set_string (value, "");
|
||||
g_value_set_string (value, SC_PLUGIN_KEYFILE_GET_PRIVATE (object)->hostname);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
const char *hostname;
|
||||
|
||||
switch (prop_id) {
|
||||
case NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME:
|
||||
hostname = g_value_get_string (value);
|
||||
if (hostname && strlen (hostname) < 1)
|
||||
hostname = NULL;
|
||||
plugin_set_hostname (SC_PLUGIN_KEYFILE (object), hostname);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
|
|
@ -313,6 +483,16 @@ dispose (GObject *object)
|
|||
g_object_unref (priv->monitor);
|
||||
}
|
||||
|
||||
if (priv->conf_file_monitor) {
|
||||
if (priv->conf_file_monitor_id)
|
||||
g_signal_handler_disconnect (priv->conf_file_monitor, priv->conf_file_monitor_id);
|
||||
|
||||
g_file_monitor_cancel (priv->conf_file_monitor);
|
||||
g_object_unref (priv->conf_file_monitor);
|
||||
}
|
||||
|
||||
g_free (priv->hostname);
|
||||
|
||||
if (priv->hash)
|
||||
g_hash_table_destroy (priv->hash);
|
||||
|
||||
|
|
@ -328,6 +508,7 @@ sc_plugin_keyfile_class_init (SCPluginKeyfileClass *req_class)
|
|||
|
||||
object_class->dispose = dispose;
|
||||
object_class->get_property = get_property;
|
||||
object_class->set_property = set_property;
|
||||
|
||||
g_object_class_override_property (object_class,
|
||||
NM_SYSTEM_CONFIG_INTERFACE_PROP_NAME,
|
||||
|
|
@ -352,6 +533,7 @@ system_config_interface_init (NMSystemConfigInterface *system_config_interface_c
|
|||
/* interface implementation */
|
||||
system_config_interface_class->get_connections = get_connections;
|
||||
system_config_interface_class->add_connection = add_connection;
|
||||
system_config_interface_class->get_unmanaged_devices = get_unmanaged_devices;
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT GObject *
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue