1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* NetworkManager system settings service - keyfile plugin
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 * Copyright (C) 2008 Novell, Inc.
19 * Copyright (C) 2015 Red Hat, Inc.
22 #ifndef __NM_KEYFILE_INTERNAL_H__
23 #define __NM_KEYFILE_INTERNAL_H__
25 #include <sys/types.h>
27 #include "nm-default.h"
28 #include "nm-connection.h"
29 #include "nm-setting-8021x.h"
31 /*********************************************************/
33 #define NM_KEYFILE_CERT_SCHEME_PREFIX_BLOB "data:;base64,"
34 #define NM_KEYFILE_CERT_SCHEME_PREFIX_PATH "file://"
36 char *nm_keyfile_detect_unqualified_path_scheme (const char *base_dir,
39 gboolean consider_exists,
40 gboolean *out_exists);
43 NM_KEYFILE_READ_TYPE_WARN = 1,
47 * NMKeyfileReadHandler:
49 * Hook to nm_keyfile_read(). The user might fail the reading by setting
52 * Returns: should return TRUE, if the reading was handled. Otherwise,
53 * a default action will be performed that depends on the @type.
54 * For %NM_KEYFILE_READ_TYPE_WARN type, the default action is doing nothing.
56 typedef gboolean (*NMKeyfileReadHandler) (GKeyFile *keyfile,
57 NMConnection *connection,
58 NMKeyfileReadType type,
64 NM_KEYFILE_WARN_SEVERITY_DEBUG = 1000,
65 NM_KEYFILE_WARN_SEVERITY_INFO = 2000,
66 NM_KEYFILE_WARN_SEVERITY_INFO_MISSING_FILE = 2901,
67 NM_KEYFILE_WARN_SEVERITY_WARN = 3000,
68 } NMKeyfileWarnSeverity;
71 * NMKeyfileReadTypeDataWarn:
73 * this struct is passed as @type_data for the @NMKeyfileReadHandler of
74 * type %NM_KEYFILE_READ_TYPE_WARN.
77 /* might be %NULL, if the warning is not about a group. */
80 /* might be %NULL, if the warning is not about a setting. */
83 /* might be %NULL, if the warning is not about a property. */
84 const char *property_name;
86 NMKeyfileWarnSeverity severity;
88 } NMKeyfileReadTypeDataWarn;
91 NMConnection *nm_keyfile_read (GKeyFile *keyfile,
92 const char *keyfile_name,
94 NMKeyfileReadHandler handler,
98 /*********************************************************/
101 NM_KEYFILE_WRITE_TYPE_CERT = 1,
102 } NMKeyfileWriteType;
105 * NMKeyfileWriteHandler:
107 * This is a hook to tweak the serialization.
109 * Handler for certain properties or events that are not entirely contained
110 * within the keyfile or that might be serialized differently. The @type and
111 * @type_data arguments tell which kind of argument we have at hand.
113 * Currently only the type %NM_KEYFILE_WRITE_TYPE_CERT is supported, which provides
114 * @type_data as %NMKeyfileWriteTypeDataCert. However, this handler should be generic enough
115 * to support other types as well.
117 * This don't have to be only "properties". For example, nm_keyfile_read() uses
118 * a similar handler to push warnings to the caller.
120 * If the handler raises an error, it should set the @error value. This causes
121 * the an overall failure.
123 * Returns: whether the issue was handled. If the type was unhandled,
124 * a default action will be performed. This might be raise an error,
125 * do some fallback parsing, or do nothing.
127 typedef gboolean (*NMKeyfileWriteHandler) (NMConnection *connection,
129 NMKeyfileWriteType type,
135 * NMKeyfileWriteTypeDataCert:
137 * this struct is passed as @type_data for the @NMKeyfileWriteHandler of
138 * type %NM_KEYFILE_WRITE_TYPE_CERT.
141 NMSetting8021x *setting;
142 const char *property_name;
144 /* The following functions are helpers that simplify the implementation
147 NMSetting8021xCKScheme (*scheme_func) (NMSetting8021x *setting);
148 NMSetting8021xCKFormat (*format_func) (NMSetting8021x *setting);
149 const char * (*path_func) (NMSetting8021x *setting);
150 GBytes * (*blob_func) (NMSetting8021x *setting);
151 } NMKeyfileWriteTypeDataCert;
154 GKeyFile *nm_keyfile_write (NMConnection *connection,
155 NMKeyfileWriteHandler handler,
159 /*********************************************************/
161 char *nm_keyfile_plugin_kf_get_string (GKeyFile *kf, const char *group, const char *key, GError **error);
162 void nm_keyfile_plugin_kf_set_string (GKeyFile *kf, const char *group, const char *key, const char *value);
164 void _nm_keyfile_copy (GKeyFile *dst, GKeyFile *src);
165 gboolean _nm_keyfile_a_contains_all_in_b (GKeyFile *kf_a, GKeyFile *kf_b);
166 gboolean _nm_keyfile_equals (GKeyFile *kf_a, GKeyFile *kf_b, gboolean consider_order);
167 gboolean _nm_keyfile_has_values (GKeyFile *keyfile);
170 #endif /* __NM_KEYFILE_INTERNAL_H__ */