Procházet zdrojové kódy

[uri] Support URIs containing only scheme and path components

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown před 9 roky
rodič
revize
17c1488a44
2 změnil soubory, kde provedl 33 přidání a 3 odebrání
  1. 2
    3
      src/core/uri.c
  2. 31
    0
      src/tests/uri_test.c

+ 2
- 3
src/core/uri.c Zobrazit soubor

456
  */
456
  */
457
 size_t format_uri ( const struct uri *uri, char *buf, size_t len ) {
457
 size_t format_uri ( const struct uri *uri, char *buf, size_t len ) {
458
 	static const char prefixes[URI_FIELDS] = {
458
 	static const char prefixes[URI_FIELDS] = {
459
-		[URI_OPAQUE] = ':',
460
 		[URI_PASSWORD] = ':',
459
 		[URI_PASSWORD] = ':',
461
 		[URI_PORT] = ':',
460
 		[URI_PORT] = ':',
462
 		[URI_QUERY] = '?',
461
 		[URI_QUERY] = '?',
495
 					    ( buf + used ), ( len - used ) );
494
 					    ( buf + used ), ( len - used ) );
496
 
495
 
497
 		/* Suffix this field, if applicable */
496
 		/* Suffix this field, if applicable */
498
-		if ( ( field == URI_SCHEME ) && ( ! uri->opaque ) ) {
497
+		if ( field == URI_SCHEME ) {
499
 			used += ssnprintf ( ( buf + used ), ( len - used ),
498
 			used += ssnprintf ( ( buf + used ), ( len - used ),
500
-					    "://" );
499
+					    ":%s", ( uri->host ? "//" : "" ) );
501
 		}
500
 		}
502
 	}
501
 	}
503
 
502
 

+ 31
- 0
src/tests/uri_test.c Zobrazit soubor

610
 	},
610
 	},
611
 };
611
 };
612
 
612
 
613
+/** File URI with relative (opaque) path */
614
+static struct uri_test uri_file_relative = {
615
+	"file:script.ipxe",
616
+	{
617
+		.scheme = "file",
618
+		.opaque = "script.ipxe",
619
+	},
620
+};
621
+
622
+/** File URI with absolute path */
623
+static struct uri_test uri_file_absolute = {
624
+	"file:/boot/script.ipxe",
625
+	{
626
+		.scheme = "file",
627
+		.path = "/boot/script.ipxe",
628
+	},
629
+};
630
+
631
+/** File URI with volume name */
632
+static struct uri_test uri_file_volume = {
633
+	"file://hpilo/boot/script.ipxe",
634
+	{
635
+		.scheme = "file",
636
+		.host = "hpilo",
637
+		.path = "/boot/script.ipxe",
638
+	},
639
+};
640
+
613
 /** URI with port number */
641
 /** URI with port number */
614
 static struct uri_port_test uri_explicit_port = {
642
 static struct uri_port_test uri_explicit_port = {
615
 	"http://192.168.0.1:8080/boot.php",
643
 	"http://192.168.0.1:8080/boot.php",
899
 	uri_parse_format_dup_ok ( &uri_ipv6_local );
927
 	uri_parse_format_dup_ok ( &uri_ipv6_local );
900
 	uri_parse_ok ( &uri_ipv6_local_non_conforming ); /* Parse only */
928
 	uri_parse_ok ( &uri_ipv6_local_non_conforming ); /* Parse only */
901
 	uri_parse_format_dup_ok ( &uri_iscsi );
929
 	uri_parse_format_dup_ok ( &uri_iscsi );
930
+	uri_parse_format_dup_ok ( &uri_file_relative );
931
+	uri_parse_format_dup_ok ( &uri_file_absolute );
932
+	uri_parse_format_dup_ok ( &uri_file_volume );
902
 
933
 
903
 	/** URI port number tests */
934
 	/** URI port number tests */
904
 	uri_port_ok ( &uri_explicit_port );
935
 	uri_port_ok ( &uri_explicit_port );

Načítá se…
Zrušit
Uložit