|
@@ -28,6 +28,7 @@
|
28
|
28
|
#include <gpxe/vsprintf.h>
|
29
|
29
|
#include <gpxe/dhcp.h>
|
30
|
30
|
#include <gpxe/uuid.h>
|
|
31
|
+#include <gpxe/uri.h>
|
31
|
32
|
#include <gpxe/settings.h>
|
32
|
33
|
|
33
|
34
|
/** @file
|
|
@@ -745,6 +746,58 @@ struct setting_type setting_type_string __setting_type = {
|
745
|
746
|
.fetchf = fetchf_string,
|
746
|
747
|
};
|
747
|
748
|
|
|
749
|
+/**
|
|
750
|
+ * Parse and store value of URI-encoded string setting
|
|
751
|
+ *
|
|
752
|
+ * @v settings Settings block
|
|
753
|
+ * @v setting Setting to store
|
|
754
|
+ * @v value Formatted setting data
|
|
755
|
+ * @ret rc Return status code
|
|
756
|
+ */
|
|
757
|
+static int storef_uristring ( struct settings *settings,
|
|
758
|
+ struct setting *setting,
|
|
759
|
+ const char *value ) {
|
|
760
|
+ char buf[ strlen ( value ) + 1 ]; /* Decoding never expands string */
|
|
761
|
+ size_t len;
|
|
762
|
+
|
|
763
|
+ len = uri_decode ( value, buf, sizeof ( buf ) );
|
|
764
|
+ return store_setting ( settings, setting, buf, len );
|
|
765
|
+}
|
|
766
|
+
|
|
767
|
+/**
|
|
768
|
+ * Fetch and format value of URI-encoded string setting
|
|
769
|
+ *
|
|
770
|
+ * @v settings Settings block, or NULL to search all blocks
|
|
771
|
+ * @v setting Setting to fetch
|
|
772
|
+ * @v buf Buffer to contain formatted value
|
|
773
|
+ * @v len Length of buffer
|
|
774
|
+ * @ret len Length of formatted value, or negative error
|
|
775
|
+ */
|
|
776
|
+static int fetchf_uristring ( struct settings *settings,
|
|
777
|
+ struct setting *setting,
|
|
778
|
+ char *buf, size_t len ) {
|
|
779
|
+ size_t raw_len;
|
|
780
|
+
|
|
781
|
+ /* We need to always retrieve the full raw string to know the
|
|
782
|
+ * length of the encoded string.
|
|
783
|
+ */
|
|
784
|
+ raw_len = fetch_setting ( settings, setting, NULL, 0 );
|
|
785
|
+ {
|
|
786
|
+ char raw_buf[ raw_len + 1 ];
|
|
787
|
+
|
|
788
|
+ fetch_string_setting ( settings, setting, raw_buf,
|
|
789
|
+ sizeof ( raw_buf ) );
|
|
790
|
+ return uri_encode ( raw_buf, buf, len );
|
|
791
|
+ }
|
|
792
|
+}
|
|
793
|
+
|
|
794
|
+/** A URI-encoded string setting type */
|
|
795
|
+struct setting_type setting_type_uristring __setting_type = {
|
|
796
|
+ .name = "uristring",
|
|
797
|
+ .storef = storef_uristring,
|
|
798
|
+ .fetchf = fetchf_uristring,
|
|
799
|
+};
|
|
800
|
+
|
748
|
801
|
/**
|
749
|
802
|
* Parse and store value of IPv4 address setting
|
750
|
803
|
*
|