128 lines
2.0 KiB
C++
128 lines
2.0 KiB
C++
#include "pch.h"
|
|
|
|
|
|
|
|
uint32_t GetJsonUint32(const char* key, Json::Value& value)
|
|
{
|
|
if (value[key].empty())
|
|
return 0;
|
|
|
|
if (value[key].isInt())
|
|
return value[key].asUInt();
|
|
|
|
if (value[key].isString())
|
|
{
|
|
string v;
|
|
v = value[key].asString();
|
|
return atoi(v.c_str());
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
std::string GetJsonString(const char* key, Json::Value& value)
|
|
{
|
|
if (value[key].empty())
|
|
return "";
|
|
|
|
if (value[key].isString())
|
|
return value[key].asString();
|
|
|
|
if (value[key].isInt())
|
|
{
|
|
uint32_t v;
|
|
char s[50] = { 0, };
|
|
v = value[key].asUInt();
|
|
sprintf_s(s, sizeof(s), "%d", v);
|
|
return s;
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
|
|
CLocalConf::CLocalConf()
|
|
{
|
|
bs1fltkernel = 0;
|
|
}
|
|
|
|
CLocalConf::~CLocalConf()
|
|
{
|
|
|
|
}
|
|
|
|
const wchar_t* CLocalConf::GetServerIpW()
|
|
{
|
|
return wstr_server_ip_.c_str();
|
|
}
|
|
|
|
int CLocalConf::GetServerPort()
|
|
{
|
|
return server_port_;
|
|
}
|
|
|
|
int CLocalConf::GetConfig(const char* filename, DWORD pid)
|
|
{
|
|
|
|
int ret = BS1_OK;
|
|
int debug_type = 0;
|
|
char logfile_name[260] = { 0, };
|
|
|
|
path_ = filename;
|
|
path_ += "\\bs1local.conf";
|
|
|
|
BSONE_DEBUGA("(%s)", path_.c_str());
|
|
|
|
try
|
|
{
|
|
Json::Value root;
|
|
Json::Reader JsonReader;
|
|
std:ifstream stream;
|
|
|
|
stream.open(path_);
|
|
if (stream.is_open())
|
|
{
|
|
if (!JsonReader.parse(stream, root))
|
|
{
|
|
BSONE_DEBUG("policy json parser error");
|
|
return BS1_ERROR_CONFIG_OPEN_FAIL;
|
|
}
|
|
|
|
Json::Value debug = root["debug"];
|
|
debug_type = GetJsonUint32("bs1flt", debug);
|
|
bs1fltkernel = GetJsonUint32("bs1fltkernel", debug);
|
|
|
|
stream.close();
|
|
}
|
|
else
|
|
{
|
|
BSONE_DEBUG("policy json file open fail");
|
|
}
|
|
|
|
if (debug_type)
|
|
{
|
|
sprintf_s(logfile_name, sizeof(logfile_name), "%s\\bslflt.log", filename);
|
|
log4_.init_log4cpp(logfile_name, 2, LOGFILE_SIZE * 2);
|
|
BSONE_DEBUGA("logfile_name(%s)", logfile_name);
|
|
}
|
|
}
|
|
|
|
catch (int e)
|
|
{
|
|
ret = e;
|
|
BSONE_DEBUGA("(%s} open parser error catch 1 (%d)", filename, e);
|
|
}
|
|
catch (exception e)
|
|
{
|
|
BSONE_DEBUGA("(%s} open parser error catch 2 (%s)", filename, e.what());
|
|
ret = BS1_ERROR_CONFIG_OPEN_FAIL;
|
|
}
|
|
catch (...)
|
|
{
|
|
BSONE_DEBUGA("open parser error catch 3");
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|