整理代码,调整参数名称,避免混淆。

pull/105/head
Apex Liu 2017-08-21 17:32:17 +08:00
parent 191d007678
commit eef2ce4460
10 changed files with 230 additions and 210 deletions

View File

@ -17,20 +17,30 @@
typedef struct TPP_CONNECT_INFO typedef struct TPP_CONNECT_INFO
{ {
char* sid; char* sid;
// 与此连接信息相关的三个要素的ID
int user_id;
int host_id;
int account_id;
char* user_name; // 申请本次连接的用户名 char* user_name; // 申请本次连接的用户名
char* real_remote_host_ip; // 真正的远程主机IP如果是直接连接模式则与remote_host_ip相同 char* real_remote_host_ip; // 真正的远程主机IP如果是直接连接模式则与remote_host_ip相同
char* remote_host_ip; // 要连接的远程主机的IP如果是端口映射模式则为路由主机的IP char* remote_host_ip; // 要连接的远程主机的IP如果是端口映射模式则为路由主机的IP
int remote_host_port; // 要连接的远程主机的端口(如果是端口映射模式,则为路由主机的端口)
char* client_ip;
char* account_name; // 远程主机的账号 char* account_name; // 远程主机的账号
char* account_secret; // 远程主机账号的密码(或者私钥) char* account_secret; // 远程主机账号的密码(或者私钥)
char* user_param; char* account_param;
int remote_host_port; // 要连接的远程主机的端口(如果是端口映射模式,则为路由主机的端口)
int protocol_type; int protocol_type;
int protocol_sub_type; int protocol_sub_type;
//int auth_id;
int auth_type; int auth_type;
int sys_type; int sys_type;
int ref_count; // 这个连接信息的引用计数如果创建的连接信息从来未被使用则超过60秒后自动销毁
ex_u64 ticket_start; // 此连接信息的创建时间(用于超时未使用就销毁的功能) // int ref_count; // 这个连接信息的引用计数如果创建的连接信息从来未被使用则超过60秒后自动销毁
// ex_u64 ticket_start; // 此连接信息的创建时间(用于超时未使用就销毁的功能)
}TPP_CONNECT_INFO; }TPP_CONNECT_INFO;
typedef TPP_CONNECT_INFO* (*TPP_GET_CONNNECT_INFO_FUNC)(const char* sid); typedef TPP_CONNECT_INFO* (*TPP_GET_CONNNECT_INFO_FUNC)(const char* sid);

View File

@ -17,12 +17,11 @@ ExLogger g_ex_logger;
bool g_is_debug = false; bool g_is_debug = false;
#define RUN_UNKNOWN 0 #define RUN_UNKNOWN 0
#define RUN_CORE 1 #define RUN_CORE 1
#define RUN_INSTALL_SRV 2 #define RUN_INSTALL_SRV 2
#define RUN_UNINST_SRV 3 #define RUN_UNINST_SRV 3
static ex_u8 g_run_type = RUN_UNKNOWN; static ex_u8 g_run_type = RUN_UNKNOWN;
#define EOM_CORE_SERVICE_NAME L"Teleport Core Service" #define EOM_CORE_SERVICE_NAME L"Teleport Core Service"
static bool _run_daemon(void); static bool _run_daemon(void);

View File

@ -113,7 +113,7 @@ bool TsEnv::init(bool load_config)
if (!ps->GetStr(L"web-server-rpc", tmp)) if (!ps->GetStr(L"web-server-rpc", tmp))
{ {
web_server_rpc = "http://127.0.0.1:7190/rpc"; web_server_rpc = "http://localhost:7190/rpc";
} }
else else
{ {

View File

@ -1,108 +1,102 @@
#include "ts_http_client.h" #include "ts_http_client.h"
#include <mongoose.h> #include <mongoose.h>
#include <ex/ex_str.h> #include <ex/ex_str.h>
// #include<map> void ts_url_encode(const char *src, ex_astr& out)
// using namespace std; {
//map<unsigned int, unsigned int> session_map; static const char *dont_escape = "._-$,;~()/";
static const char *hex = "0123456789abcdef";
void ts_url_encode(const char *src, ex_astr& out)
{ size_t s_len = strlen(src);
static const char *dont_escape = "._-$,;~()/"; size_t dst_len = s_len * 3 + 1;
static const char *hex = "0123456789abcdef"; char* dst = new char[dst_len];
memset(dst, 0, dst_len);
size_t s_len = strlen(src);
size_t dst_len = s_len * 3 + 1; size_t i = 0, j = 0;
char* dst = new char[dst_len];
memset(dst, 0, dst_len); for (i = j = 0; dst_len > 0 && i < s_len && j + 2 < dst_len - 1; i++, j++) {
if (isalnum(*(const unsigned char *)(src + i)) ||
size_t i = 0, j = 0; strchr(dont_escape, *(const unsigned char *)(src + i)) != NULL) {
dst[j] = src[i];
for (i = j = 0; dst_len > 0 && i < s_len && j + 2 < dst_len - 1; i++, j++) { }
if (isalnum(*(const unsigned char *)(src + i)) || else if (j + 3 < dst_len) {
strchr(dont_escape, *(const unsigned char *)(src + i)) != NULL) { dst[j] = '%';
dst[j] = src[i]; dst[j + 1] = hex[(*(const unsigned char *)(src + i)) >> 4];
} dst[j + 2] = hex[(*(const unsigned char *)(src + i)) & 0xf];
else if (j + 3 < dst_len) { j += 2;
dst[j] = '%'; }
dst[j + 1] = hex[(*(const unsigned char *)(src + i)) >> 4]; }
dst[j + 2] = hex[(*(const unsigned char *)(src + i)) & 0xf];
j += 2; dst[j] = '\0';
} out = dst;
} delete []dst;
}
dst[j] = '\0';
out = dst; typedef struct HTTP_DATA {
delete []dst; bool exit_flag;
} bool have_error;
ex_astr body;
typedef struct HTTP_DATA { }HTTP_DATA;
bool exit_flag;
bool have_error; static void ev_handler(struct mg_connection *nc, int ev, void *ev_data)
ex_astr body; {
}HTTP_DATA; HTTP_DATA* hdata = (HTTP_DATA*)nc->user_data;
struct http_message *hm = (struct http_message *) ev_data;
//int s_exit_flag = 0;
switch (ev) {
static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) case MG_EV_CONNECT:
{ if (*(int *)ev_data != 0) {
HTTP_DATA* hdata = (HTTP_DATA*)nc->user_data; hdata->exit_flag = true;
struct http_message *hm = (struct http_message *) ev_data; hdata->have_error = true;
}
switch (ev) { break;
case MG_EV_CONNECT: case MG_EV_HTTP_REPLY:
if (*(int *)ev_data != 0) { nc->flags |= MG_F_CLOSE_IMMEDIATELY;
hdata->exit_flag = true; hdata->exit_flag = true;
hdata->have_error = true; hdata->body.assign(hm->body.p, hm->body.len);
} break;
break; case MG_EV_CLOSE:
case MG_EV_HTTP_REPLY: // if (s_exit_flag == 0) {
nc->flags |= MG_F_CLOSE_IMMEDIATELY; // printf("Server closed connection\n");
hdata->exit_flag = true; // s_exit_flag = 1;
hdata->body.assign(hm->body.p, hm->body.len); // }
break; hdata->exit_flag = true;
case MG_EV_CLOSE: break;
// if (s_exit_flag == 0) { default:
// printf("Server closed connection\n"); break;
// s_exit_flag = 1; }
// } }
hdata->exit_flag = true;
break; bool ts_http_get(const ex_astr& url, ex_astr& body)
default: {
break; struct mg_mgr mgr;
} mg_mgr_init(&mgr, NULL);
}
mg_connection* nc = mg_connect_http(&mgr, ev_handler, url.c_str(), NULL, NULL);
bool ts_http_get(const ex_astr& url, ex_astr& body) if (NULL == nc)
{ return false;
struct mg_mgr mgr;
mg_mgr_init(&mgr, NULL); HTTP_DATA* hdata = new HTTP_DATA;
hdata->exit_flag = false;
mg_connection* nc = mg_connect_http(&mgr, ev_handler, url.c_str(), NULL, NULL); hdata->have_error = false;
if (NULL == nc)
return false; nc->user_data = hdata;
HTTP_DATA* hdata = new HTTP_DATA; // int count = 0;
hdata->exit_flag = false; while (!hdata->exit_flag)
hdata->have_error = false; {
mg_mgr_poll(&mgr, 100);
nc->user_data = hdata; // count++;
// if (count > 2)
// int count = 0; // break;
while (!hdata->exit_flag) }
{
mg_mgr_poll(&mgr, 100); bool ret = !hdata->have_error;
// count++; if (ret)
// if (count > 2) body = hdata->body;
// break;
} delete hdata;
mg_mgr_free(&mgr);
bool ret = !hdata->have_error; return ret;
if (ret) }
body = hdata->body;
delete hdata;
mg_mgr_free(&mgr);
return ret;
}

View File

@ -9,42 +9,45 @@
bool g_exit_flag = false; bool g_exit_flag = false;
TPP_CONNECT_INFO* tpp_get_session(const char* sid) TPP_CONNECT_INFO* tpp_get_connect_info(const char* sid)
{ {
TS_SESSION_INFO sinfo; TS_CONNECT_INFO sinfo;
bool ret = g_session_mgr.take_session(sid, sinfo); bool ret = g_session_mgr.get_connect_info(sid, sinfo);
if (!ret) if (!ret)
return NULL; return NULL;
TPP_CONNECT_INFO* info = (TPP_CONNECT_INFO*)calloc(1, sizeof(TPP_CONNECT_INFO)); TPP_CONNECT_INFO* info = (TPP_CONNECT_INFO*)calloc(1, sizeof(TPP_CONNECT_INFO));
info->sid = (char*)calloc(1, sinfo.sid.length() + 1); info->sid = (char*)calloc(1, sinfo.sid.length() + 1);
ex_strcpy(info->sid, sinfo.sid.length() + 1, sinfo.sid.c_str()); ex_strcpy(info->sid, sinfo.sid.length() + 1, sinfo.sid.c_str());
info->account_name = (char*)calloc(1, sinfo.account_name.length() + 1);
ex_strcpy(info->account_name, sinfo.account_name.length() + 1, sinfo.account_name.c_str());
info->real_remote_host_ip = (char*)calloc(1, sinfo.host_ip.length() + 1);
ex_strcpy(info->real_remote_host_ip, sinfo.host_ip.length() + 1, sinfo.host_ip.c_str());
info->remote_host_ip = (char*)calloc(1, sinfo.host_ip.length() + 1);
ex_strcpy(info->remote_host_ip, sinfo.host_ip.length() + 1, sinfo.host_ip.c_str());
info->user_name = (char*)calloc(1, sinfo.user_name.length() + 1); info->user_name = (char*)calloc(1, sinfo.user_name.length() + 1);
ex_strcpy(info->user_name, sinfo.user_name.length() + 1, sinfo.user_name.c_str()); ex_strcpy(info->user_name, sinfo.user_name.length() + 1, sinfo.user_name.c_str());
info->account_secret = (char*)calloc(1, sinfo.user_auth.length() + 1); info->real_remote_host_ip = (char*)calloc(1, sinfo.real_remote_host_ip.length() + 1);
ex_strcpy(info->account_secret, sinfo.user_auth.length() + 1, sinfo.user_auth.c_str()); ex_strcpy(info->real_remote_host_ip, sinfo.real_remote_host_ip.length() + 1, sinfo.real_remote_host_ip.c_str());
info->user_param = (char*)calloc(1, sinfo.user_param.length() + 1); info->remote_host_ip = (char*)calloc(1, sinfo.remote_host_ip.length() + 1);
ex_strcpy(info->user_param, sinfo.user_param.length() + 1, sinfo.user_param.c_str()); ex_strcpy(info->remote_host_ip, sinfo.remote_host_ip.length() + 1, sinfo.remote_host_ip.c_str());
info->client_ip = (char*)calloc(1, sinfo.client_ip.length() + 1);
ex_strcpy(info->client_ip, sinfo.client_ip.length() + 1, sinfo.client_ip.c_str());
info->account_name = (char*)calloc(1, sinfo.account_name.length() + 1);
ex_strcpy(info->account_name, sinfo.account_name.length() + 1, sinfo.account_name.c_str());
info->account_secret = (char*)calloc(1, sinfo.account_secret.length() + 1);
ex_strcpy(info->account_secret, sinfo.account_secret.length() + 1, sinfo.account_secret.c_str());
info->account_param = (char*)calloc(1, sinfo.account_param.length() + 1);
ex_strcpy(info->account_param, sinfo.account_param.length() + 1, sinfo.account_param.c_str());
//info->auth_id = sinfo.auth_id; info->user_id = sinfo.user_id;
info->remote_host_port = sinfo.host_port; info->host_id = sinfo.host_id;
info->protocol_type = sinfo.protocol; info->account_id = sinfo.account_id;
info->auth_type= sinfo.auth_mode; info->remote_host_port = sinfo.remote_host_port;
info->protocol_type = sinfo.protocol_type;
info->protocol_sub_type = sinfo.protocol_sub_type;
info->auth_type= sinfo.auth_type;
info->sys_type = sinfo.sys_type; info->sys_type = sinfo.sys_type;
info->ref_count = sinfo.ref_count;
info->ticket_start = sinfo.ticket_start;
return info; return info;
} }
void tpp_free_session(TPP_CONNECT_INFO* info) void tpp_free_connect_info(TPP_CONNECT_INFO* info)
{ {
if (NULL == info) if (NULL == info)
return; return;
@ -53,9 +56,10 @@ void tpp_free_session(TPP_CONNECT_INFO* info)
free(info->user_name); free(info->user_name);
free(info->real_remote_host_ip); free(info->real_remote_host_ip);
free(info->remote_host_ip); free(info->remote_host_ip);
free(info->client_ip);
free(info->account_name); free(info->account_name);
free(info->account_secret); free(info->account_secret);
free(info->user_param); free(info->account_param);
free(info); free(info);
} }
@ -64,20 +68,19 @@ bool tpp_session_begin(const TPP_CONNECT_INFO* info, int* db_id)
if (NULL == info || NULL == db_id) if (NULL == info || NULL == db_id)
return false; return false;
TS_SESSION_INFO sinfo; TS_CONNECT_INFO sinfo;
sinfo.sid = info->sid; sinfo.sid = info->sid;
sinfo.account_name = info->account_name;
sinfo.auth_id = info->auth_id;
sinfo.host_ip = info->host_ip;
sinfo.host_port = info->host_port;
sinfo.protocol = info->protocol;
sinfo.user_name = info->user_name; sinfo.user_name = info->user_name;
sinfo.user_auth = info->user_auth; sinfo.real_remote_host_ip = info->real_remote_host_ip;
sinfo.user_param = info->user_param; sinfo.remote_host_ip = info->remote_host_ip;
sinfo.auth_mode = info->auth_mode; sinfo.client_ip = info->client_ip;
sinfo.account_name = info->account_name;
sinfo.remote_host_port = info->remote_host_port;
sinfo.protocol_type = info->protocol_type;
sinfo.protocol_sub_type = info->protocol_sub_type;
sinfo.auth_type = info->auth_type;
sinfo.sys_type = info->sys_type; sinfo.sys_type = info->sys_type;
sinfo.ref_count = info->ref_count;
sinfo.ticket_start = info->ticket_start;
return ts_web_rpc_session_begin(sinfo, *db_id); return ts_web_rpc_session_begin(sinfo, *db_id);
} }
@ -184,8 +187,8 @@ bool TppManager::load_tpp(const ex_wstr& libname)
init_args.etc_path = g_env.m_etc_path; init_args.etc_path = g_env.m_etc_path;
init_args.replay_path = g_env.m_replay_path; init_args.replay_path = g_env.m_replay_path;
init_args.cfg = &g_env.get_ini(); init_args.cfg = &g_env.get_ini();
init_args.func_take_session = tpp_take_session; init_args.func_get_connect_info = tpp_get_connect_info;
init_args.func_free_session = tpp_free_session; init_args.func_free_connect_info = tpp_free_connect_info;
init_args.func_session_begin = tpp_session_begin; init_args.func_session_begin = tpp_session_begin;
init_args.func_session_end = tpp_session_end; init_args.func_session_end = tpp_session_end;

View File

@ -13,12 +13,12 @@ TsSessionManager::TsSessionManager() :
TsSessionManager::~TsSessionManager() TsSessionManager::~TsSessionManager()
{ {
ts_sessiones::iterator it = m_sessions.begin(); ts_connections::iterator it_conn = m_connections.begin();
for (; it != m_sessions.end(); ++it) for (; it_conn != m_connections.end(); ++it_conn)
{ {
delete it->second; delete it_conn->second;
} }
m_sessions.clear(); m_connections.clear();
} }
void TsSessionManager::_thread_loop(void) void TsSessionManager::_thread_loop(void)
@ -28,7 +28,7 @@ void TsSessionManager::_thread_loop(void)
ex_sleep_ms(1000); ex_sleep_ms(1000);
if (m_stop_flag) if (m_stop_flag)
return; return;
_check_sessions(); _check_connect_info();
} }
} }
@ -38,25 +38,25 @@ void TsSessionManager::_set_stop_flag(void)
} }
void TsSessionManager::_check_sessions(void) void TsSessionManager::_check_connect_info(void)
{ {
// 超过10秒未进行连接的session-id会被移除 // 超过30秒未进行连接的connect-info会被移除
ExThreadSmartLock locker(m_lock); ExThreadSmartLock locker(m_lock);
ex_u64 _now = ex_get_tick_count(); ex_u64 _now = ex_get_tick_count();
ts_sessiones::iterator it = m_sessions.begin(); ts_connections::iterator it = m_connections.begin();
for (; it != m_sessions.end(); ) for (; it != m_connections.end(); )
{ {
#ifdef EX_DEBUG #ifdef EX_DEBUG
if (_now - it->second->ticket_start >= 60*1000*60) if (it->second->ref_count == 0 && _now - it->second->ticket_start >= 60*1000*60)
#else #else
if (_now - it->second->ticket_start >= 10000) if (it->second->ref_count == 0 && _now - it->second->ticket_start >= 30000)
#endif #endif
{ {
EXLOGV("[core] remove session: %s\n", it->first.c_str()); EXLOGV("[core] remove connection info: %s\n", it->first.c_str());
delete it->second; delete it->second;
m_sessions.erase(it++); m_connections.erase(it++);
} }
else else
{ {
@ -98,19 +98,19 @@ ex_rv TsSessionManager::request_session(
EXLOGD("[core] request session: user-name: [%s], protocol: [%d], auth-mode: [%d]\n", info->user_name.c_str(), info->protocol, info->auth_mode); EXLOGD("[core] request session: user-name: [%s], protocol: [%d], auth-mode: [%d]\n", info->user_name.c_str(), info->protocol, info->auth_mode);
if (_add_session(sid, info)) if (_add_connect_info(sid, info))
return EXRV_OK; return EXRV_OK;
delete info; delete info;
return EXRV_FAILED; return EXRV_FAILED;
} }
bool TsSessionManager::get_session(const ex_astr& sid, TS_SESSION_INFO& info) bool TsSessionManager::get_connect_info(const ex_astr& sid, TS_CONNECT_INFO& info)
{ {
ExThreadSmartLock locker(m_lock); ExThreadSmartLock locker(m_lock);
ts_sessiones::iterator it = m_sessions.find(sid); ts_connections::iterator it = m_connections.find(sid);
if (it == m_sessions.end()) if (it == m_connections.end())
return false; return false;
info.sid = it->second->sid; info.sid = it->second->sid;
@ -139,18 +139,18 @@ bool TsSessionManager::get_session(const ex_astr& sid, TS_SESSION_INFO& info)
return true; return true;
} }
bool TsSessionManager::_add_session(ex_astr& sid, TS_SESSION_INFO* info) bool TsSessionManager::_add_connect_info(ex_astr& sid, TS_CONNECT_INFO* info)
{ {
ExThreadSmartLock locker(m_lock); ExThreadSmartLock locker(m_lock);
ex_astr _sid; ex_astr _sid;
int retried = 0; int retried = 0;
ts_sessiones::iterator it; ts_connections::iterator it;
for (;;) for (;;)
{ {
_gen_session_id(_sid, info, 6); _gen_session_id(_sid, info, 6);
it = m_sessions.find(_sid); it = m_connections.find(_sid);
if (it == m_sessions.end()) if (it == m_connections.end())
break; break;
retried++; retried++;
@ -159,20 +159,20 @@ bool TsSessionManager::_add_session(ex_astr& sid, TS_SESSION_INFO* info)
} }
info->sid = _sid; info->sid = _sid;
m_sessions.insert(std::make_pair(_sid, info)); m_connections.insert(std::make_pair(_sid, info));
sid = _sid; sid = _sid;
if (info->protocol == 1) if (info->protocol_type == TP_PROTOCOL_TYPE_RDP)
{ {
char szTmp[8] = { 0 }; char szTmp[8] = { 0 };
snprintf(szTmp, 8, "%02X", (unsigned char)(info->user_name.length() + info->user_auth.length())); snprintf(szTmp, 8, "%02X", (unsigned char)(info->account_name.length() + info->account_secret.length()));
sid += szTmp; sid += szTmp;
} }
return true; return true;
} }
void TsSessionManager::_gen_session_id(ex_astr& sid, const TS_SESSION_INFO* info, int len) void TsSessionManager::_gen_session_id(ex_astr& sid, const TS_CONNECT_INFO* info, int len)
{ {
mbedtls_sha1_context sha; mbedtls_sha1_context sha;
ex_u8 sha_digist[20] = { 0 }; ex_u8 sha_digist[20] = { 0 };
@ -184,8 +184,9 @@ void TsSessionManager::_gen_session_id(ex_astr& sid, const TS_SESSION_INFO* info
mbedtls_sha1_starts(&sha); mbedtls_sha1_starts(&sha);
mbedtls_sha1_update(&sha, (const unsigned char*)&_tick, sizeof(ex_u64)); mbedtls_sha1_update(&sha, (const unsigned char*)&_tick, sizeof(ex_u64));
mbedtls_sha1_update(&sha, (const unsigned char*)&_tid, sizeof(ex_u64)); mbedtls_sha1_update(&sha, (const unsigned char*)&_tid, sizeof(ex_u64));
mbedtls_sha1_update(&sha, (const unsigned char*)info->host_ip.c_str(), info->host_ip.length()); mbedtls_sha1_update(&sha, (const unsigned char*)info->remote_host_ip.c_str(), info->remote_host_ip.length());
mbedtls_sha1_update(&sha, (const unsigned char*)info->user_name.c_str(), info->user_name.length()); mbedtls_sha1_update(&sha, (const unsigned char*)info->client_ip.c_str(), info->client_ip.length());
mbedtls_sha1_update(&sha, (const unsigned char*)info->account_name.c_str(), info->account_name.length());
mbedtls_sha1_finish(&sha, sha_digist); mbedtls_sha1_finish(&sha, sha_digist);
mbedtls_sha1_free(&sha); mbedtls_sha1_free(&sha);

View File

@ -6,26 +6,36 @@
#include <ex.h> #include <ex.h>
typedef struct TS_SESSION_INFO typedef struct TS_CONNECT_INFO
{ {
ex_astr sid; ex_astr sid;
ex_astr account_name; // ÉêÇë±¾´ÎÁ¬½ÓµÄÓû§Ãû
//int auth_id; // 与此连接信息相关的三个要素的ID
ex_astr host_ip; int user_id;
int host_port; int host_id;
int protocol; int account_id;
ex_astr user_name;
ex_astr user_auth; ex_astr user_name;// 申请本次连接的用户名
ex_astr user_param;
int auth_mode; ex_astr real_remote_host_ip;// 真正的远程主机IP如果是直接连接模式则与remote_host_ip相同
ex_astr remote_host_ip;// 要连接的远程主机的IP如果是端口映射模式则为路由主机的IP
int remote_host_port;// 要连接的远程主机的端口(如果是端口映射模式,则为路由主机的端口)
ex_astr client_ip;
ex_astr account_name; // 远程主机的账号
ex_astr account_secret;// 远程主机账号的密码(或者私钥)
ex_astr account_param;
int protocol_type;
int protocol_sub_type;
int auth_type;
int sys_type; int sys_type;
int ref_count;// 这个连接信息的引用计数如果创建的连接信息从来未被使用则超过30秒后自动销毁
ex_u64 ticket_start;// 此连接信息的创建时间(用于超时未使用就销毁的功能)
}TS_CONNECT_INFO;
int ref_count; typedef std::map<ex_astr, TS_CONNECT_INFO*> ts_connections;
ex_u64 ticket_start;
}TS_SESSION_INFO;
typedef std::map<ex_astr, TS_SESSION_INFO*> ts_sessiones;
class TsSessionManager : public ExThreadBase class TsSessionManager : public ExThreadBase
{ {
@ -49,7 +59,7 @@ public:
); );
// 根据sid得到session信息 // 根据sid得到session信息
bool get_session(const ex_astr& sid, TS_SESSION_INFO& info); bool get_connect_info(const ex_astr& sid, TS_CONNECT_INFO& info);
protected: protected:
// 线程循环 // 线程循环
@ -58,13 +68,13 @@ protected:
void _set_stop_flag(void); void _set_stop_flag(void);
private: private:
bool _add_session(ex_astr& sid, TS_SESSION_INFO* info); void _gen_session_id(ex_astr& sid, const TS_CONNECT_INFO* info, int len);
void _gen_session_id(ex_astr& sid, const TS_SESSION_INFO* info, int len); bool _add_connect_info(ex_astr& sid, TS_CONNECT_INFO* info);
void _check_sessions(void); void _check_connect_info(void);
private: private:
ExThreadLock m_lock; ExThreadLock m_lock;
ts_sessiones m_sessions; ts_connections m_connections;
}; };
extern TsSessionManager g_session_mgr; extern TsSessionManager g_session_mgr;

View File

@ -92,20 +92,23 @@ int ts_web_rpc_get_conn_info(int conn_id, Json::Value& jret)
return TPE_OK; return TPE_OK;
} }
bool ts_web_rpc_session_begin(TS_SESSION_INFO& info, int& record_id) bool ts_web_rpc_session_begin(TS_CONNECT_INFO& info, int& record_id)
{ {
Json::FastWriter json_writer; Json::FastWriter json_writer;
Json::Value jreq; Json::Value jreq;
jreq["method"] = "session_begin"; jreq["method"] = "session_begin";
jreq["param"]["sid"] = info.sid.c_str(); jreq["param"]["sid"] = info.sid.c_str();
jreq["param"]["account_name"] = info.account_name.c_str();
jreq["param"]["host_ip"] = info.host_ip.c_str();
jreq["param"]["sys_type"] = info.sys_type;
jreq["param"]["host_port"] = info.host_port;
jreq["param"]["auth_mode"] = info.auth_mode,
jreq["param"]["user_name"] = info.user_name.c_str(); jreq["param"]["user_name"] = info.user_name.c_str();
jreq["param"]["protocol"] = info.protocol; jreq["param"]["account_name"] = info.account_name.c_str();
jreq["param"]["real_remote_host_ip"] = info.real_remote_host_ip.c_str();
jreq["param"]["remote_host_ip"] = info.remote_host_ip.c_str();
jreq["param"]["client_ip"] = info.client_ip.c_str();
jreq["param"]["sys_type"] = info.sys_type;
jreq["param"]["remote_host_port"] = info.remote_host_port;
jreq["param"]["auth_type"] = info.auth_type;
jreq["param"]["protocol_type"] = info.protocol_type;
jreq["param"]["protocol_sub_type"] = info.protocol_sub_type;
ex_astr json_param; ex_astr json_param;
json_param = json_writer.write(jreq); json_param = json_writer.write(jreq);

View File

@ -12,7 +12,7 @@ bool ts_web_rpc_register_core();
int ts_web_rpc_get_conn_info(int conn_id, Json::Value& jret); int ts_web_rpc_get_conn_info(int conn_id, Json::Value& jret);
// 记录会话的开始 // 记录会话的开始
bool ts_web_rpc_session_begin(TS_SESSION_INFO& info, int& record_id); bool ts_web_rpc_session_begin(TS_CONNECT_INFO& info, int& record_id);
//session 结束 //session 结束
bool ts_web_rpc_session_end(const char* sid, int id, int ret_code); bool ts_web_rpc_session_end(const char* sid, int id, int ret_code);

View File

@ -228,7 +228,7 @@ int SshSession::_on_auth_password_request(ssh_session session, const char *user,
EXLOGV("[ssh] authenticating, session-id: %s\n", _this->m_sid.c_str()); EXLOGV("[ssh] authenticating, session-id: %s\n", _this->m_sid.c_str());
int protocol = 0; int protocol = 0;
TPP_CONNECT_INFO* sess_info = g_ssh_env.get_session(_this->m_sid.c_str()); TPP_CONNECT_INFO* sess_info = g_ssh_env.get_connect_info(_this->m_sid.c_str());
if (NULL == sess_info) { if (NULL == sess_info) {
// EXLOGW("[ssh] try to get login-info from ssh-sftp-session.\n"); // EXLOGW("[ssh] try to get login-info from ssh-sftp-session.\n");
@ -261,7 +261,7 @@ int SshSession::_on_auth_password_request(ssh_session session, const char *user,
} }
if (protocol != TP_PROTOCOL_TYPE_SSH) { if (protocol != TP_PROTOCOL_TYPE_SSH) {
g_ssh_env.free_session(sess_info); g_ssh_env.free_connect_info(sess_info);
EXLOGE("[ssh] session '%s' is not for SSH.\n", _this->m_sid.c_str()); EXLOGE("[ssh] session '%s' is not for SSH.\n", _this->m_sid.c_str());
_this->m_have_error = true; _this->m_have_error = true;
_this->m_retcode = TP_SESS_STAT_ERR_AUTH_DENIED; _this->m_retcode = TP_SESS_STAT_ERR_AUTH_DENIED;
@ -270,13 +270,13 @@ int SshSession::_on_auth_password_request(ssh_session session, const char *user,
if (!_this->_on_session_begin(sess_info)) if (!_this->_on_session_begin(sess_info))
{ {
g_ssh_env.free_session(sess_info); g_ssh_env.free_connect_info(sess_info);
_this->m_have_error = true; _this->m_have_error = true;
_this->m_retcode = TP_SESS_STAT_ERR_AUTH_DENIED; _this->m_retcode = TP_SESS_STAT_ERR_AUTH_DENIED;
return SSH_AUTH_DENIED; return SSH_AUTH_DENIED;
} }
g_ssh_env.free_session(sess_info); g_ssh_env.free_connect_info(sess_info);
sess_info = NULL; sess_info = NULL;
// 现在尝试根据session-id获取得到的信息连接并登录真正的SSH服务器 // 现在尝试根据session-id获取得到的信息连接并登录真正的SSH服务器