mirror of https://github.com/ipxe/ipxe.git
[settings] Remove temporary name buffer parameter from parse_setting_name()
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/598/head
parent
3880ebeb18
commit
78178608e9
|
@ -1189,27 +1189,27 @@ static struct setting_type * find_setting_type ( const char *name ) {
|
||||||
* @v settings Settings block to fill in
|
* @v settings Settings block to fill in
|
||||||
* @v setting Setting to fill in
|
* @v setting Setting to fill in
|
||||||
* @v default_type Default type to use, if none specified
|
* @v default_type Default type to use, if none specified
|
||||||
* @v tmp_name Buffer for copy of setting name
|
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*
|
*
|
||||||
* Interprets a name of the form
|
* Interprets a name of the form
|
||||||
* "[settings_name/]tag_name[:type_name]" and fills in the appropriate
|
* "[settings_name/]tag_name[:type_name]" and fills in the appropriate
|
||||||
* fields.
|
* fields.
|
||||||
*
|
*
|
||||||
* The @c tmp_name buffer must be large enough to hold a copy of the
|
* Note that on success, this function will have modified the original
|
||||||
* setting name.
|
* setting @c name.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
parse_setting_name ( const char *name,
|
parse_setting_name ( char *name,
|
||||||
struct settings * ( * get_child ) ( struct settings *,
|
struct settings * ( * get_child )
|
||||||
const char * ),
|
( struct settings *settings,
|
||||||
|
const char *name ),
|
||||||
struct settings **settings, struct setting *setting,
|
struct settings **settings, struct setting *setting,
|
||||||
struct setting_type *default_type,
|
struct setting_type *default_type ) {
|
||||||
char *tmp_name ) {
|
|
||||||
char *settings_name;
|
char *settings_name;
|
||||||
char *setting_name;
|
char *setting_name;
|
||||||
char *type_name;
|
char *type_name;
|
||||||
struct setting *predefined;
|
struct setting *predefined;
|
||||||
|
int rc;
|
||||||
|
|
||||||
/* Set defaults */
|
/* Set defaults */
|
||||||
*settings = &settings_root;
|
*settings = &settings_root;
|
||||||
|
@ -1218,12 +1218,11 @@ parse_setting_name ( const char *name,
|
||||||
setting->type = default_type;
|
setting->type = default_type;
|
||||||
|
|
||||||
/* Split name into "[settings_name/]setting_name[:type_name]" */
|
/* Split name into "[settings_name/]setting_name[:type_name]" */
|
||||||
strcpy ( tmp_name, name );
|
if ( ( setting_name = strchr ( name, '/' ) ) != NULL ) {
|
||||||
if ( ( setting_name = strchr ( tmp_name, '/' ) ) != NULL ) {
|
|
||||||
*(setting_name++) = 0;
|
*(setting_name++) = 0;
|
||||||
settings_name = tmp_name;
|
settings_name = name;
|
||||||
} else {
|
} else {
|
||||||
setting_name = tmp_name;
|
setting_name = name;
|
||||||
settings_name = NULL;
|
settings_name = NULL;
|
||||||
}
|
}
|
||||||
if ( ( type_name = strchr ( setting_name, ':' ) ) != NULL )
|
if ( ( type_name = strchr ( setting_name, ':' ) ) != NULL )
|
||||||
|
@ -1235,7 +1234,8 @@ parse_setting_name ( const char *name,
|
||||||
if ( *settings == NULL ) {
|
if ( *settings == NULL ) {
|
||||||
DBG ( "Unrecognised settings block \"%s\" in \"%s\"\n",
|
DBG ( "Unrecognised settings block \"%s\" in \"%s\"\n",
|
||||||
settings_name, name );
|
settings_name, name );
|
||||||
return -ENODEV;
|
rc = -ENODEV;
|
||||||
|
goto err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1257,11 +1257,20 @@ parse_setting_name ( const char *name,
|
||||||
if ( setting->type == NULL ) {
|
if ( setting->type == NULL ) {
|
||||||
DBG ( "Invalid setting type \"%s\" in \"%s\"\n",
|
DBG ( "Invalid setting type \"%s\" in \"%s\"\n",
|
||||||
type_name, name );
|
type_name, name );
|
||||||
return -ENOTSUP;
|
rc = -ENOTSUP;
|
||||||
|
goto err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
err:
|
||||||
|
/* Restore original name */
|
||||||
|
if ( settings_name )
|
||||||
|
*( setting_name - 1 ) = '/';
|
||||||
|
if ( type_name )
|
||||||
|
*( type_name - 1 ) = ':';
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1299,10 +1308,13 @@ int store_named_setting ( const char *name, struct setting_type *default_type,
|
||||||
char tmp_name[ strlen ( name ) + 1 ];
|
char tmp_name[ strlen ( name ) + 1 ];
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
/* Create modifiable copy of setting name */
|
||||||
|
strcpy ( tmp_name, name );
|
||||||
|
|
||||||
/* Parse setting name */
|
/* Parse setting name */
|
||||||
if ( ( rc = parse_setting_name ( name, autovivify_child_settings,
|
if ( ( rc = parse_setting_name ( tmp_name, autovivify_child_settings,
|
||||||
&settings, &setting, default_type,
|
&settings, &setting,
|
||||||
tmp_name ) ) != 0 )
|
default_type ) ) != 0 )
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
/* Store setting */
|
/* Store setting */
|
||||||
|
@ -1327,10 +1339,13 @@ int storef_named_setting ( const char *name, struct setting_type *default_type,
|
||||||
char tmp_name[ strlen ( name ) + 1 ];
|
char tmp_name[ strlen ( name ) + 1 ];
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
/* Create modifiable copy of setting name */
|
||||||
|
strcpy ( tmp_name, name );
|
||||||
|
|
||||||
/* Parse setting name */
|
/* Parse setting name */
|
||||||
if ( ( rc = parse_setting_name ( name, autovivify_child_settings,
|
if ( ( rc = parse_setting_name ( tmp_name, autovivify_child_settings,
|
||||||
&settings, &setting, default_type,
|
&settings, &setting,
|
||||||
tmp_name ) ) != 0 )
|
default_type ) ) != 0 )
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
/* Store setting */
|
/* Store setting */
|
||||||
|
@ -1360,9 +1375,12 @@ int fetchf_named_setting ( const char *name,
|
||||||
int len;
|
int len;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
/* Create modifiable copy of setting name */
|
||||||
|
strcpy ( tmp_name, name );
|
||||||
|
|
||||||
/* Parse setting name */
|
/* Parse setting name */
|
||||||
if ( ( rc = parse_setting_name ( name, find_child_settings, &settings,
|
if ( ( rc = parse_setting_name ( tmp_name, find_child_settings,
|
||||||
&setting, NULL, tmp_name ) ) != 0 )
|
&settings, &setting, NULL ) ) != 0 )
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
/* Fetch setting */
|
/* Fetch setting */
|
||||||
|
|
Loading…
Reference in New Issue