ircproxy The Ultimate Cyborg |
#include <Authentication.h>
This object keeps the data that is needed to connect to a server and authenticate with any services.
The information contained in it is received with The PASS and USER messages. It is assumed that the PASS message is always received first. At the moment the USER message is received, this object will be used to establish a connection with a server.
Definition at line 40 of file Authentication.h.
Public Member Functions | |
void | decode_pass (ClientMessageIn const &pass_msg) |
Decode a PASS message. | |
void | decode_user (ClientMessageIn const &user_msg) |
Decode a USER message. | |
void | send_authentication (ServerConnection &server_connection) |
Send the authentication messages to the server. | |
std::string const & | service_pass (void) const |
Return the Service password (used to login into X, for example). | |
~Authentication () | |
Destructor. | |
Authentication (Authentication const &authentication) | |
Copyconstructor. | |
Static Public Member Functions | |
static void | get (Identity *identity, boost::shared_ptr< Authentication > &ptr) |
Private Member Functions | |
Authentication (Identity *identity, boost::shared_ptr< Authentication > &ptr) | |
The constructor is private, use Authentication::get to get a pointer to an Authentication object. | |
void | received_nick_and_user (void) |
Called when both NICK and USER are received from the client. | |
Private Attributes | |
std::string | M_server_pass |
Server password. | |
std::string | M_service_pass |
Service password. | |
std::string | M_ident |
Ident string. | |
std::string | M_realname |
The real name. | |
boost::shared_ptr < Authentication > & | M_ptr |
Reference to the (only) pointer to this object. | |
bool | M_received_nick |
True if NICK was received from the client. | |
bool | M_received_user |
True if USER was received from the client. | |
Friends | |
std::ostream & | operator<< (std::ostream &, Authentication const &) |
For debugging purposes. Write a Authentication to os. |
Authentication::Authentication | ( | Identity * | identity, | |
boost::shared_ptr< Authentication > & | ptr | |||
) | [inline, private] |
The constructor is private, use Authentication::get to get a pointer to an Authentication object.
Definition at line 68 of file Authentication.h.
References debug::channels::dc::objects.
Referenced by get().
00068 : 00069 IdentityReference(identity), M_ptr(ptr), M_received_nick(false), M_received_user(false) 00070 { Dout(dc::objects, "Constructing Authentication " << *this); }
Authentication::~Authentication | ( | ) | [inline] |
Destructor.
Definition at line 78 of file Authentication.h.
00078 { Dout(dc::objects, "Destructing Authentication " << *this); }
Authentication::Authentication | ( | Authentication const & | authentication | ) | [inline] |
Copyconstructor.
Definition at line 81 of file Authentication.h.
References debug::channels::dc::objects.
00081 : 00082 IdentityReference(authentication), 00083 M_server_pass(authentication.M_server_pass), 00084 M_service_pass(authentication.M_service_pass), 00085 M_ident(authentication.M_ident), 00086 M_realname(authentication.M_realname), 00087 M_ptr(authentication.M_ptr), 00088 M_received_nick(authentication.M_received_nick), 00089 M_received_user(authentication.M_received_user) 00090 { Dout(dc::objects, "Copy-constructing Authentication from " << authentication); }
void Authentication::decode_pass | ( | ClientMessageIn const & | pass_msg | ) |
Decode a PASS message.
Definition at line 42 of file Authentication.cc.
References ASSERT, Identity::authentication_password(), DoutEntering, Identity::has_authentication_password(), IdentityReference::identity(), MessageIn::key(), M_server_pass, M_service_pass, MessageIn::param(), and THROW_EXCEPTION.
00043 { 00044 DoutEntering(dc::debug, "Authentication::decode_pass(" << pass_msg << ")"); 00045 ASSERT(pass_msg.key() == keys::PASS); 00046 00047 if (identity().has_authentication_password() && pass_msg.param(1) != identity().authentication_password()) 00048 THROW_EXCEPTION(FatalError("Bad authentication"), 00049 "Received pass \"" << pass_msg.param(1) << "\" is unequal expected pass \"" << 00050 identity().authentication_password() << '"'); 00051 00052 M_service_pass = pass_msg.param(2); 00053 M_server_pass = pass_msg.param(3); 00054 }
void Authentication::decode_user | ( | ClientMessageIn const & | user_msg | ) |
Decode a USER message.
Definition at line 74 of file Authentication.cc.
References ASSERT, DoutEntering, MessageIn::key(), M_ident, M_realname, M_received_nick, M_received_user, MessageIn::param(), and received_nick_and_user().
00075 { 00076 DoutEntering(dc::debug, "Authentication::decode_user(" << user_msg << ")"); 00077 ASSERT(user_msg.key() == keys::USER); 00078 00079 M_ident = user_msg.param(0); 00080 M_realname = user_msg.param(3); 00081 00082 M_received_user = true; 00083 if (M_received_nick) 00084 received_nick_and_user(); 00085 }
void Authentication::send_authentication | ( | ServerConnection & | server_connection | ) |
Send the authentication messages to the server.
Definition at line 101 of file Authentication.cc.
References DoutEntering, IdentityReference::identity(), M_ident, M_realname, M_server_pass, Identity::mynick(), NickPair::nick_received(), ServerSession::nicks(), NickPair::send_nick(), and ServerConnection::server_session().
Referenced by AuthState::AuthState().
00102 { 00103 DoutEntering(dc::debug, "Authentication::send_authentication(" << server_connection << ")"); 00104 00105 // Generate a new random nick! 00106 identity().mynick()->set_out_nick(server_connection.server_session(), random_nick()); 00107 00108 if (!M_server_pass.empty()) 00109 server_connection.server_session() << "PASS " << M_server_pass << "\r\n"; 00110 server_connection.server_session().nicks().send_nick(identity().mynick()->out_name(server_connection.server_session())); 00111 char service_mode = 'x'; // FIXME: also used in ServerConnection::send_pong_and_mode 00112 server_connection.server_session() << "USER " << M_ident << " +i" << service_mode << " myserver :" << M_realname << "\r\n"; 00113 00114 // No NICK confirmation is sent for our initial NICK, but no other nick can be used. Pretend we received a confirmation. 00115 identity().mynick()->set_in_nick(server_connection.server_session(), identity().mynick()->out_name(server_connection.server_session())); 00116 server_connection.server_session().nicks().nick_received(identity().mynick()->in_name(server_connection.server_session())); 00117 }
static void Authentication::get | ( | Identity * | identity, | |
boost::shared_ptr< Authentication > & | ptr | |||
) | [inline, static] |
Update ptr to point to the Authentication object for this Identity. If no Authentication object exists yet, it will be created.
Definition at line 60 of file Authentication.h.
References Authentication(), and IdentityReference::identity().
Referenced by Identity::new_client_message_received().
00061 { if (!ptr.get()) ptr.reset(NEW(Authentication(identity, ptr))); }
std::string const& Authentication::service_pass | ( | void | ) | const [inline] |
Return the Service password (used to login into X, for example).
Definition at line 64 of file Authentication.h.
References M_service_pass.
Referenced by ServerConnection::invisible_event().
00064 { return M_service_pass; }
void Authentication::received_nick_and_user | ( | void | ) | [private] |
Called when both NICK and USER are received from the client.
Definition at line 87 of file Authentication.cc.
References ServerConnection::connect(), DoutEntering, IdentityReference::identity(), and Identity::server_connection().
Referenced by decode_user().
00088 { 00089 DoutEntering(dc::debug, "Authentication::received_nick_and_user()"); 00090 00091 // Be kind and already try to connect to a server at this point. 00092 if (!identity().server_connection().is_connected()) 00093 identity().server_connection().connect(true); 00094 }
std::ostream& operator<< | ( | std::ostream & | , | |
Authentication const & | ||||
) | [friend] |
For debugging purposes. Write a Authentication to os.
Definition at line 360 of file debug_ostream_operators.cc.
00361 { 00362 os << "{server_pass:" << 00363 #ifdef PRINT_AUTHENTICATION 00364 authentication.M_server_pass 00365 #else 00366 "***" 00367 #endif 00368 ; 00369 os << ", service_pass:" << 00370 #ifdef PRINT_AUTHENTICATION 00371 authentication.M_service_pass 00372 #else 00373 "***" 00374 #endif 00375 ; 00376 os << ", ident:" << authentication.M_ident; 00377 os << ", realname:" << authentication.M_realname; 00378 os << ", received_nick:" << authentication.M_received_nick; 00379 os << ", received_user:" << authentication.M_received_user; 00380 return os << ' ' << static_cast<IdentityReference const&>(authentication) << '}'; 00381 }
std::string Authentication::M_server_pass [private] |
Server password.
Definition at line 42 of file Authentication.h.
Referenced by decode_pass(), operator<<(), and send_authentication().
std::string Authentication::M_service_pass [private] |
Service password.
Definition at line 43 of file Authentication.h.
Referenced by decode_pass(), operator<<(), and service_pass().
std::string Authentication::M_ident [private] |
Ident string.
Definition at line 44 of file Authentication.h.
Referenced by decode_user(), operator<<(), and send_authentication().
std::string Authentication::M_realname [private] |
The real name.
Definition at line 45 of file Authentication.h.
Referenced by decode_user(), operator<<(), and send_authentication().
boost::shared_ptr<Authentication>& Authentication::M_ptr [private] |
bool Authentication::M_received_nick [private] |
True if NICK was received from the client.
Definition at line 47 of file Authentication.h.
Referenced by decode_user(), and operator<<().
bool Authentication::M_received_user [private] |
True if USER was received from the client.
Definition at line 48 of file Authentication.h.
Referenced by decode_user(), and operator<<().
Copyright © 2005-2007 Carlo Wood. All rights reserved. |
---|