1 /*************************************************************************** 2 * Copyright (C) 2005-2020 by the Quassel Project * 3 * devel@quassel-irc.org * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation; either version 2 of the License, or * 8 * (at your option) version 3. * 9 * * 10 * This program is distributed in the hope that it will be useful, * 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 * GNU General Public License for more details. * 14 * * 15 * You should have received a copy of the GNU General Public License * 16 * along with this program; if not, write to the * 17 * Free Software Foundation, Inc., * 18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 19 ***************************************************************************/ 20 21 #ifndef OIDENTDCONFIGGENERATOR_H 22 #define OIDENTDCONFIGGENERATOR_H 23 24 #include <QByteArray> 25 #include <QDateTime> 26 #include <QDir> 27 #include <QFile> 28 #include <QHostAddress> 29 #include <QMutex> 30 #include <QObject> 31 #include <QString> 32 33 #include "coreidentity.h" 34 #include "quassel.h" 35 36 //! Produces oidentd configuration files 37 /*! 38 Upon IRC connect this class puts the clients' ident data into an oidentd configuration file. 39 40 The default path is <~/.oidentd.conf>. 41 42 For oidentd to incorporate this file, the global oidentd.conf has to state something like this: 43 44 user "quassel" { 45 default { 46 allow spoof 47 allow spoof_all 48 } 49 } 50 51 */ 52 53 class OidentdConfigGenerator : public QObject 54 { 55 Q_OBJECT 56 public: 57 explicit OidentdConfigGenerator(QObject* parent = nullptr); 58 ~OidentdConfigGenerator() override; 59 60 public slots: 61 bool addSocket(const CoreIdentity* identity, 62 const QHostAddress& localAddress, 63 quint16 localPort, 64 const QHostAddress& peerAddress, 65 quint16 peerPort, 66 qint64 socketId); 67 bool removeSocket(const CoreIdentity* identity, 68 const QHostAddress& localAddress, 69 quint16 localPort, 70 const QHostAddress& peerAddress, 71 quint16 peerPort, 72 qint64 socketId); 73 74 private: 75 QString sysIdentForIdentity(const CoreIdentity* identity) const; 76 bool init(); 77 bool writeConfig(); 78 bool parseConfig(bool readQuasselStanzas = false); 79 bool lineByUs(const QByteArray& line); 80 81 bool _initialized{false}; 82 bool _strict; 83 QDateTime _lastSync; 84 QFile* _configFile; 85 QByteArray _parsedConfig; 86 QByteArray _quasselConfig; 87 // Mutex isn't strictly necessary at the moment, since with the current invocation in Core only one instance at a time exists 88 QMutex _mutex; 89 90 QDir _configDir; 91 QString _configFileName; 92 QString _configPath; 93 QString _configTag; 94 QRegExp _quasselStanzaRx; 95 QString _quasselStanzaTemplate; 96 }; 97 98 #endif // OIDENTDCONFIGGENERATOR_H 99