X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fircserverhandler.cpp;h=b9a2f6c988598f3353a0b1f0c154ed13d24b98c5;hp=655f68a8c7b654d1f85fed9110f22cf65a0a0e36;hb=6f0a153a674317d77233139fc50a2985af86e36e;hpb=e1801627e8e13e7eacbf0c59622a6adf20fcd4cd diff --git a/src/core/ircserverhandler.cpp b/src/core/ircserverhandler.cpp index 655f68a8..b9a2f6c9 100644 --- a/src/core/ircserverhandler.cpp +++ b/src/core/ircserverhandler.cpp @@ -33,7 +33,7 @@ #include #ifdef HAVE_QCA2 -#include "cipher.h" +# include "cipher.h" #endif IrcServerHandler::IrcServerHandler(CoreNetwork *parent) @@ -498,9 +498,9 @@ void IrcServerHandler::handlePrivmsg(const QString &prefix, const QList we let the ctcpHandler do the work network()->ctcpHandler()->parse(Message::Plain, prefix, target, msg); @@ -557,12 +557,13 @@ void IrcServerHandler::handleTopic(const QString &prefix, const QList 1) { - topic = params[1]; - #ifdef HAVE_QCA2 - topic = decryptTopic(channel->name(), topic); - #endif + 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)); @@ -999,12 +1000,12 @@ void IrcServerHandler::handle332(const QString &prefix, const QList return; QString channel = serverDecode(params[0]); - QString topic = channelDecode(channel, params[1]); - - #ifdef HAVE_QCA2 - topic = decryptTopic(channel, topic); - #endif - + 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); @@ -1247,71 +1248,26 @@ void IrcServerHandler::destroyNetsplits() { } #ifdef HAVE_QCA2 -QByteArray IrcServerHandler::decrypt(const QString &bufferName, QByteArray &message) { - if(bufferName.isEmpty()) - return message; - - if(message.isEmpty()) - return message; +QByteArray IrcServerHandler::decrypt(const QString &bufferName, const QByteArray &message_, bool isTopic) { + if(bufferName.isEmpty() || message_.isEmpty()) + return message_; - const QByteArray key = network()->bufferKey(bufferName); + const QByteArray key = network()->cipherKey(bufferName); if(key.isEmpty()) - return message; - - IrcChannel *channel = network()->ircChannel(bufferName); - IrcUser *user = network()->ircUser(bufferName); - - //only send encrypted text to decrypter - int index = message.indexOf(":",message.indexOf(":")+1); + return message_; - /* if(this->identifyMsgEnabled()) // Workaround braindead Freenode prefixing messages with + - ++index;*/ - - QByteArray backup = message.mid(0,index+1); + QByteArray message = message_; - if (channel && channel->cipher()->setKey(key)) - message = channel->cipher()->decrypt(message.mid(index+1)); - else if (user && user->cipher()->setKey(key)) - message = user->cipher()->decrypt(message.mid(index+1)); - - message.prepend(backup); + CoreIrcChannel *channel = qobject_cast(network()->ircChannel(bufferName)); + if(channel) { + if(channel->cipher()->setKey(key)) + message = isTopic? channel->cipher()->decryptTopic(message) : channel->cipher()->decrypt(message); + } else { + CoreIrcUser *user = qobject_cast(network()->ircUser(bufferName)); + if(user && user->cipher()->setKey(key)) + message = user->cipher()->decrypt(message); + } - message = channelDecode(bufferName, message).toAscii(); - return message; } - -QString IrcServerHandler::decryptTopic(const QString &bufferName, QString &topic) { - if(bufferName.isEmpty()) - return topic; - - if(topic.isEmpty()) - return topic; - - const QByteArray key = network()->bufferKey(bufferName); - if(key.isEmpty()) - return topic; - - IrcChannel *channel = network()->ircChannel(bufferName); - IrcUser *user = network()->ircUser(bufferName); - - //only send encrypted text to decrypter - int index = topic.indexOf(":",topic.indexOf(":")+1); - - QString backup = topic.mid(0,index+1); - - if (channel && channel->cipher()->setKey(key)) - topic = channel->cipher()->decryptTopic(topic.mid(index+1).toAscii()); - else if (user && user->cipher()->setKey(key)) - topic = user->cipher()->decryptTopic(topic.mid(index+1).toAscii()); - - topic.prepend(backup); - topic = channelDecode(bufferName, topic.toAscii()); - - return topic; -} #endif - -/***********************************************************************************/ - -