/***************************************************************************
- * Copyright (C) 2005-2013 by the Quassel Project *
+ * Copyright (C) 2005-2015 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
QString verboseMessage = tr("sending CTCP-%1 request to %2").arg(ctcpTag).arg(nick);
if (ctcpTag == "PING") {
- uint now = QDateTime::currentDateTime().toTime_t();
- message = QString::number(now);
+ message = QString::number(QDateTime::currentMSecsSinceEpoch());
}
// FIXME make this a proper event
if (!isNumber || maxModes == 0) maxModes = 1;
QStringList nickList;
- if (nicks == "*") { // All users in channel
+ if (nicks == "*" && bufferInfo.type() == BufferInfo::ChannelBuffer) { // All users in channel
const QList<IrcUser*> users = network()->ircChannel(bufferInfo.bufferName())->ircUsers();
foreach(IrcUser *user, users) {
if ((addOrRemove == '+' && !network()->ircChannel(bufferInfo.bufferName())->userModes(user).contains(mode))
return;
QString target = msg.section(' ', 0, 0);
- QByteArray encMsg = userEncode(target, msg.section(' ', 1));
+ QString msgSection = msg.section(' ', 1);
+
+ std::function<QByteArray(const QString &, const QString &)> encodeFunc = [this] (const QString &target, const QString &message) -> QByteArray {
+ return userEncode(target, message);
+ };
#ifdef HAVE_QCA2
- putPrivmsg(serverEncode(target), encMsg, network()->cipher(target));
+ putPrivmsg(target, msgSection, encodeFunc, network()->cipher(target));
#else
- putPrivmsg(serverEncode(target), encMsg);
+ putPrivmsg(target, msgSection, encodeFunc);
#endif
}
if (param.isEmpty())
param = QTime::currentTime().toString("hh:mm:ss.zzz");
- putCmd("PING", serverEncode(param));
+ // Take priority so this won't get stuck behind other queued messages.
+ putCmd("PING", serverEncode(param), QByteArray(), true);
+}
+
+
+void CoreUserInputHandler::handlePrint(const BufferInfo &bufferInfo, const QString &msg)
+{
+ if (bufferInfo.bufferName().isEmpty() || !bufferInfo.acceptsRegularMessages())
+ return; // server buffer
+
+ QByteArray encMsg = channelEncode(bufferInfo.bufferName(), msg);
+ emit displayMsg(Message::Info, bufferInfo.type(), bufferInfo.bufferName(), msg, network()->myNick(), Message::Self);
}
}
-void CoreUserInputHandler::issueQuit(const QString &reason)
+void CoreUserInputHandler::issueQuit(const QString &reason, bool forceImmediate)
{
- emit putCmd("QUIT", serverEncode(reason));
+ // If needing an immediate QUIT (e.g. core shutdown), prepend this to the queue
+ emit putCmd("QUIT", serverEncode(reason), QByteArray(), forceImmediate);
}
if (bufferInfo.bufferName().isEmpty() || !bufferInfo.acceptsRegularMessages())
return; // server buffer
- QByteArray encMsg = channelEncode(bufferInfo.bufferName(), msg);
+ std::function<QByteArray(const QString &, const QString &)> encodeFunc = [this] (const QString &target, const QString &message) -> QByteArray {
+ return channelEncode(target, message);
+ };
+
#ifdef HAVE_QCA2
- putPrivmsg(serverEncode(bufferInfo.bufferName()), encMsg, network()->cipher(bufferInfo.bufferName()));
+ putPrivmsg(bufferInfo.bufferName(), msg, encodeFunc, network()->cipher(bufferInfo.bufferName()));
#else
- putPrivmsg(serverEncode(bufferInfo.bufferName()), encMsg);
+ putPrivmsg(bufferInfo.bufferName(), msg, encodeFunc);
#endif
emit displayMsg(Message::Plain, bufferInfo.type(), bufferInfo.bufferName(), msg, network()->myNick(), Message::Self);
}
}
-void CoreUserInputHandler::putPrivmsg(const QByteArray &target, const QByteArray &message, Cipher *cipher)
+void CoreUserInputHandler::putPrivmsg(const QString &target, const QString &message, std::function<QByteArray(const QString &, const QString &)> encodeFunc, Cipher *cipher)
{
- // Encrypted messages need special care. There's no clear relation between cleartext and encrypted message length,
- // so we can't just compute the maxSplitPos. Instead, we need to loop through the splitpoints until the crypted
- // version is short enough...
- // TODO: check out how the various possible encryption methods behave length-wise and make
- // this clean by predicting the length of the crypted msg.
- // For example, blowfish-ebc seems to create 8-char chunks.
+ Q_UNUSED(cipher);
+ QString cmd("PRIVMSG");
+ QByteArray targetEnc = serverEncode(target);
- static const char *cmd = "PRIVMSG";
- static const char *splitter = " .,-";
+ std::function<QList<QByteArray>(QString &)> cmdGenerator = [&] (QString &splitMsg) -> QList<QByteArray> {
+ QByteArray splitMsgEnc = encodeFunc(target, splitMsg);
- int maxSplitPos = message.count();
- int splitPos = maxSplitPos;
- forever {
- QByteArray crypted = message.left(splitPos);
- bool isEncrypted = false;
#ifdef HAVE_QCA2
- if (cipher && !cipher->key().isEmpty() && !message.isEmpty()) {
- isEncrypted = cipher->encrypt(crypted);
+ if (cipher && !cipher->key().isEmpty() && !splitMsg.isEmpty()) {
+ cipher->encrypt(splitMsgEnc);
}
#endif
- int overrun = lastParamOverrun(cmd, QList<QByteArray>() << target << crypted);
- if (overrun) {
- // In case this is not an encrypted msg, we can just cut off at the end
- if (!isEncrypted)
- maxSplitPos = message.count() - overrun;
-
- splitPos = -1;
- for (const char *splitChar = splitter; *splitChar != 0; splitChar++) {
- splitPos = qMax(splitPos, message.lastIndexOf(*splitChar, maxSplitPos) + 1); // keep split char on old line
- }
- if (splitPos <= 0 || splitPos > maxSplitPos)
- splitPos = maxSplitPos;
+ return QList<QByteArray>() << targetEnc << splitMsgEnc;
+ };
- maxSplitPos = splitPos - 1;
- if (maxSplitPos <= 0) { // this should never happen, but who knows...
- qWarning() << tr("[Error] Could not encrypt your message: %1").arg(message.data());
- return;
- }
- continue; // we never come back here for !encrypted!
- }
-
- // now we have found a valid splitpos (or didn't need to split to begin with)
- putCmd(cmd, QList<QByteArray>() << target << crypted);
- if (splitPos < message.count())
- putPrivmsg(target, message.mid(splitPos), cipher);
-
- return;
- }
+ putCmd(cmd, network()->splitMessage(cmd, message, cmdGenerator));
}
// that means that the last message can be as long as:
// 512 - nicklen - userlen - hostlen - commandlen - sum(param[0]..param[n-1])) - 2 (for CRLF) - 4 (":!@" + 1space between prefix and command) - max(paramcount - 1, 0) (space for simple params) - 2 (space and colon for last param)
IrcUser *me = network()->me();
- int maxLen = 480 - cmd.toAscii().count(); // educated guess in case we don't know us (yet?)
+ int maxLen = 480 - cmd.toLatin1().count(); // educated guess in case we don't know us (yet?)
if (me)
- maxLen = 512 - serverEncode(me->nick()).count() - serverEncode(me->user()).count() - serverEncode(me->host()).count() - cmd.toAscii().count() - 6;
+ maxLen = 512 - serverEncode(me->nick()).count() - serverEncode(me->user()).count() - serverEncode(me->host()).count() - cmd.toLatin1().count() - 6;
if (!params.isEmpty()) {
for (int i = 0; i < params.count() - 1; i++) {