mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 09:30:31 +01:00
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.
This commit is contained in:
parent
6cd03bf205
commit
9bf3933855
3 changed files with 49 additions and 9 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
@ -1440,6 +1450,29 @@ nm_connection_new (void)
|
|||
return (NMConnection *) g_object_new (NM_TYPE_CONNECTION, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* _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
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue