]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[uri] Allow URIs to incorporate a parameter list
authorMichael Brown <mcb30@ipxe.org>
Wed, 14 Aug 2013 14:07:52 +0000 (15:07 +0100)
committerMichael Brown <mcb30@ipxe.org>
Mon, 19 Aug 2013 16:22:58 +0000 (17:22 +0100)
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>
src/core/uri.c
src/include/ipxe/uri.h

index e952688262f78304c6ea4af7c25b8f568940c471..bc55e4d8c68beaedb25d01f959ab3b6ea0d00949 100644 (file)
@@ -31,6 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <libgen.h>
 #include <ctype.h>
 #include <ipxe/vsprintf.h>
+#include <ipxe/params.h>
 #include <ipxe/uri.h>
 
 /**
@@ -59,6 +60,21 @@ static void dump_uri ( struct uri *uri ) {
                DBG ( " query \"%s\"", uri->query );
        if ( uri->fragment )
                DBG ( " fragment \"%s\"", uri->fragment );
+       if ( uri->params )
+               DBG ( " params \"%s\"", uri->params->name );
+}
+
+/**
+ * Free URI
+ *
+ * @v refcnt           Reference count
+ */
+static void free_uri ( struct refcnt *refcnt ) {
+       struct uri *uri = container_of ( refcnt, struct uri, refcnt );
+
+       if ( uri->params )
+               destroy_parameters ( uri->params );
+       free ( uri );
 }
 
 /**
@@ -85,12 +101,25 @@ struct uri * parse_uri ( const char *uri_string ) {
        uri = zalloc ( sizeof ( *uri ) + raw_len );
        if ( ! uri )
                return NULL;
+       ref_init ( &uri->refcnt, free_uri );
        raw = ( ( ( char * ) uri ) + sizeof ( *uri ) );
 
        /* Copy in the raw string */
        memcpy ( raw, uri_string, raw_len );
 
-       /* Start by chopping off the fragment, if it exists */
+       /* Identify the parameter list, if present */
+       if ( ( tmp = strstr ( raw, "##params" ) ) ) {
+               *tmp = '\0';
+               tmp += 8 /* "##params" */;
+               uri->params = find_parameters ( *tmp ? ( tmp + 1 ) : NULL );
+               if ( uri->params ) {
+                       claim_parameters ( uri->params );
+               } else {
+                       /* Ignore non-existent submission blocks */
+               }
+       }
+
+       /* Chop off the fragment, if it exists */
        if ( ( tmp = strchr ( raw, '#' ) ) ) {
                *(tmp++) = '\0';
                uri->fragment = tmp;
index 9a134690f074d888e87fde6f534a2ea524ebe79a..a9ec4555025bc2014dfffe170cefac5d14e3f39c 100644 (file)
@@ -13,6 +13,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <stdlib.h>
 #include <ipxe/refcnt.h>
 
+struct parameters;
+
 /** A Uniform Resource Identifier
  *
  * Terminology for this data structure is as per uri(7), except that
@@ -65,6 +67,8 @@ struct uri {
        const char *query;
        /** Fragment */
        const char *fragment;
+       /** Form parameters */
+       struct parameters *params;
 } __attribute__ (( packed ));
 
 /** A field in a URI