/* * This file is part of MXE. See LICENSE.md for licensing information. */ #include #include using std::string; using std::stringstream; void show_html(const string &); bool ends_with(const string &, const string &); string get_env_var(const string &); int main(void) { unsigned long counter = 0; while (FCGI_Accept() >= 0) { ++counter; const string full_path = get_env_var("SCRIPT_NAME"); if (ends_with(full_path, "") || ends_with(full_path, "/")) { show_html("Hello, stranger!
\n" "
\n" "What are you looking for?
\n" "
\n" "Counter of visits may be found here
\n"); } else if (ends_with(full_path, "/counter") || ends_with(full_path, "/counter/")) { stringstream counter_str; counter_str << counter; show_html("Counter: " + counter_str.str()); } else { show_html("

This is not the page you are looking for!

\n"); } } return 0; } void show_html(const string &str) { printf("Content-type: text/html\n\n"); printf("%s", str.c_str()); } bool ends_with(const string &str, const string &sfx) { if (sfx.size() > str.size()) return false; return equal(str.begin() + str.size() - sfx.size(), str.end(), sfx.begin()); } string get_env_var(const string &var) { const char *ptr = getenv(var.c_str()); return (ptr ? string(ptr) : ""); }