00001 #ifndef DV_TICKET_TICKET_H 00002 #define DV_TICKET_TICKET_H 00003 00004 // $Id: ticket.h,v 1.13 2003/09/18 13:02:25 dvermeir Exp $ 00005 #include <string> 00006 #include <set> 00007 #include <iostream> 00008 00009 #include <dvticket/user.h> 00010 #include <dvutil/date.h> 00011 #include <dvutil/ref.h> 00012 00013 namespace Dv { 00014 namespace Ticket { 00015 00016 class Server; 00017 00018 /** Class representing a ticket. */ 00019 class Ticket { 00020 friend class Server; 00021 00022 public: 00023 00024 /** Type of serial number of ticket. */ 00025 typedef unsigned long SERIAL; 00026 /** Type of reference-counted pointer to ticket. */ 00027 typedef Dv::Util::ref<Dv::Ticket::Ticket> Ref; 00028 00029 /** @return Owner of this ticket. */ 00030 const User& user() const { return user_; } 00031 /** @return Serial number of this ticket. */ 00032 SERIAL serial() const { return serial_; } 00033 /** @return expiration date of this ticket */ 00034 const Dv::Util::Date& expiration_date() const { return expiration_date_; } 00035 /** @return host of server that issued this ticket */ 00036 const std::string& server_host() const { return server_host_; } 00037 /** @return port of server that issued this ticket */ 00038 const int server_port() const { return server_port_; } 00039 /** @return host for which this ticket is valid */ 00040 const std::string& owner_host() const { return owner_host_; } 00041 00042 /** Return an XML representation of a ticket. 00043 * @param name to be used as the root tag 00044 * @return root node of XML representation 00045 */ 00046 Dv::Xml::Node xml(const std::string& name="ticket") const; 00047 00048 /** Obtain a new ticket from a ticket server. 00049 * @param host name of ticket server 00050 * @param port on which ticket server is listening 00051 * @param name of user to obtain ticket for 00052 * @param password of user to obtain ticket for 00053 * @param info to be added to (user date member) in ticket 00054 * @param duration (in minutes) that ticket should remain valid. 00055 * @return a reference-counted pointer to a valid ticket, 00056 * or a nil pointer. 00057 * @sa Dv::Ticket::Authenticator 00058 */ 00059 static Ref buy(const std::string& host, int port, const std::string& name, 00060 const std::string& password, const std::string& info="", size_t duration=30) 00061 throw (); 00062 00063 /** Obtain a new ticket from a ticket server. This function 00064 * explicitly specifies the client host, which may be different 00065 * from the host on which this function is called. 00066 * It is useful e.g. for general "login" cgi programs. Such 00067 * programs avoid user programs to deal with passwords. 00068 * @param client_host name of ticket server 00069 * @param server_host name of ticket server 00070 * @param port on which ticket server is listening 00071 * @param name of user to obtain ticket for 00072 * @param password of user to obtain ticket for 00073 * @param info to be added to (user date member) in ticket 00074 * @param duration (in minutes) that ticket should remain valid. 00075 * @return a reference-counted pointer to a valid ticket, 00076 * or a nil pointer. 00077 * @warning This function must be called from the same host 00078 * as the one running the ticket server. 00079 * @sa Dv::Ticket::Authenticator 00080 */ 00081 static Ref buy(const std::string& client_host, const std::string& server_host, int port, 00082 const std::string& name, const std::string& password, const std::string& info="", 00083 size_t duration=30) throw (); 00084 00085 /** Buy an anonymous ticket from a ticket server. 00086 * @param host name of ticket server 00087 * @param port on which ticket server is listening 00088 * @param name of user to obtain ticket for 00089 * @param info to be added to (user date member) in ticket 00090 * @param duration (in minutes) that ticket should remain valid. 00091 * @return a reference-counted pointer to a valid ticket, 00092 * or a nil pointer. The ticket user will have "anonymous" 00093 * as its category. 00094 * @sa Dv::Ticket::User 00095 * @sa Dv::Ticket::Authenticator 00096 */ 00097 static Ref buy_anon(const std::string& host, int port, const std::string& name="anonymous", 00098 const std::string& info="", size_t duration=30) throw (); 00099 00100 00101 /** Obtain a ticket by validating a serial number with a ticket 00102 * server. 00103 * @param server_host name of ticket server 00104 * @param server_port on which ticket server is listening 00105 * @param serial number of previously obtained ticket 00106 * @return a reference-counted pointer to a valid ticket, 00107 * or a nil pointer. 00108 */ 00109 static Ref validate(const std::string& server_host, int server_port, SERIAL serial) 00110 throw (); 00111 00112 /** Obtain a ticket by validating a serial number with a ticket 00113 * server. 00114 * @param server_host name of ticket server 00115 * @param server_port on which ticket server is listening 00116 * @param host dot address of owner host of ticket 00117 * @param serial number of previously obtained ticket 00118 * @return a reference-counted pointer to a valid ticket, 00119 * or a nil pointer. 00120 */ 00121 static Ref validate(const std::string& server_host, int server_port, 00122 const std::string& host, SERIAL serial) throw (); 00123 00124 private: 00125 /** Copy ctor is forbidden. */ 00126 Ticket(const Ticket&); 00127 /** Assignment is forbidden. */ 00128 Ticket& operator=(const Ticket&); 00129 00130 /** Simple ctor. 00131 * @param user which is supposed to have been authenticated 00132 * @param serial unique numeric ID of ticket 00133 * @param expiration_date when ticket expires 00134 * @param server_host host of server issuing ticket 00135 * @param server_port host of server issuing ticket 00136 * @param owner_host host for which this ticket is valid (in dot notation) 00137 */ 00138 Ticket(const User& user, SERIAL serial, Dv::Util::Date expiration_date, 00139 const std::string& server_host, int server_port, const std::string& owner_host) throw (): 00140 user_(user), serial_(serial), expiration_date_(expiration_date), 00141 server_host_(server_host), server_port_(server_port), owner_host_(owner_host) {} 00142 00143 /** Simple ctor. 00144 * @param root Xml node containing XML representation of ticket 00145 * @param server_host host of server issuing ticket 00146 * @param server_port host of server issuing ticket 00147 * @exception std::exception if xml node is not correct format 00148 */ 00149 Ticket(const Dv::Xml::Node::Ref& root, const std::string& server_host, int server_port); 00150 00151 00152 /** User to whom this ticket was issued. */ 00153 User user_; 00154 /** Host for which this ticket was issued. */ 00155 // std::string host_; 00156 /** Unique serial number of this ticket. */ 00157 SERIAL serial_; 00158 /** Expiration date for this ticket. */ 00159 Dv::Util::Date expiration_date_; 00160 /** Host of server that issued this ticket. */ 00161 std::string server_host_; 00162 /** Port of server that issued this ticket. */ 00163 int server_port_; 00164 /** Name of host for which this ticket is valid. */ 00165 std::string owner_host_; 00166 }; 00167 00168 }} 00169 00170 #endif
dvticket-0.7.1 | [24 October, 2003] |