[En-Nut-Discussion] HTTP QueryString parser

Mikael Adolfsson ethernut at ma.stendahls.net
Mon Sep 15 12:49:17 CEST 2003


Hi,

There is a short doxygen-style description of these functions in httpd.c.

In short, they convert a parameter name or value to conform with rfc1738
(see section 2.2). Typically you never have to call NutHttpURLDecode,
since it's done internally by the parser. The URLEncode is useful if you
for example want to do a link with parameters from your cgi script. Here's
an example:

char *v = "some strange text &%/+"; /* Typically an unknown string */
char *s = NutHttpURLEncode (v);
fprintf_P (stream, PSTR("<a href=\"my.cgi?param=%s\">link</a>"), s);
NutHeapFree (s);

This will generate a link like this:
<a href="my.cgi?param=some+strange+text+%26%25%2F%2B">link</a>

Note:
char *NutHttpURLEncode(char *s) returns a new allocated string, that must
be free'd by the user.

void NutHttpURLDecode(char *s) overwrites s (since the decoded string is 
allways shorter or equal the length of s)

/ Mikael

On Mon, 15 Sep 2003, Lars Andersson wrote:
> Mikael,
> 
> I have now made the changes to the code and it seems to work fine now.
> Thank you very much for the contribution of your solution. I think this
> will make implementation easier in the future!
> 
> By the way, can you please explain, in more detail, the usage of these
> functions. I looked in the header file but unfortunately that didn't
> explain it to me.
> 
> char *NutHttpURLEncode (char *str);
> void NutHttpURLDecode (char *str);




More information about the En-Nut-Discussion mailing list