X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fircserverhandler.cpp;h=033d6c8d19fea3b9007da07cc832ceef93ef212c;hp=97e00587c15207b270174cd93d2d3007f07bc853;hb=326a0d0783c8ecffb6a7bae02fd74f66bd4242fa;hpb=32dee9bed2840534e41764a6ba759d425837b8a2 diff --git a/src/core/ircserverhandler.cpp b/src/core/ircserverhandler.cpp index 97e00587..033d6c8d 100644 --- a/src/core/ircserverhandler.cpp +++ b/src/core/ircserverhandler.cpp @@ -32,6 +32,10 @@ #include +#ifdef HAVE_QCA2 +# include "cipher.h" +#endif + IrcServerHandler::IrcServerHandler(CoreNetwork *parent) : CoreBasicHandler(parent), _whois(false) @@ -84,6 +88,12 @@ void IrcServerHandler::handleServerMsg(QByteArray msg) { QString foo = serverDecode(params.takeFirst()); + // with SASL, the command is 'AUTHENTICATE +' and we should check for this here. + 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); @@ -160,6 +170,11 @@ void IrcServerHandler::defaultHandler(QString cmd, const QString &prefix, const case 321: case 366: case 376: break; + case 903: case 904: case 905: case 906: case 907: + { + network()->putRawLine("CAP END"); + emit displayMsg(Message::Info, BufferInfo::StatusBuffer, "", "CAP: " + params.join("")); + } // Everything else will be marked in red, so we can add them somewhere. default: if(_whois) { @@ -182,6 +197,21 @@ void IrcServerHandler::defaultHandler(QString cmd, const QString &prefix, const //******************************/ // IRC SERVER HANDLER //******************************/ +void IrcServerHandler::handleInvite(const QString &prefix, const QList ¶ms) { + if(!checkParamCount("IrcServerHandler::handleInvite()", params, 2)) + return; +// qDebug() << "IrcServerHandler::handleInvite()" << prefix << params; + + IrcUser *ircuser = network()->updateNickFromMask(prefix); + if(!ircuser) { + return; + } + + QString channel = serverDecode(params[1]); + + emit displayMsg(Message::Invite, BufferInfo::StatusBuffer, "", tr("%1 invited you to channel %2").arg(ircuser->nick()).arg(channel)); +} + void IrcServerHandler::handleJoin(const QString &prefix, const QList ¶ms) { if(!checkParamCount("IrcServerHandler::handleJoin()", params, 1)) return; @@ -335,6 +365,10 @@ void IrcServerHandler::handleMode(const QString &prefix, const QList if(!removeModes.isEmpty()) ircUser->removeUserModes(removeModes); + if(network()->isMe(ircUser)) { + network()->updatePersistentModes(addModes, removeModes); + } + // FIXME: redirect emit displayMsg(Message::Mode, BufferInfo::StatusBuffer, "", serverDecode(params).join(" "), prefix); } @@ -479,6 +513,9 @@ void IrcServerHandler::handlePrivmsg(const QString &prefix, const QList we let the ctcpHandler do the work network()->ctcpHandler()->parse(Message::Plain, prefix, target, msg); @@ -534,14 +571,44 @@ void IrcServerHandler::handleTopic(const QString &prefix, const QList 1) - topic = channelDecode(channel->name(), params[1]); + 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); @@ -948,7 +1015,12 @@ void IrcServerHandler::handle332(const QString &prefix, const QList return; QString channel = serverDecode(params[0]); - QString topic = channelDecode(channel, params[1]); + QByteArray rawTopic = params[1]; +#ifdef HAVE_QCA2 + rawTopic = decrypt(channel, rawTopic, true); +#endif + QString topic = channelDecode(channel, rawTopic); + IrcChannel *chan = network()->ircChannel(channel); if(chan) chan->setTopic(topic); @@ -1067,6 +1139,24 @@ void IrcServerHandler::handle433(const QString &prefix, const QList tryNextNick(errnick); } +/* ERR_UNAVAILRESOURCE */ +void IrcServerHandler::handle437(const QString &prefix, const QList ¶ms) { + Q_UNUSED(prefix); + if(!checkParamCount("IrcServerHandler::handle437()", params, 1)) + return; + + QString errnick = serverDecode(params[0]); + emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("Nick/channel is temporarily unavailable: %1").arg(errnick)); + + // if there is a problem while connecting to the server -> we handle it + // but only if our connection has not been finished yet... + if(!network()->currentServer().isEmpty()) + return; + + if(!network()->isChannelName(errnick)) + tryNextNick(errnick); +} + /* Handle signals from Netsplit objects */ void IrcServerHandler::handleNetsplitJoin(const QString &channel, const QStringList &users, const QStringList &modes, const QString& quitMessage) @@ -1172,6 +1262,17 @@ void IrcServerHandler::destroyNetsplits() { _netsplits.clear(); } -/***********************************************************************************/ +#ifdef HAVE_QCA2 +QByteArray IrcServerHandler::decrypt(const QString &bufferName, const QByteArray &message_, bool isTopic) { + if(message_.isEmpty()) + return message_; + Cipher *cipher = network()->cipher(bufferName); + if(!cipher) + return message_; + QByteArray message = message_; + message = isTopic? cipher->decryptTopic(message) : cipher->decrypt(message); + return message; +} +#endif