summaryrefslogtreecommitdiff
path: root/libnm-core/nm-keyfile.h
blob: 0967d254952654d4f1116b0ab8401035bb658076 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// SPDX-License-Identifier: LGPL-2.1+

#ifndef __NM_KEYFILE_H__
#define __NM_KEYFILE_H__

#if !defined(__NETWORKMANAGER_H_INSIDE__) && !defined(NETWORKMANAGER_COMPILATION)
    #error "Only <NetworkManager.h> can be included directly."
#endif

#include "nm-core-types.h"

G_BEGIN_DECLS

/**
 * NMKeyfileHandlerFlags:
 * @NM_KEYFILE_HANDLER_FLAGS_NONE: no flags set.
 *
 * Flags for customizing nm_keyfile_read() and nm_keyfile_write().
 *
 * Currently no flags are implemented.
 *
 * Since: 1.30
 */
typedef enum { /*< flags >*/
               NM_KEYFILE_HANDLER_FLAGS_NONE = 0,
} NMKeyfileHandlerFlags;

/**
 * NMKeyfileHandlerType:
 * @NM_KEYFILE_HANDLER_TYPE_WARN: a warning.
 * @NM_KEYFILE_HANDLER_TYPE_WRITE_CERT: for handling certificates while writing
 *   a connection to keyfile.
 *
 * The type of the callback for %NMKeyfileReadHandler and %NMKeyfileWriteHandler.
 * Depending on the type, you can interpret %NMKeyfileHandlerData.
 *
 * Since: 1.30
 */
typedef enum {
    NM_KEYFILE_HANDLER_TYPE_WARN       = 1,
    NM_KEYFILE_HANDLER_TYPE_WRITE_CERT = 2,
} NMKeyfileHandlerType;

/**
 * NMKeyfileHandlerData:
 *
 * Opaque type with parameters for the callback. The actual content
 * depends on the %NMKeyfileHandlerType.
 *
 * Since: 1.30
 */
typedef struct _NMKeyfileHandlerData NMKeyfileHandlerData;

/**
 * NMKeyfileReadHandler:
 * @keyfile: the #GKeyFile that is currently read
 * @connection: the #NMConnection that is being constructed.
 * @handler_type: the %NMKeyfileHandlerType that indicates which type
 *   the request is.
 * @handler_data: the #NMKeyfileHandlerData. What you can do with it
 *   depends on the @handler_type.
 * @user_data: the user-data argument to nm_keyfile_read().
 *
 * Hook to nm_keyfile_read().
 *
 * The callee may abort the reading by setting an error via nm_keyfile_handler_data_fail_with_error().
 *
 * Returns: the callee should return TRUE, if the event was handled and/or recognized.
 *   Otherwise, a default action will be performed that depends on the @type.
 *   For %NM_KEYFILE_HANDLER_TYPE_WARN type, the default action is doing nothing.
 *
 * Since: 1.30
 */
typedef gboolean (*NMKeyfileReadHandler)(GKeyFile *            keyfile,
                                         NMConnection *        connection,
                                         NMKeyfileHandlerType  handler_type,
                                         NMKeyfileHandlerData *handler_data,
                                         void *                user_data);

NM_AVAILABLE_IN_1_30
NMConnection *nm_keyfile_read(GKeyFile *            keyfile,
                              const char *          base_dir,
                              NMKeyfileHandlerFlags handler_flags,
                              NMKeyfileReadHandler  handler,
                              void *                user_data,
                              GError **             error);

/**
 * NMKeyfileWriteHandler:
 * @connection: the #NMConnection that is currently written.
 * @keyfile: the #GKeyFile that is currently constructed.
 * @handler_type: the %NMKeyfileHandlerType that indicates which type
 *   the request is.
 * @handler_data: the #NMKeyfileHandlerData. What you can do with it
 *   depends on the @handler_type.
 * @user_data: the user-data argument to nm_keyfile_read().
 *
 * This is a hook to tweak the serialization.
 *
 * Handler for certain properties or events that are not entirely contained
 * within the keyfile or that might be serialized differently. The @type and
 * @handler_data arguments tell which kind of argument we have at hand.
 *
 * Currently only the type %NM_KEYFILE_HANDLER_TYPE_WRITE_CERT is supported.
 *
 * The callee may call nm_keyfile_handler_data_fail_with_error() to abort
 * the writing with error.
 *
 * Returns: the callee should return %TRUE if the event was handled. If the
 *   event was unhandled, a default action will be performed that depends on
 *   the @handler_type.
 *
 * Since: 1.30
 */
typedef gboolean (*NMKeyfileWriteHandler)(NMConnection *        connection,
                                          GKeyFile *            keyfile,
                                          NMKeyfileHandlerType  handler_type,
                                          NMKeyfileHandlerData *handler_data,
                                          void *                user_data);

NM_AVAILABLE_IN_1_30
GKeyFile *nm_keyfile_write(NMConnection *        connection,
                           NMKeyfileHandlerFlags handler_flags,
                           NMKeyfileWriteHandler handler,
                           void *                user_data,
                           GError **             error);

/*****************************************************************************/

NM_AVAILABLE_IN_1_30
void nm_keyfile_handler_data_fail_with_error(NMKeyfileHandlerData *handler_data, GError *src);

NM_AVAILABLE_IN_1_30
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);

/**
 * NMKeyfileWarnSeverity:
 * @NM_KEYFILE_WARN_SEVERITY_DEBUG: debug message
 * @NM_KEYFILE_WARN_SEVERITY_INFO: info message
 * @NM_KEYFILE_WARN_SEVERITY_INFO_MISSING_FILE: info message about a missing file
 * @NM_KEYFILE_WARN_SEVERITY_WARN: a warning message
 *
 * The severity level of %NM_KEYFILE_HANDLER_TYPE_WARN events.
 *
 * Since: 1.30
 */
typedef enum {
    NM_KEYFILE_WARN_SEVERITY_DEBUG             = 1000,
    NM_KEYFILE_WARN_SEVERITY_INFO              = 2000,
    NM_KEYFILE_WARN_SEVERITY_INFO_MISSING_FILE = 2901,
    NM_KEYFILE_WARN_SEVERITY_WARN              = 3000,
} NMKeyfileWarnSeverity;

NM_AVAILABLE_IN_1_30
void nm_keyfile_handler_data_warn_get(const NMKeyfileHandlerData *handler_data,
                                      const char **               out_message,
                                      NMKeyfileWarnSeverity *     out_severity);

G_END_DECLS

#endif /* __NM_KEYFILE_H__ */