From 4d5007e41338174e564f4b15500565880372a593 Mon Sep 17 00:00:00 2001 From: Apex Lu Date: Sun, 26 Nov 2017 04:44:06 +0800 Subject: [PATCH] fix ini parser not work when new line flag '\r\n' and '\n' in the same file. --- common/libex/src/ex_ini.cpp | 74 +++++++++++++++++------ common/libex/src/ex_thread.cpp | 3 + server/.idea/encodings.xml | 4 +- server/tp_core/core/ts_env.cpp | 14 +++-- server/tp_core/core/ts_http_rpc.cpp | 20 +++--- server/tp_core/protocol/ssh/ssh_proxy.cpp | 2 +- server/tp_web/src/ts_env.cpp | 6 +- 7 files changed, 80 insertions(+), 43 deletions(-) diff --git a/common/libex/src/ex_ini.cpp b/common/libex/src/ex_ini.cpp index cbd60fc..7660f7c 100644 --- a/common/libex/src/ex_ini.cpp +++ b/common/libex/src/ex_ini.cpp @@ -267,32 +267,66 @@ bool ExIniFile::LoadFromMemory(const ex_wstr& strData, bool bClearOld) ex_wstr strValue(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 (;;) { - pos = strAll.find(L"\r\n"); - if (ex_wstr::npos == pos) - { - pos = strAll.find(L'\n'); - if (ex_wstr::npos == pos) - { - if (strAll.empty()) - break; + posCR = ex_wstr::npos; + posLF = ex_wstr::npos; + posCR = strAll.find(L"\r"); + posLF = strAll.find(L"\n"); + int tttt = 0; - strLine = strAll; - strAll.clear(); + if(posCR == ex_wstr::npos && posLF == ex_wstr::npos) { + 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 - { - strLine.assign(strAll, 0, pos); - strAll.erase(0, pos + 1); + } else { + if(posCR != ex_wstr::npos) { + strLine.assign(strAll, 0, posCR); + strAll.erase(0, posCR + 1); + } else { + strLine.assign(strAll, 0, posLF); + strAll.erase(0, posLF + 1); } } - else - { - strLine.assign(strAll, 0, pos); - strAll.erase(0, pos + 2); - } + +// if (ex_wstr::npos == pos) +// { +// 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)) continue; diff --git a/common/libex/src/ex_thread.cpp b/common/libex/src/ex_thread.cpp index 4239cd2..3641a92 100644 --- a/common/libex/src/ex_thread.cpp +++ b/common/libex/src/ex_thread.cpp @@ -69,6 +69,9 @@ bool ExThreadBase::stop(void) EXLOGV("[thread] wait thread [%s] end.\n", m_thread_name.c_str()); + if(m_handle == 0) + return true; + #ifdef EX_OS_WIN32 if (WaitForSingleObject(m_handle, INFINITE) != WAIT_OBJECT_0) { diff --git a/server/.idea/encodings.xml b/server/.idea/encodings.xml index 771d14f..d2b2ef6 100644 --- a/server/.idea/encodings.xml +++ b/server/.idea/encodings.xml @@ -8,6 +8,8 @@ + + @@ -26,8 +28,6 @@ - - diff --git a/server/tp_core/core/ts_env.cpp b/server/tp_core/core/ts_env.cpp index 74f0783..82c834f 100644 --- a/server/tp_core/core/ts_env.cpp +++ b/server/tp_core/core/ts_env.cpp @@ -76,8 +76,10 @@ bool TsEnv::init(bool load_config) { 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)) { 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; - if (ps->GetInt(L"log-level", log_level)) - { - EXLOG_LEVEL(log_level); - } + ps->GetInt(L"log-level", log_level, EX_LOG_LEVEL_INFO); + EXLOG_LEVEL(log_level); int 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); + } ex_wstr tmp; diff --git a/server/tp_core/core/ts_http_rpc.cpp b/server/tp_core/core/ts_http_rpc.cpp index 199539a..241e10c 100644 --- a/server/tp_core/core/ts_http_rpc.cpp +++ b/server/tp_core/core/ts_http_rpc.cpp @@ -57,7 +57,7 @@ TsHttpRpc::~TsHttpRpc() 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) { @@ -358,12 +358,12 @@ void TsHttpRpc::_rpc_func_request_session(const Json::Value& json_param, ex_astr _create_json_ret(buf, rv); return; } - + // info->ref_count = 0; // info->ticket_start = ex_get_tick_count(); // // 生成一个session-id(内部会避免重复) - ex_astr sid; + ex_astr sid; if (!g_session_mgr.request_session(sid, info)) { _create_json_ret(buf, TPE_FAILED); return; @@ -451,14 +451,14 @@ void TsHttpRpc::_rpc_func_enc(const Json::Value& json_param, ex_astr& buf) Json::Value c; - Json::Value p = json_param["p"]; - int cnt = p.size(); - for (int i = 0; i < cnt; ++i) - { - if (!p[i].isString()) { + Json::Value p = json_param["p"]; + int cnt = p.size(); + for (int i = 0; i < cnt; ++i) + { + if (!p[i].isString()) { _create_json_ret(buf, TPE_PARAM); return; - } + } ex_astr p_txt = p[i].asCString(); 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); return; } - + c["c"].append(c_txt); } diff --git a/server/tp_core/protocol/ssh/ssh_proxy.cpp b/server/tp_core/protocol/ssh/ssh_proxy.cpp index 6d5f72e..f9124d9 100644 --- a/server/tp_core/protocol/ssh/ssh_proxy.cpp +++ b/server/tp_core/protocol/ssh/ssh_proxy.cpp @@ -80,7 +80,7 @@ void SshProxy::timer() { 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 (;;) { diff --git a/server/tp_web/src/ts_env.cpp b/server/tp_web/src/ts_env.cpp index b14378f..381b464 100644 --- a/server/tp_web/src/ts_env.cpp +++ b/server/tp_web/src/ts_env.cpp @@ -100,17 +100,15 @@ bool TsEnv::init(bool load_config) int log_level = EX_LOG_LEVEL_INFO; if (ps->GetInt(L"log-level", log_level)) { -// EXLOGV("[tpweb] log-level: %d\n", log_level); EXLOG_LEVEL(log_level); } int debug_mode = 0; if (ps->GetInt(L"debug-mode", debug_mode)) { -// EXLOGV("[tpweb] debug-mode: %d\n", debug_mode); -// EXLOG_LEVEL(log_level); if (1 == debug_mode) { - EXLOG_LEVEL(EX_LOG_LEVEL_DEBUG); + EXLOG_LEVEL(EX_LOG_LEVEL_DEBUG); + EXLOG_DEBUG(true); } }