-class Network : public SyncableObject {
- SYNCABLE_OBJECT
- Q_OBJECT
- Q_ENUMS(ConnectionState Network::ConnectionState)
-
- Q_PROPERTY(QString networkName READ networkName WRITE setNetworkName STORED false)
- Q_PROPERTY(QString currentServer READ currentServer WRITE setCurrentServer STORED false)
- Q_PROPERTY(QString myNick READ myNick WRITE setMyNick STORED false)
- Q_PROPERTY(int latency READ latency WRITE setLatency STORED false)
- Q_PROPERTY(QByteArray codecForServer READ codecForServer WRITE setCodecForServer STORED false)
- Q_PROPERTY(QByteArray codecForEncoding READ codecForEncoding WRITE setCodecForEncoding STORED false)
- Q_PROPERTY(QByteArray codecForDecoding READ codecForDecoding WRITE setCodecForDecoding STORED false)
- Q_PROPERTY(IdentityId identityId READ identity WRITE setIdentity STORED false)
- Q_PROPERTY(bool isConnected READ isConnected WRITE setConnected STORED false)
- //Q_PROPERTY(Network::ConnectionState connectionState READ connectionState WRITE setConnectionState STORED false)
- Q_PROPERTY(int connectionState READ connectionState WRITE setConnectionState STORED false)
- Q_PROPERTY(bool useRandomServer READ useRandomServer WRITE setUseRandomServer STORED false)
- Q_PROPERTY(QStringList perform READ perform WRITE setPerform STORED false)
- Q_PROPERTY(bool useAutoIdentify READ useAutoIdentify WRITE setUseAutoIdentify STORED false)
- Q_PROPERTY(QString autoIdentifyService READ autoIdentifyService WRITE setAutoIdentifyService STORED false)
- Q_PROPERTY(QString autoIdentifyPassword READ autoIdentifyPassword WRITE setAutoIdentifyPassword STORED false)
- Q_PROPERTY(bool useSasl READ useSasl WRITE setUseSasl STORED false)
- Q_PROPERTY(QString saslAccount READ saslAccount WRITE setSaslAccount STORED false)
- Q_PROPERTY(QString saslPassword READ saslPassword WRITE setSaslPassword STORED false)
- Q_PROPERTY(bool useAutoReconnect READ useAutoReconnect WRITE setUseAutoReconnect STORED false)
- Q_PROPERTY(quint32 autoReconnectInterval READ autoReconnectInterval WRITE setAutoReconnectInterval STORED false)
- Q_PROPERTY(quint16 autoReconnectRetries READ autoReconnectRetries WRITE setAutoReconnectRetries STORED false)
- Q_PROPERTY(bool unlimitedReconnectRetries READ unlimitedReconnectRetries WRITE setUnlimitedReconnectRetries STORED false)
- Q_PROPERTY(bool rejoinChannels READ rejoinChannels WRITE setRejoinChannels STORED false)
-
-public:
- enum ConnectionState {
- Disconnected,
- Connecting,
- Initializing,
- Initialized,
- Reconnecting,
- Disconnecting
- };
-
- // see:
- // http://www.irc.org/tech_docs/005.html
- // http://www.irc.org/tech_docs/draft-brocklesby-irc-isupport-03.txt
- enum ChannelModeType {
- NOT_A_CHANMODE = 0x00,
- A_CHANMODE = 0x01,
- B_CHANMODE = 0x02,
- C_CHANMODE = 0x04,
- D_CHANMODE = 0x08
- };
-
- struct Server {
- QString host;
- uint port;
- QString password;
- bool useSsl;
- int sslVersion;
-
- bool useProxy;
- int proxyType;
- QString proxyHost;
- uint proxyPort;
- QString proxyUser;
- QString proxyPass;
-
- Server() : port(6667), useSsl(false), sslVersion(0), useProxy(false), proxyType(QNetworkProxy::Socks5Proxy), proxyHost("localhost"), proxyPort(8080) {}
- Server(const QString &host, uint port, const QString &password, bool useSsl)
- : host(host), port(port), password(password), useSsl(useSsl), sslVersion(0),
- useProxy(false), proxyType(QNetworkProxy::Socks5Proxy), proxyHost("localhost"), proxyPort(8080) {}
- bool operator==(const Server &other) const;
- bool operator!=(const Server &other) const;
- };
- typedef QList<Server> ServerList;
-
- Network(const NetworkId &networkid, QObject *parent = 0);
- ~Network();
-
- inline NetworkId networkId() const { return _networkId; }
-
- inline SignalProxy *proxy() const { return _proxy; }
- inline void setProxy(SignalProxy *proxy) { _proxy = proxy; }
-
- inline bool isMyNick(const QString &nick) const { return (myNick().toLower() == nick.toLower()); }
- inline bool isMe(IrcUser *ircuser) const { return (ircuser->nick().toLower() == myNick().toLower()); }
-
- bool isChannelName(const QString &channelname) const;
-
- inline bool isConnected() const { return _connected; }
- //Network::ConnectionState connectionState() const;
- inline int connectionState() const { return _connectionState; }
-
- QString prefixToMode(const QString &prefix);
- inline QString prefixToMode(const QCharRef &prefix) { return prefixToMode(QString(prefix)); }
- QString modeToPrefix(const QString &mode);
- inline QString modeToPrefix(const QCharRef &mode) { return modeToPrefix(QString(mode)); }
-
- ChannelModeType channelModeType(const QString &mode);
- inline ChannelModeType channelModeType(const QCharRef &mode) { return channelModeType(QString(mode)); }
-
- inline const QString &networkName() const { return _networkName; }
- inline const QString ¤tServer() const { return _currentServer; }
- inline const QString &myNick() const { return _myNick; }
- inline int latency() const { return _latency; }
- inline IrcUser *me() const { return ircUser(myNick()); }
- inline IdentityId identity() const { return _identity; }
- QStringList nicks() const;
- inline QStringList channels() const { return _ircChannels.keys(); }
- inline const ServerList &serverList() const { return _serverList; }
- inline bool useRandomServer() const { return _useRandomServer; }
- inline const QStringList &perform() const { return _perform; }
- inline bool useAutoIdentify() const { return _useAutoIdentify; }
- inline const QString &autoIdentifyService() const { return _autoIdentifyService; }
- inline const QString &autoIdentifyPassword() const { return _autoIdentifyPassword; }
- inline bool useSasl() const { return _useSasl; }
- inline const QString &saslAccount() const { return _saslAccount; }
- inline const QString &saslPassword() const { return _saslPassword; }
- inline bool useAutoReconnect() const { return _useAutoReconnect; }
- inline quint32 autoReconnectInterval() const { return _autoReconnectInterval; }
- inline quint16 autoReconnectRetries() const { return _autoReconnectRetries; }
- inline bool unlimitedReconnectRetries() const { return _unlimitedReconnectRetries; }
- inline bool rejoinChannels() const { return _rejoinChannels; }
-
- NetworkInfo networkInfo() const;
- void setNetworkInfo(const NetworkInfo &);
-
- QString prefixes();
- QString prefixModes();
-
- bool supports(const QString ¶m) const { return _supports.contains(param); }
- QString support(const QString ¶m) const;
-
- IrcUser *newIrcUser(const QString &hostmask, const QVariantMap &initData = QVariantMap());
- inline IrcUser *newIrcUser(const QByteArray &hostmask) { return newIrcUser(decodeServerString(hostmask)); }
- IrcUser *ircUser(QString nickname) const;
- inline IrcUser *ircUser(const QByteArray &nickname) const { return ircUser(decodeServerString(nickname)); }
- inline QList<IrcUser *> ircUsers() const { return _ircUsers.values(); }
- inline quint32 ircUserCount() const { return _ircUsers.count(); }
-
- IrcChannel *newIrcChannel(const QString &channelname, const QVariantMap &initData = QVariantMap());
- inline IrcChannel *newIrcChannel(const QByteArray &channelname) { return newIrcChannel(decodeServerString(channelname)); }
- IrcChannel *ircChannel(QString channelname) const;
- inline IrcChannel *ircChannel(const QByteArray &channelname) const { return ircChannel(decodeServerString(channelname)); }
- inline QList<IrcChannel *> ircChannels() const { return _ircChannels.values(); }
- inline quint32 ircChannelCount() const { return _ircChannels.count(); }
-
- QByteArray codecForServer() const;
- QByteArray codecForEncoding() const;
- QByteArray codecForDecoding() const;
- void setCodecForServer(QTextCodec *codec);
- void setCodecForEncoding(QTextCodec *codec);
- void setCodecForDecoding(QTextCodec *codec);
-
- QString decodeString(const QByteArray &text) const;
- QByteArray encodeString(const QString &string) const;
- QString decodeServerString(const QByteArray &text) const;
- QByteArray encodeServerString(const QString &string) const;
-
- static QByteArray defaultCodecForServer();
- static QByteArray defaultCodecForEncoding();
- static QByteArray defaultCodecForDecoding();
- static void setDefaultCodecForServer(const QByteArray &name);
- static void setDefaultCodecForEncoding(const QByteArray &name);
- static void setDefaultCodecForDecoding(const QByteArray &name);
-
- inline bool autoAwayActive() const { return _autoAwayActive; }
- inline void setAutoAwayActive(bool active) { _autoAwayActive = active; }
-
- static QStringList presetNetworks(bool onlyDefault = false);
- static QStringList presetDefaultChannels(const QString &networkName);
- static NetworkInfo networkInfoFromPreset(const QString &networkName);
-
- // Blowfish stuff
- QByteArray bufferKey(const QString &recipient) const;
- void setBufferKey(const QString &recipient, const QByteArray &key);
+class Network : public SyncableObject
+{
+ SYNCABLE_OBJECT
+ Q_OBJECT
+ Q_ENUMS(ConnectionState)
+
+ Q_PROPERTY(QString networkName READ networkName WRITE setNetworkName)
+ Q_PROPERTY(QString currentServer READ currentServer WRITE setCurrentServer)
+ Q_PROPERTY(QString myNick READ myNick WRITE setMyNick)
+ Q_PROPERTY(int latency READ latency WRITE setLatency)
+ Q_PROPERTY(QByteArray codecForServer READ codecForServer WRITE setCodecForServer)
+ Q_PROPERTY(QByteArray codecForEncoding READ codecForEncoding WRITE setCodecForEncoding)
+ Q_PROPERTY(QByteArray codecForDecoding READ codecForDecoding WRITE setCodecForDecoding)
+ Q_PROPERTY(IdentityId identityId READ identity WRITE setIdentity)
+ Q_PROPERTY(bool isConnected READ isConnected WRITE setConnected)
+ //Q_PROPERTY(Network::ConnectionState connectionState READ connectionState WRITE setConnectionState)
+ Q_PROPERTY(int connectionState READ connectionState WRITE setConnectionState)
+ Q_PROPERTY(bool useRandomServer READ useRandomServer WRITE setUseRandomServer)
+ Q_PROPERTY(QStringList perform READ perform WRITE setPerform)
+ Q_PROPERTY(bool useAutoIdentify READ useAutoIdentify WRITE setUseAutoIdentify)
+ Q_PROPERTY(QString autoIdentifyService READ autoIdentifyService WRITE setAutoIdentifyService)
+ Q_PROPERTY(QString autoIdentifyPassword READ autoIdentifyPassword WRITE setAutoIdentifyPassword)
+ Q_PROPERTY(bool useSasl READ useSasl WRITE setUseSasl)
+ Q_PROPERTY(QString saslAccount READ saslAccount WRITE setSaslAccount)
+ Q_PROPERTY(QString saslPassword READ saslPassword WRITE setSaslPassword)
+ Q_PROPERTY(bool useAutoReconnect READ useAutoReconnect WRITE setUseAutoReconnect)
+ Q_PROPERTY(quint32 autoReconnectInterval READ autoReconnectInterval WRITE setAutoReconnectInterval)
+ Q_PROPERTY(quint16 autoReconnectRetries READ autoReconnectRetries WRITE setAutoReconnectRetries)
+ Q_PROPERTY(bool unlimitedReconnectRetries READ unlimitedReconnectRetries WRITE setUnlimitedReconnectRetries)
+ Q_PROPERTY(bool rejoinChannels READ rejoinChannels WRITE setRejoinChannels)
+ // Custom rate limiting
+ Q_PROPERTY(bool useCustomMessageRate READ useCustomMessageRate WRITE setUseCustomMessageRate)
+ Q_PROPERTY(quint32 msgRateBurstSize READ messageRateBurstSize WRITE setMessageRateBurstSize)
+ Q_PROPERTY(quint32 msgRateMessageDelay READ messageRateDelay WRITE setMessageRateDelay)
+ Q_PROPERTY(bool unlimitedMessageRate READ unlimitedMessageRate WRITE setUnlimitedMessageRate)
+
+public :
+ enum ConnectionState {
+ Disconnected,
+ Connecting,
+ Initializing,
+ Initialized,
+ Reconnecting,
+ Disconnecting
+ };
+
+ // see:
+ // http://www.irc.org/tech_docs/005.html
+ // http://www.irc.org/tech_docs/draft-brocklesby-irc-isupport-03.txt
+ enum ChannelModeType {
+ NOT_A_CHANMODE = 0x00,
+ A_CHANMODE = 0x01,
+ B_CHANMODE = 0x02,
+ C_CHANMODE = 0x04,
+ D_CHANMODE = 0x08
+ };
+
+ // Default port assignments according to what many IRC networks have settled on.
+ // Technically not a standard, but it's fairly widespread.
+ // See https://freenode.net/news/port-6697-irc-via-tlsssl
+ enum PortDefaults {
+ PORT_PLAINTEXT = 6667, /// Default port for unencrypted connections
+ PORT_SSL = 6697 /// Default port for encrypted connections
+ };
+
+ struct Server {
+ QString host;
+ uint port;
+ QString password;
+ bool useSsl;
+ bool sslVerify; /// If true, validate SSL certificates
+ int sslVersion;
+
+ bool useProxy;
+ int proxyType;
+ QString proxyHost;
+ uint proxyPort;
+ QString proxyUser;
+ QString proxyPass;
+
+ // sslVerify only applies when useSsl is true. sslVerify should be enabled by default,
+ // so enabling useSsl offers a more secure default.
+ Server() : port(6667), useSsl(false), sslVerify(true), sslVersion(0), useProxy(false),
+ proxyType(QNetworkProxy::Socks5Proxy), proxyHost("localhost"), proxyPort(8080) {}
+
+ Server(const QString &host, uint port, const QString &password, bool useSsl,
+ bool sslVerify)
+ : host(host), port(port), password(password), useSsl(useSsl), sslVerify(sslVerify),
+ sslVersion(0), useProxy(false), proxyType(QNetworkProxy::Socks5Proxy),
+ proxyHost("localhost"), proxyPort(8080) {}
+
+ bool operator==(const Server &other) const;
+ bool operator!=(const Server &other) const;
+ };
+ typedef QList<Server> ServerList;
+
+ Network(const NetworkId &networkid, QObject *parent = 0);
+ ~Network();
+
+ inline NetworkId networkId() const { return _networkId; }
+
+ inline SignalProxy *proxy() const { return _proxy; }
+ inline void setProxy(SignalProxy *proxy) { _proxy = proxy; }
+
+ inline bool isMyNick(const QString &nick) const { return (myNick().toLower() == nick.toLower()); }
+ inline bool isMe(IrcUser *ircuser) const { return (ircuser->nick().toLower() == myNick().toLower()); }
+
+ bool isChannelName(const QString &channelname) const;
+
+ /**
+ * Checks if the target counts as a STATUSMSG
+ *
+ * Status messages are prefixed with one or more characters from the server-provided STATUSMSG
+ * if available, otherwise "@" and "+" are assumed. Generally, status messages sent to a
+ * channel are only visible to those with the same or higher permissions, e.g. voiced.
+ *
+ * @param[in] target Name of destination, e.g. a channel or query
+ * @returns True if a STATUSMSG, otherwise false
+ */
+ bool isStatusMsg(const QString &target) const;
+
+ inline bool isConnected() const { return _connected; }
+ //Network::ConnectionState connectionState() const;
+ inline int connectionState() const { return _connectionState; }
+
+ QString prefixToMode(const QString &prefix) const;
+ inline QString prefixToMode(const QCharRef &prefix) const { return prefixToMode(QString(prefix)); }
+ QString modeToPrefix(const QString &mode) const;
+ inline QString modeToPrefix(const QCharRef &mode) const { return modeToPrefix(QString(mode)); }
+
+ ChannelModeType channelModeType(const QString &mode);
+ inline ChannelModeType channelModeType(const QCharRef &mode) { return channelModeType(QString(mode)); }
+
+ inline const QString &networkName() const { return _networkName; }
+ inline const QString ¤tServer() const { return _currentServer; }
+ inline const QString &myNick() const { return _myNick; }
+ inline int latency() const { return _latency; }
+ inline IrcUser *me() const { return ircUser(myNick()); }
+ inline IdentityId identity() const { return _identity; }
+ QStringList nicks() const;
+ inline QStringList channels() const { return _ircChannels.keys(); }
+ /**
+ * Gets the list of available capabilities.
+ *
+ * @returns QStringList of available capabilities
+ */
+ inline const QStringList caps() const { return QStringList(_caps.keys()); }
+ /**
+ * Gets the list of enabled (acknowledged) capabilities.
+ *
+ * @returns QStringList of enabled (acknowledged) capabilities
+ */
+ inline const QStringList capsEnabled() const { return _capsEnabled; }
+ inline const ServerList &serverList() const { return _serverList; }
+ inline bool useRandomServer() const { return _useRandomServer; }
+ inline const QStringList &perform() const { return _perform; }
+ inline bool useAutoIdentify() const { return _useAutoIdentify; }
+ inline const QString &autoIdentifyService() const { return _autoIdentifyService; }
+ inline const QString &autoIdentifyPassword() const { return _autoIdentifyPassword; }
+ inline bool useSasl() const { return _useSasl; }
+ inline const QString &saslAccount() const { return _saslAccount; }
+ inline const QString &saslPassword() const { return _saslPassword; }
+ inline bool useAutoReconnect() const { return _useAutoReconnect; }
+ inline quint32 autoReconnectInterval() const { return _autoReconnectInterval; }
+ inline quint16 autoReconnectRetries() const { return _autoReconnectRetries; }
+ inline bool unlimitedReconnectRetries() const { return _unlimitedReconnectRetries; }
+ inline bool rejoinChannels() const { return _rejoinChannels; }
+
+ // Custom rate limiting
+
+ /**
+ * Gets whether or not custom rate limiting is used
+ *
+ * @return True if custom rate limiting is enabled, otherwise false.
+ */
+ inline bool useCustomMessageRate() const { return _useCustomMessageRate; }
+
+ /**
+ * Gets maximum number of messages to send without any delays
+ *
+ * @return
+ * @parblock
+ * Maximum number of messages to send without any delays. A value of 1 disables message
+ * bursting.
+ * @endparblock
+ */
+ inline quint32 messageRateBurstSize() const { return _messageRateBurstSize; }
+
+ /**
+ * Gets the delay between messages after the maximum number of undelayed messages have been sent
+ *
+ * @return
+ * @parblock
+ * Delay in milliseconds between messages after the maximum number of undelayed messages have
+ * been sent.
+ * @endparblock
+ */
+ inline quint32 messageRateDelay() const { return _messageRateDelay; }
+
+ /**
+ * Gets whether or not all rate limiting is disabled, e.g. for IRC bridges
+ *
+ * @return If true, disable rate limiting, otherwise apply configured limits.
+ */
+ inline bool unlimitedMessageRate() const { return _unlimitedMessageRate; }
+
+ NetworkInfo networkInfo() const;
+ void setNetworkInfo(const NetworkInfo &);
+
+ QString prefixes() const;
+ QString prefixModes() const;
+ void determinePrefixes() const;
+
+ bool supports(const QString ¶m) const { return _supports.contains(param); }
+ QString support(const QString ¶m) const;
+
+ /**
+ * Checks if a given capability is acknowledged and active.
+ *
+ * @param[in] capability Name of capability
+ * @returns True if acknowledged (active), otherwise false
+ */
+ inline bool capEnabled(const QString &capability) const { return _capsEnabled.contains(capability.toLower()); }
+ // IRCv3 specs all use lowercase capability names
+
+ /**
+ * Gets the value of an available capability, e.g. for SASL, "EXTERNAL,PLAIN".
+ *
+ * @param[in] capability Name of capability
+ * @returns Value of capability if one was specified, otherwise empty string
+ */
+ QString capValue(const QString &capability) const { return _caps.value(capability.toLower()); }
+ // IRCv3 specs all use lowercase capability names
+ // QHash returns the default constructed value if not found, in this case, empty string
+ // See: https://doc.qt.io/qt-4.8/qhash.html#value
+
+ /**
+ * Check if the given authentication mechanism is likely to be supported.
+ *
+ * This depends on the server advertising SASL support and either declaring available mechanisms
+ * (SASL 3.2), or just indicating something is supported (SASL 3.1).
+ *
+ * @param[in] saslMechanism Desired SASL mechanism
+ * @return True if mechanism supported or unknown, otherwise false
+ */
+ bool saslMaybeSupports(const QString &saslMechanism) const;
+
+ IrcUser *newIrcUser(const QString &hostmask, const QVariantMap &initData = QVariantMap());
+ inline IrcUser *newIrcUser(const QByteArray &hostmask) { return newIrcUser(decodeServerString(hostmask)); }
+ IrcUser *ircUser(QString nickname) const;
+ inline IrcUser *ircUser(const QByteArray &nickname) const { return ircUser(decodeServerString(nickname)); }
+ inline QList<IrcUser *> ircUsers() const { return _ircUsers.values(); }
+ inline quint32 ircUserCount() const { return _ircUsers.count(); }
+
+ IrcChannel *newIrcChannel(const QString &channelname, const QVariantMap &initData = QVariantMap());
+ inline IrcChannel *newIrcChannel(const QByteArray &channelname) { return newIrcChannel(decodeServerString(channelname)); }
+ IrcChannel *ircChannel(QString channelname) const;
+ inline IrcChannel *ircChannel(const QByteArray &channelname) const { return ircChannel(decodeServerString(channelname)); }
+ inline QList<IrcChannel *> ircChannels() const { return _ircChannels.values(); }
+ inline quint32 ircChannelCount() const { return _ircChannels.count(); }
+
+ QByteArray codecForServer() const;
+ QByteArray codecForEncoding() const;
+ QByteArray codecForDecoding() const;
+ void setCodecForServer(QTextCodec *codec);
+ void setCodecForEncoding(QTextCodec *codec);
+ void setCodecForDecoding(QTextCodec *codec);
+
+ QString decodeString(const QByteArray &text) const;
+ QByteArray encodeString(const QString &string) const;
+ QString decodeServerString(const QByteArray &text) const;
+ QByteArray encodeServerString(const QString &string) const;
+
+ static QByteArray defaultCodecForServer();
+ static QByteArray defaultCodecForEncoding();
+ static QByteArray defaultCodecForDecoding();
+ static void setDefaultCodecForServer(const QByteArray &name);
+ static void setDefaultCodecForEncoding(const QByteArray &name);
+ static void setDefaultCodecForDecoding(const QByteArray &name);
+
+ inline bool autoAwayActive() const { return _autoAwayActive; }
+ inline void setAutoAwayActive(bool active) { _autoAwayActive = active; }