--- HostStatus/HostStatus.cpp 2003/11/14 19:45:06 28 +++ HostStatus/HostStatus.cpp 2003/11/14 20:44:58 29 @@ -15,5 +15,84 @@ int main(int argc, char* argv[]) HostStatus::HostStatus() { - // + string method = sgetenv("REQUEST_METHOD"); + + parse(method); + + multimap::iterator itor = cgi.find("format"); + + if (itor != cgi.end()) + { + string format = itor->second; + + if (format == "t") + { + this->format = table; + } + else + { + this->format = page; + } + } + + display(method); +} + +void HostStatus::parse(const string& method) +{ + string query; + + if (method == "POST") + { + getline(cin, query); + } + else + { + query = sgetenv("QUERY_STRING"); + } + + if (query == "") return; + + istringstream input(query); + + do + { + string name, value; + + getline(input, name, '='); + getline(input, value, '&'); + + cgi.insert(pair(name, value)); + } + while (input.good()); +} + +void HostStatus::display(const string& method) +{ + cout << "Content-Type: text/html\n\n"; + + if (method == "POST") sunsetenv("HTTP_USER_AGENT"); + + pstream hostupdate("./hostupdate.cgi"); + + if (method == "POST") + { + for (multimap::iterator itor = cgi.begin(); itor != + cgi.end(); itor++) + { + hostupdate << itor->first << '=' << itor->second << '&'; + } + + hostupdate << '\n'; + } + + do + { + string line; + + getline(hostupdate, line); + + cout << line << '\n'; + } + while (hostupdate.good()); }