2016-12-06 17:05:56 +00:00
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
//=================================================================
|
|
|
|
|
<EFBFBD>ӿ<EFBFBD>ʹ<EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 127.0.0.1:50022<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>http<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽҪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|
|
|
|
|
|
|
|
|
GET <EFBFBD><EFBFBD>ʽ
|
|
|
|
|
http://127.0.0.1:50022/method/json_param
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>json_param<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>url_encode<EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>json<EFBFBD><EFBFBD>ʽ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
POST <EFBFBD><EFBFBD>ʽ
|
|
|
|
|
http://127.0.0.1:50022/method
|
|
|
|
|
post<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>json_param
|
|
|
|
|
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>URI<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD>
|
|
|
|
|
method <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
json_param <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><EFBFBD>Ӳ<EFBFBD><EFBFBD><EFBFBD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BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>ݾ<EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void http_rpc_main_loop(void);
|
2017-03-08 06:24:58 +00:00
|
|
|
|
void http_rpc_stop(void);
|
2016-12-06 17:05:56 +00:00
|
|
|
|
|
|
|
|
|
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);
|
2017-03-08 06:24:58 +00:00
|
|
|
|
void stop(void);
|
2016-12-06 17:05:56 +00:00
|
|
|
|
|
|
|
|
|
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;
|
2017-03-08 06:24:58 +00:00
|
|
|
|
bool m_stop;
|
2016-12-06 17:05:56 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // __TS_HTTP_RPC_H__
|