keyfile: refactor GObject type creation
This commit is contained in:
@@ -798,10 +798,9 @@ find_plugin (GSList *list, const char *pname)
|
|||||||
static void
|
static void
|
||||||
add_keyfile_plugin (NMSettings *self)
|
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 ();
|
keyfile_plugin = nms_keyfile_plugin_new ();
|
||||||
g_assert (keyfile_plugin);
|
|
||||||
if (!add_plugin (self, NM_SETTINGS_PLUGIN (keyfile_plugin)))
|
if (!add_plugin (self, NM_SETTINGS_PLUGIN (keyfile_plugin)))
|
||||||
g_return_if_reached ();
|
g_return_if_reached ();
|
||||||
}
|
}
|
||||||
|
@@ -36,57 +36,19 @@
|
|||||||
#include "nms-keyfile-writer.h"
|
#include "nms-keyfile-writer.h"
|
||||||
#include "nms-keyfile-utils.h"
|
#include "nms-keyfile-utils.h"
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
struct _NMSKeyfileConnection {
|
||||||
|
NMSettingsConnection parent;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _NMSKeyfileConnectionClass {
|
||||||
|
NMSettingsConnectionClass parent;
|
||||||
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE (NMSKeyfileConnection, nms_keyfile_connection, NM_TYPE_SETTINGS_CONNECTION)
|
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;
|
|
||||||
|
|
||||||
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
|
static void
|
||||||
commit_changes (NMSettingsConnection *connection,
|
commit_changes (NMSettingsConnection *connection,
|
||||||
@@ -151,19 +113,68 @@ do_delete (NMSettingsConnection *connection,
|
|||||||
user_data);
|
user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* GObject */
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nms_keyfile_connection_init (NMSKeyfileConnection *connection)
|
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
|
static void
|
||||||
nms_keyfile_connection_class_init (NMSKeyfileConnectionClass *keyfile_connection_class)
|
nms_keyfile_connection_class_init (NMSKeyfileConnectionClass *keyfile_connection_class)
|
||||||
{
|
{
|
||||||
NMSettingsConnectionClass *settings_class = NM_SETTINGS_CONNECTION_CLASS (keyfile_connection_class);
|
NMSettingsConnectionClass *settings_class = NM_SETTINGS_CONNECTION_CLASS (keyfile_connection_class);
|
||||||
|
|
||||||
/* Virtual methods */
|
|
||||||
settings_class->commit_changes = commit_changes;
|
settings_class->commit_changes = commit_changes;
|
||||||
settings_class->delete = do_delete;
|
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_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))
|
#define NMS_KEYFILE_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMS_TYPE_KEYFILE_CONNECTION, NMSKeyfileConnectionClass))
|
||||||
|
|
||||||
typedef struct {
|
typedef struct _NMSKeyfileConnection NMSKeyfileConnection;
|
||||||
NMSettingsConnection parent;
|
typedef struct _NMSKeyfileConnectionClass NMSKeyfileConnectionClass;
|
||||||
} NMSKeyfileConnection;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
NMSettingsConnectionClass parent;
|
|
||||||
} NMSKeyfileConnectionClass;
|
|
||||||
|
|
||||||
GType nms_keyfile_connection_get_type (void);
|
GType nms_keyfile_connection_get_type (void);
|
||||||
|
|
||||||
|
@@ -346,7 +346,7 @@ setup_monitoring (NMSettingsPlugin *config)
|
|||||||
GFile *file;
|
GFile *file;
|
||||||
GFileMonitor *monitor;
|
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 ());
|
file = g_file_new_for_path (nms_keyfile_utils_get_path ());
|
||||||
monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
|
monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
|
||||||
g_object_unref (file);
|
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");
|
nm_log_warn (LOGD_SETTINGS, "keyfile: 'hostname' option is deprecated and has no effect");
|
||||||
}
|
}
|
||||||
|
|
||||||
GObject *
|
NMSKeyfilePlugin *
|
||||||
nms_keyfile_plugin_new (void)
|
nms_keyfile_plugin_new (void)
|
||||||
{
|
{
|
||||||
return g_object_new (NMS_TYPE_KEYFILE_PLUGIN, NULL);
|
return g_object_new (NMS_TYPE_KEYFILE_PLUGIN, NULL);
|
||||||
|
@@ -34,6 +34,6 @@ typedef struct _NMSKeyfilePluginClass NMSKeyfilePluginClass;
|
|||||||
|
|
||||||
GType nms_keyfile_plugin_get_type (void);
|
GType nms_keyfile_plugin_get_type (void);
|
||||||
|
|
||||||
GObject *nms_keyfile_plugin_new (void);
|
NMSKeyfilePlugin *nms_keyfile_plugin_new (void);
|
||||||
|
|
||||||
#endif /* __NMS_KEYFILE_PLUGIN_H__ */
|
#endif /* __NMS_KEYFILE_PLUGIN_H__ */
|
||||||
|
@@ -29,6 +29,8 @@
|
|||||||
|
|
||||||
#include "NetworkManagerUtils.h"
|
#include "NetworkManagerUtils.h"
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
_fmt_warn (const char *group, NMSetting *setting, const char *property_name, const char *message, char **out_message)
|
_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"
|
#define NM_CONFIG_KEYFILE_PATH_DEFAULT NMCONFDIR "/system-connections"
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
static const char temp_letters[] =
|
static const char temp_letters[] =
|
||||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
|
|
||||||
@@ -166,5 +168,3 @@ nms_keyfile_utils_get_path (void)
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
|
@@ -33,10 +33,13 @@
|
|||||||
|
|
||||||
#include "nms-keyfile-utils.h"
|
#include "nms-keyfile-utils.h"
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *keyfile_dir;
|
const char *keyfile_dir;
|
||||||
} WriteInfo;
|
} WriteInfo;
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
write_cert_key_file (const char *path,
|
write_cert_key_file (const char *path,
|
||||||
|
Reference in New Issue
Block a user