multimaps and cgi/html parsing

The idea is to write a program that reads in form data, and outputs the name value data. This is going to require a multimap since the names are not unique in html form data.

Vulcan does not have a web server running, so we have to do this by hand. The idea is to write two parser functions, one that turns url encoded data into readable name/value pairs, and one that turns sane text into html escaped output.

from data

We are going to handle GET method form data. This stores the data in the environment variable named QUERY_STRING.

url encoding

When get method data is encoded there are two rules to it. so "foo=test+this+%26" is really "foo=test this &"

html escapes

The problem when outputting html is that many characters have meaning in html and have to be escaped to make them output correctly.

The most common are :
<>&"
These become :
&lt;&gt;&amp;&quot;

You can use an iso form which &#dd done with decimal numbers, or &#xdd done with hex numbers. So the "\" can be done as &#92; or &#x5c;.

We are going to want spaces done as &nbsp; so they are non-breaking.

program output

Your program needs to read the form data and output html with each name value pair on a line.

So if the html form input was "foo=test+this+%26" the data is really "foo=test this &", and the html output is


foo=test test &amp;<br>

shell script to pass data to the program
driver code to get the data
here is some sample output

test form
This form when submitted outputs the encodeds data as plain text. All I did was take the driver and change the Content-type to text/plain then output the string "input_data". Note that it also does both post and get correctly.

This program is due on April 23rd.

Goals

stringstream tips
Converting the %## is really easy since hex is an istream operator as well as ostream. The stringstream clear() only resets the state of a stringstream, to actually empty one you also need to call str("").