Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members

server.h

Go to the documentation of this file.
00001 #ifndef DVTICKET_SERVER_H
00002 #define DVTICKET_SERVER_H
00003 
00004 // $Id: server.h,v 1.7 2003/09/18 13:02:25 dvermeir Exp $
00005 
00006 #include <string>
00007 #include <iostream>
00008 #include <stdexcept>
00009 #include <dvxml/xml.h>
00010 #include <dvmysql/mysqldb.h>
00011 #include <dvssl/sslserversocket.h>
00012 #include <dvticket/authenticator.h>
00013 #include <dvticket/ticket.h>
00014 #include <dvticket/exception.h>
00015 
00016 namespace Dv { 
00017 namespace Ticket {
00018 
00019 /** Ticket server class. 
00020  * @warning The server is single-threaded. DOS attacks are --
00021  * hopefully -- avoided by using a max. client delay.
00022  * @sa Dv::Ticket::Server::client_delay
00023  */
00024 class Server {
00025 public:
00026   /** Constructor.
00027    * @param config XML node containing configuration parameters. This
00028    *   node is assumed to conform to the configuration DTD.
00029    * @param authenticator object to which actual user name/passwd
00030    *   verification will be delegated.
00031    * @exception Dv::Ticket::Exception upon any error
00032    *
00033    * The constructor will connect to the database, set up
00034    * the SSL server etc.
00035    */
00036   Server(const Dv::Xml::Node::Ref config, Dv::Ticket::Authenticator& authenticator)
00037     throw (Dv::Ticket::Exception);
00038 
00039   /** Constructor.
00040    * @param config_fn name of XML file containing configuration
00041    *   parameters. The file will be checked vs the DTD.
00042    * @param authenticator object to which actual user name/passwd
00043    *   verification will be delegated.
00044    * @exception Dv::Ticket::Exception upon any error
00045    *
00046    * The constructor will connect to the database, set up
00047    * the SSL server etc.
00048    */
00049   Server(const std::string& config_fn, Dv::Ticket::Authenticator& authenticator)
00050     throw (Dv::Ticket::Exception);
00051 
00052   /** Server main loop.
00053    * @return 0 if ok, non-zero if error.
00054    */
00055   int main() throw ();
00056 
00057   /** Destructor (virtual). */
00058   virtual ~Server();
00059 
00060   /** @return name of directory containin DTD files */
00061   const std::string& dtd_dir() const { return dtd_dir_; }
00062   /** @return name of configuration file */
00063   const std::string& config_fn() const { return config_fn_; }
00064   /** @return name of configuration DTD file */
00065   const std::string& config_dtd_fn() const { return config_dtd_fn_; }
00066   /** @return name of request DTD file */
00067   const std::string& request_dtd_fn() const { return request_dtd_fn_; }
00068   /** @return name of log file */
00069   const std::string& log_fn() const { return log_fn_; }
00070   /** @return name of server certificate file */
00071   const std::string& cert_fn() const { return cert_fn_; }
00072   /** @return name of server key file */
00073   const std::string& key_fn() const { return key_fn_; }
00074   /** @return name of file containing process ID of this server */
00075   const std::string& pid_fn() const { return pid_fn_; }
00076 
00077   /** @return port number on which the server listens for connections */
00078   int port() const { return port_; }
00079   /** @return host name, in dot notation, of the server (this machine). */
00080   const std::string& host() const { return host_; }
00081 
00082   /** @return delay the server is prepared to wait for any
00083    * communication from the client, in millisec */
00084   size_t client_delay() const { return client_delay_; }
00085 
00086   /** @return reference to log output stream */
00087   std::ostream& log() { return *log_; }
00088   /** @return pointer to ticket database connection, never 0 */
00089   Dv::MySql::Db& db() { return *db_; }
00090 
00091   /** @return reference to authentictor object that is used by this server */
00092   Dv::Ticket::Authenticator& authenticator() { return authenticator_; }
00093 
00094   /** Create and store a new ticket for a user.
00095    * @param user which is supposed to have been authenticated
00096    * @param host for which ticket will be valid, in dot notation (e.g.  134.184.65.2)
00097    * @param duration that ticket will be valid, in minutes.
00098    * @exception Dv::Ticket::Exception if anything goes wrong
00099    */
00100   Dv::Ticket::Ticket::Ref make_ticket(const User& user, const std::string& host,
00101     size_t duration) throw (Dv::Ticket::Exception);
00102 
00103   /** Retrieve a ticket with a given serial number.
00104    * @param serial unique numeric ID of ticket
00105    * @param host that should be associated with the ticket
00106    * @exception Dv::Ticket::Exception if anything goes wrong,
00107    *  e.g. the ticket is no longer valid, or the ticket with the
00108    *  given id was issued for a different host.
00109    */
00110   Dv::Ticket::Ticket::Ref validate_ticket(Dv::Ticket::Ticket::SERIAL serial, const std::string& host)
00111     throw (Dv::Ticket::Exception);
00112   
00113 private:
00114 
00115   /** Initialize a server.
00116    * @param config XML root node containing configuration info
00117    * @exception Dv::Ticket::Exception if anything goes wrong,
00118    *  e.g. config is not valid w.r.t config_dtd_fn.
00119    */
00120   void init(const Dv::Xml::Node::Ref config) throw (Dv::Ticket::Exception);
00121 
00122   /** name of directory containing relevant DTD files */
00123   std::string dtd_dir_;
00124   /** configuration file name */
00125   std::string config_fn_;
00126   /** configuration DTD file name */
00127   std::string config_dtd_fn_;
00128   /** request DTD file name */
00129   std::string request_dtd_fn_;
00130   /** log DTD file name */
00131   std::string log_fn_;
00132   /** server certificate file name */
00133   std::string cert_fn_;
00134   /** server key file name */
00135   std::string key_fn_;
00136   /** name of file containing server process ID */
00137   std::string pid_fn_;
00138 
00139   /** port on which server is listening */
00140   int port_;
00141   /** this host */
00142   std::string host_;
00143   /** delay that the server is prepared to wait for any
00144    * communication from the client, in millisec */
00145   size_t client_delay_;
00146 
00147   /** reference to authentictor object that is used by this server */
00148   Dv::Ticket::Authenticator& authenticator_;
00149   /** pointer to ticket database connection, never 0 */
00150   Dv::MySql::Db* db_;
00151   /** pointer to log output stream, never 0 */
00152   std::ostream* log_;
00153   /** SSL context */
00154   Dv::Ssl::SslContextV23* ssl_context_;
00155   /** SSL server socket */
00156   Dv::Ssl::SslServerSocket* ssl_ss_;
00157 };
00158 
00159 } }
00160 #endif
00161 

dvticket-0.7.1 [24 October, 2003]