Event backend porting
authorManuel Nickschas <sputnick@quassel-irc.org>
Tue, 5 Oct 2010 16:23:53 +0000 (18:23 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 13 Oct 2010 23:06:32 +0000 (01:06 +0200)
AUTHENTICATE, CAP, PONG, TOPIC, RPL_WELCOME (001)

src/common/eventmanager.h
src/core/coresessioneventprocessor.cpp
src/core/coresessioneventprocessor.h
src/core/eventstringifier.cpp
src/core/eventstringifier.h
src/core/ircserverhandler.cpp
src/core/ircserverhandler.h

index a5b7a27..a41dbe5 100644 (file)
@@ -77,8 +77,8 @@ public:
     IrcServerParseError,
 
     IrcEvent                    = 0x00030000,
+    IrcEventAuthenticate,
     IrcEventCap,
-    IrcEventCapAuthenticate,
     IrcEventInvite,
     IrcEventJoin,
     IrcEventKick,
index 2147071..7a44fd0 100644 (file)
@@ -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<CoreNetwork *>(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;
+
+}
+*/
index 98274fa..52a2b66 100644 (file)
@@ -21,7 +21,8 @@
 #ifndef CORESESSIONEVENTPROCESSOR_H
 #define CORESESSIONEVENTPROCESSOR_H
 
-#include <QObject>
+#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<CoreNetwork *>(e->network()); }
 
 private:
   CoreSession *_coreSession;
index 304e36c..b7ad1a6 100644 (file)
@@ -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));
+}
index 0ff417d..4bc7f1a 100644 (file)
@@ -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
index fe9f250..382fd96 100644 (file)
@@ -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<QByteArray>
   putCmd("PONG", params);
 }
 
-void IrcServerHandler::handlePong(const QString &prefix, const QList<QByteArray> &params) {
-  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<QByteArray> &params) {
   if(!checkParamCount("IrcServerHandler::handlePrivmsg()", params, 1))
     return;
@@ -415,73 +399,6 @@ void IrcServerHandler::handleQuit(const QString &prefix, const QList<QByteArray>
   }
 }
 
-void IrcServerHandler::handleTopic(const QString &prefix, const QList<QByteArray> &params) {
-  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<QByteArray> &params) {
-    // 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<QByteArray> &params) {
-  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 <nick>!<user>@<host>"
-  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<QByteArray> &params) {
index 96ededf..93fd006 100644 (file)
@@ -38,13 +38,8 @@ public slots:
   void handleMode(const QString &prefix, const QList<QByteArray> &params);
   void handleNotice(const QString &prefix, const QList<QByteArray> &params);
   void handlePing(const QString &prefix, const QList<QByteArray> &params);
-  void handlePong(const QString &prefix, const QList<QByteArray> &params);
   void handlePrivmsg(const QString &prefix, const QList<QByteArray> &params);
   void handleQuit(const QString &prefix, const QList<QByteArray> &params);
-  void handleTopic(const QString &prefix, const QList<QByteArray> &params);
-  void handleCap(const QString &prefix, const QList<QByteArray> &params);   // CAP framework
-  void handleAuthenticate();                                                // SASL auth - no params
-  void handle001(const QString &prefix, const QList<QByteArray> &params);   // RPL_WELCOME
   void handle005(const QString &prefix, const QList<QByteArray> &params);   // RPL_ISUPPORT
   void handle221(const QString &prefix, const QList<QByteArray> &params);   // RPL_UMODEIS
   void handle250(const QString &prefix, const QList<QByteArray> &params);   // RPL_STATSDLINE