From 4230a1d4fb3bf3d018d93dad692ea2fb364fb4c3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 25 May 2020 18:32:29 +0200 Subject: [PATCH] keyfile: add accessors for NMKeyfileHandlerData For introspection/bindings it is cumbersome to access the fields of the NMKeyfileHandlerData struct. Instead add accessor functions. Also, we wouldn't want to expose the struct in public API directly, because it makes it harder to extend it without breaking ABI. --- shared/nm-keyfile/nm-keyfile-internal.h | 11 +++++ shared/nm-keyfile/nm-keyfile.c | 56 +++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/shared/nm-keyfile/nm-keyfile-internal.h b/shared/nm-keyfile/nm-keyfile-internal.h index 7c259a52cf..719e5501aa 100644 --- a/shared/nm-keyfile/nm-keyfile-internal.h +++ b/shared/nm-keyfile/nm-keyfile-internal.h @@ -151,6 +151,17 @@ struct _NMKeyfileHandlerData { /*****************************************************************************/ +void nm_keyfile_handler_data_fail_with_error (NMKeyfileHandlerData *handler_data, + GError *src); + +void nm_keyfile_handler_data_get_context (const NMKeyfileHandlerData *handler_data, + const char **out_kf_group_name, + const char **out_kf_key_name, + NMSetting **out_cur_setting, + const char **out_cur_property_name); + +/*****************************************************************************/ + char *nm_keyfile_plugin_kf_get_string (GKeyFile *kf, const char *group, const char *key, GError **error); void nm_keyfile_plugin_kf_set_string (GKeyFile *kf, const char *group, const char *key, const char *value); diff --git a/shared/nm-keyfile/nm-keyfile.c b/shared/nm-keyfile/nm-keyfile.c index 7248528539..b6a89a2e4e 100644 --- a/shared/nm-keyfile/nm-keyfile.c +++ b/shared/nm-keyfile/nm-keyfile.c @@ -4337,3 +4337,59 @@ nm_keyfile_utils_create_filename (const char *name, return g_string_free (str, FALSE);; } + +/*****************************************************************************/ + +/** + * nm_keyfile_handler_data_fail_with_error: + * @handler_data: the #NMKeyfileHandlerData + * @src: (transfer full): error to move into the return location + * + * Set the error for the handler. This lets the operation fail + * with the provided error. You may only set the error once. + * + * @src must be non-%NULL. + * + * Note that @src is no longer valid after this call. If you want + * to keep using the same GError*, you need to set it to %NULL + * after calling this function on it. + */ +void +nm_keyfile_handler_data_fail_with_error (NMKeyfileHandlerData *handler_data, + GError *src) +{ + g_return_if_fail (handler_data); + g_return_if_fail (handler_data->p_error && !*handler_data->p_error); + g_return_if_fail (src); + + *handler_data->p_error = src; +} + +/** + * nm_keyfile_handler_data_get_context: + * @handler_data: the #NMKeyfileHandlerData for any event. + * @out_kf_group_name: (out) (allow-none) (transfer none): if the event is in the + * context of a keyfile group, the group name. + * @out_kf_key_name: (out) (allow-none) (transfer none): if the event is in the + * context of a keyfile value, the key name. + * @out_cur_setting: (out) (allow-none) (transfer none): if the event happens while + * handling a particular #NMSetting instance. + * @out_cur_property_name: (out) (allow-none) (transfer none): the property name if applicable. + * + * Get context information of the current event. This function can be called + * on all events, but the context information may be unset. + */ +void +nm_keyfile_handler_data_get_context (const NMKeyfileHandlerData *handler_data, + const char **out_kf_group_name, + const char **out_kf_key_name, + NMSetting **out_cur_setting, + const char **out_cur_property_name) +{ + g_return_if_fail (handler_data); + + NM_SET_OUT (out_kf_group_name, handler_data->kf_group_name); + NM_SET_OUT (out_kf_key_name, handler_data->kf_key); + NM_SET_OUT (out_cur_setting, handler_data->cur_setting); + NM_SET_OUT (out_cur_property_name, handler_data->cur_property); +}