fc022fefd3cde3c2daa55f44a023693e7aeaf8d1
[quassel.git] / src / core / oidentdconfiggenerator.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 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 <QObject>
25 #include <QString>
26 #include <QDir>
27 #include <QFile>
28 #include <QDateTime>
29 #include <QHostAddress>
30 #include <QMutex>
31 #include <QByteArray>
32
33 #include "quassel.h"
34 #include "coreidentity.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, const QHostAddress &localAddress,
62                    quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort,
63                    qint64 socketId);
64     bool removeSocket(const CoreIdentity *identity, const QHostAddress &localAddress,
65                       quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort,
66                       qint64 socketId);
67
68 private:
69     QString sysIdentForIdentity(const CoreIdentity *identity) const;
70     bool init();
71     bool writeConfig();
72     bool parseConfig(bool readQuasselStanzas = false);
73     bool lineByUs(const QByteArray &line);
74
75     bool _initialized;
76     bool _strict;
77     QDateTime _lastSync;
78     QFile *_configFile;
79     QByteArray _parsedConfig;
80     QByteArray _quasselConfig;
81     // Mutex isn't strictly necessary at the moment, since with the current invocation in Core only one instance at a time exists
82     QMutex _mutex;
83
84     QDir _configDir;
85     QString _configFileName;
86     QString _configPath;
87     QString _configTag;
88     QRegExp _quasselStanzaRx;
89     QString _quasselStanzaTemplate;
90 };
91
92
93 #endif // OIDENTDCONFIGGENERATOR_H