teleport/client/tp_assist/ts_http_rpc.h

122 lines
3.1 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 "ts_const.h"
#include <vector>
#include <string>
#include <map>
#include <ex.h>
#include <json/json.h>
#include "../../external/mongoose/mongoose.h"
typedef ex_u32 ts_rv;
#define TSR_OK 0x0000
#define TSR_INVALID_DATA 0x0001
#define TSR_SEND_ERROR 0x0002
#define TSR_NEED_MORE_DATA 0x0005
#define TSR_FAILED 0x0006
#define TSR_PING_OK 0x0007
#define TSR_PING_ERROR 0x0008
#define TSR_INVALID_REQUEST 0x1000
#define TSR_INVALID_URI 0x1001
#define TSR_INVALID_URL_ENCODE 0x1002
#define TSR_NO_SUCH_METHOD 0x1003
#define TSR_INVALID_JSON_FORMAT 0x1004
#define TSR_INVALID_JSON_PARAM 0x1005
#define TSR_CREATE_PROCESS_ERROR 0x1006
#define TSR_OPENFILE_ERROR 0x1007
#define TSR_GETTEMPPATH_ERROR 0x1007
/*
//=================================================================
接口使用说明:
本程序启动后,监听 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;
// struct sid_info
// {
// ex_astr host_ip;
// ex_astr s_id;
// bool update;
// };
// typedef std::map<DWORD, sid_info> PidSidMap;
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:
unsigned 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_create_ts_client(const ex_astr& func_args, ex_astr& buf);
void _rpc_func_ts_check(const ex_astr& func_args, ex_astr& buf);
void _rpc_func_ts_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__