|
@@ -8,73 +8,96 @@
|
8
|
8
|
*/
|
9
|
9
|
|
10
|
10
|
#include <stdint.h>
|
11
|
|
-#include <gpxe/dhcp.h>
|
12
|
11
|
#include <gpxe/tables.h>
|
|
12
|
+#include <gpxe/list.h>
|
|
13
|
+#include <gpxe/refcnt.h>
|
13
|
14
|
|
14
|
|
-struct config_setting;
|
|
15
|
+struct settings;
|
|
16
|
+struct in_addr;
|
15
|
17
|
|
16
|
|
-/**
|
17
|
|
- * A configuration context
|
18
|
|
- *
|
19
|
|
- * This identifies the context within which settings are inspected and
|
20
|
|
- * changed. For example, the context might be global, or might be
|
21
|
|
- * restricted to the settings stored in NVS on a particular device.
|
22
|
|
- */
|
23
|
|
-struct config_context {
|
24
|
|
- /** DHCP options block, or NULL
|
|
18
|
+/** Settings block operations */
|
|
19
|
+struct settings_operations {
|
|
20
|
+ /** Set value of setting
|
|
21
|
+ *
|
|
22
|
+ * @v settings Settings block
|
|
23
|
+ * @v tag Setting tag number
|
|
24
|
+ * @v data Setting data, or NULL to clear setting
|
|
25
|
+ * @v len Length of setting data
|
|
26
|
+ * @ret rc Return status code
|
|
27
|
+ */
|
|
28
|
+ int ( * set ) ( struct settings *settings, unsigned int tag,
|
|
29
|
+ const void *data, size_t len );
|
|
30
|
+ /** Get value of setting
|
|
31
|
+ *
|
|
32
|
+ * @v settings Settings block
|
|
33
|
+ * @v tag Setting tag number
|
|
34
|
+ * @v data Buffer to fill with setting data
|
|
35
|
+ * @v len Length of buffer
|
|
36
|
+ * @ret len Length of setting data, or negative error
|
25
|
37
|
*
|
26
|
|
- * If NULL, all registered DHCP options blocks will be used.
|
|
38
|
+ * The actual length of the setting will be returned even if
|
|
39
|
+ * the buffer was too small.
|
27
|
40
|
*/
|
28
|
|
- struct dhcp_option_block *options;
|
|
41
|
+ int ( * get ) ( struct settings *settings, unsigned int tag,
|
|
42
|
+ void *data, size_t len );
|
|
43
|
+};
|
|
44
|
+
|
|
45
|
+/** A settings block */
|
|
46
|
+struct settings {
|
|
47
|
+ /** Reference counter */
|
|
48
|
+ struct refcnt *refcnt;
|
|
49
|
+ /** Name */
|
|
50
|
+ char name[16];
|
|
51
|
+ /** List of all settings */
|
|
52
|
+ struct list_head list;
|
|
53
|
+ /** Settings block operations */
|
|
54
|
+ struct settings_operations *op;
|
29
|
55
|
};
|
30
|
56
|
|
31
|
57
|
/**
|
32
|
|
- * A configuration setting type
|
|
58
|
+ * A setting type
|
33
|
59
|
*
|
34
|
|
- * This represents a type of configuration setting (e.g. string, IPv4
|
35
|
|
- * address, etc.).
|
|
60
|
+ * This represents a type of setting (e.g. string, IPv4 address,
|
|
61
|
+ * etc.).
|
36
|
62
|
*/
|
37
|
|
-struct config_setting_type {
|
|
63
|
+struct setting_type {
|
38
|
64
|
/** Name
|
39
|
65
|
*
|
40
|
66
|
* This is the name exposed to the user (e.g. "string").
|
41
|
67
|
*/
|
42
|
68
|
const char *name;
|
43
|
|
- /** Description */
|
44
|
|
- const char *description;
|
45
|
|
- /** Show value of setting
|
|
69
|
+ /** Parse and set value of setting
|
46
|
70
|
*
|
47
|
|
- * @v context Configuration context
|
48
|
|
- * @v setting Configuration setting
|
49
|
|
- * @v buf Buffer to contain value
|
|
71
|
+ * @v settings Settings block
|
|
72
|
+ * @v tag Setting tag number
|
|
73
|
+ * @v value Formatted setting data
|
|
74
|
+ * @ret rc Return status code
|
|
75
|
+ */
|
|
76
|
+ int ( * setf ) ( struct settings *settings, unsigned int tag,
|
|
77
|
+ const char *value );
|
|
78
|
+ /** Get and format value of setting
|
|
79
|
+ *
|
|
80
|
+ * @v settings Settings block, or NULL to search all blocks
|
|
81
|
+ * @v tag Setting tag number
|
|
82
|
+ * @v buf Buffer to contain formatted value
|
50
|
83
|
* @v len Length of buffer
|
51
|
84
|
* @ret len Length of formatted value, or negative error
|
52
|
85
|
*/
|
53
|
|
- int ( * show ) ( struct config_context *context,
|
54
|
|
- struct config_setting *setting,
|
|
86
|
+ int ( * getf ) ( struct settings *settings, unsigned int tag,
|
55
|
87
|
char *buf, size_t len );
|
56
|
|
- /** Set value of setting
|
57
|
|
- *
|
58
|
|
- * @v context Configuration context
|
59
|
|
- * @v setting Configuration setting
|
60
|
|
- * @v value Setting value (as a string)
|
61
|
|
- * @ret rc Return status code
|
62
|
|
- */
|
63
|
|
- int ( * set ) ( struct config_context *context,
|
64
|
|
- struct config_setting *setting,
|
65
|
|
- const char *value );
|
66
|
88
|
};
|
67
|
89
|
|
68
|
90
|
/** Declare a configuration setting type */
|
69
|
|
-#define __config_setting_type \
|
70
|
|
- __table ( struct config_setting_type, config_setting_types, 01 )
|
|
91
|
+#define __setting_type \
|
|
92
|
+ __table ( struct setting_type, setting_types, 01 )
|
71
|
93
|
|
72
|
94
|
/**
|
73
|
|
- * A configuration setting
|
|
95
|
+ * A named setting
|
74
|
96
|
*
|
75
|
|
- * This represents a single configuration setting (e.g. "hostname").
|
|
97
|
+ * This represents a single setting (e.g. "hostname"), encapsulating
|
|
98
|
+ * the information about the setting's tag number and type.
|
76
|
99
|
*/
|
77
|
|
-struct config_setting {
|
|
100
|
+struct named_setting {
|
78
|
101
|
/** Name
|
79
|
102
|
*
|
80
|
103
|
* This is the human-readable name for the setting. Where
|
|
@@ -84,71 +107,90 @@ struct config_setting {
|
84
|
107
|
const char *name;
|
85
|
108
|
/** Description */
|
86
|
109
|
const char *description;
|
87
|
|
- /** DHCP option tag
|
88
|
|
- *
|
89
|
|
- * This is the DHCP tag used to identify the option in DHCP
|
90
|
|
- * packets and stored option blocks.
|
91
|
|
- */
|
|
110
|
+ /** Setting tag number */
|
92
|
111
|
unsigned int tag;
|
93
|
|
- /** Configuration setting type
|
|
112
|
+ /** Setting type
|
94
|
113
|
*
|
95
|
114
|
* This identifies the type of setting (e.g. string, IPv4
|
96
|
115
|
* address, etc.).
|
97
|
116
|
*/
|
98
|
|
- struct config_setting_type *type;
|
|
117
|
+ struct setting_type *type;
|
99
|
118
|
};
|
100
|
119
|
|
101
|
120
|
/** Declare a configuration setting */
|
102
|
|
-#define __config_setting __table ( struct config_setting, config_settings, 01 )
|
|
121
|
+#define __named_setting __table ( struct named_setting, named_settings, 01 )
|
|
122
|
+
|
|
123
|
+extern struct settings interactive_settings;
|
|
124
|
+
|
|
125
|
+extern int get_setting ( struct settings *settings, unsigned int tag,
|
|
126
|
+ void *data, size_t len );
|
|
127
|
+extern int get_setting_len ( struct settings *settings, unsigned int tag );
|
|
128
|
+extern int get_string_setting ( struct settings *settings, unsigned int tag,
|
|
129
|
+ char *data, size_t len );
|
|
130
|
+extern int get_ipv4_setting ( struct settings *settings, unsigned int tag,
|
|
131
|
+ struct in_addr *inp );
|
|
132
|
+extern int get_int_setting ( struct settings *settings, unsigned int tag,
|
|
133
|
+ long *value );
|
|
134
|
+extern int get_uint_setting ( struct settings *settings, unsigned int tag,
|
|
135
|
+ unsigned long *value );
|
|
136
|
+extern struct settings * find_settings ( const char *name );
|
|
137
|
+extern int set_typed_setting ( struct settings *settings,
|
|
138
|
+ unsigned int tag, struct setting_type *type,
|
|
139
|
+ const char *value );
|
|
140
|
+extern int set_named_setting ( const char *name, const char *value );
|
|
141
|
+extern int get_named_setting ( const char *name, char *buf, size_t len );
|
103
|
142
|
|
104
|
143
|
/**
|
105
|
|
- * Show value of setting
|
|
144
|
+ * Set value of setting
|
106
|
145
|
*
|
107
|
|
- * @v context Configuration context
|
108
|
|
- * @v setting Configuration setting
|
109
|
|
- * @v buf Buffer to contain value
|
110
|
|
- * @v len Length of buffer
|
111
|
|
- * @ret len Length of formatted value, or negative error
|
|
146
|
+ * @v settings Settings block
|
|
147
|
+ * @v tag Setting tag number
|
|
148
|
+ * @v data Setting data, or NULL to clear setting
|
|
149
|
+ * @v len Length of setting data
|
|
150
|
+ * @ret rc Return status code
|
112
|
151
|
*/
|
113
|
|
-static inline int show_setting ( struct config_context *context,
|
114
|
|
- struct config_setting *setting,
|
115
|
|
- char *buf, size_t len ) {
|
116
|
|
- return setting->type->show ( context, setting, buf, len );
|
|
152
|
+static inline int set_setting ( struct settings *settings, unsigned int tag,
|
|
153
|
+ const void *data, size_t len ) {
|
|
154
|
+ return settings->op->set ( settings, tag, data, len );
|
117
|
155
|
}
|
118
|
156
|
|
119
|
|
-extern int set_setting ( struct config_context *context,
|
120
|
|
- struct config_setting *setting,
|
121
|
|
- const char *value );
|
122
|
|
-
|
123
|
157
|
/**
|
124
|
|
- * Clear setting
|
|
158
|
+ * Delete setting
|
125
|
159
|
*
|
126
|
|
- * @v context Configuration context
|
127
|
|
- * @v setting Configuration setting
|
|
160
|
+ * @v settings Settings block
|
|
161
|
+ * @v tag Setting tag number
|
128
|
162
|
* @ret rc Return status code
|
129
|
163
|
*/
|
130
|
|
-static inline int clear_setting ( struct config_context *context,
|
131
|
|
- struct config_setting *setting ) {
|
132
|
|
- delete_dhcp_option ( context->options, setting->tag );
|
133
|
|
- return 0;
|
|
164
|
+static inline int delete_setting ( struct settings *settings,
|
|
165
|
+ unsigned int tag ) {
|
|
166
|
+ return set_setting ( settings, tag, NULL, 0 );
|
134
|
167
|
}
|
135
|
168
|
|
136
|
|
-/* Function prototypes */
|
137
|
|
-extern int show_named_setting ( struct config_context *context,
|
138
|
|
- const char *name, char *buf, size_t len );
|
139
|
|
-extern int set_named_setting ( struct config_context *context,
|
140
|
|
- const char *name, const char *value );
|
|
169
|
+/**
|
|
170
|
+ * Get and format value of setting
|
|
171
|
+ *
|
|
172
|
+ * @v settings Settings block, or NULL to search all blocks
|
|
173
|
+ * @v tag Setting tag number
|
|
174
|
+ * @v type Settings type
|
|
175
|
+ * @v buf Buffer to contain formatted value
|
|
176
|
+ * @v len Length of buffer
|
|
177
|
+ * @ret len Length of formatted value, or negative error
|
|
178
|
+ */
|
|
179
|
+static inline int get_typed_setting ( struct settings *settings,
|
|
180
|
+ unsigned int tag,
|
|
181
|
+ struct setting_type *type,
|
|
182
|
+ char *buf, size_t len ) {
|
|
183
|
+ return type->getf ( settings, tag, buf, len );
|
|
184
|
+}
|
141
|
185
|
|
142
|
186
|
/**
|
143
|
|
- * Clear named setting
|
|
187
|
+ * Delete named setting
|
144
|
188
|
*
|
145
|
|
- * @v context Configuration context
|
146
|
|
- * @v name Configuration setting name
|
|
189
|
+ * @v name Name of setting
|
147
|
190
|
* @ret rc Return status code
|
148
|
191
|
*/
|
149
|
|
-static inline int clear_named_setting ( struct config_context *context,
|
150
|
|
- const char *name ) {
|
151
|
|
- return set_named_setting ( context, name, NULL );
|
|
192
|
+static inline int delete_named_setting ( const char *name ) {
|
|
193
|
+ return set_named_setting ( name, NULL );
|
152
|
194
|
}
|
153
|
195
|
|
154
|
196
|
#endif /* _GPXE_SETTINGS_H */
|