HTTPSERVER Class Reference

Class to represent a virtual path in the HTTP server The constructor takes a virtual path. More...

#include <mi32/httpserver.h>

List of all members.

Public Member Functions

 HTTPSERVER ()
 ~CLIENT ()
virtual ~FILEHANDLER ()
virtual ~HANDLER ()
virtual ~HTTPSERVER ()
virtual ~PATH ()
virtual ~UPLOADHANDLER ()
ERRVALUE AddHandler (HTTPSERVER::HANDLER *handler)
ERRVALUE AddHandler (HANDLER *handler)
ERRVALUE AddListenSocket (MISOCKET *sock, bool bTakeOwnership=true)
ERRVALUE AddListenSocket (const MISOCKET::ADDR &address)
ERRVALUE AddMIMEType (const char *extn, const char *mimetype)
ERRVALUE AddPath (PATH *path)
bool CanHandleMethod (HTTPMESSAGE::METHOD method) const
 CLIENT (HTTPSERVER &server, MISOCKET *sock)
 FILEHANDLER (HTTPSERVER &server, const FILEPATH &DocumentRoot)
const char * FindMIMEType (const FILEPATH &filepath)
PATH * FindPath (const HTTPMESSAGE &msg)
void GenerateStatusPage (MISTRING &mistr)
const char * GetName ()
HTTPSERVERGetServer ()
HTTPSERVERGetServer ()
const char * GetVirtualPath () const
 HANDLER (HTTPSERVER &server, const char *name)
int Matches (const HTTPMESSAGE &request) const
bool Matches (const char *path) const
 PATH (HTTPSERVER &server, const char *virtualpath)
bool ProcessRequest (HTTPSERVER::CLIENT *client, const HTTPMESSAGE &request)
bool ProcessRequest (HTTPSERVER::CLIENT *client, const HTTPMESSAGE &request)
void SendErrorReply (HTTPMESSAGE::STATUS status, const HTTPMESSAGE &request, ERRVALUE err=0)
void SetMethodAllowed (HTTPMESSAGE::METHOD method, bool bIsAllowed=true)
void Shutdown ()
 UPLOADHANDLER (HTTPSERVER &server, const FILEPATH &DocumentRoot)

Private Member Functions

virtual HTTPSERVER::CLIENT * v_AllocateClient (MISOCKET *sock)
virtual bool v_CanHandleMethod (HTTPMESSAGE::METHOD method) const =0
virtual int v_Matches (const HTTPMESSAGE &request) const =0
virtual void v_OnClientConnect (CLIENT *client)
virtual void v_OnClientDisconnect (CLIENT *client)
void v_OnClose ()
void v_OnMessage (const HTTPMESSAGE &)
virtual bool v_ProcessRequest (HTTPSERVER::CLIENT *client, const HTTPMESSAGE &request)=0
virtual bool v_ProcessRequest (HTTPSERVER::CLIENT *client, const HTTPMESSAGE &request)

Private Attributes

bool m_AllowedMethods [HTTPMESSAGE::METHOD_NUM_METHODS]
bool m_bDestroying
SIMPLE_ARRAY
< HTTPSERVER::HANDLER * > 
m_Handlers
const char * m_name
HTTPSERVERm_Server
STRUTF8 m_VirtualPath

Detailed Description

Class to represent a virtual path in the HTTP server The constructor takes a virtual path.

Server side representation of a client.

Class to represent a virtual path in the HTTP server for uploads via PUT.

Class to represent a virtual path in the HTTP server from which the user can GET files.

Any request which falls within this path will be processed by calling ProcessRequest

This handler does the following security checks... 1. The request URI may not have any .. path componants in it. 2. If the URI is for a folder, it will look for and return to the the user an index.htm or index.html (in that order) 3. Any files to be retrieved must be readable by the server

Warning! This class is stupid and doesn't do any permission checking other than the following... 1. The destination directory must already exist and be writable by the server proccess. 2. If the file to be written already exists, it must be writable. 3. The request is not allowed to have any .. in its path to prevent spoofing it to write where it's not supposed to.

If you want to derive your own client, override the server's v_AllocateClient() method and have allocate your derive class via new


Constructor & Destructor Documentation

HTTPSERVER::HTTPSERVER (  ) 
virtual HTTPSERVER::~HTTPSERVER (  )  [virtual]
virtual HTTPSERVER::~PATH (  )  [virtual]
virtual HTTPSERVER::~HANDLER (  )  [virtual]
virtual HTTPSERVER::~FILEHANDLER (  )  [virtual]
virtual HTTPSERVER::~UPLOADHANDLER (  )  [virtual]
HTTPSERVER::~CLIENT (  ) 

Member Function Documentation

ERRVALUE HTTPSERVER::AddHandler ( HTTPSERVER::HANDLER *  handler  ) 

Add a handler to the path.

If a path doesn't implement ProcessRequest, the default implementation will find the best handler and use that. If no handlers are added to a path, it will use the server's handler list.

ERRVALUE HTTPSERVER::AddHandler ( HANDLER *  handler  ) 

Add a file type handler The handler is then "owned" by the server and will be deleted by the server's destructor.

ERRVALUE HTTPSERVER::AddListenSocket ( MISOCKET sock,
bool  bTakeOwnership = true 
)

Add a listening socket to the server.

The socket should already be bound to a port.

Parameters:
sock The socket to add
bTakeOwnership If true (the default), the server will "own" the socket and delete it when it shuts down. If false, you must delete it.
ERRVALUE HTTPSERVER::AddListenSocket ( const MISOCKET::ADDR address  ) 

Add a listening socket to the server.

This version will take care of creating and binding the socket to the address you provide.

ERRVALUE HTTPSERVER::AddMIMEType ( const char *  extn,
const char *  mimetype 
)

Augment the server's list of known MIME types.

There are a few types built-in (htm, html, gif, jpg, png, etc)

Parameters:
extn File extension to associate (no dot)
mimetype MIME type (eg: "text/html")
ERRVALUE HTTPSERVER::AddPath ( PATH *  path  ) 

Add a new path.

The path is then "owned" by the server and will be deleted by the server's destructor.

bool HTTPSERVER::CanHandleMethod ( HTTPMESSAGE::METHOD  method  )  const
HTTPSERVER::CLIENT ( HTTPSERVER server,
MISOCKET sock 
)
HTTPSERVER::FILEHANDLER ( HTTPSERVER server,
const FILEPATH DocumentRoot 
)
const char* HTTPSERVER::FindMIMEType ( const FILEPATH filepath  ) 
PATH* HTTPSERVER::FindPath ( const HTTPMESSAGE msg  ) 

Find the virtual path that matches a given message.

Returns NULL if no paths match.

void HTTPSERVER::GenerateStatusPage ( MISTRING mistr  ) 

Generate an HTML status page giving the server status.

const char* HTTPSERVER::GetName (  ) 
HTTPSERVER& HTTPSERVER::GetServer (  ) 
HTTPSERVER& HTTPSERVER::GetServer (  ) 
const char* HTTPSERVER::GetVirtualPath (  )  const
HTTPSERVER::HANDLER ( HTTPSERVER server,
const char *  name 
)
Parameters:
name Used for config file settings
int HTTPSERVER::Matches ( const HTTPMESSAGE request  )  const

Determine how well this handler could service the request.

Returns:
0 to indicate not at all, 100 for complete match, anything inbetween for partial match. This allows you to define a handler of last resort.
bool HTTPSERVER::Matches ( const char *  path  )  const

Returns true if our VirtualPath matches the first part of the path passed in.

HTTPSERVER::PATH ( HTTPSERVER server,
const char *  virtualpath 
)
bool HTTPSERVER::ProcessRequest ( HTTPSERVER::CLIENT *  client,
const HTTPMESSAGE request 
)

Process a request.

Should return true if it sent a reply back to the client If false is returned, the client will be sent a 404 Not Found error.

bool HTTPSERVER::ProcessRequest ( HTTPSERVER::CLIENT *  client,
const HTTPMESSAGE request 
)

Process a request.

Returns true if a reply was sent back to the client.

void HTTPSERVER::SendErrorReply ( HTTPMESSAGE::STATUS  status,
const HTTPMESSAGE request,
ERRVALUE  err = 0 
)
void HTTPSERVER::SetMethodAllowed ( HTTPMESSAGE::METHOD  method,
bool  bIsAllowed = true 
)

Set wether or not a method is allowed in this directory.

By default, the only methods allowed are GET, HEAD, and POST

void HTTPSERVER::Shutdown (  ) 

Close all client and listening sockets and shutdown.

If running our own MainLoop() exit from that too.

HTTPSERVER::UPLOADHANDLER ( HTTPSERVER server,
const FILEPATH DocumentRoot 
)
virtual HTTPSERVER::CLIENT* HTTPSERVER::v_AllocateClient ( MISOCKET sock  )  [private, virtual]

Should allocate a new client.

The default implementation allocates a new HTTPSERVER::CLIENT

virtual bool HTTPSERVER::v_CanHandleMethod ( HTTPMESSAGE::METHOD  method  )  const [private, pure virtual]
virtual int HTTPSERVER::v_Matches ( const HTTPMESSAGE request  )  const [private, pure virtual]

Determine how well this handler could service the request.

Returns:
0 to indicate not at all, 100 for complete match, anything inbetween for partial match. This allows you to define a handler of last resort. This function shouldn't try to determine if the file actually exists or is usable, just that it's the right type to try.
virtual void HTTPSERVER::v_OnClientConnect ( CLIENT *  client  )  [private, virtual]

Will be called when a new client is added.

virtual void HTTPSERVER::v_OnClientDisconnect ( CLIENT *  client  )  [private, virtual]

Will be called when a client disconnects.

unless the disconnect comes from the server's destructor

void HTTPSERVER::v_OnClose (  )  [private]
void HTTPSERVER::v_OnMessage ( const HTTPMESSAGE  )  [private]
virtual bool HTTPSERVER::v_ProcessRequest ( HTTPSERVER::CLIENT *  client,
const HTTPMESSAGE request 
) [private, pure virtual]

Process a request.

Should return true if it sent a reply back to the client If false is returned, the client will be sent a 404 Not Found error.

virtual bool HTTPSERVER::v_ProcessRequest ( HTTPSERVER::CLIENT *  client,
const HTTPMESSAGE request 
) [private, virtual]

Process a request.

Should return true if a reply was sent back to the client. If false is returned, the client will be sent a 404 Not Found error.


Member Data Documentation

bool HTTPSERVER::m_AllowedMethods[HTTPMESSAGE::METHOD_NUM_METHODS] [private]
bool HTTPSERVER::m_bDestroying [private]
SIMPLE_ARRAY<HTTPSERVER::HANDLER*> HTTPSERVER::m_Handlers [private]
const char* HTTPSERVER::m_name [private]

The documentation for this class was generated from the following file:

Generated on Sun Oct 7 21:33:30 2012 for TNTsdk 2012 by  doxygen 1.6.1