X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Foidentdconfiggenerator.cpp;h=29cb56d47217976adfe6088a084459771cf816b6;hp=779a50c9b33342616b84dc55f78b8df05a79f6b7;hb=2f4b9ffd04fad33c75254ccc3ca751a396a8470f;hpb=03eb5a574ec55546c62336428c7a9caa63b45a7a diff --git a/src/core/oidentdconfiggenerator.cpp b/src/core/oidentdconfiggenerator.cpp index 779a50c9..29cb56d4 100644 --- a/src/core/oidentdconfiggenerator.cpp +++ b/src/core/oidentdconfiggenerator.cpp @@ -32,33 +32,53 @@ 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)); + _configFile = new QFile(configPath); qDebug() << "1: _configFile" << _configFile->fileName(); - 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 (update()) - _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::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) { + Q_UNUSED(localAddress) Q_UNUSED(peerAddress) Q_UNUSED(peerPort) + QString ident = identity->ident(); + + _config.append(quasselStanzaTemplate.arg(localPort).arg(ident).arg(configTag)); + + _mutex.lock(); + bool ret = writeConfig(); + _mutex.unlock(); - return writeConfig(); + return ret; } -bool OidentdConfigGenerator::parseConfig() { - 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; @@ -66,7 +86,7 @@ bool OidentdConfigGenerator::parseConfig() { while (!_configFile->atEnd()) { QByteArray line = _configFile->readLine(); - if (checkLine(line)) + if (keepQuasselStanzas || !lineByUs(line)) parsedConfig.append(line); } @@ -76,9 +96,16 @@ bool OidentdConfigGenerator::parseConfig() { } bool OidentdConfigGenerator::writeConfig() { - return true; + if (!_configFile->isOpen() && !_configFile->open(QIODevice::ReadWrite | QIODevice::Text)) + return false; + + _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); }