From: Shane Synan Date: Mon, 11 Jul 2016 11:12:07 +0000 (-0400) Subject: Handle caps with multiple key-value pairs X-Git-Tag: travis-deploy-test~421 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=0063256bd1892d2bf3edc9acc597e9ab90152148 Handle caps with multiple key-value pairs Include everything after the first '=' in the capability value. This fixes support for future IRCv3 capabilities with multiple key-value pairs, e.g. "sts=duration=31536000,port=6697" Current IRCv3 capabilities are handled as before. --- diff --git a/src/core/coresessioneventprocessor.cpp b/src/core/coresessioneventprocessor.cpp index a89020c0..fa5fc361 100644 --- a/src/core/coresessioneventprocessor.cpp +++ b/src/core/coresessioneventprocessor.cpp @@ -175,14 +175,20 @@ void CoreSessionEventProcessor::processIrcEventCap(IrcEvent *e) availableCaps = e->params().at(2).split(' '); } // Store what capabilities are available - QStringList availableCapPair; + QString availableCapName, availableCapValue; for (int i = 0; i < availableCaps.count(); ++i) { // Capability may include values, e.g. CAP * LS :multi-prefix sasl=EXTERNAL - availableCapPair = availableCaps[i].trimmed().split('='); - if(availableCapPair.count() >= 2) { - coreNet->addCap(availableCapPair.at(0).trimmed().toLower(), availableCapPair.at(1).trimmed()); - } else { - coreNet->addCap(availableCapPair.at(0).trimmed().toLower()); + // Capability name comes before the first '='. If no '=' exists, this gets the + // whole string instead. + availableCapName = availableCaps[i].section('=', 0, 0).trimmed(); + // Some capabilities include multiple key=value pairs in the listing, + // e.g. "sts=duration=31536000,port=6697" + // Include everything after the first equal sign as part of the value. If no '=' + // exists, this gets an empty string. + availableCapValue = availableCaps[i].section('=', 1).trimmed(); + // Only add the capability if it's non-empty + if (!availableCapName.isEmpty()) { + coreNet->addCap(availableCapName, availableCapValue); } }