diff options
author | Thomas Haller <thaller@redhat.com> | 2020-05-26 09:55:40 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-06-05 09:17:21 +0200 |
commit | e2f83d4e929efd04bc30efef63031fdd94227088 (patch) | |
tree | 55285dcb8421522ac891af2ef200edd9003cd54b /shared | |
parent | 00b3a3505a6cdad7c3bb88cd3c1d447fb6963f95 (diff) | |
download | NetworkManager-e2f83d4e929efd04bc30efef63031fdd94227088.tar.gz |
keyfile: add NMKeyfileHandlerFlags
nm_keyfile_read() and nm_keyfile_write() will be public API.
As such, it must be flexible and extendible for future needs.
There is already the handler callback that fully solves this
(e.g. a future handler event could request whether a certain
behavior is enabled or not).
As additional possibility for future extension, add a flags
argument. Currently no flags are implemented.
Diffstat (limited to 'shared')
-rw-r--r-- | shared/nm-keyfile/nm-keyfile-internal.h | 6 | ||||
-rw-r--r-- | shared/nm-keyfile/nm-keyfile.c | 5 | ||||
-rw-r--r-- | shared/nm-utils/nm-test-utils.h | 6 |
3 files changed, 14 insertions, 3 deletions
diff --git a/shared/nm-keyfile/nm-keyfile-internal.h b/shared/nm-keyfile/nm-keyfile-internal.h index be0f800a52..dc4082cf52 100644 --- a/shared/nm-keyfile/nm-keyfile-internal.h +++ b/shared/nm-keyfile/nm-keyfile-internal.h @@ -31,6 +31,10 @@ char *nm_keyfile_detect_unqualified_path_scheme (const char *base_dir, gboolean consider_exists, gboolean *out_exists); +typedef enum { /*< flags >*/ + NM_KEYFILE_HANDLER_FLAGS_NONE = 0, +} NMKeyfileHandlerFlags; + typedef enum { NM_KEYFILE_HANDLER_TYPE_WARN = 1, NM_KEYFILE_HANDLER_TYPE_WRITE_CERT = 2, @@ -63,6 +67,7 @@ typedef enum { NMConnection *nm_keyfile_read (GKeyFile *keyfile, const char *base_dir, + NMKeyfileHandlerFlags handler_flags, NMKeyfileReadHandler handler, void *user_data, GError **error); @@ -105,6 +110,7 @@ typedef gboolean (*NMKeyfileWriteHandler) (NMConnection *connection, void *user_data); GKeyFile *nm_keyfile_write (NMConnection *connection, + NMKeyfileHandlerFlags handler_flags, NMKeyfileWriteHandler handler, void *user_data, GError **error); diff --git a/shared/nm-keyfile/nm-keyfile.c b/shared/nm-keyfile/nm-keyfile.c index 3b198d1ae3..77af2b6492 100644 --- a/shared/nm-keyfile/nm-keyfile.c +++ b/shared/nm-keyfile/nm-keyfile.c @@ -3758,6 +3758,7 @@ nm_keyfile_read_ensure_uuid (NMConnection *connection, * @base_dir: when reading certificates from files with relative name, * the relative path is made absolute using @base_dir. This must * be an absolute path. + * @handler_flags: the #NMKeyfileHandlerFlags. * @handler: read handler * @user_data: user data for read handler * @error: error @@ -3770,6 +3771,7 @@ nm_keyfile_read_ensure_uuid (NMConnection *connection, NMConnection * nm_keyfile_read (GKeyFile *keyfile, const char *base_dir, + NMKeyfileHandlerFlags handler_flags, NMKeyfileReadHandler handler, void *user_data, GError **error) @@ -3785,6 +3787,7 @@ nm_keyfile_read (GKeyFile *keyfile, g_return_val_if_fail (keyfile, NULL); g_return_val_if_fail (!error || !*error, NULL); g_return_val_if_fail (base_dir && base_dir[0] == '/', NULL); + g_return_val_if_fail (handler_flags == NM_KEYFILE_HANDLER_FLAGS_NONE, NULL); connection = nm_simple_connection_new (); @@ -4085,6 +4088,7 @@ _write_setting_wireguard (NMSetting *setting, KeyfileWriterInfo *info) GKeyFile * nm_keyfile_write (NMConnection *connection, + NMKeyfileHandlerFlags handler_flags, NMKeyfileWriteHandler handler, void *user_data, GError **error) @@ -4096,6 +4100,7 @@ nm_keyfile_write (NMConnection *connection, g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); g_return_val_if_fail (!error || !*error, NULL); + g_return_val_if_fail (handler_flags == NM_KEYFILE_HANDLER_FLAGS_NONE, NULL); if (!nm_connection_verify (connection, error)) return NULL; diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h index 96e361358f..15362da00d 100644 --- a/shared/nm-utils/nm-test-utils.h +++ b/shared/nm-utils/nm-test-utils.h @@ -1924,8 +1924,8 @@ nmtst_assert_connection_equals (NMConnection *a, gboolean normalize_a, NMConnect gs_unref_keyfile GKeyFile *kf_a = NULL, *kf_b = NULL; gs_free char *str_a = NULL, *str_b = NULL; - kf_a = nm_keyfile_write (a, NULL, NULL, NULL); - kf_b = nm_keyfile_write (b, NULL, NULL, NULL); + kf_a = nm_keyfile_write (a, NM_KEYFILE_HANDLER_FLAGS_NONE, NULL, NULL, NULL); + kf_b = nm_keyfile_write (b, NM_KEYFILE_HANDLER_FLAGS_NONE, NULL, NULL, NULL); if (kf_a) str_a = g_key_file_to_data (kf_a, NULL, NULL); @@ -2262,7 +2262,7 @@ nmtst_create_connection_from_keyfile (const char *keyfile_str, const char *full_ success = g_key_file_load_from_data (keyfile, keyfile_str, strlen (keyfile_str), G_KEY_FILE_NONE, &error); nmtst_assert_success (success, error); - con = nm_keyfile_read (keyfile, base_dir, NULL, NULL, &error); + con = nm_keyfile_read (keyfile, base_dir, NM_KEYFILE_HANDLER_FLAGS_NONE, NULL, NULL, &error); nmtst_assert_success (NM_IS_CONNECTION (con), error); nm_keyfile_read_ensure_id (con, filename); |