Commit 8b141171 authored by Thomas Haller's avatar Thomas Haller

keyfile: refactor GObject type creation

parent 5d80a8a7
......@@ -798,10 +798,9 @@ find_plugin (GSList *list, const char *pname)
static void
add_keyfile_plugin (NMSettings *self)
{
gs_unref_object GObject *keyfile_plugin = NULL;
gs_unref_object NMSKeyfilePlugin *keyfile_plugin = NULL;
keyfile_plugin = nms_keyfile_plugin_new ();
g_assert (keyfile_plugin);
if (!add_plugin (self, NM_SETTINGS_PLUGIN (keyfile_plugin)))
g_return_if_reached ();
}
......
......@@ -36,57 +36,19 @@
#include "nms-keyfile-writer.h"
#include "nms-keyfile-utils.h"
G_DEFINE_TYPE (NMSKeyfileConnection, nms_keyfile_connection, NM_TYPE_SETTINGS_CONNECTION)
/*****************************************************************************/
NMSKeyfileConnection *
nms_keyfile_connection_new (NMConnection *source,
const char *full_path,
GError **error)
{
GObject *object;
NMConnection *tmp;
const char *uuid;
gboolean update_unsaved = TRUE;
struct _NMSKeyfileConnection {
NMSettingsConnection parent;
};
g_assert (source || full_path);
struct _NMSKeyfileConnectionClass {
NMSettingsConnectionClass parent;
};
/* If we're given a connection already, prefer that instead of re-reading */
if (source)
tmp = g_object_ref (source);
else {
tmp = nms_keyfile_reader_from_file (full_path, error);
if (!tmp)
return NULL;
uuid = nm_connection_get_uuid (NM_CONNECTION (tmp));
if (!uuid) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Connection in file %s had no UUID", full_path);
g_object_unref (tmp);
return NULL;
}
/* If we just read the connection from disk, it's clearly not Unsaved */
update_unsaved = FALSE;
}
object = (GObject *) g_object_new (NMS_TYPE_KEYFILE_CONNECTION,
NM_SETTINGS_CONNECTION_FILENAME, full_path,
NULL);
/* Update our settings with what was read from the file */
if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object),
tmp,
update_unsaved,
NULL,
error)) {
g_object_unref (object);
object = NULL;
}
G_DEFINE_TYPE (NMSKeyfileConnection, nms_keyfile_connection, NM_TYPE_SETTINGS_CONNECTION)
g_object_unref (tmp);
return (NMSKeyfileConnection *) object;
}
/*****************************************************************************/
static void
commit_changes (NMSettingsConnection *connection,
......@@ -151,19 +113,68 @@ do_delete (NMSettingsConnection *connection,
user_data);
}
/* GObject */
/*****************************************************************************/
static void
nms_keyfile_connection_init (NMSKeyfileConnection *connection)
{
}
NMSKeyfileConnection *
nms_keyfile_connection_new (NMConnection *source,
const char *full_path,
GError **error)
{
GObject *object;
NMConnection *tmp;
const char *uuid;
gboolean update_unsaved = TRUE;
g_assert (source || full_path);
/* If we're given a connection already, prefer that instead of re-reading */
if (source)
tmp = g_object_ref (source);
else {
tmp = nms_keyfile_reader_from_file (full_path, error);
if (!tmp)
return NULL;
uuid = nm_connection_get_uuid (NM_CONNECTION (tmp));
if (!uuid) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Connection in file %s had no UUID", full_path);
g_object_unref (tmp);
return NULL;
}
/* If we just read the connection from disk, it's clearly not Unsaved */
update_unsaved = FALSE;
}
object = (GObject *) g_object_new (NMS_TYPE_KEYFILE_CONNECTION,
NM_SETTINGS_CONNECTION_FILENAME, full_path,
NULL);
/* Update our settings with what was read from the file */
if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object),
tmp,
update_unsaved,
NULL,
error)) {
g_object_unref (object);
object = NULL;
}
g_object_unref (tmp);
return (NMSKeyfileConnection *) object;
}
static void
nms_keyfile_connection_class_init (NMSKeyfileConnectionClass *keyfile_connection_class)
{
NMSettingsConnectionClass *settings_class = NM_SETTINGS_CONNECTION_CLASS (keyfile_connection_class);
/* Virtual methods */
settings_class->commit_changes = commit_changes;
settings_class->delete = do_delete;
}
......@@ -31,13 +31,8 @@
#define NMS_IS_KEYFILE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMS_TYPE_KEYFILE_CONNECTION))
#define NMS_KEYFILE_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMS_TYPE_KEYFILE_CONNECTION, NMSKeyfileConnectionClass))
typedef struct {
NMSettingsConnection parent;
} NMSKeyfileConnection;
typedef struct {
NMSettingsConnectionClass parent;
} NMSKeyfileConnectionClass;
typedef struct _NMSKeyfileConnection NMSKeyfileConnection;
typedef struct _NMSKeyfileConnectionClass NMSKeyfileConnectionClass;
GType nms_keyfile_connection_get_type (void);
......
......@@ -346,7 +346,7 @@ setup_monitoring (NMSettingsPlugin *config)
GFile *file;
GFileMonitor *monitor;
if (nm_config_get_monitor_connection_files (nm_config_get ())) {
if (nm_config_get_monitor_connection_files (priv->config)) {
file = g_file_new_for_path (nms_keyfile_utils_get_path ());
monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
g_object_unref (file);
......@@ -586,7 +586,7 @@ constructed (GObject *object)
nm_log_warn (LOGD_SETTINGS, "keyfile: 'hostname' option is deprecated and has no effect");
}
GObject *
NMSKeyfilePlugin *
nms_keyfile_plugin_new (void)
{
return g_object_new (NMS_TYPE_KEYFILE_PLUGIN, NULL);
......
......@@ -34,6 +34,6 @@ typedef struct _NMSKeyfilePluginClass NMSKeyfilePluginClass;
GType nms_keyfile_plugin_get_type (void);
GObject *nms_keyfile_plugin_new (void);
NMSKeyfilePlugin *nms_keyfile_plugin_new (void);
#endif /* __NMS_KEYFILE_PLUGIN_H__ */
......@@ -29,6 +29,8 @@
#include "NetworkManagerUtils.h"
/*****************************************************************************/
static const char *
_fmt_warn (const char *group, NMSetting *setting, const char *property_name, const char *message, char **out_message)
{
......
......@@ -32,6 +32,8 @@
#define NM_CONFIG_KEYFILE_PATH_DEFAULT NMCONFDIR "/system-connections"
/*****************************************************************************/
static const char temp_letters[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
......@@ -166,5 +168,3 @@ nms_keyfile_utils_get_path (void)
return path;
}
/*****************************************************************************/
......@@ -33,10 +33,13 @@
#include "nms-keyfile-utils.h"
/*****************************************************************************/
typedef struct {
const char *keyfile_dir;
} WriteInfo;
/*****************************************************************************/
static gboolean
write_cert_key_file (const char *path,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment