-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleConfigure_Json.cpp
More file actions
465 lines (427 loc) · 18.2 KB
/
ModuleConfigure_Json.cpp
File metadata and controls
465 lines (427 loc) · 18.2 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
#include "pch.h"
#include "ModuleConfigure_Json.h"
/********************************************************************
// Created: 2021/12/02 16:14:11
// File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ModuleConfigure\ModuleConfigure_Json\ModuleConfigure_Json.cpp
// File Path: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ModuleConfigure\ModuleConfigure_Json
// File Base: ModuleConfigure_Json
// File Ext: cpp
// Project: XEngine(网络通信引擎)
// Author: qyt
// Purpose: JSON配置读写实现
// History:
*********************************************************************/
CModuleConfigure_Json::CModuleConfigure_Json()
{
}
CModuleConfigure_Json::~CModuleConfigure_Json()
{
}
//////////////////////////////////////////////////////////////////////////
// 公用函数
//////////////////////////////////////////////////////////////////////////
/********************************************************************
函数名称:ModuleConfigure_Json_File
函数功能:读取JSON配置文件
参数.一:lpszConfigFile
In/Out:In
类型:常量字符指针
可空:N
意思:输入要读取的配置文件
参数.二:pSt_ServerConfig
In/Out:Out
类型:数据结构指针
可空:N
意思:输出服务配置信息
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XENGINE_SERVICECONFIG* pSt_ServerConfig)
{
// 每次读取前先重置错误状态,确保调用方获得的是本次调用结果。
Config_IsErrorOccur = false;
// 参数校验:配置文件路径和输出结构体都必须有效。
if ((NULL == lpszConfigFile) || (NULL == pSt_ServerConfig))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_PARAMENT;
return false;
}
// JSON 解析上下文:根节点、错误信息和 Reader 构造器。
Json::Value st_JsonRoot;
JSONCPP_STRING st_JsonError;
Json::CharReaderBuilder st_JsonBuilder;
// 读取配置文件内容到缓冲区;当前实现按固定 8KB 缓冲区读取。
FILE* pSt_File = _xtfopen(lpszConfigFile, _X("rb"));
if (NULL == pSt_File)
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_OPENFILE;
return false;
}
XCHAR tszMsgBuffer[8192] = {};
size_t nRet = fread(tszMsgBuffer, 1, sizeof(tszMsgBuffer), pSt_File);
fclose(pSt_File);
// 解析 JSON 文本;失败时记录统一解析错误码并返回。
std::unique_ptr<Json::CharReader> const pSt_JsonReader(st_JsonBuilder.newCharReader());
if (!pSt_JsonReader->parse(tszMsgBuffer, tszMsgBuffer + nRet, &st_JsonRoot, &st_JsonError))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_PARSE;
return false;
}
// 将 JSON 字段逐项映射到服务配置结构体,供后续模块统一使用。
_tcsxcpy(pSt_ServerConfig->tszIPAddr, st_JsonRoot["tszIPAddr"].asCString());
pSt_ServerConfig->bDeamon = st_JsonRoot["bDeamon"].asBool();
pSt_ServerConfig->bShowWnd = st_JsonRoot["bShowWnd"].asBool();
pSt_ServerConfig->nHttpPort = st_JsonRoot["nHttpPort"].asInt();
pSt_ServerConfig->nRFCPort = st_JsonRoot["nRFCPort"].asInt();
pSt_ServerConfig->nNTPPort = st_JsonRoot["nNTPPort"].asInt();
pSt_ServerConfig->nDNSPort = st_JsonRoot["nDNSPort"].asInt();
if (st_JsonRoot["XMax"].empty() || (4 != st_JsonRoot["XMax"].size()))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XMAX;
return false;
}
Json::Value st_JsonXMax = st_JsonRoot["XMax"];
pSt_ServerConfig->st_XMax.nMaxClient = st_JsonXMax["nMaxClient"].asInt();
pSt_ServerConfig->st_XMax.nMaxQueue = st_JsonXMax["nMaxQueue"].asInt();
pSt_ServerConfig->st_XMax.nIOThread = st_JsonXMax["nIOThread"].asInt();
pSt_ServerConfig->st_XMax.nHTTPThread = st_JsonXMax["nHttpThread"].asInt();
if (st_JsonRoot["XTime"].empty() || (3 != st_JsonRoot["XTime"].size()))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XTIME;
return false;
}
Json::Value st_JsonXTime = st_JsonRoot["XTime"];
pSt_ServerConfig->st_XTime.nTimeCheck = st_JsonXTime["nTimeCheck"].asInt();
pSt_ServerConfig->st_XTime.nHTTPTimeOut = st_JsonXTime["nHttpTimeOut"].asInt();
pSt_ServerConfig->st_XTime.nP2PTimeOut = st_JsonXTime["nP2PTimeOut"].asInt();
if (st_JsonRoot["XLog"].empty() || (6 != st_JsonRoot["XLog"].size()))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XLOG;
return false;
}
Json::Value st_JsonXLog = st_JsonRoot["XLog"];
pSt_ServerConfig->st_XLog.nMaxSize = st_JsonXLog["MaxSize"].asInt();
pSt_ServerConfig->st_XLog.nMaxCount = st_JsonXLog["MaxCount"].asInt();
pSt_ServerConfig->st_XLog.nLogLeave = st_JsonXLog["LogLeave"].asInt();
pSt_ServerConfig->st_XLog.nLogType = st_JsonXLog["LogType"].asInt();
_tcsxcpy(pSt_ServerConfig->st_XLog.tszAPIFile, st_JsonXLog["tszAPIFile"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XLog.tszServiceFile, st_JsonXLog["tszServiceFile"].asCString());
if (st_JsonRoot["XApi"].empty() || (4 != st_JsonRoot["XApi"].size()))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XAPI;
return false;
}
Json::Value st_JsonXApi = st_JsonRoot["XApi"];
_tcsxcpy(pSt_ServerConfig->st_XApi.tszWeatherUrl, st_JsonXApi["tszWeatherUrl"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XApi.tszBankUrl, st_JsonXApi["tszBankUrl"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XApi.tszOilUrl, st_JsonXApi["tszOilUrl"].asCString());
Json::Value st_JsonTranslationInfo = st_JsonXApi["st_TranslationInfo"];
_tcsxcpy(pSt_ServerConfig->st_XApi.st_TranslationInfo.tszAPPUrl, st_JsonTranslationInfo["url"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XApi.st_TranslationInfo.tszAPPID, st_JsonTranslationInfo["appid"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XApi.st_TranslationInfo.tszAPPKey, st_JsonTranslationInfo["key"].asCString());
if (st_JsonRoot["XSql"].empty() || (5 != st_JsonRoot["XSql"].size()))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XDB;
return false;
}
Json::Value st_JsonXSql = st_JsonRoot["XSql"];
pSt_ServerConfig->st_XSql.bEnable = st_JsonXSql["bEnable"].asBool();
pSt_ServerConfig->st_XSql.nSQLPort = st_JsonXSql["SQLPort"].asInt();
_tcsxcpy(pSt_ServerConfig->st_XSql.tszSQLAddr, st_JsonXSql["SQLAddr"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XSql.tszSQLUser, st_JsonXSql["SQLUser"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XSql.tszSQLPass, st_JsonXSql["SQLPass"].asCString());
if (st_JsonRoot["XPlugin"].empty() || (3 != st_JsonRoot["XPlugin"].size()))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XPLUGIN;
return false;
}
Json::Value st_JsonXPlugin = st_JsonRoot["XPlugin"];
pSt_ServerConfig->st_XPlugin.bEnable = st_JsonXPlugin["bEnable"].asBool();
_tcsxcpy(pSt_ServerConfig->st_XPlugin.tszLibPlugin, st_JsonXPlugin["tszLibPlugin"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XPlugin.tszLuaPlugin, st_JsonXPlugin["tszLuaPlugin"].asCString());
if (st_JsonRoot["XConfig"].empty() || (4 != st_JsonRoot["XConfig"].size()))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XCONFIG;
return false;
}
Json::Value st_JsonXConfig = st_JsonRoot["XConfig"];
_tcsxcpy(pSt_ServerConfig->st_XConfig.tszConfigDeamon, st_JsonXConfig["tszConfigDeamon"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XConfig.tszConfigHTTPMime, st_JsonXConfig["tszConfigHTTPMime"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XConfig.tszConfigHTTPCode, st_JsonXConfig["tszConfigHTTPCode"].asCString());
Json::Value st_JsonXConfigQRCode = st_JsonXConfig["st_ConfigQRCode"];
_tcsxcpy(pSt_ServerConfig->st_XConfig.st_ConfigQRCodec.tszModelDetect, st_JsonXConfigQRCode["tszModelDetect"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XConfig.st_ConfigQRCodec.tszModelSr, st_JsonXConfigQRCode["tszModelSr"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XConfig.st_ConfigQRCodec.tszProtoDetect, st_JsonXConfigQRCode["tszProtoDetect"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XConfig.st_ConfigQRCodec.tszProtoSr, st_JsonXConfigQRCode["tszProtoSr"].asCString());
if (st_JsonRoot["XShortLink"].empty() || (2 != st_JsonRoot["XShortLink"].size()))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XSLINK;
return false;
}
Json::Value st_JsonXShort = st_JsonRoot["XShortLink"];
_tcsxcpy(pSt_ServerConfig->st_XShortLink.tszHostUrl, st_JsonXShort["tszHostUrl"].asCString());
pSt_ServerConfig->st_XShortLink.nHTTPCode = st_JsonXShort["nHTTPCode"].asInt();
if (st_JsonRoot["XImageText"].empty() || (3 != st_JsonRoot["XImageText"].size()))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XIMAGETEXT;
return false;
}
Json::Value st_JsonXImageText = st_JsonRoot["XImageText"];
pSt_ServerConfig->st_XImageText.bEnable = st_JsonXImageText["bEnable"].asBool();
_tcsxcpy(pSt_ServerConfig->st_XImageText.tszImagePath, st_JsonXImageText["tszImagePath"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XImageText.tszImageLanguage, st_JsonXImageText["tszImageLanguage"].asCString());
if (st_JsonRoot["XVerification"].empty() || (6 != st_JsonRoot["XVerification"].size()))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XVERICATION;
return false;
}
Json::Value st_JsonXVerifcation = st_JsonRoot["XVerification"];
pSt_ServerConfig->st_XVerifcation.bEnable = st_JsonXVerifcation["bEnable"].asBool();
pSt_ServerConfig->st_XVerifcation.nVType = st_JsonXVerifcation["nVType"].asInt();
_tcsxcpy(pSt_ServerConfig->st_XVerifcation.tszAPIAuth, st_JsonXVerifcation["tszAPIAuth"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XVerifcation.tszUserName, st_JsonXVerifcation["tszUserName"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XVerifcation.tszUserPass, st_JsonXVerifcation["tszUserPass"].asCString());
Json::Value st_JsonVerSwitch = st_JsonXVerifcation["st_VerSwitch"];
pSt_ServerConfig->st_XVerifcation.st_VerSwitch.bBackService = st_JsonVerSwitch["bBackService"].asBool();
pSt_ServerConfig->st_XVerifcation.st_VerSwitch.bDeamon = st_JsonVerSwitch["bDeamon"].asBool();
if (st_JsonRoot["XAPIModule"].empty() || (5 != st_JsonRoot["XAPIModule"].size()))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XREPORT;
return false;
}
Json::Value st_JsonXAPIModule = st_JsonRoot["XAPIModule"];
pSt_ServerConfig->st_XAPIModule.bEnable = st_JsonXAPIModule["bEnable"].asBool();
_tcsxcpy(pSt_ServerConfig->st_XAPIModule.tszDBIPAddr, st_JsonXAPIModule["tszDBIPAddr"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XAPIModule.tszDBISPAddr, st_JsonXAPIModule["tszDBISPAddr"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XAPIModule.tszDBMac, st_JsonXAPIModule["tszDBMac"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XAPIModule.tszDBPhone, st_JsonXAPIModule["tszDBPhone"].asCString());
if (st_JsonRoot["XReport"].empty() || (3 != st_JsonRoot["XReport"].size()))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XREPORT;
return false;
}
Json::Value st_JsonXReport = st_JsonRoot["XReport"];
pSt_ServerConfig->st_XReport.bEnable = st_JsonXReport["bEnable"].asBool();
_tcsxcpy(pSt_ServerConfig->st_XReport.tszAPIUrl, st_JsonXReport["tszAPIUrl"].asCString());
_tcsxcpy(pSt_ServerConfig->st_XReport.tszServiceName, st_JsonXReport["tszServiceName"].asCString());
return true;
}
/********************************************************************
函数名称:ModuleConfigure_Json_VersionFile
函数功能:读取版本配置文件
参数.一:lpszConfigFile
In/Out:In
类型:常量字符指针
可空:N
意思:输入要读取的配置文件
参数.二:pSt_ServerConfig
In/Out:Out
类型:数据结构指针
可空:N
意思:输出服务配置信息
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
bool CModuleConfigure_Json::ModuleConfigure_Json_VersionFile(LPCXSTR lpszConfigFile, XENGINE_SERVICECONFIG* pSt_ServerConfig)
{
Config_IsErrorOccur = false;
if ((NULL == lpszConfigFile) || (NULL == pSt_ServerConfig))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_PARAMENT;
return false;
}
Json::Value st_JsonRoot;
JSONCPP_STRING st_JsonError;
Json::CharReaderBuilder st_JsonBuilder;
//读取配置文件所有内容到缓冲区
FILE* pSt_File = _xtfopen(lpszConfigFile, _X("rb"));
if (NULL == pSt_File)
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_OPENFILE;
return false;
}
XCHAR tszMsgBuffer[8192] = {};
size_t nRet = fread(tszMsgBuffer, 1, sizeof(tszMsgBuffer), pSt_File);
fclose(pSt_File);
//开始解析配置文件
std::unique_ptr<Json::CharReader> const pSt_JsonReader(st_JsonBuilder.newCharReader());
if (!pSt_JsonReader->parse(tszMsgBuffer, tszMsgBuffer + nRet, &st_JsonRoot, &st_JsonError))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_PARSE;
return false;
}
if (st_JsonRoot["XVer"].empty())
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XVER;
return false;
}
pSt_ServerConfig->st_XVer.pStl_ListVer = new list<string>;
if (NULL == pSt_ServerConfig->st_XVer.pStl_ListVer)
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_MALLOC;
return false;
}
Json::Value st_JsonXVer = st_JsonRoot["XVer"];
for (unsigned int i = 0; i < st_JsonXVer.size(); i++)
{
pSt_ServerConfig->st_XVer.pStl_ListVer->push_back(st_JsonXVer[i].asCString());
}
return true;
}
/********************************************************************
函数名称:ModuleConfigure_Json_DeamonList
函数功能:读取JSON配置文件
参数.一:lpszConfigFile
In/Out:In
类型:常量字符指针
可空:N
意思:输入要读取的配置文件
参数.二:pSt_AppConfig
In/Out:Out
类型:数据结构指针
可空:N
意思:输出守护进程列表
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
bool CModuleConfigure_Json::ModuleConfigure_Json_DeamonList(LPCXSTR lpszConfigFile, XENGINE_DEAMONAPPLIST* pSt_AppConfig)
{
Config_IsErrorOccur = false;
if ((NULL == lpszConfigFile) || (NULL == pSt_AppConfig))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_PARAMENT;
return false;
}
JSONCPP_STRING st_JsonError;
Json::Value st_JsonRoot;
Json::CharReaderBuilder st_JsonBuilder;
FILE* pSt_File = fopen(lpszConfigFile, "rb");
if (NULL == pSt_File)
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_OPENFILE;
return false;
}
XCHAR tszMsgBuffer[8192] = {};
size_t nRet = fread(tszMsgBuffer, 1, sizeof(tszMsgBuffer), pSt_File);
fclose(pSt_File);
std::unique_ptr<Json::CharReader> const pSt_JsonReader(st_JsonBuilder.newCharReader());
if (!pSt_JsonReader->parse(tszMsgBuffer, tszMsgBuffer + nRet, &st_JsonRoot, &st_JsonError))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_PARSE;
return false;
}
Json::Value st_JsonArray = st_JsonRoot["ListArray"];
for (unsigned int i = 0; i < st_JsonRoot["ListArray"].size(); i++)
{
XENGINE_DEAMONAPPINFO st_APPInfo;
memset(&st_APPInfo, '\0', sizeof(XENGINE_DEAMONAPPINFO));
strcpy(st_APPInfo.tszAPPName, st_JsonArray[i]["tszAPPName"].asCString());
strcpy(st_APPInfo.tszAPPPath, st_JsonArray[i]["tszAPPPath"].asCString());
st_APPInfo.bEnable = st_JsonArray[i]["bEnable"].asBool();
st_APPInfo.nReTime = st_JsonArray[i]["nAPPReTime"].asInt();
st_APPInfo.nReNumber = st_JsonArray[i]["nAPPReNumber"].asInt();
pSt_AppConfig->stl_ListDeamonApp.push_back(st_APPInfo);
}
return true;
}
/********************************************************************
函数名称:ModuleConfigure_Json_DNSFile
函数功能:读取JSON配置文件
参数.一:lpszConfigFile
In/Out:In
类型:常量字符指针
可空:N
意思:输入要读取的配置文件
参数.二:pSt_DNSList
In/Out:Out
类型:数据结构指针
可空:N
意思:输出DNS服务器列表
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
bool CModuleConfigure_Json::ModuleConfigure_Json_DNSFile(LPCXSTR lpszConfigFile, XENGINE_DNSINFO* pSt_DNSList)
{
Config_IsErrorOccur = false;
if ((NULL == lpszConfigFile) || (NULL == pSt_DNSList))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_PARAMENT;
return false;
}
JSONCPP_STRING st_JsonError;
Json::Value st_JsonRoot;
Json::CharReaderBuilder st_JsonBuilder;
FILE* pSt_File = fopen(lpszConfigFile, "rb");
if (NULL == pSt_File)
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_OPENFILE;
return false;
}
XCHAR tszMsgBuffer[8192] = {};
size_t nRet = fread(tszMsgBuffer, 1, sizeof(tszMsgBuffer), pSt_File);
fclose(pSt_File);
std::unique_ptr<Json::CharReader> const pSt_JsonReader(st_JsonBuilder.newCharReader());
if (!pSt_JsonReader->parse(tszMsgBuffer, tszMsgBuffer + nRet, &st_JsonRoot, &st_JsonError))
{
Config_IsErrorOccur = true;
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_PARSE;
return false;
}
Json::Value st_JsonServer = st_JsonRoot["DNSServer"];
for (unsigned int i = 0; i < st_JsonRoot["DNSServer"].size(); i++)
{
pSt_DNSList->stl_ListDNSServer.push_back(st_JsonServer[i].asCString());
}
Json::Value st_JsonList = st_JsonRoot["DNSList"];
for (unsigned int i = 0; i < st_JsonRoot["DNSList"].size(); i++)
{
XENGINE_DNSDOMAIN st_DNSDomain = {};
st_DNSDomain.bEnable = st_JsonList[i]["bEnable"].asBool();
_tcsxcpy(st_DNSDomain.tszDNSName, st_JsonList[i]["DNSName"].asCString());
Json::Value st_JsonAddr = st_JsonList[i]["DNSAddr"];
for (unsigned int j = 0; j < st_JsonList[i]["DNSAddr"].size(); j++)
{
XENGINE_DNSADDRINFO st_DNSAddr = {};
st_DNSAddr.nType = st_JsonAddr[j]["Type"].asInt();
st_DNSAddr.nTTL = st_JsonAddr[j]["TTL"].asInt();
_tcsxcpy(st_DNSAddr.tszDNSName, st_JsonAddr[j]["Name"].asCString());
_tcsxcpy(st_DNSAddr.tszDNSAddr, st_JsonAddr[j]["Addr"].asCString());
st_DNSDomain.stl_ListDNSAddr.push_back(st_DNSAddr);
}
pSt_DNSList->stl_ListDNSList.push_back(st_DNSDomain);
}
return true;
}