Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 andreas 1
/*
197 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
 */
21 andreas 18
 
2 andreas 19
#include <fstream>
20
#include <vector>
21
#include <iterator>
22
#include <unistd.h>
21 andreas 23
#include <sys/stat.h>
24
#include <sys/types.h>
22 andreas 25
#ifdef __ANDROID__
134 andreas 26
#include <QUuid>
22 andreas 27
#include <android/log.h>
28
#include "tvalidatefile.h"
43 andreas 29
#include "tvalidatefile.h"
134 andreas 30
#else
31
#include <uuid/uuid.h>
22 andreas 32
#endif
118 andreas 33
#include "ttpinit.h"
22 andreas 34
#include "tconfig.h"
2 andreas 35
#include "terror.h"
73 andreas 36
#include "tresources.h"
292 andreas 37
#include "tlock.h"
240 andreas 38
#ifdef __APPLE__
39
#include <TargetConditionals.h>
40
#if TARGET_OS_SIMULATOR || TARGET_OS_IOS
239 andreas 41
#include <QString>
250 andreas 42
#include "ios/QASettings.h"
239 andreas 43
#endif
240 andreas 44
#endif
2 andreas 45
using std::string;
46
using std::ifstream;
21 andreas 47
using std::ofstream;
2 andreas 48
using std::fstream;
49
using std::vector;
21 andreas 50
using std::cout;
51
using std::cerr;
52
using std::endl;
2 andreas 53
 
116 andreas 54
bool TConfig::mInitialized{false};
134 andreas 55
int TConfig::mChannel{0};
141 andreas 56
bool TConfig::mMute{false};
192 andreas 57
bool TConfig::mTemporary{false};
257 andreas 58
bool TConfig::mLogFileEnabled{false};
292 andreas 59
std::mutex config_mutex;
116 andreas 60
 
21 andreas 61
/**
62
 * @struct SETTINGS
63
 * @brief The SETTINGS struct bundles the configuration options.
64
 *
65
 * This structure contains variables for all possible configuration options.
66
 * It is used by the class TConfig. Through this class it's possible to
67
 * access all configuration options.
68
 */
2 andreas 69
struct SETTINGS
70
{
21 andreas 71
    string pname{"tpanel"};     //!< Name of the program (default "tpanel")
72
    string path;                //!< The path where the configuration file is located
73
    string name;                //!< The name of the configuration file
74
    string project;             //!< The path where the original project files are located
75
    string server;              //!< The name or IP address of the server to connect
76
    int system{0};              //!< The number of the AMX system
77
    int port{0};                //!< The port number
78
    int ID{0};                  //!< the panel ID (a number starting by 10000)
79
    string ptype;               //!< The type of the panel (android, ipad, iphone, ...)
80
    string version;             //!< The "firmware" version
81
    string logFile;             //!< Optional path and name of a logfile
82
    string logLevel;            //!< The log level(s).
71 andreas 83
    uint logLevelBits;          //!< The numeric bit field of the loglevel
21 andreas 84
    bool longformat{false};     //!< TRUE = long format
85
    bool noBanner{false};       //!< Startup without showing a banner on the command line.
86
    bool certCheck{false};      //!< TRUE = Check certificate for SSL connection
24 andreas 87
    bool scale{false};          //!< TRUE = Images are scaled to fit the whole screen
151 andreas 88
    bool tbsuppress{false};     //!< TRUE = Don't show toolbar even if enough space
89
    bool tbforce{true};         //!< Only if "tbsuppress" = FALSE: TRUE = The toolbar is forced to display, FALSE = The toolbar is only visible if there is enough space left
35 andreas 90
    bool profiling{false};      //!< TRUE = The declaration traces meassure the time and write it to the log
175 andreas 91
    size_t max_cache{100};      //!< Size of internal button cache in Mb
51 andreas 92
    string password1;           //!< First panel password
93
    string password2;           //!< Second panel password
94
    string password3;           //!< Third panel password
95
    string password4;           //!< Fourth panel password
134 andreas 96
    bool systemRotationFix{false};  //!< TRUE = Rotation is blocked and orientation sensor is ignored.
97
    string uuid;                //!< An UUID set automatically after first start.
112 andreas 98
    // FTP credentials
99
    string ftpUser;             //!< The username for FTP of the controller (default: administrator)
100
    string ftpPassword;         //!< The password for FTP of the controller (default: password)
115 andreas 101
    string ftpSurface;          //!< The name of the file containing the TPDesign4 file to load
116 andreas 102
    bool ftpPassive{true};      //!< If false the data port 20 is used for file transfer
115 andreas 103
    time_t ftpLastDownload{0};  //!< The timestamp of the last download
104 andreas 104
    // SIP settings
105
    string sip_proxy;           //!< The address of the SIP proxy
106
    int sip_port{5060};         //!< Initializes the port of the SIP proxy to 5060
127 andreas 107
    int sip_portTLS{0};         //!< Initializes the TLS port of the SIP proxy to 0 (not used by default)
104 andreas 108
    string sip_stun;            //!< STUN address
109
    string sip_domain;          //!< Local domain
110
    string sip_user;            //!< The SIP user to connect.
111
    string sip_password;        //!< The SIP password to connect. Note: This password is saved in plain text!
127 andreas 112
    bool sip_ipv4{true};        //!< Default: TRUE, Enables or disables IPv4.
113
    bool sip_ipv6{true};        //!< Default: TRUE, Enables or disables IPv6. Has precedence over IPv4.
139 andreas 114
    bool sip_iphone{false};     //!< Default: FALSE, if enabled and SIP is enabled then the internal phone dialog is used.
127 andreas 115
    TConfig::SIP_FIREWALL_t sip_firewall{TConfig::SIP_NO_FIREWALL}; //!< Defines how to deal with a firewall.
104 andreas 116
    bool sip_enabled{false};    //!< By default SIP is disabled
141 andreas 117
    // Sound settings
118
    string systemSound;         //!< name of the set system sound played on every touch.
119
    bool systemSoundState{false};   //!< TRUE = play systemsound on every touch
120
    string systemSingleBeep;    //!< name of the system sound file to play a single beep.
121
    string systemDoubleBeep;    //!< name of the system sound file to play a double beep.
122
    int systemVolume{100};      //!< The set volume to use [0 ... 100]
123
    int systemGain{100};        //!< The set microphone level to use [0 ... 100]
2 andreas 124
};
125
 
126
typedef struct SETTINGS settings_t;
192 andreas 127
static settings_t localSettings;        //!< Global defines settings used in class TConfig.
128
static settings_t localSettings_temp;   //!< Global defines settings temporary settings
2 andreas 129
 
21 andreas 130
/**
131
 * @brief TConfig::TConfig constructor
132
 *
133
 * @param path  A path and name of a configuration file.
134
 */
2 andreas 135
TConfig::TConfig(const std::string& path)
116 andreas 136
    : mPath(path)
2 andreas 137
{
240 andreas 138
#if TARGET_OS_IOS == 0 && TARGET_OS_SIMULATOR == 0
90 andreas 139
    // Initialize the possible configuration paths
140
    mCfgPaths.push_back("/etc");
141
    mCfgPaths.push_back("/etc/tpanel");
142
    mCfgPaths.push_back("/usr/etc");
143
    mCfgPaths.push_back("/usr/etc/tpanel");
144
#ifdef __APPLE__
235 andreas 145
    mCfgPaths.push_back("/opt/local/etc");
146
    mCfgPaths.push_back("/opt/local/etc/tpanel");
147
    mCfgPaths.push_back("/opt/local/usr/etc");
148
    mCfgPaths.push_back("/opt/local/usr/etc/tpanel");
90 andreas 149
#endif
150
    if (findConfig())
151
        readConfig();
239 andreas 152
#else
153
    readConfig();
154
#endif
2 andreas 155
}
156
 
118 andreas 157
/**
158
 * Simple method to read the configuration again. This is usefull if, for
159
 * example the configuration options changed but should not be saved. Instead
160
 * they were canceled and therefor the options are read again from file.
161
 *
162
 * @return On success it returns TRUE.
163
 */
23 andreas 164
bool TConfig::reReadConfig()
165
{
166
    return readConfig();
167
}
168
 
316 andreas 169
/**
170
 * @brief TConfig::setTemporary - Activate/deactivate temporary config
171
 * Activates or deactivates the state of the temporary configuration. The
172
 * temporary configuration is a shadow configuration which holds all changes
173
 * to the configuration without saving it.
174
 *
175
 * @param tmp   State of the active configuration.
176
 * @return
177
 * Returns the previous state of the configuration setting.
178
 */
179
bool TConfig::setTemporary(bool tmp)
192 andreas 180
{
181
    DECL_TRACER("TConfig::setTemporary(bool tmp)");
182
 
316 andreas 183
    bool old = mTemporary;
192 andreas 184
    mTemporary = tmp;
316 andreas 185
    return old;
192 andreas 186
}
187
 
188
void TConfig::reset()
189
{
190
    DECL_TRACER("TConfig::reset()");
191
 
192
    localSettings_temp = localSettings;
193
    mTemporary = false;
194
}
195
 
21 andreas 196
/**
197
 * @brief TConfig::setProgName Sets the name of the application.
198
 * @param pname The name of the application.
199
 */
2 andreas 200
void TConfig::setProgName(const std::string& pname)
201
{
192 andreas 202
    if (mTemporary)
203
        localSettings_temp.pname = pname;
204
    else
205
        localSettings.pname = pname;
206
 
207
    mTemporary = false;
2 andreas 208
}
209
 
21 andreas 210
/**
211
 * @brief TConfig::getProgName Retrieves the prevously stored application name.
212
 * @return The name of this application.
213
 */
2 andreas 214
std::string & TConfig::getProgName()
215
{
192 andreas 216
    return mTemporary ? localSettings_temp.pname : localSettings.pname;
2 andreas 217
}
218
 
21 andreas 219
/**
220
 * @brief TConfig::getChannel returns the AMX channel to use.
221
 *
222
 * The AMX channels an AMX panel can use start at 10000. This method returns
223
 * the channel number found in the configuration file. If there was no
224
 * channel defination found, it returns the default channel 10001.
225
 *
226
 * @return The AMX channel number to use.
227
 */
2 andreas 228
int TConfig::getChannel()
229
{
116 andreas 230
    DECL_TRACER("TConfig::getChannel()");
231
 
192 andreas 232
    int ID = mTemporary ? localSettings_temp.ID : localSettings.ID;
233
 
234
    if (mChannel > 0 && mChannel != ID)
134 andreas 235
        return mChannel;
236
 
192 andreas 237
    return ID;
2 andreas 238
}
239
 
21 andreas 240
/**
241
 * @brief TConfig::getConfigFileName returns the name of the configuration file.
242
 *
243
 * @return The name of the configuration file.
244
 */
2 andreas 245
std::string& TConfig::getConfigFileName()
246
{
192 andreas 247
    return mTemporary ? localSettings_temp.name : localSettings.name;
2 andreas 248
}
249
 
21 andreas 250
/**
251
 * @brief TConfig::getConfigPath returns the path configuration file.
252
 *
253
 * The path was defined on the command line or found by searching the standard
254
 * directories.
255
 *
256
 * @return The path of the configuration file.
257
 */
2 andreas 258
std::string& TConfig::getConfigPath()
259
{
192 andreas 260
    return mTemporary ? localSettings_temp.path : localSettings.path;
2 andreas 261
}
262
 
21 andreas 263
/**
264
 * @brief TConfig::getController returns the network name or IP address of the AMX controller.
265
 *
266
 * The network name or the IP address was read from the configuration file.
267
 *
268
 * @return The network name of the AMX controller.
269
 */
2 andreas 270
std::string& TConfig::getController()
271
{
116 andreas 272
    DECL_TRACER("TConfig::getController()");
273
 
192 andreas 274
    return mTemporary ? localSettings_temp.server : localSettings.server;
2 andreas 275
}
276
 
21 andreas 277
/**
278
 * @brief TConfig::getSystem return the AMX system number.
279
 *
280
 * This number was read from the configuration file. If there was no system
281
 * number defined in the configuration file, then the default number 0 is
282
 * returned.
283
 *
284
 * @return The AMX system number.
285
 */
11 andreas 286
int TConfig::getSystem()
287
{
116 andreas 288
    DECL_TRACER("TConfig::getSystem()");
289
 
192 andreas 290
    return mTemporary ? localSettings_temp.system :  localSettings.system;
11 andreas 291
}
292
 
21 andreas 293
/**
294
 * @brief TConfig::getFirmVersion returns the version of the firmware.
295
 *
296
 * This option was read from the configuration file. There can be any version
297
 * number defined. But you must keep in mind, that the AMX controller may not
298
 * accept any number. If there was no version number defined, the standard
299
 * version number 1.0 is returned.
300
 *
301
 * @return The firmware version of this panel.
302
 */
2 andreas 303
std::string& TConfig::getFirmVersion()
304
{
116 andreas 305
    DECL_TRACER("TConfig::getFirmVersion()");
306
 
192 andreas 307
    return mTemporary ? localSettings_temp.version : localSettings.version;
2 andreas 308
}
309
 
21 andreas 310
/**
311
 * @brief TConfig::getLogFile the path and name of a logfile.
312
 *
313
 * If there is a logfile name defined in the configuration file, it is used
314
 * to write messages there. It depends on the _log level_ what is logged.
315
 *
316
 * @return The path and name of a logfile.
317
 */
2 andreas 318
std::string& TConfig::getLogFile()
319
{
192 andreas 320
    return mTemporary ? localSettings_temp.logFile : localSettings.logFile;
2 andreas 321
}
322
 
21 andreas 323
/**
324
 * @brief TConfig::getLogLevel returns the defined log level.
325
 *
51 andreas 326
 * The loglevel can consist of the following values:
21 andreas 327
 *
328
 *     NONE         Logs nothing (default for Android)
329
 *     INFO         Logs only informations
330
 *     WARNING      Logs only warnings
51 andreas 331
 *     ERROR        Logs only errors
21 andreas 332
 *     TRACE        Logs only trace messages
333
 *     DEBUG        Logs only debug messages
334
 *     PROTOCOL     Logs only INFO and ERROR (default if NOT Android)
335
 *     ALL          Logs everything
336
 *
337
 * All log levels can be combined by concatenating them with the | symbol.
338
 *
339
 * @return The log level(s) as a string.
340
 */
2 andreas 341
string& TConfig::getLogLevel()
342
{
192 andreas 343
    return mTemporary ? localSettings_temp.logLevel : localSettings.logLevel;
2 andreas 344
}
345
 
21 andreas 346
/**
59 andreas 347
 * @brief TConfig::getLogLevelBits
348
 *
349
 * Returns the raw bit field defining the loglevels selected.
350
 *
351
 * @return The bit field of representing the selected log levels.
352
 */
353
uint TConfig::getLogLevelBits()
354
{
116 andreas 355
    DECL_TRACER("TConfig::getLogLevelBits()");
356
 
192 andreas 357
    return mTemporary ? localSettings_temp.logLevelBits : localSettings.logLevelBits;
59 andreas 358
}
359
/**
21 andreas 360
 * @brief TConfig::getPanelType the AMX type name of the panel.
361
 *
362
 * The type name of the panel is defined in the configuration file. If this
363
 * option was not defined, the default panel _android_ is returned.
364
 *
365
 * @return The type name of the panel.
366
 */
2 andreas 367
std::string& TConfig::getPanelType()
368
{
116 andreas 369
    DECL_TRACER("TConfig::getPanelType()");
370
 
192 andreas 371
    return mTemporary ? localSettings_temp.ptype : localSettings.ptype;
2 andreas 372
}
373
 
21 andreas 374
/**
375
 * @brief TConfig::getPort returnes the AMX port number to connect to.
376
 *
377
 * The port number can be defined in the configuration file. If there is no
378
 * configuration the default number 1319 is returned.
379
 *
380
 * @return The AMX network port number.
381
 */
2 andreas 382
int TConfig::getPort()
383
{
116 andreas 384
    DECL_TRACER("TConfig::getPort()");
385
 
192 andreas 386
    return mTemporary ? localSettings_temp.port : localSettings.port;
2 andreas 387
}
388
 
21 andreas 389
/**
390
 * @brief TConfig::getProjectPath returns the path to the AMX configuration files.
391
 *
392
 * The path was read from the configuration file. This path contains all the
393
 * files needed to display the elements of the surface.
394
 *
395
 * @return The path to the AMX configuration files.
396
 */
71 andreas 397
string& TConfig::getProjectPath()
2 andreas 398
{
197 andreas 399
    return localSettings.project;
2 andreas 400
}
401
 
197 andreas 402
/**
403
 * @brief TConfig::getSystemProjectPath returns the path to the AMX setup
404
 * configuration files.
405
 *
406
 * The path was read from the configuration file. This path contains all the
407
 * files needed to display the setup elements of the setup dialog.
408
 *
409
 * @return The path to the AMX setup configuration files.
410
 */
411
string TConfig::getSystemProjectPath()
412
{
413
    return localSettings.project + "/__system";
414
}
112 andreas 415
 
71 andreas 416
string TConfig::getSystemPath(SYSTEMRESOURCE_t sres)
417
{
116 andreas 418
    DECL_TRACER("TConfig::getSystemPath(SYSTEMRESOURCE_t sres)");
419
 
71 andreas 420
    string p;
421
 
422
    switch(sres)
423
    {
424
        case BORDERS:   p = "/borders"; break;
425
        case FONTS:     p = "/fonts"; break;
426
        case IMAGES:    p = "/images"; break;
427
        case SLIDERS:   p = "/sliders"; break;
428
        case SOUNDS:    p = "/sounds"; break;
429
        default:
430
            p.clear();
431
    }
432
 
197 andreas 433
    return localSettings.project + "/__system/graphics" + p;
71 andreas 434
}
435
 
23 andreas 436
bool TConfig::saveLogFile(const string &file)
437
{
438
    DECL_TRACER("TConfig::saveLogFile(const string &file)");
439
 
192 andreas 440
    string logFile = mTemporary ? localSettings_temp.logFile : localSettings.logFile;
441
 
442
    if (file.empty() || logFile.compare(file) == 0)
23 andreas 443
        return false;
444
 
192 andreas 445
    if (mTemporary)
446
        localSettings_temp.logFile = file;
447
    else
448
        localSettings.logFile = file;
449
 
450
    mTemporary = false;
23 andreas 451
    return true;
452
}
453
 
454
bool TConfig::saveLogLevel(const string &level)
455
{
456
    DECL_TRACER("TConfig::saveLogLevel(const string &level)");
457
 
59 andreas 458
    if (level.find(SLOG_NONE) == string::npos && level.find(SLOG_INFO) == string::npos && level.find(SLOG_WARNING) == string::npos &&
459
            level.find(SLOG_ERROR) == string::npos && level.find(SLOG_TRACE) == string::npos && level.find(SLOG_DEBUG) == string::npos &&
460
            level.find(SLOG_PROTOCOL) == string::npos && level.find(SLOG_ALL) == string::npos)
23 andreas 461
        return false;
462
 
192 andreas 463
    if (mTemporary)
464
    {
465
        localSettings_temp.logLevel = level;
466
        localSettings_temp.logLevelBits = logLevelStrToBits(level);
467
    }
468
    else
469
    {
470
        localSettings.logLevel = level;
471
        localSettings.logLevelBits = logLevelStrToBits(level);
472
    }
473
 
59 andreas 474
    MSG_INFO("New log level: " << level);
192 andreas 475
    mTemporary = false;
23 andreas 476
    return true;
477
}
478
 
59 andreas 479
bool TConfig::saveLogLevel(uint level)
480
{
481
    DECL_TRACER("TConfig::saveLogLevel(uint level)");
482
 
483
    if (level != 0 && !(level&HLOG_INFO) && !(level&HLOG_WARNING) &&
484
            !(level&HLOG_ERROR) && !(level&HLOG_TRACE) && !(level&HLOG_DEBUG))
485
        return false;
486
 
192 andreas 487
    if (mTemporary)
488
    {
489
        localSettings_temp.logLevelBits = level;
490
        localSettings_temp.logLevel = logLevelBitsToString(level);
491
    }
492
    else
493
    {
494
        localSettings.logLevelBits = level;
495
        localSettings.logLevel = logLevelBitsToString(level);
496
        MSG_INFO("New log level from bits: " << localSettings.logLevel);
497
    }
498
 
499
    mTemporary = false;
59 andreas 500
    return true;
501
}
502
 
23 andreas 503
bool TConfig::saveChannel(int channel)
504
{
505
    DECL_TRACER("TConfig::saveChannel(int channel)");
506
 
271 andreas 507
    if (channel < 10000 || channel > 20000)
23 andreas 508
        return false;
509
 
192 andreas 510
    if (mTemporary)
511
        localSettings_temp.ID = channel;
512
    else
513
        localSettings.ID = channel;
514
 
515
    mTemporary = false;
23 andreas 516
    return true;
517
}
518
 
519
bool TConfig::saveController(const string &cnt)
520
{
521
    DECL_TRACER("TConfig::saveController(const string &cnt)");
522
 
192 andreas 523
    if (mTemporary)
524
        localSettings_temp.server = cnt;
525
    else
526
        localSettings.server = cnt;
527
 
528
    mTemporary = false;
23 andreas 529
    return true;
530
}
531
 
532
bool TConfig::savePanelType(const string &pt)
533
{
534
    DECL_TRACER("TConfig::savePanelType(const string &pt)");
535
 
192 andreas 536
    if (mTemporary)
537
        localSettings_temp.ptype = pt;
538
    else
539
        localSettings.ptype = pt;
540
 
541
    mTemporary = false;
23 andreas 542
    return true;
543
}
544
 
545
bool TConfig::savePort(int port)
546
{
547
    DECL_TRACER("TConfig::savePort(int port)");
548
 
549
    if (port < 1024 || port > 32767)
550
        return false;
551
 
192 andreas 552
    if (mTemporary)
553
        localSettings_temp.port = port;
554
    else
555
        localSettings.port = port;
556
 
557
    mTemporary = false;
23 andreas 558
    return true;
559
}
560
 
561
bool TConfig::saveProjectPath(const string &path)
562
{
563
    DECL_TRACER("TConfig::saveProjectPath(const string &path)");
564
 
565
    if (path.empty())
566
        return false;
567
 
192 andreas 568
    if (mTemporary)
569
        localSettings_temp.project = path;
570
    else
571
        localSettings.project = path;
572
 
573
    mTemporary = false;
23 andreas 574
    return true;
575
}
576
 
577
void TConfig::saveFormat(bool format)
578
{
192 andreas 579
    DECL_TRACER(string("TConfig::saveFormat(bool format) ") + (format ? "[TRUE]" : "[FALSE]"));
23 andreas 580
 
192 andreas 581
    if (mTemporary)
582
        localSettings_temp.longformat = format;
583
    else
584
        localSettings.longformat = format;
585
 
586
    mTemporary = false;
23 andreas 587
}
588
 
24 andreas 589
void TConfig::saveScale(bool scale)
590
{
591
    DECL_TRACER("TConfig::saveScale(bool scale)");
592
 
192 andreas 593
    if (mTemporary)
594
        localSettings_temp.scale = scale;
595
    else
596
        localSettings.scale = scale;
597
 
598
    mTemporary = false;
24 andreas 599
}
600
 
118 andreas 601
void TConfig::saveBanner(bool banner)
602
{
603
    DECL_TRACER("TConfig::saveBanner(bool banner)");
604
 
192 andreas 605
    if (mTemporary)
606
        localSettings_temp.noBanner = banner;
607
    else
608
        localSettings.noBanner = banner;
609
 
610
    mTemporary = false;
118 andreas 611
}
612
 
120 andreas 613
void TConfig::saveToolbarForce(bool tb)
614
{
615
    DECL_TRACER("TConfig::saveToolbarForce(bool tb)");
616
 
192 andreas 617
    if (mTemporary)
618
        localSettings_temp.tbforce = tb;
619
    else
620
        localSettings.tbforce = tb;
621
 
622
    mTemporary = false;
120 andreas 623
}
624
 
151 andreas 625
void TConfig::saveToolbarSuppress(bool tb)
626
{
627
    DECL_TRACER("TConfig::saveToolbarSuppress(bool tb)");
628
 
192 andreas 629
    if (mTemporary)
630
        localSettings_temp.tbsuppress = tb;
631
    else
632
        localSettings.tbsuppress = tb;
633
 
634
    mTemporary = false;
151 andreas 635
}
636
 
35 andreas 637
void TConfig::saveProfiling(bool prof)
638
{
116 andreas 639
    DECL_TRACER("TConfig::saveProfiling(bool prof)");
640
 
192 andreas 641
    if (mTemporary)
642
        localSettings_temp.profiling = prof;
643
    else
644
        localSettings.profiling = prof;
645
 
646
    mTemporary = false;
35 andreas 647
}
648
 
175 andreas 649
void TConfig::saveButtonCache(size_t size)
650
{
651
    DECL_TRACER("TConfig::saveButtonCache(size_t size)");
652
 
192 andreas 653
    if (mTemporary)
654
        localSettings_temp.max_cache = size;
655
    else
656
        localSettings.max_cache = size;
657
 
658
    mTemporary = false;
175 andreas 659
}
660
 
51 andreas 661
void TConfig::savePassword1(const std::string& pw)
662
{
116 andreas 663
    DECL_TRACER("TConfig::savePassword1(const std::string& pw)");
664
 
192 andreas 665
    if (mTemporary)
666
        localSettings_temp.password1 = pw;
667
    else
668
        localSettings.password1 = pw;
669
 
670
    mTemporary = false;
51 andreas 671
}
672
 
673
void TConfig::savePassword2(const std::string& pw)
674
{
116 andreas 675
    DECL_TRACER("TConfig::savePassword2(const std::string& pw)");
676
 
192 andreas 677
    if (mTemporary)
678
        localSettings_temp.password2 = pw;
679
    else
680
        localSettings.password2 = pw;
681
 
682
    mTemporary = false;
51 andreas 683
}
684
 
685
void TConfig::savePassword3(const std::string& pw)
686
{
116 andreas 687
    DECL_TRACER("TConfig::savePassword3(const std::string& pw)");
688
 
192 andreas 689
    if (mTemporary)
690
        localSettings_temp.password3 = pw;
691
    else
692
        localSettings.password3 = pw;
693
 
694
    mTemporary = false;
51 andreas 695
}
696
 
697
void TConfig::savePassword4(const std::string& pw)
698
{
116 andreas 699
    DECL_TRACER("TConfig::savePassword4(const std::string& pw)");
700
 
192 andreas 701
    if (mTemporary)
702
        localSettings_temp.password4 = pw;
703
    else
704
        localSettings.password4 = pw;
705
 
706
    mTemporary = false;
51 andreas 707
}
708
 
71 andreas 709
void TConfig::saveSystemSoundFile(const std::string& snd)
710
{
116 andreas 711
    DECL_TRACER("TConfig::saveSystemSoundFile(const std::string& snd)");
712
 
192 andreas 713
    if (mTemporary)
714
        localSettings_temp.systemSound = snd;
715
    else
716
        localSettings.systemSound = snd;
717
 
718
    mTemporary = false;
71 andreas 719
}
720
 
721
void TConfig::saveSystemSoundState(bool state)
722
{
116 andreas 723
    DECL_TRACER("TConfig::saveSystemSoundState(bool state)");
724
 
192 andreas 725
    if (mTemporary)
726
        localSettings_temp.systemSoundState = state;
727
    else
195 andreas 728
        localSettings.systemSoundState = localSettings_temp.systemSoundState = state;
192 andreas 729
 
730
    mTemporary = false;
71 andreas 731
}
732
 
141 andreas 733
void TConfig::saveSingleBeepFile(const std::string& snd)
734
{
735
    DECL_TRACER("TConfig::saveSingleBeepFile(const std::string& snd)");
736
 
192 andreas 737
    if (mTemporary)
738
        localSettings_temp.systemSingleBeep = snd;
739
    else
740
        localSettings.systemSingleBeep = snd;
741
 
742
    mTemporary = false;
141 andreas 743
}
744
 
745
void TConfig::saveDoubleBeepFile(const std::string& snd)
746
{
747
    DECL_TRACER("TConfig::saveDoubleBeepFile(const std::string& snd)");
748
 
192 andreas 749
    if (mTemporary)
750
        localSettings_temp.systemDoubleBeep = snd;
751
    else
752
        localSettings.systemDoubleBeep = snd;
753
 
754
    mTemporary = false;
141 andreas 755
}
756
 
757
void TConfig::saveSystemVolume(int volume)
758
{
759
    DECL_TRACER("TConfig::saveSystemVolume(int volume)");
760
 
761
    if (volume < 0 || volume > 100)
762
        return;
763
 
192 andreas 764
    if (mTemporary)
765
        localSettings_temp.systemVolume = volume;
766
    else
767
        localSettings.systemVolume = volume;
768
 
769
    mTemporary = false;
141 andreas 770
}
771
 
772
void TConfig::saveSystemGain(int gain)
773
{
774
    DECL_TRACER("TConfig::saveSystemGain(int gain)");
775
 
776
    if (gain < 0 || gain > 100)
777
        return;
778
 
192 andreas 779
    if (mTemporary)
780
        localSettings_temp.systemGain = gain;
781
    else
782
        localSettings.systemGain = gain;
783
 
784
    mTemporary = false;
141 andreas 785
}
786
 
112 andreas 787
void TConfig::saveFtpUser(const string& user)
788
{
116 andreas 789
    DECL_TRACER("TConfig::saveFtpUser(const string& user)");
790
 
192 andreas 791
    if (mTemporary)
792
        localSettings_temp.ftpUser = user;
793
    else
794
        localSettings.ftpUser = user;
795
 
796
    mTemporary = false;
112 andreas 797
}
798
 
799
void TConfig::saveFtpPassword(const string& pw)
800
{
116 andreas 801
    DECL_TRACER("TConfig::saveFtpPassword(const string& pw)");
802
 
192 andreas 803
    if (mTemporary)
804
        localSettings_temp.ftpPassword = pw;
805
    else
806
        localSettings.ftpPassword = pw;
807
 
808
    mTemporary = false;
112 andreas 809
}
810
 
115 andreas 811
void TConfig::saveFtpSurface(const string& fname)
812
{
116 andreas 813
    DECL_TRACER("TConfig::saveFtpSurface(const string& fname)");
814
 
192 andreas 815
    if (mTemporary)
816
        localSettings_temp.ftpSurface = fname;
817
    else
818
        localSettings.ftpSurface = fname;
819
 
820
    mTemporary = false;
115 andreas 821
}
822
 
116 andreas 823
void TConfig::saveFtpPassive(bool mode)
824
{
825
    DECL_TRACER("TConfig::saveFtpPassive(bool mode)");
826
 
192 andreas 827
    if (mTemporary)
828
        localSettings_temp.ftpPassive = mode;
829
    else
830
        localSettings.ftpPassive = mode;
831
 
832
    mTemporary = false;
116 andreas 833
}
834
 
115 andreas 835
void TConfig::saveFtpDownloadTime(time_t t)
836
{
116 andreas 837
    DECL_TRACER("TConfig::saveFtpDownloadTime(time_t t)");
838
 
192 andreas 839
    if (mTemporary)
840
        localSettings_temp.ftpLastDownload = t;
841
    else
842
        localSettings.ftpLastDownload = t;
843
 
844
    mTemporary = false;
115 andreas 845
}
846
 
104 andreas 847
std::string& TConfig::getSIPproxy()
848
{
116 andreas 849
    DECL_TRACER("TConfig::getSIPproxy()");
850
 
192 andreas 851
    return mTemporary ? localSettings_temp.sip_proxy : localSettings.sip_proxy;
104 andreas 852
}
853
 
854
void TConfig::setSIPproxy(const std::string& address)
855
{
116 andreas 856
    DECL_TRACER("TConfig::setSIPproxy(const std::string& address)");
857
 
192 andreas 858
    if (mTemporary)
859
        localSettings_temp.sip_proxy = address;
860
    else
861
        localSettings.sip_proxy = address;
862
 
863
    mTemporary = false;
104 andreas 864
}
865
 
866
int TConfig::getSIPport()
867
{
116 andreas 868
    DECL_TRACER("TConfig::getSIPport()");
869
 
192 andreas 870
    return mTemporary ? localSettings_temp.sip_port : localSettings.sip_port;
104 andreas 871
}
872
 
873
void TConfig::setSIPport(int port)
874
{
116 andreas 875
    DECL_TRACER("TConfig::setSIPport(int port)");
876
 
192 andreas 877
    if (mTemporary)
878
        localSettings_temp.sip_port = port;
879
    else
880
        localSettings.sip_port = port;
881
 
882
    mTemporary = false;
104 andreas 883
}
884
 
127 andreas 885
int TConfig::getSIPportTLS()
886
{
887
    DECL_TRACER("TConfig::getSIPportTLS()");
888
 
192 andreas 889
    return mTemporary ? localSettings_temp.sip_portTLS : localSettings.sip_portTLS;
127 andreas 890
}
891
 
892
void TConfig::setSIPportTLS(int port)
893
{
894
    DECL_TRACER("TConfig::setSIPportTLS(int port)");
895
 
192 andreas 896
    if (mTemporary)
897
        localSettings_temp.sip_portTLS = port;
898
    else
899
        localSettings.sip_portTLS = port;
900
 
901
    mTemporary = false;
127 andreas 902
}
903
 
104 andreas 904
std::string& TConfig::getSIPstun()
905
{
116 andreas 906
    DECL_TRACER("TConfig::getSIPstun()");
907
 
192 andreas 908
    return mTemporary ? localSettings_temp.sip_stun : localSettings.sip_stun;
104 andreas 909
}
910
 
911
void TConfig::setSIPstun(const std::string& address)
912
{
116 andreas 913
    DECL_TRACER("TConfig::setSIPstun(const std::string& address)");
914
 
192 andreas 915
    if (mTemporary)
916
        localSettings_temp.sip_stun = address;
917
    else
918
        localSettings.sip_stun = address;
919
 
920
    mTemporary = false;
104 andreas 921
}
922
 
923
std::string& TConfig::getSIPdomain()
924
{
116 andreas 925
    DECL_TRACER("TConfig::getSIPdomain()");
926
 
192 andreas 927
    return mTemporary ? localSettings_temp.sip_domain : localSettings.sip_domain;
104 andreas 928
}
929
 
930
void TConfig::setSIPdomain(const std::string& domain)
931
{
116 andreas 932
    DECL_TRACER("TConfig::setSIPdomain(const std::string& domain)");
933
 
192 andreas 934
    if (mTemporary)
935
        localSettings_temp.sip_domain = domain;
936
    else
937
        localSettings.sip_domain = domain;
938
 
939
    mTemporary = false;
104 andreas 940
}
941
 
942
std::string& TConfig::getSIPuser()
943
{
116 andreas 944
    DECL_TRACER("TConfig::getSIPuser()");
945
 
192 andreas 946
    return mTemporary ? localSettings_temp.sip_user : localSettings.sip_user;
104 andreas 947
}
948
 
949
void TConfig::setSIPuser(const std::string& user)
950
{
116 andreas 951
    DECL_TRACER("TConfig::setSIPuser(const std::string& user)");
952
 
192 andreas 953
    if (mTemporary)
954
        localSettings_temp.sip_user = user;
955
    else
956
        localSettings.sip_user = user;
957
 
958
    mTemporary = false;
104 andreas 959
}
960
 
961
std::string& TConfig::getSIPpassword()
962
{
116 andreas 963
    DECL_TRACER("TConfig::getSIPpassword()");
964
 
192 andreas 965
    return mTemporary ? localSettings_temp.sip_password : localSettings.sip_password;
104 andreas 966
}
967
 
968
void TConfig::setSIPpassword(const std::string& pw)
969
{
116 andreas 970
    DECL_TRACER("TConfig::setSIPpassword(const std::string& pw)");
971
 
192 andreas 972
    if (mTemporary)
973
        localSettings_temp.sip_password = pw;
974
    else
975
        localSettings.sip_password = pw;
976
 
977
    mTemporary = false;
104 andreas 978
}
979
 
980
bool TConfig::getSIPstatus()
981
{
116 andreas 982
    DECL_TRACER("TConfig::getSIPstatus()");
983
 
192 andreas 984
    return mTemporary ? localSettings_temp.sip_enabled : localSettings.sip_enabled;
104 andreas 985
}
986
 
127 andreas 987
bool TConfig::getSIPnetworkIPv4()
988
{
989
    DECL_TRACER("TConfig::getSIPnetworkIPv4()");
990
 
192 andreas 991
    return mTemporary ? localSettings_temp.sip_ipv4 : localSettings.sip_ipv4;
127 andreas 992
}
993
 
994
void TConfig::setSIPnetworkIPv4(bool state)
995
{
996
    DECL_TRACER("TConfig::setSIPnetworkIPv4(bool state)");
997
 
192 andreas 998
    if (mTemporary)
999
        localSettings_temp.sip_ipv4 = state;
1000
    else
1001
        localSettings.sip_ipv4 = state;
1002
 
1003
    mTemporary = false;
127 andreas 1004
}
1005
 
1006
bool TConfig::getSIPnetworkIPv6()
1007
{
1008
    DECL_TRACER("TConfig::getSIPnetworkIPv6()");
1009
 
192 andreas 1010
    return mTemporary ? localSettings_temp.sip_ipv6 : localSettings.sip_ipv6;
127 andreas 1011
}
1012
 
1013
void TConfig::setSIPnetworkIPv6(bool state)
1014
{
1015
    DECL_TRACER("TConfig::setSIPnetworkIPv6(bool state)");
1016
 
192 andreas 1017
    if (mTemporary)
1018
        localSettings_temp.sip_ipv6 = state;
1019
    else
1020
        localSettings.sip_ipv6 = state;
1021
 
1022
    mTemporary = false;
127 andreas 1023
}
1024
 
139 andreas 1025
void TConfig::setSIPiphone(bool state)
1026
{
1027
    DECL_TRACER("TConfig::setSIPiphone(bool state)");
1028
 
192 andreas 1029
    if (mTemporary)
1030
        localSettings_temp.sip_iphone = state;
1031
    else
1032
        localSettings.sip_iphone = state;
1033
 
1034
    mTemporary = false;
139 andreas 1035
}
1036
 
1037
bool TConfig::getSIPiphone()
1038
{
1039
    DECL_TRACER("TConfig::getSIPiphone()");
1040
 
192 andreas 1041
    return mTemporary ? localSettings_temp.sip_iphone : localSettings.sip_iphone;
139 andreas 1042
}
1043
 
127 andreas 1044
TConfig::SIP_FIREWALL_t TConfig::getSIPfirewall()
1045
{
1046
    DECL_TRACER("TConfig::getSIPfirewall()");
1047
 
192 andreas 1048
    return mTemporary ? localSettings_temp.sip_firewall : localSettings.sip_firewall;
127 andreas 1049
}
1050
 
1051
string TConfig::getSIPfirewallStr()
1052
{
1053
    DECL_TRACER("TConfig::getSIPfirewallStr()");
1054
 
192 andreas 1055
    return sipFirewallToString(mTemporary ? localSettings_temp.sip_firewall : localSettings.sip_firewall);
127 andreas 1056
}
1057
 
1058
void TConfig::setSIPfirewall(TConfig::SIP_FIREWALL_t fw)
1059
{
1060
    DECL_TRACER("TConfig::setSIPfirewall(TConfig::SIP_FIREWALL_t fw)")
1061
 
192 andreas 1062
    if (mTemporary)
1063
        localSettings_temp.sip_firewall = fw;
1064
    else
1065
        localSettings.sip_firewall = fw;
1066
 
1067
    mTemporary = false;
127 andreas 1068
}
1069
 
104 andreas 1070
void TConfig::setSIPstatus(bool state)
1071
{
116 andreas 1072
    DECL_TRACER("TConfig::setSIPstatus(bool state)");
1073
 
192 andreas 1074
    if (mTemporary)
1075
        localSettings_temp.sip_enabled = state;
1076
    else
1077
        localSettings.sip_enabled = state;
1078
 
1079
    mTemporary = false;
104 andreas 1080
}
1081
 
23 andreas 1082
bool TConfig::saveSettings()
1083
{
1084
    DECL_TRACER("TConfig::saveSettings()");
1085
 
292 andreas 1086
    TLock<std::mutex> guard(config_mutex);
1087
 
23 andreas 1088
    try
1089
    {
1090
        string fname = localSettings.path + "/" + localSettings.name;
192 andreas 1091
 
1092
        if (mTemporary)
1093
        {
1094
            localSettings = localSettings_temp;
1095
            MSG_INFO("Temporary settings were copied over.");
1096
        }
1097
 
1098
        MSG_DEBUG("Saving to file " << fname);
23 andreas 1099
        ofstream file(fname);
1100
        string lines = "LogFile=" + localSettings.logFile + "\n";
1101
        lines += "LogLevel=" + localSettings.logLevel + "\n";
1102
        lines += "ProjectPath=" + localSettings.project + "\n";
1103
        lines += string("NoBanner=") + (localSettings.noBanner ? "true" : "false") + "\n";
151 andreas 1104
        lines += string("ToolbarSuppress=") + (localSettings.tbsuppress ? "true" : "false") + "\n";
120 andreas 1105
        lines += string("ToolbarForce=") + (localSettings.tbforce ? "true" : "false") + "\n";
23 andreas 1106
        lines += string("LongFormat=") + (localSettings.longformat ? "true" : "false") + "\n";
1107
        lines += "Address=" + localSettings.server + "\n";
1108
        lines += "Port=" + std::to_string(localSettings.port) + "\n";
1109
        lines += "Channel=" + std::to_string(localSettings.ID) + "\n";
1110
        lines += "System=" + std::to_string(localSettings.system) + "\n";
1111
        lines += "PanelType=" + localSettings.ptype + "\n";
1112
        lines += "Firmware=" + localSettings.version + "\n";
1113
        lines += string("CertCheck=") + (localSettings.certCheck ? "true" : "false") + "\n";
24 andreas 1114
        lines += string("Scale=") + (localSettings.scale ? "true" : "false") + "\n";
35 andreas 1115
        lines += string("Profiling=") + (localSettings.profiling ? "true" : "false") + "\n";
175 andreas 1116
        lines += "MaxButtonCache=" + std::to_string(localSettings.max_cache) + "\n";
51 andreas 1117
        lines += string("Password1=") + localSettings.password1 + "\n";
1118
        lines += string("Password2=") + localSettings.password2 + "\n";
1119
        lines += string("Password3=") + localSettings.password3 + "\n";
1120
        lines += string("Password4=") + localSettings.password4 + "\n";
71 andreas 1121
        lines += string("SystemSoundFile=") + localSettings.systemSound + "\n";
1122
        lines += string("SystemSoundState=") + (localSettings.systemSoundState ? "ON" : "OFF") + "\n";
1123
        lines += string("SystemSingleBeep=") + localSettings.systemSingleBeep + "\n";
1124
        lines += string("SystemDoubleBeep=") + localSettings.systemDoubleBeep + "\n";
141 andreas 1125
        lines += "SystemVolume=" + std::to_string(localSettings.systemVolume) + "\n";
1126
        lines += "SystemGain=" + std::to_string(localSettings.systemGain) + "\n";
134 andreas 1127
        lines += string("SystemRotationFix=") + (localSettings.systemRotationFix ? "ON" : "OFF") + "\n";
1128
        lines += string("UUID=") + localSettings.uuid + "\n";
112 andreas 1129
        // FTP credentials
1130
        lines += string("FTPuser=") + localSettings.ftpUser + "\n";
1131
        lines += string("FTPpassword=") + localSettings.ftpPassword + "\n";
115 andreas 1132
        lines += string("FTPsurface=") + localSettings.ftpSurface + "\n";
116 andreas 1133
        lines += string("FTPpassive=") + (localSettings.ftpPassive ? "true" : "false") + "\n";
115 andreas 1134
        lines += string("FTPdownloadTime=") + std::to_string(localSettings.ftpLastDownload) + "\n";
104 andreas 1135
        // SIP settings
116 andreas 1136
        lines += string("SIP_DOMAIN=") + localSettings.sip_domain + "\n";
127 andreas 1137
        lines += string("SIP_PROXY=") + localSettings.sip_proxy + "\n";
116 andreas 1138
        lines += string("SIP_PORT=") + std::to_string(localSettings.sip_port) + "\n";
127 andreas 1139
        lines += string("SIP_PORTTLS=") + std::to_string(localSettings.sip_portTLS) + "\n";
116 andreas 1140
        lines += string("SIP_STUN=") + localSettings.sip_stun + "\n";
1141
        lines += string("SIP_USER=") + localSettings.sip_user + "\n";
1142
        lines += string("SIP_PASSWORD=") + localSettings.sip_password + "\n";
127 andreas 1143
        lines += string("SIP_IPV4=") + (localSettings.sip_ipv4 ? "true" : "false") + "\n";
1144
        lines += string("SIP_IPV6=") + (localSettings.sip_ipv6 ? "true" : "false") + "\n";
139 andreas 1145
        lines += string("SIP_IPHONE=") + (localSettings.sip_iphone ? "true" : "false") + "\n";
127 andreas 1146
        lines += "SIP_FIREWALL=" + sipFirewallToString(localSettings.sip_firewall) + "\n";
116 andreas 1147
        lines += string("SIP_ENABLED=") + (localSettings.sip_enabled ? "true" : "false") + "\n";
23 andreas 1148
        file.write(lines.c_str(), lines.size());
1149
        file.close();
59 andreas 1150
        MSG_INFO("Actual log level: " << localSettings.logLevel);
214 andreas 1151
 
1152
        if (mTemporary)
1153
        {
1154
            TError::Current()->setLogLevel(localSettings.logLevel);
1155
            TError::Current()->setLogFile(localSettings.logFile);
1156
        }
1157
 
1158
        mTemporary = false;
23 andreas 1159
    }
1160
    catch (std::exception& e)
1161
    {
1162
        MSG_ERROR("Couldn't write configs: " << e.what());
1163
        return false;
1164
    }
1165
 
1166
    return true;
1167
}
1168
 
21 andreas 1169
/**
1170
 * @brief TConfig::isLongFormat defines the format in the logfile.
1171
 *
1172
 * If this returns `true` the format in the logfile is a long format. This
1173
 * means, that in front of each message is an additional timestamp.
1174
 *
1175
 * @return `true` = long format, `false` = short format (default).
1176
 */
2 andreas 1177
bool TConfig::isLongFormat()
1178
{
192 andreas 1179
    return mTemporary ? localSettings_temp.longformat : localSettings.longformat;
2 andreas 1180
}
1181
 
21 andreas 1182
/**
1183
 * @brief TConfig::showBanner defines whether the banner should be showed or not.
1184
 *
1185
 * If this method returns `false` the banner on startup is not displayed.
1186
 *
1187
 * @return `true` = display the banner (default), `false` = show no banner.
1188
 */
2 andreas 1189
bool TConfig::showBanner()
1190
{
116 andreas 1191
    DECL_TRACER("TConfig::showBanner()");
1192
 
192 andreas 1193
    return mTemporary ? (!localSettings_temp.noBanner) : (!localSettings.noBanner);
2 andreas 1194
}
1195
 
21 andreas 1196
/**
24 andreas 1197
 * @brief TConfig::getScale returns the scale setting
1198
 *
1199
 * If this is set to TRUE, all images are scaled to fit the screen.
1200
 *
1201
 * @return scale state
1202
 */
1203
bool TConfig::getScale()
1204
{
116 andreas 1205
    DECL_TRACER("TConfig::getScale()");
1206
 
192 andreas 1207
    return mTemporary ? localSettings_temp.scale : localSettings.scale;
24 andreas 1208
}
1209
 
120 andreas 1210
bool TConfig::getToolbarForce()
1211
{
1212
    DECL_TRACER("TConfig::getToolbarForce()");
1213
 
192 andreas 1214
    return mTemporary ? localSettings_temp.tbforce : localSettings.tbforce;
120 andreas 1215
}
1216
 
151 andreas 1217
bool TConfig::getToolbarSuppress()
1218
{
1219
    DECL_TRACER("TConfig::getToolbarSuppress()");
1220
 
192 andreas 1221
    return mTemporary ? localSettings_temp.tbsuppress : localSettings.tbsuppress;
151 andreas 1222
}
1223
 
35 andreas 1224
bool TConfig::getProfiling()
1225
{
192 andreas 1226
    return mTemporary ? localSettings_temp.profiling : localSettings.profiling;
35 andreas 1227
}
1228
 
175 andreas 1229
size_t TConfig::getButttonCache()
1230
{
192 andreas 1231
    if (mTemporary && localSettings_temp.max_cache > 0)
1232
        return localSettings_temp.max_cache;
1233
 
1234
    if (!mTemporary && localSettings.max_cache > 0)
177 andreas 1235
        return localSettings.max_cache * 1000 * 1000;
1236
 
1237
    return 0;
175 andreas 1238
}
1239
 
51 andreas 1240
string & TConfig::getPassword1()
1241
{
116 andreas 1242
    DECL_TRACER("TConfig::getPassword1()");
1243
 
192 andreas 1244
    return mTemporary ? localSettings_temp.password1 : localSettings.password1;
51 andreas 1245
}
1246
 
1247
string & TConfig::getPassword2()
1248
{
116 andreas 1249
    DECL_TRACER("TConfig::getPassword2()");
1250
 
192 andreas 1251
    return mTemporary ? localSettings_temp.password2 : localSettings.password2;
51 andreas 1252
}
1253
 
1254
string & TConfig::getPassword3()
1255
{
116 andreas 1256
    DECL_TRACER("TConfig::getPassword3()");
1257
 
192 andreas 1258
    return mTemporary ? localSettings_temp.password3 : localSettings.password3;
51 andreas 1259
}
1260
 
1261
string & TConfig::getPassword4()
1262
{
116 andreas 1263
    DECL_TRACER("TConfig::getPassword4()");
1264
 
192 andreas 1265
    return mTemporary ? localSettings_temp.password4 : localSettings.password4;
51 andreas 1266
}
1267
 
71 andreas 1268
string & TConfig::getSystemSound()
1269
{
116 andreas 1270
    DECL_TRACER("TConfig::getSystemSound()");
1271
 
192 andreas 1272
    return mTemporary ? localSettings_temp.systemSound : localSettings.systemSound;
71 andreas 1273
}
1274
 
1275
bool TConfig::getSystemSoundState()
1276
{
116 andreas 1277
    DECL_TRACER("TConfig::getSystemSoundState()");
1278
 
192 andreas 1279
    return mTemporary ? localSettings_temp.systemSoundState : localSettings.systemSoundState;
71 andreas 1280
}
1281
 
141 andreas 1282
int TConfig::getSystemVolume()
1283
{
1284
    DECL_TRACER("TConfig::getSystemVolume()");
1285
 
192 andreas 1286
    return mTemporary ? localSettings_temp.systemVolume : localSettings.systemVolume;
141 andreas 1287
}
1288
 
1289
int TConfig::getSystemGain()
1290
{
1291
    DECL_TRACER("TConfig::getSystemGain()");
1292
 
192 andreas 1293
    return mTemporary ? localSettings_temp.systemGain : localSettings.systemGain;
141 andreas 1294
}
1295
 
134 andreas 1296
bool TConfig::getRotationFixed()
1297
{
1298
    DECL_TRACER("TConfig::getRotationFixed()");
1299
 
192 andreas 1300
    return mTemporary ? localSettings_temp.systemRotationFix : localSettings.systemRotationFix;
134 andreas 1301
}
1302
 
1303
void TConfig::setRotationFixed(bool fix)
1304
{
1305
    DECL_TRACER("TConfig::setRotationFixed(bool fix)");
1306
 
192 andreas 1307
    if (mTemporary)
1308
        localSettings_temp.systemRotationFix = fix;
1309
    else
1310
        localSettings.systemRotationFix = fix;
1311
 
1312
    mTemporary = false;
134 andreas 1313
}
1314
 
1315
void TConfig::setSystemChannel(int ch)
1316
{
1317
    DECL_TRACER("TConfig::setSystemChannel(int ch)");
1318
 
1319
    if (ch >= 10000 && ch < 30000)
1320
        mChannel = ch;
1321
}
1322
 
71 andreas 1323
string& TConfig::getSingleBeepSound()
1324
{
116 andreas 1325
    DECL_TRACER("TConfig::getSingleBeepSound()");
1326
 
192 andreas 1327
    return mTemporary ? localSettings_temp.systemSingleBeep : localSettings.systemSingleBeep;
71 andreas 1328
}
1329
 
1330
string& TConfig::getDoubleBeepSound()
1331
{
116 andreas 1332
    DECL_TRACER("TConfig::getDoubleBeepSound()");
1333
 
192 andreas 1334
    return mTemporary ? localSettings_temp.systemDoubleBeep : localSettings.systemDoubleBeep;
71 andreas 1335
}
1336
 
134 andreas 1337
string& TConfig::getUUID()
1338
{
1339
    DECL_TRACER("TConfig::getUUID()");
1340
 
192 andreas 1341
    return mTemporary ? localSettings_temp.uuid : localSettings.uuid;
134 andreas 1342
}
1343
 
112 andreas 1344
string& TConfig::getFtpUser()
1345
{
116 andreas 1346
    DECL_TRACER("TConfig::getFtpUser()");
1347
 
192 andreas 1348
    return mTemporary ? localSettings_temp.ftpUser : localSettings.ftpUser;
112 andreas 1349
}
1350
 
1351
string& TConfig::getFtpPassword()
1352
{
116 andreas 1353
    DECL_TRACER("TConfig::getFtpPassword()");
1354
 
192 andreas 1355
    return mTemporary ? localSettings_temp.ftpPassword : localSettings.ftpPassword;
112 andreas 1356
}
1357
 
115 andreas 1358
string& TConfig::getFtpSurface()
1359
{
116 andreas 1360
    DECL_TRACER("TConfig::getFtpSurface()");
1361
 
192 andreas 1362
    return mTemporary ? localSettings_temp.ftpSurface : localSettings.ftpSurface;
115 andreas 1363
}
1364
 
116 andreas 1365
bool TConfig::getFtpPassive()
1366
{
1367
    DECL_TRACER("TConfig::getFtpPassive()");
1368
 
192 andreas 1369
    return mTemporary ? localSettings_temp.ftpPassive : localSettings.ftpPassive;
116 andreas 1370
}
1371
 
115 andreas 1372
time_t TConfig::getFtpDownloadTime()
1373
{
116 andreas 1374
    DECL_TRACER("TConfig::getFtpDownloadTime()");
1375
 
192 andreas 1376
    return mTemporary ? localSettings_temp.ftpLastDownload : localSettings.ftpLastDownload;
115 andreas 1377
}
1378
 
24 andreas 1379
/**
21 andreas 1380
 * @brief TConfig::certCheck check the certificate if the connection is encrypted.
1381
 *
1382
 * Currently not implemented!
1383
 *
1384
 * @return `true` = check the certificate, `false` = accept any certificate (default).
1385
 */
1386
bool TConfig::certCheck()
1387
{
192 andreas 1388
    return mTemporary ? localSettings_temp.certCheck : localSettings.certCheck;
21 andreas 1389
}
1390
 
1391
/**
59 andreas 1392
 * @brief TConfig::logLevelStrToBits
1393
 * Converts a string containing one or more loglevels into a bit field.
1394
 * @param level A string containing the log levels
1395
 * @return A bit field representing the log levels.
1396
 */
1397
uint TConfig::logLevelStrToBits(const string& level)
1398
{
1399
    uint l = 0;
1400
 
1401
    if (level.find("INFO") != string::npos)
1402
        l |= HLOG_INFO;
1403
 
1404
    if (level.find("WARNING") != string::npos)
1405
        l |= HLOG_WARNING;
1406
 
1407
    if (level.find("ERROR") != string::npos)
1408
        l |= HLOG_ERROR;
1409
 
1410
    if (level.find("TRACE") != string::npos)
1411
        l |= HLOG_TRACE;
1412
 
1413
    if (level.find("DEBUG") != string::npos)
1414
        l |= HLOG_DEBUG;
1415
 
1416
    if (level.find("PROTOCOL") != string::npos)
71 andreas 1417
        l |= HLOG_PROTOCOL;
59 andreas 1418
 
1419
    if (level.find("ALL") != string::npos)
1420
        l = HLOG_ALL;
1421
 
1422
    return l;
1423
}
1424
 
1425
string TConfig::logLevelBitsToString(uint level)
1426
{
1427
    string l;
1428
 
1429
    if (level == 0)
1430
    {
1431
        l = SLOG_NONE;
1432
        return l;
1433
    }
1434
 
1435
    if (level & HLOG_INFO)
1436
    {
1437
        if (l.length() > 0)
1438
            l.append("|");
1439
 
1440
        l.append(SLOG_INFO);
1441
    }
1442
 
1443
    if (level & HLOG_WARNING)
1444
    {
1445
        if (l.length() > 0)
1446
            l.append("|");
1447
 
1448
        l.append(SLOG_WARNING);
1449
    }
1450
 
1451
    if (level & HLOG_ERROR)
1452
    {
1453
        if (l.length() > 0)
1454
            l.append("|");
1455
 
1456
        l.append(SLOG_ERROR);
1457
    }
1458
 
1459
    if (level & HLOG_TRACE)
1460
    {
1461
        if (l.length() > 0)
1462
            l.append("|");
1463
 
1464
        l.append(SLOG_TRACE);
1465
    }
1466
 
1467
    if (level & HLOG_DEBUG)
1468
    {
1469
        if (l.length() > 0)
1470
            l.append("|");
1471
 
1472
        l.append(SLOG_DEBUG);
1473
    }
1474
 
1475
    return l;
1476
}
118 andreas 1477
 
127 andreas 1478
string TConfig::sipFirewallToString(TConfig::SIP_FIREWALL_t fw)
1479
{
1480
    switch(fw)
1481
    {
1482
        case SIP_NO_FIREWALL:   return "SIP_NO_FIREWALL";
1483
        case SIP_NAT_ADDRESS:   return "SIP_NAT_ADDRESS";
1484
        case SIP_STUN:          return "SIP_STUN";
1485
        case SIP_ICE:           return "SIP_ICE";
1486
        case SIP_UPNP:          return "SIP_UPNP";
1487
    }
140 andreas 1488
 
1489
    return string();
127 andreas 1490
}
1491
 
1492
TConfig::SIP_FIREWALL_t TConfig::sipFirewallStrToEnum(const std::string& str)
1493
{
1494
    if (strCaseCompare(str, "SIP_NO_FIREWALL") == 0)
1495
        return SIP_NO_FIREWALL;
1496
    else if (strCaseCompare(str, "SIP_NAT_ADDRESS") == 0)
1497
        return SIP_NAT_ADDRESS;
1498
    else if (strCaseCompare(str, "SIP_STUN") == 0)
1499
        return SIP_STUN;
1500
    else if (strCaseCompare(str, "SIP_ICE") == 0)
1501
        return SIP_ICE;
1502
    else if (strCaseCompare(str, "SIP_UPNP") == 0)
1503
        return SIP_UPNP;
1504
 
1505
    return SIP_NO_FIREWALL;
1506
}
1507
 
118 andreas 1508
string TConfig::makeConfigDefault(const std::string& log, const std::string& project)
1509
{
1510
    string content = "LogFile=" + log + "\n";
260 andreas 1511
#if defined(QT_DEBUG) || defined(DEBUG)
1512
    content += "LogLevel=INFO|WARNING|ERROR|DEBUG\n";
131 andreas 1513
#else
1514
    content += "LogLevel=NONE\n";
1515
#endif
118 andreas 1516
    content += "ProjectPath=" + project + "\n";
1517
    content += "LongFormat=false\n";
1518
    content += "Address=0.0.0.0\n";
1519
    content += "Port=1319\n";
1520
    content += "Channel=10001\n";
1521
    content += "PanelType=Android\n";
1522
    content += string("Firmware=") + VERSION_STRING() + "\n";
1523
    content += "Scale=true\n";
134 andreas 1524
    content += "ToolbarForce=true\n";
118 andreas 1525
    content += "Profiling=false\n";
1526
    content += "Password1=1988\n";
1527
    content += "Password2=1988\n";
1528
    content += "Password3=1988\n";
1529
    content += "Password4=1988\n";
1530
    content += "SystemSoundFile=singleBeep.wav\n";
1531
    content += "SystemSoundState=ON\n";
1532
    content += "SystemSingleBeep=singleBeep01.wav\n";
1533
    content += "SystemDoubleBeep=doubleBeep01.wav\n";
134 andreas 1534
    content += "SystemRotationFix=" + string(localSettings.systemRotationFix ? "TRUE" : "FALSE") + "\n";
1535
    content += "UUID=" + localSettings.uuid + "\n";
118 andreas 1536
    content += "FTPuser=administrator\n";
1537
    content += "FTPpassword=password\n";
1538
    content += "FTPsurface=tpanel.tp4\n";
1539
    content += "FTPpassive=true\n";
1540
    content += "FTPdownloadTime=0\n";
127 andreas 1541
    content += "SIP_PROXY=" + localSettings.sip_proxy + "\n";
118 andreas 1542
    content += "SIP_PORT=" + std::to_string(localSettings.sip_port) + "\n";
127 andreas 1543
    content += "SIP_PORTTLS=" + std::to_string(localSettings.sip_portTLS) + "\n";
1544
    content += "SIP_STUN=" + localSettings.sip_stun + "\n";
1545
    content += "SIP_DOMAIN=" + localSettings.sip_domain + "\n";
1546
    content += "SIP_USER=" + localSettings.sip_user + "\n";
1547
    content += "SIP_PASSWORD=" + localSettings.sip_password + "\n";
1548
    content += "SIP_IPV4=" + string(localSettings.sip_ipv4 ? "TRUE" : "FALSE") + "\n";
139 andreas 1549
    content += "SIP_IPV6=" + string(localSettings.sip_ipv6 ? "TRUE" : "FALSE") + "\n";
1550
    content += "SIP_IPHONE=" + string(localSettings.sip_iphone ? "TRUE" : "FALSE") + "\n";
127 andreas 1551
    content += "SIP_FIREWALL=" + sipFirewallToString(localSettings.sip_firewall) + "\n";
1552
    content += "SIP_ENABLED=" + string(localSettings.sip_ipv6 ? "TRUE" : "FALSE") + "\n";
118 andreas 1553
 
1554
    return content;
1555
}
1556
 
59 andreas 1557
/**
21 andreas 1558
 * @brief TConfig::findConfig search for the location of the configuration file.
1559
 *
1560
 * If there was no configuration file given on the command line, this method
1561
 * searches for a configuration file on a few standard directories. This are:
1562
 *
1563
 *     /etc/tpanel.conf
1564
 *     /etc/tpanel/tpanel.conf
1565
 *     /usr/etc/tpanel.conf
1566
 *     $HOME/.tpanel.conf
1567
 *
1568
 * On macOS the following additional directories are searched:
1569
 *
1570
 *     /opt/local/etc/tpanel.conf
1571
 *     /opt/local/etc/tpanel/tpanel.conf
1572
 *     /opt/local/usr/etc/tpanel.conf
1573
 *
1574
 * @return On success `true`, otherwise `false`.
1575
 */
2 andreas 1576
bool TConfig::findConfig()
1577
{
292 andreas 1578
    TLock<std::mutex> guard(config_mutex);
1579
 
90 andreas 1580
    char *HOME = nullptr;
1581
    string sFileName;
22 andreas 1582
 
90 andreas 1583
    if (!mPath.empty())
1584
    {
1585
        size_t pos = mPath.find_last_of("/");
2 andreas 1586
 
90 andreas 1587
        if (pos != string::npos)
1588
        {
1589
            localSettings.path = mPath.substr(0, pos);
1590
            localSettings.name = mPath.substr(pos+1);
192 andreas 1591
            localSettings_temp.path = localSettings.path;
1592
            localSettings_temp.name = localSettings.name;
90 andreas 1593
            mCFile = mPath;
1594
            return !mCFile.empty();
1595
        }
2 andreas 1596
 
192 andreas 1597
        localSettings.path = ".";
90 andreas 1598
        localSettings.name = mPath;
192 andreas 1599
        localSettings_temp.path = localSettings.path;
1600
        localSettings_temp.name = localSettings.name;
90 andreas 1601
        mCFile = mPath;
1602
        return !mCFile.empty();
1603
    }
2 andreas 1604
 
90 andreas 1605
    localSettings.name = "tpanel.conf";
51 andreas 1606
    localSettings.password1 = "1988";
1607
    localSettings.password2 = "1988";
1608
    localSettings.password3 = "1988";
1609
    localSettings.password4 = "1988";
71 andreas 1610
    localSettings.systemSound = "singleBeep.wav";
1611
    localSettings.systemSoundState = true;
1612
    localSettings.systemSingleBeep = "singleBeep01.wav";
1613
    localSettings.systemDoubleBeep = "doubleBeep01.wav";
112 andreas 1614
    localSettings.ftpUser = "administrator";
1615
    localSettings.ftpPassword = "password";
115 andreas 1616
    localSettings.ftpSurface = "tpanel.tp4";
21 andreas 1617
#ifdef __ANDROID__
22 andreas 1618
    std::stringstream s;
1619
    TValidateFile vf;
1620
    HOME = getenv("HOME");
2 andreas 1621
 
22 andreas 1622
    if (!HOME || !*HOME)
21 andreas 1623
    {
43 andreas 1624
        s << "Error: Environment variable HOME does not exist!";
22 andreas 1625
        __android_log_print(ANDROID_LOG_ERROR, "tpanel", "%s", s.str().c_str());
1626
        TError::setErrorMsg(s.str());
21 andreas 1627
        return false;
1628
    }
1629
 
22 andreas 1630
    localSettings.path = HOME;
1631
 
88 andreas 1632
    if (!vf.isValidDir(localSettings.path))
21 andreas 1633
    {
22 andreas 1634
        s << "Error: Path " << localSettings.path << " does not exist!";
1635
        __android_log_print(ANDROID_LOG_ERROR, "tpanel", "%s", s.str().c_str());
1636
        TError::setErrorMsg(s.str());
21 andreas 1637
        return false;
1638
    }
1639
 
22 andreas 1640
    sFileName = localSettings.path + "/" + localSettings.name;
21 andreas 1641
 
22 andreas 1642
    if (access(sFileName.c_str(), F_OK) == -1)    // Does the configuration file exist?
21 andreas 1643
    {                                       // No, than create it and also the directory structure
1644
        try
1645
        {
1646
            ofstream cfg(sFileName);
1647
 
118 andreas 1648
            string content = makeConfigDefault(localSettings.path + "/tpanel.log", localSettings.path + "/tpanel");
21 andreas 1649
            cfg.write(content.c_str(), content.size());
1650
            cfg.close();
1651
 
1652
            string path = localSettings.path + "/tpanel";
22 andreas 1653
            TTPInit init(path);
21 andreas 1654
        }
1655
        catch (std::exception& e)
1656
        {
23 andreas 1657
            s << "Error: " << e.what();
22 andreas 1658
            __android_log_print(ANDROID_LOG_ERROR, "tpanel" , "%s", s.str().c_str());
21 andreas 1659
            TError::setErrorMsg(TERRERROR, string("Error: ") + e.what());
1660
            return false;
1661
        }
1662
    }
1663
#else
90 andreas 1664
    if (!(HOME = getenv("HOME")))
116 andreas 1665
        MSG_ERROR("TConfig::findConfig: No environment variable HOME!");
2 andreas 1666
 
90 andreas 1667
    vector<string>::iterator iter;
1668
    bool found = false;
2 andreas 1669
 
90 andreas 1670
    for (iter = mCfgPaths.begin(); iter != mCfgPaths.end(); ++iter)
1671
    {
1672
        string f = *iter + "/tpanel.conf";
1673
 
1674
        if (!access(f.c_str(), R_OK))
1675
        {
1676
            sFileName = f;
1677
            localSettings.path = *iter;
113 andreas 1678
            found = true;
90 andreas 1679
            break;
1680
        }
1681
    }
1682
 
1683
    // The local configuration file has precedence over the global one.
1684
    if (HOME)
1685
    {
1686
        string f = HOME;
113 andreas 1687
#ifndef __ANDROID__
90 andreas 1688
        f += "/.tpanel.conf";
113 andreas 1689
#else
1690
        f += "/tpanel.conf";
1691
#endif
90 andreas 1692
        if (!access(f.data(), R_OK))
1693
        {
1694
            sFileName = f;
1695
            localSettings.path = HOME;
1696
            found = true;
1697
        }
1698
    }
1699
 
192 andreas 1700
    localSettings_temp = localSettings;
1701
 
90 andreas 1702
    if (!found)
1703
    {
118 andreas 1704
        MSG_WARNING("This seems to be the first start because of missing configuration file. Will try to create a default one ...");
1705
 
1706
        if (HOME)
1707
        {
1708
            localSettings.path = HOME;
1709
            sFileName = string(HOME) + "/.tpanel.conf";
1710
 
1711
            try
1712
            {
1713
                ofstream cfg(sFileName);
1714
 
1715
                string content = makeConfigDefault(localSettings.path + "/tpanel.log", localSettings.path + "/tpanel");
1716
                cfg.write(content.c_str(), content.size());
1717
                cfg.close();
1718
 
192 andreas 1719
                localSettings_temp = localSettings;
118 andreas 1720
                string path = localSettings.path + "/tpanel";
1721
                TTPInit init(path);
1722
            }
1723
            catch (std::exception& e)
1724
            {
1725
                cerr << "Error: " << e.what();
1726
                TError::setErrorMsg(TERRERROR, string("Error: ") + e.what());
1727
                return false;
1728
            }
1729
        }
1730
        else
1731
        {
1732
            MSG_ERROR("TConfig::findConfig: Can't find any configuration file!");
1733
            TError::setError();
1734
            sFileName.clear();
1735
            localSettings.name.clear();
1736
            localSettings.path.clear();
192 andreas 1737
            localSettings_temp = localSettings;
118 andreas 1738
        }
90 andreas 1739
    }
21 andreas 1740
#endif
90 andreas 1741
    mCFile = sFileName;
1742
    return !sFileName.empty();
2 andreas 1743
}
1744
 
21 andreas 1745
/**
1746
 * @brief TConfig::readConfig reads a config file.
1747
 *
1748
 * This method reads a config file and stores the known options into the
1749
 * struct localSettings.
1750
 *
1751
 * @return `true` on success.\n
1752
 * Returns `false` on error and sets the internal error.
1753
 */
2 andreas 1754
bool TConfig::readConfig()
1755
{
240 andreas 1756
#if defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_SIMULATOR)
239 andreas 1757
    QASettings settings;
1758
    localSettings.path = QASettings::getLibraryPath().toStdString();
1759
    localSettings.project = localSettings.path + "/tpanel";
242 andreas 1760
    localSettings.version = "1.0";
1761
    localSettings.ptype = "iPhone";
1762
    localSettings.max_cache = 100;
1763
    localSettings.logLevel = SLOG_NONE;
1764
    localSettings.logLevelBits = HLOG_NONE;
239 andreas 1765
    mkdir(localSettings.project.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
1766
    localSettings.name = "tpanel.cfg";
1767
    localSettings.scale = true;
1768
    localSettings.tbforce = false;
1769
    localSettings.tbsuppress = false;
1770
 
1771
    // Settings for NetLinx
1772
    settings.registerDefaultPrefs();
1773
    localSettings.server = settings.getNetlinxIP().toStdString();
1774
    localSettings.port = settings.getNetlinxPort();
1775
    localSettings.ID = settings.getNetlinxChannel();
1776
    localSettings.ptype = settings.getNetlinxPanelType().toStdString();
1777
    localSettings.ftpUser = settings.getFTPUser().toStdString();
1778
    localSettings.ftpPassword = settings.getFTPPassword().toStdString();
1779
    localSettings.ftpSurface = settings.getNetlinxSurface().toStdString();
1780
 
1781
    // Settings for SIP
1782
    localSettings.sip_proxy = settings.getSipProxy().toStdString();
1783
    localSettings.sip_port = settings.getSipNetworkPort();
1784
    localSettings.sip_portTLS = settings.getSipNetworkTlsPort();
1785
    localSettings.sip_stun = settings.getSipStun().toStdString();
1786
    localSettings.sip_domain = settings.getSipDomain().toStdString();
1787
    localSettings.sip_ipv4 = settings.getSipNetworkIpv4();
1788
    localSettings.sip_ipv6 = settings.getSipNetworkIpv6();
1789
    localSettings.sip_user = settings.getSipUser().toStdString();
1790
    localSettings.sip_password = settings.getSipPassword().toStdString();
1791
    localSettings.sip_enabled = settings.getSipEnabled();
1792
    localSettings.sip_iphone = settings.getSipIntegratedPhone();
1793
 
1794
    // Settings for View
1795
    localSettings.scale = settings.getViewScale();
1796
    localSettings.tbforce = settings.getViewToolbarForce();
1797
    localSettings.tbsuppress = !settings.getViewToolbarVisible();
1798
 
1799
    if (localSettings.tbforce)
1800
        localSettings.tbsuppress = false;
1801
 
1802
    localSettings.systemRotationFix = settings.getViewRotation();
1803
 
1804
    // Settings for sound
1805
    localSettings.systemSound = settings.getSoundSystem().toStdString();
1806
    localSettings.systemSingleBeep = settings.getSoundSingleBeep().toStdString();
1807
    localSettings.systemDoubleBeep = settings.getSoundDoubleBeep().toStdString();
1808
    localSettings.systemSoundState = settings.getSoundEnabled();
1809
    localSettings.systemVolume = settings.getSoundVolume();
1810
    localSettings.systemGain = settings.getSoundGain();
1811
 
1812
    // Settings for logging
1813
    unsigned int logLevel = 0;
1814
 
1815
    if (settings.getLoggingInfo())
1816
        logLevel |= HLOG_INFO;
1817
 
1818
    if (settings.getLoggingWarning())
1819
        logLevel |= HLOG_WARNING;
1820
 
1821
    if (settings.getLoggingError())
1822
        logLevel |= HLOG_ERROR;
1823
 
1824
    if (settings.getLoggingDebug())
1825
        logLevel |= HLOG_DEBUG;
1826
 
1827
    if (settings.getLoggingTrace())
1828
        logLevel |= HLOG_TRACE;
1829
 
1830
    if (settings.getLoggingProfile())
1831
        localSettings.profiling = true;
1832
    else
1833
        localSettings.profiling = false;
1834
 
1835
    if (settings.getLoggingLogFormat())
1836
        localSettings.longformat = true;
1837
    else
1838
        localSettings.longformat = false;
1839
 
1840
    localSettings.logLevelBits = logLevel;
1841
    localSettings.logLevel = logLevelBitsToString(logLevel);
243 andreas 1842
    TStreamError::setLogLevel(localSettings.logLevel);
239 andreas 1843
 
242 andreas 1844
    if (settings.getLoggingLogfileEnabled())
1845
    {
1846
        string fname = settings.getLoggingLogfile().toStdString();
1847
 
1848
        if (!fname.empty())
1849
        {
1850
            localSettings.logFile = QASettings::getDocumentPath().toStdString() + "/" + fname;
243 andreas 1851
            TStreamError::setLogFile(localSettings.logFile);
242 andreas 1852
        }
1853
    }
1854
    else
1855
        localSettings.logFile.clear();
1856
 
239 andreas 1857
    if (localSettings.uuid.empty())
1858
    {
1859
        uuid_t uuid;
1860
        char sUUID[256];
1861
 
1862
        uuid_generate_random(uuid);
1863
        uuid_unparse_lower(uuid, sUUID);
1864
        localSettings.uuid.assign(sUUID);
1865
        localSettings_temp = localSettings;
1866
    }
1867
 
1868
    mInitialized = true;
1869
 
242 andreas 1870
    if (IS_LOG_DEBUG())
1871
    {
1872
        cout << "Selected Parameters:" << endl;
1873
        cout << "    Path to cfg.: " << localSettings.path << endl;
1874
        cout << "    Name of cfg.: " << localSettings.name << endl;
1875
        cout << "    Logfile use:  " << (settings.getLoggingLogfileEnabled() ? "YES": "NO") << endl;
1876
        cout << "    Logfile:      " << localSettings.logFile  << endl;
1877
        cout << "    LogLevel:     " << localSettings.logLevel  << endl;
1878
        cout << "    Long format:  " << (localSettings.longformat ? "YES" : "NO")  << endl;
1879
        cout << "    Project path: " << localSettings.project  << endl;
1880
        cout << "    Controller:   " << localSettings.server  << endl;
1881
        cout << "    Port:         " << localSettings.port  << endl;
1882
        cout << "    Channel:      " << localSettings.ID  << endl;
1883
        cout << "    Panel type:   " << localSettings.ptype  << endl;
1884
        cout << "    Firmware ver. " << localSettings.version  << endl;
1885
        cout << "    Scaling:      " << (localSettings.scale ? "YES" : "NO")  << endl;
1886
        cout << "    Profiling:    " << (localSettings.profiling ? "YES" : "NO")  << endl;
1887
        cout << "    Button cache: " << localSettings.max_cache  << endl;
1888
        cout << "    System Sound: " << localSettings.systemSound  << endl;
1889
        cout << "    Sound state:  " << (localSettings.systemSoundState ? "ACTIVATED" : "DEACTIVATED")  << endl;
1890
        cout << "    Single beep:  " << localSettings.systemSingleBeep  << endl;
1891
        cout << "    Double beep:  " << localSettings.systemDoubleBeep  << endl;
1892
        cout << "    Volume:       " << localSettings.systemVolume  << endl;
1893
        cout << "    Gain:         " << localSettings.systemGain  << endl;
1894
        cout << "    Rotation:     " << (localSettings.systemRotationFix ? "LOCKED" : "UNLOCKED")  << endl;
1895
        cout << "    UUID:         " << localSettings.uuid  << endl;
1896
        cout << "    FTP user:     " << localSettings.ftpUser  << endl;
1897
        cout << "    FTP password: " << localSettings.ftpPassword  << endl;
1898
        cout << "    FTP surface:  " << localSettings.ftpSurface  << endl;
1899
        cout << "    FTP passive:  " << (localSettings.ftpPassive ? "YES" : "NO")  << endl;
1900
        cout << "    FTP dl. time: " << localSettings.ftpLastDownload  << endl;
1901
        cout << "    SIP proxy:    " << localSettings.sip_proxy  << endl;
1902
        cout << "    SIP port:     " << localSettings.sip_port  << endl;
1903
        cout << "    SIP TLS port: " << localSettings.sip_portTLS  << endl;
1904
        cout << "    SIP STUN:     " << localSettings.sip_stun  << endl;
1905
        cout << "    SIP doamain:  " << localSettings.sip_domain  << endl;
1906
        cout << "    SIP user:     " << localSettings.sip_user  << endl;
1907
        cout << "    SIP IPv4:     " << (localSettings.sip_ipv4 ? "YES" : "NO")  << endl;
1908
        cout << "    SIP IPv6:     " << (localSettings.sip_ipv6 ? "YES" : "NO")  << endl;
1909
        cout << "    SIP Int.Phone:" << (localSettings.sip_iphone ? "YES" : "NO")  << endl;
1910
        cout << "    SIP firewall: " << sipFirewallToString(localSettings.sip_firewall)  << endl;
1911
        cout << "    SIP enabled:  " << (localSettings.sip_enabled ? "YES" : "NO")  << endl;
1912
    }
239 andreas 1913
#else
35 andreas 1914
    ifstream fs;
2 andreas 1915
 
192 andreas 1916
    mTemporary = false;
35 andreas 1917
    // First initialize the defaults
1918
    localSettings.ID = 0;
1919
    localSettings.port = 1397;
1920
    localSettings.ptype = "android";
1921
    localSettings.version = "1.0";
1922
    localSettings.longformat = false;
43 andreas 1923
    localSettings.profiling = false;
175 andreas 1924
#ifdef __ANDROID__
1925
    localSettings.max_cache = 100;
1926
#else
1927
    localSettings.max_cache = 400;
1928
#endif
71 andreas 1929
    localSettings.systemSoundState = true;
1930
    localSettings.systemSound = "singleBeep.wav";
1931
    localSettings.systemSingleBeep = "singleBeep01.wav";
1932
    localSettings.systemDoubleBeep = "doubleBeep01.wav";
112 andreas 1933
    localSettings.ftpUser = "administrator";
1934
    localSettings.ftpPassword = "password";
115 andreas 1935
    localSettings.ftpSurface = "tpanel.tp4";
116 andreas 1936
    localSettings.sip_port = 5060;
127 andreas 1937
    localSettings.sip_portTLS = 0;
2 andreas 1938
 
35 andreas 1939
    // Now get the settings from file
1940
    try
1941
    {
1942
        fs.open(mCFile.c_str(), fstream::in);
1943
    }
1944
    catch (const fstream::failure e)
1945
    {
192 andreas 1946
        localSettings_temp = localSettings;
116 andreas 1947
        cerr << "TConfig::readConfig: Error on file " << mCFile << ": " << e.what() << endl;
35 andreas 1948
        TError::setError();
1949
        return false;
1950
    }
2 andreas 1951
 
35 andreas 1952
    for (string line; getline(fs, line);)
1953
    {
1954
        size_t pos;
2 andreas 1955
 
35 andreas 1956
        if ((pos = line.find("#")) != string::npos)
1957
        {
1958
            if (pos == 0)
1959
                line.clear();
1960
            else
1961
                line = line.substr(0, pos);
1962
        }
2 andreas 1963
 
35 andreas 1964
        if (line.empty() || line.find("=") == string::npos)
1965
            continue;
2 andreas 1966
 
35 andreas 1967
        vector<string> parts = split(line, "=", true);
2 andreas 1968
 
35 andreas 1969
        if (parts.size() == 2)
1970
        {
1971
            string left = parts[0];
1972
            string right = ltrim(parts[1]);
2 andreas 1973
 
35 andreas 1974
            if (caseCompare(left, "PORT") == 0 && !right.empty())
1975
                localSettings.port = atoi(right.c_str());
1976
            else if (caseCompare(left, "LOGFILE") == 0 && !right.empty())
1977
            {
1978
                localSettings.logFile = right;
23 andreas 1979
                TStreamError::setLogFileOnly(right);
35 andreas 1980
            }
1981
            else if (caseCompare(left, "LOGLEVEL") == 0 && !right.empty())
1982
            {
1983
                TStreamError::setLogLevel(right);
1984
                localSettings.logLevel = right;
59 andreas 1985
                localSettings.logLevelBits = logLevelStrToBits(right);
35 andreas 1986
            }
1987
            else if (caseCompare(left, "ProjectPath") == 0 && !right.empty())
43 andreas 1988
            {
35 andreas 1989
                localSettings.project = right;
43 andreas 1990
#ifdef __ANDROID__
1991
                TValidateFile vf;
1992
 
1993
                if (!vf.isValidFile(right))
1994
                {
1995
                    char *HOME = getenv("HOME");
1996
 
1997
                    if (HOME)
1998
                    {
1999
                        localSettings.project = HOME;
2000
                        localSettings.project += "/tpanel";
2001
                    }
2002
                }
2003
#endif
2004
            }
11 andreas 2005
            else if (caseCompare(left, "System") == 0 && !right.empty())
2006
                localSettings.system = atoi(right.c_str());
2007
            else if (caseCompare(left, "PanelType") == 0 && !right.empty())
35 andreas 2008
                localSettings.ptype = right;
2009
            else if (caseCompare(left, "Address") == 0 && !right.empty())
2010
                localSettings.server = right;
2011
            else if (caseCompare(left, "Firmware") == 0 && !right.empty())
2012
                localSettings.version = right;
2013
            else if (caseCompare(left, "LongFormat") == 0 && !right.empty())
71 andreas 2014
                localSettings.longformat = isTrue(right);
35 andreas 2015
            else if (caseCompare(left, "NoBanner") == 0 && !right.empty())
71 andreas 2016
                localSettings.noBanner = isTrue(right);
35 andreas 2017
            else if (caseCompare(left, "CertCheck") == 0 && !right.empty())
71 andreas 2018
                localSettings.certCheck = isTrue(right);
21 andreas 2019
            else if (caseCompare(left, "Channel") == 0 && !right.empty())
35 andreas 2020
            {
2021
                localSettings.ID = atoi(right.c_str());
2 andreas 2022
 
113 andreas 2023
                if (localSettings.ID < 10000 || localSettings.ID >= 29000)
35 andreas 2024
                {
260 andreas 2025
#ifdef __ANDROID__
2026
                    __android_log_print(ANDROID_LOG_ERROR, "tpanel", "TConfig::readConfig: Invalid port number %s", right.c_str());
2027
#else
116 andreas 2028
                    cerr << "TConfig::readConfig: Invalid port number " << right << endl;
260 andreas 2029
#endif
35 andreas 2030
                    localSettings.ID = 0;
2031
                }
134 andreas 2032
 
2033
                mChannel = localSettings.ID;
35 andreas 2034
            }
26 andreas 2035
            else if (caseCompare(left, "Scale") == 0 && !right.empty())
71 andreas 2036
                localSettings.scale = isTrue(right);
120 andreas 2037
            else if (caseCompare(left, "ToolbarForce") == 0 && !right.empty())
2038
                localSettings.tbforce = isTrue(right);
151 andreas 2039
            else if (caseCompare(left, "ToolbarSuppress") == 0 && !right.empty())
2040
                localSettings.tbsuppress = isTrue(right);
35 andreas 2041
            else if (caseCompare(left, "Profiling") == 0 && !right.empty())
71 andreas 2042
                localSettings.profiling = isTrue(right);
175 andreas 2043
            else if (caseCompare(left, "MaxButtonCache") == 0 && !right.empty())
2044
                localSettings.max_cache = atoi(right.c_str());
51 andreas 2045
            else if (caseCompare(left, "Password1") == 0 && !right.empty())
2046
                localSettings.password1 = right;
2047
            else if (caseCompare(left, "Password2") == 0 && !right.empty())
2048
                localSettings.password2 = right;
2049
            else if (caseCompare(left, "Password3") == 0 && !right.empty())
2050
                localSettings.password3 = right;
2051
            else if (caseCompare(left, "Password4") == 0 && !right.empty())
2052
                localSettings.password4 = right;
71 andreas 2053
            else if (caseCompare(left, "SystemSoundFile") == 0 && !right.empty())
2054
                localSettings.systemSound = right;
2055
            else if (caseCompare(left, "SystemSoundState") == 0 && !right.empty())
2056
                localSettings.systemSoundState = isTrue(right);
2057
            else if (caseCompare(left, "SystemSingleBeep") == 0 && !right.empty())
2058
                localSettings.systemSingleBeep = right;
2059
            else if (caseCompare(left, "SystemDoubleBeep") == 0 && !right.empty())
2060
                localSettings.systemDoubleBeep = right;
141 andreas 2061
            else if (caseCompare(left, "SystemVolume") == 0 && !right.empty())
2062
            {
2063
                int volume = atoi(right.c_str());
2064
 
2065
                if (volume < 0)
2066
                    volume = 0;
2067
                else if (volume > 100)
2068
                    volume = 100;
2069
 
2070
                localSettings.systemVolume = volume;
2071
            }
2072
            else if (caseCompare(left, "SystemGain") == 0 && !right.empty())
2073
            {
2074
                int gain = atoi(right.c_str());
2075
 
2076
                if (gain < 0)
2077
                    gain = 0;
2078
                else if (gain > 100)
2079
                    gain = 100;
2080
 
2081
                localSettings.systemGain = gain;
2082
            }
134 andreas 2083
            else if (caseCompare(left, "SystemRotationFix") == 0 && !right.empty())
2084
                localSettings.systemRotationFix = isTrue(right);
2085
            else if (caseCompare(left, "UUID") == 0 && !right.empty())
2086
                localSettings.uuid = right;
112 andreas 2087
            else if (caseCompare(left, "FTPuser") == 0 && !right.empty())       // FTP credentials
2088
                localSettings.ftpUser = right;
2089
            else if (caseCompare(left, "FTPpassword") == 0 && !right.empty())
2090
                localSettings.ftpPassword = right;
115 andreas 2091
            else if (caseCompare(left, "FTPsurface") == 0 && !right.empty())
2092
                localSettings.ftpSurface = right;
116 andreas 2093
            else if (caseCompare(left, "FTPpassive") == 0 && !right.empty())
2094
                localSettings.ftpPassive = isTrue(right);
115 andreas 2095
            else if (caseCompare(left, "FTPdownloadTime") == 0 && !right.empty())
2096
                localSettings.ftpLastDownload = atol(right.c_str());
104 andreas 2097
            else if (caseCompare(left, "SIP_PROXY") == 0 && !right.empty())     // SIP settings starting here
2098
                localSettings.sip_proxy = right;
2099
            else if (caseCompare(left, "SIP_PORT") == 0 && !right.empty())
2100
                localSettings.sip_port = atoi(right.c_str());
127 andreas 2101
            else if (caseCompare(left, "SIP_PORTTLS") == 0 && !right.empty())
2102
                localSettings.sip_portTLS = atoi(right.c_str());
104 andreas 2103
            else if (caseCompare(left, "SIP_STUN") == 0 && !right.empty())
2104
                localSettings.sip_stun = right;
2105
            else if (caseCompare(left, "SIP_DOMAIN") == 0 && !right.empty())
2106
                localSettings.sip_domain = right;
2107
            else if (caseCompare(left, "SIP_USER") == 0 && !right.empty())
2108
                localSettings.sip_user = right;
2109
            else if (caseCompare(left, "SIP_PASSWORD") == 0 && !right.empty())
2110
                localSettings.sip_password = right;
127 andreas 2111
            else if (caseCompare(left, "SIP_IPV4") == 0 && !right.empty())
2112
                localSettings.sip_ipv4 = isTrue(right);
2113
            else if (caseCompare(left, "SIP_IPV6") == 0 && !right.empty())
2114
                localSettings.sip_ipv6 = isTrue(right);
139 andreas 2115
            else if (caseCompare(left, "SIP_IPHONE") == 0 && !right.empty())
2116
                localSettings.sip_iphone = isTrue(right);
127 andreas 2117
            else if (caseCompare(left, "SIP_FIREWALL") == 0 && !right.empty())
2118
                localSettings.sip_firewall = sipFirewallStrToEnum(right);
104 andreas 2119
            else if (caseCompare(left, "SIP_ENABLED") == 0 && !right.empty())
2120
                localSettings.sip_enabled = isTrue(right);
26 andreas 2121
        }
35 andreas 2122
    }
2 andreas 2123
 
35 andreas 2124
    fs.close();
116 andreas 2125
    mInitialized = true;
2126
    TStreamError::setLogLevel(localSettings.logLevel);
260 andreas 2127
//    TStreamError::setLogLevel("INFO|WARNING|ERROR|DEBUG");
116 andreas 2128
    TStreamError::setLogFile(localSettings.logFile);
2 andreas 2129
 
134 andreas 2130
    if (localSettings.uuid.empty())
2131
    {
2132
#ifdef __ANDROID__
2133
        QUuid qUid = QUuid::createUuid();
2134
        localSettings.uuid = qUid.toString().toStdString();
2135
#else
2136
        uuid_t uuid;
2137
        char sUUID[256];
2138
 
2139
        uuid_generate_random(uuid);
2140
        uuid_unparse_lower(uuid, sUUID);
2141
        localSettings.uuid.assign(sUUID);
2142
#endif
192 andreas 2143
        localSettings_temp = localSettings;
134 andreas 2144
        saveSettings();
2145
    }
192 andreas 2146
 
23 andreas 2147
    if (TStreamError::checkFilter(HLOG_DEBUG))
35 andreas 2148
    {
2149
        MSG_INFO("Selected Parameters:");
2150
        MSG_INFO("    Path to cfg.: " << localSettings.path);
2151
        MSG_INFO("    Name of cfg.: " << localSettings.name);
23 andreas 2152
#ifndef __ANDROID__
2153
        MSG_INFO("    Logfile:      " << localSettings.logFile);
2154
#endif
26 andreas 2155
        MSG_INFO("    LogLevel:     " << localSettings.logLevel);
35 andreas 2156
        MSG_INFO("    Long format:  " << (localSettings.longformat ? "YES" : "NO"));
2157
        MSG_INFO("    Project path: " << localSettings.project);
23 andreas 2158
#ifndef __ANDROID__
35 andreas 2159
        MSG_INFO("    Show banner:  " << (localSettings.noBanner ? "NO" : "YES"));
23 andreas 2160
#endif
35 andreas 2161
        MSG_INFO("    Controller:   " << localSettings.server);
2162
        MSG_INFO("    Port:         " << localSettings.port);
2163
        MSG_INFO("    Channel:      " << localSettings.ID);
2164
        MSG_INFO("    Panel type:   " << localSettings.ptype);
2165
        MSG_INFO("    Firmware ver. " << localSettings.version);
26 andreas 2166
        MSG_INFO("    Scaling:      " << (localSettings.scale ? "YES" : "NO"));
35 andreas 2167
        MSG_INFO("    Profiling:    " << (localSettings.profiling ? "YES" : "NO"));
175 andreas 2168
        MSG_INFO("    Button cache: " << localSettings.max_cache);
71 andreas 2169
        MSG_INFO("    System Sound: " << localSettings.systemSound);
2170
        MSG_INFO("    Sound state:  " << (localSettings.systemSoundState ? "ACTIVATED" : "DEACTIVATED"));
2171
        MSG_INFO("    Single beep:  " << localSettings.systemSingleBeep);
2172
        MSG_INFO("    Double beep:  " << localSettings.systemDoubleBeep);
141 andreas 2173
        MSG_INFO("    Volume:       " << localSettings.systemVolume);
2174
        MSG_INFO("    Gain:         " << localSettings.systemGain);
134 andreas 2175
        MSG_INFO("    Rotation:     " << (localSettings.systemRotationFix ? "LOCKED" : "UNLOCKED"));
2176
        MSG_INFO("    UUID:         " << localSettings.uuid);
115 andreas 2177
        MSG_INFO("    FTP user:     " << localSettings.ftpUser);
2178
        MSG_INFO("    FTP password: " << localSettings.ftpPassword);
2179
        MSG_INFO("    FTP surface:  " << localSettings.ftpSurface);
116 andreas 2180
        MSG_INFO("    FTP passive:  " << (localSettings.ftpPassive ? "YES" : "NO"));
115 andreas 2181
        MSG_INFO("    FTP dl. time: " << localSettings.ftpLastDownload);
127 andreas 2182
        MSG_INFO("    SIP proxy:    " << localSettings.sip_proxy);
2183
        MSG_INFO("    SIP port:     " << localSettings.sip_port);
2184
        MSG_INFO("    SIP TLS port: " << localSettings.sip_portTLS);
2185
        MSG_INFO("    SIP STUN:     " << localSettings.sip_stun);
2186
        MSG_INFO("    SIP doamain:  " << localSettings.sip_domain);
2187
        MSG_INFO("    SIP user:     " << localSettings.sip_user);
2188
        MSG_INFO("    SIP IPv4:     " << (localSettings.sip_ipv4 ? "YES" : "NO"));
2189
        MSG_INFO("    SIP IPv6:     " << (localSettings.sip_ipv6 ? "YES" : "NO"));
139 andreas 2190
        MSG_INFO("    SIP Int.Phone:" << (localSettings.sip_iphone ? "YES" : "NO"));
127 andreas 2191
        MSG_INFO("    SIP firewall: " << sipFirewallToString(localSettings.sip_firewall));
2192
        MSG_INFO("    SIP enabled:  " << (localSettings.sip_enabled ? "YES" : "NO"));
35 andreas 2193
    }
2 andreas 2194
 
192 andreas 2195
    localSettings_temp = localSettings;
239 andreas 2196
#endif
35 andreas 2197
    return true;
2 andreas 2198
}
2199
 
21 andreas 2200
/**
2201
 * @brief TConfig::split splitts a string into parts.
2202
 *
2203
 * The method splitts a string into parts separated by \p seps. It puts the
2204
 * parts into a vector array.
2205
 *
2206
 * @param str           The string to split
2207
 * @param seps          The separator(s)
2208
 * @param trimEmpty     `true` = trum the parts.
2209
 *
2210
 * @return A vector array containing the parts of the string \p str.
2211
 */
2 andreas 2212
vector<string> TConfig::split(const string& str, const string& seps, const bool trimEmpty)
2213
{
116 andreas 2214
    DECL_TRACER("TConfig::split(const string& str, const string& seps, const bool trimEmpty)");
2215
 
2 andreas 2216
	size_t pos = 0, mark = 0;
2217
	vector<string> parts;
2218
 
2219
	for (auto it = str.begin(); it != str.end(); ++it)
2220
	{
2221
		for (auto sepIt = seps.begin(); sepIt != seps.end(); ++sepIt)
2222
		{
2223
			if (*it == *sepIt)
2224
			{
2225
				size_t len = pos - mark;
2226
				parts.push_back(str.substr(mark, len));
2227
				mark = pos + 1;
2228
				break;
2229
			}
2230
		}
2231
 
2232
		pos++;
2233
	}
2234
 
2235
	parts.push_back(str.substr(mark));
2236
 
2237
	if (trimEmpty)
2238
	{
2239
		vector<string> nparts;
2240
 
2241
		for (auto it = parts.begin(); it != parts.end(); ++it)
2242
		{
2243
			if (it->empty())
2244
				continue;
2245
 
2246
			nparts.push_back(*it);
2247
		}
2248
 
2249
		return nparts;
2250
	}
2251
 
2252
	return parts;
2253
}
2254
 
21 andreas 2255
/**
2256
 * @brief TConfig::caseCompare compares 2 strings
2257
 *
2258
 * This method compares 2 strings case insensitive. This means that it ignores
2259
 * the case of the letters. For example:
2260
 *
2261
 *     BLAME
2262
 *     blame
2263
 *     Blame
2264
 *
2265
 * are all the same and would return 0, which means _equal_.
2266
 *
2267
 * @param str1  1st string to compare
2268
 * @param str2  2nd string to compare
2269
 *
2270
 * @return 0 if the strings are equal\n
2271
 * less than 0 if the byte of \p str1 is bigger than the byte of \p str2\n
2272
 * grater than 0 if the byte of \p str1 is smaller than the byte of \p str2.
2273
 */
2 andreas 2274
int TConfig::caseCompare(const string& str1, const string& str2)
2275
{
116 andreas 2276
    DECL_TRACER("TConfig::caseCompare(const string& str1, const string& str2)");
2277
 
2 andreas 2278
	size_t i = 0;
2279
 
2280
	if (str1.length() != str2.length())
2281
		return ((str1.length() < str2.length()) ? -1 : 1);
2282
 
2283
	for (auto it = str1.begin(); it != str1.end(); ++it)
2284
	{
2285
		if (tolower(*it) != tolower(str2.at(i)))
2286
			return (int)(*it - str2.at(i));
2287
 
2288
		i++;
2289
	}
2290
 
2291
	return 0;
2292
}