X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Foidentdconfiggenerator.cpp;h=877981cb163584e9e8b4fd559191bf9a726b1214;hp=2e6e0ca2247a6f8f444df2ae2a68a1f4e3d2481b;hb=160492494676f09b7836badc165727a538f03ece;hpb=f81ad4f71a532ca310fae0fbe2f412bde9a37521 diff --git a/src/core/oidentdconfiggenerator.cpp b/src/core/oidentdconfiggenerator.cpp index 2e6e0ca2..877981cb 100644 --- a/src/core/oidentdconfiggenerator.cpp +++ b/src/core/oidentdconfiggenerator.cpp @@ -24,7 +24,6 @@ OidentdConfigGenerator::OidentdConfigGenerator(QObject *parent) : QObject(parent), _initialized(false) { - qDebug() << "OidentdConfigGenerator() checking for being initialized"; if (!_initialized) init(); } @@ -32,38 +31,52 @@ OidentdConfigGenerator::OidentdConfigGenerator(QObject *parent) : bool OidentdConfigGenerator::init() { configDir = QDir::homePath(); configFileName = ".oidentd.conf"; + + if(Quassel::isOptionSet("oidentd-conffile")) + configPath = Quassel::optionValue("oidentd-conffile"); + else + configPath = configDir.absoluteFilePath(configFileName); + configTag = " stanza created by Quassel"; - _configFile = new QFile(configDir.absoluteFilePath(configFileName)); - qDebug() << "1: _configFile" << _configFile->fileName(); + _configFile = new QFile(configPath); - quasselStanza = QRegExp(QString("^lport .* { .* } #%1$").arg(configTag)); + // Rx has to match Template in order for cleanup to work. + // Template should be enhanced with the "from" parameter as soon as Quassel gains + // the ability to bind to an IP on client sockets. - if (parseConfig(true) && writeConfig()) - _initialized = true; + quasselStanzaTemplate = QString("lport %1 { reply \"%2\" } #%3\n"); + quasselStanzaRx = QRegExp(QString("^lport .* \\{ .* \\} #%1\\r?\\n").arg(configTag)); - qDebug() << "konichi wa °-°"; + _mutex.lock(); + // initially remove all Quassel stanzas that might be present + if (parseConfig(false) && writeConfig()) + _initialized = true; + _mutex.unlock(); return _initialized; } 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(); - + Q_UNUSED(localAddress) Q_UNUSED(peerAddress) Q_UNUSED(peerPort) QString ident = identity->ident(); - _config.append(QString("lport %1 { reply \"%2\" } #%3\n").arg(localPort).arg(ident).arg(configTag)); + _config.append(quasselStanzaTemplate.arg(localPort).arg(ident).arg(configTag)); - return writeConfig(); + _mutex.lock(); + bool ret = writeConfig(); + _mutex.unlock(); + + return ret; } -bool OidentdConfigGenerator::parseConfig(bool stripQuasselStanzas) { - qDebug() << "_configFile name" << _configFile->fileName(); - qDebug() << "open?" << _configFile->isOpen(); +// not yet implemented +bool OidentdConfigGenerator::removeSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort) { + Q_UNUSED(identity) Q_UNUSED(localAddress) Q_UNUSED(localPort) Q_UNUSED(peerAddress) Q_UNUSED(peerPort) + return true; +} + +bool OidentdConfigGenerator::parseConfig(bool keepQuasselStanzas) { if (!_configFile->isOpen() && !_configFile->open(QIODevice::ReadWrite)) return false; @@ -71,7 +84,7 @@ bool OidentdConfigGenerator::parseConfig(bool stripQuasselStanzas) { while (!_configFile->atEnd()) { QByteArray line = _configFile->readLine(); - if (!stripQuasselStanzas || checkLine(line)) + if (keepQuasselStanzas || !lineByUs(line)) parsedConfig.append(line); } @@ -81,16 +94,16 @@ bool OidentdConfigGenerator::parseConfig(bool stripQuasselStanzas) { } bool OidentdConfigGenerator::writeConfig() { - if (!_configFile->isOpen() && !_configFile->open(QIODevice::ReadWrite)) + if (!_configFile->isOpen() && !_configFile->open(QIODevice::ReadWrite | QIODevice::Text)) return false; - //FIXME: thread safety - QTextStream out(_configFile); - out << _config; + _configFile->seek(0); + _configFile->resize(0); + _configFile->write(_config); return _configFile->flush(); } -bool OidentdConfigGenerator::checkLine(const QByteArray &line) { - return !quasselStanza.exactMatch(line); +bool OidentdConfigGenerator::lineByUs(const QByteArray &line) { + return quasselStanzaRx.exactMatch(line); }