WebServer Class Reference
[WebserverSingle inited classes]

The central class of the webserver. More...

#include <webserver.h>

Inheritance diagram for WebServer:

Inheritance graph
[legend]
Collaboration diagram for WebServer:

Collaboration graph
[legend]
List of all members.

Public Member Functions

DECLSPEC WebServer (const char *name, BasicObject *p)
DECLSPEC WebServer (TiXmlElement *el, BasicObject *p)
virtual const char * getClassName ()
virtual DECLSPEC bool init (Uint16 port=80)
virtual DECLSPEC void destroy ()
virtual DECLSPEC bool poll (Uint16 tWait=0)
DECLSPEC void closeOutTimedThreads ()
DECLSPEC void parseXMLNode (TiXmlNode *node)
DECLSPEC int addPageDirectory (const char *dir, const char *basic_uri="/", const char *fn_index=0, bool subdirs=true)
list< WebPage * >::iterator beginPage ()
list< WebPage * >::iterator endPage ()

Static Public Member Functions

static DECLSPEC WebServergetThe ()

Static Public Attributes

static WebServerthe

Protected Member Functions

virtual DECLSPEC void onInit ()
virtual DECLSPEC void onDestroy ()

Protected Attributes

TCPsocket socket
 the socket, that listens for HTTP requests
list< WebPage * > lPages
 the list with all published web pages/files
list< WebThread * > lThreads
 the list with all threads, that respond on requests

Friends

class WebPage
class WebThread

Detailed Description

The central class of the webserver.

Required header file:

 #include <webserver.h> 

This class is not dependant on any Net* classes, but if you do not init a NetBasicManager-derived class before initing this, you have to call SDLNet_Init().

If you use NetThread for polling, be sure not to have WEB_CLIENT defined.

To use text-based configuration files, this class supports XML based files for basic configuration.

This class must not be used in two variables at a time.

See also:
Single inited classes


Constructor & Destructor Documentation

WebServer::WebServer ( TiXmlElement el,
BasicObject p 
)

Parameters:
el the TiXmlElement to parse for getting the initialisation data It can contain "Port" as an attribute, which contains the port to listen for requests (usually 80); if there is no attribute, the default port (80) is used. Furthermore the element can contain subnodes, which will be parsed by calling parseXMLNode(node). Here an example of a XML element:
      <Web Port="8000">
        <TimeoutIv value="30000" />
        <Directory Path="html/SDL" URI="/help/" Indexpage="index.html" SubDirs="true" />
        <Page URI="/favicon.ico" Filename="html/favicon.ico" ContentType="image/x-icon" />
        <Forward URI="/" Aim="index.html" />
      </Web>


Member Function Documentation

virtual const char* WebServer::getClassName (  )  [inline, virtual]

This function should be overriden in every sub-class of BasicObject!

Returns:
the name of the class.

Reimplemented from BasicObject.

bool WebServer::init ( Uint16  port = 80  )  [virtual]

(probably obsolete soon!) Initializes the web server. Use this only, if no XML data is used for Initialisation.
Before calling init, make sure to have inited SDL-net with SDLNet_Init() (which is also done with initing a NetBasicManager-derived class).

Parameters:
port The port to listen for requests (usually 80)
Returns:
true, if successful, false if not

void WebServer::destroy (  )  [virtual]

Uninitializes the web server. Call this before closing the application.

Reimplemented from BasicObject.

bool WebServer::poll ( Uint16  tWait = 0  )  [virtual]

Waits for connecting clients. Call this regularly to be able to keep the response time short.

Parameters:
tWait time to wait in msecs, if no request is pending
Returns:
true, if connection-request was recieved, false if not

void WebServer::closeOutTimedThreads (  ) 

Closes connections of inactive / stopped threads and deletes them. Kills threads that did not do anything for WebThread::tIdleToExit msecs

void WebServer::parseXMLNode ( TiXmlNode node  ) 

Parses the TiXmlNode and configures the server accordingly.

Parameters:
node the TiXmlNode, that can contain the following subnodes:
  • TimeoutIv: the time in msecs, after that an inactive thread can be killed
  • Directory: (more than one node possible) has to contain the attributes:
    • Path: the path (relative to the working dir or absolute) to the html files to make accessible via HTTP
    • URI: the basic URI, where the directory can be found from a browser the complete URI looks like http://IP-Addr"URI"/"filename" URI has to start with a '/'!
    • Indexpage: the file to send, if there is no file specified after the '/' like http://IP-addr/mydir/ then this equals http://IP-addr/mydir/"Indexpage"
    • SubDirs: (boolean value) if true, subdirectories of Path will be published; if false, only the files in Path will be published
  • Page: (more than one node possible) has to contain the attributes:
    • URI: the URI, where a browser can find the file (like http://IP-addr"URI"). URI has to start with a '/'!
    • Filename: the file's filename (relative to the cwd or absolute), where the file is located
    • ContentType: (optional) the MIME-type of the file like "text/html" if it is not specified, the app looks at the ending of the filename and uses the default type for this ending
  • Forward: (more than one node possible) has to contain the attributes:
    • URI: the URI, that should be forwarded, it has to start with a '/'!
    • Aim: the URI of the file to respond, it has to start with a '/'!
See also:
addPageDirectory, WebFilePage, WebForwardPage; for an example: init(TiXmlNode)

int WebServer::addPageDirectory ( const char *  dir,
const char *  basic_uri = "/",
const char *  fn_index = 0,
bool  subdirs = true 
)

Makes the files in the directory availible through the web

Parameters:
dir the directory, of which the files should be published (it can be relative to the app's data directory or absolute)
basic_uri the basic URI, where the directory can be accessed via browser like http://IP-addr"basic_uri"/
basic_uri has to start with a '/'!
fn_index if fn_index != 0 then the uri [..]/ is forwarded to [..]/"fn_index"
subdirs if true, subdirectories' files will also be published, if false not
Returns:
the number of files that were made availible

list<WebPage*>::iterator WebServer::beginPage (  )  [inline]

Returns:
a WebPage list iterator, pointing to the first page

list<WebPage*>::iterator WebServer::endPage (  )  [inline]

Returns:
a WebPage list iterator, pointing after the last page

WebServer * WebServer::getThe (  )  [static]

Returns:
a pointer to the WebServer-variable, or NULL if not initialized. (There is only one variable with the type WebServer allowed in an application)
Every netrinjo-class that can only exist once at a time, has this static function.
See also:
Single inited classes

void WebServer::onInit (  )  [protected, virtual]

Initializes the object's variables by reading data from the XML element. If there were no XML data used for creation, nothing is done. This function calls onInit() of its children recursively (after it has inited itself). It is highly recommended to call BasicObject::onInit(), usually at the end of the onInit() method, when overwriting it in a derived class.

Reimplemented from BasicLog.

void WebServer::onDestroy (  )  [protected, virtual]

May be called to reinitialise this object or stop an initialised module. Calls all children's onDestroy(). Most classes do not use this method. But sometimes it is useful to reset the functionality of an object.

Reimplemented from BasicObject.


Member Data Documentation

WebServer * WebServer::the [static]

only accessible in Linux, and equals the result of getThe()


The documentation for this class was generated from the following files:
Generated on Wed May 9 17:36:37 2007 for netrinjo by  doxygen 1.5.1