diff options
-rw-r--r-- | libnm-core/nm-connection.c | 84 | ||||
-rw-r--r-- | libnm-core/nm-connection.h | 4 | ||||
-rw-r--r-- | libnm/libnm.ver | 1 |
3 files changed, 62 insertions, 27 deletions
diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index 32fa9fd78a..720ba8468d 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -1798,52 +1798,82 @@ _for_each_sort (NMSetting **p_a, NMSetting **p_b, void *unused) } /** - * nm_connection_for_each_setting_value: - * @connection: the #NMConnection - * @func: (scope call): user-supplied function called for each setting's property - * @user_data: user data passed to @func at each invocation + * nm_connection_get_settings: + * @connection: the #NMConnection instance + * @out_length: (allow-none): (out): the length of the returned array * - * Iterates over the properties of each #NMSetting object in the #NMConnection, - * calling the supplied user function for each property. - **/ -void -nm_connection_for_each_setting_value (NMConnection *connection, - NMSettingValueIterFn func, - gpointer user_data) + * 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; - gs_free NMSetting **arr_free = NULL; - NMSetting *arr_temp[20], **arr; + NMSetting **arr; GHashTableIter iter; - gpointer value; + NMSetting *setting; guint i, size; - g_return_if_fail (NM_IS_CONNECTION (connection)); - g_return_if_fail (func); + 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) - return; - if (size > G_N_ELEMENTS (arr_temp)) - arr = arr_free = g_new (NMSetting *, size); - else - arr = arr_temp; + 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, &value); i++) - arr[i] = NM_SETTING (value); - g_assert (i == size); + 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); - for (i = 0; i < size; i++) - nm_setting_enumerate_values (arr[i], func, user_data); + NM_SET_OUT (out_length, size); + return arr; +} + +/** + * nm_connection_for_each_setting_value: + * @connection: the #NMConnection + * @func: (scope call): user-supplied function called for each setting's property + * @user_data: user data passed to @func at each invocation + * + * Iterates over the properties of each #NMSetting object in the #NMConnection, + * calling the supplied user function for each property. + **/ +void +nm_connection_for_each_setting_value (NMConnection *connection, + NMSettingValueIterFn func, + gpointer user_data) +{ + gs_free NMSetting **settings = NULL; + guint i, length = 0; + + g_return_if_fail (NM_IS_CONNECTION (connection)); + g_return_if_fail (func); + + settings = nm_connection_get_settings (connection, &length); + for (i = 0; i < length; i++) + nm_setting_enumerate_values (settings[i], func, user_data); } /** diff --git a/libnm-core/nm-connection.h b/libnm-core/nm-connection.h index 9419c6254e..c6b23a00bc 100644 --- a/libnm-core/nm-connection.h +++ b/libnm-core/nm-connection.h @@ -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 */ diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 72690ff4f2..1b245b277b 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -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; |