david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

[settings] Remove "uristring" setting type

Commit b5f5f73 ("[cmdline] Expand settings within each command-line
token individually") effectively rendered the "uristring" setting type
obsolete, since strings containing whitespace no longer break the
command line parser.  The concept of the "uristring" type is not well
defined, since URI escaping rules depend on which portion of a URI is
being escaped.

Remove the "uristring" type, converting it into an alias for the
"string" setting type so as to avoid breaking existing scripts.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2014-02-17 16:14:25 +00:00
parent ced4f8d1d3
commit 09b057ce84
2 changed files with 5 additions and 62 deletions

View File

@ -1658,59 +1658,15 @@ const struct setting_type setting_type_string __setting_type = {
.format = format_string_setting,
};
/**
* Parse URI-encoded string setting value
/** A URI-encoded string setting type
*
* @v type Setting type
* @v value Formatted setting value
* @v buf Buffer to contain raw value
* @v len Length of buffer
* @ret len Length of raw value, or negative error
* This setting type is obsolete; the name ":uristring" is retained to
* avoid breaking existing scripts.
*/
static int parse_uristring_setting ( const struct setting_type *type __unused,
const char *value, void *buf, size_t len ){
char tmp[ len + 1 /* NUL */ ];
size_t raw_len;
/* Decode to temporary buffer (including NUL) */
raw_len = uri_decode ( value, tmp, sizeof ( tmp ) );
/* Copy to output buffer (excluding NUL) */
if ( len > raw_len )
len = raw_len;
memcpy ( buf, tmp, len );
return raw_len;
}
/**
* Format URI-encoded string setting value
*
* @v type Setting type
* @v raw Raw setting value
* @v raw_len Length of raw setting value
* @v buf Buffer to contain formatted value
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
static int format_uristring_setting ( const struct setting_type *type __unused,
const void *raw, size_t raw_len,
char *buf, size_t len ) {
char tmp[ raw_len + 1 /* NUL */ ];
/* Copy to temporary buffer and terminate */
memcpy ( tmp, raw, raw_len );
tmp[raw_len] = '\0';
/* Encode directly into output buffer */
return uri_encode ( tmp, buf, len, URI_FRAGMENT );
}
/** A URI-encoded string setting type */
const struct setting_type setting_type_uristring __setting_type = {
.name = "uristring",
.parse = parse_uristring_setting,
.format = format_uristring_setting,
.parse = parse_string_setting,
.format = format_string_setting,
};
/**

View File

@ -162,12 +162,6 @@ static struct setting test_string_setting = {
.type = &setting_type_string,
};
/** Test URI-encoded string setting */
static struct setting test_uristring_setting = {
.name = "test_uristring",
.type = &setting_type_uristring,
};
/** Test IPv4 address setting type */
static struct setting test_ipv4_setting = {
.name = "test_ipv4",
@ -261,13 +255,6 @@ static void settings_test_exec ( void ) {
fetchf_ok ( &test_settings, &test_string_setting,
RAW ( 'w', 'o', 'r', 'l', 'd' ), "world" );
/* "uristring" setting type */
storef_ok ( &test_settings, &test_uristring_setting, "hello%20world",
RAW ( 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l',
'd' ) );
fetchf_ok ( &test_settings, &test_uristring_setting,
RAW ( 1, 2, 3, 4, 5 ), "%01%02%03%04%05" );
/* "ipv4" setting type */
storef_ok ( &test_settings, &test_ipv4_setting, "192.168.0.1",
RAW ( 192, 168, 0, 1 ) );