device: renew dhcp leases on awake for software devices
[NetworkManager.git] / libnm-core / nm-keyfile-internal.h
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* NetworkManager system settings service - keyfile plugin
3  *
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.
8  *
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.
13  *
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.
17  *
18  * Copyright (C) 2008 Novell, Inc.
19  * Copyright (C) 2015 Red Hat, Inc.
20  */
21
22 #ifndef __NM_KEYFILE_INTERNAL_H__
23 #define __NM_KEYFILE_INTERNAL_H__
24
25 #include <sys/types.h>
26
27 #include "nm-default.h"
28 #include "nm-connection.h"
29 #include "nm-setting-8021x.h"
30
31 /*********************************************************/
32
33 #define NM_KEYFILE_CERT_SCHEME_PREFIX_BLOB "data:;base64,"
34 #define NM_KEYFILE_CERT_SCHEME_PREFIX_PATH "file://"
35
36 char *nm_keyfile_detect_unqualified_path_scheme (const char *base_dir,
37                                                  gconstpointer pdata,
38                                                  gsize data_len,
39                                                  gboolean consider_exists,
40                                                  gboolean *out_exists);
41
42 typedef enum {
43         NM_KEYFILE_READ_TYPE_WARN               = 1,
44 } NMKeyfileReadType;
45
46 /**
47  * NMKeyfileReadHandler:
48  *
49  * Hook to nm_keyfile_read(). The user might fail the reading by setting
50  * @error.
51  *
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.
55  */
56 typedef gboolean (*NMKeyfileReadHandler) (GKeyFile *keyfile,
57                                           NMConnection *connection,
58                                           NMKeyfileReadType type,
59                                           void *type_data,
60                                           void *user_data,
61                                           GError **error);
62
63 typedef enum {
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;
69
70 /**
71  * NMKeyfileReadTypeDataWarn:
72  *
73  * this struct is passed as @type_data for the @NMKeyfileReadHandler of
74  * type %NM_KEYFILE_READ_TYPE_WARN.
75  */
76 typedef struct {
77         /* might be %NULL, if the warning is not about a group. */
78         const char *group;
79
80         /* might be %NULL, if the warning is not about a setting. */
81         NMSetting *setting;
82
83         /* might be %NULL, if the warning is not about a property. */
84         const char *property_name;
85
86         NMKeyfileWarnSeverity severity;
87         const char *message;
88 } NMKeyfileReadTypeDataWarn;
89
90
91 NMConnection *nm_keyfile_read (GKeyFile *keyfile,
92                                const char *keyfile_name,
93                                const char *base_dir,
94                                NMKeyfileReadHandler handler,
95                                void *user_data,
96                                GError **error);
97
98 /*********************************************************/
99
100 typedef enum {
101         NM_KEYFILE_WRITE_TYPE_CERT              = 1,
102 } NMKeyfileWriteType;
103
104 /**
105  * NMKeyfileWriteHandler:
106  *
107  * This is a hook to tweak the serialization.
108  *
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.
112  *
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.
116  *
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.
119  *
120  * If the handler raises an error, it should set the @error value. This causes
121  * the an overall failure.
122  *
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.
126  */
127 typedef gboolean (*NMKeyfileWriteHandler) (NMConnection *connection,
128                                            GKeyFile *keyfile,
129                                            NMKeyfileWriteType type,
130                                            void *type_data,
131                                            void *user_data,
132                                            GError **error);
133
134 /**
135  * NMKeyfileWriteTypeDataCert:
136  *
137  * this struct is passed as @type_data for the @NMKeyfileWriteHandler of
138  * type %NM_KEYFILE_WRITE_TYPE_CERT.
139  */
140 typedef struct {
141         NMSetting8021x *setting;
142         const char *property_name;
143
144         /* The following functions are helpers that simplify the implementation
145          * of the handler. */
146         const char *suffix;
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;
152
153
154 GKeyFile *nm_keyfile_write (NMConnection *connection,
155                             NMKeyfileWriteHandler handler,
156                             void *user_data,
157                             GError **error);
158
159 /*********************************************************/
160
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);
163
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);
168
169
170 #endif /* __NM_KEYFILE_INTERNAL_H__ */