[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>
This commit is contained in:
Michael Brown
2013-12-03 16:48:56 +00:00
parent a2638a8edd
commit 22001cb206
37 changed files with 620 additions and 573 deletions

View File

@@ -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,

View File

@@ -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;

View File

@@ -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 );