Handle non-standard missing event parameters
authorShane Synan <digitalcircuit36939@gmail.com>
Wed, 29 Jun 2016 21:16:42 +0000 (17:16 -0400)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 7 Sep 2016 19:29:32 +0000 (21:29 +0200)
Improve 'IrcEventAway', 'IrcEvent330', and 'IrcEvent403' to be more
resilient to missing parameters.  We don't need all of the parameters
to get the needed information.

These event handlers were introduced as part of the IRCv3 changes and
shouldn't modify how 0.12.4 handled commands.

src/core/coresessioneventprocessor.cpp

index c7a5b5b..a89020c 100644 (file)
@@ -253,13 +253,17 @@ void CoreSessionEventProcessor::processIrcEventAccount(IrcEvent *e)
 /* IRCv3 away-notify - ":nick!user@host AWAY [:message]" */
 void CoreSessionEventProcessor::processIrcEventAway(IrcEvent *e)
 {
 /* IRCv3 away-notify - ":nick!user@host AWAY [:message]" */
 void CoreSessionEventProcessor::processIrcEventAway(IrcEvent *e)
 {
-    if (!checkParamCount(e, 2))
+    if (!checkParamCount(e, 1))
         return;
         return;
+    // Don't use checkParamCount(e, 2) since the message is optional.  Some servers respond in a way
+    // that it counts as two parameters, but we shouldn't rely on that.
 
     // Nick is sent as part of parameters in order to split user/server decoding
     IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
     if (ircuser) {
 
     // Nick is sent as part of parameters in order to split user/server decoding
     IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
     if (ircuser) {
-        if (!e->params().at(1).isEmpty()) {
+        // If two parameters are sent -and- the second parameter isn't empty, then user is away.
+        // Otherwise, mark them as not away.
+        if (e->params().count() >= 2 && !e->params().at(1).isEmpty()) {
             ircuser->setAway(true);
             ircuser->setAwayMessage(e->params().at(1));
         } else {
             ircuser->setAway(true);
             ircuser->setAwayMessage(e->params().at(1));
         } else {
@@ -881,7 +885,9 @@ void CoreSessionEventProcessor::processIrcEvent324(IrcEvent *e)
 /*  RPL_WHOISACCOUNT - "<nick> <account> :is authed as" */
 void CoreSessionEventProcessor::processIrcEvent330(IrcEvent *e)
 {
 /*  RPL_WHOISACCOUNT - "<nick> <account> :is authed as" */
 void CoreSessionEventProcessor::processIrcEvent330(IrcEvent *e)
 {
-    if (!checkParamCount(e, 3))
+    // Though the ":is authed as" remark should always be there, we should handle cases when it's
+    // not included, too.
+    if (!checkParamCount(e, 2))
         return;
 
     IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
         return;
 
     IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
@@ -1100,7 +1106,9 @@ void CoreSessionEventProcessor::processWhoInformation (Network *net, const QStri
 void CoreSessionEventProcessor::processIrcEvent403(IrcEventNumeric *e)
 {
     // If this is the result of an AutoWho, hide it.  It's confusing to show to the user.
 void CoreSessionEventProcessor::processIrcEvent403(IrcEventNumeric *e)
 {
     // If this is the result of an AutoWho, hide it.  It's confusing to show to the user.
-    if (!checkParamCount(e, 2))
+    // Though the ":No such channel" remark should always be there, we should handle cases when it's
+    // not included, too.
+    if (!checkParamCount(e, 1))
         return;
 
     QString channelOrNick = e->params()[0];
         return;
 
     QString channelOrNick = e->params()[0];