fix ini parser not work when new line flag '\r\n' and '\n' in the same file.

pull/105/head v3.0.0.1-ctp
Apex Lu 2017-11-26 04:44:06 +08:00
parent 2fac0b76a5
commit 4d5007e413
7 changed files with 80 additions and 43 deletions

View File

@ -267,32 +267,66 @@ bool ExIniFile::LoadFromMemory(const ex_wstr& strData, bool bClearOld)
ex_wstr strValue(L""); ex_wstr strValue(L"");
ex_wstr strLine(L""); ex_wstr strLine(L"");
ex_wstr::size_type pos = ex_wstr::npos; ex_wstr::size_type posCR = ex_wstr::npos;
ex_wstr::size_type posLF = ex_wstr::npos;
for (;;) for (;;)
{ {
pos = strAll.find(L"\r\n"); posCR = ex_wstr::npos;
if (ex_wstr::npos == pos) posLF = ex_wstr::npos;
{ posCR = strAll.find(L"\r");
pos = strAll.find(L'\n'); posLF = strAll.find(L"\n");
if (ex_wstr::npos == pos) int tttt = 0;
{
if (strAll.empty())
break;
strLine = strAll; if(posCR == ex_wstr::npos && posLF == ex_wstr::npos) {
strAll.clear(); if (strAll.empty())
break;
strLine = strAll;
strAll.clear();
} else if(posCR != ex_wstr::npos && posLF != ex_wstr::npos) {
if(posLF != posCR + 1) {
if(posLF < posCR) {
strLine.assign(strAll, 0, posLF);
strAll.erase(0, posLF + 1);
} else {
strLine.assign(strAll, 0, posCR);
strAll.erase(0, posCR + 1);
}
} else {
strLine.assign(strAll, 0, posCR);
strAll.erase(0, posCR + 2);
} }
else } else {
{ if(posCR != ex_wstr::npos) {
strLine.assign(strAll, 0, pos); strLine.assign(strAll, 0, posCR);
strAll.erase(0, pos + 1); strAll.erase(0, posCR + 1);
} else {
strLine.assign(strAll, 0, posLF);
strAll.erase(0, posLF + 1);
} }
} }
else
{ // if (ex_wstr::npos == pos)
strLine.assign(strAll, 0, pos); // {
strAll.erase(0, pos + 2); // pos = strAll.find(L'\n');
} // if (ex_wstr::npos == pos)
// {
// if (strAll.empty())
// break;
//
// strLine = strAll;
// strAll.clear();
// }
// else
// {
// strLine.assign(strAll, 0, pos);
// strAll.erase(0, pos + 1);
// }
// }
// else
// {
// strLine.assign(strAll, 0, pos);
// strAll.erase(0, pos + 2);
// }
if (ex_only_white_space(strLine)) if (ex_only_white_space(strLine))
continue; continue;

View File

@ -69,6 +69,9 @@ bool ExThreadBase::stop(void)
EXLOGV("[thread] wait thread [%s] end.\n", m_thread_name.c_str()); EXLOGV("[thread] wait thread [%s] end.\n", m_thread_name.c_str());
if(m_handle == 0)
return true;
#ifdef EX_OS_WIN32 #ifdef EX_OS_WIN32
if (WaitForSingleObject(m_handle, INFINITE) != WAIT_OBJECT_0) if (WaitForSingleObject(m_handle, INFINITE) != WAIT_OBJECT_0)
{ {

View File

@ -8,6 +8,8 @@
<file url="file://$PROJECT_DIR$/../common/libex/src/ex_ini.cpp" charset="GBK" /> <file url="file://$PROJECT_DIR$/../common/libex/src/ex_ini.cpp" charset="GBK" />
<file url="file://$PROJECT_DIR$/../common/libex/src/ex_log.cpp" charset="GBK" /> <file url="file://$PROJECT_DIR$/../common/libex/src/ex_log.cpp" charset="GBK" />
<file url="file://$PROJECT_DIR$/../common/libex/src/ex_util.cpp" charset="GBK" /> <file url="file://$PROJECT_DIR$/../common/libex/src/ex_util.cpp" charset="GBK" />
<file url="file://$PROJECT_DIR$/../common/pyshell/src/pys_api.cpp" charset="GBK" />
<file url="file://$PROJECT_DIR$/../common/pyshell/src/pys_core.cpp" charset="GBK" />
<file url="file://$PROJECT_DIR$/../common/teleport/teleport_const.h" charset="GBK" /> <file url="file://$PROJECT_DIR$/../common/teleport/teleport_const.h" charset="GBK" />
<file url="file://$PROJECT_DIR$/tp_core/common/base_env.h" charset="GBK" /> <file url="file://$PROJECT_DIR$/tp_core/common/base_env.h" charset="GBK" />
<file url="file://$PROJECT_DIR$/tp_core/common/base_record.cpp" charset="GBK" /> <file url="file://$PROJECT_DIR$/tp_core/common/base_record.cpp" charset="GBK" />
@ -26,8 +28,6 @@
<file url="file://$PROJECT_DIR$/tp_core/core/ts_session.h" charset="GBK" /> <file url="file://$PROJECT_DIR$/tp_core/core/ts_session.h" charset="GBK" />
<file url="file://$PROJECT_DIR$/tp_core/core/ts_web_rpc.cpp" charset="GBK" /> <file url="file://$PROJECT_DIR$/tp_core/core/ts_web_rpc.cpp" charset="GBK" />
<file url="file://$PROJECT_DIR$/tp_core/core/ts_web_rpc.h" charset="GBK" /> <file url="file://$PROJECT_DIR$/tp_core/core/ts_web_rpc.h" charset="GBK" />
<file url="file://$PROJECT_DIR$/tp_core/protocol/rdp/rdp_recorder.h" charset="GBK" />
<file url="file://$PROJECT_DIR$/tp_core/protocol/rdp/rdp_session.h" charset="GBK" />
<file url="file://$PROJECT_DIR$/tp_core/protocol/ssh/ssh_proxy.cpp" charset="GBK" /> <file url="file://$PROJECT_DIR$/tp_core/protocol/ssh/ssh_proxy.cpp" charset="GBK" />
<file url="file://$PROJECT_DIR$/tp_core/protocol/ssh/ssh_proxy.h" charset="GBK" /> <file url="file://$PROJECT_DIR$/tp_core/protocol/ssh/ssh_proxy.h" charset="GBK" />
<file url="file://$PROJECT_DIR$/tp_core/protocol/ssh/ssh_recorder.cpp" charset="GBK" /> <file url="file://$PROJECT_DIR$/tp_core/protocol/ssh/ssh_recorder.cpp" charset="GBK" />

View File

@ -76,8 +76,10 @@ bool TsEnv::init(bool load_config)
{ {
m_replay_path = replay_path; m_replay_path = replay_path;
} }
ex_mkdirs(m_replay_path);
ex_wstr log_file;
ex_wstr log_file;
if (!ps->GetStr(L"log-file", log_file)) if (!ps->GetStr(L"log-file", log_file))
{ {
EXLOG_FILE(L"tpcore.log", log_path.c_str()); EXLOG_FILE(L"tpcore.log", log_path.c_str());
@ -99,15 +101,15 @@ bool TsEnv::init(bool load_config)
} }
int log_level = EX_LOG_LEVEL_INFO; int log_level = EX_LOG_LEVEL_INFO;
if (ps->GetInt(L"log-level", log_level)) ps->GetInt(L"log-level", log_level, EX_LOG_LEVEL_INFO);
{ EXLOG_LEVEL(log_level);
EXLOG_LEVEL(log_level);
}
int debug_mode = 0; int debug_mode = 0;
ps->GetInt(L"debug-mode", debug_mode, 0); ps->GetInt(L"debug-mode", debug_mode, 0);
if (debug_mode == 1) if (debug_mode == 1) {
EXLOG_LEVEL(EX_LOG_LEVEL_DEBUG);
EXLOG_DEBUG(true); EXLOG_DEBUG(true);
}
ex_wstr tmp; ex_wstr tmp;

View File

@ -57,7 +57,7 @@ TsHttpRpc::~TsHttpRpc()
void TsHttpRpc::_thread_loop(void) void TsHttpRpc::_thread_loop(void)
{ {
EXLOGV("[core] TeleportServer-RPC ready on %s:%d\n", m_host_ip.c_str(), m_host_port); EXLOGI("[core] TeleportServer-RPC ready on %s:%d\n", m_host_ip.c_str(), m_host_port);
while (!m_stop_flag) while (!m_stop_flag)
{ {
@ -358,12 +358,12 @@ void TsHttpRpc::_rpc_func_request_session(const Json::Value& json_param, ex_astr
_create_json_ret(buf, rv); _create_json_ret(buf, rv);
return; return;
} }
// info->ref_count = 0; // info->ref_count = 0;
// info->ticket_start = ex_get_tick_count(); // info->ticket_start = ex_get_tick_count();
// //
// 生成一个session-id内部会避免重复 // 生成一个session-id内部会避免重复
ex_astr sid; ex_astr sid;
if (!g_session_mgr.request_session(sid, info)) { if (!g_session_mgr.request_session(sid, info)) {
_create_json_ret(buf, TPE_FAILED); _create_json_ret(buf, TPE_FAILED);
return; return;
@ -451,14 +451,14 @@ void TsHttpRpc::_rpc_func_enc(const Json::Value& json_param, ex_astr& buf)
Json::Value c; Json::Value c;
Json::Value p = json_param["p"]; Json::Value p = json_param["p"];
int cnt = p.size(); int cnt = p.size();
for (int i = 0; i < cnt; ++i) for (int i = 0; i < cnt; ++i)
{ {
if (!p[i].isString()) { if (!p[i].isString()) {
_create_json_ret(buf, TPE_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
ex_astr p_txt = p[i].asCString(); ex_astr p_txt = p[i].asCString();
if (p_txt.length() == 0) { if (p_txt.length() == 0) {
@ -471,7 +471,7 @@ void TsHttpRpc::_rpc_func_enc(const Json::Value& json_param, ex_astr& buf)
_create_json_ret(buf, TPE_FAILED); _create_json_ret(buf, TPE_FAILED);
return; return;
} }
c["c"].append(c_txt); c["c"].append(c_txt);
} }

View File

@ -80,7 +80,7 @@ void SshProxy::timer() {
void SshProxy::_thread_loop() void SshProxy::_thread_loop()
{ {
EXLOGV("[ssh] TeleportServer-SSH ready on %s:%d\n", m_host_ip.c_str(), m_host_port); EXLOGI("[ssh] TeleportServer-SSH ready on %s:%d\n", m_host_ip.c_str(), m_host_port);
for (;;) for (;;)
{ {

View File

@ -100,17 +100,15 @@ bool TsEnv::init(bool load_config)
int log_level = EX_LOG_LEVEL_INFO; int log_level = EX_LOG_LEVEL_INFO;
if (ps->GetInt(L"log-level", log_level)) if (ps->GetInt(L"log-level", log_level))
{ {
// EXLOGV("[tpweb] log-level: %d\n", log_level);
EXLOG_LEVEL(log_level); EXLOG_LEVEL(log_level);
} }
int debug_mode = 0; int debug_mode = 0;
if (ps->GetInt(L"debug-mode", debug_mode)) if (ps->GetInt(L"debug-mode", debug_mode))
{ {
// EXLOGV("[tpweb] debug-mode: %d\n", debug_mode);
// EXLOG_LEVEL(log_level);
if (1 == debug_mode) { if (1 == debug_mode) {
EXLOG_LEVEL(EX_LOG_LEVEL_DEBUG); EXLOG_LEVEL(EX_LOG_LEVEL_DEBUG);
EXLOG_DEBUG(true);
} }
} }