Minor cleanup of messages handling
authorJanne Koschinski <janne@kuschku.de>
Fri, 15 Feb 2019 08:24:26 +0000 (09:24 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 30 May 2019 20:59:25 +0000 (22:59 +0200)
14 files changed:
src/common/messageevent.h
src/core/CMakeLists.txt
src/core/corebasichandler.h
src/core/corenetwork.cpp
src/core/corenetwork.h
src/core/coresession.cpp
src/core/coresession.h
src/core/coresessioneventprocessor.cpp
src/core/coresessioneventprocessor.h
src/core/coreuserinputhandler.cpp
src/core/coreuserinputhandler.h
src/core/ircparser.cpp
src/core/ircparser.h
src/core/irctags.h [new file with mode: 0644]

index 49c70f4..8ac668d 100644 (file)
@@ -63,7 +63,9 @@ protected:
     inline void debugInfo(QDebug& dbg) const override
     {
         NetworkEvent::debugInfo(dbg);
-        dbg.nospace() << ", sender = " << qPrintable(sender()) << ", target = " << qPrintable(target()) << ", text = " << text()
+        dbg.nospace() << ", sender = " << qPrintable(sender())
+                      << ", target = " << qPrintable(target())
+                      << ", text = " << text()
                       << ", msgtype = " << qPrintable(QString::number(msgType(), 16))
                       << ", buffertype = " << qPrintable(QString::number(bufferType(), 16))
                       << ", msgflags = " << qPrintable(QString::number(msgFlags(), 16));
index a4cc809..2e9199a 100644 (file)
@@ -32,6 +32,7 @@ target_sources(${TARGET} PRIVATE
     eventstringifier.cpp
     identserver.cpp
     ircparser.cpp
+    irctags.h
     netsplit.cpp
     oidentdconfiggenerator.cpp
     postgresqlstorage.cpp
index 697775a..0777de5 100644 (file)
@@ -52,12 +52,7 @@ public:
     QList<QByteArray> userEncode(const QString& userNick, const QStringList& stringlist);
 
 signals:
-    void displayMsg(Message::Type,
-                    BufferInfo::Type,
-                    const QString& target,
-                    const QString& text,
-                    const QString& sender = "",
-                    Message::Flags flags = Message::None);
+    void displayMsg(const NetworkInternalMessage& msg);
 
     /**
      * Sends the raw (encoded) line, adding to the queue if needed, optionally with higher priority.
index 2f14a5b..b1923c3 100644 (file)
@@ -40,13 +40,9 @@ CoreNetwork::CoreNetwork(const NetworkId& networkid, CoreSession* session)
     , _autoReconnectCount(0)
     , _quitRequested(false)
     , _disconnectExpected(false)
-    ,
-
-    _previousConnectionAttemptFailed(false)
+    , _previousConnectionAttemptFailed(false)
     , _lastUsedServerIndex(0)
-    ,
-
-    _requestedUserModes('-')
+    , _requestedUserModes('-')
 {
     // Check if raw IRC logging is enabled
     _debugLogRawIrc = (Quassel::isOptionSet("debug-irc") || Quassel::isOptionSet("debug-irc-id"));
@@ -62,12 +58,12 @@ CoreNetwork::CoreNetwork(const NetworkId& networkid, CoreSession* session)
     setAutoWhoInterval(networkConfig()->autoWhoInterval());
 
     QHash<QString, QString> channels = coreSession()->persistentChannels(networkId());
-    foreach (QString chan, channels.keys()) {
+    for (const QString& chan : channels.keys()) {
         _channelKeys[chan.toLower()] = channels[chan];
     }
 
     QHash<QString, QByteArray> bufferCiphers = coreSession()->bufferCiphers(networkId());
-    foreach (QString buffer, bufferCiphers.keys()) {
+    for (const QString& buffer : bufferCiphers.keys()) {
         storeChannelCipherKey(buffer.toLower(), bufferCiphers[buffer]);
     }
 
@@ -122,9 +118,9 @@ CoreNetwork::~CoreNetwork()
     disconnect(&socket, nullptr, this, nullptr);
     if (!forceDisconnect()) {
         qWarning() << QString{"Could not disconnect from network %1 (network ID: %2, user ID: %3)"}
-                          .arg(networkName())
-                          .arg(networkId().toInt())
-                          .arg(userId().toInt());
+            .arg(networkName())
+            .arg(networkId().toInt())
+            .arg(userId().toInt());
     }
 }
 
@@ -222,7 +218,12 @@ void CoreNetwork::connectToIrc(bool reconnecting)
     else if (_previousConnectionAttemptFailed) {
         // cycle to next server if previous connection attempt failed
         _previousConnectionAttemptFailed = false;
-        showMessage(Message::Server, BufferInfo::StatusBuffer, "", tr("Connection failed. Cycling to next Server"));
+        showMessage(NetworkInternalMessage(
+            Message::Server,
+            BufferInfo::StatusBuffer,
+            "",
+            tr("Connection failed. Cycling to next server...")
+        ));
         if (++_lastUsedServerIndex >= serverList().size()) {
             _lastUsedServerIndex = 0;
         }
@@ -234,10 +235,15 @@ void CoreNetwork::connectToIrc(bool reconnecting)
 
     Server server = usedServer();
     displayStatusMsg(tr("Connecting to %1:%2...").arg(server.host).arg(server.port));
-    showMessage(Message::Server, BufferInfo::StatusBuffer, "", tr("Connecting to %1:%2...").arg(server.host).arg(server.port));
+    showMessage(NetworkInternalMessage(
+        Message::Server,
+        BufferInfo::StatusBuffer,
+        "",
+        tr("Connecting to %1:%2...").arg(server.host).arg(server.port)
+    ));
 
     if (server.useProxy) {
-        QNetworkProxy proxy((QNetworkProxy::ProxyType)server.proxyType, server.proxyHost, server.proxyPort, server.proxyUser, server.proxyPass);
+        QNetworkProxy proxy((QNetworkProxy::ProxyType) server.proxyType, server.proxyHost, server.proxyPort, server.proxyUser, server.proxyPass);
         socket.setProxy(proxy);
     }
     else {
@@ -298,10 +304,12 @@ void CoreNetwork::disconnectFromIrc(bool requested, const QString& reason, bool
     else
         _quitReason = reason;
 
-    showMessage(Message::Server,
-                BufferInfo::StatusBuffer,
-                "",
-                tr("Disconnecting. (%1)").arg((!requested && !withReconnect) ? tr("Core Shutdown") : _quitReason));
+    showMessage(NetworkInternalMessage(
+        Message::Server,
+        BufferInfo::StatusBuffer,
+        "",
+        tr("Disconnecting. (%1)").arg((!requested && !withReconnect) ? tr("Core Shutdown") : _quitReason)
+    ));
     if (socket.state() == QAbstractSocket::UnconnectedState) {
         onSocketDisconnected();
     }
@@ -323,9 +331,9 @@ void CoreNetwork::disconnectFromIrc(bool requested, const QString& reason, bool
 void CoreNetwork::onSocketCloseTimeout()
 {
     qWarning() << QString{"Timed out quitting network %1 (network ID: %2, user ID: %3)"}
-                      .arg(networkName())
-                      .arg(networkId().toInt())
-                      .arg(userId().toInt());
+        .arg(networkName())
+        .arg(networkId().toInt())
+        .arg(userId().toInt());
     socket.abort();
 }
 
@@ -361,12 +369,12 @@ void CoreNetwork::putRawLine(const QByteArray& s, bool prepend)
     }
 }
 
-void CoreNetwork::putCmd(const QString& cmd, const QList<QByteArray>& params, const QByteArray& prefix, const QHash<IrcTagKey, QString> &tags, const bool prepend)
+void CoreNetwork::putCmd(const QString& cmd, const QList<QByteArray>& params, const QByteArray& prefix, const QHash<IrcTagKey, QString>& tags, bool prepend)
 {
     putRawLine(IrcEncoder::writeMessage(tags, prefix, cmd, params), prepend);
 }
 
-void CoreNetwork::putCmd(const QString& cmd, const QList<QList<QByteArray>>& params, const QByteArray& prefix, const QHash<IrcTagKey, QString> &tags, const bool prependAll)
+void CoreNetwork::putCmd(const QString& cmd, const QList<QList<QByteArray>>& params, const QByteArray& prefix, const QHash<IrcTagKey, QString>& tags, bool prependAll)
 {
     QListIterator<QList<QByteArray>> i(params);
     while (i.hasNext()) {
@@ -517,7 +525,12 @@ void CoreNetwork::onSocketError(QAbstractSocket::SocketError error)
     _previousConnectionAttemptFailed = true;
     qWarning() << qPrintable(tr("Could not connect to %1 (%2)").arg(networkName(), socket.errorString()));
     emit connectionError(socket.errorString());
-    showMessage(Message::Error, BufferInfo::StatusBuffer, "", tr("Connection failure: %1").arg(socket.errorString()));
+    showMessage(NetworkInternalMessage(
+        Message::Error,
+        BufferInfo::StatusBuffer,
+        "",
+        tr("Connection failure: %1").arg(socket.errorString())
+    ));
     emitConnectionError(socket.errorString());
     if (socket.state() < QAbstractSocket::ConnectedState) {
         onSocketDisconnected();
@@ -564,7 +577,12 @@ void CoreNetwork::onSocketInitialized()
 
     // Request capabilities as per IRCv3.2 specifications
     // Older servers should ignore this; newer servers won't downgrade to RFC1459
-    showMessage(Message::Server, BufferInfo::StatusBuffer, "", tr("Requesting capability list..."));
+    showMessage(NetworkInternalMessage(
+        Message::Server,
+        BufferInfo::StatusBuffer,
+        "",
+        tr("Requesting capability list...")
+    ));
     putRawLine(serverEncode(QString("CAP LS 302")));
 
     if (!server.password.isEmpty()) {
@@ -599,8 +617,14 @@ void CoreNetwork::onSocketDisconnected()
 
     IrcUser* me_ = me();
     if (me_) {
-        foreach (QString channel, me_->channels())
-            showMessage(Message::Quit, BufferInfo::ChannelBuffer, channel, _quitReason, me_->hostmask());
+        for (const QString& channel : me_->channels()) {
+            showMessage(NetworkInternalMessage(
+                Message::Quit,
+                BufferInfo::ChannelBuffer,
+                channel,
+                _quitReason, me_->hostmask()
+            ));
+        }
     }
 
     setConnected(false);
@@ -706,7 +730,7 @@ void CoreNetwork::sendPerform()
     }
 
     // send perform list
-    foreach (QString line, perform()) {
+    for (const QString& line : perform()) {
         if (!line.isEmpty())
             userInput(statusBuf, line);
     }
@@ -714,7 +738,7 @@ void CoreNetwork::sendPerform()
     // rejoin channels we've been in
     if (rejoinChannels()) {
         QStringList channels, keys;
-        foreach (QString chan, coreSession()->persistentChannels(networkId()).keys()) {
+        for (const QString& chan : coreSession()->persistentChannels(networkId()).keys()) {
             QString key = channelKey(chan);
             if (!key.isEmpty()) {
                 channels.prepend(chan);
@@ -898,7 +922,7 @@ void CoreNetwork::sendPing()
         qDebug() << "UserId:" << userId() << "Network:" << networkName() << "missed" << _pingCount << "pings."
                  << "BA:" << socket.bytesAvailable() << "BTW:" << socket.bytesToWrite();
     }
-    if ((int)_pingCount >= networkConfig()->maxPingCount() && (now - _lastPingTime) <= (_pingTimer.interval() + (1 * 1000))) {
+    if ((int) _pingCount >= networkConfig()->maxPingCount() && (now - _lastPingTime) <= (_pingTimer.interval() + (1 * 1000))) {
         // In transitioning to 64-bit time, the interval no longer needs converted down to seconds.
         // However, to reduce the risk of breaking things by changing past behavior, we still allow
         // up to 1 second missed instead of enforcing a stricter 1 millisecond allowance.
@@ -955,7 +979,7 @@ void CoreNetwork::setPongTimestampValid(bool validTimestamp)
 
 /******** Custom Rate Limiting ********/
 
-void CoreNetwork::updateRateLimiting(const bool forceUnlimited)
+void CoreNetwork::updateRateLimiting(bool forceUnlimited)
 {
     // Verify and apply custom rate limiting options, always resetting the delay and burst size
     // (safe-guarding against accidentally starting the timer), but don't reset the token bucket as
@@ -1075,7 +1099,12 @@ void CoreNetwork::serverCapAcknowledged(const QString& capability)
                 putRawLine(serverEncode("AUTHENTICATE EXTERNAL"));
             }
             else {
-                showMessage(Message::Error, BufferInfo::StatusBuffer, "", tr("SASL EXTERNAL authentication not supported"));
+                showMessage(NetworkInternalMessage(
+                    Message::Error,
+                    BufferInfo::StatusBuffer,
+                    "",
+                    tr("SASL EXTERNAL authentication not supported")
+                ));
                 sendNextCap();
             }
         }
@@ -1087,7 +1116,12 @@ void CoreNetwork::serverCapAcknowledged(const QString& capability)
                 putRawLine(serverEncode("AUTHENTICATE PLAIN"));
             }
             else {
-                showMessage(Message::Error, BufferInfo::StatusBuffer, "", tr("SASL PLAIN authentication not supported"));
+                showMessage(NetworkInternalMessage(
+                    Message::Error,
+                    BufferInfo::StatusBuffer,
+                    "",
+                    tr("SASL PLAIN authentication not supported")
+                ));
                 sendNextCap();
             }
 #ifdef HAVE_SSL
@@ -1196,10 +1230,12 @@ void CoreNetwork::retryCapsIndividually()
     // Add most recently tried capability set to individual list, re-requesting them one at a time
     _capsQueuedIndividual.append(_capsQueuedLastBundle);
     // Warn of this issue to explain the slower login.  Servers usually shouldn't trigger this.
-    showMessage(Message::Server,
-                BufferInfo::StatusBuffer,
-                "",
-                tr("Could not negotiate some capabilities, retrying individually (%1)...").arg(_capsQueuedLastBundle.join(", ")));
+    showMessage(NetworkInternalMessage(
+        Message::Server,
+        BufferInfo::StatusBuffer,
+        "",
+        tr("Could not negotiate some capabilities, retrying individually (%1)...").arg(_capsQueuedLastBundle.join(", "))
+    ));
     // Capabilities are already removed from the capability bundle queue via takeQueuedCaps(), no
     // need to remove them here.
     // Clear the most recently tried set to reduce risk that mistakes elsewhere causes retrying
@@ -1213,20 +1249,35 @@ void CoreNetwork::beginCapNegotiation()
     if (!capNegotiationInProgress()) {
         // If the server doesn't have any capabilities, but supports CAP LS, continue on with the
         // normal connection.
-        showMessage(Message::Server, BufferInfo::StatusBuffer, "", tr("No capabilities available"));
+        showMessage(NetworkInternalMessage(
+            Message::Server,
+            BufferInfo::StatusBuffer,
+            "",
+            tr("No capabilities available")
+        ));
         endCapNegotiation();
         return;
     }
 
     _capNegotiationActive = true;
-    showMessage(Message::Server, BufferInfo::StatusBuffer, "", tr("Ready to negotiate (found: %1)").arg(caps().join(", ")));
+    showMessage(NetworkInternalMessage(
+        Message::Server,
+        BufferInfo::StatusBuffer,
+        "",
+        tr("Ready to negotiate (found: %1)").arg(caps().join(", "))
+    ));
 
     // Build a list of queued capabilities, starting with individual, then bundled, only adding the
     // comma separator between the two if needed (both individual and bundled caps exist).
     QString queuedCapsDisplay = _capsQueuedIndividual.join(", ")
                                 + ((!_capsQueuedIndividual.empty() && !_capsQueuedBundled.empty()) ? ", " : "")
                                 + _capsQueuedBundled.join(", ");
-    showMessage(Message::Server, BufferInfo::StatusBuffer, "", tr("Negotiating capabilities (requesting: %1)...").arg(queuedCapsDisplay));
+    showMessage(NetworkInternalMessage(
+        Message::Server,
+        BufferInfo::StatusBuffer,
+        "",
+        tr("Negotiating capabilities (requesting: %1)...").arg(queuedCapsDisplay)
+    ));
 
     sendNextCap();
 }
@@ -1241,13 +1292,20 @@ void CoreNetwork::sendNextCap()
         // No pending desired capabilities, capability negotiation finished
         // If SASL requested but not available, print a warning
         if (networkInfo().useSasl && !capEnabled(IrcCap::SASL))
-            showMessage(Message::Error, BufferInfo::StatusBuffer, "", tr("SASL authentication currently not supported by server"));
+            showMessage(NetworkInternalMessage(
+                Message::Error,
+                BufferInfo::StatusBuffer,
+                "",
+                tr("SASL authentication currently not supported by server")
+            ));
 
         if (_capNegotiationActive) {
-            showMessage(Message::Server,
-                        BufferInfo::StatusBuffer,
-                        "",
-                        tr("Capability negotiation finished (enabled: %1)").arg(capsEnabled().join(", ")));
+            showMessage(NetworkInternalMessage(
+                Message::Server,
+                BufferInfo::StatusBuffer,
+                "",
+                tr("Capability negotiation finished (enabled: %1)").arg(capsEnabled().join(", "))
+            ));
             _capNegotiationActive = false;
         }
 
@@ -1385,7 +1443,12 @@ void CoreNetwork::onSslErrors(const QList<QSslError>& sslErrors)
             // Add the error reason if known
             sslErrorMessage.append(tr(" (Reason: %1)").arg(sslErrors.first().errorString()));
         }
-        showMessage(Message::Error, BufferInfo::StatusBuffer, "", sslErrorMessage);
+        showMessage(NetworkInternalMessage(
+            Message::Error,
+            BufferInfo::StatusBuffer,
+            "",
+            sslErrorMessage
+        ));
 
         // Disconnect, triggering a reconnect in case it's a temporary issue with certificate
         // validity, network trouble, etc.
@@ -1399,7 +1462,12 @@ void CoreNetwork::onSslErrors(const QList<QSslError>& sslErrors)
             // Add the error reason if known
             sslErrorMessage.append(tr(" (Reason: %1)").arg(sslErrors.first().errorString()));
         }
-        showMessage(Message::Info, BufferInfo::StatusBuffer, "", sslErrorMessage);
+        showMessage(NetworkInternalMessage(
+            Message::Info,
+            BufferInfo::StatusBuffer,
+            "",
+            sslErrorMessage
+        ));
 
         // Proceed with the connection
         socket.ignoreSslErrors();
@@ -1411,7 +1479,7 @@ void CoreNetwork::onSslErrors(const QList<QSslError>& sslErrors)
 void CoreNetwork::checkTokenBucket()
 {
     if (_skipMessageRates) {
-        if (_msgQueue.size() == 0) {
+        if (_msgQueue.empty()) {
             // Message queue emptied; stop the timer and bail out
             _tokenBucketTimer.stop();
             return;
@@ -1431,7 +1499,7 @@ void CoreNetwork::fillBucketAndProcessQueue()
     }
 
     // As long as there's tokens available and messages remaining, sending messages from the queue
-    while (_msgQueue.size() > 0 && _tokenBucket > 0) {
+    while (!_msgQueue.empty() && _tokenBucket > 0) {
         writeToSocket(_msgQueue.takeFirst());
     }
 }
index f07f2a2..bcab1df 100644 (file)
@@ -335,7 +335,7 @@ public slots:
      * set by the user.  Use with caution and remember to re-enable configured limits when done.
      * @endparmblock
      */
-    void updateRateLimiting(const bool forceUnlimited = false);
+    void updateRateLimiting(bool forceUnlimited = false);
 
     /**
      * Resets the token bucket up to the maximum
@@ -418,21 +418,15 @@ public slots:
      */
     inline void resetPongReplyPending() { _pongReplyPending = false; }
 
-    void onDisplayMsg(Message::Type msgType,
-                      BufferInfo::Type bufferType,
-                      const QString& target,
-                      const QString& text,
-                      const QString& sender,
-                      Message::Flags flags)
+    void onDisplayMsg(const NetworkInternalMessage& msg)
     {
-        emit displayMsg(networkId(), msgType, bufferType, target, text, sender, flags);
+        emit displayMsg(RawMessage(networkId(), msg));
     }
 
 signals:
-    void recvRawServerMsg(QString);
-    void displayStatusMsg(QString);
-    void displayMsg(
-        NetworkId, Message::Type, BufferInfo::Type, const QString& target, const QString& text, const QString& sender, Message::Flags flags);
+    void recvRawServerMsg(const QString&);
+    void displayStatusMsg(const QString&);
+    void displayMsg(const RawMessage& msg);
     void disconnected(NetworkId networkId);
     void connectionError(const QString& errorMsg);
 
@@ -508,14 +502,9 @@ private slots:
     void writeToSocket(const QByteArray& data);
 
 private:
-    void showMessage(Message::Type msgType,
-                     BufferInfo::Type bufferType,
-                     const QString& target,
-                     const QString& text,
-                     const QString& sender = "",
-                     Message::Flags flags = Message::None)
+    void showMessage(const NetworkInternalMessage& msg)
     {
-        emit displayMsg(networkId(), msgType, bufferType, target, text, sender, flags);
+        emit displayMsg(RawMessage(networkId(), msg));
     }
 
 private:
index 3bc6f3c..852c37b 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "coresession.h"
 
+#include <utility>
+
 #include <QtScript>
 
 #include "core.h"
@@ -113,7 +115,7 @@ CoreSession::CoreSession(UserId uid, bool restoreState, bool strictIdentEnabled,
     QVariantMap data;
     data["quasselVersion"] = Quassel::buildInfo().fancyVersionString;
     data["quasselBuildDate"] = Quassel::buildInfo().commitDate;  // "BuildDate" for compatibility
-    data["startTime"] = Core::instance()->startTime();
+    data["startTime"] = Core::startTime();
     data["sessionConnectedClients"] = 0;
     _coreInfo->setCoreData(data);
 
@@ -130,7 +132,7 @@ CoreSession::CoreSession(UserId uid, bool restoreState, bool strictIdentEnabled,
     eventManager()->registerObject(ctcpParser(), EventManager::LowPriority, "send");
 
     // periodically save our session state
-    connect(Core::instance()->syncTimer(), &QTimer::timeout, this, &CoreSession::saveSessionState);
+    connect(Core::syncTimer(), &QTimer::timeout, this, &CoreSession::saveSessionState);
 
     p->synchronize(_bufferSyncer);
     p->synchronize(&aliasManager());
@@ -201,7 +203,7 @@ void CoreSession::loadSettings()
     // migrate to db
     QList<IdentityId> ids = s.identityIds();
     QList<NetworkInfo> networkInfos = Core::networks(user());
-    foreach (IdentityId id, ids) {
+    for (IdentityId id : ids) {
         CoreIdentity identity(s.identity(id));
         IdentityId newId = Core::createIdentity(user(), identity);
         QList<NetworkInfo>::iterator networkIter = networkInfos.begin();
@@ -219,11 +221,11 @@ void CoreSession::loadSettings()
     }
     // end of migration
 
-    foreach (CoreIdentity identity, Core::identities(user())) {
+    for (const CoreIdentity& identity : Core::identities(user())) {
         createIdentity(identity);
     }
 
-    foreach (NetworkInfo info, Core::networks(user())) {
+    for (const NetworkInfo& info : Core::networks(user())) {
         createNetwork(info);
     }
 }
@@ -239,7 +241,7 @@ void CoreSession::restoreSessionState()
 {
     QList<NetworkId> nets = Core::connectedNetworks(user());
     CoreNetwork* net = nullptr;
-    foreach (NetworkId id, nets) {
+    for (NetworkId id :  nets) {
         net = network(id);
         Q_ASSERT(net);
         net->connectToIrc();
@@ -300,31 +302,23 @@ void CoreSession::msgFromClient(BufferInfo bufinfo, QString msg)
 
 // ALL messages coming pass through these functions before going to the GUI.
 // So this is the perfect place for storing the backlog and log stuff.
-void CoreSession::recvMessageFromServer(NetworkId networkId,
-                                        Message::Type type,
-                                        BufferInfo::Type bufferType,
-                                        const QString& target,
-                                        const QString& text_,
-                                        const QString& sender,
-                                        Message::Flags flags)
+void CoreSession::recvMessageFromServer(RawMessage msg)
 {
     // U+FDD0 and U+FDD1 are special characters for Qt's text engine, specifically they mark the boundaries of
     // text frames in a QTextDocument. This might lead to problems in widgets displaying QTextDocuments (such as
     // KDE's notifications), hence we remove those just to be safe.
-    QString text = text_;
-    text.remove(QChar(0xfdd0)).remove(QChar(0xfdd1));
-    RawMessage rawMsg(networkId, type, bufferType, target, text, sender, flags);
+    msg.text.remove(QChar(0xfdd0)).remove(QChar(0xfdd1));
 
     // check for HardStrictness ignore
-    CoreNetwork* currentNetwork = network(networkId);
+    CoreNetwork* currentNetwork = network(msg.networkId);
     QString networkName = currentNetwork ? currentNetwork->networkName() : QString("");
-    if (_ignoreListManager.match(rawMsg, networkName) == IgnoreListManager::HardStrictness)
+    if (_ignoreListManager.match(msg, networkName) == IgnoreListManager::HardStrictness)
         return;
 
-    if (currentNetwork && _highlightRuleManager.match(rawMsg, currentNetwork->myNick(), currentNetwork->identityPtr()->nicks()))
-        rawMsg.flags |= Message::Flag::Highlight;
+    if (currentNetwork && _highlightRuleManager.match(msg, currentNetwork->myNick(), currentNetwork->identityPtr()->nicks()))
+        msg.flags |= Message::Flag::Highlight;
 
-    _messageQueue << rawMsg;
+    _messageQueue << std::move(msg);
     if (!_processMessages) {
         _processMessages = true;
         QCoreApplication::postEvent(this, new ProcessMessagesEvent());
@@ -335,18 +329,20 @@ void CoreSession::recvStatusMsgFromServer(QString msg)
 {
     auto* net = qobject_cast<CoreNetwork*>(sender());
     Q_ASSERT(net);
-    emit displayStatusMsg(net->networkName(), msg);
+    emit displayStatusMsg(net->networkName(), std::move(msg));
 }
 
 void CoreSession::processMessageEvent(MessageEvent* event)
 {
-    recvMessageFromServer(event->networkId(),
-                          event->msgType(),
-                          event->bufferType(),
-                          event->target().isNull() ? "" : event->target(),
-                          event->text().isNull() ? "" : event->text(),
-                          event->sender().isNull() ? "" : event->sender(),
-                          event->msgFlags());
+    recvMessageFromServer(RawMessage{
+        event->networkId(),
+        event->msgType(),
+        event->bufferType(),
+        event->target().isNull() ? "" : event->target(),
+        event->text().isNull() ? "" : event->text(),
+        event->sender().isNull() ? "" : event->sender(),
+        event->msgFlags()
+    });
 }
 
 QList<BufferInfo> CoreSession::buffers() const
@@ -502,12 +498,15 @@ Protocol::SessionState CoreSession::sessionState() const
     QVariantList networkIds;
     QVariantList identities;
 
-    foreach (const BufferInfo& id, buffers())
+    for (const BufferInfo& id : buffers()) {
         bufferInfos << QVariant::fromValue(id);
-    foreach (const NetworkId& id, _networks.keys())
+    }
+    for (const NetworkId& id : _networks.keys()) {
         networkIds << QVariant::fromValue(id);
-    foreach (const Identity* i, _identities.values())
+    }
+    for (const Identity* i : _identities.values()) {
         identities << QVariant::fromValue(*i);
+    }
 
     return Protocol::SessionState(identities, bufferInfos, networkIds);
 }
@@ -609,7 +608,7 @@ void CoreSession::createNetwork(const NetworkInfo& info_, const QStringList& per
     if (!_networks.contains(id)) {
         // create persistent chans
         QRegExp rx(R"(\s*(\S+)(?:\s*(\S+))?\s*)");
-        foreach (QString channel, persistentChans) {
+        for (const QString& channel : persistentChans) {
             if (!rx.exactMatch(channel)) {
                 qWarning() << QString("Invalid persistent channel declaration: %1").arg(channel);
                 continue;
@@ -672,7 +671,7 @@ void CoreSession::destroyNetwork(NetworkId id)
             }
         }
         // remove buffers from syncer
-        foreach (BufferId bufferId, removedBuffers) {
+        for (BufferId bufferId : removedBuffers) {
             _bufferSyncer->removeBuffer(bufferId);
         }
         emit networkRemoved(id);
index 07426f9..5a05f02 100644 (file)
@@ -52,7 +52,6 @@ class EventStringifier;
 class InternalPeer;
 class IrcParser;
 class MessageEvent;
-class NetworkConnection;
 class RemotePeer;
 class SignalProxy;
 
@@ -83,7 +82,6 @@ public:
     const QString strictCompliantIdent(const CoreIdentity* identity);
 
     inline CoreNetworkConfig* networkConfig() const { return _networkConfig; }
-    NetworkConnection* networkConnection(NetworkId) const;
 
     Protocol::SessionState sessionState() const;
 
@@ -164,7 +162,7 @@ public slots:
      * @param[in] msg             Away message, or blank to set unaway
      * @param[in] skipFormatting  If true, skip timestamp formatting codes (e.g. if already done)
      */
-    void globalAway(const QString& msg = QString(), const bool skipFormatting = false);
+    void globalAway(const QString& msg = QString(), bool skipFormatting = false);
 
 signals:
     void initialized();
@@ -203,13 +201,7 @@ private slots:
     void removeClient(Peer* peer);
 
     void recvStatusMsgFromServer(QString msg);
-    void recvMessageFromServer(NetworkId networkId,
-                               Message::Type,
-                               BufferInfo::Type,
-                               const QString& target,
-                               const QString& text,
-                               const QString& sender = "",
-                               Message::Flags flags = Message::None);
+    void recvMessageFromServer(RawMessage msg);
 
     void destroyNetwork(NetworkId);
 
@@ -289,6 +281,24 @@ private:
     CoreHighlightRuleManager _highlightRuleManager;
 };
 
+struct NetworkInternalMessage
+{
+    Message::Type type;
+    BufferInfo::Type bufferType;
+    QString target;
+    QString text;
+    QString sender;
+    Message::Flags flags;
+    NetworkInternalMessage(Message::Type type, BufferInfo::Type bufferType, QString target, QString text, QString sender = "", Message::Flags flags = Message::None)
+        : type(type)
+        , bufferType(bufferType)
+        , target(std::move(target))
+        , text(std::move(text))
+        , sender(std::move(sender))
+        , flags(flags)
+    {}
+};
+
 struct RawMessage
 {
     NetworkId networkId;
@@ -308,4 +318,14 @@ struct RawMessage
         , sender(std::move(sender))
         , flags(flags)
     {}
+
+    RawMessage(NetworkId networkId, const NetworkInternalMessage& msg)
+        : networkId(networkId)
+        , type(msg.type)
+        , bufferType(msg.bufferType)
+        , target(msg.target)
+        , text(msg.text)
+        , sender(msg.sender)
+        , flags(msg.flags)
+    {}
 };
index 98d833e..c1807ab 100644 (file)
@@ -406,7 +406,7 @@ void CoreSessionEventProcessor::processIrcEventJoin(IrcEvent* e)
     // Else :nick!user@host JOIN #channelname
 
     bool handledByNetsplit = false;
-    foreach (Netsplit* n, _netsplits.value(e->network())) {
+    for (Netsplit* n : _netsplits.value(e->network())) {
         handledByNetsplit = n->userJoined(e->prefix(), channel);
         if (handledByNetsplit)
             break;
@@ -488,7 +488,7 @@ void CoreSessionEventProcessor::processIrcEventMode(IrcEvent* e)
                         if (add) {
                             bool handledByNetsplit = false;
                             QHash<QString, Netsplit*> splits = _netsplits.value(e->network());
-                            foreach (Netsplit* n, _netsplits.value(e->network())) {
+                            for (Netsplit* n : _netsplits.value(e->network())) {
                                 handledByNetsplit = n->userAlreadyJoined(ircUser->hostmask(), channel->name());
                                 if (handledByNetsplit) {
                                     n->addMode(ircUser->hostmask(), channel->name(), QString(mode));
@@ -1191,7 +1191,7 @@ void CoreSessionEventProcessor::processIrcEvent353(IrcEvent* e)
     // Cache result of multi-prefix to avoid unneeded casts and lookups with each iteration.
     bool _useCapMultiPrefix = coreNetwork(e)->capEnabled(IrcCap::MULTI_PREFIX);
 
-    foreach (QString nick, e->params()[2].split(' ', QString::SkipEmptyParts)) {
+    for (QString nick : e->params()[2].split(' ', QString::SkipEmptyParts)) {
         QString mode;
 
         if (_useCapMultiPrefix) {
@@ -1427,7 +1427,7 @@ void CoreSessionEventProcessor::handleNetsplitJoin(
     QStringList newModes = modes;
     QStringList newUsers = users;
 
-    foreach (const QString& user, users) {
+    for (const QString& user : users) {
         IrcUser* iu = net->ircUser(nickFromMask(user));
         if (iu)
             ircUsers.append(iu);
@@ -1447,10 +1447,9 @@ void CoreSessionEventProcessor::handleNetsplitQuit(Network* net, const QString&
 {
     NetworkSplitEvent* event = new NetworkSplitEvent(EventManager::NetworkSplitQuit, net, channel, users, quitMessage);
     emit newEvent(event);
-    foreach (QString user, users) {
-        IrcUser* iu = net->ircUser(nickFromMask(user));
-        if (iu)
-            iu->quit();
+    for (const QString& user : users) {
+        IrcUser* ircUser = net->ircUser(nickFromMask(user));
+        if (ircUser) ircUser->quit();
     }
 }
 
@@ -1465,19 +1464,19 @@ void CoreSessionEventProcessor::handleEarlyNetsplitJoin(Network* net, const QStr
     QList<IrcUser*> ircUsers;
     QStringList newModes = modes;
 
-    foreach (QString user, users) {
-        IrcUser* iu = net->updateNickFromMask(user);
-        if (iu) {
-            ircUsers.append(iu);
+    for (const QString& user : users) {
+        IrcUser* ircUser = net->updateNickFromMask(user);
+        if (ircUser) {
+            ircUsers.append(ircUser);
             // fake event for scripts that consume join events
-            events << new IrcEvent(EventManager::IrcEventJoin, net, iu->hostmask(), QStringList() << channel);
+            events << new IrcEvent(EventManager::IrcEventJoin, net, ircUser->hostmask(), QStringList() << channel);
         }
         else {
             newModes.removeAt(users.indexOf(user));
         }
     }
     ircChannel->joinIrcUsers(ircUsers, newModes);
-    foreach (NetworkEvent* event, events) {
+    for (NetworkEvent* event : events) {
         event->setFlag(EventManager::Fake);  // ignore this in here!
         emit newEvent(event);
     }
@@ -1535,7 +1534,7 @@ void CoreSessionEventProcessor::handleCtcpAction(CtcpEvent* e)
 void CoreSessionEventProcessor::handleCtcpClientinfo(CtcpEvent* e)
 {
     QStringList supportedHandlers;
-    foreach (QString handler, providesHandlers())
+    for (const QString& handler : providesHandlers())
         supportedHandlers << handler.toUpper();
     qSort(supportedHandlers);
     e->setReply(supportedHandlers.join(" "));
index 76fe1f4..e168faf 100644 (file)
@@ -18,8 +18,7 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
-#ifndef CORESESSIONEVENTPROCESSOR_H
-#define CORESESSIONEVENTPROCESSOR_H
+#pragma once
 
 #include "basichandler.h"
 #include "corenetwork.h"
@@ -40,7 +39,7 @@ class CoreSessionEventProcessor : public BasicHandler
     Q_OBJECT
 
 public:
-    CoreSessionEventProcessor(CoreSession* session);
+    explicit CoreSessionEventProcessor(CoreSession* session);
 
     inline CoreSession* coreSession() const { return _coreSession; }
 
@@ -186,5 +185,3 @@ private:
                                const QString& awayStateAndModes,
                                const QString& realname);
 };
-
-#endif
index 03bee36..1e00426 100644 (file)
@@ -122,7 +122,12 @@ void CoreUserInputHandler::banOrUnban(const BufferInfo& bufferInfo, const QStrin
         banChannel = bufferInfo.bufferName();
     }
     else {
-        emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", QString("Error: channel unknown in command: /BAN %1").arg(msg));
+        emit displayMsg(NetworkInternalMessage(
+            Message::Error,
+            BufferInfo::StatusBuffer,
+            "",
+            QString("Error: channel unknown in command: /BAN %1").arg(msg)
+        ));
         return;
     }
 
@@ -131,7 +136,12 @@ void CoreUserInputHandler::banOrUnban(const BufferInfo& bufferInfo, const QStrin
         // generalizedHost changes <nick> to  *!ident@*.sld.tld.
         QString generalizedHost = ircuser->host();
         if (generalizedHost.isEmpty()) {
-            emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", QString("Error: host unknown in command: /BAN %1").arg(msg));
+            emit displayMsg(NetworkInternalMessage(
+                Message::Error,
+                BufferInfo::StatusBuffer,
+                "",
+                QString("Error: host unknown in command: /BAN %1").arg(msg)
+            ));
             return;
         }
 
@@ -173,7 +183,14 @@ void CoreUserInputHandler::handleCtcp(const BufferInfo& bufferInfo, const QStrin
 
     // FIXME make this a proper event
     coreNetwork()->coreSession()->ctcpParser()->query(coreNetwork(), nick, ctcpTag, message);
-    emit displayMsg(Message::Action, BufferInfo::StatusBuffer, "", verboseMessage, network()->myNick(), Message::Flag::Self);
+    emit displayMsg(NetworkInternalMessage(
+        Message::Action,
+        BufferInfo::StatusBuffer,
+        "",
+        verboseMessage,
+        network()->myNick(),
+        Message::Flag::Self
+    ));
 }
 
 void CoreUserInputHandler::handleDelkey(const BufferInfo& bufferInfo, const QString& msg)
@@ -184,10 +201,12 @@ void CoreUserInputHandler::handleDelkey(const BufferInfo& bufferInfo, const QStr
         return;
 
     if (!Cipher::neededFeaturesAvailable()) {
-        emit displayMsg(Message::Error,
-                        typeByTarget(bufname),
-                        bufname,
-                        tr("Error: QCA provider plugin not found. It is usually provided by the qca-ossl plugin."));
+        emit displayMsg(NetworkInternalMessage(
+            Message::Error,
+            typeByTarget(bufname),
+            bufname,
+            tr("Error: QCA provider plugin not found. It is usually provided by the qca-ossl plugin.")
+        ));
         return;
     }
 
@@ -197,39 +216,52 @@ void CoreUserInputHandler::handleDelkey(const BufferInfo& bufferInfo, const QStr
         parms.prepend(bufferInfo.bufferName());
 
     if (parms.isEmpty()) {
-        emit displayMsg(Message::Info,
-                        typeByTarget(bufname),
-                        bufname,
-                        tr("[usage] /delkey <nick|channel> deletes the encryption key for nick or channel or just /delkey when in a "
-                           "channel or query."));
+        emit displayMsg(NetworkInternalMessage(
+            Message::Info,
+            typeByTarget(bufname),
+            bufname,
+            tr("[usage] /delkey <nick|channel> deletes the encryption key for nick or channel or just /delkey when in a "
+               "channel or query.")
+        ));
         return;
     }
 
     QString target = parms.at(0);
 
     if (network()->cipherKey(target).isEmpty()) {
-        emit displayMsg(Message::Info, typeByTarget(bufname), bufname, tr("No key has been set for %1.").arg(target));
+        emit displayMsg(NetworkInternalMessage(
+            Message::Info,
+            typeByTarget(bufname),
+            bufname,
+            tr("No key has been set for %1.").arg(target)
+        ));
         return;
     }
 
     network()->setCipherKey(target, QByteArray());
-    emit displayMsg(Message::Info, typeByTarget(bufname), bufname, tr("The key for %1 has been deleted.").arg(target));
+    emit displayMsg(NetworkInternalMessage(
+        Message::Info,
+        typeByTarget(bufname),
+        bufname,
+        tr("The key for %1 has been deleted.").arg(target)
+    ));
 
 #else
     Q_UNUSED(msg)
-    emit displayMsg(Message::Error,
-                    typeByTarget(bufname),
-                    bufname,
-                    tr("Error: Setting an encryption key requires Quassel to have been built "
-                       "with support for the Qt Cryptographic Architecture (QCA2) library. "
-                       "Contact your distributor about a Quassel package with QCA2 "
-                       "support, or rebuild Quassel with QCA2 present."));
+    emit displayMsg(NetworkInternalMessage(
+        Message::Error,
+        typeByTarget(bufname),
+        bufname,
+        tr("Error: Setting an encryption key requires Quassel to have been built "
+           "with support for the Qt Cryptographic Architecture (QCA2) library. "
+           "Contact your distributor about a Quassel package with QCA2 "
+           "support, or rebuild Quassel with QCA2 present.")
+    ));
 #endif
 }
 
 void CoreUserInputHandler::doMode(const BufferInfo& bufferInfo, const QChar& addOrRemove, const QChar& mode, const QString& nicks)
 {
-    QString m;
     bool isNumber;
     int maxModes = network()->support("MODES").toInt(&isNumber);
     if (!isNumber || maxModes == 0)
@@ -238,7 +270,7 @@ void CoreUserInputHandler::doMode(const BufferInfo& bufferInfo, const QChar& add
     QStringList nickList;
     if (nicks == "*" && bufferInfo.type() == BufferInfo::ChannelBuffer) {  // All users in channel
         const QList<IrcUser*> users = network()->ircChannel(bufferInfo.bufferName())->ircUsers();
-        foreach (IrcUser* user, users) {
+        for (IrcUser* user : users) {
             if ((addOrRemove == '+' && !network()->ircChannel(bufferInfo.bufferName())->userModes(user).contains(mode))
                 || (addOrRemove == '-' && network()->ircChannel(bufferInfo.bufferName())->userModes(user).contains(mode)))
                 nickList.append(user->nick());
@@ -365,10 +397,12 @@ void CoreUserInputHandler::handleKeyx(const BufferInfo& bufferInfo, const QStrin
         return;
 
     if (!Cipher::neededFeaturesAvailable()) {
-        emit displayMsg(Message::Error,
-                        typeByTarget(bufname),
-                        bufname,
-                        tr("Error: QCA provider plugin not found. It is usually provided by the qca-ossl plugin."));
+        emit displayMsg(NetworkInternalMessage(
+            Message::Error,
+            typeByTarget(bufname),
+            bufname,
+            tr("Error: QCA provider plugin not found. It is usually provided by the qca-ossl plugin.")
+        ));
         return;
     }
 
@@ -377,17 +411,24 @@ void CoreUserInputHandler::handleKeyx(const BufferInfo& bufferInfo, const QStrin
     if (parms.count() == 0 && !bufferInfo.bufferName().isEmpty() && bufferInfo.acceptsRegularMessages())
         parms.prepend(bufferInfo.bufferName());
     else if (parms.count() != 1) {
-        emit displayMsg(Message::Info,
-                        typeByTarget(bufname),
-                        bufname,
-                        tr("[usage] /keyx [<nick>] Initiates a DH1080 key exchange with the target."));
+        emit displayMsg(NetworkInternalMessage(
+            Message::Info,
+            typeByTarget(bufname),
+            bufname,
+            tr("[usage] /keyx [<nick>] Initiates a DH1080 key exchange with the target.")
+        ));
         return;
     }
 
     QString target = parms.at(0);
 
     if (network()->isChannelName(target)) {
-        emit displayMsg(Message::Info, typeByTarget(bufname), bufname, tr("It is only possible to exchange keys in a query buffer."));
+        emit displayMsg(NetworkInternalMessage(
+            Message::Info,
+            typeByTarget(bufname),
+            bufname,
+            tr("It is only possible to exchange keys in a query buffer.")
+        ));
         return;
     }
 
@@ -397,22 +438,34 @@ void CoreUserInputHandler::handleKeyx(const BufferInfo& bufferInfo, const QStrin
 
     QByteArray pubKey = cipher->initKeyExchange();
     if (pubKey.isEmpty())
-        emit displayMsg(Message::Error, typeByTarget(bufname), bufname, tr("Failed to initiate key exchange with %1.").arg(target));
+        emit displayMsg(NetworkInternalMessage(
+            Message::Error,
+            typeByTarget(bufname),
+            bufname,
+            tr("Failed to initiate key exchange with %1.").arg(target)
+        ));
     else {
         QList<QByteArray> params;
         params << serverEncode(target) << serverEncode("DH1080_INIT ") + pubKey;
         emit putCmd("NOTICE", params);
-        emit displayMsg(Message::Info, typeByTarget(bufname), bufname, tr("Initiated key exchange with %1.").arg(target));
+        emit displayMsg(NetworkInternalMessage(
+            Message::Info,
+            typeByTarget(bufname),
+            bufname,
+            tr("Initiated key exchange with %1.").arg(target)
+        ));
     }
 #else
     Q_UNUSED(msg)
-    emit displayMsg(Message::Error,
-                    typeByTarget(bufname),
-                    bufname,
-                    tr("Error: Setting an encryption key requires Quassel to have been built "
-                       "with support for the Qt Cryptographic Architecture (QCA) library. "
-                       "Contact your distributor about a Quassel package with QCA "
-                       "support, or rebuild Quassel with QCA present."));
+    emit displayMsg(NetworkInternalMessage(
+        Message::Error,
+        typeByTarget(bufname),
+        bufname,
+        tr("Error: Setting an encryption key requires Quassel to have been built "
+           "with support for the Qt Cryptographic Architecture (QCA) library. "
+           "Contact your distributor about a Quassel package with QCA "
+           "support, or rebuild Quassel with QCA present.")
+    ));
 #endif
 }
 
@@ -454,10 +507,17 @@ void CoreUserInputHandler::handleMe(const BufferInfo& bufferInfo, const QString&
     // they need to be split into multiple messages.
     QStringList messages = msg.split(QChar::LineFeed);
 
-    foreach (auto message, messages) {
+    for (const auto& message : messages) {
         // Handle each separated message independently
         coreNetwork()->coreSession()->ctcpParser()->query(coreNetwork(), bufferInfo.bufferName(), "ACTION", message);
-        emit displayMsg(Message::Action, bufferInfo.type(), bufferInfo.bufferName(), message, network()->myNick(), Message::Self);
+        emit displayMsg(NetworkInternalMessage(
+            Message::Action,
+            bufferInfo.type(),
+            bufferInfo.bufferName(),
+            message,
+            network()->myNick(),
+            Message::Self
+        ));
     }
 }
 
@@ -469,7 +529,12 @@ void CoreUserInputHandler::handleMode(const BufferInfo& bufferInfo, const QStrin
     if (!params.isEmpty()) {
         if (params[0] == "-reset" && params.count() == 1) {
             network()->resetPersistentModes();
-            emit displayMsg(Message::Info, BufferInfo::StatusBuffer, "", tr("Your persistent modes have been reset."));
+            emit displayMsg(NetworkInternalMessage(
+                Message::Info,
+                BufferInfo::StatusBuffer,
+                "",
+                tr("Your persistent modes have been reset.")
+            ));
             return;
         }
         if (!network()->isChannelName(params[0]) && !network()->isMyNick(params[0]))
@@ -520,12 +585,19 @@ void CoreUserInputHandler::handleNotice(const BufferInfo& bufferInfo, const QStr
     // they need to be split into multiple messages.
     QStringList messages = msg.section(' ', 1).split(QChar::LineFeed);
 
-    foreach (auto message, messages) {
+    for (const auto& message : messages) {
         // Handle each separated message independently
         params.clear();
         params << serverEncode(bufferName) << channelEncode(bufferInfo.bufferName(), message);
         emit putCmd("NOTICE", params);
-        emit displayMsg(Message::Notice, typeByTarget(bufferName), bufferName, message, network()->myNick(), Message::Self);
+        emit displayMsg(NetworkInternalMessage(
+            Message::Notice,
+            typeByTarget(bufferName),
+            bufferName,
+            message,
+            network()->myNick(),
+            Message::Self
+        ));
     }
 }
 
@@ -575,7 +647,14 @@ void CoreUserInputHandler::handlePrint(const BufferInfo& bufferInfo, const QStri
         return;  // server buffer
 
     QByteArray encMsg = channelEncode(bufferInfo.bufferName(), msg);
-    emit displayMsg(Message::Info, bufferInfo.type(), bufferInfo.bufferName(), msg, network()->myNick(), Message::Self);
+    emit displayMsg(NetworkInternalMessage(
+        Message::Info,
+        bufferInfo.type(),
+        bufferInfo.bufferName(),
+        msg,
+        network()->myNick(),
+        Message::Self
+    ));
 }
 
 // TODO: implement queries
@@ -587,19 +666,28 @@ void CoreUserInputHandler::handleQuery(const BufferInfo& bufferInfo, const QStri
     // they need to be split into multiple messages.
     QStringList messages = msg.section(' ', 1).split(QChar::LineFeed);
 
-    foreach (auto message, messages) {
+    for (const auto& message : messages) {
         // Handle each separated message independently
         if (message.isEmpty()) {
-            emit displayMsg(Message::Server,
-                            BufferInfo::QueryBuffer,
-                            target,
-                            tr("Starting query with %1").arg(target),
-                            network()->myNick(),
-                            Message::Self);
+            emit displayMsg(NetworkInternalMessage(
+                Message::Server,
+                BufferInfo::QueryBuffer,
+                target,
+                tr("Starting query with %1").arg(target),
+                network()->myNick(),
+                Message::Self
+            ));
             // handleMsg is a no-op if message is empty
         }
         else {
-            emit displayMsg(Message::Plain, BufferInfo::QueryBuffer, target, message, network()->myNick(), Message::Self);
+            emit displayMsg(NetworkInternalMessage(
+                Message::Plain,
+                BufferInfo::QueryBuffer,
+                target,
+                message,
+                network()->myNick(),
+                Message::Self
+            ));
             // handleMsg needs the target specified at the beginning of the message
             handleMsg(bufferInfo, target + " " + message);
         }
@@ -636,14 +724,21 @@ void CoreUserInputHandler::handleSay(const BufferInfo& bufferInfo, const QString
     // they need to be split into multiple messages.
     QStringList messages = msg.split(QChar::LineFeed, QString::SkipEmptyParts);
 
-    foreach (auto message, messages) {
+    for (const auto& message : messages) {
         // Handle each separated message independently
 #ifdef HAVE_QCA2
         putPrivmsg(bufferInfo.bufferName(), message, encodeFunc, network()->cipher(bufferInfo.bufferName()));
 #else
         putPrivmsg(bufferInfo.bufferName(), message, encodeFunc);
 #endif
-        emit displayMsg(Message::Plain, bufferInfo.type(), bufferInfo.bufferName(), message, network()->myNick(), Message::Self);
+        emit displayMsg(NetworkInternalMessage(
+            Message::Plain,
+            bufferInfo.type(),
+            bufferInfo.bufferName(),
+            message,
+            network()->myNick(),
+            Message::Self
+        ));
     }
 }
 
@@ -655,10 +750,12 @@ void CoreUserInputHandler::handleSetkey(const BufferInfo& bufferInfo, const QStr
         return;
 
     if (!Cipher::neededFeaturesAvailable()) {
-        emit displayMsg(Message::Error,
-                        typeByTarget(bufname),
-                        bufname,
-                        tr("Error: QCA provider plugin not found. It is usually provided by the qca-ossl plugin."));
+        emit displayMsg(NetworkInternalMessage(
+            Message::Error,
+            typeByTarget(bufname),
+            bufname,
+            tr("Error: QCA provider plugin not found. It is usually provided by the qca-ossl plugin.")
+        ));
         return;
     }
 
@@ -667,11 +764,13 @@ void CoreUserInputHandler::handleSetkey(const BufferInfo& bufferInfo, const QStr
     if (parms.count() == 1 && !bufferInfo.bufferName().isEmpty() && bufferInfo.acceptsRegularMessages())
         parms.prepend(bufferInfo.bufferName());
     else if (parms.count() != 2) {
-        emit displayMsg(Message::Info,
-                        typeByTarget(bufname),
-                        bufname,
-                        tr("[usage] /setkey <nick|channel> <key> sets the encryption key for nick or channel. "
-                           "/setkey <key> when in a channel or query buffer sets the key for it."));
+        emit displayMsg(NetworkInternalMessage(
+            Message::Info,
+            typeByTarget(bufname),
+            bufname,
+            tr("[usage] /setkey <nick|channel> <key> sets the encryption key for nick or channel. "
+               "/setkey <key> when in a channel or query buffer sets the key for it.")
+        ));
         return;
     }
 
@@ -679,16 +778,23 @@ void CoreUserInputHandler::handleSetkey(const BufferInfo& bufferInfo, const QStr
     QByteArray key = parms.at(1).toLocal8Bit();
     network()->setCipherKey(target, key);
 
-    emit displayMsg(Message::Info, typeByTarget(bufname), bufname, tr("The key for %1 has been set.").arg(target));
+    emit displayMsg(NetworkInternalMessage(
+        Message::Info,
+        typeByTarget(bufname),
+        bufname,
+        tr("The key for %1 has been set.").arg(target)
+    ));
 #else
     Q_UNUSED(msg)
-    emit displayMsg(Message::Error,
-                    typeByTarget(bufname),
-                    bufname,
-                    tr("Error: Setting an encryption key requires Quassel to have been built "
-                       "with support for the Qt Cryptographic Architecture (QCA) library. "
-                       "Contact your distributor about a Quassel package with QCA "
-                       "support, or rebuild Quassel with QCA present."));
+    emit displayMsg(NetworkInternalMessage(
+        Message::Error,
+        typeByTarget(bufname),
+        bufname,
+        tr("Error: Setting an encryption key requires Quassel to have been built "
+           "with support for the Qt Cryptographic Architecture (QCA) library. "
+           "Contact your distributor about a Quassel package with QCA "
+           "support, or rebuild Quassel with QCA present.")
+    ));
 #endif
 }
 
@@ -700,10 +806,12 @@ void CoreUserInputHandler::handleShowkey(const BufferInfo& bufferInfo, const QSt
         return;
 
     if (!Cipher::neededFeaturesAvailable()) {
-        emit displayMsg(Message::Error,
-                        typeByTarget(bufname),
-                        bufname,
-                        tr("Error: QCA provider plugin not found. It is usually provided by the qca-ossl plugin."));
+        emit displayMsg(NetworkInternalMessage(
+            Message::Error,
+            typeByTarget(bufname),
+            bufname,
+            tr("Error: QCA provider plugin not found. It is usually provided by the qca-ossl plugin.")
+        ));
         return;
     }
 
@@ -713,11 +821,13 @@ void CoreUserInputHandler::handleShowkey(const BufferInfo& bufferInfo, const QSt
         parms.prepend(bufferInfo.bufferName());
 
     if (parms.isEmpty()) {
-        emit displayMsg(Message::Info,
-                        typeByTarget(bufname),
-                        bufname,
-                        tr("[usage] /showkey <nick|channel> shows the encryption key for nick or channel or just /showkey when in a "
-                           "channel or query."));
+        emit displayMsg(NetworkInternalMessage(
+            Message::Info,
+            typeByTarget(bufname),
+            bufname,
+            tr("[usage] /showkey <nick|channel> shows the encryption key for nick or channel or just /showkey when in a "
+               "channel or query.")
+        ));
         return;
     }
 
@@ -725,24 +835,33 @@ void CoreUserInputHandler::handleShowkey(const BufferInfo& bufferInfo, const QSt
     QByteArray key = network()->cipherKey(target);
 
     if (key.isEmpty()) {
-        emit displayMsg(Message::Info, typeByTarget(bufname), bufname, tr("No key has been set for %1.").arg(target));
+        emit displayMsg(NetworkInternalMessage(
+            Message::Info,
+            typeByTarget(bufname),
+            bufname,
+            tr("No key has been set for %1.").arg(target)
+        ));
         return;
     }
 
-    emit displayMsg(Message::Info,
-                    typeByTarget(bufname),
-                    bufname,
-                    tr("The key for %1 is %2:%3").arg(target, network()->cipherUsesCBC(target) ? "CBC" : "ECB", QString(key)));
+    emit displayMsg(NetworkInternalMessage(
+        Message::Info,
+        typeByTarget(bufname),
+        bufname,
+        tr("The key for %1 is %2:%3").arg(target, network()->cipherUsesCBC(target) ? "CBC" : "ECB", QString(key))
+    ));
 
 #else
     Q_UNUSED(msg)
-    emit displayMsg(Message::Error,
-                    typeByTarget(bufname),
-                    bufname,
-                    tr("Error: Setting an encryption key requires Quassel to have been built "
-                       "with support for the Qt Cryptographic Architecture (QCA2) library. "
-                       "Contact your distributor about a Quassel package with QCA2 "
-                       "support, or rebuild Quassel with QCA2 present."));
+    emit displayMsg(NetworkInternalMessage(
+        Message::Error,
+        typeByTarget(bufname),
+        bufname,
+        tr("Error: Setting an encryption key requires Quassel to have been built "
+           "with support for the Qt Cryptographic Architecture (QCA2) library. "
+           "Contact your distributor about a Quassel package with QCA2 "
+           "support, or rebuild Quassel with QCA2 present.")
+    ));
 #endif
 }
 
@@ -916,7 +1035,7 @@ void CoreUserInputHandler::timerEvent(QTimerEvent* event)
 
     // the stored command might be the result of an alias expansion, so we need to split it up again
     QStringList commands = rawCommand.split(QRegExp("; ?"));
-    foreach (QString command, commands) {
+    for (const QString& command : commands) {
         handleUserInput(bufferInfo, command);
     }
 }
index c2d249c..ac798a7 100644 (file)
@@ -18,8 +18,7 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
-#ifndef COREUSERINPUTHANDLER_H
-#define COREUSERINPUTHANDLER_H
+#pragma once
 
 #include <utility>
 
@@ -135,5 +134,3 @@ private:
 
     QHash<int, Command> _delayedCommands;
 };
-
-#endif
index f5b3784..a030a6a 100644 (file)
@@ -26,6 +26,7 @@
 #include "eventmanager.h"
 #include "ircdecoder.h"
 #include "ircevent.h"
+#include "irctags.h"
 #include "messageevent.h"
 #include "networkevent.h"
 
index 1485337..a119ae3 100644 (file)
@@ -33,7 +33,7 @@ class IrcParser : public QObject
     Q_OBJECT
 
 public:
-    IrcParser(CoreSession* session);
+    explicit IrcParser(CoreSession* session);
 
     inline CoreSession* coreSession() const { return _coreSession; }
     inline EventManager* eventManager() const { return coreSession()->eventManager(); }
diff --git a/src/core/irctags.h b/src/core/irctags.h
new file mode 100644 (file)
index 0000000..36b642a
--- /dev/null
@@ -0,0 +1,37 @@
+/***************************************************************************
+ *   Copyright (C) 2005-2019 by the Quassel Project                        *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+ ***************************************************************************/
+
+#pragma once
+
+#include "irctag.h"
+
+/**
+ * This namespace contains commonly used message tags, similar to the IrcCaps
+ * namespace used for IRCv3 capabilities.
+ */
+namespace IrcTags
+{
+    /**
+     * Server time for messages.
+     *
+     * https://ircv3.net/specs/extensions/server-time-3.2.html
+     */
+    const IrcTagKey SERVER_TIME = IrcTagKey{"", "time", false};
+}