Browse Source

[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 years ago
parent
commit
e52380fa3b
2 changed files with 34 additions and 1 deletions
  1. 30
    1
      src/core/uri.c
  2. 4
    0
      src/include/ipxe/uri.h

+ 30
- 1
src/core/uri.c View File

31
 #include <libgen.h>
31
 #include <libgen.h>
32
 #include <ctype.h>
32
 #include <ctype.h>
33
 #include <ipxe/vsprintf.h>
33
 #include <ipxe/vsprintf.h>
34
+#include <ipxe/params.h>
34
 #include <ipxe/uri.h>
35
 #include <ipxe/uri.h>
35
 
36
 
36
 /**
37
 /**
59
 		DBG ( " query \"%s\"", uri->query );
60
 		DBG ( " query \"%s\"", uri->query );
60
 	if ( uri->fragment )
61
 	if ( uri->fragment )
61
 		DBG ( " fragment \"%s\"", uri->fragment );
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
 	uri = zalloc ( sizeof ( *uri ) + raw_len );
101
 	uri = zalloc ( sizeof ( *uri ) + raw_len );
86
 	if ( ! uri )
102
 	if ( ! uri )
87
 		return NULL;
103
 		return NULL;
104
+	ref_init ( &uri->refcnt, free_uri );
88
 	raw = ( ( ( char * ) uri ) + sizeof ( *uri ) );
105
 	raw = ( ( ( char * ) uri ) + sizeof ( *uri ) );
89
 
106
 
90
 	/* Copy in the raw string */
107
 	/* Copy in the raw string */
91
 	memcpy ( raw, uri_string, raw_len );
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
 	if ( ( tmp = strchr ( raw, '#' ) ) ) {
123
 	if ( ( tmp = strchr ( raw, '#' ) ) ) {
95
 		*(tmp++) = '\0';
124
 		*(tmp++) = '\0';
96
 		uri->fragment = tmp;
125
 		uri->fragment = tmp;

+ 4
- 0
src/include/ipxe/uri.h View File

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

Loading…
Cancel
Save