Browse Source

[Settings] Add settings hierarchy

Add the notion of the settings hierarchy, complete with
register/unregister routines.

Rename set->store and get->fetch to avoid naming conflicts with get/put
as used in reference counting.
tags/v0.9.4
Michael Brown 17 years ago
parent
commit
260b93bb72
5 changed files with 321 additions and 210 deletions
  1. 227
    154
      src/core/settings.c
  2. 1
    3
      src/hci/commands/config_cmd.c
  3. 3
    2
      src/hci/commands/nvo_cmd.c
  4. 5
    5
      src/hci/tui/settings_ui.c
  5. 85
    46
      src/include/gpxe/settings.h

+ 227
- 154
src/core/settings.c View File

37
 
37
 
38
 /** Registered setting types */
38
 /** Registered setting types */
39
 static struct setting_type setting_types[0]
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
 static struct setting_type setting_types_end[0]
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
 /** Registered named settings */
44
 /** Registered named settings */
45
 static struct named_setting named_settings[0]
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
 static struct named_setting named_settings_end[0]
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
  * Obtain printable version of a settings tag number
51
  * Obtain printable version of a settings tag number
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
 // Dummy routine just for testing
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
 	       settings, setting_tag_name ( tag ) );
80
 	       settings, setting_tag_name ( tag ) );
88
 	DBGC_HD ( settings, data, len );
81
 	DBGC_HD ( settings, data, len );
89
 	return 0;
82
 	return 0;
90
 }
83
 }
91
 
84
 
92
 // Dummy routine just for testing
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
 	unsigned int i;
88
 	unsigned int i;
96
 
89
 
97
-	DBGC ( settings, "Settings %p: get %s\n",
90
+	DBGC ( settings, "Settings %p: fetch %s\n",
98
 	       settings, setting_tag_name ( tag ) );
91
 	       settings, setting_tag_name ( tag ) );
99
 	for ( i = 0 ; i < len ; i++ )
92
 	for ( i = 0 ; i < len ; i++ )
100
 		*( ( ( uint8_t * ) data ) + i ) = i;
93
 		*( ( ( uint8_t * ) data ) + i ) = i;
101
 	return ( len ? len : 8 );
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
 	.refcnt = NULL,
109
 	.refcnt = NULL,
112
 	.name = "",
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
  * @ret settings	Settings block, or NULL
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
 	struct settings *settings;
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
 			return settings;
178
 			return settings;
179
+		if ( name[len] == '.' )
180
+			return find_child_settings ( settings,
181
+						     ( name + len + 1 ) );
129
 	}
182
 	}
183
+
130
 	return NULL;
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
  * Core settings routines
204
  * Core settings routines
138
  */
207
  */
139
 
208
 
140
 /**
209
 /**
141
- * Get value of setting
210
+ * Fetch value of setting
142
  *
211
  *
143
  * @v settings		Settings block, or NULL to search all blocks
212
  * @v settings		Settings block, or NULL to search all blocks
144
  * @v tag		Setting tag number
213
  * @v tag		Setting tag number
149
  * The actual length of the setting will be returned even if
218
  * The actual length of the setting will be returned even if
150
  * the buffer was too small.
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
 	int ret;
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
  * @v settings		Settings block, or NULL to search all blocks
246
  * @v settings		Settings block, or NULL to search all blocks
172
  * @v tag		Setting tag number
247
  * @v tag		Setting tag number
175
  * This function can also be used as an existence check for the
250
  * This function can also be used as an existence check for the
176
  * setting.
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
  * @v settings		Settings block, or NULL to search all blocks
260
  * @v settings		Settings block, or NULL to search all blocks
186
  * @v tag		Setting tag number
261
  * @v tag		Setting tag number
192
  * The returned length will be the length of the underlying setting
267
  * The returned length will be the length of the underlying setting
193
  * data.
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
 	memset ( data, 0, len );
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
  * @v settings		Settings block, or NULL to search all blocks
279
  * @v settings		Settings block, or NULL to search all blocks
205
  * @v tag		Setting tag number
280
  * @v tag		Setting tag number
206
  * @v inp		IPv4 address to fill in
281
  * @v inp		IPv4 address to fill in
207
  * @ret len		Length of setting, or negative error
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
 	int len;
286
 	int len;
212
 
287
 
213
-	len = get_setting ( settings, tag, inp, sizeof ( *inp ) );
288
+	len = fetch_setting ( settings, tag, inp, sizeof ( *inp ) );
214
 	if ( len < 0 )
289
 	if ( len < 0 )
215
 		return len;
290
 		return len;
216
 	if ( len != sizeof ( *inp ) )
291
 	if ( len != sizeof ( *inp ) )
219
 }
294
 }
220
 
295
 
221
 /**
296
 /**
222
- * Get value of signed integer setting
297
+ * Fetch value of signed integer setting
223
  *
298
  *
224
  * @v settings		Settings block, or NULL to search all blocks
299
  * @v settings		Settings block, or NULL to search all blocks
225
  * @v tag		Setting tag number
300
  * @v tag		Setting tag number
226
  * @v value		Integer value to fill in
301
  * @v value		Integer value to fill in
227
  * @ret len		Length of setting, or negative error
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
 	union {
306
 	union {
232
 		long value;
307
 		long value;
233
 		uint8_t u8[ sizeof ( long ) ];
308
 		uint8_t u8[ sizeof ( long ) ];
237
 	int i;
312
 	int i;
238
 
313
 
239
 	buf.value = 0;
314
 	buf.value = 0;
240
-	len = get_setting ( settings, tag, &buf, sizeof ( buf ) );
315
+	len = fetch_setting ( settings, tag, &buf, sizeof ( buf ) );
241
 	if ( len < 0 )
316
 	if ( len < 0 )
242
 		return len;
317
 		return len;
243
 	if ( len > ( int ) sizeof ( buf ) )
318
 	if ( len > ( int ) sizeof ( buf ) )
252
 }
327
 }
253
 
328
 
254
 /**
329
 /**
255
- * Get value of unsigned integer setting
330
+ * Fetch value of unsigned integer setting
256
  *
331
  *
257
  * @v settings		Settings block, or NULL to search all blocks
332
  * @v settings		Settings block, or NULL to search all blocks
258
  * @v tag		Setting tag number
333
  * @v tag		Setting tag number
259
  * @v value		Integer value to fill in
334
  * @v value		Integer value to fill in
260
  * @ret len		Length of setting, or negative error
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
 	long svalue;
339
 	long svalue;
265
 	int len;
340
 	int len;
266
 
341
 
267
-	len = get_int_setting ( settings, tag, &svalue );
342
+	len = fetch_int_setting ( settings, tag, &svalue );
268
 	if ( len < 0 )
343
 	if ( len < 0 )
269
 		return len;
344
 		return len;
270
 
345
 
281
  */
356
  */
282
 
357
 
283
 /**
358
 /**
284
- * Set value of typed setting
359
+ * Store value of typed setting
285
  *
360
  *
286
  * @v settings		Settings block
361
  * @v settings		Settings block
287
  * @v tag		Setting tag number
362
  * @v tag		Setting tag number
289
  * @v value		Formatted setting data, or NULL
364
  * @v value		Formatted setting data, or NULL
290
  * @ret rc		Return status code
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
 	/* NULL value implies deletion.  Avoid imposing the burden of
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
 	 * method.
373
 	 * method.
299
 	 */
374
 	 */
300
 	if ( ! value )
375
 	if ( ! value )
301
 		return delete_setting ( settings, tag );
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
 
389
 
315
 	for ( setting = named_settings ; setting < named_settings_end ;
390
 	for ( setting = named_settings ; setting < named_settings_end ;
316
 	      setting++ ) {
391
 	      setting++ ) {
317
-		if ( strcasecmp ( name, setting->name ) == 0 )
392
+		if ( strcmp ( name, setting->name ) == 0 )
318
 			return setting;
393
 			return setting;
319
 	}
394
 	}
320
 	return NULL;
395
 	return NULL;
330
 	struct setting_type *type;
405
 	struct setting_type *type;
331
 
406
 
332
 	for ( type = setting_types ; type < setting_types_end ; type++ ) {
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
 			return type;
409
 			return type;
335
 	}
410
 	}
336
 	return NULL;
411
 	return NULL;
360
 	char *tmp;
435
 	char *tmp;
361
 
436
 
362
 	/* Set defaults */
437
 	/* Set defaults */
363
-	*settings = NULL;
438
+	*settings = &settings_root;
364
 	*tag = 0;
439
 	*tag = 0;
365
 	*type = &setting_type_hex;
440
 	*type = &setting_type_hex;
366
 
441
 
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
  * @v name		Name of setting
500
  * @v name		Name of setting
426
  * @v value		Formatted setting data, or NULL
501
  * @v value		Formatted setting data, or NULL
427
  * @ret rc		Return status code
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
 	struct settings *settings;
505
 	struct settings *settings;
431
 	unsigned int tag;
506
 	unsigned int tag;
432
 	struct setting_type *type;
507
 	struct setting_type *type;
435
 	if ( ( rc = parse_setting_name ( name, &settings, &tag,
510
 	if ( ( rc = parse_setting_name ( name, &settings, &tag,
436
 					 &type ) ) != 0 )
511
 					 &type ) ) != 0 )
437
 		return rc;
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
  * @v name		Name of setting
519
  * @v name		Name of setting
447
  * @v buf		Buffer to contain formatted value
520
  * @v buf		Buffer to contain formatted value
448
  * @v len		Length of buffer
521
  * @v len		Length of buffer
449
  * @ret len		Length of formatted value, or negative error
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
 	struct settings *settings;
525
 	struct settings *settings;
453
 	unsigned int tag;
526
 	unsigned int tag;
454
 	struct setting_type *type;
527
 	struct setting_type *type;
457
 	if ( ( rc = parse_setting_name ( name, &settings, &tag,
530
 	if ( ( rc = parse_setting_name ( name, &settings, &tag,
458
 					 &type ) ) != 0 )
531
 					 &type ) ) != 0 )
459
 		return rc;
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
  */
541
  */
469
 
542
 
470
 /**
543
 /**
471
- * Parse and set value of string setting
544
+ * Parse and store value of string setting
472
  *
545
  *
473
  * @v settings		Settings block
546
  * @v settings		Settings block
474
  * @v tag		Setting tag number
547
  * @v tag		Setting tag number
475
  * @v value		Formatted setting data
548
  * @v value		Formatted setting data
476
  * @ret rc		Return status code
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
  * @v settings		Settings block, or NULL to search all blocks
559
  * @v settings		Settings block, or NULL to search all blocks
487
  * @v tag		Setting tag number
560
  * @v tag		Setting tag number
489
  * @v len		Length of buffer
562
  * @v len		Length of buffer
490
  * @ret len		Length of formatted value, or negative error
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
 /** A string setting type */
570
 /** A string setting type */
498
 struct setting_type setting_type_string __setting_type = {
571
 struct setting_type setting_type_string __setting_type = {
499
 	.name = "string",
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
  * @v settings		Settings block
580
  * @v settings		Settings block
508
  * @v tag		Setting tag number
581
  * @v tag		Setting tag number
509
  * @v value		Formatted setting data
582
  * @v value		Formatted setting data
510
  * @ret rc		Return status code
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
 	struct in_addr ipv4;
587
 	struct in_addr ipv4;
515
 
588
 
516
 	if ( inet_aton ( value, &ipv4 ) == 0 )
589
 	if ( inet_aton ( value, &ipv4 ) == 0 )
517
 		return -EINVAL;
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
  * @v settings		Settings block, or NULL to search all blocks
597
  * @v settings		Settings block, or NULL to search all blocks
525
  * @v tag		Setting tag number
598
  * @v tag		Setting tag number
527
  * @v len		Length of buffer
600
  * @v len		Length of buffer
528
  * @ret len		Length of formatted value, or negative error
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
 	struct in_addr ipv4;
605
 	struct in_addr ipv4;
533
 	int rc;
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
 		return rc;
609
 		return rc;
537
 	return snprintf ( buf, len, inet_ntoa ( ipv4 ) );
610
 	return snprintf ( buf, len, inet_ntoa ( ipv4 ) );
538
 }
611
 }
540
 /** An IPv4 address setting type */
613
 /** An IPv4 address setting type */
541
 struct setting_type setting_type_ipv4 __setting_type = {
614
 struct setting_type setting_type_ipv4 __setting_type = {
542
 	.name = "ipv4",
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
  * @v settings		Settings block
623
  * @v settings		Settings block
551
  * @v tag		Setting tag number
624
  * @v tag		Setting tag number
553
  * @v size		Integer size, in bytes
626
  * @v size		Integer size, in bytes
554
  * @ret rc		Return status code
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
 	union {
631
 	union {
559
 		uint32_t num;
632
 		uint32_t num;
560
 		uint8_t bytes[4];
633
 		uint8_t bytes[4];
564
 	u.num = htonl ( strtoul ( value, &endp, 0 ) );
637
 	u.num = htonl ( strtoul ( value, &endp, 0 ) );
565
 	if ( *endp )
638
 	if ( *endp )
566
 		return -EINVAL;
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
  * @v settings		Settings block
647
  * @v settings		Settings block
575
  * @v tag		Setting tag number
648
  * @v tag		Setting tag number
577
  * @v size		Integer size, in bytes
650
  * @v size		Integer size, in bytes
578
  * @ret rc		Return status code
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
  * @v settings		Settings block
661
  * @v settings		Settings block
589
  * @v tag		Setting tag number
662
  * @v tag		Setting tag number
591
  * @v size		Integer size, in bytes
664
  * @v size		Integer size, in bytes
592
  * @ret rc		Return status code
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
  * @v settings		Settings block
675
  * @v settings		Settings block
603
  * @v tag		Setting tag number
676
  * @v tag		Setting tag number
605
  * @v size		Integer size, in bytes
678
  * @v size		Integer size, in bytes
606
  * @ret rc		Return status code
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
  * @v settings		Settings block, or NULL to search all blocks
689
  * @v settings		Settings block, or NULL to search all blocks
617
  * @v tag		Setting tag number
690
  * @v tag		Setting tag number
619
  * @v len		Length of buffer
692
  * @v len		Length of buffer
620
  * @ret len		Length of formatted value, or negative error
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
 	long value;
697
 	long value;
625
 	int rc;
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
 		return rc;
701
 		return rc;
629
 	return snprintf ( buf, len, "%ld", value );
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
  * @v settings		Settings block, or NULL to search all blocks
708
  * @v settings		Settings block, or NULL to search all blocks
636
  * @v tag		Setting tag number
709
  * @v tag		Setting tag number
638
  * @v len		Length of buffer
711
  * @v len		Length of buffer
639
  * @ret len		Length of formatted value, or negative error
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
 	unsigned long value;
716
 	unsigned long value;
644
 	int rc;
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
 		return rc;
720
 		return rc;
648
 	return snprintf ( buf, len, "%#lx", value );
721
 	return snprintf ( buf, len, "%#lx", value );
649
 }
722
 }
651
 /** A signed 8-bit integer setting type */
724
 /** A signed 8-bit integer setting type */
652
 struct setting_type setting_type_int8 __setting_type = {
725
 struct setting_type setting_type_int8 __setting_type = {
653
 	.name = "int8",
726
 	.name = "int8",
654
-	.setf = setf_int8,
655
-	.getf = getf_int,
727
+	.storef = storef_int8,
728
+	.fetchf = fetchf_int,
656
 };
729
 };
657
 
730
 
658
 /** A signed 16-bit integer setting type */
731
 /** A signed 16-bit integer setting type */
659
 struct setting_type setting_type_int16 __setting_type = {
732
 struct setting_type setting_type_int16 __setting_type = {
660
 	.name = "int16",
733
 	.name = "int16",
661
-	.setf = setf_int16,
662
-	.getf = getf_int,
734
+	.storef = storef_int16,
735
+	.fetchf = fetchf_int,
663
 };
736
 };
664
 
737
 
665
 /** A signed 32-bit integer setting type */
738
 /** A signed 32-bit integer setting type */
666
 struct setting_type setting_type_int32 __setting_type = {
739
 struct setting_type setting_type_int32 __setting_type = {
667
 	.name = "int32",
740
 	.name = "int32",
668
-	.setf = setf_int32,
669
-	.getf = getf_int,
741
+	.storef = storef_int32,
742
+	.fetchf = fetchf_int,
670
 };
743
 };
671
 
744
 
672
 /** An unsigned 8-bit integer setting type */
745
 /** An unsigned 8-bit integer setting type */
673
 struct setting_type setting_type_uint8 __setting_type = {
746
 struct setting_type setting_type_uint8 __setting_type = {
674
 	.name = "uint8",
747
 	.name = "uint8",
675
-	.setf = setf_int8,
676
-	.getf = getf_uint,
748
+	.storef = storef_int8,
749
+	.fetchf = fetchf_uint,
677
 };
750
 };
678
 
751
 
679
 /** An unsigned 16-bit integer setting type */
752
 /** An unsigned 16-bit integer setting type */
680
 struct setting_type setting_type_uint16 __setting_type = {
753
 struct setting_type setting_type_uint16 __setting_type = {
681
 	.name = "uint16",
754
 	.name = "uint16",
682
-	.setf = setf_int16,
683
-	.getf = getf_uint,
755
+	.storef = storef_int16,
756
+	.fetchf = fetchf_uint,
684
 };
757
 };
685
 
758
 
686
 /** An unsigned 32-bit integer setting type */
759
 /** An unsigned 32-bit integer setting type */
687
 struct setting_type setting_type_uint32 __setting_type = {
760
 struct setting_type setting_type_uint32 __setting_type = {
688
 	.name = "uint32",
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
  * @v settings		Settings block
769
  * @v settings		Settings block
697
  * @v tag		Setting tag number
770
  * @v tag		Setting tag number
698
  * @v value		Formatted setting data
771
  * @v value		Formatted setting data
699
  * @ret rc		Return status code
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
 	char *ptr = ( char * ) value;
776
 	char *ptr = ( char * ) value;
704
 	uint8_t bytes[ strlen ( value ) ]; /* cannot exceed strlen(value) */
777
 	uint8_t bytes[ strlen ( value ) ]; /* cannot exceed strlen(value) */
705
 	unsigned int len = 0;
778
 	unsigned int len = 0;
708
 		bytes[len++] = strtoul ( ptr, &ptr, 16 );
781
 		bytes[len++] = strtoul ( ptr, &ptr, 16 );
709
 		switch ( *ptr ) {
782
 		switch ( *ptr ) {
710
 		case '\0' :
783
 		case '\0' :
711
-			return set_setting ( settings, tag, bytes, len );
784
+			return store_setting ( settings, tag, bytes, len );
712
 		case ':' :
785
 		case ':' :
713
 			ptr++;
786
 			ptr++;
714
 			break;
787
 			break;
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
  * @v settings		Settings block, or NULL to search all blocks
797
  * @v settings		Settings block, or NULL to search all blocks
725
  * @v tag		Setting tag number
798
  * @v tag		Setting tag number
727
  * @v len		Length of buffer
800
  * @v len		Length of buffer
728
  * @ret len		Length of formatted value, or negative error
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
 	int raw_len;
805
 	int raw_len;
733
 	int check_len;
806
 	int check_len;
734
 	int used = 0;
807
 	int used = 0;
735
 	int i;
808
 	int i;
736
 
809
 
737
-	raw_len = get_setting_len ( settings, tag );
810
+	raw_len = fetch_setting_len ( settings, tag );
738
 	if ( raw_len < 0 )
811
 	if ( raw_len < 0 )
739
 		return raw_len;
812
 		return raw_len;
740
 
813
 
741
 	{
814
 	{
742
 		uint8_t raw[raw_len];
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
 		assert ( check_len == raw_len );
818
 		assert ( check_len == raw_len );
746
 		
819
 		
747
 		if ( len )
820
 		if ( len )
758
 /** A hex-string setting */
831
 /** A hex-string setting */
759
 struct setting_type setting_type_hex __setting_type = {
832
 struct setting_type setting_type_hex __setting_type = {
760
 	.name = "hex",
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
 struct named_setting basic_named_settings[] __named_setting = {
846
 struct named_setting basic_named_settings[] __named_setting = {
774
 	{
847
 	{
775
 		.name = "ip",
848
 		.name = "ip",
776
-		.description = "IPv4 address of this interface",
849
+		.description = "IPv4 address",
777
 		.tag = DHCP_EB_YIADDR,
850
 		.tag = DHCP_EB_YIADDR,
778
 		.type = &setting_type_ipv4,
851
 		.type = &setting_type_ipv4,
779
 	},
852
 	},
780
 	{
853
 	{
781
-		.name = "subnet-mask",
854
+		.name = "netmask",
782
 		.description = "IPv4 subnet mask",
855
 		.description = "IPv4 subnet mask",
783
 		.tag = DHCP_SUBNET_MASK,
856
 		.tag = DHCP_SUBNET_MASK,
784
 		.type = &setting_type_ipv4,
857
 		.type = &setting_type_ipv4,
785
 	},
858
 	},
786
 	{
859
 	{
787
-		.name = "routers",
860
+		.name = "gateway",
788
 		.description = "Default gateway",
861
 		.description = "Default gateway",
789
 		.tag = DHCP_ROUTERS,
862
 		.tag = DHCP_ROUTERS,
790
 		.type = &setting_type_ipv4,
863
 		.type = &setting_type_ipv4,
791
 	},
864
 	},
792
 	{
865
 	{
793
-		.name = "domain-name-servers",
866
+		.name = "dns",
794
 		.description = "DNS server",
867
 		.description = "DNS server",
795
 		.tag = DHCP_DNS_SERVERS,
868
 		.tag = DHCP_DNS_SERVERS,
796
 		.type = &setting_type_ipv4,
869
 		.type = &setting_type_ipv4,
797
 	},
870
 	},
798
 	{
871
 	{
799
 		.name = "hostname",
872
 		.name = "hostname",
800
-		.description = "Host name of this machine",
873
+		.description = "Host name",
801
 		.tag = DHCP_HOST_NAME,
874
 		.tag = DHCP_HOST_NAME,
802
 		.type = &setting_type_string,
875
 		.type = &setting_type_string,
803
 	},
876
 	},
815
 	},
888
 	},
816
 	{
889
 	{
817
 		.name = "username",
890
 		.name = "username",
818
-		.description = "User name for authentication",
891
+		.description = "User name",
819
 		.tag = DHCP_EB_USERNAME,
892
 		.tag = DHCP_EB_USERNAME,
820
 		.type = &setting_type_string,
893
 		.type = &setting_type_string,
821
 	},
894
 	},
822
 	{
895
 	{
823
 		.name = "password",
896
 		.name = "password",
824
-		.description = "Password for authentication",
897
+		.description = "Password",
825
 		.tag = DHCP_EB_PASSWORD,
898
 		.tag = DHCP_EB_PASSWORD,
826
 		.type = &setting_type_string,
899
 		.type = &setting_type_string,
827
 	},
900
 	},
833
 	},
906
 	},
834
 	{
907
 	{
835
 		.name = "priority",
908
 		.name = "priority",
836
-		.description = "Priority of these options",
909
+		.description = "Priority of these settings",
837
 		.tag = DHCP_EB_PRIORITY,
910
 		.tag = DHCP_EB_PRIORITY,
838
 		.type = &setting_type_int8,
911
 		.type = &setting_type_int8,
839
 	},
912
 	},

+ 1
- 3
src/hci/commands/config_cmd.c View File

5
 #include <gpxe/settings_ui.h>
5
 #include <gpxe/settings_ui.h>
6
 
6
 
7
 static int config_exec ( int argc, char **argv ) {
7
 static int config_exec ( int argc, char **argv ) {
8
-	struct settings *settings;
8
+	struct settings *settings = NULL;
9
 	int rc;
9
 	int rc;
10
 
10
 
11
 	if ( argc > 2 ) {
11
 	if ( argc > 2 ) {
20
 			printf ( "No such scope \"%s\"\n", argv[1] );
20
 			printf ( "No such scope \"%s\"\n", argv[1] );
21
 			return 1;
21
 			return 1;
22
 		}
22
 		}
23
-	} else {
24
-		settings = &interactive_settings;
25
 	}
23
 	}
26
 
24
 
27
 	if ( ( rc = settings_ui ( settings ) ) != 0 ) {
25
 	if ( ( rc = settings_ui ( settings ) ) != 0 ) {

+ 3
- 2
src/hci/commands/nvo_cmd.c View File

16
 		return 1;
16
 		return 1;
17
 	}
17
 	}
18
 
18
 
19
-	if ( ( rc = get_named_setting ( argv[1], buf, sizeof ( buf ) ) ) < 0 ){
19
+	if ( ( rc = fetch_named_setting ( argv[1], buf,
20
+					  sizeof ( buf ) ) ) < 0 ){
20
 		printf ( "Could not find \"%s\": %s\n",
21
 		printf ( "Could not find \"%s\": %s\n",
21
 			 argv[1], strerror ( rc ) );
22
 			 argv[1], strerror ( rc ) );
22
 		return 1;
23
 		return 1;
34
 		return 1;
35
 		return 1;
35
 	}
36
 	}
36
 
37
 
37
-	if ( ( rc = set_named_setting ( argv[1], argv[2] ) ) != 0 ) {
38
+	if ( ( rc = store_named_setting ( argv[1], argv[2] ) ) != 0 ) {
38
 		printf ( "Could not set \"%s\"=\"%s\": %s\n",
39
 		printf ( "Could not set \"%s\"=\"%s\": %s\n",
39
 			 argv[1], argv[2], strerror ( rc ) );
40
 			 argv[1], argv[2], strerror ( rc ) );
40
 		return 1;
41
 		return 1;

+ 5
- 5
src/hci/tui/settings_ui.c View File

114
 	widget->editing = 0;
114
 	widget->editing = 0;
115
 
115
 
116
 	/* Read current setting value */
116
 	/* Read current setting value */
117
-	if ( get_typed_setting ( widget->settings, widget->setting->tag,
118
-				 widget->setting->type, widget->value,
119
-				 sizeof ( widget->value ) ) < 0 ) {
117
+	if ( fetch_typed_setting ( widget->settings, widget->setting->tag,
118
+				   widget->setting->type, widget->value,
119
+				   sizeof ( widget->value ) ) < 0 ) {
120
 		widget->value[0] = '\0';
120
 		widget->value[0] = '\0';
121
 	}	
121
 	}	
122
 
122
 
133
  * @v widget		Setting widget
133
  * @v widget		Setting widget
134
  */
134
  */
135
 static int save_setting ( struct setting_widget *widget ) {
135
 static int save_setting ( struct setting_widget *widget ) {
136
-	return set_typed_setting ( widget->settings, widget->setting->tag,
137
-				   widget->setting->type, widget->value );
136
+	return store_typed_setting ( widget->settings, widget->setting->tag,
137
+				     widget->setting->type, widget->value );
138
 }
138
 }
139
 
139
 
140
 /**
140
 /**

+ 85
- 46
src/include/gpxe/settings.h View File

25
 	 * @v len		Length of setting data
25
 	 * @v len		Length of setting data
26
 	 * @ret rc		Return status code
26
 	 * @ret rc		Return status code
27
 	 */
27
 	 */
28
-	int ( * set ) ( struct settings *settings, unsigned int tag,
29
-			const void *data, size_t len );
30
-	/** Get value of setting
28
+	int ( * store ) ( struct settings *settings, unsigned int tag,
29
+			  const void *data, size_t len );
30
+	/** Fetch value of setting
31
 	 *
31
 	 *
32
 	 * @v settings		Settings block
32
 	 * @v settings		Settings block
33
 	 * @v tag		Setting tag number
33
 	 * @v tag		Setting tag number
38
 	 * The actual length of the setting will be returned even if
38
 	 * The actual length of the setting will be returned even if
39
 	 * the buffer was too small.
39
 	 * the buffer was too small.
40
 	 */
40
 	 */
41
-	int ( * get ) ( struct settings *settings, unsigned int tag,
42
-			void *data, size_t len );
41
+	int ( * fetch ) ( struct settings *settings, unsigned int tag,
42
+			  void *data, size_t len );
43
 };
43
 };
44
 
44
 
45
 /** A settings block */
45
 /** A settings block */
47
 	/** Reference counter */
47
 	/** Reference counter */
48
 	struct refcnt *refcnt;
48
 	struct refcnt *refcnt;
49
 	/** Name */
49
 	/** Name */
50
-	char name[16];
51
-	/** List of all settings */
52
-	struct list_head list;
50
+	const char *name;
51
+	/** Parent settings block */
52
+	struct settings *parent;
53
+	/** Sibling settings blocks */
54
+	struct list_head siblings;
55
+	/** Child settings blocks */
56
+	struct list_head children;
53
 	/** Settings block operations */
57
 	/** Settings block operations */
54
 	struct settings_operations *op;
58
 	struct settings_operations *op;
55
 };
59
 };
73
 	 * @v value		Formatted setting data
77
 	 * @v value		Formatted setting data
74
 	 * @ret rc		Return status code
78
 	 * @ret rc		Return status code
75
 	 */
79
 	 */
76
-	int ( * setf ) ( struct settings *settings, unsigned int tag,
77
-			 const char *value );
78
-	/** Get and format value of setting
80
+	int ( * storef ) ( struct settings *settings, unsigned int tag,
81
+			   const char *value );
82
+	/** Fetch and format value of setting
79
 	 *
83
 	 *
80
 	 * @v settings		Settings block, or NULL to search all blocks
84
 	 * @v settings		Settings block, or NULL to search all blocks
81
 	 * @v tag		Setting tag number
85
 	 * @v tag		Setting tag number
83
 	 * @v len		Length of buffer
87
 	 * @v len		Length of buffer
84
 	 * @ret len		Length of formatted value, or negative error
88
 	 * @ret len		Length of formatted value, or negative error
85
 	 */
89
 	 */
86
-	int ( * getf ) ( struct settings *settings, unsigned int tag,
87
-			 char *buf, size_t len );
90
+	int ( * fetchf ) ( struct settings *settings, unsigned int tag,
91
+			   char *buf, size_t len );
88
 };
92
 };
89
 
93
 
90
 /** Declare a configuration setting type */
94
 /** Declare a configuration setting type */
100
 struct named_setting {
104
 struct named_setting {
101
 	/** Name
105
 	/** Name
102
 	 *
106
 	 *
103
-	 * This is the human-readable name for the setting.  Where
104
-	 * possible, it should match the name used in dhcpd.conf (see
105
-	 * dhcp-options(5)).
107
+	 * This is the human-readable name for the setting.
106
 	 */
108
 	 */
107
 	const char *name;
109
 	const char *name;
108
 	/** Description */
110
 	/** Description */
120
 /** Declare a configuration setting */
122
 /** Declare a configuration setting */
121
 #define	__named_setting __table ( struct named_setting, named_settings, 01 )
123
 #define	__named_setting __table ( struct named_setting, named_settings, 01 )
122
 
124
 
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 );
125
+extern int simple_settings_store ( struct settings *settings, unsigned int tag,
126
+				   const void *data, size_t len );
127
+extern int simple_settings_fetch ( struct settings *settings, unsigned int tag,
128
+				   void *data, size_t len );
129
+extern struct settings_operations simple_settings_operations;
130
+
131
+extern int register_settings ( struct settings *settings,
132
+			       struct settings *parent );
133
+extern void unregister_settings ( struct settings *settings );
134
+extern int fetch_setting ( struct settings *settings, unsigned int tag,
135
+			   void *data, size_t len );
136
+extern int fetch_setting_len ( struct settings *settings, unsigned int tag );
137
+extern int fetch_string_setting ( struct settings *settings, unsigned int tag,
138
+				  char *data, size_t len );
139
+extern int fetch_ipv4_setting ( struct settings *settings, unsigned int tag,
140
+				struct in_addr *inp );
141
+extern int fetch_int_setting ( struct settings *settings, unsigned int tag,
142
+			       long *value );
143
+extern int fetch_uint_setting ( struct settings *settings, unsigned int tag,
144
+				unsigned long *value );
136
 extern struct settings * find_settings ( const char *name );
145
 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 );
146
+extern int store_typed_setting ( struct settings *settings,
147
+				 unsigned int tag, struct setting_type *type,
148
+				 const char *value );
149
+extern int store_named_setting ( const char *name, const char *value );
150
+extern int fetch_named_setting ( const char *name, char *buf, size_t len );
151
+
152
+extern struct setting_type setting_type_ __setting_type;
153
+extern struct setting_type setting_type_string __setting_type;
154
+extern struct setting_type setting_type_ipv4 __setting_type;
155
+extern struct setting_type setting_type_int8 __setting_type;
156
+extern struct setting_type setting_type_int16 __setting_type;
157
+extern struct setting_type setting_type_int32 __setting_type;
158
+extern struct setting_type setting_type_uint8 __setting_type;
159
+extern struct setting_type setting_type_uint16 __setting_type;
160
+extern struct setting_type setting_type_uint32 __setting_type;
161
+extern struct setting_type setting_type_hex __setting_type;
162
+
163
+/**
164
+ * Initialise a settings block
165
+ *
166
+ * @v settings		Settings block
167
+ * @v op		Settings block operations
168
+ * @v refcnt		Containing object reference counter, or NULL
169
+ * @v name		Settings block name
170
+ */
171
+static inline void settings_init ( struct settings *settings,
172
+				   struct settings_operations *op,
173
+				   struct refcnt *refcnt,
174
+				   const char *name ) {
175
+	INIT_LIST_HEAD ( &settings->siblings );
176
+	INIT_LIST_HEAD ( &settings->children );
177
+	settings->op = op;
178
+	settings->refcnt = refcnt;
179
+	settings->name = name;
180
+}
142
 
181
 
143
 /**
182
 /**
144
- * Set value of setting
183
+ * Store value of setting
145
  *
184
  *
146
  * @v settings		Settings block
185
  * @v settings		Settings block
147
  * @v tag		Setting tag number
186
  * @v tag		Setting tag number
149
  * @v len		Length of setting data
188
  * @v len		Length of setting data
150
  * @ret rc		Return status code
189
  * @ret rc		Return status code
151
  */
190
  */
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 );
191
+static inline int store_setting ( struct settings *settings, unsigned int tag,
192
+				  const void *data, size_t len ) {
193
+	return settings->op->store ( settings, tag, data, len );
155
 }
194
 }
156
 
195
 
157
 /**
196
 /**
163
  */
202
  */
164
 static inline int delete_setting ( struct settings *settings,
203
 static inline int delete_setting ( struct settings *settings,
165
 				   unsigned int tag ) {
204
 				   unsigned int tag ) {
166
-	return set_setting ( settings, tag, NULL, 0 );
205
+	return store_setting ( settings, tag, NULL, 0 );
167
 }
206
 }
168
 
207
 
169
 /**
208
 /**
170
- * Get and format value of setting
209
+ * Fetch and format value of setting
171
  *
210
  *
172
  * @v settings		Settings block, or NULL to search all blocks
211
  * @v settings		Settings block, or NULL to search all blocks
173
  * @v tag		Setting tag number
212
  * @v tag		Setting tag number
176
  * @v len		Length of buffer
215
  * @v len		Length of buffer
177
  * @ret len		Length of formatted value, or negative error
216
  * @ret len		Length of formatted value, or negative error
178
  */
217
  */
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 );
218
+static inline int fetch_typed_setting ( struct settings *settings,
219
+					unsigned int tag,
220
+					struct setting_type *type,
221
+					char *buf, size_t len ) {
222
+	return type->fetchf ( settings, tag, buf, len );
184
 }
223
 }
185
 
224
 
186
 /**
225
 /**
190
  * @ret rc		Return status code
229
  * @ret rc		Return status code
191
  */
230
  */
192
 static inline int delete_named_setting ( const char *name ) {
231
 static inline int delete_named_setting ( const char *name ) {
193
-	return set_named_setting ( name, NULL );
232
+	return store_named_setting ( name, NULL );
194
 }
233
 }
195
 
234
 
196
 #endif /* _GPXE_SETTINGS_H */
235
 #endif /* _GPXE_SETTINGS_H */

Loading…
Cancel
Save