修正:核心服务接收POST请求时根据第一个字符是否为%来决定是否要进行url_decode,以支持curl命令行调用和tp_web调用两种情况。

pull/173/head
Apex Liu 2018-12-28 02:27:56 +08:00
parent 8c354ec02c
commit e3f57d7b96
3 changed files with 14 additions and 14 deletions

Binary file not shown.

View File

@ -176,9 +176,18 @@ ex_rv TsHttpRpc::_parse_request(struct http_message* req, ex_astr& func_cmd, Jso
return TPE_HTTP_METHOD;
ex_astr json_str;
bool need_decode = false;
if (is_get) {
json_str.assign(req->query_string.p, req->query_string.len);
need_decode = true;
}
else {
json_str.assign(req->body.p, req->body.len);
if (json_str.length() > 0 && json_str[0] == '%')
need_decode = true;
}
if (need_decode) {
// 将参数进行 url-decode 解码
int len = json_str.length() * 2;
ex_chars sztmp;
@ -189,9 +198,6 @@ ex_rv TsHttpRpc::_parse_request(struct http_message* req, ex_astr& func_cmd, Jso
json_str = &sztmp[0];
}
else {
json_str.assign(req->body.p, req->body.len);
}
if (0 == json_str.length())
return TPE_PARAM;
@ -331,7 +337,7 @@ void TsHttpRpc::_rpc_func_get_config(const Json::Value& json_param, ex_astr& buf
void TsHttpRpc::_rpc_func_request_session(const Json::Value& json_param, ex_astr& buf)
{
// https://github.com/eomsoft/teleport/wiki/TELEPORT-CORE-JSON-RPC#request_session
// https://github.com/tp4a/teleport/wiki/TELEPORT-CORE-JSON-RPC#request_session
int conn_id = 0;
ex_rv rv = TPE_OK;
@ -414,7 +420,7 @@ void TsHttpRpc::_rpc_func_kill_sessions(const Json::Value& json_param, ex_astr&
void TsHttpRpc::_rpc_func_enc(const Json::Value& json_param, ex_astr& buf)
{
// https://github.com/eomsoft/teleport/wiki/TELEPORT-CORE-JSON-RPC#enc
// https://github.com/tp4a/teleport/wiki/TELEPORT-CORE-JSON-RPC#enc
// 加密一个字符串 [ p=plain-text, c=cipher-text ]
// 入参: {"p":"need be encrypt"}
// 示例: {"p":"this-is-a-password"}
@ -459,7 +465,7 @@ void TsHttpRpc::_rpc_func_enc(const Json::Value& json_param, ex_astr& buf)
void TsHttpRpc::_rpc_func_set_config(const Json::Value& json_param, ex_astr& buf)
{
// https://github.com/eomsoft/teleport/wiki/TELEPORT-CORE-JSON-RPC#set_config
// https://github.com/tp4a/teleport/wiki/TELEPORT-CORE-JSON-RPC#set_config
/*
{
"noop-timeout": 15 #
@ -477,11 +483,6 @@ void TsHttpRpc::_rpc_func_set_config(const Json::Value& json_param, ex_astr& buf
}
int noop_timeout = json_param["noop_timeout"].asUInt();
// if (noop_timeout == 0) {
// _create_json_ret(buf, TPE_PARAM);
// return;
// }
EXLOGV("[core] set run-time config:\n");
EXLOGV("[core] noop_timeout = %dm\n", noop_timeout);
@ -495,7 +496,7 @@ void TsHttpRpc::_rpc_func_set_config(const Json::Value& json_param, ex_astr& buf
/*
void TsHttpRpc::_rpc_func_enc(const Json::Value& json_param, ex_astr& buf)
{
// https://github.com/eomsoft/teleport/wiki/TELEPORT-CORE-JSON-RPC#enc
// https://github.com/tp4a/teleport/wiki/TELEPORT-CORE-JSON-RPC#enc
// 加密多个个字符串 [ p=plain-text, c=cipher-text ]
// 入参: {"p":["need be encrypt", "plain to cipher"]}
// 示例: {"p":["password-for-A"]}

View File

@ -7,8 +7,7 @@
#include <json/json.h>
// JSON-RPC documentation at:
// https://github.com/eomsoft/teleport/wiki/TELEPORT-CORE-JSON-RPC
// https://github.com/tp4a/teleport/wiki/TELEPORT-CORE-JSON-RPC
class TsHttpRpc : public ExThreadBase
{