first working version of oidentd support - broken, WIP
authorDaniel Albers <daniel@lbe.rs>
Mon, 6 Feb 2012 23:43:48 +0000 (00:43 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 13 Feb 2012 19:35:38 +0000 (20:35 +0100)
src/common/quassel.cpp
src/common/types.h
src/core/core.cpp
src/core/corenetwork.cpp
src/core/corenetwork.h
src/core/oidentdconfiggenerator.cpp
src/core/oidentdconfiggenerator.h

index c1e2c17..db56043 100644 (file)
@@ -32,6 +32,7 @@
 #include <QLibraryInfo>
 #include <QSettings>
 #include <QTranslator>
+#include <QHostAddress>
 
 #include "message.h"
 #include "identity.h"
@@ -176,6 +177,8 @@ void Quassel::registerMetaTypes() {
   qRegisterMetaType<AccountId>("AccountId");
   qRegisterMetaType<MsgId>("MsgId");
 
+  qRegisterMetaType<QHostAddress>("QHostAddress");
+
   qRegisterMetaTypeStreamOperators<IdentityId>("IdentityId");
   qRegisterMetaTypeStreamOperators<BufferId>("BufferId");
   qRegisterMetaTypeStreamOperators<NetworkId>("NetworkId");
index 4e98b41..9424ec8 100644 (file)
@@ -25,6 +25,7 @@
 #include <QString>
 #include <QVariant>
 #include <QTextStream>
+#include <QHostAddress>
 
 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<MsgId> MsgIdList;
 typedef QList<BufferId> BufferIdList;
index 2a2e5eb..3b1a9e5 100644 (file)
@@ -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() {
index 8ea229f..9846a26 100644 (file)
@@ -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<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &)));
 #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;
index 2dbd6a9..0dc6c5f 100644 (file)
@@ -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); }
index 779a50c..2e6e0ca 100644 (file)
@@ -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) {
index db4016c..f4e819f 100644 (file)
@@ -25,7 +25,9 @@
 #include <QDir>
 #include <QFile>
 #include <QDateTime>
+#include <QHostAddress>
 
+#include "coreidentity.h"
 #include <QDebug>
 
 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;