ircproxy The Ultimate Cyborg |
#include <MessageIn.h>
Definition at line 41 of file MessageIn.h.
Public Types | |
typedef std::vector< Part > | params_type |
Type of M_params. | |
Public Member Functions | |
void | init (msg_block_ct msg_block) |
(re)initialize this MessageIn. | |
bool | uninitialized (void) const |
Return true if this MessageIn is still uninitialized. | |
bool | is_numeric (void) const |
Returns true when this message is a numeric reply. | |
int | numeric (void) const |
The numeric value of this numeric reply. | |
int | key (void) const |
Numeric representation of command or numeric. | |
params_type::size_type | params_size (void) const |
The number of parameters. | |
params_type const & | params (void) const |
A const reference to the vector with parameter Parts. | |
std::string | param (size_t n) const |
Returns parameter n as a std::string. The result is empty if there no such parameter. | |
MsgPart | params (size_t n) const |
Returns parameters n and higher as MsgPart. The result is empty if there no such parameter. | |
bool | has_prefix (void) const |
Returns true if there is a prefix. | |
std::string | prefix_str (void) const |
The prefix. | |
Part | prefix_part (void) const |
The prefix. The returned Part is only valid as long as the MessageIn is not destructed. | |
Prefix | prefix (void) const |
The prefix. | |
std::string | command_str (void) const |
The command as received. | |
Part const & | command_part (void) const |
The command. The returned Part is only valid as long as the MessageIn is not destructed. | |
char const * | uppercase_command (void) const |
The command as uppercase C string. | |
char const * | end (void) const |
Pointer to one beyond the end of the message. | |
Protected Member Functions | |
MessageIn (void) | |
Construct an uninitialized MessageIn. | |
virtual bool | is_server_message (void) const =0 |
Return true if this is a ServerMessageIn. | |
virtual ServerSession & | priv_server_session (void) const =0 |
The session of the derived class. | |
virtual ClientSession & | priv_client_session (void) const =0 |
The session of the derived class. | |
Private Attributes | |
msg_block_ct | M_msg_block |
Message block to keep message alive as long as we use it. | |
char const * | M_end |
Points one after the message (at '\r' or '\n'). | |
Part | M_prefix |
The prefix (without colon). | |
Part | M_command |
The command or numeric. | |
int | M_key |
The command or numeric as integer. | |
Keyword const * | M_keyword_ptr |
Pointer to Keyword struct, if the command is a known command. | |
params_type | M_params |
The command parameters. | |
Classes | |
class | Part |
Part of an MessageIn. More... |
typedef std::vector<Part> MessageIn::params_type |
MessageIn::MessageIn | ( | void | ) | [protected] |
Construct an uninitialized MessageIn.
Definition at line 27 of file MessageIn.cc.
References debug::channels::dc::objects.
00027 : M_msg_block(Application::instance().dummy_msg_block()) 00028 { 00029 Dout(dc::objects, "Constructing MessageIn()"); 00030 }
void MessageIn::init | ( | msg_block_ct | msg_block | ) |
(re)initialize this MessageIn.
Definition at line 32 of file MessageIn.cc.
References ASSERT, MessageIn::Part::clear(), is_numeric(), MessageIn::Part::len(), M_command, M_end, M_key, M_keyword_ptr, M_msg_block, M_params, M_prefix, MessageIn::Part::set(), and Keyword::value.
Referenced by ServerSessionInput::decode(), and ClientSessionInput::decode().
00033 { 00034 M_msg_block = msg_block; // Don't delete message until we are done with it. 00035 char const* p = msg_block.get_start(); 00036 char const* e = p + msg_block.get_size(); 00037 ASSERT(msg_block.get_size() > 0); 00038 --e; // Ignore new-line. 00039 ASSERT(*e == '\n'); 00040 if (e[-1] == '\r') 00041 --e; // Ignore carriage-return; 00042 M_end = e; 00043 while (*p == ' ') // Trailing spaces are ignored by the IRC server. 00044 ++p; // Advance to first token. 00045 00046 // Decode prefix, if any. 00047 if (*p == ':') 00048 { 00049 char const* prefix_start = p + 1; // Skip the colon. 00050 while (p < e && *++p != ' '); // Find the end of the prefix. 00051 M_prefix.set(prefix_start, p); 00052 while (*p == ' ') // Multiple spaces are treated as one by the IRC server. 00053 ++p; // Advance to command. 00054 } 00055 else 00056 M_prefix.clear(); 00057 00058 // Decode command. 00059 if (p == e) // No command? 00060 { 00061 M_command.clear(); 00062 M_params.clear(); 00063 return; 00064 } 00065 char const* start = p; 00066 while (p < e && *++p != ' '); 00067 M_command.set(start, p); 00068 if (is_numeric()) 00069 M_key = atoi(start); 00070 else 00071 { 00072 M_key = 0; // Default value, means: unknown command. 00073 static char buf[MAX_WORD_LENGTH]; // MAX_WORD_LENGTH is defined in msg_key.h. 00074 if (M_command.len() <= sizeof(buf)) 00075 { 00076 for (size_t i = 0; i < M_command.len(); ++i) 00077 buf[i] = std::toupper(start[i]); 00078 M_keyword_ptr = msg_key(buf, M_command.len()); 00079 if (M_keyword_ptr) 00080 M_key = M_keyword_ptr->value; // Uppercase value is now available in M_keyword_ptr->name. 00081 } 00082 } 00083 00084 // Decode possible parameters. 00085 M_params.clear(); 00086 for (; p < e; ++p) 00087 { 00088 if (*p == ' ') // Skip space till next token. 00089 continue; 00090 if (p == e) // No more tokens? 00091 return; 00092 start = p; 00093 if (*p == ':') // Found last token? 00094 { 00095 M_params.push_back(Part(p + 1, e)); // Skip colon. 00096 return; 00097 } 00098 while (p < e && *++p != ' '); // Find end of token. 00099 M_params.push_back(Part(start, p)); 00100 } 00101 }
bool MessageIn::uninitialized | ( | void | ) | const [inline] |
Return true if this MessageIn is still uninitialized.
Definition at line 91 of file MessageIn.h.
References M_msg_block.
Referenced by operator<<().
00091 { return M_msg_block.get_size() == 0; }
bool MessageIn::is_numeric | ( | void | ) | const [inline] |
Returns true when this message is a numeric reply.
Definition at line 94 of file MessageIn.h.
References M_command, and MessageIn::Part::start().
Referenced by init(), numeric(), and Identity::pass_as_is_to().
int MessageIn::numeric | ( | void | ) | const [inline] |
The numeric value of this numeric reply.
Definition at line 97 of file MessageIn.h.
References ASSERT, is_numeric(), and M_key.
Referenced by Identity::pass_as_is_to().
00097 { ASSERT(is_numeric()); return M_key; }
int MessageIn::key | ( | void | ) | const [inline] |
Numeric representation of command or numeric.
Definition at line 100 of file MessageIn.h.
References M_key.
Referenced by Authentication::decode_pass(), Authentication::decode_user(), MatchRequestList::is_match(), QuestionTarget::new_client_message_received(), PrivateTarget::new_client_message_received(), NoticeTarget::new_client_message_received(), Identity::new_client_message_received(), Channel::new_client_message_received(), ServerSession::new_message_received(), ClientSession::new_message_received(), Identity::new_server_message_received(), Channel::new_server_message_received(), operator<<(), Identity::pass_as_is_to_server(), ServerSession::queue_msg_as_is(), ClientSession::queue_msg_as_is(), and ClientSession::queue_msg_me_as_is().
00100 { return M_key; }
params_type::size_type MessageIn::params_size | ( | void | ) | const [inline] |
The number of parameters.
Definition at line 103 of file MessageIn.h.
References M_params.
Referenced by Identity::new_client_message_received(), ServerSession::new_message_received(), and Identity::pass_as_is_to().
00103 { return M_params.size(); }
params_type const& MessageIn::params | ( | void | ) | const [inline] |
A const reference to the vector with parameter Parts.
Definition at line 106 of file MessageIn.h.
References M_params.
Referenced by Matcher::match(), Identity::new_client_message_received(), Channel::new_client_message_received(), ServerSession::new_message_received(), Identity::new_server_message_received(), Channel::new_server_message_received(), operator<<(), ServerSession::queue_msg_as_is(), ClientSession::queue_msg_as_is(), and ClientSession::queue_msg_me_as_is().
00106 { return M_params; }
std::string MessageIn::param | ( | size_t | n | ) | const [inline] |
Returns parameter n as a std::string. The result is empty if there no such parameter.
Definition at line 109 of file MessageIn.h.
References M_params.
Referenced by Authentication::decode_pass(), ServerConnection::decode_ping(), Authentication::decode_user(), ServerConnection::error_message_received(), PrivateTarget::handle_command(), QuestionTarget::new_client_message_received(), PrivateTarget::new_client_message_received(), Identity::new_client_message_received(), Channel::new_client_message_received(), ServerSession::new_message_received(), ClientSession::new_message_received(), UserMode::new_server_message_received(), Identity::new_server_message_received(), Channel::new_server_message_received(), Identity::pass_as_is_to(), and ClientSession::queue_msg_me_as_is().
00110 { 00111 std::string result; 00112 if (n < M_params.size()) 00113 result.assign(M_params[n].start(), M_params[n].len()); 00114 return result; 00115 }
MsgPart MessageIn::params | ( | size_t | n | ) | const [inline] |
Returns parameters n and higher as MsgPart. The result is empty if there no such parameter.
Definition at line 168 of file MessageIn.h.
References MessageIn::Part::clear(), M_end, M_msg_block, M_params, and MessageIn::Part::set().
00169 { 00170 MsgPart result(M_msg_block); 00171 if (n < M_params.size()) 00172 { 00173 char const* start = M_params[n].start(); 00174 if (n == M_params.size() - 1 && start[-1] == ':') 00175 --start; 00176 result.set(start, M_end); 00177 } 00178 else 00179 result.clear(); 00180 return result; 00181 }
bool MessageIn::has_prefix | ( | void | ) | const [inline] |
Returns true if there is a prefix.
Definition at line 121 of file MessageIn.h.
References M_prefix, and MessageIn::Part::start().
Referenced by operator<<(), Identity::pass_as_is_to(), Prefix::Prefix(), prefix(), prefix_part(), and prefix_str().
std::string MessageIn::prefix_str | ( | void | ) | const [inline] |
The prefix.
Definition at line 124 of file MessageIn.h.
References ASSERT, has_prefix(), MessageIn::Part::len(), M_prefix, and MessageIn::Part::start().
Referenced by ServerSession::new_message_received(), Channel::new_server_message_received(), Identity::pass_as_is_to(), Prefix::Prefix(), and prefix().
Part MessageIn::prefix_part | ( | void | ) | const [inline] |
The prefix. The returned Part is only valid as long as the MessageIn is not destructed.
Definition at line 127 of file MessageIn.h.
References ASSERT, has_prefix(), and M_prefix.
Referenced by Matcher::match(), operator<<(), and ServerConnection::received_first_umode().
00127 { ASSERT(has_prefix()); return M_prefix; }
Prefix MessageIn::prefix | ( | void | ) | const [inline] |
The prefix.
Definition at line 130 of file MessageIn.h.
References has_prefix(), is_server_message(), prefix_str(), priv_client_session(), and priv_server_session().
Referenced by Identity::new_server_message_received().
00131 { return has_prefix() ? (is_server_message() ? Prefix(priv_server_session(), prefix_str()) : Prefix(priv_client_session(), prefix_str())) : Prefix(); }
std::string MessageIn::command_str | ( | void | ) | const [inline] |
The command as received.
Definition at line 134 of file MessageIn.h.
References MessageIn::Part::len(), M_command, and MessageIn::Part::start().
Part const& MessageIn::command_part | ( | void | ) | const [inline] |
The command. The returned Part is only valid as long as the MessageIn is not destructed.
Definition at line 137 of file MessageIn.h.
References M_command.
Referenced by operator<<().
00137 { return M_command; }
char const* MessageIn::uppercase_command | ( | void | ) | const [inline] |
The command as uppercase C string.
Definition at line 140 of file MessageIn.h.
References ASSERT, M_key, M_keyword_ptr, and Keyword::name.
Referenced by Identity::pass_as_is_to().
00140 { ASSERT(M_key < 0); return M_keyword_ptr->name; }
char const* MessageIn::end | ( | void | ) | const [inline] |
Pointer to one beyond the end of the message.
Definition at line 143 of file MessageIn.h.
References M_end.
Referenced by Matcher::match().
00143 { return M_end; }
virtual bool MessageIn::is_server_message | ( | void | ) | const [protected, pure virtual] |
Return true if this is a ServerMessageIn.
Implemented in ClientMessageIn, and ServerMessageIn.
Referenced by prefix().
virtual ServerSession& MessageIn::priv_server_session | ( | void | ) | const [protected, pure virtual] |
The session of the derived class.
Implemented in ClientMessageIn, and ServerMessageIn.
Referenced by prefix().
virtual ClientSession& MessageIn::priv_client_session | ( | void | ) | const [protected, pure virtual] |
The session of the derived class.
Implemented in ClientMessageIn, and ServerMessageIn.
Referenced by prefix().
msg_block_ct MessageIn::M_msg_block [private] |
Message block to keep message alive as long as we use it.
Definition at line 74 of file MessageIn.h.
Referenced by init(), params(), and uninitialized().
char const* MessageIn::M_end [private] |
Part MessageIn::M_prefix [private] |
The prefix (without colon).
Definition at line 76 of file MessageIn.h.
Referenced by has_prefix(), init(), prefix_part(), and prefix_str().
Part MessageIn::M_command [private] |
The command or numeric.
Definition at line 77 of file MessageIn.h.
Referenced by command_part(), command_str(), init(), and is_numeric().
int MessageIn::M_key [private] |
The command or numeric as integer.
Definition at line 78 of file MessageIn.h.
Referenced by init(), key(), numeric(), and uppercase_command().
Keyword const* MessageIn::M_keyword_ptr [private] |
Pointer to Keyword struct, if the command is a known command.
Definition at line 79 of file MessageIn.h.
Referenced by init(), and uppercase_command().
params_type MessageIn::M_params [private] |
The command parameters.
Definition at line 80 of file MessageIn.h.
Referenced by init(), param(), params(), and params_size().
Copyright © 2005-2007 Carlo Wood. All rights reserved. |
---|