From: Manuel Nickschas Date: Wed, 20 Oct 2010 17:35:54 +0000 (+0200) Subject: Kill IrcServerHandler and CtcpHandler X-Git-Tag: 0.8-beta1~81 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=ddeaf866099f56f42bf86b2bfc72a92763c733aa Kill IrcServerHandler and CtcpHandler Since all incoming traffic is handled by the event system now and porting is complete, there's no need for the pitiful reminders of the afforementioned handlers to exist anymore. Thus, kill them with a vengeance. --- diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index fe99f34d..a7eaf0b0 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -29,11 +29,9 @@ set(SOURCES coresettings.cpp coreuserinputhandler.cpp coreusersettings.cpp - ctcphandler.cpp ctcpparser.cpp eventstringifier.cpp ircparser.cpp - ircserverhandler.cpp netsplit.cpp postgresqlstorage.cpp sessionthread.cpp @@ -61,11 +59,9 @@ set(MOC_HDRS coresession.h coresessioneventprocessor.h coreuserinputhandler.h - ctcphandler.h ctcpparser.h eventstringifier.h ircparser.h - ircserverhandler.h netsplit.h postgresqlstorage.h sqlitestorage.h diff --git a/src/core/corenetwork.cpp b/src/core/corenetwork.cpp index 42b090ff..94854990 100644 --- a/src/core/corenetwork.cpp +++ b/src/core/corenetwork.cpp @@ -20,22 +20,18 @@ #include "corenetwork.h" -#include "ctcphandler.h" #include "core.h" #include "coreidentity.h" #include "corenetworkconfig.h" #include "coresession.h" #include "coreuserinputhandler.h" -#include "ircserverhandler.h" #include "networkevent.h" INIT_SYNCABLE_OBJECT(CoreNetwork) CoreNetwork::CoreNetwork(const NetworkId &networkid, CoreSession *session) : Network(networkid, session), _coreSession(session), - _ircServerHandler(new IrcServerHandler(this)), _userInputHandler(new CoreUserInputHandler(this)), - _ctcpHandler(new CtcpHandler(this)), _autoReconnectCount(0), _quitRequested(false), @@ -87,9 +83,7 @@ CoreNetwork::~CoreNetwork() { if(connectionState() != Disconnected && connectionState() != Network::Reconnecting) disconnectFromIrc(false); // clean up, but this does not count as requested disconnect! disconnect(&socket, 0, this, 0); // this keeps the socket from triggering events during clean up - delete _ircServerHandler; delete _userInputHandler; - delete _ctcpHandler; } QString CoreNetwork::channelDecode(const QString &bufferName, const QByteArray &string) const { @@ -327,8 +321,6 @@ void CoreNetwork::setMyNick(const QString &mynick) { void CoreNetwork::socketHasData() { while(socket.canReadLine()) { QByteArray s = socket.readLine().trimmed(); - ircServerHandler()->handleServerMsg(s); // FIXME remove with events - NetworkDataEvent *event = new NetworkDataEvent(EventManager::NetworkIncoming, this, s); #if QT_VERSION >= 0x040700 event->setTimestamp(QDateTime::currentDateTimeUtc()); diff --git a/src/core/corenetwork.h b/src/core/corenetwork.h index a579e3bb..f4744d92 100644 --- a/src/core/corenetwork.h +++ b/src/core/corenetwork.h @@ -41,9 +41,7 @@ #include "coresession.h" class CoreIdentity; -class IrcServerHandler; class CoreUserInputHandler; -class CtcpHandler; class CoreIgnoreListManager; class CoreNetwork : public Network { @@ -59,9 +57,7 @@ public: inline CoreSession *coreSession() const { return _coreSession; } inline CoreNetworkConfig *networkConfig() const { return coreSession()->networkConfig(); } - inline IrcServerHandler *ircServerHandler() const { return _ircServerHandler; } inline CoreUserInputHandler *userInputHandler() const { return _userInputHandler; } - inline CtcpHandler *ctcpHandler() const { return _ctcpHandler; } inline CoreIgnoreListManager *ignoreListManager() { return coreSession()->ignoreListManager(); } //! Decode a string using the server (network) decoding. @@ -193,9 +189,7 @@ private: QTcpSocket socket; #endif - IrcServerHandler *_ircServerHandler; CoreUserInputHandler *_userInputHandler; - CtcpHandler *_ctcpHandler; QHash _channelKeys; // stores persistent channels and their passwords, if any diff --git a/src/core/coreuserinputhandler.cpp b/src/core/coreuserinputhandler.cpp index 8289eaae..8292325f 100644 --- a/src/core/coreuserinputhandler.cpp +++ b/src/core/coreuserinputhandler.cpp @@ -21,7 +21,7 @@ #include "util.h" -#include "ctcphandler.h" +#include "ctcpparser.h" #include @@ -154,7 +154,8 @@ void CoreUserInputHandler::handleCtcp(const BufferInfo &bufferInfo, const QStrin message = QString::number(now); } - network()->ctcpHandler()->query(nick, ctcpTag, message); + // FIXME make this a proper event + coreNetwork()->coreSession()->ctcpParser()->query(coreNetwork(), nick, ctcpTag, message); emit displayMsg(Message::Action, BufferInfo::StatusBuffer, "", verboseMessage, network()->myNick()); } @@ -309,7 +310,8 @@ void CoreUserInputHandler::handleList(const BufferInfo &bufferInfo, const QStrin void CoreUserInputHandler::handleMe(const BufferInfo &bufferInfo, const QString &msg) { if(bufferInfo.bufferName().isEmpty()) return; // server buffer - network()->ctcpHandler()->query(bufferInfo.bufferName(), "ACTION", msg); + // FIXME make this a proper event + coreNetwork()->coreSession()->ctcpParser()->query(coreNetwork(), bufferInfo.bufferName(), "ACTION", msg); emit displayMsg(Message::Action, bufferInfo.type(), bufferInfo.bufferName(), msg, network()->myNick(), Message::Self); } diff --git a/src/core/coreuserinputhandler.h b/src/core/coreuserinputhandler.h index 9a31f69e..7c4e9302 100644 --- a/src/core/coreuserinputhandler.h +++ b/src/core/coreuserinputhandler.h @@ -22,6 +22,7 @@ #define COREUSERINPUTHANDLER_H #include "corebasichandler.h" +#include "corenetwork.h" class Cipher; class Server; @@ -31,6 +32,7 @@ class CoreUserInputHandler : public CoreBasicHandler { public: CoreUserInputHandler(CoreNetwork *parent = 0); + inline CoreNetwork *coreNetwork() const { return qobject_cast(parent()); } void handleUserInput(const BufferInfo &bufferInfo, const QString &text); diff --git a/src/core/ctcphandler.cpp b/src/core/ctcphandler.cpp deleted file mode 100644 index 56f8b332..00000000 --- a/src/core/ctcphandler.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005-10 by the Quassel Project * - * devel@quassel-irc.org * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) version 3. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#include "ctcphandler.h" - -#include "message.h" -#include "network.h" -#include "quassel.h" -#include "util.h" -#include "coreignorelistmanager.h" - -CtcpHandler::CtcpHandler(CoreNetwork *parent) - : CoreBasicHandler(parent), - XDELIM("\001"), - _ignoreListManager(parent->ignoreListManager()) -{ - - QByteArray MQUOTE = QByteArray("\020"); - ctcpMDequoteHash[MQUOTE + '0'] = QByteArray(1, '\000'); - ctcpMDequoteHash[MQUOTE + 'n'] = QByteArray(1, '\n'); - ctcpMDequoteHash[MQUOTE + 'r'] = QByteArray(1, '\r'); - ctcpMDequoteHash[MQUOTE + MQUOTE] = MQUOTE; - - QByteArray XQUOTE = QByteArray("\134"); - ctcpXDelimDequoteHash[XQUOTE + XQUOTE] = XQUOTE; - ctcpXDelimDequoteHash[XQUOTE + QByteArray("a")] = XDELIM; -} - -QByteArray CtcpHandler::lowLevelQuote(const QByteArray &message) { - QByteArray quotedMessage = message; - - QHash quoteHash = ctcpMDequoteHash; - QByteArray MQUOTE = QByteArray("\020"); - quoteHash.remove(MQUOTE + MQUOTE); - quotedMessage.replace(MQUOTE, MQUOTE + MQUOTE); - - QHash::const_iterator quoteIter = quoteHash.constBegin(); - while(quoteIter != quoteHash.constEnd()) { - quotedMessage.replace(quoteIter.value(), quoteIter.key()); - quoteIter++; - } - return quotedMessage; -} - -QByteArray CtcpHandler::lowLevelDequote(const QByteArray &message) { - QByteArray dequotedMessage; - QByteArray messagepart; - QHash::iterator ctcpquote; - - // copy dequote Message - for(int i = 0; i < message.size(); i++) { - messagepart = message.mid(i,1); - if(i+1 < message.size()) { - for(ctcpquote = ctcpMDequoteHash.begin(); ctcpquote != ctcpMDequoteHash.end(); ++ctcpquote) { - if(message.mid(i,2) == ctcpquote.key()) { - messagepart = ctcpquote.value(); - i++; - break; - } - } - } - dequotedMessage += messagepart; - } - return dequotedMessage; -} - -QByteArray CtcpHandler::xdelimQuote(const QByteArray &message) { - QByteArray quotedMessage = message; - QHash::const_iterator quoteIter = ctcpXDelimDequoteHash.constBegin(); - while(quoteIter != ctcpXDelimDequoteHash.constEnd()) { - quotedMessage.replace(quoteIter.value(), quoteIter.key()); - quoteIter++; - } - return quotedMessage; -} - -QByteArray CtcpHandler::xdelimDequote(const QByteArray &message) { - QByteArray dequotedMessage; - QByteArray messagepart; - QHash::iterator xdelimquote; - - for(int i = 0; i < message.size(); i++) { - messagepart = message.mid(i,1); - if(i+1 < message.size()) { - for(xdelimquote = ctcpXDelimDequoteHash.begin(); xdelimquote != ctcpXDelimDequoteHash.end(); ++xdelimquote) { - if(message.mid(i,2) == xdelimquote.key()) { - messagepart = xdelimquote.value(); - i++; - break; - } - } - } - dequotedMessage += messagepart; - } - return dequotedMessage; -} - -void CtcpHandler::parse(Message::Type messageType, const QString &prefix, const QString &target, const QByteArray &message) { - QByteArray ctcp; - - //lowlevel message dequote - QByteArray dequotedMessage = lowLevelDequote(message); - - CtcpType ctcptype = messageType == Message::Notice - ? CtcpReply - : CtcpQuery; - - Message::Flags flags = (messageType == Message::Notice && !network()->isChannelName(target)) - ? Message::Redirected - : Message::None; - - // extract tagged / extended data - int xdelimPos = -1; - int xdelimEndPos = -1; - int spacePos = -1; - QList replies; - while((xdelimPos = dequotedMessage.indexOf(XDELIM)) != -1) { - if(xdelimPos > 0) - displayMsg(messageType, target, userDecode(target, dequotedMessage.left(xdelimPos)), prefix, flags); - - xdelimEndPos = dequotedMessage.indexOf(XDELIM, xdelimPos + 1); - if(xdelimEndPos == -1) { - // no matching end delimiter found... treat rest of the message as ctcp - xdelimEndPos = dequotedMessage.count(); - } - ctcp = xdelimDequote(dequotedMessage.mid(xdelimPos + 1, xdelimEndPos - xdelimPos - 1)); - dequotedMessage = dequotedMessage.mid(xdelimEndPos + 1); - - //dispatch the ctcp command - QString ctcpcmd = userDecode(target, ctcp.left(spacePos)); - QString ctcpparam = userDecode(target, ctcp.mid(spacePos + 1)); - - spacePos = ctcp.indexOf(' '); - if(spacePos != -1) { - ctcpcmd = userDecode(target, ctcp.left(spacePos)); - ctcpparam = userDecode(target, ctcp.mid(spacePos + 1)); - } else { - ctcpcmd = userDecode(target, ctcp); - ctcpparam = QString(); - } - - if(!_ignoreListManager->ctcpMatch(prefix, network()->networkName(), ctcpcmd.toUpper())) { - QString reply_; - handle(ctcpcmd, Q_ARG(CtcpType, ctcptype), Q_ARG(QString, prefix), Q_ARG(QString, target), Q_ARG(QString, ctcpparam), Q_ARG(QString, reply_)); - if(ctcptype == CtcpQuery && !reply_.isNull()) { - replies << lowLevelQuote(pack(serverEncode(ctcpcmd), userEncode(nickFromMask(prefix), reply_))); - } - } - } - if(ctcptype == CtcpQuery && !replies.isEmpty()) { - packedReply(nickFromMask(prefix), replies); - } - - if(!dequotedMessage.isEmpty()) - displayMsg(messageType, target, userDecode(target, dequotedMessage), prefix, flags); -} - -QByteArray CtcpHandler::pack(const QByteArray &ctcpTag, const QByteArray &message) { - if(message.isEmpty()) - return XDELIM + ctcpTag + XDELIM; - - return XDELIM + ctcpTag + ' ' + xdelimQuote(message) + XDELIM; -} - -void CtcpHandler::query(const QString &bufname, const QString &ctcpTag, const QString &message) { - QList params; - params << serverEncode(bufname) << lowLevelQuote(pack(serverEncode(ctcpTag), userEncode(bufname, message))); - emit putCmd("PRIVMSG", params); -} - -void CtcpHandler::reply(const QString &bufname, const QString &ctcpTag, const QString &message) { - QList params; - params << serverEncode(bufname) << lowLevelQuote(pack(serverEncode(ctcpTag), userEncode(bufname, message))); - emit putCmd("NOTICE", params); -} - -void CtcpHandler::packedReply(const QString &bufname, const QList &replies) { - QList params; - - int answerSize = 0; - for(int i = 0; i < replies.count(); i++) { - answerSize += replies.at(i).size(); - } - - QByteArray quotedReply(answerSize, 0); - int nextPos = 0; - QByteArray &reply = quotedReply; - for(int i = 0; i < replies.count(); i++) { - reply = replies.at(i); - quotedReply.replace(nextPos, reply.size(), reply); - nextPos += reply.size(); - } - - params << serverEncode(bufname) << quotedReply; - emit putCmd("NOTICE", params); -} - -//******************************/ -// CTCP HANDLER -//******************************/ -void CtcpHandler::handleAction(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &/*reply*/) { - Q_UNUSED(ctcptype) - emit displayMsg(Message::Action, typeByTarget(target), target, param, prefix); -} - -void CtcpHandler::handleClientinfo(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) { - Q_UNUSED(target) - if(ctcptype == CtcpQuery) { - QStringList supportedHandlers; - foreach(QString handler, providesHandlers()) { - supportedHandlers << handler.toUpper(); - } - reply = supportedHandlers.join(" "); - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP CLIENTINFO request from %1").arg(prefix)); - } else { - // display clientinfo answer - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP CLIENTINFO answer from %1: %2") - .arg(nickFromMask(prefix)).arg(param)); - } -} - -void CtcpHandler::handlePing(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) { - Q_UNUSED(target) - if(ctcptype == CtcpQuery) { - reply = param; - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP PING request from %1").arg(prefix)); - } else { - // display ping answer - uint now = QDateTime::currentDateTime().toTime_t(); - uint then = QDateTime().fromTime_t(param.toInt()).toTime_t(); - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP PING answer from %1 with %2 seconds round trip time") - .arg(nickFromMask(prefix)).arg(now-then)); - } -} - -void CtcpHandler::handleVersion(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) { - Q_UNUSED(target) - if(ctcptype == CtcpQuery) { - reply = QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org").arg(Quassel::buildInfo().plainVersionString).arg(Quassel::buildInfo().buildDate); - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP VERSION request by %1").arg(prefix)); - } else { - // display Version answer - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP VERSION answer from %1: %2") - .arg(nickFromMask(prefix)).arg(param)); - } -} - -void CtcpHandler::handleTime(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) { - Q_UNUSED(target) - if(ctcptype == CtcpQuery) { - reply = QDateTime::currentDateTime().toString(); - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP TIME request by %1").arg(prefix)); - } else { - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP TIME answer from %1: %2") - .arg(nickFromMask(prefix)).arg(param)); - } -} - -void CtcpHandler::defaultHandler(const QString &cmd, CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) { - Q_UNUSED(ctcptype); - Q_UNUSED(target); - Q_UNUSED(reply); - QString str = tr("Received unknown CTCP %1 by %2").arg(cmd).arg(prefix); - if(!param.isEmpty()) - str.append(tr(" with arguments: %1").arg(param)); - emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", str); -} - diff --git a/src/core/ctcphandler.h b/src/core/ctcphandler.h deleted file mode 100644 index e8d1c18f..00000000 --- a/src/core/ctcphandler.h +++ /dev/null @@ -1,69 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005-10 by the Quassel Project * - * devel@quassel-irc.org * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) version 3. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef _CTCPHANDLER_H_ -#define _CTCPHANDLER_H_ - -#include -#include - -#include "corebasichandler.h" - -class CoreListIgnoreListManager; - -class CtcpHandler : public CoreBasicHandler { - Q_OBJECT - -public: - CtcpHandler(CoreNetwork *parent = 0); - - enum CtcpType {CtcpQuery, CtcpReply}; - - void parse(Message::Type, const QString &prefix, const QString &target, const QByteArray &message); - - QByteArray lowLevelQuote(const QByteArray &); - QByteArray lowLevelDequote(const QByteArray &); - QByteArray xdelimQuote(const QByteArray &); - QByteArray xdelimDequote(const QByteArray &); - - QByteArray pack(const QByteArray &ctcpTag, const QByteArray &message); - void query(const QString &bufname, const QString &ctcpTag, const QString &message); - void reply(const QString &bufname, const QString &ctcpTag, const QString &message); - -public slots: - void handleAction(CtcpType, const QString &prefix, const QString &target, const QString ¶m, QString &reply); - void handleClientinfo(CtcpType, const QString &prefix, const QString &target, const QString ¶m, QString &reply); - void handlePing(CtcpType, const QString &prefix, const QString &target, const QString ¶m, QString &reply); - void handleTime(CtcpType, const QString &prefix, const QString &target, const QString ¶m, QString &reply); - void handleVersion(CtcpType, const QString &prefix, const QString &target, const QString ¶m, QString &reply); - - void defaultHandler(const QString &cmd, CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply); - -private: - void packedReply(const QString &bufname, const QList &replies); - - QByteArray XDELIM; - QHash ctcpMDequoteHash; - QHash ctcpXDelimDequoteHash; - CoreIgnoreListManager *_ignoreListManager; -}; - - -#endif diff --git a/src/core/ircserverhandler.cpp b/src/core/ircserverhandler.cpp deleted file mode 100644 index 235f7d5e..00000000 --- a/src/core/ircserverhandler.cpp +++ /dev/null @@ -1,265 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005-10 by the Quassel Project * - * devel@quassel-irc.org * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) version 3. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#include "ircserverhandler.h" - -#include "util.h" - -#include "coresession.h" -#include "coreirclisthelper.h" -#include "coreidentity.h" -#include "ctcphandler.h" - -#include "ircuser.h" -#include "coreircchannel.h" -#include "logger.h" - -#include - -#ifdef HAVE_QCA2 -# include "cipher.h" -#endif - -IrcServerHandler::IrcServerHandler(CoreNetwork *parent) - : CoreBasicHandler(parent), - _whois(false) -{ - -} - -IrcServerHandler::~IrcServerHandler() { - -} - -/*! Handle a raw message string sent by the server. We try to find a suitable handler, otherwise we call a default handler. */ -void IrcServerHandler::handleServerMsg(QByteArray msg) { - if(msg.isEmpty()) { - qWarning() << "Received empty string from server!"; - return; - } - - // Now we split the raw message into its various parts... - QString prefix = ""; - QByteArray trailing; - QString cmd; - - // First, check for a trailing parameter introduced by " :", since this might screw up splitting the msg - // NOTE: This assumes that this is true in raw encoding, but well, hopefully there are no servers running in japanese on protocol level... - int idx = msg.indexOf(" :"); - if(idx >= 0) { - if(msg.length() > idx + 2) - trailing = msg.mid(idx + 2); - msg = msg.left(idx); - } - // OK, now it is safe to split... - QList params = msg.split(' '); - - // This could still contain empty elements due to (faulty?) ircds sending multiple spaces in a row - // Also, QByteArray is not nearly as convenient to work with as QString for such things :) - QList::iterator iter = params.begin(); - while(iter != params.end()) { - if(iter->isEmpty()) - iter = params.erase(iter); - else - ++iter; - } - - if(!trailing.isEmpty()) params << trailing; - if(params.count() < 1) { - qWarning() << "Received invalid string from server!"; - return; - } - - QString foo = serverDecode(params.takeFirst()); - - // with SASL, the command is 'AUTHENTICATE +' and we should check for this here. - /* obsolete because of events - if(foo == QString("AUTHENTICATE +")) { - handleAuthenticate(); - return; - } - */ - // a colon as the first chars indicates the existence of a prefix - if(foo[0] == ':') { - foo.remove(0, 1); - prefix = foo; - if(params.count() < 1) { - qWarning() << "Received invalid string from server!"; - return; - } - foo = serverDecode(params.takeFirst()); - } - - // next string without a whitespace is the command - cmd = foo.trimmed().toUpper(); - - // numeric replies have the target as first param (RFC 2812 - 2.4). this is usually our own nick. Remove this! - uint num = cmd.toUInt(); - if(num > 0) { - if(params.count() == 0) { - qWarning() << "Message received from server violates RFC and is ignored!" << msg; - return; - } - _target = serverDecode(params.takeFirst()); - } else { - _target = QString(); - } - - // note that the IRC server is still alive - network()->resetPingTimeout(); - - // Now we try to find a handler for this message. BTW, I do love the Trolltech guys ;-) - handle(cmd, Q_ARG(QString, prefix), Q_ARG(QList, params)); -} - - -void IrcServerHandler::defaultHandler(QString cmd, const QString &prefix, const QList &rawparams) { - // many commands are handled by the event system now - Q_UNUSED(cmd) - Q_UNUSED(prefix) - Q_UNUSED(rawparams) -} - -//******************************/ -// IRC SERVER HANDLER -//******************************/ - -void IrcServerHandler::handleNotice(const QString &prefix, const QList ¶ms) { - if(!checkParamCount("IrcServerHandler::handleNotice()", params, 2)) - return; - - - QStringList targets = serverDecode(params[0]).split(',', QString::SkipEmptyParts); - QStringList::const_iterator targetIter; - for(targetIter = targets.constBegin(); targetIter != targets.constEnd(); targetIter++) { - QString target = *targetIter; - - // special treatment for welcome messages like: - // :ChanServ!ChanServ@services. NOTICE egst :[#apache] Welcome, this is #apache. Please read the in-channel topic message. This channel is being logged by IRSeekBot. If you have any question please see http://blog.freenode.net/?p=68 - if(!network()->isChannelName(target)) { - QString msg = serverDecode(params[1]); - QRegExp welcomeRegExp("^\\[([^\\]]+)\\] "); - if(welcomeRegExp.indexIn(msg) != -1) { - QString channelname = welcomeRegExp.cap(1); - msg = msg.mid(welcomeRegExp.matchedLength()); - CoreIrcChannel *chan = static_cast(network()->ircChannel(channelname)); // we only have CoreIrcChannels in the core, so this cast is safe - if(chan && !chan->receivedWelcomeMsg()) { - chan->setReceivedWelcomeMsg(); - emit displayMsg(Message::Notice, BufferInfo::ChannelBuffer, channelname, msg, prefix); - continue; - } - } - } - - if(prefix.isEmpty() || target == "AUTH") { - target = ""; - } else { - if(!target.isEmpty() && network()->prefixes().contains(target[0])) - target = target.mid(1); - if(!network()->isChannelName(target)) - target = nickFromMask(prefix); - } - - network()->ctcpHandler()->parse(Message::Notice, prefix, target, params[1]); - } - -} - -void IrcServerHandler::handlePrivmsg(const QString &prefix, const QList ¶ms) { - if(!checkParamCount("IrcServerHandler::handlePrivmsg()", params, 1)) - return; - - IrcUser *ircuser = network()->updateNickFromMask(prefix); - if(!ircuser) { - qWarning() << "IrcServerHandler::handlePrivmsg(): Unknown IrcUser!"; - return; - } - - if(params.isEmpty()) { - qWarning() << "IrcServerHandler::handlePrivmsg(): received PRIVMSG without target or message from:" << prefix; - return; - } - - QString senderNick = nickFromMask(prefix); - - QByteArray msg = params.count() < 2 - ? QByteArray("") - : params[1]; - - QStringList targets = serverDecode(params[0]).split(',', QString::SkipEmptyParts); - QStringList::const_iterator targetIter; - for(targetIter = targets.constBegin(); targetIter != targets.constEnd(); targetIter++) { - const QString &target = network()->isChannelName(*targetIter) - ? *targetIter - : senderNick; - -#ifdef HAVE_QCA2 - msg = decrypt(target, msg); -#endif - // it's possible to pack multiple privmsgs into one param using ctcp - // - > we let the ctcpHandler do the work - network()->ctcpHandler()->parse(Message::Plain, prefix, target, msg); - } -} - -// FIXME networkConnection()->setChannelKey("") for all ERR replies indicating that a JOIN went wrong -// mostly, these are codes in the 47x range - -/* */ - -void IrcServerHandler::tryNextNick(const QString &errnick, bool erroneus) { - QStringList desiredNicks = coreSession()->identity(network()->identity())->nicks(); - int nextNickIdx = desiredNicks.indexOf(errnick) + 1; - QString nextNick; - if(nextNickIdx > 0 && desiredNicks.size() > nextNickIdx) { - nextNick = desiredNicks[nextNickIdx]; - } else { - if(erroneus) { - emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("No free and valid nicks in nicklist found. use: /nick to continue")); - return; - } else { - nextNick = errnick + "_"; - } - } - putCmd("NICK", serverEncode(nextNick)); -} - -bool IrcServerHandler::checkParamCount(const QString &methodName, const QList ¶ms, int minParams) { - if(params.count() < minParams) { - qWarning() << qPrintable(methodName) << "requires" << minParams << "parameters but received only" << params.count() << serverDecode(params); - return false; - } else { - return true; - } -} - -#ifdef HAVE_QCA2 -QByteArray IrcServerHandler::decrypt(const QString &bufferName, const QByteArray &message_, bool isTopic) { - if(message_.isEmpty()) - return message_; - - Cipher *cipher = network()->cipher(bufferName); - if(!cipher) - return message_; - - QByteArray message = message_; - message = isTopic? cipher->decryptTopic(message) : cipher->decrypt(message); - return message; -} -#endif diff --git a/src/core/ircserverhandler.h b/src/core/ircserverhandler.h deleted file mode 100644 index 52ecb6a5..00000000 --- a/src/core/ircserverhandler.h +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005-10 by the Quassel Project * - * devel@quassel-irc.org * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) version 3. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef IRCSERVERHANDLER_H -#define IRCSERVERHANDLER_H - -#include "corebasichandler.h" -#include "netsplit.h" - -class IrcServerHandler : public CoreBasicHandler { - Q_OBJECT - -public: - IrcServerHandler(CoreNetwork *parent); - ~IrcServerHandler(); - - void handleServerMsg(QByteArray rawMsg); - -public slots: - void handleNotice(const QString &prefix, const QList ¶ms); - void handlePrivmsg(const QString &prefix, const QList ¶ms); - - void defaultHandler(QString cmd, const QString &prefix, const QList ¶ms); - -private: - void tryNextNick(const QString &errnick, bool erroneus = false); - bool checkParamCount(const QString &methodName, const QList ¶ms, int minParams); - - // holds the target for numeric replies or is invalid otherwise - inline const QString &target() const { return _target; } - - bool _whois; - QString _target; - - // structure to organize netsplits - // key: quit message - // value: the corresponding netsplit object - QHash _netsplits; - -#ifdef HAVE_QCA2 - QByteArray decrypt(const QString &target, const QByteArray &message, bool isTopic = false); -#endif -}; - -#endif