Add command queue prepend, prioritize PING/PONG
[quassel.git] / src / core / corenetwork.h
index 3b31f0d..e7e7836 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   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  *
@@ -40,6 +40,8 @@
 
 #include "coresession.h"
 
+#include <functional>
+
 class CoreIdentity;
 class CoreUserInputHandler;
 class CoreIgnoreListManager;
@@ -82,6 +84,9 @@ public:
 
     inline QString channelKey(const QString &channel) const { return _channelKeys.value(channel.toLower(), QString()); }
 
+    inline QByteArray readChannelCipherKey(const QString &channel) const { return _cipherKeys.value(channel.toLower()); }
+    inline void storeChannelCipherKey(const QString &channel, const QByteArray &key) { _cipherKeys[channel.toLower()] = key; }
+
     inline bool isAutoWhoInProgress(const QString &channel) const { return _autoWhoPending.value(channel.toLower(), 0); }
 
     inline UserId userId() const { return _coreSession->user(); }
@@ -93,6 +98,8 @@ public:
     inline quint16 localPort() const { return socket.localPort(); }
     inline quint16 peerPort() const { return socket.peerPort(); }
 
+    QList<QList<QByteArray>> splitMessage(const QString &cmd, const QString &message, std::function<QList<QByteArray>(QString &)> cmdGenerator);
+
 public slots:
     virtual void setMyNick(const QString &mynick);
 
@@ -110,8 +117,53 @@ public slots:
     void disconnectFromIrc(bool requested = true, const QString &reason = QString(), bool withReconnect = false);
 
     void userInput(BufferInfo bufferInfo, QString msg);
-    void putRawLine(QByteArray input);
-    void putCmd(const QString &cmd, const QList<QByteArray> &params, const QByteArray &prefix = QByteArray());
+
+    /**
+     * Sends the raw (encoded) line, adding to the queue if needed, optionally with higher priority.
+     *
+     * @param[in] input   QByteArray of encoded characters
+     * @param[in] prepend
+     * @parmblock
+     * If true, the line is prepended into the start of the queue, otherwise, it's appended to the
+     * end.  This should be used sparingly, for if either the core or the IRC server cannot maintain
+     * PING/PONG replies, the other side will close the connection.
+     * @endparmblock
+     */
+    void putRawLine(const QByteArray input, const bool prepend = false);
+
+    /**
+     * Sends the command with encoded parameters, with optional prefix or high priority.
+     *
+     * @param[in] cmd      Command to send, ignoring capitalization
+     * @param[in] params   Parameters for the command, encoded within a QByteArray
+     * @param[in] prefix   Optional command prefix
+     * @param[in] prepend
+     * @parmblock
+     * If true, the command is prepended into the start of the queue, otherwise, it's appended to
+     * the end.  This should be used sparingly, for if either the core or the IRC server cannot
+     * maintain PING/PONG replies, the other side will close the connection.
+     * @endparmblock
+     */
+    void putCmd(const QString &cmd, const QList<QByteArray> &params, const QByteArray &prefix = QByteArray(), const bool prepend = false);
+
+    /**
+     * Sends the command for each set of encoded parameters, with optional prefix or high priority.
+     *
+     * @param[in] cmd         Command to send, ignoring capitalization
+     * @param[in] params
+     * @parmblock
+     * List of parameter lists for the command, encoded within a QByteArray.  The command will be
+     * sent multiple times, once for each set of params stored within the outer list.
+     * @endparmblock
+     * @param[in] prefix      Optional command prefix
+     * @param[in] prependAll
+     * @parmblock
+     * If true, ALL of the commands are prepended into the start of the queue, otherwise, they're
+     * appended to the end.  This should be used sparingly, for if either the core or the IRC server
+     * cannot maintain PING/PONG replies, the other side will close the connection.
+     * @endparmblock
+     */
+    void putCmd(const QString &cmd, const QList<QList<QByteArray>> &params, const QByteArray &prefix = QByteArray(), const bool prependAll = false);
 
     void setChannelJoined(const QString &channel);
     void setChannelParted(const QString &channel);
@@ -123,6 +175,7 @@ public slots:
     Cipher *cipher(const QString &recipient);
     QByteArray cipherKey(const QString &recipient) const;
     void setCipherKey(const QString &recipient, const QByteArray &key);
+    bool cipherUsesCBC(const QString &target);
 #endif
 
     void setAutoWhoEnabled(bool enabled);
@@ -173,7 +226,7 @@ private slots:
     void socketHasData();
     void socketError(QAbstractSocket::SocketError);
     void socketInitialized();
-    inline void socketCloseTimeout() { socket.disconnectFromHost(); }
+    inline void socketCloseTimeout() { socket.abort(); }
     void socketDisconnected();
     void socketStateChanged(QAbstractSocket::SocketState);
     void networkInitialized();
@@ -225,6 +278,7 @@ private:
     QTimer _pingTimer;
     uint _lastPingTime;
     uint _pingCount;
+    bool _sendPings;
 
     QStringList _autoWhoQueue;
     QHash<QString, int> _autoWhoPending;
@@ -238,7 +292,7 @@ private:
 
     QString _requestedUserModes; // 2 strings separated by a '-' character. first part are requested modes to add, the second to remove
 
-    // Blowfish key map
+    // List of blowfish keys for channels
     QHash<QString, QByteArray> _cipherKeys;
 };