00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef USE_PCH
00017 #include "sys.h"
00018
00019 #endif
00020
00021 #ifdef CWDEBUG
00022
00023 #ifndef USE_PCH
00024 #include <iostream>
00025 #include <libcw/support.h>
00026 #include "debug.h"
00027 #include <libcwd/buf2str.h>
00028 #include <libcwd/cwprint.h>
00029 #endif
00030
00031 #include "casereturnstr.h"
00032 #include "PersistXML.h"
00033 #include "Network.h"
00034 #include "MessageIn.h"
00035 #include "UserAnswer.h"
00036 #include "Identity.h"
00037 #include "IdentityReference.h"
00038 #include "Authentication.h"
00039 #include "Channel.h"
00040 #include "Nick.h"
00041 #include "ClientSession.h"
00042 #include "QuestionTarget.h"
00043 #include "NoticeTarget.h"
00044 #include "ServerSession.h"
00045 #include "DestructEvent.h"
00046 #include "ServerConnection.h"
00047 #include "Expression.h"
00048 #include "keys.h"
00049 #include "Matcher.h"
00050 #include "Prefix.h"
00051 #include "JustInTime.h"
00052 #include "PseudoMessageEvent.h"
00053 #include "Member.h"
00054 #include "WhoRequest.h"
00055
00056 namespace debug {
00057
00058
00059
00060
00061
00062 char const* state_nt_name(state_nt state)
00063 {
00064 switch(state)
00065 {
00066
00067 CASERETURNSTR(disconnected);
00068 CASERETURNSTR(successful_connect);
00069 CASERETURNSTR(authentication_started);
00070 CASERETURNSTR(pong_sent);
00071 CASERETURNSTR(login_sent);
00072 CASERETURNSTR(real_nick_sent);
00073 CASERETURNSTR(real_nick_accepted);
00074 }
00075 DoutFatal(dc::fatal, "Unhandled state_nt in state_nt_name");
00076 }
00077
00078
00079
00080
00081
00082 char const* openmode_name(PersistXML::openmode_type openmode)
00083 {
00084 switch(openmode)
00085 {
00086
00087 CASERETURNSTR(PersistXML::not_open);
00088 CASERETURNSTR(PersistXML::store);
00089 CASERETURNSTR(PersistXML::load);
00090 }
00091 DoutFatal(dc::fatal, "Unhandled PersistXML::openmode in openmode_name");
00092 }
00093
00094
00095
00096
00097
00098 char const* match0_type_name(match0_type mt)
00099 {
00100 switch(mt)
00101 {
00102
00103 CASERETURNSTR(anystring_mt);
00104 CASERETURNSTR(nonemptystring_mt);
00105 CASERETURNSTR(anyserver_mt);
00106 CASERETURNSTR(localserver_mt);
00107 CASERETURNSTR(anynick_mt);
00108 CASERETURNSTR(mynick_mt);
00109 CASERETURNSTR(anychannel_mt);
00110 CASERETURNSTR(anyglobalchannel_mt);
00111 CASERETURNSTR(anylocalchannel_mt);
00112 }
00113 DoutFatal(dc::fatal, "Unhandled match0_type in match0_type_name");
00114 }
00115
00116
00117
00118
00119
00120 char const* match1_type_name(match1_type mt)
00121 {
00122 switch(mt)
00123 {
00124
00125 CASERETURNSTR(wildcard_mt);
00126 CASERETURNSTR(regexp_mt);
00127 CASERETURNSTR(exactmatch_mt);
00128 }
00129 DoutFatal(dc::fatal, "Unhandled match1_type in match1_type_name");
00130 }
00131
00132
00133
00134
00135
00136 char const* command_name(int command)
00137 {
00138 using namespace keys;
00139 switch(command)
00140 {
00141
00142 CASERETURNSTR(PASS);
00143 CASERETURNSTR(USER);
00144 CASERETURNSTR(NICK);
00145 CASERETURNSTR(PING);
00146 CASERETURNSTR(ERROR);
00147 CASERETURNSTR(QUIT);
00148 CASERETURNSTR(WHO);
00149 CASERETURNSTR(WHOIS);
00150 CASERETURNSTR(WHOWAS);
00151 CASERETURNSTR(PRIVMSG);
00152 CASERETURNSTR(NOTICE);
00153 CASERETURNSTR(CPRIVMSG);
00154 CASERETURNSTR(CNOTICE);
00155 CASERETURNSTR(LINKS);
00156 CASERETURNSTR(JOIN);
00157 CASERETURNSTR(PART);
00158 CASERETURNSTR(KICK);
00159 CASERETURNSTR(MODE);
00160 CASERETURNSTR(NAMES);
00161 CASERETURNSTR(TOPIC);
00162 }
00163 DoutFatal(dc::fatal, "Unhandled command key in command_name");
00164 }
00165
00166 }
00167
00168
00169 std::ostream& operator<<(std::ostream& os, state_nt state)
00170 {
00171 return os << debug::state_nt_name(state);
00172 }
00173
00174
00175 std::ostream& operator<<(std::ostream& os, PersistXML::openmode_type openmode)
00176 {
00177 return os << debug::openmode_name(openmode);
00178 }
00179
00180
00181 std::ostream& operator<<(std::ostream& os, match0_type mt)
00182 {
00183 return os << debug::match0_type_name(mt);
00184 }
00185
00186
00187 std::ostream& operator<<(std::ostream& os, match1_type mt)
00188 {
00189 return os << debug::match1_type_name(mt);
00190 }
00191
00192
00193 std::ostream& operator<<(std::ostream& os, Application const& LIBCW_UNUSED(application))
00194 {
00195 return os << "(application)";
00196 }
00197
00198
00199 std::ostream& operator<<(std::ostream& os, Network const& network)
00200 {
00201 os << "{name:" << network.name();
00202 if (network.has_domain())
00203 os << ", domain:" << network.domain();
00204 os << ", servers:{";
00205 Network::servers_type::const_iterator iter = network.servers().begin();
00206 if (iter != network.servers().end())
00207 {
00208 os << *iter;
00209 while (++iter != network.servers().end())
00210 os << ", " << *iter;
00211 }
00212 return os << "}}";
00213 }
00214
00215
00216 std::ostream& operator<<(std::ostream& os, Server const& server)
00217 {
00218 os << "{hostname:" << server.hostname() <<
00219 ", irc_name:" << server.get_irc_name() <<
00220 ", ports:{";
00221 Server::ports_type::const_iterator iter = server.ports().begin();
00222 if (iter != server.ports().end())
00223 {
00224 os << *iter;
00225 while (++iter != server.ports().end())
00226 os << ", " << *iter;
00227 }
00228 os << "}, last_connection_event:" << server.last_connection_event();
00229 return os << '}';
00230 }
00231
00232
00233 std::ostream& operator<<(std::ostream& os, MessageIn const& msg)
00234 {
00235 os << '{';
00236 if (msg.uninitialized())
00237 return os << "<uninitialized>}";
00238 if (msg.has_prefix())
00239 os << "prefix:\"" << libcwd::buf2str(msg.prefix_part().start(), msg.prefix_part().len()) << "\", ";
00240 if (msg.command_part().start())
00241 os << "command:\"" <<
00242 libcwd::buf2str(msg.command_part().start(), msg.command_part().len()) << "\" [key:" << msg.key() << "]";
00243 os << ", params:{";
00244 MessageIn::params_type::const_iterator iter = msg.params().begin();
00245 if (iter != msg.params().end())
00246 {
00247 os << *iter;
00248 while(++iter != msg.params().end())
00249 os << ", " << *iter;
00250 }
00251 return os << "}}";
00252 }
00253
00254
00255 std::ostream& operator<<(std::ostream& os, ClientMessageIn const& msg)
00256 {
00257 return os << "{client_session:" << msg.client_session() <<
00258 "; MessageIn:" << *static_cast<MessageIn const*>(&msg) << '}';
00259 }
00260
00261
00262 std::ostream& operator<<(std::ostream& os, ServerMessageIn const& msg)
00263 {
00264 return os << "{server_session:" << msg.server_session() <<
00265 "; MessageIn:" << *static_cast<MessageIn const*>(&msg) << '}';
00266 }
00267
00268
00269 std::ostream& operator<<(std::ostream& os, UserAnswerRequestData const& request_data)
00270 {
00271 return os << '{' << "question:\"" << request_data.question() << "\" [client_session:" << request_data.client_session() << "]}";
00272 }
00273
00274
00275 std::ostream& operator<<(std::ostream& os, UserAnswer const& answer)
00276 {
00277 os << '{' << "answer:\"" << answer.M_answer;
00278 os << "\", client_session:" << answer.M_client_session;
00279 os << ", target:\"" << answer.M_target_name;
00280 os << "\"}";
00281 return os;
00282 }
00283
00284
00285 std::ostream& operator<<(std::ostream& os, UserAnswerEventRequestBase const& request)
00286 {
00287 os << "{request_data:" << request.M_request_data;
00288 if (request.M_target.get())
00289 os << ", target:" << *request.M_target.get();
00290 return os << '}';
00291 }
00292
00293
00294 std::ostream& operator<<(std::ostream& os, Identity const& identity)
00295 {
00296 os << "{key:" << identity.M_key;
00297 #ifdef VERBOSE_IDENTITY
00298 #ifdef PRINT_AUTHENTICATION
00299 if (identity.M_authentication.get())
00300 os << ", authentication:" << *identity.M_authentication.get();
00301 os << ", server_connection:" << identity.M_server_connection;
00302 if (!identity.M_authpass.empty())
00303 os << ", authpass:" << identity.M_authpass;
00304 #endif
00305 os << ", private_network:" << identity.M_private_network;
00306 if (identity.M_client_session)
00307 os << ", client_session:" << *identity.M_client_session;
00308 os << ", ident:\"" << identity.M_ident <<
00309 "\", hostname:\"" << identity.M_hostname <<
00310 "\", real_name:\"" << identity.M_real_name <<
00311 "\", network_name:\"" << identity.M_network_name << '"';
00312 #endif
00313 os << '}';
00314 return os;
00315 }
00316
00317
00318 std::ostream& operator<<(std::ostream& os, ServerConnection const& server_connection)
00319 {
00320 os << "{server:";
00321 if (server_connection.M_server.get())
00322 os << *server_connection.M_server.get();
00323 else
00324 os << "<none>";
00325 os << "; server_session:";
00326 if (server_connection.has_server_session())
00327 os << server_connection.server_session();
00328 else
00329 os << "<NULL>";
00330 os << "; reconnect:";
00331 if (server_connection.reconnect())
00332 os << "true";
00333 else
00334 os << "false";
00335 os << "; connected:";
00336 if (server_connection.is_connected())
00337 os << "true";
00338 else
00339 os << "false";
00340 os << "; state:" << server_connection.state();
00341 os << "; connect_delay:" << server_connection.connect_delay();
00342 os << "; timed_out:";
00343 if (server_connection.timed_out())
00344 os << "true";
00345 else
00346 os << "false";
00347 os << "; timed_out_count:" << server_connection.timed_out_count();
00348 os << "; secondary_connection:" << server_connection.secondary_connection();
00349 return os << '}';
00350 }
00351
00352
00353 std::ostream& operator<<(std::ostream& os, IdentityReference const& identity_reference)
00354 {
00355 os << "[identity:" << identity_reference.identity().key() << ']';
00356 return os;
00357 }
00358
00359
00360 std::ostream& operator<<(std::ostream& os, Authentication const& authentication)
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 }
00382
00383
00384 std::ostream& operator<<(std::ostream& os, Channel const& channel)
00385 {
00386 os << "{Channel " << static_cast<Target const&>(channel);
00387 return os << '}';
00388 }
00389
00390
00391 std::ostream& operator<<(std::ostream& os, Nick const& nick)
00392 {
00393 os << "{Nick " << static_cast<Target const&>(nick);
00394 return os;
00395 }
00396
00397
00398 std::ostream& operator<<(std::ostream& os, ClientSession const& client_session)
00399 {
00400 os << "{ClientSession ";
00401 if (client_session.has_identity())
00402 os << static_cast<IdentityReference const&>(client_session);
00403 else
00404 os << "with no Identity";
00405 return os << '}';
00406 }
00407
00408
00409 std::ostream& operator<<(std::ostream& os, QuestionTarget const& question_target)
00410 {
00411 os << "{QuestionTarget " << static_cast<Target const&>(question_target) << '}';
00412 return os;
00413 }
00414
00415 std::ostream& operator<<(std::ostream& os, NoticeTarget const& notice_target)
00416 {
00417 os << "{NoticeTarget " << static_cast<Target const&>(notice_target) << '}';
00418 return os;
00419 }
00420
00421
00422 std::ostream& operator<<(std::ostream& os, ServerSession const& server_session)
00423 {
00424 os << "{ServerSession ";
00425 os << static_cast<IdentityReference const&>(server_session);
00426 return os << '}';
00427 }
00428
00429
00430 std::ostream& operator<<(std::ostream& os, Target const& target)
00431 {
00432
00433 os << "{FIXME";
00434 return os << '}';
00435 }
00436
00437
00438 std::ostream& operator<<(std::ostream& os, PseudoMessageEventRequestData const& request_data)
00439 {
00440 os << "{PseudoMessageEventRequestData FIXME";
00441 return os << '}';
00442 }
00443
00444
00445 std::ostream& operator<<(std::ostream& os, MessageOutData const& data)
00446 {
00447 os << "{message:";
00448 #if 0
00449 for (std::vector<boost::shared_ptr<JustInTimeToken> >::const_iterator iter = data.M_tokens.begin(); iter != data.M_tokens.end(); ++iter)
00450 {
00451 std::string str1((*iter)->value(serverside));
00452 std::string str2((*iter)->value(clientside));
00453 if (str1 == str2)
00454 os << '{' << libcwd::buf2str(str1.data(), str1.length()) << '}';
00455 else
00456 os << "{serverside:" << libcwd::buf2str(str1.data(), str1.length()) << ", clientside:" << libcwd::buf2str(str2.data(), str2.length()) << '}';
00457 }
00458 #else
00459 os << "FIXME";
00460 #endif
00461 os << "}, priority:" << data.M_priority;
00462 return os << '}';
00463 }
00464
00465
00466 std::ostream& operator<<(std::ostream& os, MessageOut const& message)
00467 {
00468 os << "{data:" << *message.M_data;
00469 return os << '}';
00470 }
00471
00472
00473 std::ostream& operator<<(std::ostream& os, Priority const& priority)
00474 {
00475
00476 os << "{<priority>";
00477 return os << '}';
00478 }
00479
00480
00481 std::ostream& operator<<(std::ostream& os, timeval const& time)
00482 {
00483 return os << "{tv_sec:" << time.tv_sec << ", tv_usec:" << time.tv_usec << '}';
00484 }
00485
00486
00487 std::ostream& operator<<(std::ostream& os, regex_t const&)
00488 {
00489 os << "{<compiled>";
00490 return os << '}';
00491 }
00492
00493
00494 std::ostream& operator<<(std::ostream& os, ExpressionEventType const& event_type)
00495 {
00496 os << "{expression_value:" << (event_type.M_expression_value ? "true" : "false");
00497 os << ", expression:\"";
00498 event_type.M_expression->print_on(os);
00499 return os << "\"}";
00500 }
00501
00502
00503 std::ostream& operator<<(std::ostream& os, ExpressionEventServer const& expression_event_server)
00504 {
00505 os << "{expression:\"";
00506 expression_event_server.M_expression->print_on(os);
00507 os << "\", ok:" << (expression_event_server.M_ok ? "true" : "false");
00508 os << ", evaluation:" << (expression_event_server.M_evaluation ? "true" : "false");
00509 return os << '}';
00510 }
00511
00512
00513 std::ostream& operator<<(std::ostream& os, Bool const& b)
00514 {
00515 return os << "{value:" << b.M_value << "; name:\"" << b.M_name << "\"}";
00516 }
00517
00518
00519 std::ostream& operator<<(std::ostream& os, Matcher const& matcher)
00520 {
00521 os << '{';
00522 matcher.print_type_on(os);
00523 os << ' ';
00524 matcher.Matcher::print_on(os);
00525 os << ", ";
00526 matcher.print_on(os);
00527 return os << '}';
00528 }
00529
00530
00531 std::ostream& operator<<(std::ostream& os, MatchRequestList const& match_request_list)
00532 {
00533 os << "{command: ";
00534 if (match_request_list.M_command < 0)
00535 os << debug::command_name(match_request_list.M_command);
00536 else
00537 os << match_request_list.M_command;
00538 os << ", conditions:{";
00539 std::multiset<boost::shared_ptr<Matcher> >::const_iterator iter = match_request_list.M_conditions.begin();
00540 if (iter != match_request_list.M_conditions.end())
00541 {
00542 os << **iter;
00543 while(++iter != match_request_list.M_conditions.end())
00544 os << ", " << **iter;
00545 }
00546 return os << "}}";
00547 }
00548
00549
00550 std::ostream& operator<<(std::ostream& os, MatchRequest const& match_request)
00551 {
00552 os << "{match_request_list:" << match_request.match_request_list();
00553 return os << '}';
00554 }
00555
00556
00557 std::ostream& operator<<(std::ostream& os, MatcherEventType const& event_type)
00558 {
00559 os << "{message:" << event_type.message();
00560 return os << '}';
00561 }
00562
00563
00564 std::ostream& operator<<(std::ostream& os, MatcherEventRequestBase const& request)
00565 {
00566 os << "{request_data:" << request.M_request_data;
00567 return os << '}';
00568 }
00569
00570
00571 std::ostream& operator<<(std::ostream& os, Prefix const& prefix)
00572 {
00573 os << '{';
00574 if (prefix.empty())
00575 os << "Empty Prefix";
00576 else if (!prefix.server_name().empty())
00577 os << prefix.server_name();
00578 else
00579 {
00580 #if 0
00581 if (prefix.nick()->serverside_name() == prefix.nick()->clientside_name())
00582 os << prefix.nick()->serverside_name();
00583 else
00584 os << "{serverside:" << prefix.nick()->serverside_name() << "; clientside:" << prefix.nick()->clientside_name() << '}';
00585 #else
00586 os << "FIXME";
00587 #endif
00588 os << '!';
00589 if ((prefix.nick()->data().initialized() & username_bit))
00590 os << prefix.nick()->data().username();
00591 else
00592 os << "<uninitialized>";
00593 os << '@';
00594 if ((prefix.nick()->data().initialized() & hostname_bit))
00595 os << prefix.nick()->data().hostname();
00596 else
00597 os << "<uninitialized>";
00598 }
00599 return os << '}';
00600 }
00601
00602 std::ostream& operator<<(std::ostream& os, Member const& member)
00603 {
00604 os << '{';
00605 os << "nick:" << member.get_nick();
00606 return os << '}';
00607 }
00608
00609 std::ostream& operator<<(std::ostream& os, WhoOptions const& options)
00610 {
00611 return os << options.str();
00612 }
00613
00614 std::ostream& operator<<(std::ostream& os, WhoRequest const& who_request)
00615 {
00616 return os << "{mask:" << who_request.mask() << "; options:" << who_request.options() << '}';
00617 }
00618
00619 std::ostream& operator<<(std::ostream& os, SignalType const& signal)
00620 {
00621 return os << "{sig:" << signal.get_signal() << "; count:" << signal.get_count() << '}';
00622 }
00623
00624 std::ostream& operator<<(std::ostream& os, ServerVersion const& server_version)
00625 {
00626 return os << libcwd::cwprint(server_version);
00627 }
00628
00629 std::ostream& operator<<(std::ostream& os, AuthState const& auth_state)
00630 {
00631 return os << libcwd::cwprint(auth_state);
00632 }
00633
00634 #endif // CWDEBUG