summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-03-26 13:04:43 +0100
committerThomas Haller <thaller@redhat.com>2016-03-29 11:56:27 +0200
commit9bf3933855f6c9ccd65447e73a59e24055a6e340 (patch)
tree9dc751d7a3fb7e95186e1569797e6c6aac4d4687
parent6cd03bf205745bf13ec3a9af7af30a376e348015 (diff)
downloadNetworkManager-9bf3933855f6c9ccd65447e73a59e24055a6e340.tar.gz
libnm-util: add non-failing versions of nm_connection_new_from_hash() and replace-settings
Add internal functions _nm_connection_replace_settings() and _nm_connection_new_from_hash() that cannot fail. Altough they are not public API, we have to expose them via libnm-util.ver so that they can be used from libnm-glib.
-rw-r--r--libnm-util/libnm-util.ver2
-rw-r--r--libnm-util/nm-connection.c50
-rw-r--r--libnm-util/nm-setting-private.h6
3 files changed, 49 insertions, 9 deletions
diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver
index 1ad853f5fb..385cdb8e3b 100644
--- a/libnm-util/libnm-util.ver
+++ b/libnm-util/libnm-util.ver
@@ -1,5 +1,7 @@
{
global:
+ _nm_connection_new_from_hash;
+ _nm_connection_replace_settings;
nm_connection_add_setting;
nm_connection_clear_secrets;
nm_connection_clear_secrets_with_flags;
diff --git a/libnm-util/nm-connection.c b/libnm-util/nm-connection.c
index f77e322307..51c480284f 100644
--- a/libnm-util/nm-connection.c
+++ b/libnm-util/nm-connection.c
@@ -327,19 +327,30 @@ validate_permissions_type (GHashTable *hash, GError **error)
return TRUE;
}
-static void
-hash_to_connection (NMConnection *connection, GHashTable *new)
+/**
+ * _nm_connection_replace_settings:
+ * @connection: a #NMConnection
+ * @new_settings: (element-type utf8 GLib.HashTable): a #GHashTable of settings
+ **/
+void
+_nm_connection_replace_settings (NMConnection *connection,
+ GHashTable *new_settings)
{
+ NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection);
GHashTableIter iter;
const char *setting_name;
GHashTable *setting_hash;
gboolean changed;
- NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection);
+
+ g_return_if_fail (NM_IS_CONNECTION (connection));
+ g_return_if_fail (new_settings != NULL);
+
+ priv = NM_CONNECTION_GET_PRIVATE (connection);
if ((changed = g_hash_table_size (priv->settings) > 0))
g_hash_table_foreach_remove (priv->settings, _setting_release, connection);
- g_hash_table_iter_init (&iter, new);
+ g_hash_table_iter_init (&iter, new_settings);
while (g_hash_table_iter_next (&iter, (gpointer) &setting_name, (gpointer) &setting_hash)) {
GType type = nm_connection_lookup_setting_type (setting_name);
@@ -373,13 +384,12 @@ nm_connection_replace_settings (NMConnection *connection,
{
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
g_return_val_if_fail (new_settings != NULL, FALSE);
- if (error)
- g_return_val_if_fail (*error == NULL, FALSE);
+ g_return_val_if_fail (!error || !*error, FALSE);
if (!validate_permissions_type (new_settings, error))
return FALSE;
- hash_to_connection (connection, new_settings);
+ _nm_connection_replace_settings (connection, new_settings);
return nm_connection_verify (connection, error);
}
@@ -1441,6 +1451,29 @@ nm_connection_new (void)
}
/**
+ * _nm_connection_new_from_hash:
+ * @hash: (element-type utf8 GLib.HashTable): the #GHashTable describing
+ * the connection
+ *
+ * Creates a new #NMConnection from a hash table describing the connection. See
+ * nm_connection_to_hash() for a description of the expected hash table.
+ *
+ * Returns: the new #NMConnection object, populated with settings created
+ * from the values in the hash table.
+ **/
+NMConnection *
+_nm_connection_new_from_hash (GHashTable *hash)
+{
+ NMConnection *connection;
+
+ g_return_val_if_fail (hash != NULL, NULL);
+
+ connection = nm_connection_new ();
+ _nm_connection_replace_settings (connection, hash);
+ return connection;
+}
+
+/**
* nm_connection_new_from_hash:
* @hash: (element-type utf8 GLib.HashTable): the #GHashTable describing
* the connection
@@ -1463,8 +1496,7 @@ nm_connection_new_from_hash (GHashTable *hash, GError **error)
if (!validate_permissions_type (hash, error))
return NULL;
- connection = nm_connection_new ();
- hash_to_connection (connection, hash);
+ connection = _nm_connection_new_from_hash (hash);
if (!nm_connection_verify (connection, error))
g_clear_object (&connection);
return connection;
diff --git a/libnm-util/nm-setting-private.h b/libnm-util/nm-setting-private.h
index 6956463c3f..beb87484f0 100644
--- a/libnm-util/nm-setting-private.h
+++ b/libnm-util/nm-setting-private.h
@@ -23,6 +23,8 @@
#include "nm-default.h"
+#include "nm-connection.h"
+
#define NM_SETTING_SECRET_FLAGS_ALL \
(NM_SETTING_SECRET_FLAG_NONE | \
NM_SETTING_SECRET_FLAG_AGENT_OWNED | \
@@ -62,6 +64,10 @@ gint _nm_setting_compare_priority (gconstpointer a, gconstpointer b);
gboolean _nm_setting_get_property (NMSetting *setting, const char *name, GValue *value);
+NMConnection *_nm_connection_new_from_hash (GHashTable *hash);
+void _nm_connection_replace_settings (NMConnection *connection,
+ GHashTable *new_settings);
+
typedef enum NMSettingUpdateSecretResult {
NM_SETTING_UPDATE_SECRET_ERROR = FALSE,
NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED = TRUE,