Subversion Repositories tpanel

Rev

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