#include <webserver.h>
Inheritance diagram for WebServer:
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 WebServer * | getThe () |
Static Public Attributes | |
static WebServer * | the |
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 |
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.
WebServer::WebServer | ( | TiXmlElement * | el, | |
BasicObject * | p | |||
) |
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> |
virtual const char* WebServer::getClassName | ( | ) | [inline, virtual] |
This function should be overriden in every sub-class of BasicObject!
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).
port | The port to listen for requests (usually 80) |
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.
tWait | time to wait in msecs, if no request is pending |
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.
node | the TiXmlNode, that can contain the following subnodes:
|
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
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 |
list<WebPage*>::iterator WebServer::beginPage | ( | ) | [inline] |
list<WebPage*>::iterator WebServer::endPage | ( | ) | [inline] |
WebServer * WebServer::getThe | ( | ) | [static] |
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.
WebServer * WebServer::the [static] |
only accessible in Linux, and equals the result of getThe()