Main Page   Class Hierarchy   Compound List   File List   Compound Members  

XRServer Class Reference

#include <xrserver.h>

Inheritance diagram for XRServer:

XRValidationServer List of all members.

Public Slots

void sendMethodResponse (int req, const QVariant &result)
void sendFault (int req, int fault_code, const QString &fault_string)


void methodCall (int req, const QString &methodname, const QValueList< QVariant > &params, bool &handled)

Public Methods

 XRServer (Q_UINT16 port=8080, int backlog=1, QObject *parent=0, const char *name=0)
 ~XRServer ()
QHostAddress getPeerForRequest (int req) const

Protected Slots

void readFromClient ()
void deleteClient ()

Protected Methods

void newConnection (int socket)
void parseContentAndEmit (QSocket *s)
void sendHttpError (QSocket *s, int status_code, const QString &reason, QString resp)
void sendHttpResponse (QSocket *s, int status_code, const QString &reason, QHttpHeader &headers, QString resp)

Protected Attributes

QMap< QSocket *, QString > _header_strings
QMap< QSocket *, QHttpRequestHeader > _headers
QMap< QSocket *, bool > _open_sockets
QMap< int, QSocket * > _req_to_socket
int _last_req

Detailed Description

Provides a minimal HTTP Server to handle XML-RPC requests and emit signals when requests are recieved. This server implements only what is required for XML-RPC, with a few extras. In particular, connections are left open (when compatible with the HTTP spec). Leaving TCP connections open results in usually 3 packets being sent per methodCall (assuming small calls and responses), as opposed to 10-12 if the connection is set up and destroyed each time. It also supports sending compressed (deflate) responses which DRAMATICALLY reduces the size of XML-RPC responses.

See also: ,

Constructor & Destructor Documentation

XRServer::XRServer Q_UINT16    port = 8080,
int    backlog = 1,
QObject *    parent = 0,
const char *    name = 0

Create an xml-rpc server on given port.

port  the port to bind to


Delete (which closes) all the sockets immediately. Does not do any graceful closing of the HTTP connections.

Member Function Documentation

void XRServer::deleteClient   [protected, slot]

The constructor connects this slot to QServerSocket::delayedCloseFinished()

QHostAddress XRServer::getPeerForRequest int    req const

Lightweight authentication function. Useful if you only want certain hosts to be able to call a method. Returns if the request is not an active request.

req  a request number
the host address for the peer that made the request.

void XRServer::methodCall int    req,
const QString &    methodname,
const QValueList< QVariant > &    params,
bool &    handled

This signal is emitted when a new method call comes in. Handlers should connect to this signal. Qt's signal and slot mechanism will make sure it gets to all handlers. Each handler is responsible for checking the method name and seeing if this is a request they should handle. If they do, they set handled to true.

req  This is an identifier for the call
handled  This is initialized as false, and when a slot handles this methodcall, it should be set to true.
See also:
sendMethodResponse , sendFault

void XRServer::newConnection int    socket [protected]

the  socket number for the new connection. This is a method implemented from QServerSocket

void XRServer::parseContentAndEmit QSocket *    s [protected]

s  the socket to parse the XML in and then emit a signal to handle the request

void XRServer::readFromClient   [protected, slot]

The constructor connects this slot to QServerSocket::readyRead()

void XRServer::sendFault int    req,
int    fault_code,
const QString &    fault_string

When a methodCall is handled with an unsuccessful (fault) result, this slot is used to send the fault back to the caller. Either this, or XRServer::sendMethodResponse may be called, but not both.

req  the request this is a fault for
fault_code  the number of the fault that occured.
fault_string  the string representation of the fault
See also: , sendHttpResponse

void XRServer::sendHttpError QSocket *    s,
int    status_code,
const QString &    reason,
QString    resp

Convienience function to handle the HTTP transport.

void XRServer::sendHttpResponse QSocket *    s,
int    status_code,
const QString &    reason,
QHttpHeader &    headers,
QString    resp

Convienience function to handle the HTTP transport. Used to send responses and faults

See also:
sendMethodResponse , sendFault

void XRServer::sendMethodResponse int    req,
const QVariant &    result

When a methodCall is handled with a successful (non-fault) result, this slot is used to send the response back to the caller. Either this, or XRServer::sendFault may be called, but not both.

req  the request this is a response for
result  the result of the methodcall. If the result cannot be converted to a XML-RPC type (using XRVariant) an application fault is sent (faultCode -32500).
See also:
methodCall , sendHttpResponse , XRVariant

Member Data Documentation

QMap<QSocket*, QString> XRServer::_header_strings [protected]

Until we read all the headers, each time we can read data, we check to see if we can read an entire line. If we can, we append to header strings recieved so far. When we get an empty line (which in HTTP means the headers are over) we create an HttpRequestHeader and add it to _headers

QMap<QSocket*, QHttpRequestHeader> XRServer::_headers [protected]

Stores the complete headers for the current request from a socket. If there is not current request, this map will have no entry for the socket. In this way, it also represents a set of sockets that have active requests.

int XRServer::_last_req [protected]

Counter that increases with each request.

QMap<QSocket*,bool> XRServer::_open_sockets [protected]

Since QT does not have a Set object, and we don't want to introduce an STL dependence for one class, we hack QMap to be a set of open sockets. When the destructor is called, all these sockets are deleted.

QMap<int,QSocket*> XRServer::_req_to_socket [protected]

Keeps track of requests for each socket.

The documentation for this class was generated from the following files:
Generated on Tue Feb 25 18:38:57 2003 for qutexr by doxygen1.2.15