diff options
author | Michael Brown <mcb30@ipxe.org> | 2015-08-25 12:33:40 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2015-08-25 13:31:46 +0100 |
commit | ba3695353add020b686547699ba5e259c339bfa6 (patch) | |
tree | d400084f87152adbbbc7dbca3140c1c2789c03b0 /src/core/settings.c | |
parent | 4e03af8ec2d497e725566a91fd5c19dd604c18a6 (diff) | |
download | ipxe-ba3695353add020b686547699ba5e259c339bfa6.tar.gz |
[settings] Re-add "uristring" setting type
Commit 09b057c ("[settings] Remove "uristring" setting type") removed
support for URI-encoded settings via the "uristring" setting type, on
the basis that such encoding was no longer necessary to avoid problems
with the command line parser.
Other valid use cases for the "uristring" setting type do exist: for
example, a password containing a '/' character expanded via
chain http://username:${password:uristring}@server.name/boot.php
Restore the existence of the "uristring" setting, avoiding the
potentially large stack allocations that were used in the old code
prior to commit 09b057c ("[settings] Remove "uristring" setting
type").
Requested-by: Robin Smidsrød <robin@smidsrod.no>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/settings.c')
-rw-r--r-- | src/core/settings.c | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/src/core/settings.c b/src/core/settings.c index 12e6c7d61..f6f62d226 100644 --- a/src/core/settings.c +++ b/src/core/settings.c @@ -1666,15 +1666,43 @@ const struct setting_type setting_type_string __setting_type = { .format = format_string_setting, }; -/** A URI-encoded string setting type +/** + * Parse URI-encoded string setting value * - * This setting type is obsolete; the name ":uristring" is retained to - * avoid breaking existing scripts. + * @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 */ +static int parse_uristring_setting ( const struct setting_type *type __unused, + const char *value, void *buf, size_t len ){ + + return uri_decode ( value, buf, 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 ) { + + return uri_encode ( 0, raw, raw_len, buf, len ); +} + +/** A URI-encoded string setting type */ const struct setting_type setting_type_uristring __setting_type = { .name = "uristring", - .parse = parse_string_setting, - .format = format_string_setting, + .parse = parse_uristring_setting, + .format = format_uristring_setting, }; /** |