|
@@ -37,17 +37,15 @@
|
37
|
37
|
|
38
|
38
|
/** Registered setting types */
|
39
|
39
|
static struct setting_type setting_types[0]
|
40
|
|
- __table_start ( struct setting_type, setting_types );
|
|
40
|
+__table_start ( struct setting_type, setting_types );
|
41
|
41
|
static struct setting_type setting_types_end[0]
|
42
|
|
- __table_end ( struct setting_type, setting_types );
|
|
42
|
+__table_end ( struct setting_type, setting_types );
|
43
|
43
|
|
44
|
44
|
/** Registered named settings */
|
45
|
45
|
static struct named_setting named_settings[0]
|
46
|
|
- __table_start ( struct named_setting, named_settings );
|
|
46
|
+__table_start ( struct named_setting, named_settings );
|
47
|
47
|
static struct named_setting named_settings_end[0]
|
48
|
|
- __table_end ( struct named_setting, named_settings );
|
49
|
|
-
|
50
|
|
-struct setting_type setting_type_hex __setting_type;
|
|
48
|
+__table_end ( struct named_setting, named_settings );
|
51
|
49
|
|
52
|
50
|
/**
|
53
|
51
|
* Obtain printable version of a settings tag number
|
|
@@ -75,61 +73,132 @@ static inline char * setting_tag_name ( unsigned int tag ) {
|
75
|
73
|
******************************************************************************
|
76
|
74
|
*/
|
77
|
75
|
|
78
|
|
-/** List of all registered settings */
|
79
|
|
-static struct list_head all_settings = {
|
80
|
|
- &interactive_settings.list, &interactive_settings.list
|
81
|
|
-};
|
82
|
|
-
|
83
|
76
|
// Dummy routine just for testing
|
84
|
|
-static int dummy_set ( struct settings *settings, unsigned int tag,
|
85
|
|
- const void *data, size_t len ) {
|
86
|
|
- DBGC ( settings, "Settings %p: set %s to:\n",
|
|
77
|
+int simple_settings_store ( struct settings *settings, unsigned int tag,
|
|
78
|
+ const void *data, size_t len ) {
|
|
79
|
+ DBGC ( settings, "Settings %p: store %s to:\n",
|
87
|
80
|
settings, setting_tag_name ( tag ) );
|
88
|
81
|
DBGC_HD ( settings, data, len );
|
89
|
82
|
return 0;
|
90
|
83
|
}
|
91
|
84
|
|
92
|
85
|
// Dummy routine just for testing
|
93
|
|
-static int dummy_get ( struct settings *settings, unsigned int tag,
|
94
|
|
- void *data, size_t len ) {
|
|
86
|
+int simple_settings_fetch ( struct settings *settings, unsigned int tag,
|
|
87
|
+ void *data, size_t len ) {
|
95
|
88
|
unsigned int i;
|
96
|
89
|
|
97
|
|
- DBGC ( settings, "Settings %p: get %s\n",
|
|
90
|
+ DBGC ( settings, "Settings %p: fetch %s\n",
|
98
|
91
|
settings, setting_tag_name ( tag ) );
|
99
|
92
|
for ( i = 0 ; i < len ; i++ )
|
100
|
93
|
*( ( ( uint8_t * ) data ) + i ) = i;
|
101
|
94
|
return ( len ? len : 8 );
|
102
|
95
|
}
|
103
|
96
|
|
104
|
|
-struct settings_operations dummy_settings_operations = {
|
105
|
|
- .set = dummy_set,
|
106
|
|
- .get = dummy_get,
|
|
97
|
+// Dummy routine just for testing
|
|
98
|
+static void apply_settings ( void ) {
|
|
99
|
+}
|
|
100
|
+
|
|
101
|
+/** Simple settings operations */
|
|
102
|
+struct settings_operations simple_settings_operations = {
|
|
103
|
+ .store = simple_settings_store,
|
|
104
|
+ .fetch = simple_settings_fetch,
|
107
|
105
|
};
|
108
|
106
|
|
109
|
|
-/** Interactively-edited settings */
|
110
|
|
-struct settings interactive_settings = {
|
|
107
|
+/** Root settings block */
|
|
108
|
+struct settings settings_root = {
|
111
|
109
|
.refcnt = NULL,
|
112
|
110
|
.name = "",
|
113
|
|
- .list = { &all_settings, &all_settings },
|
114
|
|
- .op = &dummy_settings_operations,
|
|
111
|
+ .siblings = LIST_HEAD_INIT ( settings_root.siblings ),
|
|
112
|
+ .children = LIST_HEAD_INIT ( settings_root.children ),
|
|
113
|
+ .op = &simple_settings_operations,
|
115
|
114
|
};
|
116
|
115
|
|
117
|
116
|
/**
|
118
|
|
- * Find named settings block
|
|
117
|
+ * Register settings block
|
119
|
118
|
*
|
120
|
|
- * @v name Name
|
|
119
|
+ * @v settings Settings block
|
|
120
|
+ * @v parent Parent settings block, or NULL
|
|
121
|
+ * @ret rc Return status code
|
|
122
|
+ */
|
|
123
|
+int register_settings ( struct settings *settings, struct settings *parent ) {
|
|
124
|
+
|
|
125
|
+ /* NULL parent => add to settings root */
|
|
126
|
+ assert ( settings != NULL );
|
|
127
|
+ if ( parent == NULL )
|
|
128
|
+ parent = &settings_root;
|
|
129
|
+
|
|
130
|
+ /* Add to list of settings */
|
|
131
|
+ ref_get ( settings->refcnt );
|
|
132
|
+ ref_get ( parent->refcnt );
|
|
133
|
+ settings->parent = parent;
|
|
134
|
+ list_add_tail ( &settings->siblings, &parent->children );
|
|
135
|
+ DBGC ( settings, "Settings %p registered\n", settings );
|
|
136
|
+
|
|
137
|
+ /* Apply potentially-updated settings */
|
|
138
|
+ apply_settings();
|
|
139
|
+
|
|
140
|
+ return 0;
|
|
141
|
+}
|
|
142
|
+
|
|
143
|
+/**
|
|
144
|
+ * Unregister settings block
|
|
145
|
+ *
|
|
146
|
+ * @v settings Settings block
|
|
147
|
+ */
|
|
148
|
+void unregister_settings ( struct settings *settings ) {
|
|
149
|
+
|
|
150
|
+ /* Remove from list of settings */
|
|
151
|
+ ref_put ( settings->refcnt );
|
|
152
|
+ ref_put ( settings->parent->refcnt );
|
|
153
|
+ list_del ( &settings->siblings );
|
|
154
|
+ DBGC ( settings, "Settings %p unregistered\n", settings );
|
|
155
|
+
|
|
156
|
+ /* Apply potentially-updated settings */
|
|
157
|
+ apply_settings();
|
|
158
|
+}
|
|
159
|
+
|
|
160
|
+/**
|
|
161
|
+ * Find child named settings block
|
|
162
|
+ *
|
|
163
|
+ * @v parent Parent settings block
|
|
164
|
+ * @v name Name within this parent
|
121
|
165
|
* @ret settings Settings block, or NULL
|
122
|
166
|
*/
|
123
|
|
-struct settings * find_settings ( const char *name ) {
|
|
167
|
+struct settings * find_child_settings ( struct settings *parent,
|
|
168
|
+ const char *name ) {
|
124
|
169
|
struct settings *settings;
|
125
|
|
-
|
126
|
|
- list_for_each_entry ( settings, &all_settings, list ) {
|
127
|
|
- if ( strcasecmp ( name, settings->name ) == 0 )
|
|
170
|
+ size_t len;
|
|
171
|
+
|
|
172
|
+ /* Look for a child whose name matches the initial component */
|
|
173
|
+ list_for_each_entry ( settings, &parent->children, siblings ) {
|
|
174
|
+ len = strlen ( settings->name );
|
|
175
|
+ if ( strncmp ( name, settings->name, len ) != 0 )
|
|
176
|
+ continue;
|
|
177
|
+ if ( name[len] == 0 )
|
128
|
178
|
return settings;
|
|
179
|
+ if ( name[len] == '.' )
|
|
180
|
+ return find_child_settings ( settings,
|
|
181
|
+ ( name + len + 1 ) );
|
129
|
182
|
}
|
|
183
|
+
|
130
|
184
|
return NULL;
|
131
|
185
|
}
|
132
|
186
|
|
|
187
|
+/**
|
|
188
|
+ * Find named settings block
|
|
189
|
+ *
|
|
190
|
+ * @v name Name
|
|
191
|
+ * @ret settings Settings block, or NULL
|
|
192
|
+ */
|
|
193
|
+struct settings * find_settings ( const char *name ) {
|
|
194
|
+
|
|
195
|
+ /* If name is empty, use the root */
|
|
196
|
+ if ( ! *name )
|
|
197
|
+ return &settings_root;
|
|
198
|
+
|
|
199
|
+ return find_child_settings ( &settings_root, name );
|
|
200
|
+}
|
|
201
|
+
|
133
|
202
|
/******************************************************************************
|
134
|
203
|
*
|
135
|
204
|
* Core settings routines
|
|
@@ -138,7 +207,7 @@ struct settings * find_settings ( const char *name ) {
|
138
|
207
|
*/
|
139
|
208
|
|
140
|
209
|
/**
|
141
|
|
- * Get value of setting
|
|
210
|
+ * Fetch value of setting
|
142
|
211
|
*
|
143
|
212
|
* @v settings Settings block, or NULL to search all blocks
|
144
|
213
|
* @v tag Setting tag number
|
|
@@ -149,24 +218,30 @@ struct settings * find_settings ( const char *name ) {
|
149
|
218
|
* The actual length of the setting will be returned even if
|
150
|
219
|
* the buffer was too small.
|
151
|
220
|
*/
|
152
|
|
-int get_setting ( struct settings *settings, unsigned int tag,
|
153
|
|
- void *data, size_t len ) {
|
|
221
|
+int fetch_setting ( struct settings *settings, unsigned int tag,
|
|
222
|
+ void *data, size_t len ) {
|
|
223
|
+ struct settings *child;
|
154
|
224
|
int ret;
|
155
|
225
|
|
156
|
|
- if ( settings ) {
|
157
|
|
- return settings->op->get ( settings, tag, data, len );
|
158
|
|
- } else {
|
159
|
|
- list_for_each_entry ( settings, &all_settings, list ) {
|
160
|
|
- if ( ( ret = settings->op->get ( settings, tag,
|
161
|
|
- data, len ) ) >= 0 )
|
162
|
|
- return ret;
|
163
|
|
- }
|
164
|
|
- return -ENOENT;
|
|
226
|
+ /* NULL settings implies starting at the global settings root */
|
|
227
|
+ if ( ! settings )
|
|
228
|
+ settings = &settings_root;
|
|
229
|
+
|
|
230
|
+ /* Try this block first */
|
|
231
|
+ if ( ( ret = settings->op->fetch ( settings, tag, data, len ) ) >= 0)
|
|
232
|
+ return ret;
|
|
233
|
+
|
|
234
|
+ /* Recurse into each child block in turn */
|
|
235
|
+ list_for_each_entry ( child, &settings->children, siblings ) {
|
|
236
|
+ if ( ( ret = fetch_setting ( settings, tag, data, len ) ) >= 0)
|
|
237
|
+ return ret;
|
165
|
238
|
}
|
|
239
|
+
|
|
240
|
+ return -ENOENT;
|
166
|
241
|
}
|
167
|
242
|
|
168
|
243
|
/**
|
169
|
|
- * Get length of setting
|
|
244
|
+ * Fetch length of setting
|
170
|
245
|
*
|
171
|
246
|
* @v settings Settings block, or NULL to search all blocks
|
172
|
247
|
* @v tag Setting tag number
|
|
@@ -175,12 +250,12 @@ int get_setting ( struct settings *settings, unsigned int tag,
|
175
|
250
|
* This function can also be used as an existence check for the
|
176
|
251
|
* setting.
|
177
|
252
|
*/
|
178
|
|
-int get_setting_len ( struct settings *settings, unsigned int tag ) {
|
179
|
|
- return get_setting ( settings, tag, NULL, 0 );
|
|
253
|
+int fetch_setting_len ( struct settings *settings, unsigned int tag ) {
|
|
254
|
+ return fetch_setting ( settings, tag, NULL, 0 );
|
180
|
255
|
}
|
181
|
256
|
|
182
|
257
|
/**
|
183
|
|
- * Get value of string setting
|
|
258
|
+ * Fetch value of string setting
|
184
|
259
|
*
|
185
|
260
|
* @v settings Settings block, or NULL to search all blocks
|
186
|
261
|
* @v tag Setting tag number
|
|
@@ -192,25 +267,25 @@ int get_setting_len ( struct settings *settings, unsigned int tag ) {
|
192
|
267
|
* The returned length will be the length of the underlying setting
|
193
|
268
|
* data.
|
194
|
269
|
*/
|
195
|
|
-int get_string_setting ( struct settings *settings, unsigned int tag,
|
196
|
|
- char *data, size_t len ) {
|
|
270
|
+int fetch_string_setting ( struct settings *settings, unsigned int tag,
|
|
271
|
+ char *data, size_t len ) {
|
197
|
272
|
memset ( data, 0, len );
|
198
|
|
- return get_setting ( settings, tag, data, ( len - 1 ) );
|
|
273
|
+ return fetch_setting ( settings, tag, data, ( len - 1 ) );
|
199
|
274
|
}
|
200
|
275
|
|
201
|
276
|
/**
|
202
|
|
- * Get value of IPv4 address setting
|
|
277
|
+ * Fetch value of IPv4 address setting
|
203
|
278
|
*
|
204
|
279
|
* @v settings Settings block, or NULL to search all blocks
|
205
|
280
|
* @v tag Setting tag number
|
206
|
281
|
* @v inp IPv4 address to fill in
|
207
|
282
|
* @ret len Length of setting, or negative error
|
208
|
283
|
*/
|
209
|
|
-int get_ipv4_setting ( struct settings *settings, unsigned int tag,
|
210
|
|
- struct in_addr *inp ) {
|
|
284
|
+int fetch_ipv4_setting ( struct settings *settings, unsigned int tag,
|
|
285
|
+ struct in_addr *inp ) {
|
211
|
286
|
int len;
|
212
|
287
|
|
213
|
|
- len = get_setting ( settings, tag, inp, sizeof ( *inp ) );
|
|
288
|
+ len = fetch_setting ( settings, tag, inp, sizeof ( *inp ) );
|
214
|
289
|
if ( len < 0 )
|
215
|
290
|
return len;
|
216
|
291
|
if ( len != sizeof ( *inp ) )
|
|
@@ -219,15 +294,15 @@ int get_ipv4_setting ( struct settings *settings, unsigned int tag,
|
219
|
294
|
}
|
220
|
295
|
|
221
|
296
|
/**
|
222
|
|
- * Get value of signed integer setting
|
|
297
|
+ * Fetch value of signed integer setting
|
223
|
298
|
*
|
224
|
299
|
* @v settings Settings block, or NULL to search all blocks
|
225
|
300
|
* @v tag Setting tag number
|
226
|
301
|
* @v value Integer value to fill in
|
227
|
302
|
* @ret len Length of setting, or negative error
|
228
|
303
|
*/
|
229
|
|
-int get_int_setting ( struct settings *settings, unsigned int tag,
|
230
|
|
- long *value ) {
|
|
304
|
+int fetch_int_setting ( struct settings *settings, unsigned int tag,
|
|
305
|
+ long *value ) {
|
231
|
306
|
union {
|
232
|
307
|
long value;
|
233
|
308
|
uint8_t u8[ sizeof ( long ) ];
|
|
@@ -237,7 +312,7 @@ int get_int_setting ( struct settings *settings, unsigned int tag,
|
237
|
312
|
int i;
|
238
|
313
|
|
239
|
314
|
buf.value = 0;
|
240
|
|
- len = get_setting ( settings, tag, &buf, sizeof ( buf ) );
|
|
315
|
+ len = fetch_setting ( settings, tag, &buf, sizeof ( buf ) );
|
241
|
316
|
if ( len < 0 )
|
242
|
317
|
return len;
|
243
|
318
|
if ( len > ( int ) sizeof ( buf ) )
|
|
@@ -252,19 +327,19 @@ int get_int_setting ( struct settings *settings, unsigned int tag,
|
252
|
327
|
}
|
253
|
328
|
|
254
|
329
|
/**
|
255
|
|
- * Get value of unsigned integer setting
|
|
330
|
+ * Fetch value of unsigned integer setting
|
256
|
331
|
*
|
257
|
332
|
* @v settings Settings block, or NULL to search all blocks
|
258
|
333
|
* @v tag Setting tag number
|
259
|
334
|
* @v value Integer value to fill in
|
260
|
335
|
* @ret len Length of setting, or negative error
|
261
|
336
|
*/
|
262
|
|
-int get_uint_setting ( struct settings *settings, unsigned int tag,
|
263
|
|
- unsigned long *value ) {
|
|
337
|
+int fetch_uint_setting ( struct settings *settings, unsigned int tag,
|
|
338
|
+ unsigned long *value ) {
|
264
|
339
|
long svalue;
|
265
|
340
|
int len;
|
266
|
341
|
|
267
|
|
- len = get_int_setting ( settings, tag, &svalue );
|
|
342
|
+ len = fetch_int_setting ( settings, tag, &svalue );
|
268
|
343
|
if ( len < 0 )
|
269
|
344
|
return len;
|
270
|
345
|
|
|
@@ -281,7 +356,7 @@ int get_uint_setting ( struct settings *settings, unsigned int tag,
|
281
|
356
|
*/
|
282
|
357
|
|
283
|
358
|
/**
|
284
|
|
- * Set value of typed setting
|
|
359
|
+ * Store value of typed setting
|
285
|
360
|
*
|
286
|
361
|
* @v settings Settings block
|
287
|
362
|
* @v tag Setting tag number
|
|
@@ -289,18 +364,18 @@ int get_uint_setting ( struct settings *settings, unsigned int tag,
|
289
|
364
|
* @v value Formatted setting data, or NULL
|
290
|
365
|
* @ret rc Return status code
|
291
|
366
|
*/
|
292
|
|
-int set_typed_setting ( struct settings *settings,
|
293
|
|
- unsigned int tag, struct setting_type *type,
|
294
|
|
- const char *value ) {
|
|
367
|
+int store_typed_setting ( struct settings *settings,
|
|
368
|
+ unsigned int tag, struct setting_type *type,
|
|
369
|
+ const char *value ) {
|
295
|
370
|
|
296
|
371
|
/* NULL value implies deletion. Avoid imposing the burden of
|
297
|
|
- * checking for NULL values on each typed setting's setf()
|
|
372
|
+ * checking for NULL values on each typed setting's storef()
|
298
|
373
|
* method.
|
299
|
374
|
*/
|
300
|
375
|
if ( ! value )
|
301
|
376
|
return delete_setting ( settings, tag );
|
302
|
377
|
|
303
|
|
- return type->setf ( settings, tag, value );
|
|
378
|
+ return type->storef ( settings, tag, value );
|
304
|
379
|
}
|
305
|
380
|
|
306
|
381
|
/**
|
|
@@ -314,7 +389,7 @@ static struct named_setting * find_named_setting ( const char *name ) {
|
314
|
389
|
|
315
|
390
|
for ( setting = named_settings ; setting < named_settings_end ;
|
316
|
391
|
setting++ ) {
|
317
|
|
- if ( strcasecmp ( name, setting->name ) == 0 )
|
|
392
|
+ if ( strcmp ( name, setting->name ) == 0 )
|
318
|
393
|
return setting;
|
319
|
394
|
}
|
320
|
395
|
return NULL;
|
|
@@ -330,7 +405,7 @@ static struct setting_type * find_setting_type ( const char *name ) {
|
330
|
405
|
struct setting_type *type;
|
331
|
406
|
|
332
|
407
|
for ( type = setting_types ; type < setting_types_end ; type++ ) {
|
333
|
|
- if ( strcasecmp ( name, type->name ) == 0 )
|
|
408
|
+ if ( strcmp ( name, type->name ) == 0 )
|
334
|
409
|
return type;
|
335
|
410
|
}
|
336
|
411
|
return NULL;
|
|
@@ -360,7 +435,7 @@ static int parse_setting_name ( const char *name, struct settings **settings,
|
360
|
435
|
char *tmp;
|
361
|
436
|
|
362
|
437
|
/* Set defaults */
|
363
|
|
- *settings = NULL;
|
|
438
|
+ *settings = &settings_root;
|
364
|
439
|
*tag = 0;
|
365
|
440
|
*type = &setting_type_hex;
|
366
|
441
|
|
|
@@ -420,13 +495,13 @@ static int parse_setting_name ( const char *name, struct settings **settings,
|
420
|
495
|
}
|
421
|
496
|
|
422
|
497
|
/**
|
423
|
|
- * Parse and set value of named setting
|
|
498
|
+ * Parse and store value of named setting
|
424
|
499
|
*
|
425
|
500
|
* @v name Name of setting
|
426
|
501
|
* @v value Formatted setting data, or NULL
|
427
|
502
|
* @ret rc Return status code
|
428
|
503
|
*/
|
429
|
|
-int set_named_setting ( const char *name, const char *value ) {
|
|
504
|
+int store_named_setting ( const char *name, const char *value ) {
|
430
|
505
|
struct settings *settings;
|
431
|
506
|
unsigned int tag;
|
432
|
507
|
struct setting_type *type;
|
|
@@ -435,20 +510,18 @@ int set_named_setting ( const char *name, const char *value ) {
|
435
|
510
|
if ( ( rc = parse_setting_name ( name, &settings, &tag,
|
436
|
511
|
&type ) ) != 0 )
|
437
|
512
|
return rc;
|
438
|
|
- if ( settings == NULL )
|
439
|
|
- return -ENODEV;
|
440
|
|
- return set_typed_setting ( settings, tag, type, value );
|
|
513
|
+ return store_typed_setting ( settings, tag, type, value );
|
441
|
514
|
}
|
442
|
515
|
|
443
|
516
|
/**
|
444
|
|
- * Get and format value of named setting
|
|
517
|
+ * Fetch and format value of named setting
|
445
|
518
|
*
|
446
|
519
|
* @v name Name of setting
|
447
|
520
|
* @v buf Buffer to contain formatted value
|
448
|
521
|
* @v len Length of buffer
|
449
|
522
|
* @ret len Length of formatted value, or negative error
|
450
|
523
|
*/
|
451
|
|
-int get_named_setting ( const char *name, char *buf, size_t len ) {
|
|
524
|
+int fetch_named_setting ( const char *name, char *buf, size_t len ) {
|
452
|
525
|
struct settings *settings;
|
453
|
526
|
unsigned int tag;
|
454
|
527
|
struct setting_type *type;
|
|
@@ -457,7 +530,7 @@ int get_named_setting ( const char *name, char *buf, size_t len ) {
|
457
|
530
|
if ( ( rc = parse_setting_name ( name, &settings, &tag,
|
458
|
531
|
&type ) ) != 0 )
|
459
|
532
|
return rc;
|
460
|
|
- return get_typed_setting ( settings, tag, type, buf, len );
|
|
533
|
+ return fetch_typed_setting ( settings, tag, type, buf, len );
|
461
|
534
|
}
|
462
|
535
|
|
463
|
536
|
/******************************************************************************
|
|
@@ -468,20 +541,20 @@ int get_named_setting ( const char *name, char *buf, size_t len ) {
|
468
|
541
|
*/
|
469
|
542
|
|
470
|
543
|
/**
|
471
|
|
- * Parse and set value of string setting
|
|
544
|
+ * Parse and store value of string setting
|
472
|
545
|
*
|
473
|
546
|
* @v settings Settings block
|
474
|
547
|
* @v tag Setting tag number
|
475
|
548
|
* @v value Formatted setting data
|
476
|
549
|
* @ret rc Return status code
|
477
|
550
|
*/
|
478
|
|
-static int setf_string ( struct settings *settings, unsigned int tag,
|
479
|
|
- const char *value ) {
|
480
|
|
- return set_setting ( settings, tag, value, strlen ( value ) );
|
|
551
|
+static int storef_string ( struct settings *settings, unsigned int tag,
|
|
552
|
+ const char *value ) {
|
|
553
|
+ return store_setting ( settings, tag, value, strlen ( value ) );
|
481
|
554
|
}
|
482
|
555
|
|
483
|
556
|
/**
|
484
|
|
- * Get and format value of string setting
|
|
557
|
+ * Fetch and format value of string setting
|
485
|
558
|
*
|
486
|
559
|
* @v settings Settings block, or NULL to search all blocks
|
487
|
560
|
* @v tag Setting tag number
|
|
@@ -489,37 +562,37 @@ static int setf_string ( struct settings *settings, unsigned int tag,
|
489
|
562
|
* @v len Length of buffer
|
490
|
563
|
* @ret len Length of formatted value, or negative error
|
491
|
564
|
*/
|
492
|
|
-static int getf_string ( struct settings *settings, unsigned int tag,
|
493
|
|
- char *buf, size_t len ) {
|
494
|
|
- return get_string_setting ( settings, tag, buf, len );
|
|
565
|
+static int fetchf_string ( struct settings *settings, unsigned int tag,
|
|
566
|
+ char *buf, size_t len ) {
|
|
567
|
+ return fetch_string_setting ( settings, tag, buf, len );
|
495
|
568
|
}
|
496
|
569
|
|
497
|
570
|
/** A string setting type */
|
498
|
571
|
struct setting_type setting_type_string __setting_type = {
|
499
|
572
|
.name = "string",
|
500
|
|
- .setf = setf_string,
|
501
|
|
- .getf = getf_string,
|
|
573
|
+ .storef = storef_string,
|
|
574
|
+ .fetchf = fetchf_string,
|
502
|
575
|
};
|
503
|
576
|
|
504
|
577
|
/**
|
505
|
|
- * Parse and set value of IPv4 address setting
|
|
578
|
+ * Parse and store value of IPv4 address setting
|
506
|
579
|
*
|
507
|
580
|
* @v settings Settings block
|
508
|
581
|
* @v tag Setting tag number
|
509
|
582
|
* @v value Formatted setting data
|
510
|
583
|
* @ret rc Return status code
|
511
|
584
|
*/
|
512
|
|
-static int setf_ipv4 ( struct settings *settings, unsigned int tag,
|
513
|
|
- const char *value ) {
|
|
585
|
+static int storef_ipv4 ( struct settings *settings, unsigned int tag,
|
|
586
|
+ const char *value ) {
|
514
|
587
|
struct in_addr ipv4;
|
515
|
588
|
|
516
|
589
|
if ( inet_aton ( value, &ipv4 ) == 0 )
|
517
|
590
|
return -EINVAL;
|
518
|
|
- return set_setting ( settings, tag, &ipv4, sizeof ( ipv4 ) );
|
|
591
|
+ return store_setting ( settings, tag, &ipv4, sizeof ( ipv4 ) );
|
519
|
592
|
}
|
520
|
593
|
|
521
|
594
|
/**
|
522
|
|
- * Get and format value of IPv4 address setting
|
|
595
|
+ * Fetch and format value of IPv4 address setting
|
523
|
596
|
*
|
524
|
597
|
* @v settings Settings block, or NULL to search all blocks
|
525
|
598
|
* @v tag Setting tag number
|
|
@@ -527,12 +600,12 @@ static int setf_ipv4 ( struct settings *settings, unsigned int tag,
|
527
|
600
|
* @v len Length of buffer
|
528
|
601
|
* @ret len Length of formatted value, or negative error
|
529
|
602
|
*/
|
530
|
|
-static int getf_ipv4 ( struct settings *settings, unsigned int tag,
|
531
|
|
- char *buf, size_t len ) {
|
|
603
|
+static int fetchf_ipv4 ( struct settings *settings, unsigned int tag,
|
|
604
|
+ char *buf, size_t len ) {
|
532
|
605
|
struct in_addr ipv4;
|
533
|
606
|
int rc;
|
534
|
607
|
|
535
|
|
- if ( ( rc = get_ipv4_setting ( settings, tag, &ipv4 ) ) < 0 )
|
|
608
|
+ if ( ( rc = fetch_ipv4_setting ( settings, tag, &ipv4 ) ) < 0 )
|
536
|
609
|
return rc;
|
537
|
610
|
return snprintf ( buf, len, inet_ntoa ( ipv4 ) );
|
538
|
611
|
}
|
|
@@ -540,12 +613,12 @@ static int getf_ipv4 ( struct settings *settings, unsigned int tag,
|
540
|
613
|
/** An IPv4 address setting type */
|
541
|
614
|
struct setting_type setting_type_ipv4 __setting_type = {
|
542
|
615
|
.name = "ipv4",
|
543
|
|
- .setf = setf_ipv4,
|
544
|
|
- .getf = getf_ipv4,
|
|
616
|
+ .storef = storef_ipv4,
|
|
617
|
+ .fetchf = fetchf_ipv4,
|
545
|
618
|
};
|
546
|
619
|
|
547
|
620
|
/**
|
548
|
|
- * Parse and set value of integer setting
|
|
621
|
+ * Parse and store value of integer setting
|
549
|
622
|
*
|
550
|
623
|
* @v settings Settings block
|
551
|
624
|
* @v tag Setting tag number
|
|
@@ -553,8 +626,8 @@ struct setting_type setting_type_ipv4 __setting_type = {
|
553
|
626
|
* @v size Integer size, in bytes
|
554
|
627
|
* @ret rc Return status code
|
555
|
628
|
*/
|
556
|
|
-static int setf_int ( struct settings *settings, unsigned int tag,
|
557
|
|
- const char *value, unsigned int size ) {
|
|
629
|
+static int storef_int ( struct settings *settings, unsigned int tag,
|
|
630
|
+ const char *value, unsigned int size ) {
|
558
|
631
|
union {
|
559
|
632
|
uint32_t num;
|
560
|
633
|
uint8_t bytes[4];
|
|
@@ -564,12 +637,12 @@ static int setf_int ( struct settings *settings, unsigned int tag,
|
564
|
637
|
u.num = htonl ( strtoul ( value, &endp, 0 ) );
|
565
|
638
|
if ( *endp )
|
566
|
639
|
return -EINVAL;
|
567
|
|
- return set_setting ( settings, tag,
|
568
|
|
- &u.bytes[ sizeof ( u ) - size ], size );
|
|
640
|
+ return store_setting ( settings, tag,
|
|
641
|
+ &u.bytes[ sizeof ( u ) - size ], size );
|
569
|
642
|
}
|
570
|
643
|
|
571
|
644
|
/**
|
572
|
|
- * Parse and set value of 8-bit integer setting
|
|
645
|
+ * Parse and store value of 8-bit integer setting
|
573
|
646
|
*
|
574
|
647
|
* @v settings Settings block
|
575
|
648
|
* @v tag Setting tag number
|
|
@@ -577,13 +650,13 @@ static int setf_int ( struct settings *settings, unsigned int tag,
|
577
|
650
|
* @v size Integer size, in bytes
|
578
|
651
|
* @ret rc Return status code
|
579
|
652
|
*/
|
580
|
|
-static int setf_int8 ( struct settings *settings, unsigned int tag,
|
581
|
|
- const char *value ) {
|
582
|
|
- return setf_int ( settings, tag, value, 1 );
|
|
653
|
+static int storef_int8 ( struct settings *settings, unsigned int tag,
|
|
654
|
+ const char *value ) {
|
|
655
|
+ return storef_int ( settings, tag, value, 1 );
|
583
|
656
|
}
|
584
|
657
|
|
585
|
658
|
/**
|
586
|
|
- * Parse and set value of 16-bit integer setting
|
|
659
|
+ * Parse and store value of 16-bit integer setting
|
587
|
660
|
*
|
588
|
661
|
* @v settings Settings block
|
589
|
662
|
* @v tag Setting tag number
|
|
@@ -591,13 +664,13 @@ static int setf_int8 ( struct settings *settings, unsigned int tag,
|
591
|
664
|
* @v size Integer size, in bytes
|
592
|
665
|
* @ret rc Return status code
|
593
|
666
|
*/
|
594
|
|
-static int setf_int16 ( struct settings *settings, unsigned int tag,
|
595
|
|
- const char *value ) {
|
596
|
|
- return setf_int ( settings, tag, value, 2 );
|
|
667
|
+static int storef_int16 ( struct settings *settings, unsigned int tag,
|
|
668
|
+ const char *value ) {
|
|
669
|
+ return storef_int ( settings, tag, value, 2 );
|
597
|
670
|
}
|
598
|
671
|
|
599
|
672
|
/**
|
600
|
|
- * Parse and set value of 32-bit integer setting
|
|
673
|
+ * Parse and store value of 32-bit integer setting
|
601
|
674
|
*
|
602
|
675
|
* @v settings Settings block
|
603
|
676
|
* @v tag Setting tag number
|
|
@@ -605,13 +678,13 @@ static int setf_int16 ( struct settings *settings, unsigned int tag,
|
605
|
678
|
* @v size Integer size, in bytes
|
606
|
679
|
* @ret rc Return status code
|
607
|
680
|
*/
|
608
|
|
-static int setf_int32 ( struct settings *settings, unsigned int tag,
|
609
|
|
- const char *value ) {
|
610
|
|
- return setf_int ( settings, tag, value, 4 );
|
|
681
|
+static int storef_int32 ( struct settings *settings, unsigned int tag,
|
|
682
|
+ const char *value ) {
|
|
683
|
+ return storef_int ( settings, tag, value, 4 );
|
611
|
684
|
}
|
612
|
685
|
|
613
|
686
|
/**
|
614
|
|
- * Get and format value of signed integer setting
|
|
687
|
+ * Fetch and format value of signed integer setting
|
615
|
688
|
*
|
616
|
689
|
* @v settings Settings block, or NULL to search all blocks
|
617
|
690
|
* @v tag Setting tag number
|
|
@@ -619,18 +692,18 @@ static int setf_int32 ( struct settings *settings, unsigned int tag,
|
619
|
692
|
* @v len Length of buffer
|
620
|
693
|
* @ret len Length of formatted value, or negative error
|
621
|
694
|
*/
|
622
|
|
-static int getf_int ( struct settings *settings, unsigned int tag,
|
623
|
|
- char *buf, size_t len ) {
|
|
695
|
+static int fetchf_int ( struct settings *settings, unsigned int tag,
|
|
696
|
+ char *buf, size_t len ) {
|
624
|
697
|
long value;
|
625
|
698
|
int rc;
|
626
|
699
|
|
627
|
|
- if ( ( rc = get_int_setting ( settings, tag, &value ) ) < 0 )
|
|
700
|
+ if ( ( rc = fetch_int_setting ( settings, tag, &value ) ) < 0 )
|
628
|
701
|
return rc;
|
629
|
702
|
return snprintf ( buf, len, "%ld", value );
|
630
|
703
|
}
|
631
|
704
|
|
632
|
705
|
/**
|
633
|
|
- * Get and format value of unsigned integer setting
|
|
706
|
+ * Fetch and format value of unsigned integer setting
|
634
|
707
|
*
|
635
|
708
|
* @v settings Settings block, or NULL to search all blocks
|
636
|
709
|
* @v tag Setting tag number
|
|
@@ -638,12 +711,12 @@ static int getf_int ( struct settings *settings, unsigned int tag,
|
638
|
711
|
* @v len Length of buffer
|
639
|
712
|
* @ret len Length of formatted value, or negative error
|
640
|
713
|
*/
|
641
|
|
-static int getf_uint ( struct settings *settings, unsigned int tag,
|
642
|
|
- char *buf, size_t len ) {
|
|
714
|
+static int fetchf_uint ( struct settings *settings, unsigned int tag,
|
|
715
|
+ char *buf, size_t len ) {
|
643
|
716
|
unsigned long value;
|
644
|
717
|
int rc;
|
645
|
718
|
|
646
|
|
- if ( ( rc = get_uint_setting ( settings, tag, &value ) ) < 0 )
|
|
719
|
+ if ( ( rc = fetch_uint_setting ( settings, tag, &value ) ) < 0 )
|
647
|
720
|
return rc;
|
648
|
721
|
return snprintf ( buf, len, "%#lx", value );
|
649
|
722
|
}
|
|
@@ -651,55 +724,55 @@ static int getf_uint ( struct settings *settings, unsigned int tag,
|
651
|
724
|
/** A signed 8-bit integer setting type */
|
652
|
725
|
struct setting_type setting_type_int8 __setting_type = {
|
653
|
726
|
.name = "int8",
|
654
|
|
- .setf = setf_int8,
|
655
|
|
- .getf = getf_int,
|
|
727
|
+ .storef = storef_int8,
|
|
728
|
+ .fetchf = fetchf_int,
|
656
|
729
|
};
|
657
|
730
|
|
658
|
731
|
/** A signed 16-bit integer setting type */
|
659
|
732
|
struct setting_type setting_type_int16 __setting_type = {
|
660
|
733
|
.name = "int16",
|
661
|
|
- .setf = setf_int16,
|
662
|
|
- .getf = getf_int,
|
|
734
|
+ .storef = storef_int16,
|
|
735
|
+ .fetchf = fetchf_int,
|
663
|
736
|
};
|
664
|
737
|
|
665
|
738
|
/** A signed 32-bit integer setting type */
|
666
|
739
|
struct setting_type setting_type_int32 __setting_type = {
|
667
|
740
|
.name = "int32",
|
668
|
|
- .setf = setf_int32,
|
669
|
|
- .getf = getf_int,
|
|
741
|
+ .storef = storef_int32,
|
|
742
|
+ .fetchf = fetchf_int,
|
670
|
743
|
};
|
671
|
744
|
|
672
|
745
|
/** An unsigned 8-bit integer setting type */
|
673
|
746
|
struct setting_type setting_type_uint8 __setting_type = {
|
674
|
747
|
.name = "uint8",
|
675
|
|
- .setf = setf_int8,
|
676
|
|
- .getf = getf_uint,
|
|
748
|
+ .storef = storef_int8,
|
|
749
|
+ .fetchf = fetchf_uint,
|
677
|
750
|
};
|
678
|
751
|
|
679
|
752
|
/** An unsigned 16-bit integer setting type */
|
680
|
753
|
struct setting_type setting_type_uint16 __setting_type = {
|
681
|
754
|
.name = "uint16",
|
682
|
|
- .setf = setf_int16,
|
683
|
|
- .getf = getf_uint,
|
|
755
|
+ .storef = storef_int16,
|
|
756
|
+ .fetchf = fetchf_uint,
|
684
|
757
|
};
|
685
|
758
|
|
686
|
759
|
/** An unsigned 32-bit integer setting type */
|
687
|
760
|
struct setting_type setting_type_uint32 __setting_type = {
|
688
|
761
|
.name = "uint32",
|
689
|
|
- .setf = setf_int32,
|
690
|
|
- .getf = getf_uint,
|
|
762
|
+ .storef = storef_int32,
|
|
763
|
+ .fetchf = fetchf_uint,
|
691
|
764
|
};
|
692
|
765
|
|
693
|
766
|
/**
|
694
|
|
- * Parse and set value of hex string setting
|
|
767
|
+ * Parse and store value of hex string setting
|
695
|
768
|
*
|
696
|
769
|
* @v settings Settings block
|
697
|
770
|
* @v tag Setting tag number
|
698
|
771
|
* @v value Formatted setting data
|
699
|
772
|
* @ret rc Return status code
|
700
|
773
|
*/
|
701
|
|
-static int setf_hex ( struct settings *settings, unsigned int tag,
|
702
|
|
- const char *value ) {
|
|
774
|
+static int storef_hex ( struct settings *settings, unsigned int tag,
|
|
775
|
+ const char *value ) {
|
703
|
776
|
char *ptr = ( char * ) value;
|
704
|
777
|
uint8_t bytes[ strlen ( value ) ]; /* cannot exceed strlen(value) */
|
705
|
778
|
unsigned int len = 0;
|
|
@@ -708,7 +781,7 @@ static int setf_hex ( struct settings *settings, unsigned int tag,
|
708
|
781
|
bytes[len++] = strtoul ( ptr, &ptr, 16 );
|
709
|
782
|
switch ( *ptr ) {
|
710
|
783
|
case '\0' :
|
711
|
|
- return set_setting ( settings, tag, bytes, len );
|
|
784
|
+ return store_setting ( settings, tag, bytes, len );
|
712
|
785
|
case ':' :
|
713
|
786
|
ptr++;
|
714
|
787
|
break;
|
|
@@ -719,7 +792,7 @@ static int setf_hex ( struct settings *settings, unsigned int tag,
|
719
|
792
|
}
|
720
|
793
|
|
721
|
794
|
/**
|
722
|
|
- * Get and format value of hex string setting
|
|
795
|
+ * Fetch and format value of hex string setting
|
723
|
796
|
*
|
724
|
797
|
* @v settings Settings block, or NULL to search all blocks
|
725
|
798
|
* @v tag Setting tag number
|
|
@@ -727,21 +800,21 @@ static int setf_hex ( struct settings *settings, unsigned int tag,
|
727
|
800
|
* @v len Length of buffer
|
728
|
801
|
* @ret len Length of formatted value, or negative error
|
729
|
802
|
*/
|
730
|
|
-static int getf_hex ( struct settings *settings, unsigned int tag,
|
731
|
|
- char *buf, size_t len ) {
|
|
803
|
+static int fetchf_hex ( struct settings *settings, unsigned int tag,
|
|
804
|
+ char *buf, size_t len ) {
|
732
|
805
|
int raw_len;
|
733
|
806
|
int check_len;
|
734
|
807
|
int used = 0;
|
735
|
808
|
int i;
|
736
|
809
|
|
737
|
|
- raw_len = get_setting_len ( settings, tag );
|
|
810
|
+ raw_len = fetch_setting_len ( settings, tag );
|
738
|
811
|
if ( raw_len < 0 )
|
739
|
812
|
return raw_len;
|
740
|
813
|
|
741
|
814
|
{
|
742
|
815
|
uint8_t raw[raw_len];
|
743
|
816
|
|
744
|
|
- check_len = get_setting ( settings, tag, raw, sizeof ( raw ) );
|
|
817
|
+ check_len = fetch_setting ( settings, tag, raw, sizeof (raw) );
|
745
|
818
|
assert ( check_len == raw_len );
|
746
|
819
|
|
747
|
820
|
if ( len )
|
|
@@ -758,8 +831,8 @@ static int getf_hex ( struct settings *settings, unsigned int tag,
|
758
|
831
|
/** A hex-string setting */
|
759
|
832
|
struct setting_type setting_type_hex __setting_type = {
|
760
|
833
|
.name = "hex",
|
761
|
|
- .setf = setf_hex,
|
762
|
|
- .getf = getf_hex,
|
|
834
|
+ .storef = storef_hex,
|
|
835
|
+ .fetchf = fetchf_hex,
|
763
|
836
|
};
|
764
|
837
|
|
765
|
838
|
/******************************************************************************
|
|
@@ -773,31 +846,31 @@ struct setting_type setting_type_hex __setting_type = {
|
773
|
846
|
struct named_setting basic_named_settings[] __named_setting = {
|
774
|
847
|
{
|
775
|
848
|
.name = "ip",
|
776
|
|
- .description = "IPv4 address of this interface",
|
|
849
|
+ .description = "IPv4 address",
|
777
|
850
|
.tag = DHCP_EB_YIADDR,
|
778
|
851
|
.type = &setting_type_ipv4,
|
779
|
852
|
},
|
780
|
853
|
{
|
781
|
|
- .name = "subnet-mask",
|
|
854
|
+ .name = "netmask",
|
782
|
855
|
.description = "IPv4 subnet mask",
|
783
|
856
|
.tag = DHCP_SUBNET_MASK,
|
784
|
857
|
.type = &setting_type_ipv4,
|
785
|
858
|
},
|
786
|
859
|
{
|
787
|
|
- .name = "routers",
|
|
860
|
+ .name = "gateway",
|
788
|
861
|
.description = "Default gateway",
|
789
|
862
|
.tag = DHCP_ROUTERS,
|
790
|
863
|
.type = &setting_type_ipv4,
|
791
|
864
|
},
|
792
|
865
|
{
|
793
|
|
- .name = "domain-name-servers",
|
|
866
|
+ .name = "dns",
|
794
|
867
|
.description = "DNS server",
|
795
|
868
|
.tag = DHCP_DNS_SERVERS,
|
796
|
869
|
.type = &setting_type_ipv4,
|
797
|
870
|
},
|
798
|
871
|
{
|
799
|
872
|
.name = "hostname",
|
800
|
|
- .description = "Host name of this machine",
|
|
873
|
+ .description = "Host name",
|
801
|
874
|
.tag = DHCP_HOST_NAME,
|
802
|
875
|
.type = &setting_type_string,
|
803
|
876
|
},
|
|
@@ -815,13 +888,13 @@ struct named_setting basic_named_settings[] __named_setting = {
|
815
|
888
|
},
|
816
|
889
|
{
|
817
|
890
|
.name = "username",
|
818
|
|
- .description = "User name for authentication",
|
|
891
|
+ .description = "User name",
|
819
|
892
|
.tag = DHCP_EB_USERNAME,
|
820
|
893
|
.type = &setting_type_string,
|
821
|
894
|
},
|
822
|
895
|
{
|
823
|
896
|
.name = "password",
|
824
|
|
- .description = "Password for authentication",
|
|
897
|
+ .description = "Password",
|
825
|
898
|
.tag = DHCP_EB_PASSWORD,
|
826
|
899
|
.type = &setting_type_string,
|
827
|
900
|
},
|
|
@@ -833,7 +906,7 @@ struct named_setting basic_named_settings[] __named_setting = {
|
833
|
906
|
},
|
834
|
907
|
{
|
835
|
908
|
.name = "priority",
|
836
|
|
- .description = "Priority of these options",
|
|
909
|
+ .description = "Priority of these settings",
|
837
|
910
|
.tag = DHCP_EB_PRIORITY,
|
838
|
911
|
.type = &setting_type_int8,
|
839
|
912
|
},
|