#include #include #include #include #include #include #include using namespace std; // Routing Table // Wird später zur Laufzeit aus der Konfiguration geladen map routes; map ::iterator el; // Basis Responseklasse class Response{ private: stringstream body_stream; public:string body(){ body_stream.str("Das ist der Body der Baisklasse"); return body_stream.str(); }; public: stringstream header_stream; public:void set_header(const string header){ header_stream << header << "\n"; }; public: string get_header(){ header_stream << "\n\n"; return header_stream.str(); } }; class Foo : public Response{ private: stringstream body_stream; public:string body(){ body_stream.str("Das ist der Body der Klasse Foo"); return body_stream.str(); }; public: string header(){ this->set_header("Content-Type: text/plain"); return this->get_header(); }; }; class Bar : public Response{ private: stringstream body_stream; public:string body(){ body_stream.str("Das ist der Body der Klasse Bar"); return body_stream.str(); }; public: string header(){ this->set_header("Content-Type: text/plain; charset=UTF-8"); return this->get_header(); }; }; class NotFound : public Response{ private: stringstream body_stream; public:string body(){ body_stream.str("Die Seite wurde nicht gefunden"); return body_stream.str(); }; public: string header(){ this->set_header("Status: 404"); this->set_header("Content-Type: text/html; charset=utf-8"); return this->get_header(); } }; int main(){ string ns = "Foo"; string url = getenv("REDIRECT_URL") ? getenv("REDIRECT_URL") : "/qwertz.chtml"; // Diese Konfiguration wird später zur Laufzeit geladen routes["/foo.chtml"] = "Foo"; routes["/bar.chtml"] = "Bar"; string classname = routes[url]; if( ! classname.compare("Foo") ){ Foo *response = new Foo; cout << response->header(); cout << response->body(); } else if( ! classname.compare("Bar") ){ Bar *response = new Bar; cout << response->header(); cout << response->body(); } else{ NotFound *response = new NotFound; cout << response->header(); cout << response->body(); } return 0; }