oidentd support - WIP
authorDaniel Albers <daniel@lbe.rs>
Mon, 6 Feb 2012 01:28:56 +0000 (02:28 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 13 Feb 2012 19:35:38 +0000 (20:35 +0100)
src/core/CMakeLists.txt
src/core/core.cpp
src/core/core.h
src/core/coreapplication.cpp
src/core/corenetwork.cpp
src/core/corenetwork.h
src/core/oidentdconfiggenerator.cpp [new file with mode: 0644]
src/core/oidentdconfiggenerator.h [new file with mode: 0644]

index a7eaf0b..a6d3f20 100644 (file)
@@ -24,6 +24,7 @@ set(SOURCES
     coreircuser.cpp
     corenetwork.cpp
     corenetworkconfig.cpp
+    oidentdconfiggenerator.cpp
     coresession.cpp
     coresessioneventprocessor.cpp
     coresettings.cpp
@@ -56,6 +57,7 @@ set(MOC_HDRS
     coreircuser.h
     corenetwork.h
     corenetworkconfig.h
+    oidentdconfiggenerator.h
     coresession.h
     coresessioneventprocessor.h
     coreuserinputhandler.h
index c894820..2a2e5eb 100644 (file)
@@ -169,6 +169,8 @@ Core::Core()
 }
 
 void Core::init() {
+  _oidentdConfigGenerator = new OidentdConfigGenerator();
+
   CoreSettings cs;
   _configured = initStorage(cs.storageSettings().toMap());
 
@@ -240,6 +242,7 @@ void Core::restoreState() {
     return;
   }
   */
+
   QVariantList activeSessions = s.coreState().toMap()["ActiveSessions"].toList();
   if(activeSessions.count() > 0) {
     quInfo() << "Restoring previous core state...";
index d3f2fab..8ee1129 100644 (file)
@@ -33,6 +33,7 @@
 #  include <QTcpSocket>
 #  include <QTcpServer>
 #endif
+#include "oidentdconfiggenerator.h"
 
 #include "storage.h"
 #include "bufferinfo.h"
@@ -404,6 +405,8 @@ public:
 
   static inline QTimer &syncTimer() { return instance()->_storageSyncTimer; }
 
+  inline OidentdConfigGenerator *oidentdConfigGenerator() { return _oidentdConfigGenerator; }
+
   static const int AddClientEventId;
 
 public slots:
@@ -472,6 +475,8 @@ private:
   QTcpServer _server, _v6server;
 #endif
 
+  OidentdConfigGenerator *_oidentdConfigGenerator;
+
   QHash<QTcpSocket *, quint32> blocksizes;
   QHash<QTcpSocket *, QVariantMap> clientInfo;
 
index f7f36c5..f881d9e 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "core.h"
 #include "logger.h"
+#include <QDebug>
 
 CoreApplicationInternal::CoreApplicationInternal()
   : _coreCreated(false)
index d18ddca..8ea229f 100644 (file)
@@ -68,6 +68,7 @@ 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)));
index 0f6559a..2dbd6a9 100644 (file)
@@ -26,6 +26,7 @@
 #include "coreircuser.h"
 
 #include <QTimer>
+#include <QDebug>
 
 #ifdef HAVE_SSL
 # include <QSslSocket>
@@ -33,6 +34,7 @@
 #else
 # include <QTcpSocket>
 #endif
+#include <QAbstractSocket>
 
 #ifdef HAVE_QCA2
 #  include "cipher.h"
diff --git a/src/core/oidentdconfiggenerator.cpp b/src/core/oidentdconfiggenerator.cpp
new file mode 100644 (file)
index 0000000..779a50c
--- /dev/null
@@ -0,0 +1,84 @@
+/***************************************************************************
+ *   Copyright (C) 2012 by the Quassel Project                             *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   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.             *
+ ***************************************************************************/
+
+#include "oidentdconfiggenerator.h"
+
+OidentdConfigGenerator::OidentdConfigGenerator(QObject *parent) :
+  QObject(parent),
+  _initialized(false)
+{
+  qDebug() << "OidentdConfigGenerator() checking for being initialized";
+  if (!_initialized)
+    init();
+}
+
+bool OidentdConfigGenerator::init() {
+  configDir = QDir::homePath();
+  configFileName = ".oidentd.conf";
+  configTag = " stanza created by Quassel";
+
+  _configFile = new QFile(configDir.absoluteFilePath(configFileName));
+  qDebug() << "1: _configFile" << _configFile->fileName();
+
+  quasselStanza = QRegExp(QString("^lport .* { .* } #%1$").arg(configTag));
+
+  if (update())
+    _initialized = true;
+
+  qDebug() << "konichi wa °-°";
+
+  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());
+
+  return writeConfig();
+}
+
+bool OidentdConfigGenerator::parseConfig() {
+  qDebug() << "_configFile name" << _configFile->fileName();
+  qDebug() << "open?" << _configFile->isOpen();
+  if (!_configFile->isOpen() && !_configFile->open(QIODevice::ReadWrite))
+    return false;
+
+  QByteArray parsedConfig;
+  while (!_configFile->atEnd()) {
+    QByteArray line = _configFile->readLine();
+
+    if (checkLine(line))
+      parsedConfig.append(line);
+  }
+
+  _config = parsedConfig;
+
+  return true;
+}
+
+bool OidentdConfigGenerator::writeConfig() {
+  return true;
+}
+
+bool OidentdConfigGenerator::checkLine(const QByteArray &line) {
+  return !quasselStanza.exactMatch(line);
+}
diff --git a/src/core/oidentdconfiggenerator.h b/src/core/oidentdconfiggenerator.h
new file mode 100644 (file)
index 0000000..db4016c
--- /dev/null
@@ -0,0 +1,61 @@
+/***************************************************************************
+ *   Copyright (C) 2012 by the Quassel Project                             *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   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.             *
+ ***************************************************************************/
+
+#ifndef OIDENTDCONFIGGENERATOR_H
+#define OIDENTDCONFIGGENERATOR_H
+
+#include <QObject>
+#include <QDir>
+#include <QFile>
+#include <QDateTime>
+
+#include <QDebug>
+
+class OidentdConfigGenerator : public QObject
+{
+    Q_OBJECT
+public:
+  explicit OidentdConfigGenerator(QObject *parent = 0);
+
+  QDir configDir;
+  QString configFileName;
+    
+signals:
+    
+public slots:
+  bool update();
+
+private:
+  bool init();
+  bool writeConfig();
+  bool parseConfig();
+  bool checkLine(const QByteArray &line);
+
+  bool _initialized;
+  QDateTime _lastSync;
+  QFile *_configFile;
+  QByteArray _config;
+
+  QString configTag;
+
+  QRegExp quasselStanza;
+};
+
+#endif // OIDENTDCONFIGGENERATOR_H