Subversion Repositories tpanel

Rev

Rev 481 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
446 andreas 1
/*
2
 * Copyright (C) 2020 to 2022 by Andreas Theofilu <andreas@theosys.at>
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
 
486 andreas 25
#define V_MAJOR     2
26
#define V_MINOR     0
27
#define V_PATCH     0
28
#define V_ADD       "b1"
446 andreas 29
 
30
#ifndef V_SERIAL
486 andreas 31
#define V_SERIAL    "20250222TP200B"
446 andreas 32
#endif
33
 
34
/**
35
 * @def TPANEL_VERSION
36
 * Defines the version of this application.
37
 */
38
#define TPANEL_VERSION      ((V_MAJOR * 0x10000) + (V_MINOR * 0x100) + V_PATCH)
39
 
40
#define VERSION_STRING() _GET_X_VERSION(V_MAJOR, V_MINOR, V_PATCH)
41
#define _GET_X_VERSION(a, b, c) _GET_VERSION(a, b, c)
42
//#define _GET_VERSION(a, b, c) ( #a "." #b "." #c )          // Release version
43
#define _GET_VERSION(a, b, c) ( #a "." #b "." #c V_ADD)     // Beta version
44
 
45
#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
46
typedef unsigned short          ushort;         /* Sys V compatibility */
47
typedef unsigned int            uint;           /* Sys V compatibility */
48
#endif
49
 
465 andreas 50
extern std::string realPrgName;
51
 
446 andreas 52
/**
53
 * @brief The TConfig class manages the configurations.
54
 *
55
 * The class contains methods to read a config file, parse it's content and
56
 * hold the configuration options in the class. All public methods are static.
57
 */
58
class TConfig
59
{
60
    public:
61
        TConfig(const std::string& path);
62
        bool reReadConfig();
63
 
64
        typedef enum SYSTEMRESOURCE_t
65
        {
66
            BASE,
67
            BORDERS,
68
            FONTS,
69
            IMAGES,
70
            SLIDERS,
71
            SOUNDS
72
        }SYSTEMRESOURCE_t;
73
 
74
        typedef enum SIP_FIREWALL_t
75
        {
76
            SIP_NO_FIREWALL,
77
            SIP_NAT_ADDRESS,    // Currently not configurable
78
            SIP_STUN,
79
            SIP_ICE,
80
            SIP_UPNP
81
        }SIP_FIREWALL_t;
82
 
83
        static bool setTemporary(bool tmp);
84
        static bool getTemporary() { return mTemporary; }
85
        static void reset();
86
        static void setProgName(const std::string& pname);
87
        static std::string& getProgName();
88
        static std::string& getConfigPath();
89
        static std::string& getConfigFileName();
90
        static std::string& getProjectPath();
91
        static std::string getSystemProjectPath();
92
        static std::string getSystemPath(SYSTEMRESOURCE_t sres);
93
        static std::string& getLogFile();
94
        static std::string& getLogLevel();
95
        static uint getLogLevelBits();
96
        static bool isLongFormat();
97
        static bool getLogFileEnabled() { return mLogFileEnabled; }
98
        static void setLogFileEnabled(bool lf) { mLogFileEnabled = lf; }
99
        static bool showBanner();
100
        static bool getScale();
101
        static bool getToolbarForce();
102
        static bool getToolbarSuppress();
103
        static bool getProfiling();
104
        static size_t getButttonCache();
105
        static std::string& getPassword1();
106
        static std::string& getPassword2();
107
        static std::string& getPassword3();
108
        static std::string& getPassword4();
109
        static std::string& getSystemSound();
110
        static bool getSystemSoundState();
111
        static int getSystemVolume();
112
        static int getSystemGain();
113
        static bool getRotationFixed();
114
        static void setRotationFixed(bool fix);
115
        static void setSystemChannel(int ch);
116
        static std::string& getUUID();
117
        static std::string& getSingleBeepSound();
118
        static std::string& getDoubleBeepSound();
119
        static std::string& getFtpUser();
120
        static std::string& getFtpPassword();
121
        static std::string& getFtpSurface();
122
        static bool getFtpPassive();
123
        static time_t getFtpDownloadTime();
124
 
125
        static std::string& getController();
126
        static int getSystem();
127
        static int getPort();
128
        static int getChannel();
129
        static std::string& getPanelType();
130
        static std::string& getFirmVersion();
131
        static bool certCheck();
132
        static bool isInitialized() { return mInitialized; }
133
        static bool getMuteState() { return mMute; }
134
        static void setMuteState(bool state) { mMute = state; }
135
 
136
        static bool saveProjectPath(const std::string& path);
137
        static bool saveLogFile(const std::string& file);
138
        static bool saveLogLevel(const std::string& level);
139
        static bool saveLogLevel(uint level);
140
        static bool saveController(const std::string& cnt);
141
        static bool savePort(int port);
142
        static bool saveChannel(int channel);
143
        static bool savePanelType(const std::string& pt);
144
        static bool saveSettings();
145
        static void saveFormat(bool format);
146
        static void saveScale(bool scale);
147
        static void saveBanner(bool banner);
148
        static void saveToolbarForce(bool tb);
149
        static void saveToolbarSuppress(bool tb);
150
        static void saveProfiling(bool prof);
151
        static void saveButtonCache(size_t size);
152
        static void savePassword1(const std::string& pw);
153
        static void savePassword2(const std::string& pw);
154
        static void savePassword3(const std::string& pw);
155
        static void savePassword4(const std::string& pw);
156
        static void setUserPassword(const std::string& user, const std::string& pw);
157
        static std::string getUserPassword(const std::string& user);
158
        static void clearUserPassword(const std::string& user);
159
        static void clearUserPasswords();
160
        static void saveSystemSoundFile(const std::string& snd);
161
        static void saveSystemSoundState(bool state);
162
        static void saveSingleBeepFile(const std::string& snd);
163
        static void saveDoubleBeepFile(const std::string& snd);
164
        static void saveSystemVolume(int volume);
165
        static void saveSystemGain(int gain);
166
        static void saveFtpUser(const std::string& user);
167
        static void saveFtpPassword(const std::string& pw);
168
        static void saveFtpSurface(const std::string& fname);
169
        static void saveFtpPassive(bool mode);
170
        static void saveFtpDownloadTime(time_t t);
171
 
172
        // SIP management
173
        static std::string& getSIPproxy();
174
        static void setSIPproxy(const std::string& address);
175
        static int getSIPport();
176
        static void setSIPport(int port);
177
        static int getSIPportTLS();
178
        static void setSIPportTLS(int port);
179
        static std::string& getSIPstun();
180
        static void setSIPstun(const std::string& address);
181
        static std::string& getSIPdomain();
182
        static void setSIPdomain(const std::string& domain);
183
        static std::string& getSIPuser();
184
        static void setSIPuser(const std::string& user);
185
        static std::string& getSIPpassword();
186
        static void setSIPpassword(const std::string& pw);
187
        static bool getSIPstatus();
188
        static bool getSIPnetworkIPv4();
189
        static void setSIPnetworkIPv4(bool state);
190
        static bool getSIPnetworkIPv6();
191
        static void setSIPnetworkIPv6(bool state);
192
        static SIP_FIREWALL_t getSIPfirewall();
193
        static std::string getSIPfirewallStr();
194
        static void setSIPfirewall(SIP_FIREWALL_t fw);
195
        static void setSIPstatus(bool state);
196
        static void setSIPiphone(bool state);
197
        static bool getSIPiphone();
198
 
480 andreas 199
        // G5 extensions
481 andreas 200
        static std::string getApp(const std::string& id);
480 andreas 201
 
446 andreas 202
    private:
203
        static uint logLevelStrToBits(const std::string& level);
204
        static std::string logLevelBitsToString(uint level);
205
        static std::string sipFirewallToString(SIP_FIREWALL_t fw);
206
        static SIP_FIREWALL_t sipFirewallStrToEnum(const std::string& str);
207
        static void writeUserPasswords();
208
        void readUserPasswords();
209
        bool findConfig();
210
        bool readConfig();
211
        std::vector<std::string> split(const std::string& str, const std::string& seps, const bool trimEmpty);
212
        static int caseCompare(const std::string& str1, const std::string& str2);
213
        static std::string makeConfigDefault(const std::string& log, const std::string& project);
214
 
215
        std::string mPath;
216
        std::string mCFile;
217
        std::vector<std::string> mCfgPaths;
218
        static bool mInitialized;
219
        static int mChannel;        // If the channel was changed by a command, this variable holds the new value.
220
        static bool mMute;          // Holds the mute status. This is temporary!
221
        static bool mTemporary;     // If TRUE the temporary parameter table is used
222
        static bool mLogFileEnabled;// if TRUE the logging is written into the logfile, if there is a valid name.
223
#ifdef __ANDROID__
224
        std::string mRoot;
225
#endif
226
};
227
 
228
#endif