From f81ad4f71a532ca310fae0fbe2f412bde9a37521 Mon Sep 17 00:00:00 2001 From: Daniel Albers Date: Tue, 7 Feb 2012 00:43:48 +0100 Subject: [PATCH] first working version of oidentd support - broken, WIP --- src/common/quassel.cpp | 3 +++ src/common/types.h | 3 +++ src/core/core.cpp | 4 ++-- src/core/corenetwork.cpp | 5 ++++- src/core/corenetwork.h | 1 + src/core/oidentdconfiggenerator.cpp | 30 ++++++++++++++++++++--------- src/core/oidentdconfiggenerator.h | 6 ++++-- 7 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/common/quassel.cpp b/src/common/quassel.cpp index c1e2c176..db56043b 100644 --- a/src/common/quassel.cpp +++ b/src/common/quassel.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include "message.h" #include "identity.h" @@ -176,6 +177,8 @@ void Quassel::registerMetaTypes() { qRegisterMetaType("AccountId"); qRegisterMetaType("MsgId"); + qRegisterMetaType("QHostAddress"); + qRegisterMetaTypeStreamOperators("IdentityId"); qRegisterMetaTypeStreamOperators("BufferId"); qRegisterMetaTypeStreamOperators("NetworkId"); diff --git a/src/common/types.h b/src/common/types.h index 4e98b418..9424ec8a 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -25,6 +25,7 @@ #include #include #include +#include class SignedId { protected: @@ -95,6 +96,8 @@ Q_DECLARE_METATYPE(NetworkId) Q_DECLARE_METATYPE(IdentityId) Q_DECLARE_METATYPE(AccountId) +Q_DECLARE_METATYPE(QHostAddress) + // a few typedefs typedef QList MsgIdList; typedef QList BufferIdList; diff --git a/src/core/core.cpp b/src/core/core.cpp index 2a2e5ebe..3b1a9e53 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -169,8 +169,6 @@ Core::Core() } void Core::init() { - _oidentdConfigGenerator = new OidentdConfigGenerator(); - CoreSettings cs; _configured = initStorage(cs.storageSettings().toMap()); @@ -203,6 +201,8 @@ void Core::init() { connect(&_server, SIGNAL(newConnection()), this, SLOT(incomingConnection())); connect(&_v6server, SIGNAL(newConnection()), this, SLOT(incomingConnection())); if(!startListening()) exit(1); // TODO make this less brutal + + _oidentdConfigGenerator = new OidentdConfigGenerator(this); } Core::~Core() { diff --git a/src/core/corenetwork.cpp b/src/core/corenetwork.cpp index 8ea229f6..9846a268 100644 --- a/src/core/corenetwork.cpp +++ b/src/core/corenetwork.cpp @@ -68,7 +68,6 @@ CoreNetwork::CoreNetwork(const NetworkId &networkid, CoreSession *session) connect(&_autoWhoCycleTimer, SIGNAL(timeout()), this, SLOT(startAutoWhoCycle())); connect(&_tokenBucketTimer, SIGNAL(timeout()), this, SLOT(fillBucketAndProcessQueue())); - connect(&socket, SIGNAL(connected()), Core::instance()->oidentdConfigGenerator(), SLOT(update())); connect(&socket, SIGNAL(connected()), this, SLOT(socketInitialized())); connect(&socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError))); @@ -79,6 +78,7 @@ CoreNetwork::CoreNetwork(const NetworkId &networkid, CoreSession *session) connect(&socket, SIGNAL(sslErrors(const QList &)), this, SLOT(sslErrors(const QList &))); #endif connect(this, SIGNAL(newEvent(Event *)), coreSession()->eventManager(), SLOT(postEvent(Event *))); + connect(this, SIGNAL(newSocket(const CoreIdentity*,QHostAddress,quint16,QHostAddress,quint16)), Core::instance()->oidentdConfigGenerator(), SLOT(addSocket(const CoreIdentity*,QHostAddress,quint16,QHostAddress,quint16))); } CoreNetwork::~CoreNetwork() { @@ -351,6 +351,7 @@ void CoreNetwork::socketError(QAbstractSocket::SocketError error) { } void CoreNetwork::socketInitialized() { +qDebug() << "connected()"; Server server = usedServer(); #ifdef HAVE_SSL if(server.useSsl && !socket.isEncrypted()) @@ -364,6 +365,8 @@ void CoreNetwork::socketInitialized() { return; } + emit newSocket(identity, localAddress(), localPort(), peerAddress(), peerPort()); + // TokenBucket to avoid sending too much at once _messageDelay = 2200; // this seems to be a safe value (2.2 seconds delay) _burstSize = 5; diff --git a/src/core/corenetwork.h b/src/core/corenetwork.h index 2dbd6a9e..0dc6c5f5 100644 --- a/src/core/corenetwork.h +++ b/src/core/corenetwork.h @@ -155,6 +155,7 @@ signals: void sslErrors(const QVariant &errorData); void newEvent(Event *event); + void newSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort); protected: inline virtual IrcChannel *ircChannelFactory(const QString &channelname) { return new CoreIrcChannel(channelname, this); } diff --git a/src/core/oidentdconfiggenerator.cpp b/src/core/oidentdconfiggenerator.cpp index 779a50c9..2e6e0ca2 100644 --- a/src/core/oidentdconfiggenerator.cpp +++ b/src/core/oidentdconfiggenerator.cpp @@ -39,7 +39,7 @@ bool OidentdConfigGenerator::init() { quasselStanza = QRegExp(QString("^lport .* { .* } #%1$").arg(configTag)); - if (update()) + if (parseConfig(true) && writeConfig()) _initialized = true; qDebug() << "konichi wa °-°"; @@ -47,16 +47,21 @@ bool OidentdConfigGenerator::init() { return _initialized; } -bool OidentdConfigGenerator::update() { - if (parseConfig()) - qDebug() << "oidentd config parsed successfully"; - else - qDebug() << QString("parsing oidentd config failed (%1 [%2])").arg(_configFile->errorString()).arg(_configFile->error()); +bool OidentdConfigGenerator::addSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort) { + qDebug() << "localAddress" << localAddress; + qDebug() << "localPort" << localPort; + qDebug() << "peerAddress" << peerAddress; + qDebug() << "peerPort" << peerPort; + qDebug() << "ident" << identity->ident(); + + QString ident = identity->ident(); + + _config.append(QString("lport %1 { reply \"%2\" } #%3\n").arg(localPort).arg(ident).arg(configTag)); return writeConfig(); } -bool OidentdConfigGenerator::parseConfig() { +bool OidentdConfigGenerator::parseConfig(bool stripQuasselStanzas) { qDebug() << "_configFile name" << _configFile->fileName(); qDebug() << "open?" << _configFile->isOpen(); if (!_configFile->isOpen() && !_configFile->open(QIODevice::ReadWrite)) @@ -66,7 +71,7 @@ bool OidentdConfigGenerator::parseConfig() { while (!_configFile->atEnd()) { QByteArray line = _configFile->readLine(); - if (checkLine(line)) + if (!stripQuasselStanzas || checkLine(line)) parsedConfig.append(line); } @@ -76,7 +81,14 @@ bool OidentdConfigGenerator::parseConfig() { } bool OidentdConfigGenerator::writeConfig() { - return true; + if (!_configFile->isOpen() && !_configFile->open(QIODevice::ReadWrite)) + return false; + + //FIXME: thread safety + QTextStream out(_configFile); + out << _config; + + return _configFile->flush(); } bool OidentdConfigGenerator::checkLine(const QByteArray &line) { diff --git a/src/core/oidentdconfiggenerator.h b/src/core/oidentdconfiggenerator.h index db4016c1..f4e819f9 100644 --- a/src/core/oidentdconfiggenerator.h +++ b/src/core/oidentdconfiggenerator.h @@ -25,7 +25,9 @@ #include #include #include +#include +#include "coreidentity.h" #include class OidentdConfigGenerator : public QObject @@ -40,12 +42,12 @@ public: signals: public slots: - bool update(); + bool addSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort); private: bool init(); bool writeConfig(); - bool parseConfig(); + bool parseConfig(bool stripQuasselStanzas = false); bool checkLine(const QByteArray &line); bool _initialized; -- 2.20.1