Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 andreas 1
/*
101 andreas 2
 * Copyright (C) 2020 to 2022 by Andreas Theofilu <andreas@theosys.at>
2 andreas 3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
#ifndef __TCONFIG_H__
19
#define __TCONFIG_H__
20
 
21
#include <string>
22
#include <vector>
23
#include <algorithm>
24
#include "terror.h"
25
 
35 andreas 26
#define V_MAJOR     1
113 andreas 27
#define V_MINOR     3
138 andreas 28
#define V_PATCH     2
162 andreas 29
#define V_ADD       "b7"
2 andreas 30
 
134 andreas 31
#ifndef V_SERIAL
162 andreas 32
#define V_SERIAL    "20220524T132B"
134 andreas 33
#endif
34
 
21 andreas 35
/**
36
 * @def TPANEL_VERSION
37
 * Defines the version of this application.
38
 */
35 andreas 39
#define TPANEL_VERSION      ((V_MAJOR * 0x10000) + (V_MINOR * 0x100) + V_PATCH)
2 andreas 40
 
24 andreas 41
#define VERSION_STRING() _GET_X_VERSION(V_MAJOR, V_MINOR, V_PATCH)
42
#define _GET_X_VERSION(a, b, c) _GET_VERSION(a, b, c)
138 andreas 43
//#define _GET_VERSION(a, b, c) ( #a "." #b "." #c )          // Release version
44
#define _GET_VERSION(a, b, c) ( #a "." #b "." #c V_ADD)     // Beta version
24 andreas 45
 
21 andreas 46
/**
47
 * @brief The TConfig class manages the configurations.
48
 *
49
 * The class contains methods to read a config file, parse it's content and
50
 * hold the configuration options in the class. All public methods are static.
51
 */
2 andreas 52
class TConfig
53
{
35 andreas 54
    public:
55
        TConfig(const std::string& path);
23 andreas 56
        bool reReadConfig();
2 andreas 57
 
71 andreas 58
        typedef enum SYSTEMRESOURCE_t
59
        {
60
            BASE,
61
            BORDERS,
62
            FONTS,
63
            IMAGES,
64
            SLIDERS,
65
            SOUNDS
66
        }SYSTEMRESOURCE_t;
67
 
127 andreas 68
        typedef enum SIP_FIREWALL_t
69
        {
70
            SIP_NO_FIREWALL,
71
            SIP_NAT_ADDRESS,    // Currently not configurable
72
            SIP_STUN,
73
            SIP_ICE,
74
            SIP_UPNP
75
        }SIP_FIREWALL_t;
76
 
35 andreas 77
        static void setProgName(const std::string& pname);
78
        static std::string& getProgName();
79
        static std::string& getConfigPath();
80
        static std::string& getConfigFileName();
81
        static std::string& getProjectPath();
71 andreas 82
        static std::string getSystemPath(SYSTEMRESOURCE_t sres);
35 andreas 83
        static std::string& getLogFile();
84
        static std::string& getLogLevel();
59 andreas 85
        static uint getLogLevelBits();
35 andreas 86
        static bool isLongFormat();
87
        static bool showBanner();
24 andreas 88
        static bool getScale();
120 andreas 89
        static bool getToolbarForce();
151 andreas 90
        static bool getToolbarSuppress();
35 andreas 91
        static bool getProfiling();
51 andreas 92
        static std::string& getPassword1();
93
        static std::string& getPassword2();
94
        static std::string& getPassword3();
95
        static std::string& getPassword4();
71 andreas 96
        static std::string& getSystemSound();
97
        static bool getSystemSoundState();
141 andreas 98
        static int getSystemVolume();
99
        static int getSystemGain();
134 andreas 100
        static bool getRotationFixed();
101
        static void setRotationFixed(bool fix);
102
        static void setSystemChannel(int ch);
103
        static std::string& getUUID();
71 andreas 104
        static std::string& getSingleBeepSound();
105
        static std::string& getDoubleBeepSound();
112 andreas 106
        static std::string& getFtpUser();
107
        static std::string& getFtpPassword();
115 andreas 108
        static std::string& getFtpSurface();
116 andreas 109
        static bool getFtpPassive();
115 andreas 110
        static time_t getFtpDownloadTime();
2 andreas 111
 
35 andreas 112
        static std::string& getController();
11 andreas 113
        static int getSystem();
35 andreas 114
        static int getPort();
115
        static int getChannel();
116
        static std::string& getPanelType();
117
        static std::string& getFirmVersion();
21 andreas 118
        static bool certCheck();
116 andreas 119
        static bool isInitialized() { return mInitialized; }
141 andreas 120
        static bool getMuteState() { return mMute; }
121
        static void setMuteState(bool state) { mMute = state; }
2 andreas 122
 
23 andreas 123
        static bool saveProjectPath(const std::string& path);
124
        static bool saveLogFile(const std::string& file);
125
        static bool saveLogLevel(const std::string& level);
59 andreas 126
        static bool saveLogLevel(uint level);
23 andreas 127
        static bool saveController(const std::string& cnt);
128
        static bool savePort(int port);
129
        static bool saveChannel(int channel);
130
        static bool savePanelType(const std::string& pt);
131
        static bool saveSettings();
132
        static void saveFormat(bool format);
24 andreas 133
        static void saveScale(bool scale);
118 andreas 134
        static void saveBanner(bool banner);
120 andreas 135
        static void saveToolbarForce(bool tb);
151 andreas 136
        static void saveToolbarSuppress(bool tb);
35 andreas 137
        static void saveProfiling(bool prof);
51 andreas 138
        static void savePassword1(const std::string& pw);
139
        static void savePassword2(const std::string& pw);
140
        static void savePassword3(const std::string& pw);
141
        static void savePassword4(const std::string& pw);
71 andreas 142
        static void saveSystemSoundFile(const std::string& snd);
143
        static void saveSystemSoundState(bool state);
141 andreas 144
        static void saveSingleBeepFile(const std::string& snd);
145
        static void saveDoubleBeepFile(const std::string& snd);
146
        static void saveSystemVolume(int volume);
147
        static void saveSystemGain(int gain);
112 andreas 148
        static void saveFtpUser(const std::string& user);
149
        static void saveFtpPassword(const std::string& pw);
115 andreas 150
        static void saveFtpSurface(const std::string& fname);
116 andreas 151
        static void saveFtpPassive(bool mode);
115 andreas 152
        static void saveFtpDownloadTime(time_t t);
23 andreas 153
 
104 andreas 154
        // SIP management
155
        static std::string& getSIPproxy();
156
        static void setSIPproxy(const std::string& address);
157
        static int getSIPport();
158
        static void setSIPport(int port);
127 andreas 159
        static int getSIPportTLS();
160
        static void setSIPportTLS(int port);
104 andreas 161
        static std::string& getSIPstun();
162
        static void setSIPstun(const std::string& address);
163
        static std::string& getSIPdomain();
164
        static void setSIPdomain(const std::string& domain);
165
        static std::string& getSIPuser();
166
        static void setSIPuser(const std::string& user);
167
        static std::string& getSIPpassword();
168
        static void setSIPpassword(const std::string& pw);
169
        static bool getSIPstatus();
127 andreas 170
        static bool getSIPnetworkIPv4();
171
        static void setSIPnetworkIPv4(bool state);
172
        static bool getSIPnetworkIPv6();
173
        static void setSIPnetworkIPv6(bool state);
174
        static SIP_FIREWALL_t getSIPfirewall();
175
        static std::string getSIPfirewallStr();
176
        static void setSIPfirewall(SIP_FIREWALL_t fw);
104 andreas 177
        static void setSIPstatus(bool state);
139 andreas 178
        static void setSIPiphone(bool state);
179
        static bool getSIPiphone();
104 andreas 180
 
35 andreas 181
    protected:
71 andreas 182
        static bool isTrue(const std::string& boolean);
23 andreas 183
 
35 andreas 184
    private:
59 andreas 185
        static uint logLevelStrToBits(const std::string& level);
186
        static std::string logLevelBitsToString(uint level);
127 andreas 187
        static std::string sipFirewallToString(SIP_FIREWALL_t fw);
188
        static SIP_FIREWALL_t sipFirewallStrToEnum(const std::string& str);
35 andreas 189
        bool findConfig();
190
        bool readConfig();
191
        std::vector<std::string> split(const std::string& str, const std::string& seps, const bool trimEmpty);
71 andreas 192
        static int caseCompare(const std::string& str1, const std::string& str2);
118 andreas 193
        static std::string makeConfigDefault(const std::string& log, const std::string& project);
2 andreas 194
 
35 andreas 195
        std::string mPath;
196
        std::string mCFile;
90 andreas 197
        std::vector<std::string> mCfgPaths;
116 andreas 198
        static bool mInitialized;
134 andreas 199
        static int mChannel;        // If the channel was changed by a command, this variable holds the new value.
141 andreas 200
        static bool mMute;          // Holds the mute status. This is temporary!
21 andreas 201
#ifdef __ANDROID__
202
        std::string mRoot;
203
#endif
2 andreas 204
};
205
 
206
#endif