libnm-core-aux-intern: Add helper function _nm_connection_ensure_setting()

Introduce internal function `_nm_connection_ensure_setting()` to
`libnm-core-aux-intern` and add specified setting to connection if not
found.

Signed-off-by: Gris Ge <fge@redhat.com>
This commit is contained in:
Gris Ge 2021-08-20 15:20:08 +08:00 committed by Thomas Haller
parent bbb7eb1767
commit c265096d66
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 16 additions and 0 deletions

View file

@ -8,6 +8,7 @@
#include "nm-common-macros.h"
#include "nm-errors.h"
#include "libnm-core-public/nm-connection.h"
/*****************************************************************************/
@ -358,3 +359,16 @@ nm_settings_connection_validate_permission_user(const char *item, gssize len)
return TRUE;
}
gpointer
_nm_connection_ensure_setting(NMConnection *connection, GType gtype)
{
NMSetting *setting;
setting = (gpointer) nm_connection_get_setting(connection, gtype);
if (!setting) {
setting = g_object_new(gtype, NULL);
nm_connection_add_setting(connection, setting);
}
return setting;
}

View file

@ -166,4 +166,6 @@ gboolean nm_utils_validate_dhcp4_vendor_class_id(const char *vci, GError **error
gboolean nm_settings_connection_validate_permission_user(const char *item, gssize len);
gpointer _nm_connection_ensure_setting(NMConnection *connection, GType gtype);
#endif /* __NM_LIBNM_SHARED_UTILS_H__ */