mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-05 10:20:14 +01:00
libnm: add nm_connection_get_settings()
There is no API to get all settings. You can only ask for settings explicitly, but that requires you to probe for them and know which ones may exist. The alternative API might be nm_connection_for_each_setting_value(), but that only iterates over settings' properties. If a setting has no properties, it is ignored.
This commit is contained in:
parent
f2858220e3
commit
7b36a6a890
3 changed files with 64 additions and 29 deletions
|
|
@ -1797,6 +1797,60 @@ _for_each_sort (NMSetting **p_a, NMSetting **p_b, void *unused)
|
|||
return strcmp (nm_setting_get_name (a), nm_setting_get_name (b));
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_connection_get_settings:
|
||||
* @connection: the #NMConnection instance
|
||||
* @out_length: (allow-none): (out): the length of the returned array
|
||||
*
|
||||
* Retrieves the settings in @connection.
|
||||
*
|
||||
* The returned array is %NULL-terminated.
|
||||
*
|
||||
* Returns: (array length=out_length) (transfer container): a
|
||||
* %NULL-terminated array containing every setting of
|
||||
* @connection.
|
||||
* If the connection has no settings, %NULL is returned.
|
||||
*
|
||||
* Since: 1.10
|
||||
*/
|
||||
NMSetting **
|
||||
nm_connection_get_settings (NMConnection *connection,
|
||||
guint *out_length)
|
||||
{
|
||||
NMConnectionPrivate *priv;
|
||||
NMSetting **arr;
|
||||
GHashTableIter iter;
|
||||
NMSetting *setting;
|
||||
guint i, size;
|
||||
|
||||
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
|
||||
|
||||
priv = NM_CONNECTION_GET_PRIVATE (connection);
|
||||
|
||||
size = g_hash_table_size (priv->settings);
|
||||
|
||||
if (!size) {
|
||||
NM_SET_OUT (out_length, 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
arr = g_new (NMSetting *, size + 1);
|
||||
|
||||
g_hash_table_iter_init (&iter, priv->settings);
|
||||
for (i = 0; g_hash_table_iter_next (&iter, NULL, (gpointer *) &setting); i++)
|
||||
arr[i] = setting;
|
||||
nm_assert (i == size);
|
||||
arr[size] = NULL;
|
||||
|
||||
/* sort the settings. This has an effect on the order in which keyfile
|
||||
* prints them. */
|
||||
if (size > 1)
|
||||
g_qsort_with_data (arr, size, sizeof (NMSetting *), (GCompareDataFunc) _for_each_sort, NULL);
|
||||
|
||||
NM_SET_OUT (out_length, size);
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_connection_for_each_setting_value:
|
||||
* @connection: the #NMConnection
|
||||
|
|
@ -1811,39 +1865,15 @@ nm_connection_for_each_setting_value (NMConnection *connection,
|
|||
NMSettingValueIterFn func,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMConnectionPrivate *priv;
|
||||
gs_free NMSetting **arr_free = NULL;
|
||||
NMSetting *arr_temp[20], **arr;
|
||||
GHashTableIter iter;
|
||||
gpointer value;
|
||||
guint i, size;
|
||||
gs_free NMSetting **settings = NULL;
|
||||
guint i, length = 0;
|
||||
|
||||
g_return_if_fail (NM_IS_CONNECTION (connection));
|
||||
g_return_if_fail (func);
|
||||
|
||||
priv = NM_CONNECTION_GET_PRIVATE (connection);
|
||||
|
||||
size = g_hash_table_size (priv->settings);
|
||||
if (!size)
|
||||
return;
|
||||
|
||||
if (size > G_N_ELEMENTS (arr_temp))
|
||||
arr = arr_free = g_new (NMSetting *, size);
|
||||
else
|
||||
arr = arr_temp;
|
||||
|
||||
g_hash_table_iter_init (&iter, priv->settings);
|
||||
for (i = 0; g_hash_table_iter_next (&iter, NULL, &value); i++)
|
||||
arr[i] = NM_SETTING (value);
|
||||
g_assert (i == size);
|
||||
|
||||
/* sort the settings. This has an effect on the order in which keyfile
|
||||
* prints them. */
|
||||
if (size > 1)
|
||||
g_qsort_with_data (arr, size, sizeof (NMSetting *), (GCompareDataFunc) _for_each_sort, NULL);
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
nm_setting_enumerate_values (arr[i], func, user_data);
|
||||
settings = nm_connection_get_settings (connection, &length);
|
||||
for (i = 0; i < length; i++)
|
||||
nm_setting_enumerate_values (settings[i], func, user_data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -179,6 +179,10 @@ void nm_connection_for_each_setting_value (NMConnection *connection,
|
|||
NMSettingValueIterFn func,
|
||||
gpointer user_data);
|
||||
|
||||
NM_AVAILABLE_IN_1_10
|
||||
NMSetting ** nm_connection_get_settings (NMConnection *connection,
|
||||
guint *out_length);
|
||||
|
||||
void nm_connection_dump (NMConnection *connection);
|
||||
|
||||
/* Helpers */
|
||||
|
|
|
|||
|
|
@ -1185,6 +1185,7 @@ global:
|
|||
nm_client_connectivity_check_get_available;
|
||||
nm_client_connectivity_check_get_enabled;
|
||||
nm_client_connectivity_check_set_enabled;
|
||||
nm_connection_get_settings;
|
||||
nm_device_dummy_get_hw_address;
|
||||
nm_device_ovs_bridge_get_type;
|
||||
nm_device_ovs_interface_get_type;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue