summaryrefslogtreecommitdiffstats
path: root/src/core/settings.c
diff options
context:
space:
mode:
authorMichael Brown2010-11-13 01:22:23 +0100
committerMichael Brown2010-11-13 01:28:26 +0100
commit312ae024d823a199a436d3065701b621d435a5a1 (patch)
treeb03ce21e2d005a27bdcd288257fc59875fc9ee43 /src/core/settings.c
parent[bzimage] Increase maximum command-line size to 0x7ff (diff)
downloadipxe-312ae024d823a199a436d3065701b621d435a5a1.tar.gz
ipxe-312ae024d823a199a436d3065701b621d435a5a1.tar.xz
ipxe-312ae024d823a199a436d3065701b621d435a5a1.zip
[settings] Add "hexhyp" setting type
Provide a "hexhyp" setting type, which functions identically to the "hex" setting type except that it uses a hyphen instead of a colon as the byte delimiter. For example, if ${mac} expands to "52:54:00:12:34:56", then ${mac:hexhyp} will expand to "52-54-00-12-34-56". Originally-implemented-by: Jarrod Johnson <jarrod.b.johnson@gmail.com> Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/settings.c')
-rw-r--r--src/core/settings.c47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/core/settings.c b/src/core/settings.c
index 6c0733c9..8a3660ef 100644
--- a/src/core/settings.c
+++ b/src/core/settings.c
@@ -1312,6 +1312,7 @@ static int storef_hex ( struct settings *settings, struct setting *setting,
case '\0' :
return store_setting ( settings, setting, bytes, len );
case ':' :
+ case '-' :
ptr++;
break;
default :
@@ -1327,10 +1328,11 @@ static int storef_hex ( struct settings *settings, struct setting *setting,
* @v setting Setting to fetch
* @v buf Buffer to contain formatted value
* @v len Length of buffer
+ * @v delimiter Byte delimiter
* @ret len Length of formatted value, or negative error
*/
static int fetchf_hex ( struct settings *settings, struct setting *setting,
- char *buf, size_t len ) {
+ char *buf, size_t len, const char *delimiter ) {
int raw_len;
int check_len;
int used = 0;
@@ -1353,18 +1355,55 @@ static int fetchf_hex ( struct settings *settings, struct setting *setting,
buf[0] = 0; /* Ensure that a terminating NUL exists */
for ( i = 0 ; i < raw_len ; i++ ) {
used += ssnprintf ( ( buf + used ), ( len - used ),
- "%s%02x", ( used ? ":" : "" ),
+ "%s%02x", ( used ? delimiter : "" ),
raw[i] );
}
return used;
}
}
-/** A hex-string setting */
+/**
+ * Fetch and format value of hex string setting (using colon delimiter)
+ *
+ * @v settings Settings block, or NULL to search all blocks
+ * @v setting Setting to fetch
+ * @v buf Buffer to contain formatted value
+ * @v len Length of buffer
+ * @ret len Length of formatted value, or negative error
+ */
+static int fetchf_hex_colon ( struct settings *settings,
+ struct setting *setting,
+ char *buf, size_t len ) {
+ return fetchf_hex ( settings, setting, buf, len, ":" );
+}
+
+/**
+ * Fetch and format value of hex string setting (using hyphen delimiter)
+ *
+ * @v settings Settings block, or NULL to search all blocks
+ * @v setting Setting to fetch
+ * @v buf Buffer to contain formatted value
+ * @v len Length of buffer
+ * @ret len Length of formatted value, or negative error
+ */
+static int fetchf_hex_hyphen ( struct settings *settings,
+ struct setting *setting,
+ char *buf, size_t len ) {
+ return fetchf_hex ( settings, setting, buf, len, "-" );
+}
+
+/** A hex-string setting (colon-delimited) */
struct setting_type setting_type_hex __setting_type = {
.name = "hex",
.storef = storef_hex,
- .fetchf = fetchf_hex,
+ .fetchf = fetchf_hex_colon,
+};
+
+/** A hex-string setting (hyphen-delimited) */
+struct setting_type setting_type_hexhyp __setting_type = {
+ .name = "hexhyp",
+ .storef = storef_hex,
+ .fetchf = fetchf_hex_hyphen,
};
/**