teleport/client/tp_assist_win/ts_http_rpc.h

94 lines
2.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#ifndef __TS_HTTP_RPC_H__
#define __TS_HTTP_RPC_H__
#include "../../external/mongoose/mongoose.h"
#include "ts_const.h"
#include <vector>
#include <string>
#include <map>
#include <ex.h>
#include <json/json.h>
/*
//=================================================================
接口使用说明:
本程序启动后,监听 127.0.0.1:50022接收http请求请求格式要求如下
GET 方式
http://127.0.0.1:50022/method/json_param
其中json_param是使用url_encode进行编码后的json格式字符串
POST 方式
http://127.0.0.1:50022/method
post的数据区域是json_param
其中URI分为三个部分
method 请求执行的任务方法。
json_param 此任务方法的附加参数,如果没有附加参数,这部分可以省略。
返回格式执行结束后返回一个json格式的字符串给请求者格式如下
{"code":0,"data":varb}
其中code是必有的其值是一个错误编码0表示成功。如果失败则可能没有data域。操作成功时data域就是
操作的返回数据,其格式根据具体执行的任务方法不同而不同。
*/
void http_rpc_main_loop(void);
void http_rpc_stop(void);
typedef std::map<ex_astr, ex_astr> content_type_map;
class TsHttpRpc
{
public:
TsHttpRpc();
~TsHttpRpc();
bool init(const char* ip, int port);
void run(void);
void stop(void);
ex_astr get_content_type(ex_astr file_suffix)
{
content_type_map::iterator it = m_content_type_map.find(file_suffix);
if (it != m_content_type_map.end())
{
return it->second;
}
else
{
return "application/octet-stream";
}
};
private:
int _parse_request(struct http_message* req, ex_astr& func_cmd, ex_astr& func_args);
void _process_js_request(const ex_astr& func_cmd, const ex_astr& func_args, ex_astr& buf);
void _create_json_ret(ex_astr& buf, int errcode);
void _create_json_ret(ex_astr& buf, Json::Value& jr_root);
void _rpc_func_run_client(const ex_astr& func_args, ex_astr& buf);
// void _rpc_func_check(const ex_astr& func_args, ex_astr& buf);
void _rpc_func_rdp_play(const ex_astr& func_args, ex_astr& buf);
void _rpc_func_get_config(const ex_astr& func_args, ex_astr& buf);
void _rpc_func_set_config(const ex_astr& func_args, ex_astr& buf);
void _rpc_func_file_action(const ex_astr& func_args, ex_astr& buf);
void _rpc_func_get_version(const ex_astr& func_args, ex_astr& buf);
static void _mg_event_handler(struct mg_connection *nc, int ev, void *ev_data);
private:
content_type_map m_content_type_map;
struct mg_mgr m_mg_mgr;
bool m_stop;
};
#endif // __TS_HTTP_RPC_H__