mirror of https://github.com/ipxe/ipxe.git
[settings] Add parsing for UUID and GUID settings types
The ":uuid" and ":guid" settings types are currently format-only: it is possible to format a setting as a UUID (via e.g. "show foo:uuid") but it is not currently possible to parse a string into a UUID setting (via e.g. "set foo:uuid 406343fe-998b-44be-8a28-44ca38cb202b"). Use uuid_aton() to implement parsing of these settings types, and add appropriate test cases for both. Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/1165/head
parent
da7b266289
commit
0eb8fbd0bf
|
@ -2194,6 +2194,37 @@ const struct setting_type setting_type_base64 __setting_type = {
|
|||
.format = format_base64_setting,
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse UUID/GUID setting value
|
||||
*
|
||||
* @v type Setting type
|
||||
* @v value Formatted setting value
|
||||
* @v buf Buffer to contain raw value
|
||||
* @v len Length of buffer
|
||||
* @v size Integer size, in bytes
|
||||
* @ret len Length of raw value, or negative error
|
||||
*/
|
||||
static int parse_uuid_setting ( const struct setting_type *type,
|
||||
const char *value, void *buf, size_t len ) {
|
||||
union uuid uuid;
|
||||
int rc;
|
||||
|
||||
/* Parse UUID */
|
||||
if ( ( rc = uuid_aton ( value, &uuid ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
/* Mangle GUID byte ordering */
|
||||
if ( type == &setting_type_guid )
|
||||
uuid_mangle ( &uuid );
|
||||
|
||||
/* Copy value */
|
||||
if ( len > sizeof ( uuid ) )
|
||||
len = sizeof ( uuid );
|
||||
memcpy ( buf, uuid.raw, len );
|
||||
|
||||
return ( sizeof ( uuid ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Format UUID/GUID setting value
|
||||
*
|
||||
|
@ -2227,12 +2258,14 @@ static int format_uuid_setting ( const struct setting_type *type,
|
|||
/** UUID setting type */
|
||||
const struct setting_type setting_type_uuid __setting_type = {
|
||||
.name = "uuid",
|
||||
.parse = parse_uuid_setting,
|
||||
.format = format_uuid_setting,
|
||||
};
|
||||
|
||||
/** GUID setting type */
|
||||
const struct setting_type setting_type_guid __setting_type = {
|
||||
.name = "guid",
|
||||
.parse = parse_uuid_setting,
|
||||
.format = format_uuid_setting,
|
||||
};
|
||||
|
||||
|
|
|
@ -420,13 +420,21 @@ static void settings_test_exec ( void ) {
|
|||
RAW ( 0x80, 0x81, 0x82, 0x83, 0x84, 0x00, 0xff ),
|
||||
"gIGCg4QA/w==" );
|
||||
|
||||
/* "uuid" setting type (no store capability) */
|
||||
/* "uuid" setting type */
|
||||
storef_ok ( &test_settings, &test_uuid_setting,
|
||||
"36d22ed9-b64f-4fdb-941b-a54a0854f991",
|
||||
RAW ( 0x36, 0xd2, 0x2e, 0xd9, 0xb6, 0x4f, 0x4f, 0xdb, 0x94,
|
||||
0x1b, 0xa5, 0x4a, 0x08, 0x54, 0xf9, 0x91 ) );
|
||||
storef_ok ( &test_settings, &test_guid_setting,
|
||||
"7ad4478f-c270-4601-a245-78598f25a984",
|
||||
RAW ( 0x8f, 0x47, 0xd4, 0x7a, 0x70, 0xc2, 0x01, 0x46, 0xa2,
|
||||
0x45, 0x78, 0x59, 0x8f, 0x25, 0xa9, 0x84 ) );
|
||||
fetchf_ok ( &test_settings, &test_uuid_setting,
|
||||
RAW ( 0x1a, 0x6a, 0x74, 0x9d, 0x0e, 0xda, 0x46, 0x1a,0xa8,
|
||||
RAW ( 0x1a, 0x6a, 0x74, 0x9d, 0x0e, 0xda, 0x46, 0x1a, 0xa8,
|
||||
0x7a, 0x7c, 0xfe, 0x4f, 0xca, 0x4a, 0x57 ),
|
||||
"1a6a749d-0eda-461a-a87a-7cfe4fca4a57" );
|
||||
fetchf_ok ( &test_settings, &test_guid_setting,
|
||||
RAW ( 0x1a, 0x6a, 0x74, 0x9d, 0x0e, 0xda, 0x46, 0x1a,0xa8,
|
||||
RAW ( 0x1a, 0x6a, 0x74, 0x9d, 0x0e, 0xda, 0x46, 0x1a, 0xa8,
|
||||
0x7a, 0x7c, 0xfe, 0x4f, 0xca, 0x4a, 0x57 ),
|
||||
"9d746a1a-da0e-1a46-a87a-7cfe4fca4a57" );
|
||||
|
||||
|
|
Loading…
Reference in New Issue