#include <QLibraryInfo>
#include <QSettings>
#include <QTranslator>
+#include <QHostAddress>
#include "message.h"
#include "identity.h"
qRegisterMetaType<AccountId>("AccountId");
qRegisterMetaType<MsgId>("MsgId");
+ qRegisterMetaType<QHostAddress>("QHostAddress");
+
qRegisterMetaTypeStreamOperators<IdentityId>("IdentityId");
qRegisterMetaTypeStreamOperators<BufferId>("BufferId");
qRegisterMetaTypeStreamOperators<NetworkId>("NetworkId");
#include <QString>
#include <QVariant>
#include <QTextStream>
+#include <QHostAddress>
class SignedId {
protected:
Q_DECLARE_METATYPE(IdentityId)
Q_DECLARE_METATYPE(AccountId)
+Q_DECLARE_METATYPE(QHostAddress)
+
// a few typedefs
typedef QList<MsgId> MsgIdList;
typedef QList<BufferId> BufferIdList;
}
void Core::init() {
- _oidentdConfigGenerator = new OidentdConfigGenerator();
-
CoreSettings cs;
_configured = initStorage(cs.storageSettings().toMap());
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() {
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)));
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() {
}
void CoreNetwork::socketInitialized() {
+qDebug() << "connected()";
Server server = usedServer();
#ifdef HAVE_SSL
if(server.useSsl && !socket.isEncrypted())
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;
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); }
quasselStanza = QRegExp(QString("^lport .* { .* } #%1$").arg(configTag));
- if (update())
+ if (parseConfig(true) && writeConfig())
_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());
+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))
while (!_configFile->atEnd()) {
QByteArray line = _configFile->readLine();
- if (checkLine(line))
+ if (!stripQuasselStanzas || checkLine(line))
parsedConfig.append(line);
}
}
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) {
#include <QDir>
#include <QFile>
#include <QDateTime>
+#include <QHostAddress>
+#include "coreidentity.h"
#include <QDebug>
class OidentdConfigGenerator : public QObject
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;