Commit 272439cb authored by Thomas Haller's avatar Thomas Haller

shared/compat: add compat for nm_setting_vpn_get_data_keys() and nm_setting_vpn_get_secret_keys()

parent 1cb14766
...@@ -670,7 +670,6 @@ libnm_core_tests_test_setting_dcb_CPPFLAGS = $(libnm_core_tests_cppflags) ...@@ -670,7 +670,6 @@ libnm_core_tests_test_setting_dcb_CPPFLAGS = $(libnm_core_tests_cppflags)
libnm_core_tests_test_settings_defaults_CPPFLAGS = $(libnm_core_tests_cppflags) libnm_core_tests_test_settings_defaults_CPPFLAGS = $(libnm_core_tests_cppflags)
libnm_core_tests_test_general_SOURCES = \ libnm_core_tests_test_general_SOURCES = \
shared/nm-utils/nm-compat.c \
libnm-core/tests/test-general-enums.h \ libnm-core/tests/test-general-enums.h \
libnm-core/tests/test-general.c libnm-core/tests/test-general.c
...@@ -1067,6 +1066,7 @@ libnm_tests_test_remote_settings_client_CPPFLAGS = $(libnm_tests_cppflags) ...@@ -1067,6 +1066,7 @@ libnm_tests_test_remote_settings_client_CPPFLAGS = $(libnm_tests_cppflags)
libnm_tests_test_secret_agent_CPPFLAGS = $(libnm_tests_cppflags) libnm_tests_test_secret_agent_CPPFLAGS = $(libnm_tests_cppflags)
libnm_tests_test_general_SOURCES = \ libnm_tests_test_general_SOURCES = \
shared/nm-utils/nm-compat.c \
libnm/tests/test-general.c libnm/tests/test-general.c
libnm_tests_test_nm_client_SOURCES = \ libnm_tests_test_nm_client_SOURCES = \
......
...@@ -23,3 +23,66 @@ ...@@ -23,3 +23,66 @@
#include "nm-compat.h" #include "nm-compat.h"
/*****************************************************************************/
static void
_get_keys_cb (const char *key, const char *val, gpointer user_data)
{
GPtrArray *a = user_data;
g_ptr_array_add (a, g_strdup (key));
}
static const char **
_get_keys (NMSettingVpn *setting,
gboolean is_secrets,
guint *out_length)
{
guint len;
const char **keys = NULL;
gs_unref_ptrarray GPtrArray *a = NULL;
nm_assert (NM_IS_SETTING_VPN (setting));
a = g_ptr_array_new ();
if (is_secrets)
nm_setting_vpn_foreach_secret (setting, _get_keys_cb, a);
else
nm_setting_vpn_foreach_data_item (setting, _get_keys_cb, a);
len = a->len;
if (a->len) {
g_ptr_array_sort (a, nm_strcmp_p);
g_ptr_array_add (a, NULL);
keys = (const char **) g_ptr_array_free (g_steal_pointer (&a), FALSE);
/* we need to cache the keys *somewhere*. */
g_object_set_qdata_full (G_OBJECT (setting),
is_secrets
? NM_CACHED_QUARK ("libnm._nm_setting_vpn_get_secret_keys")
: NM_CACHED_QUARK ("libnm._nm_setting_vpn_get_data_keys"),
keys,
(GDestroyNotify) g_strfreev);
}
NM_SET_OUT (out_length, len);
return keys;
}
const char **
_nm_setting_vpn_get_data_keys (NMSettingVpn *setting,
guint *out_length)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
return _get_keys (setting, FALSE, out_length);
}
const char **
_nm_setting_vpn_get_secret_keys (NMSettingVpn *setting,
guint *out_length)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
return _get_keys (setting, TRUE, out_length);
}
...@@ -22,5 +22,32 @@ ...@@ -22,5 +22,32 @@
#ifndef __NM_COMPAT_H__ #ifndef __NM_COMPAT_H__
#define __NM_COMPAT_H__ #define __NM_COMPAT_H__
#include "nm-setting-vpn.h"
const char **_nm_setting_vpn_get_data_keys (NMSettingVpn *setting,
guint *out_length);
const char **_nm_setting_vpn_get_secret_keys (NMSettingVpn *setting,
guint *out_length);
#if NM_CHECK_VERSION (1, 11, 0)
#define nm_setting_vpn_get_data_keys(setting, out_length) \
({ \
G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
nm_setting_vpn_get_data_keys (setting, out_length); \
G_GNUC_END_IGNORE_DEPRECATIONS \
})
#define nm_setting_vpn_get_secret_keys(setting, out_length) \
({ \
G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
nm_setting_vpn_get_secret_keys (setting, out_length); \
G_GNUC_END_IGNORE_DEPRECATIONS \
})
#else
#define nm_setting_vpn_get_data_keys(setting, out_length) \
_nm_setting_vpn_get_data_keys (setting, out_length)
#define nm_setting_vpn_get_secret_keys(setting, out_length) \
_nm_setting_vpn_get_secret_keys (setting, out_length)
#endif
#endif /* __NM_COMPAT_H__ */ #endif /* __NM_COMPAT_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment