diff options
author | Thomas Haller <thaller@redhat.com> | 2014-07-08 15:01:54 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-08-22 15:24:30 +0200 |
commit | 1effc604cbcdc06d40f505e2858845fc04788f1e (patch) | |
tree | a7bce316ebe4fc68d52b6d8b700b6a265e82eb23 | |
parent | 686e912b82405151566cd4deae9926196d09c79e (diff) | |
download | NetworkManager-1effc604cbcdc06d40f505e2858845fc04788f1e.tar.gz |
libnm-core: add _nm_setting_find_in_list_required() function
This is an utility function that can be called during verify()
to find an NMSetting from @all_settings.
This is especially useful for looking up the NMSettingConnection
which usually is present. So just get it quickly. In the unexpected
case that it is missing, it sets @error and we can return.
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r-- | libnm-core/nm-setting-private.h | 6 | ||||
-rw-r--r-- | libnm-core/nm-setting.c | 28 |
2 files changed, 34 insertions, 0 deletions
diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h index 913b8a739e..e68d5a4278 100644 --- a/libnm-core/nm-setting-private.h +++ b/libnm-core/nm-setting-private.h @@ -90,6 +90,12 @@ static void __attribute__((constructor)) register_setting (void) \ NMSetting *nm_setting_find_in_list (GSList *settings_list, const char *setting_name); +NMSetting * _nm_setting_find_in_list_required (GSList *all_settings, + const char *setting_name, + GError **error, + const char *error_prefix_setting_name, + const char *error_prefix_property_name); + NMSettingVerifyResult _nm_setting_verify_deprecated_virtual_iface_name (const char *interface_name, gboolean allow_missing, const char *setting_name, diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 6acb75ef27..830484b569 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -1288,6 +1288,34 @@ nm_setting_get_virtual_iface_name (NMSetting *setting) return NULL; } +NMSetting * +_nm_setting_find_in_list_required (GSList *all_settings, + const char *setting_name, + GError **error, + const char *error_prefix_setting_name, + const char *error_prefix_property_name) +{ + NMSetting *setting; + + g_return_val_if_fail (!error || !*error, NULL); + g_return_val_if_fail (all_settings, NULL); + g_return_val_if_fail (setting_name, NULL); + g_return_val_if_fail (!error_prefix_setting_name == !error_prefix_property_name, NULL); + + setting = nm_setting_find_in_list (all_settings, setting_name); + if (!setting) { + g_set_error (error, + NM_CONNECTION_ERROR, + !strcmp (setting_name, NM_SETTING_CONNECTION_SETTING_NAME) + ? NM_CONNECTION_ERROR_CONNECTION_SETTING_NOT_FOUND + : NM_CONNECTION_ERROR_SETTING_NOT_FOUND, + _("Missing '%s' setting"), + setting_name); + if (error_prefix_setting_name) + g_prefix_error (error, "%s.%s: ", error_prefix_setting_name, error_prefix_property_name); + } + return setting; +} NMSettingVerifyResult _nm_setting_verify_deprecated_virtual_iface_name (const char *interface_name, |