/**************************************************************** * * * CgiEnv is a class to parse and maintain a collection * * of environment variable/value pairs * * Originally by Jim Lu of Bucknell University in Spring 2001 * * Revised: Xiannong Meng of Bucknell University * * aug-10-2001 * * Rick Zaccone 2001-08-15 * * 1) extractInputString * * 2) make formatize a part of cgienv * * 3) revise the names to conform with what we ask for students * * * * Revised: Xiannong Meng 2002-08-16 * * 1) add a method to return a name/value pair at a given index * * 2) add a method to return the number of pais * ****************************************************************/ #ifndef CGIENV_H #define CGIENV_H #include #include #include using namespace std; class CgiEnv { public: CgiEnv(); void reset(); // pre: unparsed is the input string from the form in its raw format // post: each var/value pair has been stored void populate(string inUnparsed); // a different way to store var/value pairs // pre: inVar and inValue are correct // post: they are added to the parallel array void set(const string & inVar, const string & inValue); // pre: var is one of the variables stored // post: corresponding value is returned // exception: when variable not found string get(const string & inVar) const; // put pluses back into a string for cgi processing // pre: inString is a free text string // post: all blank spaces ' ' are replaced by pluses ('+') string formatize(const string & inString) const; // extractInputString // an HTML input to CGI program is in the form of // title1=content1&title2=content2, ... // The function extract the content one at a time and return it // through the heading of the function // If the input contains multiple words, they are separated by '+'. This // function will remove these '+'s. // Pre: 'buf' contains CGI input from stdin // Post: one 'name' and 'value' pair extracted, 'buf' advanced to next pair void extractInputString(string & ioBuf, string & outName, string & outValue); void extractInputInt(string & ioBuf, string & outName, int & outValue); // getSize // return the count of pairs stored in mEnvVars // Pre: none // Post: the count of the pairs is returned int getSize() const; // getPair // return the pair of name/value at a given index // Pre: the given index is valid // Post: the name/value pair at the specified location is returned // if the index is valid, a 'false' is returned if invalid bool getPair(int inLoc, string & outName, string & outValue); private: vector mEnvVars; vector mEnvVals; }; #endif