/***************************************************************************
- * Copyright (C) 2005-2014 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 *
#include "coresession.h"
+#include <functional>
+
class CoreIdentity;
class CoreUserInputHandler;
class CoreIgnoreListManager;
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(); }
inline quint16 localPort() const { return socket.localPort(); }
inline quint16 peerPort() const { return socket.peerPort(); }
+ /**
+ * Gets whether or not a disconnect was expected.
+ *
+ * Distinguishes desired quits from unexpected disconnections such as socket errors or timeouts.
+ *
+ * @return True if disconnect was requested, otherwise false.
+ */
+ inline bool disconnectExpected() const { return _disconnectExpected; }
+
+ QList<QList<QByteArray>> splitMessage(const QString &cmd, const QString &message, std::function<QList<QByteArray>(QString &)> cmdGenerator);
+
public slots:
virtual void setMyNick(const QString &mynick);
void setPingInterval(int interval);
void connectToIrc(bool reconnecting = false);
- void disconnectFromIrc(bool requested = true, const QString &reason = QString(), bool withReconnect = false);
+ /**
+ * Disconnect from the IRC server.
+ *
+ * Begin disconnecting from the IRC server, including optionally reconnecting.
+ *
+ * @param requested If true, user requested this disconnect; don't try to reconnect
+ * @param reason Reason for quitting, defaulting to the user-configured quit reason
+ * @param withReconnect Reconnect to the network after disconnecting (e.g. ping timeout)
+ * @param forceImmediate Immediately disconnect from network, skipping queue of other commands
+ */
+ void disconnectFromIrc(bool requested = true, const QString &reason = QString(),
+ bool withReconnect = false, bool forceImmediate = false);
+
+ /**
+ * Forcibly close the IRC server socket, waiting for it to close.
+ *
+ * Call CoreNetwork::disconnectFromIrc() first, allow the event loop to run, then if you need to
+ * be sure the network's disconencted (e.g. clean-up), call this.
+ *
+ * @param msecs Maximum time to wait for socket to close, in milliseconds.
+ * @return True if socket closes successfully; false if error occurs or timeout reached
+ */
+ bool forceDisconnect(int msecs = 1000);
void userInput(BufferInfo bufferInfo, QString msg);
- void putRawLine(QByteArray input);
- void putCmd(const QString &cmd, const QList<QByteArray> ¶ms, 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> ¶ms, 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>> ¶ms, const QByteArray &prefix = QByteArray(), const bool prependAll = false);
void setChannelJoined(const QString &channel);
void setChannelParted(const QString &channel);
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();
bool _quitRequested;
QString _quitReason;
+ bool _disconnectExpected; /// If true, connection is quitting, expect a socket close
+ // This avoids logging a spurious RemoteHostClosedError whenever disconnect is called without
+ // specifying a permanent (saved to core session) disconnect.
+
bool _previousConnectionAttemptFailed;
int _lastUsedServerIndex;
QList<QByteArray> _msgQueue;
QString _requestedUserModes; // 2 strings separated by a '-' character. first part are requested modes to add, the second to remove
+
+ // List of blowfish keys for channels
+ QHash<QString, QByteArray> _cipherKeys;
};