From: Manuel Nickschas Date: Tue, 5 Oct 2010 16:23:53 +0000 (+0200) Subject: Event backend porting X-Git-Tag: 0.8-beta1~101 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=46984aca05b2d5f8dddd0c8739e60a1753078123 Event backend porting AUTHENTICATE, CAP, PONG, TOPIC, RPL_WELCOME (001) --- diff --git a/src/common/eventmanager.h b/src/common/eventmanager.h index a5b7a272..a41dbe5d 100644 --- a/src/common/eventmanager.h +++ b/src/common/eventmanager.h @@ -77,8 +77,8 @@ public: IrcServerParseError, IrcEvent = 0x00030000, + IrcEventAuthenticate, IrcEventCap, - IrcEventCapAuthenticate, IrcEventInvite, IrcEventJoin, IrcEventKick, diff --git a/src/core/coresessioneventprocessor.cpp b/src/core/coresessioneventprocessor.cpp index 2147071e..7a44fd0f 100644 --- a/src/core/coresessioneventprocessor.cpp +++ b/src/core/coresessioneventprocessor.cpp @@ -58,6 +58,39 @@ void CoreSessionEventProcessor::processIrcEventNumeric(IrcEventNumeric *e) { } } +void CoreSessionEventProcessor::processIrcEventAuthenticate(IrcEvent *e) { + if(!checkParamCount(e, 1)) + return; + + if(e->params().at(0) != "+") { + qWarning() << "Invalid AUTHENTICATE" << e; + return; + } + + CoreNetwork *net = coreNetwork(e); + + QString construct = net->saslAccount(); + construct.append(QChar(QChar::Null)); + construct.append(net->saslAccount()); + construct.append(QChar(QChar::Null)); + construct.append(net->saslPassword()); + QByteArray saslData = QByteArray(construct.toAscii().toBase64()); + saslData.prepend("AUTHENTICATE "); + net->putRawLine(saslData); +} + +void CoreSessionEventProcessor::processIrcEventCap(IrcEvent *e) { + // for SASL, there will only be a single param of 'sasl', however you can check here for + // additional CAP messages (ls, multi-prefix, et cetera). + + if(e->params().count() == 3) { + if(e->params().at(2) == "sasl") { + // FIXME use event + coreNetwork(e)->putRawLine(coreNetwork(e)->serverEncode("AUTHENTICATE PLAIN")); // Only working with PLAIN atm, blowfish later + } + } +} + void CoreSessionEventProcessor::processIrcEventInvite(IrcEvent *e) { if(checkParamCount(e, 2)) { e->network()->updateNickFromMask(e->prefix()); @@ -106,3 +139,41 @@ void CoreSessionEventProcessor::processIrcEventPart(IrcEvent *e) { qobject_cast(e->network())->setChannelParted(channel); } } + +void CoreSessionEventProcessor::processIrcEventPong(IrcEvent *e) { + // the server is supposed to send back what we passed as param. and we send a timestamp + // but using quote and whatnought one can send arbitrary pings, so we have to do some sanity checks + if(checkParamCount(e, 2)) { + QString timestamp = e->params().at(1); + QTime sendTime = QTime::fromString(timestamp, "hh:mm:ss.zzz"); + if(sendTime.isValid()) + e->network()->setLatency(sendTime.msecsTo(QTime::currentTime()) / 2); + } +} + +void CoreSessionEventProcessor::processIrcEventTopic(IrcEvent *e) { + if(checkParamCount(e, 2)) { + e->network()->updateNickFromMask(e->prefix()); + IrcChannel *channel = e->network()->ircChannel(e->params().at(0)); + if(channel) + channel->setTopic(e->params().at(1)); + } +} + +/* RPL_WELCOME */ +void CoreSessionEventProcessor::processIrcEvent001(IrcEvent *e) { + if(!checkParamCount(e, 1)) + return; + + QString myhostmask = e->params().at(0).section(' ', -1, -1); + e->network()->setCurrentServer(e->prefix()); + e->network()->setMyNick(nickFromMask(myhostmask)); +} + +/* template +void CoreSessionEventProcessor::processIrcEvent(IrcEvent *e) { + if(!checkParamCount(e, 1)) + return; + +} +*/ diff --git a/src/core/coresessioneventprocessor.h b/src/core/coresessioneventprocessor.h index 98274fa7..52a2b666 100644 --- a/src/core/coresessioneventprocessor.h +++ b/src/core/coresessioneventprocessor.h @@ -21,7 +21,8 @@ #ifndef CORESESSIONEVENTPROCESSOR_H #define CORESESSIONEVENTPROCESSOR_H -#include +#include "corenetwork.h" +#include "networkevent.h" class CoreSession; class IrcEvent; @@ -37,13 +38,22 @@ public: Q_INVOKABLE void processIrcEventNumeric(IrcEventNumeric *event); + Q_INVOKABLE void processIrcEventAuthenticate(IrcEvent *event); // SASL auth + Q_INVOKABLE void processIrcEventCap(IrcEvent *event); // CAP framework Q_INVOKABLE void processIrcEventInvite(IrcEvent *event); Q_INVOKABLE void processIrcEventKick(IrcEvent *event); Q_INVOKABLE void processIrcEventNick(IrcEvent *event); Q_INVOKABLE void processIrcEventPart(IrcEvent *event); + Q_INVOKABLE void processIrcEventPong(IrcEvent *event); + Q_INVOKABLE void processIrcEventTopic(IrcEvent *event); + + Q_INVOKABLE void processIrcEvent001(IrcEvent *event); // RPL_WELCOME + + // Q_INVOKABLE void processIrcEvent(IrcEvent *event); protected: bool checkParamCount(IrcEvent *event, int minParams); + inline CoreNetwork *coreNetwork(NetworkEvent *e) const { return qobject_cast(e->network()); } private: CoreSession *_coreSession; diff --git a/src/core/eventstringifier.cpp b/src/core/eventstringifier.cpp index 304e36c5..b7ad1a60 100644 --- a/src/core/eventstringifier.cpp +++ b/src/core/eventstringifier.cpp @@ -50,8 +50,8 @@ void EventStringifier::processIrcEventNumeric(IrcEventNumeric *e) { //qDebug() << e->number(); switch(e->number()) { // Welcome, status, info messages. Just display these. - case 2: case 3: case 4: case 5: case 251: case 252: case 253: case 254: case 255: case 372: case 375: - displayMsg(e, Message::Server, e->params().join(" "), e->prefix()); + case 1: case 2: case 3: case 4: case 5: case 251: case 252: case 253: case 254: case 255: case 372: case 375: + displayMsg(e, Message::Server, e->params().join(" "), e->prefix()); qDebug () << e; break; // Server error messages without param, just display them @@ -154,3 +154,15 @@ void EventStringifier::earlyProcessIrcEventPart(IrcEvent *e) { displayMsg(e, Message::Part, msg, e->prefix(), channel); } + +void EventStringifier::processIrcEventPong(IrcEvent *e) { + QString timestamp = e->params().at(1); + QTime sendTime = QTime::fromString(timestamp, "hh:mm:ss.zzz"); + if(!sendTime.isValid()) + displayMsg(e, Message::Server, "PONG " + e->params().join(" "), e->prefix()); +} + +void EventStringifier::processIrcEventTopic(IrcEvent *e) { + displayMsg(e, Message::Topic, tr("%1 has changed topic for %2 to: \"%3\"") + .arg(e->nick(), e->params().at(0), e->params().at(1)), QString(), e->params().at(0)); +} diff --git a/src/core/eventstringifier.h b/src/core/eventstringifier.h index 0ff417d3..4bc7f1a5 100644 --- a/src/core/eventstringifier.h +++ b/src/core/eventstringifier.h @@ -54,6 +54,10 @@ public: Q_INVOKABLE void earlyProcessIrcEventKick(IrcEvent *event); Q_INVOKABLE void earlyProcessIrcEventNick(IrcEvent *event); Q_INVOKABLE void earlyProcessIrcEventPart(IrcEvent *event); + Q_INVOKABLE void processIrcEventPong(IrcEvent *event); + Q_INVOKABLE void processIrcEventTopic(IrcEvent *event); + + // Q_INVOKABLE void processIrcEvent(IrcEvent *event); public slots: //! Creates and sends a MessageEvent diff --git a/src/core/ircserverhandler.cpp b/src/core/ircserverhandler.cpp index fe9f2500..382fd966 100644 --- a/src/core/ircserverhandler.cpp +++ b/src/core/ircserverhandler.cpp @@ -89,11 +89,12 @@ void IrcServerHandler::handleServerMsg(QByteArray msg) { 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); @@ -325,23 +326,6 @@ void IrcServerHandler::handlePing(const QString &prefix, const QList putCmd("PONG", params); } -void IrcServerHandler::handlePong(const QString &prefix, const QList ¶ms) { - Q_UNUSED(prefix); - // the server is supposed to send back what we passed as param. and we send a timestamp - // but using quote and whatnought one can send arbitrary pings, so we have to do some sanity checks - if(params.count() < 2) - return; - - QString timestamp = serverDecode(params[1]); - QTime sendTime = QTime::fromString(timestamp, "hh:mm:ss.zzz"); - if(!sendTime.isValid()) { - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", "PONG " + serverDecode(params).join(" "), prefix); - return; - } - - network()->setLatency(sendTime.msecsTo(QTime::currentTime()) / 2); -} - void IrcServerHandler::handlePrivmsg(const QString &prefix, const QList ¶ms) { if(!checkParamCount("IrcServerHandler::handlePrivmsg()", params, 1)) return; @@ -415,73 +399,6 @@ void IrcServerHandler::handleQuit(const QString &prefix, const QList } } -void IrcServerHandler::handleTopic(const QString &prefix, const QList ¶ms) { - if(!checkParamCount("IrcServerHandler::handleTopic()", params, 1)) - return; - - IrcUser *ircuser = network()->updateNickFromMask(prefix); - if(!ircuser) - return; - - IrcChannel *channel = network()->ircChannel(serverDecode(params[0])); - if(!channel) - return; - - QString topic; - if(params.count() > 1) { - QByteArray rawTopic = params[1]; -#ifdef HAVE_QCA2 - rawTopic = decrypt(channel->name(), rawTopic, true); -#endif - topic = channelDecode(channel->name(), rawTopic); - } - - channel->setTopic(topic); - - emit displayMsg(Message::Topic, BufferInfo::ChannelBuffer, channel->name(), tr("%1 has changed topic for %2 to: \"%3\"").arg(ircuser->nick()).arg(channel->name()).arg(topic)); -} - -void IrcServerHandler::handleCap(const QString &prefix, const QList ¶ms) { - // for SASL, there will only be a single param of 'sasl', however you can check here for - // additional CAP messages (ls, multi-prefix, et cetera). - - Q_UNUSED(prefix); - - if(params.size() == 3) { - QString param = serverDecode(params[2]); - if(param == QString("sasl")) { // SASL Ready - network()->putRawLine(serverEncode("AUTHENTICATE PLAIN")); // Only working with PLAIN atm, blowfish later - } - } -} - -void IrcServerHandler::handleAuthenticate() { - QString construct = network()->saslAccount(); - construct.append(QChar(QChar::Null)); - construct.append(network()->saslAccount()); - construct.append(QChar(QChar::Null)); - construct.append(network()->saslPassword()); - QByteArray saslData = QByteArray(construct.toAscii().toBase64()); - saslData.prepend(QString("AUTHENTICATE ").toAscii()); - network()->putRawLine(saslData); -} - -/* RPL_WELCOME */ -void IrcServerHandler::handle001(const QString &prefix, const QList ¶ms) { - network()->setCurrentServer(prefix); - - if(params.isEmpty()) { - emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", QString("%1 didn't supply a valid welcome message... expect some serious issues...")); - } - // there should be only one param: "Welcome to the Internet Relay Network !@" - QString param = serverDecode(params[0]); - QString myhostmask = param.section(' ', -1, -1); - - network()->setMyNick(nickFromMask(myhostmask)); - - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", param, prefix); -} - /* RPL_ISUPPORT */ // TODO Complete 005 handling, also use sensible defaults for non-sent stuff void IrcServerHandler::handle005(const QString &prefix, const QList ¶ms) { diff --git a/src/core/ircserverhandler.h b/src/core/ircserverhandler.h index 96ededf8..93fd0067 100644 --- a/src/core/ircserverhandler.h +++ b/src/core/ircserverhandler.h @@ -38,13 +38,8 @@ public slots: void handleMode(const QString &prefix, const QList ¶ms); void handleNotice(const QString &prefix, const QList ¶ms); void handlePing(const QString &prefix, const QList ¶ms); - void handlePong(const QString &prefix, const QList ¶ms); void handlePrivmsg(const QString &prefix, const QList ¶ms); void handleQuit(const QString &prefix, const QList ¶ms); - void handleTopic(const QString &prefix, const QList ¶ms); - void handleCap(const QString &prefix, const QList ¶ms); // CAP framework - void handleAuthenticate(); // SASL auth - no params - void handle001(const QString &prefix, const QList ¶ms); // RPL_WELCOME void handle005(const QString &prefix, const QList ¶ms); // RPL_ISUPPORT void handle221(const QString &prefix, const QList ¶ms); // RPL_UMODEIS void handle250(const QString &prefix, const QList ¶ms); // RPL_STATSDLINE