-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserverconfigreader.cpp
67 lines (65 loc) · 2.26 KB
/
serverconfigreader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "serverconfigreader.h"
#include <QFileInfo>
#include <QFile>
#include <QDir>
#include <QJsonObject>
#include <QJsonArray>
ServerConfigReader::ServerConfigReader(QString scriptPath)
{
QFileInfo fi(scriptPath);
QString ext = fi.completeSuffix();
QString pathPart = fi.path();
if(!pathPart.endsWith(QDir::separator()))
pathPart += QDir::separator();
QString jsonPath = scriptPath.replace(scriptPath.length() - ext.length(), ext.length(), QString("json"));
#ifdef QT_DEBUG
qDebug() << "Json config path is" << jsonPath;
#endif
QFile jfile(jsonPath);
if(jfile.open(QIODevice::ReadOnly))
{
QByteArray cfgData = jfile.readAll();
QJsonDocument jdoc(QJsonDocument::fromJson(cfgData));
if(jdoc.object().contains("allowedIPs"))
{
QVariantList vlist = jdoc.object().value("allowedIPs").toArray().toVariantList();
foreach (QVariant v, vlist)
{
allowedIPs.append(v.toString());
#ifdef QT_DEBUG
qDebug() << v.toString();
#endif
}
}
if(jdoc.object().contains("exchangeLogPrefix"))
{
QString prefix = jdoc.object().value("exchangeLogPrefix").toString();
logPathPrefix = pathPart+prefix;
}
if(jdoc.object().contains("debugLogPrefix"))
{
QString prefix = jdoc.object().value("debugLogPrefix").toString();
debugLogPathPrefix = pathPart+prefix;
}
if(jdoc.object().contains("host"))
{
QString hname = jdoc.object().value("host").toString().toLower();
if(hname == "local" || hname == "localhost")
host = QHostAddress(QHostAddress::LocalHost);
else if(hname == "any")
host = QHostAddress(QHostAddress::Any);
else if(hname == "anyipv4")
host = QHostAddress(QHostAddress::AnyIPv4);
else if(hname == "anyipv6")
host = QHostAddress(QHostAddress::AnyIPv6);
else
host = QHostAddress(hname);
}
else
host = QHostAddress(QHostAddress::Any);
if(jdoc.object().contains("port"))
port = jdoc.object().value("port").toInt(0);
else
port = 0;
}
}