// Smersh // // Douglas Thrift // // $Id$ #include "Smersh.hpp" #include "Matcher.hpp" #include "Person.hpp" #include "Daemon.hpp" #include "Redirector.hpp" string program; bool debug(false); int main(int argc, char* argv[]) { program = argv[0]; int port(8080); bool daemon(false), redirector(false); string redirect; for (int index(1); index < argc; ++index) { string arg(argv[index]); Matcher matcher; if (arg == "-D") { if (!debug) debug = true; } else if (arg == "-daemon") { if (!daemon) daemon = true; } else if (arg == matcher("^-redirector=(.+)$")) { if (!redirector) redirector = true; redirect = matcher[1]; } else if (arg == matcher("^-port=([0-9]+)$")) { port = lexical_cast(matcher[1]); } } if (daemon) { Daemon daemon(port); } else if (redirector) { Redirector redirector(port, redirect); } else { Smersh smersh; } return 0; } Smersh::Smersh(ostream& sout) { string method = sgetenv("REQUEST_METHOD"); parse(method); sout << "Content-Type: text/plain\n\n" << (cgi.find("sn") != cgi.end() ? cgi.find("sn")->second : "Unknown") << '\n'; } void Smersh::parse(const string& method) { string query(sgetenv("QUERY_STRING")); if (method == "POST") getline(cin, query); if (query == "") return; istringstream input(query); do { string name, value; getline(input, name, '='); getline(input, value, '&'); cgi.insert(pair(name, value)); } while (input.good()); }