]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[uri] Support URIs containing only scheme and path components
authorMichael Brown <mcb30@ipxe.org>
Sun, 13 Mar 2016 14:51:15 +0000 (14:51 +0000)
committerMichael Brown <mcb30@ipxe.org>
Sun, 13 Mar 2016 14:51:15 +0000 (14:51 +0000)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/uri.c
src/tests/uri_test.c

index aa6eedb91adb735e4152703423438e1ada77e92f..0abd8bdcd18f2d6b279f9a7bfc7f0326394e71ec 100644 (file)
@@ -456,7 +456,6 @@ unsigned int uri_port ( const struct uri *uri, unsigned int default_port ) {
  */
 size_t format_uri ( const struct uri *uri, char *buf, size_t len ) {
        static const char prefixes[URI_FIELDS] = {
-               [URI_OPAQUE] = ':',
                [URI_PASSWORD] = ':',
                [URI_PORT] = ':',
                [URI_QUERY] = '?',
@@ -495,9 +494,9 @@ size_t format_uri ( const struct uri *uri, char *buf, size_t len ) {
                                            ( buf + used ), ( len - used ) );
 
                /* Suffix this field, if applicable */
-               if ( ( field == URI_SCHEME ) && ( ! uri->opaque ) ) {
+               if ( field == URI_SCHEME ) {
                        used += ssnprintf ( ( buf + used ), ( len - used ),
-                                           "://" );
+                                           ":%s", ( uri->host ? "//" : "" ) );
                }
        }
 
index 57f211aafc6ce7150e799fe51abd781e5b432788..add6e468c4de78686b546015e286c7beae8664c9 100644 (file)
@@ -610,6 +610,34 @@ static struct uri_test uri_iscsi = {
        },
 };
 
+/** File URI with relative (opaque) path */
+static struct uri_test uri_file_relative = {
+       "file:script.ipxe",
+       {
+               .scheme = "file",
+               .opaque = "script.ipxe",
+       },
+};
+
+/** File URI with absolute path */
+static struct uri_test uri_file_absolute = {
+       "file:/boot/script.ipxe",
+       {
+               .scheme = "file",
+               .path = "/boot/script.ipxe",
+       },
+};
+
+/** File URI with volume name */
+static struct uri_test uri_file_volume = {
+       "file://hpilo/boot/script.ipxe",
+       {
+               .scheme = "file",
+               .host = "hpilo",
+               .path = "/boot/script.ipxe",
+       },
+};
+
 /** URI with port number */
 static struct uri_port_test uri_explicit_port = {
        "http://192.168.0.1:8080/boot.php",
@@ -899,6 +927,9 @@ static void uri_test_exec ( void ) {
        uri_parse_format_dup_ok ( &uri_ipv6_local );
        uri_parse_ok ( &uri_ipv6_local_non_conforming ); /* Parse only */
        uri_parse_format_dup_ok ( &uri_iscsi );
+       uri_parse_format_dup_ok ( &uri_file_relative );
+       uri_parse_format_dup_ok ( &uri_file_absolute );
+       uri_parse_format_dup_ok ( &uri_file_volume );
 
        /** URI port number tests */
        uri_port_ok ( &uri_explicit_port );