/***************************************************************************
- * Copyright (C) 2012 by the Quassel Project *
+ * Copyright (C) 2005-2019 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* 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., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
+#ifdef HAVE_UMASK
+# include <sys/stat.h>
+# include <sys/types.h>
+#endif /* HAVE_UMASK */
+
+#include <QString>
+
+#include "corenetwork.h"
#include "oidentdconfiggenerator.h"
-OidentdConfigGenerator::OidentdConfigGenerator(QObject *parent) :
- QObject(parent),
- _initialized(false)
+OidentdConfigGenerator::OidentdConfigGenerator(QObject* parent)
+ : QObject(parent)
{
if (!_initialized)
init();
}
-
OidentdConfigGenerator::~OidentdConfigGenerator()
{
_quasselConfig.clear();
_configFile->deleteLater();
}
-
bool OidentdConfigGenerator::init()
{
_configDir = QDir::homePath();
// the ability to bind to an IP on client sockets.
_quasselStanzaTemplate = QString("lport %1 { reply \"%2\" } #%3\n");
- _quasselStanzaRx = QRegExp(QString("^lport .* \\{ .* \\} #%1\\r?\\n").arg(_configTag));
+ _quasselStanzaRx = QRegExp(QString(R"(^lport .* \{ .* \} #%1\r?\n)").arg(_configTag));
// initially remove all Quassel stanzas that might be present
if (parseConfig(false) && writeConfig())
return _initialized;
}
+QString OidentdConfigGenerator::sysIdentForIdentity(const CoreIdentity* identity) const
+{
+ // Make sure the identity's ident complies with strict mode if enabled
+ const CoreNetwork* network = qobject_cast<CoreNetwork*>(sender());
+ return network->coreSession()->strictCompliantIdent(identity);
+}
-bool OidentdConfigGenerator::addSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort)
+bool OidentdConfigGenerator::addSocket(const CoreIdentity* identity,
+ const QHostAddress& localAddress,
+ quint16 localPort,
+ const QHostAddress& peerAddress,
+ quint16 peerPort,
+ qint64 socketId)
{
- Q_UNUSED(localAddress) Q_UNUSED(peerAddress) Q_UNUSED(peerPort)
- QString ident = identity->ident();
+ Q_UNUSED(localAddress)
+ Q_UNUSED(peerAddress)
+ Q_UNUSED(peerPort)
+ Q_UNUSED(socketId)
- _quasselConfig.append(_quasselStanzaTemplate.arg(localPort).arg(ident).arg(_configTag).toAscii());
+ const QString ident = sysIdentForIdentity(identity);
+
+ _quasselConfig.append(_quasselStanzaTemplate.arg(localPort).arg(ident).arg(_configTag).toLatin1());
bool ret = writeConfig();
return ret;
}
-
//! not yet implemented
-bool OidentdConfigGenerator::removeSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort)
+bool OidentdConfigGenerator::removeSocket(const CoreIdentity* identity,
+ const QHostAddress& localAddress,
+ quint16 localPort,
+ const QHostAddress& peerAddress,
+ quint16 peerPort,
+ qint64 socketId)
{
- Q_UNUSED(identity) Q_UNUSED(localAddress) Q_UNUSED(localPort) Q_UNUSED(peerAddress) Q_UNUSED(peerPort)
+ Q_UNUSED(identity)
+ Q_UNUSED(localAddress)
+ Q_UNUSED(localPort)
+ Q_UNUSED(peerAddress)
+ Q_UNUSED(peerPort)
+ Q_UNUSED(socketId)
+
return true;
}
-
bool OidentdConfigGenerator::parseConfig(bool readQuasselStanzas)
{
if (!_configFile->exists())
return true;
}
-
bool OidentdConfigGenerator::writeConfig()
{
#ifdef HAVE_UMASK
- mode_t prev_umask = umask(S_IXUSR | S_IWGRP | S_IXGRP | S_IWOTH | S_IXOTH); // == 0133, rw-r--r--
+ mode_t prev_umask = umask(S_IXUSR | S_IWGRP | S_IXGRP | S_IWOTH | S_IXOTH); // == 0133, rw-r--r--
#endif
bool not_open = (!_configFile->isOpen() && !_configFile->open(QIODevice::ReadWrite | QIODevice::Text));
#ifdef HAVE_UMASK
return true;
}
-
-bool OidentdConfigGenerator::lineByUs(const QByteArray &line)
+bool OidentdConfigGenerator::lineByUs(const QByteArray& line)
{
return _quasselStanzaRx.exactMatch(line);
}