瀏覽代碼

[uri] Allow URIs to incorporate a parameter list

HTTP POST requires the ability to associate a parameter list with a
URI.  There is no standardised syntax for this.  Use a non-standard
URI syntax to incorporate the specification of a parameter list within
a URI:

  URI = [ absoluteURI | relativeURI ]
	[ "#" fragment ] [ "##params" [ "=" paramsName ] ]

e.g.

  http://boot.ipxe.org/demo/boot.php##params
  http://boot.ipxe.org/demo/boot.php##params=mylist

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 年之前
父節點
當前提交
e52380fa3b
共有 2 個文件被更改,包括 34 次插入1 次删除
  1. 30
    1
      src/core/uri.c
  2. 4
    0
      src/include/ipxe/uri.h

+ 30
- 1
src/core/uri.c 查看文件

@@ -31,6 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
31 31
 #include <libgen.h>
32 32
 #include <ctype.h>
33 33
 #include <ipxe/vsprintf.h>
34
+#include <ipxe/params.h>
34 35
 #include <ipxe/uri.h>
35 36
 
36 37
 /**
@@ -59,6 +60,21 @@ static void dump_uri ( struct uri *uri ) {
59 60
 		DBG ( " query \"%s\"", uri->query );
60 61
 	if ( uri->fragment )
61 62
 		DBG ( " fragment \"%s\"", uri->fragment );
63
+	if ( uri->params )
64
+		DBG ( " params \"%s\"", uri->params->name );
65
+}
66
+
67
+/**
68
+ * Free URI
69
+ *
70
+ * @v refcnt		Reference count
71
+ */
72
+static void free_uri ( struct refcnt *refcnt ) {
73
+	struct uri *uri = container_of ( refcnt, struct uri, refcnt );
74
+
75
+	if ( uri->params )
76
+		destroy_parameters ( uri->params );
77
+	free ( uri );
62 78
 }
63 79
 
64 80
 /**
@@ -85,12 +101,25 @@ struct uri * parse_uri ( const char *uri_string ) {
85 101
 	uri = zalloc ( sizeof ( *uri ) + raw_len );
86 102
 	if ( ! uri )
87 103
 		return NULL;
104
+	ref_init ( &uri->refcnt, free_uri );
88 105
 	raw = ( ( ( char * ) uri ) + sizeof ( *uri ) );
89 106
 
90 107
 	/* Copy in the raw string */
91 108
 	memcpy ( raw, uri_string, raw_len );
92 109
 
93
-	/* Start by chopping off the fragment, if it exists */
110
+	/* Identify the parameter list, if present */
111
+	if ( ( tmp = strstr ( raw, "##params" ) ) ) {
112
+		*tmp = '\0';
113
+		tmp += 8 /* "##params" */;
114
+		uri->params = find_parameters ( *tmp ? ( tmp + 1 ) : NULL );
115
+		if ( uri->params ) {
116
+			claim_parameters ( uri->params );
117
+		} else {
118
+			/* Ignore non-existent submission blocks */
119
+		}
120
+	}
121
+
122
+	/* Chop off the fragment, if it exists */
94 123
 	if ( ( tmp = strchr ( raw, '#' ) ) ) {
95 124
 		*(tmp++) = '\0';
96 125
 		uri->fragment = tmp;

+ 4
- 0
src/include/ipxe/uri.h 查看文件

@@ -13,6 +13,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
13 13
 #include <stdlib.h>
14 14
 #include <ipxe/refcnt.h>
15 15
 
16
+struct parameters;
17
+
16 18
 /** A Uniform Resource Identifier
17 19
  *
18 20
  * Terminology for this data structure is as per uri(7), except that
@@ -65,6 +67,8 @@ struct uri {
65 67
 	const char *query;
66 68
 	/** Fragment */
67 69
 	const char *fragment;
70
+	/** Form parameters */
71
+	struct parameters *params;
68 72
 } __attribute__ (( packed ));
69 73
 
70 74
 /** A field in a URI

Loading…
取消
儲存