X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Foidentdconfiggenerator.cpp;h=877981cb163584e9e8b4fd559191bf9a726b1214;hp=62d31c25096607b4a2f6e4290b781beff5216d69;hb=160492494676f09b7836badc165727a538f03ece;hpb=f9a73e3ad8142212028a39b26ced62456e575b7a diff --git a/src/core/oidentdconfiggenerator.cpp b/src/core/oidentdconfiggenerator.cpp index 62d31c25..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(); } @@ -41,35 +40,43 @@ bool OidentdConfigGenerator::init() { configTag = " stanza created by Quassel"; _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 (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)); + + _mutex.lock(); + bool ret = writeConfig(); + _mutex.unlock(); - return writeConfig(); + 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; @@ -77,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); } @@ -87,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); }