#include #include #include #include #include "CGI.H" using namespace std; string __CGI_DEBUG_STRING = ""; //************************************************************************** // Member Function: setCGIDebug // Purpose: If called, causes getQueryString() to return the value passed // to this function instead of a value obtained via the normal // GET/POST data passing. Use this function to debug your script // purely within Visual Studio. // The string provided should be an encoded parameter string, // such as "name=John+Smith&rsvp=yes" //************************************************************************** void setCGIDebug(string str) { __CGI_DEBUG_STRING = str; } //************************************************************************** // Member Function: getThisPath // Purpose: Returns a string representing the current relative directory // of the running script. //************************************************************************** string getThisPath() { string rawPath = string(getenv("SCRIPT_NAME")); string finalPath = ""; int i = rawPath.find_last_of('/', rawPath.length()) + 1; for(int x = 1; x < i; x++) { if ( rawPath[x] == '/') { finalPath.append(1,'\\'); } else { finalPath.append(1,rawPath[x]); } } return finalPath; } //************************************************************************** // Member Function: xhtmlHeaders // Purpose: Writes standard xhtml header information to standard cout (cout) //************************************************************************** void xhtmlHeaders(string pageTitle){ // Inform the browser about the contents of the file; must include a blank line cout << "content-type: text/html" << endl << endl; // Send the correct XHTML header information to the browser cout << "" << endl << "" << endl; // Send the formatted text to the browser using correct XHTML syntax cout << "" << endl; cout << "" << endl << "" << pageTitle << "" << endl << "" << endl << " " << endl; return; } //************************************************************************** // Member Function: xhtmlFooters // Purpose: Writes standard xhtml footer information to standard cout (cout) //************************************************************************** void xhtmlFooters(){ // Inform the browser about the contents of the file; must include a blank line // Send the formatted text to the browser using correct XHTML syntax cout << "" << endl << "" << endl; return; } //************************************************************************** // Member Function: getQueryString // Purpose: Determines and returns the query string generated from a form. //************************************************************************** string getQueryString(){ int count; string qString = ""; string method; if (__CGI_DEBUG_STRING != "") return __CGI_DEBUG_STRING; method = string(getenv("REQUEST_METHOD")); if(method=="GET"){ qString.append(getenv("QUERY_STRING")); }else{ if(getenv("CONTENT_LENGTH")){ count = atoi(getenv("CONTENT_LENGTH")); for(int i=0;i