00001 #ifndef DV_TICKET_REQUEST_H 00002 #define DV_TICKET_REQUEST_H 00003 00004 #include <dvxml/xml.h> 00005 #include <dvssl/sslsocket.h> 00006 #include <dvmysql/sqldb.h> 00007 #include <dvticket/authenticator.h> 00008 00009 namespace Dv { 00010 namespace Ticket { 00011 class Server; 00012 /** A class representing a reques from a client. A client may e.g. 00013 * request to obtain a new ticket (anonymous or otherwise), or 00014 * to validate an existing ticket (via its serial number). 00015 * @sa Dv::Ticket::Ticket 00016 */ 00017 class Request { 00018 public: 00019 /** Shorthand typedef */ 00020 typedef Dv::Util::ref<Request> Ref; 00021 /** Factory function. The function will return a pointer to 00022 * an instance object of a class derived from a Request. 00023 * The derived class depends on the data in the req XML document 00024 * parameter. 00025 * 00026 * @param req XML document as received from a client. 00027 * @param client SSL connection with client making the request 00028 * @param server that received this request 00029 * @return 0 upon any error, e.g. unknown request type, 00030 * otherwise a pointer to a valid instance of a class derived from Request. 00031 * @sa Dv::Ticket::LoginRequest, Dv::Ticket::AnonLoginRequest, Dv::Ticket::ValidateRequest 00032 */ 00033 static Ref make(const Dv::Xml::Document& req, 00034 Dv::Util::ref<Dv::Ssl::SslSocket> client, Server& server); 00035 /** Handle a request. This is a virtual function, the default 00036 * implementation simly returns its unmodified argument. 00037 * @param result reference to an XML document that will 00038 * be filled with the reply to the request. 00039 * @return a reference to the first argument. 00040 */ 00041 virtual Dv::Xml::Document& handle(Dv::Xml::Document& result) { 00042 return result; 00043 } 00044 /** Destructor */ 00045 virtual ~Request() {} 00046 /** @return reference to root node of the request XML representation. */ 00047 const Dv::Xml::Node::Ref& root() const { return root_; } 00048 /** @return dot address of client making the request, e.g. "134.184.65.2" */ 00049 const std::string& host() const { return host_; } 00050 /** Server that received the request. */ 00051 Dv::Ticket::Server& server() { return server_; } 00052 protected: 00053 /** Constructor (protected, use Dv::Request::make). 00054 * @param req XML document as received from a client. 00055 * @param client SSL connection with client making the request 00056 * @param server that received this request 00057 * @sa Dv::Ticket::Request::make 00058 */ 00059 Request(const Dv::Xml::Document& req, Dv::Util::ref<Dv::Ssl::SslSocket> client, Server& server); 00060 /** @return reference to SSL connection with requesting client */ 00061 Dv::Util::ref<Dv::Ssl::SslSocket> client() { return client_; } 00062 private: 00063 /** XML document containing the request */ 00064 Dv::Xml::Document req_; 00065 /** root of req_ */ 00066 Dv::Xml::Node::Ref root_; 00067 /** SSL connection to client making the request */ 00068 Dv::Util::ref<Dv::Ssl::SslSocket> client_; 00069 /** Dot address of client making the request. E.g. 134.184.65.2 */ 00070 std::string host_; 00071 /** Server that received the request. */ 00072 Server& server_; 00073 }; 00074 00075 /** Request from a user to obtain a new ticket. */ 00076 class LoginRequest: public Request { 00077 public: 00078 /** Constructor. 00079 * @param req XML document as received from a client. 00080 * @param client SSL connection with client making the request 00081 * @param server that received this request 00082 * @sa Dv::Ticket::Request::make 00083 */ 00084 LoginRequest(const Dv::Xml::Document& req, Dv::Util::ref<Dv::Ssl::SslSocket> client, 00085 Server& server): Request(req, client, server) {} 00086 /** Handle a request. This is implements Dv::Ticket::Request::handle 00087 * @param result reference to an XML document that will 00088 * be filled with the reply to the request. 00089 * @return a reference to the first argument. 00090 */ 00091 Dv::Xml::Document& handle(Dv::Xml::Document& result); 00092 }; 00093 00094 /** Request from a user to obtain an anonymous ticket. */ 00095 class AnonLoginRequest: public Request { 00096 public: 00097 /** Constructor. 00098 * @param req XML document as received from a client. 00099 * @param client SSL connection with client making the request 00100 * @param server that received this request 00101 * @sa Dv::Ticket::Request::make 00102 */ 00103 AnonLoginRequest(const Dv::Xml::Document& req, Dv::Util::ref<Dv::Ssl::SslSocket> client, 00104 Server& server): Request(req, client, server) {} 00105 /** Handle a request. This is implements Dv::Ticket::Request::handle 00106 * @param result reference to an XML document that will 00107 * be filled with the reply to the request. 00108 * @return a reference to the first argument. 00109 */ 00110 Dv::Xml::Document& handle(Dv::Xml::Document& result); 00111 }; 00112 00113 /** Request from a user to validate a ticket. */ 00114 class ValidateRequest: public Request { 00115 public: 00116 /** Constructor. 00117 * @param req XML document as received from a client. 00118 * @param client SSL connection with client making the request 00119 * @param server that received this request 00120 * @sa Dv::Ticket::Request::make 00121 */ 00122 ValidateRequest(const Dv::Xml::Document& req, Dv::Util::ref<Dv::Ssl::SslSocket> client, 00123 Server& server): Request(req, client, server) {} 00124 /** Handle a request. This is implements Dv::Ticket::Request::handle 00125 * @param result reference to an XML document that will 00126 * be filled with the reply to the request. 00127 * @return a reference to the first argument. 00128 */ 00129 Dv::Xml::Document& handle(Dv::Xml::Document& result); 00130 }; 00131 00132 }} 00133 #endif 00134
dvticket-0.7.1 | [24 October, 2003] |