summaryrefslogtreecommitdiffstats
path: root/src/usr
diff options
context:
space:
mode:
authorMichael Brown2013-12-03 17:48:56 +0100
committerMichael Brown2013-12-05 01:37:02 +0100
commit22001cb206c1320aee27f679a63d2171d35e99c5 (patch)
treea972bb914371a68d4925dcc007238dcb836546ba /src/usr
parent[fbcon] Add support for displaying a cursor (diff)
downloadipxe-22001cb206c1320aee27f679a63d2171d35e99c5.tar.gz
ipxe-22001cb206c1320aee27f679a63d2171d35e99c5.tar.xz
ipxe-22001cb206c1320aee27f679a63d2171d35e99c5.zip
[settings] Explicitly separate the concept of a completed fetched setting
The fetch_setting() family of functions may currently modify the definition of the specified setting (e.g. to add missing type information). Clean up this interface by requiring callers to provide an explicit buffer to contain the completed definition of the fetched setting, if required. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/usr')
-rw-r--r--src/usr/autoboot.c45
-rw-r--r--src/usr/nslookup.c2
-rw-r--r--src/usr/pxemenu.c15
3 files changed, 33 insertions, 29 deletions
diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c
index 6d6419d6..a29f8c17 100644
--- a/src/usr/autoboot.c
+++ b/src/usr/autoboot.c
@@ -59,7 +59,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#define CYAN "\033[36m"
/** The "scriptlet" setting */
-struct setting scriptlet_setting __setting ( SETTING_MISC ) = {
+const struct setting scriptlet_setting __setting ( SETTING_MISC ) = {
.name = "scriptlet",
.description = "Boot scriptlet",
.tag = DHCP_EB_SCRIPTLET,
@@ -119,7 +119,7 @@ static struct uri * parse_next_server_and_filename ( struct in_addr next_server,
}
/** The "keep-san" setting */
-struct setting keep_san_setting __setting ( SETTING_SANBOOT_EXTRA ) = {
+const struct setting keep_san_setting __setting ( SETTING_SANBOOT_EXTRA ) = {
.name = "keep-san",
.description = "Preserve SAN connection",
.tag = DHCP_EB_KEEP_SAN,
@@ -127,7 +127,7 @@ struct setting keep_san_setting __setting ( SETTING_SANBOOT_EXTRA ) = {
};
/** The "skip-san-boot" setting */
-struct setting skip_san_boot_setting __setting ( SETTING_SANBOOT_EXTRA ) = {
+const struct setting skip_san_boot_setting __setting ( SETTING_SANBOOT_EXTRA )={
.name = "skip-san-boot",
.description = "Do not boot from SAN device",
.tag = DHCP_EB_SKIP_SAN_BOOT,
@@ -256,16 +256,15 @@ struct uri * fetch_next_server_and_filename ( struct settings *settings ) {
struct uri *uri = NULL;
char *filename;
- /* Determine settings block containing the filename, if any */
- settings = fetch_setting_origin ( settings, &filename_setting );
-
- /* If we have a filename, fetch it along with next-server */
- if ( settings ) {
+ /* If we have a filename, fetch it along with the next-server
+ * setting from the same settings block.
+ */
+ if ( fetch_setting ( settings, &filename_setting, &settings,
+ NULL, NULL, 0 ) >= 0 ) {
+ fetch_string_setting_copy ( settings, &filename_setting,
+ &raw_filename );
fetch_ipv4_setting ( settings, &next_server_setting,
&next_server );
- if ( fetch_string_setting_copy ( settings, &filename_setting,
- &raw_filename ) < 0 )
- goto err_fetch;
}
/* Expand filename setting */
@@ -286,7 +285,6 @@ struct uri * fetch_next_server_and_filename ( struct settings *settings ) {
free ( filename );
err_expand:
free ( raw_filename );
- err_fetch:
return uri;
}
@@ -297,25 +295,30 @@ struct uri * fetch_next_server_and_filename ( struct settings *settings ) {
* @ret uri URI, or NULL on failure
*/
static struct uri * fetch_root_path ( struct settings *settings ) {
- char buf[256];
+ struct uri *uri = NULL;
+ char *raw_root_path;
char *root_path;
- struct uri *uri;
/* Fetch root-path setting */
- fetch_string_setting ( settings, &root_path_setting,
- buf, sizeof ( buf ) );
- if ( buf[0] )
- printf ( "Root path: %s\n", buf );
+ fetch_string_setting_copy ( settings, &root_path_setting,
+ &raw_root_path );
/* Expand filename setting */
- root_path = expand_settings ( buf );
+ root_path = expand_settings ( raw_root_path ? raw_root_path : "" );
if ( ! root_path )
- return NULL;
+ goto err_expand;
/* Parse root path */
+ if ( root_path[0] )
+ printf ( "Root path: %s\n", root_path );
uri = parse_uri ( root_path );
+ if ( ! uri )
+ goto err_parse;
+ err_parse:
free ( root_path );
+ err_expand:
+ free ( raw_root_path );
return uri;
}
@@ -331,7 +334,7 @@ static int have_pxe_menu ( void ) {
= { .tag = DHCP_PXE_DISCOVERY_CONTROL };
struct setting pxe_boot_menu_setting
= { .tag = DHCP_PXE_BOOT_MENU };
- char buf[256];
+ char buf[ 10 /* "PXEClient" + NUL */ ];
unsigned int pxe_discovery_control;
fetch_string_setting ( NULL, &vendor_class_id_setting,
diff --git a/src/usr/nslookup.c b/src/usr/nslookup.c
index b691962e..66818d11 100644
--- a/src/usr/nslookup.c
+++ b/src/usr/nslookup.c
@@ -71,7 +71,7 @@ static void nslookup_close ( struct nslookup *nslookup, int rc ) {
static void nslookup_resolv_done ( struct nslookup *nslookup,
struct sockaddr *sa ) {
struct sockaddr_in *sin;
- struct setting_type *default_type;
+ const struct setting_type *default_type;
struct settings *settings;
struct setting setting;
void *data;
diff --git a/src/usr/pxemenu.c b/src/usr/pxemenu.c
index d50ee6ba..c5cffd3d 100644
--- a/src/usr/pxemenu.c
+++ b/src/usr/pxemenu.c
@@ -101,9 +101,9 @@ static int pxe_menu_parse ( struct pxe_menu **menu ) {
/* Fetch raw menu */
memset ( raw_menu, 0, sizeof ( raw_menu ) );
- if ( ( raw_menu_len = fetch_setting ( NULL, &pxe_boot_menu_setting,
- raw_menu,
- sizeof ( raw_menu ) ) ) < 0 ) {
+ if ( ( raw_menu_len = fetch_raw_setting ( NULL, &pxe_boot_menu_setting,
+ raw_menu,
+ sizeof ( raw_menu ) ) ) < 0 ){
rc = raw_menu_len;
DBG ( "Could not retrieve raw PXE boot menu: %s\n",
strerror ( rc ) );
@@ -116,8 +116,9 @@ static int pxe_menu_parse ( struct pxe_menu **menu ) {
raw_menu_end = ( raw_menu + raw_menu_len );
/* Fetch raw prompt length */
- raw_prompt_len = fetch_setting_len ( NULL,
- &pxe_boot_menu_prompt_setting );
+ raw_prompt_len =
+ fetch_raw_setting ( NULL, &pxe_boot_menu_prompt_setting,
+ NULL, 0 );
if ( raw_prompt_len < 0 )
raw_prompt_len = 0;
@@ -168,8 +169,8 @@ static int pxe_menu_parse ( struct pxe_menu **menu ) {
if ( raw_prompt_len ) {
raw_menu_prompt = ( ( ( void * ) raw_menu_item ) +
1 /* NUL */ );
- fetch_setting ( NULL, &pxe_boot_menu_prompt_setting,
- raw_menu_prompt, raw_prompt_len );
+ fetch_raw_setting ( NULL, &pxe_boot_menu_prompt_setting,
+ raw_menu_prompt, raw_prompt_len );
(*menu)->timeout =
( ( raw_menu_prompt->timeout == 0xff ) ?
-1 : raw_menu_prompt->timeout );