From 32023e27e875eede980d7323c1d05b5d4cc795d8 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Thu, 30 Sep 2010 17:55:11 +0200 Subject: [PATCH 1/1] Add checkParamCount() which stops the event if something's wrong --- src/common/ircevent.h | 3 +++ src/core/coresessioneventprocessor.cpp | 14 ++++++++++++++ src/core/coresessioneventprocessor.h | 2 ++ 3 files changed, 19 insertions(+) diff --git a/src/common/ircevent.h b/src/common/ircevent.h index 0f4336df..e8e21acb 100644 --- a/src/common/ircevent.h +++ b/src/common/ircevent.h @@ -22,6 +22,7 @@ #define IRCEVENT_H #include "networkevent.h" +#include "util.h" class IrcEvent : public NetworkEvent { public: @@ -34,6 +35,8 @@ public: inline QString prefix() const { return _prefix; } inline void setPrefix(const QString &prefix) { _prefix = prefix; } + inline QString nick() const { return nickFromMask(prefix()); } + inline QStringList params() const { return _params; } inline void setParams(const QStringList ¶ms) { _params = params; } diff --git a/src/core/coresessioneventprocessor.cpp b/src/core/coresessioneventprocessor.cpp index ebfb007a..85995247 100644 --- a/src/core/coresessioneventprocessor.cpp +++ b/src/core/coresessioneventprocessor.cpp @@ -31,6 +31,20 @@ CoreSessionEventProcessor::CoreSessionEventProcessor(CoreSession *session) } +bool CoreSessionEventProcessor::checkParamCount(IrcEvent *e, int minParams) { + if(e->params().count() < minParams) { + if(e->type() == EventManager::IrcEventNumeric) { + qWarning() << "Command " << static_cast(e)->number() << " requires " << minParams << "params, got: " << e->params(); + } else { + QString name = coreSession()->eventManager()->enumName(e->type()); + qWarning() << qPrintable(name) << "requires" << minParams << "params, got:" << e->params(); + } + e->stop(); + return false; + } + return true; +} + void CoreSessionEventProcessor::processIrcEventNumeric(IrcEventNumeric *e) { switch(e->number()) { diff --git a/src/core/coresessioneventprocessor.h b/src/core/coresessioneventprocessor.h index fa647d0a..4d7559d2 100644 --- a/src/core/coresessioneventprocessor.h +++ b/src/core/coresessioneventprocessor.h @@ -24,6 +24,7 @@ #include class CoreSession; +class IrcEvent; class IrcEventNumeric; class CoreSessionEventProcessor : public QObject { @@ -37,6 +38,7 @@ public: Q_INVOKABLE void processIrcEventNumeric(IrcEventNumeric *event); protected: + bool checkParamCount(IrcEvent *event, int minParams); private: CoreSession *_coreSession; -- 2.20.1