Browse Source

Tied NVO commands into the human-interactable settings code that I

completely forgot I'd written ages ago.
tags/v0.9.3
Michael Brown 17 years ago
parent
commit
d041d74054
3 changed files with 56 additions and 52 deletions
  1. 27
    11
      src/commandline/commands/nvo_cmd.c
  2. 25
    37
      src/core/settings.c
  3. 4
    4
      src/include/gpxe/settings.h

+ 27
- 11
src/commandline/commands/nvo_cmd.c View File

@@ -6,20 +6,37 @@
6 6
 #include <command.h>
7 7
 #include <gpxe/nvo.h>
8 8
 #include <gpxe/dhcp.h>
9
+#include <gpxe/settings.h>
9 10
 
10 11
 void nvo_cmd_req() {}
11 12
 
12 13
 extern struct nvo_block *ugly_nvo_hack;
13 14
 
14 15
 static int show_exec ( int argc, char **argv ) {
16
+	struct config_context dummy_context;
17
+	char buf[256];
18
+	int rc;
15 19
 
16 20
 	if ( ! ugly_nvo_hack ) {
17 21
 		printf ( "No non-volatile option storage available\n" );
18 22
 		return 1;
19 23
 	}
20 24
 
21
-	hex_dump ( ugly_nvo_hack->options->data,
22
-		   ugly_nvo_hack->options->len );
25
+	if ( argc != 2 ) {
26
+		printf ( "Syntax: %s <identifier>\n", argv[0] );
27
+		return 1;
28
+	}
29
+
30
+	dummy_context.options = ugly_nvo_hack->options;
31
+	if ( ( rc = show_setting ( &dummy_context, argv[1], buf,
32
+				   sizeof ( buf ) ) ) != 0 ) {
33
+		printf ( "Could not find \"%s\": %s\n",
34
+			 argv[1], strerror ( -rc ) );
35
+		return 1;
36
+	}
37
+
38
+	printf ( "%s = %s\n", argv[1], buf );
39
+	return 0;
23 40
 }
24 41
 
25 42
 struct command show_command __command = {
@@ -30,8 +47,8 @@ struct command show_command __command = {
30 47
 };
31 48
 
32 49
 static int set_exec ( int argc, char **argv ) {
33
-	unsigned long tag;
34
-	struct dhcp_option *option;
50
+	struct config_context dummy_context;
51
+	int rc;
35 52
 
36 53
 	if ( ! ugly_nvo_hack ) {
37 54
 		printf ( "No non-volatile option storage available\n" );
@@ -39,19 +56,18 @@ static int set_exec ( int argc, char **argv ) {
39 56
 	}
40 57
 
41 58
 	if ( argc != 3 ) {
42
-		printf ( "Syntax: %s <option number> <option string>\n",
59
+		printf ( "Syntax: %s <identifier> <value>\n",
43 60
 			 argv[0] );
44 61
 		return 1;
45 62
 	}
46 63
 
47
-	tag = strtoul ( argv[1], NULL, 0 );
48
-	option = set_dhcp_option ( ugly_nvo_hack->options, tag, argv[2],
49
-				   strlen ( argv[2] ) );
50
-	if ( ! option ) {
51
-		printf ( "Could not set option %ld\n", tag );
64
+	dummy_context.options = ugly_nvo_hack->options;
65
+	if ( ( rc = set_setting ( &dummy_context, argv[1], argv[2] ) ) != 0 ) {
66
+		printf ( "Could not set \"%s\"=\"%s\": %s\n",
67
+			 argv[1], argv[2], strerror ( -rc ) );
52 68
 		return 1;
53 69
 	}
54
-
70
+	
55 71
 	if ( nvo_save ( ugly_nvo_hack ) != 0 ) {
56 72
 		printf ( "Could not save options to non-volatile storage\n" );
57 73
 		return 1;

+ 25
- 37
src/core/settings.c View File

@@ -122,8 +122,8 @@ find_or_build_config_setting ( const char *name,
122 122
  * @v len		Length of buffer
123 123
  * @ret rc		Return status code
124 124
  */
125
-int ( show_setting ) ( struct config_context *context, const char *name,
126
-		       char *buf, size_t len ) {
125
+int show_setting ( struct config_context *context, const char *name,
126
+		   char *buf, size_t len ) {
127 127
 	struct config_setting *setting;
128 128
 	struct config_setting tmp_setting;
129 129
 
@@ -140,8 +140,8 @@ int ( show_setting ) ( struct config_context *context, const char *name,
140 140
  * @v value		Setting value (as a string)
141 141
  * @ret rc		Return status code
142 142
  */
143
-int ( set_setting ) ( struct config_context *context, const char *name,
144
-		      const char *value ) {
143
+int set_setting ( struct config_context *context, const char *name,
144
+		  const char *value ) {
145 145
 	struct config_setting *setting;
146 146
 	struct config_setting tmp_setting;
147 147
 
@@ -167,7 +167,7 @@ static int show_string ( struct config_context *context,
167 167
 
168 168
 	option = find_dhcp_option ( context->options, setting->tag );
169 169
 	if ( ! option )
170
-		return -ENOENT;
170
+		return -ENODATA;
171 171
 	dhcp_snprintf ( buf, len, option );
172 172
 	return 0;
173 173
 }
@@ -215,7 +215,7 @@ static int show_ipv4 ( struct config_context *context,
215 215
 
216 216
 	option = find_dhcp_option ( context->options, setting->tag );
217 217
 	if ( ! option )
218
-		return -ENOENT;
218
+		return -ENODATA;
219 219
 	dhcp_ipv4_option ( option, &ipv4 );
220 220
 	snprintf ( buf, len, inet_ntoa ( ipv4 ) );
221 221
 	return 0;
@@ -252,35 +252,23 @@ struct config_setting_type config_setting_type_ipv4 __config_setting_type = {
252 252
 };
253 253
 
254 254
 /** Some basic setting definitions */
255
-struct config_setting basic_config_settings[] __config_setting = {
256
-	{
257
-		.name = "hostname",
258
-		.tag = DHCP_HOST_NAME,
259
-		.type = &config_setting_type_string,
260
-	},
261
-	{
262
-		.name = "ip",
263
-		.tag = DHCP_EB_YIADDR,
264
-		.type = &config_setting_type_ipv4,
265
-	},
255
+struct config_setting ip_config_setting __config_setting = {
256
+	.name = "ip",
257
+	.tag = DHCP_EB_YIADDR,
258
+	.type = &config_setting_type_ipv4,
259
+};
260
+struct config_setting hostname_config_setting __config_setting = {
261
+	.name = "hostname",
262
+	.tag = DHCP_HOST_NAME,
263
+	.type = &config_setting_type_string,
264
+};
265
+struct config_setting username_config_setting __config_setting = {
266
+	.name = "username",
267
+	.tag = DHCP_EB_USERNAME,
268
+	.type = &config_setting_type_string,
269
+};
270
+struct config_setting password_config_setting __config_setting = {
271
+	.name = "password",
272
+	.tag = DHCP_EB_PASSWORD,
273
+	.type = &config_setting_type_string,
266 274
 };
267
-
268
-
269
-
270
-/* Quick and dirty proof of concept */
271
-int cmdl_show ( int argc, char **argv ) {
272
-	char buf[256];
273
-	struct config_context dummy_context = { NULL };
274
-	int rc;
275
-
276
-	if ( argc < 2 )
277
-		return -EINVAL;
278
-	
279
-	if ( ( rc = show_setting ( &dummy_context, argv[1],
280
-				   buf, sizeof ( buf ) ) ) != 0 )
281
-		return rc;
282
-
283
-	printf ( "%s = %s\n", argv[1], buf );
284
-	return 0;
285
-}
286
-

+ 4
- 4
src/include/gpxe/settings.h View File

@@ -98,9 +98,9 @@ struct config_setting {
98 98
 
99 99
 /* Function prototypes */
100 100
 
101
-extern int ( show_setting ) ( struct config_context *context, const char *name,
102
-			      char *buf, size_t len );
103
-extern int ( set_setting ) ( struct config_context *context, const char *name,
104
-			     const char *value );
101
+extern int show_setting ( struct config_context *context, const char *name,
102
+			  char *buf, size_t len );
103
+extern int set_setting ( struct config_context *context, const char *name,
104
+			 const char *value );
105 105
 
106 106
 #endif /* _GPXE_SETTINGS_H */

Loading…
Cancel
Save