From bbdabec18228665d548557f1c78159486cffc54d Mon Sep 17 00:00:00 2001 From: pixel Date: Sat, 14 Apr 2007 14:29:22 +0000 Subject: Creation of the HtmlSkinner class. --- TODO | 1 - include/Action.h | 6 +++++- include/HtmlSkinner.h | 17 +++++++++++++++++ lib/Action.cc | 20 +++++++++++--------- lib/HtmlSkinner.cc | 33 +++++++++++++++++++++++++++++++++ lib/HttpServ.cc | 15 ++------------- 6 files changed, 68 insertions(+), 24 deletions(-) create mode 100644 include/HtmlSkinner.h create mode 100644 lib/HtmlSkinner.cc diff --git a/TODO b/TODO index 2591ec6..d384ee1 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,2 @@ -) Add timeouts in HttpServ. -) Add logging support in HttpServ. --) Remove hardcoded skin, and create the HtmlSkin class. diff --git a/include/Action.h b/include/Action.h index 6110945..329592c 100644 --- a/include/Action.h +++ b/include/Action.h @@ -5,6 +5,7 @@ #include #include #include +#include //! This is the basic HTTP action. /*! @@ -16,7 +17,7 @@ class Action : public Base { /*! If no URL is provided, one will be generated on the fly. */ - Action(const String & url = ""); + Action(const String & url = "", HtmlSkinner * = 0); virtual ~Action(); //! Will recursively resolve an URL, and return the corresponding action, or NULL if not found. Action * Look4URL(const String &); @@ -42,6 +43,8 @@ class Action : public Base { String GetURL(void); //! Mark this action to be erased as soon as the Do method ends. void CleanUp(void); + //! Skinner accessor. + HtmlSkinner * GetSkinner(); protected: //! Mark this action as beeing accessed. @@ -52,6 +55,7 @@ class Action : public Base { Action * next, * prev; String URL; bool hastoclean, accessed; + HtmlSkinner * skin; }; #endif diff --git a/include/HtmlSkinner.h b/include/HtmlSkinner.h new file mode 100644 index 0000000..6603cde --- /dev/null +++ b/include/HtmlSkinner.h @@ -0,0 +1,17 @@ +#ifndef __HTMLSKINNER_H__ +#define __HTMLSKINNER_H__ + +#include +#include + +class HtmlSkinner : public Base { + public: + HtmlSkinner(); + virtual ~HtmlSkinner(); + virtual String Redirect(const String & location); + virtual String Error(const String & location); + virtual String Header(const String & title); + virtual String Footer(); +}; + +#endif diff --git a/lib/Action.cc b/lib/Action.cc index 23f96d0..2fb0e2a 100644 --- a/lib/Action.cc +++ b/lib/Action.cc @@ -8,6 +8,7 @@ Action * Action::start = 0; static int counter = 0; +static HtmlSkinner default_skinner; static String genurl(const String & u) { if (u.strlen()) { @@ -19,9 +20,12 @@ static String genurl(const String & u) { } } -Action::Action(const String & u) : next(start), prev(0), URL(genurl(u)), hastoclean(false), accessed(false) { +Action::Action(const String & u, HtmlSkinner * _skin) : next(start), prev(0), URL(genurl(u)), hastoclean(false), accessed(false), skin(_skin) { start = this; if (next) next->prev = this; + if (!skin) { + skin = &default_skinner; + } } Action::~Action() { @@ -57,17 +61,15 @@ Action * Action::Look4URL(const String & URL) { */ void Action::SendHead(Handle * h) { - (*h) << "" << GetTitle() << "" << endnl << - "" << endnl << - "" << endnl << - "" << endnl << - "
" << endnl << - "

" << GetTitle() << "

" << endnl << - "
" << endnl; + (*h) << skin->Header(GetTitle()); } void Action::SendFoot(Handle * h) { - (*h) << "
" << endnl; + (*h) << skin->Footer(); +} + +HtmlSkinner * Action::GetSkinner() { + return skin; } String Action::GetURL(void) { diff --git a/lib/HtmlSkinner.cc b/lib/HtmlSkinner.cc new file mode 100644 index 0000000..31ed083 --- /dev/null +++ b/lib/HtmlSkinner.cc @@ -0,0 +1,33 @@ +#include "HtmlSkinner.h" + +HtmlSkinner::HtmlSkinner() { +} + +HtmlSkinner::~HtmlSkinner() { +} + +String HtmlSkinner::Redirect(const String & location) { + return "301 - Moved Permanently\n" + "

You should be redirected here shortly

\n" + "\n"; +} + +String HtmlSkinner::Error(const String & location) { + return "404 - Error\n" + "

The server was unable to process your query

\n" + "Click here to go the main page.\n"; +} + +String HtmlSkinner::Header(const String & title) { + return "" + title + "\n" + "\n" + "\n" + "\n" + "
\n" + "

" + title + "

\n" + "
\n"; +} + +String HtmlSkinner::Footer() { + return "
"; +} diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc index 1105745..9a59dc2 100644 --- a/lib/HttpServ.cc +++ b/lib/HttpServ.cc @@ -359,10 +359,7 @@ void ProcessRequest::SendRedirect(Handle * s) { "Cache-Control: no-cache" << endhl << "Connection: closed" << endhl << "Content-Type: text/html" << endhl << endhl << - "301 - Moved Permanently" << endnl << - "

You should be redirected to the " << endnl << endnl << - "start page

" << endnl << - "" << endnl; + p->GetSkinner()->Redirect("http://" + host + "/bin/start"); } /* @@ -391,15 +388,7 @@ void ProcessRequest::SendHeads(Handle * s, const String & mime, const String & e */ void ProcessRequest::ShowError(Handle * s) { - *s << "HTTP/1.1 404 Not Found" << endhl << - "Server: " << name << endhl << - "Cache-Control: no-cache" << endhl << - "Connection: closed" << endhl << - "Content-Type: text/html" << endhl << endhl << - "404 - Error" << endnl << - "

The server was unable to process your query

" << endnl << - "Click here to go the main page." << - "" << endnl; + *s << p->GetSkinner()->Error(""); } /* -- cgit v1.2.3