Logo
~Apps~
~Projects~
~Contact~


StatusSocket Class Reference

Small web server interface. More...

#include <StatusSocket.h>

Collaboration diagram for StatusSocket:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 StatusSocket (ISocketHandler &)
 ~StatusSocket ()
void Exec ()
void GetEnvironment ()
void ReadCookies ()
void FormInput ()
void CreateHeader ()
void GenerateDocument ()

Private Member Functions

 StatusSocket (const StatusSocket &s)
StatusSocketoperator= (const StatusSocket &)
void SetTheCookie ()
void menyval (int val, int sheet, const std::string &text)

Private Attributes

std::string m_tmp
int m_sheet

Detailed Description

Small web server interface.

Definition at line 35 of file StatusSocket.h.


Constructor & Destructor Documentation

StatusSocket::StatusSocket ( ISocketHandler &   ) 

Definition at line 41 of file StatusSocket.cpp.

00042 :HttpdSocket(h)
00043 ,m_sheet(0)
00044 {
00045         SetFlushBeforeClose();
00046 }

StatusSocket::~StatusSocket (  ) 

Definition at line 49 of file StatusSocket.cpp.

00050 {
00051 }

StatusSocket::StatusSocket ( const StatusSocket s  )  [inline, private]

Definition at line 50 of file StatusSocket.h.

00050 : HttpdSocket(s) {} // copy constructor


Member Function Documentation

void StatusSocket::Exec (  ) 

Definition at line 54 of file StatusSocket.cpp.

References CreateHeader(), DEB, FormInput(), GenerateDocument(), GetEnvironment(), and ReadCookies().

00055 {
00056 DEB(printf("%s %s %s\n", GetMethod().c_str(), GetUrl().c_str(), GetHttpVersion().c_str());)
00057         GetEnvironment();
00058         ReadCookies();
00059         FormInput();
00060         CreateHeader();
00061         GenerateDocument();
00062 }

void StatusSocket::GetEnvironment (  ) 

Definition at line 65 of file StatusSocket.cpp.

Referenced by Exec().

00066 {
00067 }

void StatusSocket::ReadCookies (  ) 

Definition at line 70 of file StatusSocket.cpp.

References m_sheet.

Referenced by Exec().

00071 {
00072         HttpdCookies *cs = GetCookies();
00073         if (!cs)
00074                 return;
00075         std::string slask;
00076         if (cs -> getvalue("bleep", slask))
00077         {
00078                 Parse pa(slask,":");
00079                 m_sheet = pa.getvalue();
00080         }
00081 }

void StatusSocket::FormInput (  ) 

Definition at line 84 of file StatusSocket.cpp.

References DEB, m_sheet, and m_tmp.

Referenced by Exec().

00085 {
00086         const HttpdForm *form = GetForm();
00087         if (!form)
00088         {
00089 DEB(printf("form is NULL\n");)
00090                 return;
00091         }
00092 
00093         m_tmp = form -> getvalue("ah");
00094 
00095         if (GetUri() == "/stop")
00096         {
00097                 static_cast<PeerHandler&>(Handler()).SetQuit();
00098         }
00099         if (GetUri() == "/debug")
00100         {
00101                 int val = 0;
00102                 std::string key;
00103                 std::string value;
00104                 form -> getfirst(key, value);
00105                 while (key.size())
00106                 {
00107 DEB(printf("%s == '%s'\n", key.c_str(), value.c_str());)
00108                         if (!strcmp(key.c_str(), "debug"))
00109                                 val |= atoi(value.c_str());
00110                         //
00111                         form -> getnext(key, value);
00112                 }
00113                 static_cast<PeerHandler&>(Handler()).SetDebug(val);
00114         }
00115         std::string tmp = form -> getvalue("sheet");
00116         if (tmp.size())
00117                 m_sheet = atoi(tmp.c_str());
00118 }

void StatusSocket::CreateHeader (  ) 

Definition at line 121 of file StatusSocket.cpp.

References SetTheCookie().

Referenced by Exec().

00122 {
00123         // header
00124         AddResponseHeader("Date", GetHttpDate());
00125         AddResponseHeader("Server", "++ 0.001");
00126         AddResponseHeader("Connection", "close");
00127         AddResponseHeader("Content-type", "text/html");
00128 
00129         // status
00130         if (GetUri() == "/favicon.ico")
00131         {
00132                 SetStatus("404");
00133                 SetStatusText("Not Found");
00134         }
00135         else
00136         {
00137                 SetStatus("200");
00138                 SetStatusText("OK");
00139 
00140                 // cookie
00141                 SetTheCookie();
00142         }
00143 
00144         // send
00145         SendResponse();
00146 }

void StatusSocket::GenerateDocument (  ) 

Definition at line 149 of file StatusSocket.cpp.

References m_sheet, m_tmp, and menyval().

Referenced by Exec().

00150 {
00151         if (GetStatus() != "200")
00152                 return;
00153 
00154         // page
00155         Send("<html>"
00156                 "<head>"
00157                 "<style type='text/css'>"
00158                 "td.h {"
00159                 "background: #e0e0e0;"
00160                 "}"
00161                 "</style>"
00162                 "</head>"
00163                 "<body>"); //<h1>status</h1>");
00164         Send("<div style='border: 2px #000000 solid; background: #e0e0e0; margin: 5px;'>");
00165         menyval(1, m_sheet, "server commands");
00166         menyval(2, m_sheet, "debug options");
00167         menyval(3, m_sheet, "sessions");
00168         Send("</div>");
00169         Send("<br>");
00170 
00171         switch (m_sheet)
00172         {
00173         case 1:
00174                 Send("<a href='/stop'>stop server</a><br>");
00175                 Send("AH: " + m_tmp + "<br>");
00176                 break;
00177         case 2:
00178                 Send("<h3>Debug</h3>");
00179                 Send("<form action=/debug method=POST>");
00180                 {
00181                 int debug = static_cast<PeerHandler&>(Handler()).GetDebug();
00182                 char slask[200];
00183                 sprintf(slask, "<input type=checkbox name=debug value=1%s>     * 0 - choke<br>", (debug & 1) ? " checked" : "");
00184                 Send(slask);
00185                 sprintf(slask, "<input type=checkbox name=debug value=2%s>     * 1 - unchoke<br>", (debug & 2) ? " checked" : "");
00186                 Send(slask);
00187                 sprintf(slask, "<input type=checkbox name=debug value=4%s>     * 2 - interested<br>", (debug & 4) ? " checked" : "");
00188                 Send(slask);
00189                 sprintf(slask, "<input type=checkbox name=debug value=8%s>     * 3 - not interested<br>", (debug & 8) ? " checked" : "");
00190                 Send(slask);
00191                 sprintf(slask, "<input type=checkbox name=debug value=16%s>     * 4 - have [piece(integer)]<br>", (debug & 16) ? " checked" : "");
00192                 Send(slask);
00193                 sprintf(slask, "<input type=checkbox name=debug value=32%s>     * 5 - bitfield [bitmap]<br>", (debug & 32) ? " checked" : "");
00194                 Send(slask);
00195                 sprintf(slask, "<input type=checkbox name=debug value=64%s>     * 6 - request [index begin length]<br>", (debug & 64) ? " checked" : "");
00196                 Send(slask);
00197                 sprintf(slask, "<input type=checkbox name=debug value=128%s>     * 7 - piece [index begin piece(byte[])]<br>", (debug & 128) ? " checked" : "");
00198                 Send(slask);
00199                 sprintf(slask, "<input type=checkbox name=debug value=256%s>     * 8 - cancel [index begin length]<br>", (debug & 256) ? " checked" : "");
00200                 Send(slask);
00201                 sprintf(slask, "<input type=checkbox name=debug value=512%s> Time<br>", (debug & 512) ? " checked" : "");
00202                 Send(slask);
00203                 sprintf(slask, "<input type=checkbox name=debug value=1024%s> Connect<br>", (debug & 1024) ? " checked" : "");
00204                 Send(slask);
00205                 sprintf(slask, "<input type=checkbox name=debug value=2048%s> SocketLog<br>", (debug & 2048) ? " checked" : "");
00206                 Send(slask);
00207                 sprintf(slask, "<input type=checkbox name=debug value=4096%s> Speeds<br>", (debug & 4096) ? " checked" : "");
00208                 Send(slask);
00209                 Send("<input type=submit name=submit value=' Update '>");
00210                 }
00211                 Send("</form>");
00212                 break;
00213         case 3:
00214                 static_cast<PeerHandler&>(Handler()).Show( this );
00215                 break;
00216         } // switch (m_sheet)
00217         
00218 
00219         //
00220         Send("</body></html>");
00221 
00222         // close
00223         SetCloseAndDelete();
00224 }

StatusSocket& StatusSocket::operator= ( const StatusSocket  )  [inline, private]

Definition at line 51 of file StatusSocket.h.

00051 { return *this; } // assignment operator

void StatusSocket::SetTheCookie (  )  [private]

Definition at line 227 of file StatusSocket.cpp.

References COOKIE_DOMAIN, COOKIE_PATH, and m_sheet.

Referenced by CreateHeader().

00228 {
00229         char slask[1000];
00230         sprintf(slask, "%d", m_sheet);
00231         HttpdCookies *cs = GetCookies();
00232         if (!cs)
00233                 return;
00234         cs -> setcookie(this, COOKIE_DOMAIN, COOKIE_PATH, "bleep", slask);
00235 }

void StatusSocket::menyval ( int  val,
int  sheet,
const std::string &  text 
) [private]

Definition at line 238 of file StatusSocket.cpp.

Referenced by GenerateDocument().

00239 {
00240         char slask[1000];
00241         Send("&nbsp;&nbsp;&nbsp;");
00242         if (val == sheet)
00243         {
00244                 sprintf(slask,"<a href='/?sheet=%d'>%s</a>", val, text.c_str());
00245         }
00246         else
00247         {
00248                 sprintf(slask,"<a style='text-decoration: none;' href='/?sheet=%d'>%s</a>", val, text.c_str());
00249         }
00250         Send(slask);
00251         Send("&nbsp;&nbsp;&nbsp;");
00252 }


Member Data Documentation

std::string StatusSocket::m_tmp [private]

Definition at line 55 of file StatusSocket.h.

Referenced by FormInput(), and GenerateDocument().

int StatusSocket::m_sheet [private]

Definition at line 56 of file StatusSocket.h.

Referenced by FormInput(), GenerateDocument(), ReadCookies(), and SetTheCookie().


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4