/***************************************************************************
- * Copyright (C) 2005-2014 by the Quassel Project *
+ * Copyright (C) 2005-2016 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#include <QSettings>
#include <QTextCodec>
#include "network.h"
-#include "quassel.h"
QTextCodec *Network::_defaultCodecForServer = 0;
QTextCodec *Network::_defaultCodecForEncoding = 0;
QTextCodec *Network::_defaultCodecForDecoding = 0;
-QString Network::_networksIniPath = QString();
// ====================
// Public:
}
+bool Network::isStatusMsg(const QString &target) const
+{
+ if (target.isEmpty())
+ return false;
+
+ if (supports("STATUSMSG"))
+ return support("STATUSMSG").contains(target[0]);
+ else
+ return QString("@+").contains(target[0]);
+}
+
+
NetworkInfo Network::networkInfo() const
{
NetworkInfo info;
if (_defaultCodecForEncoding) {
return _defaultCodecForEncoding->fromUnicode(string);
}
- return string.toAscii();
+ return string.toLatin1();
}
if (_defaultCodecForServer) {
return _defaultCodecForServer->fromUnicode(string);
}
- return string.toAscii();
-}
-
-
-/*** Handle networks.ini ***/
-
-QStringList Network::presetNetworks(bool onlyDefault)
-{
- // lazily find the file, make sure to not call one of the other preset functions first (they'll fail else)
- if (_networksIniPath.isNull()) {
- _networksIniPath = Quassel::findDataFilePath("networks.ini");
- if (_networksIniPath.isNull()) {
- _networksIniPath = ""; // now we won't check again, as it's not null anymore
- return QStringList();
- }
- }
- if (!_networksIniPath.isEmpty()) {
- QSettings s(_networksIniPath, QSettings::IniFormat);
- QStringList networks = s.childGroups();
- if (!networks.isEmpty()) {
- // we sort the list case-insensitive
- QMap<QString, QString> sorted;
- foreach(QString net, networks) {
- if (onlyDefault && !s.value(QString("%1/Default").arg(net)).toBool())
- continue;
- sorted[net.toLower()] = net;
- }
- return sorted.values();
- }
- }
- return QStringList();
-}
-
-
-QStringList Network::presetDefaultChannels(const QString &networkName)
-{
- if (_networksIniPath.isEmpty()) // be sure to have called presetNetworks() first, else this always fails
- return QStringList();
- QSettings s(_networksIniPath, QSettings::IniFormat);
- return s.value(QString("%1/DefaultChannels").arg(networkName)).toStringList();
-}
-
-
-NetworkInfo Network::networkInfoFromPreset(const QString &networkName)
-{
- NetworkInfo info;
- if (!_networksIniPath.isEmpty()) {
- info.networkName = networkName;
- QSettings s(_networksIniPath, QSettings::IniFormat);
- s.beginGroup(info.networkName);
- foreach(QString server, s.value("Servers").toStringList()) {
- bool ssl = false;
- QStringList splitserver = server.split(':', QString::SkipEmptyParts);
- if (splitserver.count() != 2) {
- qWarning() << "Invalid server entry in networks.conf:" << server;
- continue;
- }
- if (splitserver[1].at(0) == '+')
- ssl = true;
- uint port = splitserver[1].toUInt();
- if (!port) {
- qWarning() << "Invalid port entry in networks.conf:" << server;
- continue;
- }
- info.serverList << Network::Server(splitserver[0].trimmed(), port, QString(), ssl);
- }
- }
- return info;
+ return string.toLatin1();
}
return supports;
}
+void Network::addCap(const QString &capability, const QString &value)
+{
+ // IRCv3 specs all use lowercase capability names
+ QString _capLowercase = capability.toLower();
+ if (!_caps.contains(_capLowercase)) {
+ _caps[_capLowercase] = value;
+ SYNC(ARG(capability), ARG(value))
+ emit capAdded(_capLowercase);
+ }
+}
+
+void Network::acknowledgeCap(const QString &capability)
+{
+ // IRCv3 specs all use lowercase capability names
+ QString _capLowercase = capability.toLower();
+ if (!_capsEnabled.contains(_capLowercase)) {
+ _capsEnabled.append(_capLowercase);
+ SYNC(ARG(capability))
+ emit capAcknowledged(_capLowercase);
+ }
+}
+
+void Network::removeCap(const QString &capability)
+{
+ // IRCv3 specs all use lowercase capability names
+ QString _capLowercase = capability.toLower();
+ if (_caps.contains(_capLowercase)) {
+ // Remove from the list of available capabilities.
+ _caps.remove(_capLowercase);
+ // Remove it from the acknowledged list if it was previously acknowledged. The SYNC call
+ // ensures this propogates to the other side.
+ // Use removeOne() for speed; no more than one due to contains() check in acknowledgeCap().
+ _capsEnabled.removeOne(_capLowercase);
+ SYNC(ARG(capability))
+ emit capRemoved(_capLowercase);
+ }
+}
+
+void Network::clearCaps()
+{
+ // IRCv3 specs all use lowercase capability names
+ // To ease core-side configuration, loop through the list and emit capRemoved for each entry.
+ // If performance issues arise, this can be converted to a more-efficient setup without breaking
+ // protocol (in theory).
+ QString _capLowercase;
+ foreach (const QString &capability, _caps) {
+ _capLowercase = capability.toLower();
+ emit capRemoved(_capLowercase);
+ }
+ // Clear capabilities from the stored list
+ _caps.clear();
+ _capsEnabled.clear();
+
+ SYNC(NO_ARG)
+}
+
+QVariantMap Network::initCaps() const
+{
+ QVariantMap caps;
+ QHashIterator<QString, QString> iter(_caps);
+ while (iter.hasNext()) {
+ iter.next();
+ caps[iter.key()] = iter.value();
+ }
+ return caps;
+}
+
// There's potentially a lot of users and channels, so it makes sense to optimize the format of this.
// Rather than sending a thousand maps with identical keys, we convert this into one map containing lists
}
+void Network::initSetCaps(const QVariantMap &caps)
+{
+ QMapIterator<QString, QVariant> iter(caps);
+ while (iter.hasNext()) {
+ iter.next();
+ addCap(iter.key(), iter.value().toString());
+ }
+}
+
+
IrcUser *Network::updateNickFromMask(const QString &mask)
{
QString nick(nickFromMask(mask).toLower());
serverMap["Port"] = server.port;
serverMap["Password"] = server.password;
serverMap["UseSSL"] = server.useSsl;
+ serverMap["sslVerify"] = server.sslVerify;
serverMap["sslVersion"] = server.sslVersion;
serverMap["UseProxy"] = server.useProxy;
serverMap["ProxyType"] = server.proxyType;
server.port = serverMap["Port"].toUInt();
server.password = serverMap["Password"].toString();
server.useSsl = serverMap["UseSSL"].toBool();
+ server.sslVerify = serverMap["sslVerify"].toBool();
server.sslVersion = serverMap["sslVersion"].toInt();
server.useProxy = serverMap["UseProxy"].toBool();
server.proxyType = serverMap["ProxyType"].toInt();
if (port != other.port) return false;
if (password != other.password) return false;
if (useSsl != other.useSsl) return false;
+ if (sslVerify != other.sslVerify) return false;
if (sslVersion != other.sslVersion) return false;
if (useProxy != other.useProxy) return false;
if (proxyType != other.proxyType) return false;
QDebug operator<<(QDebug dbg, const Network::Server &server)
{
- dbg.nospace() << "Server(host = " << server.host << ":" << server.port << ", useSsl = " << server.useSsl << ")";
+ dbg.nospace() << "Server(host = " << server.host << ":" << server.port << ", useSsl = " <<
+ server.useSsl << ", sslVerify = " << server.sslVerify << ")";
return dbg.space();
}