From ff3ed2a8ca548a5adbfac76b09608657bc68f8e4 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Fri, 8 Oct 2010 08:58:18 +0200 Subject: [PATCH] Event backend porting RPL_ISUPPORT (005), RPL_LIST (322), RPL_LISTEND (323), channel creation time (328) and homepage (329), RPL_NOTOPIC (331), RPL_TOPIC (332), "topic set by" (333) --- src/core/coresessioneventprocessor.cpp | 68 +++++++++++++ src/core/coresessioneventprocessor.h | 5 + src/core/eventstringifier.cpp | 79 ++++++++++++++ src/core/eventstringifier.h | 8 ++ src/core/ircserverhandler.cpp | 136 ------------------------- src/core/ircserverhandler.h | 8 -- 6 files changed, 160 insertions(+), 144 deletions(-) diff --git a/src/core/coresessioneventprocessor.cpp b/src/core/coresessioneventprocessor.cpp index 3abae902..048913ff 100644 --- a/src/core/coresessioneventprocessor.cpp +++ b/src/core/coresessioneventprocessor.cpp @@ -20,6 +20,7 @@ #include "coresessioneventprocessor.h" +#include "coreirclisthelper.h" #include "corenetwork.h" #include "coresession.h" #include "ircevent.h" @@ -171,6 +172,23 @@ void CoreSessionEventProcessor::processIrcEvent001(IrcEvent *e) { e->network()->setMyNick(nickFromMask(myhostmask)); } +/* RPL_ISUPPORT */ +// TODO Complete 005 handling, also use sensible defaults for non-sent stuff +void CoreSessionEventProcessor::processIrcEvent005(IrcEvent *e) { + if(!checkParamCount(e, 1)) + return; + + QString key, value; + for(int i = 0; i < e->params().count() - 1; i++) { + QString key = e->params()[i].section("=", 0, 0); + QString value = e->params()[i].section("=", 1); + e->network()->addSupport(key, value); + } + + /* determine our prefixes here to get an accurate result */ + e->network()->determinePrefixes(); +} + /* RPL_UMODEIS - " []" */ void CoreSessionEventProcessor::processIrcEvent221(IrcEvent *) { // TODO: save information in network object @@ -320,7 +338,57 @@ void CoreSessionEventProcessor::processIrcEvent317(IrcEvent *e) { } } +/* RPL_LIST - " <# visible> :" */ +void CoreSessionEventProcessor::processIrcEvent322(IrcEvent *e) { + if(!checkParamCount(e, 1)) + return; + + QString channelName; + quint32 userCount = 0; + QString topic; + + switch(e->params().count()) { + case 3: + topic = e->params()[2]; + case 2: + userCount = e->params()[1].toUInt(); + case 1: + channelName = e->params()[0]; + default: + break; + } + if(coreSession()->ircListHelper()->addChannel(e->networkId(), channelName, userCount, topic)) + e->stop(); // consumed by IrcListHelper, so don't further process/show this event +} + +/* RPL_LISTEND ":End of LIST" */ +void CoreSessionEventProcessor::processIrcEvent323(IrcEvent *e) { + if(!checkParamCount(e, 1)) + return; + + if(coreSession()->ircListHelper()->endOfChannelList(e->networkId())) + e->stop(); // consumed by IrcListHelper, so don't further process/show this event +} + +/* RPL_NOTOPIC */ +void CoreSessionEventProcessor::processIrcEvent331(IrcEvent *e) { + if(!checkParamCount(e, 1)) + return; + + IrcChannel *chan = e->network()->ircChannel(e->params()[0]); + if(chan) + chan->setTopic(QString()); +} + +/* RPL_TOPIC */ +void CoreSessionEventProcessor::processIrcEvent332(IrcEvent *e) { + if(!checkParamCount(e, 2)) + return; + IrcChannel *chan = e->network()->ircChannel(e->params()[0]); + if(chan) + chan->setTopic(e->params()[1]); +} /* template void CoreSessionEventProcessor::processIrcEvent(IrcEvent *e) { diff --git a/src/core/coresessioneventprocessor.h b/src/core/coresessioneventprocessor.h index edb4b2d1..5c3907b3 100644 --- a/src/core/coresessioneventprocessor.h +++ b/src/core/coresessioneventprocessor.h @@ -48,6 +48,7 @@ public: Q_INVOKABLE void processIrcEventTopic(IrcEvent *event); Q_INVOKABLE void processIrcEvent001(IrcEvent *event); // RPL_WELCOME + Q_INVOKABLE void processIrcEvent005(IrcEvent *event); // RPL_ISUPPORT Q_INVOKABLE void processIrcEvent221(IrcEvent *event); // RPL_UMODEIS Q_INVOKABLE void processIrcEvent250(IrcEvent *event); // RPL_STATSCONN Q_INVOKABLE void processIrcEvent265(IrcEvent *event); // RPL_LOCALUSERS @@ -62,6 +63,10 @@ public: Q_INVOKABLE void processIrcEvent313(IrcEvent *event); // RPL_WHOISOPERATOR Q_INVOKABLE void processIrcEvent315(IrcEvent *event); // RPL_ENDOFWHO Q_INVOKABLE void processIrcEvent317(IrcEvent *event); // RPL_WHOISIDLE + Q_INVOKABLE void processIrcEvent322(IrcEvent *event); // RPL_LIST + Q_INVOKABLE void processIrcEvent323(IrcEvent *event); // RPL_LISTEND + Q_INVOKABLE void processIrcEvent331(IrcEvent *event); // RPL_NOTOPIC + Q_INVOKABLE void processIrcEvent332(IrcEvent *event); // RPL_TOPIC // Q_INVOKABLE void processIrcEvent(IrcEvent *event); diff --git a/src/core/eventstringifier.cpp b/src/core/eventstringifier.cpp index bdaf77e7..9135d485 100644 --- a/src/core/eventstringifier.cpp +++ b/src/core/eventstringifier.cpp @@ -187,6 +187,14 @@ void EventStringifier::processIrcEventTopic(IrcEvent *e) { .arg(e->nick(), e->params().at(0), e->params().at(1)), QString(), e->params().at(0)); } +/* RPL_ISUPPORT */ +void EventStringifier::processIrcEvent005(IrcEvent *e) { + if(!e->params().last().contains(QRegExp("are supported (by|on) this server"))) + displayMsg(e, Message::Error, tr("Received non-RFC-compliant RPL_ISUPPORT: this can lead to unexpected behavior!"), e->prefix()); + displayMsg(e, Message::Server, e->params().join(" "), e->prefix()); +} + +/* RPL_AWAY - " :" */ void EventStringifier::processIrcEvent301(IrcEvent *e) { QString nick = e->params().at(0); QString awayMsg = e->params().at(1); @@ -317,6 +325,55 @@ void EventStringifier::processIrcEvent319(IrcEvent *e) { displayMsg(e, Message::Server, tr("[Whois] %1 is an operator on channels: %2").arg(nick, op.join(" "))); } +/* RPL_LIST - " <# visible> :" */ +void EventStringifier::processIrcEvent322(IrcEvent *e) { + QString channelName; + quint32 userCount = 0; + QString topic; + + switch(e->params().count()) { + case 3: + topic = e->params()[2]; + case 2: + userCount = e->params()[1].toUInt(); + case 1: + channelName = e->params()[0]; + default: + break; + } + displayMsg(e, Message::Server, tr("Channel %1 has %2 users. Topic is: \"%3\"") + .arg(channelName).arg(userCount).arg(topic)); +} + +/* RPL_LISTEND ":End of LIST" */ +void EventStringifier::processIrcEvent323(IrcEvent *e) { + displayMsg(e, Message::Server, tr("End of channel list")); +} + +/* RPL_??? - " */ +void EventStringifier::processIrcEvent328(IrcEvent *e) { + if(!checkParamCount(e, 2)) + return; + + QString channel = e->params()[0]; + displayMsg(e, Message::Topic, tr("Homepage for %1 is %2").arg(channel, e->params()[1]), QString(), channel); +} + +/* RPL_??? - " " */ +void EventStringifier::processIrcEvent329(IrcEvent *e) { + if(!checkParamCount(e, 2)) + return; + + QString channel = e->params()[0]; + uint unixtime = e->params()[1].toUInt(); + if(!unixtime) { + qWarning() << Q_FUNC_INFO << "received invalid timestamp:" << e->params()[1]; + return; + } + QDateTime time = QDateTime::fromTime_t(unixtime); + displayMsg(e, Message::Topic, tr("Channel %1 created on %2").arg(channel, time.toString()), QString(), channel); +} + /* RPL_WHOISACCOUNT: " :is authed as */ void EventStringifier::processIrcEvent330(IrcEvent *e) { if(e->params().count() < 3) @@ -325,6 +382,28 @@ void EventStringifier::processIrcEvent330(IrcEvent *e) { displayMsg(e, Message::Server, tr("[Whois] %1 is authed as %2").arg(e->params()[0], e->params()[1])); } +/* RPL_NOTOPIC */ +void EventStringifier::processIrcEvent331(IrcEvent *e) { + QString channel = e->params().first(); + displayMsg(e, Message::Topic, tr("No topic is set for %1.").arg(channel), QString(), channel); +} + +/* RPL_TOPIC */ +void EventStringifier::processIrcEvent332(IrcEvent *e) { + QString channel = e->params().first(); + displayMsg(e, Message::Topic, tr("Topic for %1 is \"%2\"").arg(channel, e->params()[1]), QString(), channel); +} + +/* Topic set by... */ +void EventStringifier::processIrcEvent333(IrcEvent *e) { + if(!checkParamCount(e, 3)) + return; + + QString channel = e->params().first(); + displayMsg(e, Message::Topic, tr("Topic set by %1 on %2") + .arg(e->params()[1], QDateTime::fromTime_t(e->params()[2].toInt()).toString()), QString(), channel); +} + // template /* diff --git a/src/core/eventstringifier.h b/src/core/eventstringifier.h index d97bfead..3de23f98 100644 --- a/src/core/eventstringifier.h +++ b/src/core/eventstringifier.h @@ -57,6 +57,7 @@ public: Q_INVOKABLE void processIrcEventPong(IrcEvent *event); Q_INVOKABLE void processIrcEventTopic(IrcEvent *event); + Q_INVOKABLE void processIrcEvent005(IrcEvent *event); // RPL_ISUPPORT Q_INVOKABLE void processIrcEvent301(IrcEvent *event); // RPL_AWAY Q_INVOKABLE void processIrcEvent305(IrcEvent *event); // RPL_UNAWAY Q_INVOKABLE void processIrcEvent306(IrcEvent *event); // RPL_NOWAWAY @@ -67,7 +68,14 @@ public: Q_INVOKABLE void processIrcEvent317(IrcEvent *event); // RPL_WHOISIDLE Q_INVOKABLE void processIrcEvent318(IrcEvent *event); // RPL_ENDOFWHOIS Q_INVOKABLE void processIrcEvent319(IrcEvent *event); // RPL_WHOISCHANNELS + Q_INVOKABLE void processIrcEvent322(IrcEvent *event); // RPL_LIST + Q_INVOKABLE void processIrcEvent323(IrcEvent *event); // RPL_LISTEND + Q_INVOKABLE void processIrcEvent328(IrcEvent *event); // RPL_??? (channel creation time) + Q_INVOKABLE void processIrcEvent329(IrcEvent *event); // RPL_??? (channel homepage) Q_INVOKABLE void processIrcEvent330(IrcEvent *event); // RPL_WHOISACCOUNT (quakenet/snircd/undernet) + Q_INVOKABLE void processIrcEvent331(IrcEvent *event); // RPL_NOTOPIC + Q_INVOKABLE void processIrcEvent332(IrcEvent *event); // RPL_TOPIC + Q_INVOKABLE void processIrcEvent333(IrcEvent *event); // RPL_??? (topic set by) // Q_INVOKABLE void processIrcEvent(IrcEvent *event); diff --git a/src/core/ircserverhandler.cpp b/src/core/ircserverhandler.cpp index efe1e532..363b0f15 100644 --- a/src/core/ircserverhandler.cpp +++ b/src/core/ircserverhandler.cpp @@ -399,148 +399,12 @@ void IrcServerHandler::handleQuit(const QString &prefix, const QList } } -/* RPL_ISUPPORT */ -// TODO Complete 005 handling, also use sensible defaults for non-sent stuff -void IrcServerHandler::handle005(const QString &prefix, const QList ¶ms) { - Q_UNUSED(prefix); - const int numParams = params.size(); - if(numParams == 0) { - emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("Received RPL_ISUPPORT (005) without parameters!"), prefix); - return; - } - - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", serverDecode(params).join(" "), prefix); - - QString rpl_isupport_suffix = serverDecode(params.last()); - if(!rpl_isupport_suffix.toLower().contains("are supported by this server")) { - emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("Received non RFC compliant RPL_ISUPPORT: this can lead to unexpected behavior!"), prefix); - } - - QString rawSupport; - QString key, value; - for(int i = 0; i < numParams - 1; i++) { - QString rawSupport = serverDecode(params[i]); - QString key = rawSupport.section("=", 0, 0); - QString value = rawSupport.section("=", 1); - network()->addSupport(key, value); - } - - /* determine our prefixes here to get an accurate result */ - network()->determinePrefixes(); -} - -/* RPL_LIST - " <# visible> :" */ -void IrcServerHandler::handle322(const QString &prefix, const QList ¶ms) { - Q_UNUSED(prefix) - QString channelName; - quint32 userCount = 0; - QString topic; - - int paramCount = params.count(); - switch(paramCount) { - case 3: - topic = serverDecode(params[2]); - case 2: - userCount = serverDecode(params[1]).toUInt(); - case 1: - channelName = serverDecode(params[0]); - default: - break; - } - if(!coreSession()->ircListHelper()->addChannel(network()->networkId(), channelName, userCount, topic)) - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Channel %1 has %2 users. Topic is: %3").arg(channelName).arg(userCount).arg(topic)); -} - -/* RPL_LISTEND ":End of LIST" */ -void IrcServerHandler::handle323(const QString &prefix, const QList ¶ms) { - Q_UNUSED(prefix) - Q_UNUSED(params) - - if(!coreSession()->ircListHelper()->endOfChannelList(network()->networkId())) - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("End of channel list")); -} - /* RPL_CHANNELMODEIS - " " */ void IrcServerHandler::handle324(const QString &prefix, const QList ¶ms) { Q_UNUSED(prefix); handleMode(prefix, params); } -/* RPL_??? - " */ -void IrcServerHandler::handle328(const QString &prefix, const QList ¶ms) { - Q_UNUSED(prefix); - if(!checkParamCount("IrcServerHandler::handle328()", params, 2)) - return; - - QString channel = serverDecode(params[0]); - QString homepage = serverDecode(params[1]); - - emit displayMsg(Message::Server, BufferInfo::ChannelBuffer, channel, tr("Homepage for %1 is %2").arg(channel, homepage)); -} - - -/* RPL_??? - " " */ -void IrcServerHandler::handle329(const QString &prefix, const QList ¶ms) { - Q_UNUSED(prefix); - if(!checkParamCount("IrcServerHandler::handle329()", params, 2)) - return; - - QString channel = serverDecode(params[0]); - uint unixtime = params[1].toUInt(); - if(!unixtime) { - qWarning() << Q_FUNC_INFO << "received invalid timestamp:" << params[1]; - return; - } - QDateTime time = QDateTime::fromTime_t(unixtime); - - emit displayMsg(Message::Server, BufferInfo::ChannelBuffer, channel, tr("Channel %1 created on %2").arg(channel, time.toString())); -} - -/* RPL_NOTOPIC */ -void IrcServerHandler::handle331(const QString &prefix, const QList ¶ms) { - Q_UNUSED(prefix); - if(!checkParamCount("IrcServerHandler::handle331()", params, 1)) - return; - - QString channel = serverDecode(params[0]); - IrcChannel *chan = network()->ircChannel(channel); - if(chan) - chan->setTopic(QString()); - - emit displayMsg(Message::Topic, BufferInfo::ChannelBuffer, channel, tr("No topic is set for %1.").arg(channel)); -} - -/* RPL_TOPIC */ -void IrcServerHandler::handle332(const QString &prefix, const QList ¶ms) { - Q_UNUSED(prefix); - if(!checkParamCount("IrcServerHandler::handle332()", params, 2)) - return; - - QString channel = serverDecode(params[0]); - QByteArray rawTopic = params[1]; -#ifdef HAVE_QCA2 - rawTopic = decrypt(channel, rawTopic, true); -#endif - QString topic = channelDecode(channel, rawTopic); - - IrcChannel *chan = network()->ircChannel(channel); - if(chan) - chan->setTopic(topic); - - emit displayMsg(Message::Topic, BufferInfo::ChannelBuffer, channel, tr("Topic for %1 is \"%2\"").arg(channel, topic)); -} - -/* Topic set by... */ -void IrcServerHandler::handle333(const QString &prefix, const QList ¶ms) { - Q_UNUSED(prefix); - if(!checkParamCount("IrcServerHandler::handle333()", params, 3)) - return; - - QString channel = serverDecode(params[0]); - emit displayMsg(Message::Topic, BufferInfo::ChannelBuffer, channel, - tr("Topic set by %1 on %2") .arg(serverDecode(params[1]), QDateTime::fromTime_t(channelDecode(channel, params[2]).toUInt()).toString())); -} - /* RPL_INVITING - " */ void IrcServerHandler::handle341(const QString &prefix, const QList ¶ms) { Q_UNUSED(prefix); diff --git a/src/core/ircserverhandler.h b/src/core/ircserverhandler.h index 25ef895c..f8305473 100644 --- a/src/core/ircserverhandler.h +++ b/src/core/ircserverhandler.h @@ -40,15 +40,7 @@ public slots: void handlePing(const QString &prefix, const QList ¶ms); void handlePrivmsg(const QString &prefix, const QList ¶ms); void handleQuit(const QString &prefix, const QList ¶ms); - void handle005(const QString &prefix, const QList ¶ms); // RPL_ISUPPORT - void handle322(const QString &prefix, const QList ¶ms); // RPL_LIST - void handle323(const QString &prefix, const QList ¶ms); // RPL_LISTEND void handle324(const QString &prefix, const QList ¶ms); // RPL_CHANNELMODEIS - void handle328(const QString &prefix, const QList ¶ms); // RPL_??? (channel homepage) - void handle329(const QString &prefix, const QList ¶ms); // RPL_??? (channel creation time) - void handle331(const QString &prefix, const QList ¶ms); // RPL_NOTOPIC - void handle332(const QString &prefix, const QList ¶ms); // RPL_TOPIC - void handle333(const QString &prefix, const QList ¶ms); // Topic set by... void handle341(const QString &prefix, const QList ¶ms); // RPL_INVITING void handle352(const QString &prefix, const QList ¶ms); // RPL_WHOREPLY void handle353(const QString &prefix, const QList ¶ms); // RPL_NAMREPLY -- 2.20.1