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
|
|
|
29 |
#define V_ADD "b"
|
2 |
andreas |
30 |
|
134 |
andreas |
31 |
#ifndef V_SERIAL
|
|
|
32 |
#define V_SERIAL "20220401T131B"
|
|
|
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();
|
35 |
andreas |
90 |
static bool getProfiling();
|
51 |
andreas |
91 |
static std::string& getPassword1();
|
|
|
92 |
static std::string& getPassword2();
|
|
|
93 |
static std::string& getPassword3();
|
|
|
94 |
static std::string& getPassword4();
|
71 |
andreas |
95 |
static std::string& getSystemSound();
|
|
|
96 |
static bool getSystemSoundState();
|
141 |
andreas |
97 |
static int getSystemVolume();
|
|
|
98 |
static int getSystemGain();
|
134 |
andreas |
99 |
static bool getRotationFixed();
|
|
|
100 |
static void setRotationFixed(bool fix);
|
|
|
101 |
static void setSystemChannel(int ch);
|
|
|
102 |
static std::string& getUUID();
|
71 |
andreas |
103 |
static std::string& getSingleBeepSound();
|
|
|
104 |
static std::string& getDoubleBeepSound();
|
112 |
andreas |
105 |
static std::string& getFtpUser();
|
|
|
106 |
static std::string& getFtpPassword();
|
115 |
andreas |
107 |
static std::string& getFtpSurface();
|
116 |
andreas |
108 |
static bool getFtpPassive();
|
115 |
andreas |
109 |
static time_t getFtpDownloadTime();
|
2 |
andreas |
110 |
|
35 |
andreas |
111 |
static std::string& getController();
|
11 |
andreas |
112 |
static int getSystem();
|
35 |
andreas |
113 |
static int getPort();
|
|
|
114 |
static int getChannel();
|
|
|
115 |
static std::string& getPanelType();
|
|
|
116 |
static std::string& getFirmVersion();
|
21 |
andreas |
117 |
static bool certCheck();
|
116 |
andreas |
118 |
static bool isInitialized() { return mInitialized; }
|
141 |
andreas |
119 |
static bool getMuteState() { return mMute; }
|
|
|
120 |
static void setMuteState(bool state) { mMute = state; }
|
2 |
andreas |
121 |
|
23 |
andreas |
122 |
static bool saveProjectPath(const std::string& path);
|
|
|
123 |
static bool saveLogFile(const std::string& file);
|
|
|
124 |
static bool saveLogLevel(const std::string& level);
|
59 |
andreas |
125 |
static bool saveLogLevel(uint level);
|
23 |
andreas |
126 |
static bool saveController(const std::string& cnt);
|
|
|
127 |
static bool savePort(int port);
|
|
|
128 |
static bool saveChannel(int channel);
|
|
|
129 |
static bool savePanelType(const std::string& pt);
|
|
|
130 |
static bool saveSettings();
|
|
|
131 |
static void saveFormat(bool format);
|
24 |
andreas |
132 |
static void saveScale(bool scale);
|
118 |
andreas |
133 |
static void saveBanner(bool banner);
|
120 |
andreas |
134 |
static void saveToolbarForce(bool tb);
|
35 |
andreas |
135 |
static void saveProfiling(bool prof);
|
51 |
andreas |
136 |
static void savePassword1(const std::string& pw);
|
|
|
137 |
static void savePassword2(const std::string& pw);
|
|
|
138 |
static void savePassword3(const std::string& pw);
|
|
|
139 |
static void savePassword4(const std::string& pw);
|
71 |
andreas |
140 |
static void saveSystemSoundFile(const std::string& snd);
|
|
|
141 |
static void saveSystemSoundState(bool state);
|
141 |
andreas |
142 |
static void saveSingleBeepFile(const std::string& snd);
|
|
|
143 |
static void saveDoubleBeepFile(const std::string& snd);
|
|
|
144 |
static void saveSystemVolume(int volume);
|
|
|
145 |
static void saveSystemGain(int gain);
|
112 |
andreas |
146 |
static void saveFtpUser(const std::string& user);
|
|
|
147 |
static void saveFtpPassword(const std::string& pw);
|
115 |
andreas |
148 |
static void saveFtpSurface(const std::string& fname);
|
116 |
andreas |
149 |
static void saveFtpPassive(bool mode);
|
115 |
andreas |
150 |
static void saveFtpDownloadTime(time_t t);
|
23 |
andreas |
151 |
|
104 |
andreas |
152 |
// SIP management
|
|
|
153 |
static std::string& getSIPproxy();
|
|
|
154 |
static void setSIPproxy(const std::string& address);
|
|
|
155 |
static int getSIPport();
|
|
|
156 |
static void setSIPport(int port);
|
127 |
andreas |
157 |
static int getSIPportTLS();
|
|
|
158 |
static void setSIPportTLS(int port);
|
104 |
andreas |
159 |
static std::string& getSIPstun();
|
|
|
160 |
static void setSIPstun(const std::string& address);
|
|
|
161 |
static std::string& getSIPdomain();
|
|
|
162 |
static void setSIPdomain(const std::string& domain);
|
|
|
163 |
static std::string& getSIPuser();
|
|
|
164 |
static void setSIPuser(const std::string& user);
|
|
|
165 |
static std::string& getSIPpassword();
|
|
|
166 |
static void setSIPpassword(const std::string& pw);
|
|
|
167 |
static bool getSIPstatus();
|
127 |
andreas |
168 |
static bool getSIPnetworkIPv4();
|
|
|
169 |
static void setSIPnetworkIPv4(bool state);
|
|
|
170 |
static bool getSIPnetworkIPv6();
|
|
|
171 |
static void setSIPnetworkIPv6(bool state);
|
|
|
172 |
static SIP_FIREWALL_t getSIPfirewall();
|
|
|
173 |
static std::string getSIPfirewallStr();
|
|
|
174 |
static void setSIPfirewall(SIP_FIREWALL_t fw);
|
104 |
andreas |
175 |
static void setSIPstatus(bool state);
|
139 |
andreas |
176 |
static void setSIPiphone(bool state);
|
|
|
177 |
static bool getSIPiphone();
|
104 |
andreas |
178 |
|
35 |
andreas |
179 |
protected:
|
71 |
andreas |
180 |
static bool isTrue(const std::string& boolean);
|
23 |
andreas |
181 |
|
35 |
andreas |
182 |
private:
|
59 |
andreas |
183 |
static uint logLevelStrToBits(const std::string& level);
|
|
|
184 |
static std::string logLevelBitsToString(uint level);
|
127 |
andreas |
185 |
static std::string sipFirewallToString(SIP_FIREWALL_t fw);
|
|
|
186 |
static SIP_FIREWALL_t sipFirewallStrToEnum(const std::string& str);
|
35 |
andreas |
187 |
bool findConfig();
|
|
|
188 |
bool readConfig();
|
|
|
189 |
std::vector<std::string> split(const std::string& str, const std::string& seps, const bool trimEmpty);
|
71 |
andreas |
190 |
static int caseCompare(const std::string& str1, const std::string& str2);
|
118 |
andreas |
191 |
static std::string makeConfigDefault(const std::string& log, const std::string& project);
|
2 |
andreas |
192 |
|
35 |
andreas |
193 |
std::string mPath;
|
|
|
194 |
std::string mCFile;
|
90 |
andreas |
195 |
std::vector<std::string> mCfgPaths;
|
116 |
andreas |
196 |
static bool mInitialized;
|
134 |
andreas |
197 |
static int mChannel; // If the channel was changed by a command, this variable holds the new value.
|
141 |
andreas |
198 |
static bool mMute; // Holds the mute status. This is temporary!
|
21 |
andreas |
199 |
#ifdef __ANDROID__
|
|
|
200 |
std::string mRoot;
|
|
|
201 |
#endif
|
2 |
andreas |
202 |
};
|
|
|
203 |
|
|
|
204 |
#endif
|