mirror of
https://github.com/xcat2/xNBA.git
synced 2024-11-26 11:19:17 +00:00
[settings] Add "hexraw" setting type
Originally-implemented-by: Jeppe Toustrup <ipxe@tenzer.dk> Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
parent
7774ceed2f
commit
9f3bbaca07
@ -1767,6 +1767,34 @@ static int format_hex_hyphen_setting ( const void *raw, size_t raw_len,
|
||||
return format_hex_setting ( raw, raw_len, buf, len, "-" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse hex string setting value (using no delimiter)
|
||||
*
|
||||
* @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_hex_raw_setting ( const char *value, void *buf,
|
||||
size_t len ) {
|
||||
return hex_decode ( value, 0, buf, len );
|
||||
}
|
||||
|
||||
/**
|
||||
* Format hex string setting value (using no delimiter)
|
||||
*
|
||||
* @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_hex_raw_setting ( const void *raw, size_t raw_len,
|
||||
char *buf, size_t len ) {
|
||||
return format_hex_setting ( raw, raw_len, buf, len, "" );
|
||||
}
|
||||
|
||||
/** A hex-string setting (colon-delimited) */
|
||||
struct setting_type setting_type_hex __setting_type = {
|
||||
.name = "hex",
|
||||
@ -1781,6 +1809,13 @@ struct setting_type setting_type_hexhyp __setting_type = {
|
||||
.format = format_hex_hyphen_setting,
|
||||
};
|
||||
|
||||
/** A hex-string setting (non-delimited) */
|
||||
struct setting_type setting_type_hexraw __setting_type = {
|
||||
.name = "hexraw",
|
||||
.parse = parse_hex_raw_setting,
|
||||
.format = format_hex_raw_setting,
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse UUID setting value
|
||||
*
|
||||
|
@ -322,6 +322,7 @@ extern struct setting_type setting_type_uint16 __setting_type;
|
||||
extern struct setting_type setting_type_uint32 __setting_type;
|
||||
extern struct setting_type setting_type_hex __setting_type;
|
||||
extern struct setting_type setting_type_hexhyp __setting_type;
|
||||
extern struct setting_type setting_type_hexraw __setting_type;
|
||||
extern struct setting_type setting_type_uuid __setting_type;
|
||||
|
||||
extern struct setting ip_setting __setting ( SETTING_IPv4 );
|
||||
|
@ -170,6 +170,12 @@ static struct setting test_hexhyp_setting = {
|
||||
.type = &setting_type_hexhyp,
|
||||
};
|
||||
|
||||
/** Test raw hex string setting type */
|
||||
static struct setting test_hexraw_setting = {
|
||||
.name = "test_hexraw",
|
||||
.type = &setting_type_hexraw,
|
||||
};
|
||||
|
||||
/** Test UUID setting type */
|
||||
static struct setting test_uuid_setting = {
|
||||
.name = "test_uuid",
|
||||
@ -262,6 +268,14 @@ static void settings_test_exec ( void ) {
|
||||
0x09, 0x6c, 0x66, 0x13, 0xc1, 0xa8, 0xec, 0x27 ),
|
||||
"9f-e5-6d-fb-24-3a-4c-bb-a9-09-6c-66-13-c1-a8-ec-27" );
|
||||
|
||||
/* "hexraw" setting type */
|
||||
storef_ok ( &test_settings, &test_hexraw_setting,
|
||||
"012345abcdef", RAW ( 0x01, 0x23, 0x45, 0xab, 0xcd, 0xef ));
|
||||
fetchf_ok ( &test_settings, &test_hexraw_setting,
|
||||
RAW ( 0x9e, 0x4b, 0x6e, 0xef, 0x36, 0xb6, 0x46, 0xfe, 0x8f,
|
||||
0x17, 0x06, 0x39, 0x6b, 0xf4, 0x48, 0x4e ),
|
||||
"9e4b6eef36b646fe8f1706396bf4484e" );
|
||||
|
||||
/* "uuid" setting type (no store capability) */
|
||||
fetchf_ok ( &test_settings, &test_uuid_setting,
|
||||
RAW ( 0x1a, 0x6a, 0x74, 0x9d, 0x0e, 0xda, 0x46, 0x1a,0xa8,
|
||||
|
Loading…
Reference in New Issue
Block a user