Skip to content

Commit 4e70051

Browse files
committed
added:authorize verification support with http authorize
1 parent 3d38019 commit 4e70051

File tree

6 files changed

+93
-60
lines changed

6 files changed

+93
-60
lines changed

XEngine_Release/XEngine_Config/XEngine_Config.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"LogType":17
2424
},
2525
"XSql":{
26-
"SQLAddr":"10.0.2.6",
26+
"SQLAddr":"10.0.4.150",
2727
"SQLPort":3306,
2828
"SQLUser":"root",
2929
"SQLPass":"123123aa"
@@ -39,9 +39,14 @@
3939
"bDataQueryEnable":true,
4040
"bDataInsertEnable":true,
4141
"bUserQueryEnable":true,
42-
"nTimeLast":60,
42+
"nTimeLast":3600,
4343
"nTimeCount":0
4444
},
45+
"XAuthorize":{
46+
"bHTTPAuth":false,
47+
"tszHTTPPass":"",
48+
"tszToken":"XENGINE_MQPasskey"
49+
},
4550
"XReport":{
4651
"bEnable":true,
4752
"tszServiceName":"XEngine_MQService",

XEngine_Source/MQCore_ConfigModule/Config_Define.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ typedef struct
6464
int nTimeLast;
6565
int nTimeCount;
6666
}st_XMemory;
67+
struct
68+
{
69+
bool bHTTPAuth;
70+
XCHAR tszHTTPPass[MAX_PATH];
71+
XCHAR tszToken[MAX_PATH];
72+
}st_XAuthorize;
6773
struct
6874
{
6975
bool bEnable;

XEngine_Source/MQCore_ConfigModule/Config_Error.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@
2222
#define ERROR_MQ_MODULE_CONFIG_JSON_XPASS 0x0020007
2323
#define ERROR_MQ_MODULE_CONFIG_JSON_XVER 0x0020008
2424
#define ERROR_MQ_MODULE_CONFIG_JSON_XREPORT 0x0020009
25-
#define ERROR_MQ_MODULE_CONFIG_JSON_XMEMORY 0x0020010
25+
#define ERROR_MQ_MODULE_CONFIG_JSON_XMEMORY 0x0020010
26+
#define ERROR_MQ_MODULE_CONFIG_JSON_XAUTHORIZE 0x0020011

XEngine_Source/MQCore_ConfigModule/Config_Json/Config_Json.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ bool CConfig_Json::Config_Json_File(LPCXSTR lpszConfigFile,XENGINE_SERVERCONFIG
137137
pSt_ServerConfig->st_XMemory.nTimeLast = st_JsonXMemory["nTimeLast"].asInt();
138138
pSt_ServerConfig->st_XMemory.nTimeCount = st_JsonXMemory["nTimeCount"].asInt();
139139

140+
if (st_JsonRoot["XAuthorize"].empty() || (3 != st_JsonRoot["XAuthorize"].size()))
141+
{
142+
Config_IsErrorOccur = true;
143+
Config_dwErrorCode = ERROR_MQ_MODULE_CONFIG_JSON_XAUTHORIZE;
144+
return false;
145+
}
146+
Json::Value st_JsonXAuthorize = st_JsonRoot["XAuthorize"];
147+
pSt_ServerConfig->st_XAuthorize.bHTTPAuth = st_JsonXAuthorize["bHTTPAuth"].asBool();
148+
_tcsxcpy(pSt_ServerConfig->st_XAuthorize.tszHTTPPass, st_JsonXAuthorize["tszHTTPPass"].asCString());
149+
_tcsxcpy(pSt_ServerConfig->st_XAuthorize.tszToken, st_JsonXAuthorize["tszToken"].asCString());
150+
140151
if (st_JsonRoot["XReport"].empty() || (3 != st_JsonRoot["XReport"].size()))
141152
{
142153
Config_IsErrorOccur = true;

XEngine_Source/XEngine_MQServiceApp/MQService_HttpTask.cpp

Lines changed: 66 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -56,79 +56,88 @@ bool MessageQueue_Http_Handle(RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam, LPCXST
5656
LPCXSTR lpszAPITopic = _X("topic");
5757
LPCXSTR lpszAPIOnline = _X("online");
5858

59-
if (0 == _tcsxnicmp(lpszPostMethod, pSt_HTTPParam->tszHttpMethod, _tcsxlen(lpszPostMethod)))
59+
int nUrlCount = 0;
60+
XCHAR** ppSt_ListUrl;
61+
HttpProtocol_ServerHelp_GetParament(pSt_HTTPParam->tszHttpUri, &ppSt_ListUrl, &nUrlCount);
62+
if (nUrlCount < 1)
6063
{
64+
ProtocolModule_Packet_Http(tszPKTBuffer, &nPKTLen, ERROR_XENGINE_MESSAGE_HTTP_PARAMENT, "url parament is incorrent");
65+
XEngine_MQXService_Send(lpszClientAddr, tszPKTBuffer, nPKTLen, XENGINE_MQAPP_NETTYPE_HTTP);
66+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,请求HTTP管理接口失败,参数错误:%s"), lpszClientAddr, pSt_HTTPParam->tszHttpUri);
67+
return false;
6168
}
62-
else if (0 == _tcsxnicmp(lpszGetMethod, pSt_HTTPParam->tszHttpMethod, _tcsxlen(lpszGetMethod)))
69+
int nMethodPos = 0;
70+
//判断是否需要验证
71+
if (st_ServiceCfg.st_XAuthorize.bHTTPAuth)
6372
{
64-
int nUrlCount = 0;
65-
XCHAR** ppSt_ListUrl;
66-
HttpProtocol_ServerHelp_GetParament(pSt_HTTPParam->tszHttpUri, &ppSt_ListUrl, &nUrlCount);
67-
if (nUrlCount < 1)
73+
//http://127.0.0.1:5202/api?function=user&auth=XENGINE_MQPasskey
74+
BaseLib_String_GetKeyValue(ppSt_ListUrl[1], _X("="), tszKey, tszValue);
75+
if (0 != _tcsxncmp(st_ServiceCfg.st_XAuthorize.tszToken, tszValue, _tcsxlen(st_ServiceCfg.st_XAuthorize.tszToken)))
6876
{
69-
ProtocolModule_Packet_Http(tszPKTBuffer, &nPKTLen, ERROR_XENGINE_MESSAGE_HTTP_PARAMENT, "url parament is incorrent");
77+
ProtocolModule_Packet_Http(tszPKTBuffer, &nPKTLen, ERROR_XENGINE_MESSAGE_HTTP_AUTHORIZE, "auth key is incorrent");
7078
XEngine_MQXService_Send(lpszClientAddr, tszPKTBuffer, nPKTLen, XENGINE_MQAPP_NETTYPE_HTTP);
79+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,请求HTTP管理接口失败,验证失败:%s"), lpszClientAddr, pSt_HTTPParam->tszHttpUri);
7180
return false;
7281
}
82+
nMethodPos++;
83+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,请求HTTP管理接口验证成功,验证TOKEN:%s"), lpszClientAddr, ppSt_ListUrl[1]);
84+
}
85+
//判断请求
86+
if (0 == _tcsxnicmp(lpszPostMethod, pSt_HTTPParam->tszHttpMethod, _tcsxlen(lpszPostMethod)))
87+
{
88+
89+
}
90+
else if (0 == _tcsxnicmp(lpszGetMethod, pSt_HTTPParam->tszHttpMethod, _tcsxlen(lpszGetMethod)))
91+
{
7392
//获取函数
93+
memset(tszValue, '\0', MAX_PATH);
7494
BaseLib_String_GetKeyValue(ppSt_ListUrl[0], _X("="), tszKey, tszValue);
75-
if (0 == _tcsxnicmp(lpszAPIGet, tszValue, _tcsxlen(lpszAPIGet)))
95+
if (0 == _tcsxnicmp(lpszAPIUser, tszValue, _tcsxlen(lpszAPIUser)))
7696
{
77-
memset(tszValue, '\0', MAX_PATH);
78-
BaseLib_String_GetKeyValue(ppSt_ListUrl[1], _X("="), tszKey, tszValue);
79-
if (0 == _tcsxnicmp(lpszAPIUser, tszValue, _tcsxlen(lpszAPIUser)))
80-
{
81-
//用户 http://127.0.0.1:5202/api?function=get&method=user
82-
int nListCount = 0;
83-
XENGINE_PROTOCOL_USERINFO** ppSt_UserInfo;
84-
DBModule_MQUser_UserList(&ppSt_UserInfo, &nListCount);
85-
ProtocolModule_Packet_UserList(tszPKTBuffer, &nPKTLen, &ppSt_UserInfo, nListCount);
86-
BaseLib_Memory_Free((XPPPMEM)&ppSt_UserInfo, nListCount);
97+
//用户 http://127.0.0.1:5202/api?function=user
98+
int nListCount = 0;
99+
XENGINE_PROTOCOL_USERINFO** ppSt_UserInfo;
100+
DBModule_MQUser_UserList(&ppSt_UserInfo, &nListCount);
101+
ProtocolModule_Packet_UserList(tszPKTBuffer, &nPKTLen, &ppSt_UserInfo, nListCount);
102+
BaseLib_Memory_Free((XPPPMEM)&ppSt_UserInfo, nListCount);
87103

88-
XEngine_MQXService_Send(lpszClientAddr, tszPKTBuffer, nPKTLen, XENGINE_MQAPP_NETTYPE_HTTP);
89-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,发送的获取用户列表请求成功,获取到的用户列表个数:%d"), lpszClientAddr, nListCount);
90-
}
91-
else if (0 == _tcsxnicmp(lpszAPIOnline, tszValue, _tcsxlen(lpszAPIOnline)))
104+
XEngine_MQXService_Send(lpszClientAddr, tszPKTBuffer, nPKTLen, XENGINE_MQAPP_NETTYPE_HTTP);
105+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,发送的获取用户列表请求成功,获取到的用户列表个数:%d"), lpszClientAddr, nListCount);
106+
}
107+
else if (0 == _tcsxnicmp(lpszAPIOnline, tszValue, _tcsxlen(lpszAPIOnline)))
108+
{
109+
//获取在线用户 http://127.0.0.1:5202/api?function=online&type=0
110+
int nListCount = 0;
111+
XCHAR** pptszListAddr;
112+
113+
BaseLib_String_GetKeyValue(ppSt_ListUrl[nMethodPos + 1], _X("="), tszKey, tszValue);
114+
SessionModule_Client_GetListAddr(&pptszListAddr, &nListCount, _ttxoi(tszValue));
115+
ProtocolModule_Packet_OnlineList(tszPKTBuffer, &nPKTLen, &pptszListAddr, nListCount);
116+
BaseLib_Memory_Free((XPPPMEM)&pptszListAddr, nListCount);
117+
XEngine_MQXService_Send(lpszClientAddr, tszPKTBuffer, nPKTLen, XENGINE_MQAPP_NETTYPE_HTTP);
118+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,发送的获取在线用户列表请求成功,获取到的列表个数:%d"), lpszClientAddr, nListCount);
119+
}
120+
else if (0 == _tcsxnicmp(lpszAPITopic, tszValue, _tcsxlen(lpszAPITopic)))
121+
{
122+
//主题 http://127.0.0.1:5202/api?function=topic&name=comm
123+
if (2 == nUrlCount)
92124
{
93-
//获取在线用户 http://127.0.0.1:5202/api?function=get&method=online&type=0
94-
if (3 != nUrlCount)
95-
{
96-
ProtocolModule_Packet_Http(tszPKTBuffer, &nPKTLen, ERROR_XENGINE_MESSAGE_HTTP_PARAMENT, "url parament is incorrent");
97-
XEngine_MQXService_Send(lpszClientAddr, tszPKTBuffer, nPKTLen, XENGINE_MQAPP_NETTYPE_HTTP);
98-
return false;
99-
}
100125
int nListCount = 0;
101-
XCHAR** pptszListAddr;
102-
103-
BaseLib_String_GetKeyValue(ppSt_ListUrl[2], _X("="), tszKey, tszValue);
104-
SessionModule_Client_GetListAddr(&pptszListAddr, &nListCount, _ttxoi(tszValue));
105-
ProtocolModule_Packet_OnlineList(tszPKTBuffer, &nPKTLen, &pptszListAddr, nListCount);
106-
BaseLib_Memory_Free((XPPPMEM)&pptszListAddr, nListCount);
126+
XCHAR** ppszTableName;
127+
DBModule_MQData_ShowTable(&ppszTableName, &nListCount);
128+
ProtocolModule_Packet_TopicList(tszPKTBuffer, &nPKTLen, &ppszTableName, nListCount);
129+
BaseLib_Memory_Free((XPPPMEM)&ppszTableName, nListCount);
107130
XEngine_MQXService_Send(lpszClientAddr, tszPKTBuffer, nPKTLen, XENGINE_MQAPP_NETTYPE_HTTP);
108-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,发送的获取在线用户列表请求成功,获取到的列表个数:%d"), lpszClientAddr, nListCount);
131+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,发送的获取主题列表请求成功,获取到的主题列表个数:%d"), lpszClientAddr, nListCount);
109132
}
110-
else if (0 == _tcsxnicmp(lpszAPITopic, tszValue, _tcsxlen(lpszAPITopic)))
133+
else
111134
{
112-
//主题 http://127.0.0.1:5202/api?function=get&method=topic&name=comm
113-
if (2 == nUrlCount)
114-
{
115-
int nListCount = 0;
116-
XCHAR** ppszTableName;
117-
DBModule_MQData_ShowTable(&ppszTableName, &nListCount);
118-
ProtocolModule_Packet_TopicList(tszPKTBuffer, &nPKTLen, &ppszTableName, nListCount);
119-
BaseLib_Memory_Free((XPPPMEM)&ppszTableName, nListCount);
120-
XEngine_MQXService_Send(lpszClientAddr, tszPKTBuffer, nPKTLen, XENGINE_MQAPP_NETTYPE_HTTP);
121-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,发送的获取主题列表请求成功,获取到的主题列表个数:%d"), lpszClientAddr, nListCount);
122-
}
123-
else
124-
{
125-
int nDBCount = 0;
126-
BaseLib_String_GetKeyValue(ppSt_ListUrl[2], _X("="), tszKey, tszValue);
127-
DBModule_MQData_GetLeftCount(tszValue, 0, &nDBCount);
128-
ProtocolModule_Packet_TopicName(tszPKTBuffer, &nPKTLen, tszValue, nDBCount);
129-
XEngine_MQXService_Send(lpszClientAddr, tszPKTBuffer, nPKTLen, XENGINE_MQAPP_NETTYPE_HTTP);
130-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,发送的获取主题列表请求成功,获取到的主题消息个数:%d"), lpszClientAddr, nDBCount);
131-
}
135+
int nDBCount = 0;
136+
BaseLib_String_GetKeyValue(ppSt_ListUrl[nMethodPos + 1], _X("="), tszKey, tszValue);
137+
DBModule_MQData_GetLeftCount(tszValue, 0, &nDBCount);
138+
ProtocolModule_Packet_TopicName(tszPKTBuffer, &nPKTLen, tszValue, nDBCount);
139+
XEngine_MQXService_Send(lpszClientAddr, tszPKTBuffer, nPKTLen, XENGINE_MQAPP_NETTYPE_HTTP);
140+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,发送的获取主题列表请求成功,获取到的主题消息个数:%d"), lpszClientAddr, nDBCount);
132141
}
133142
}
134143
}

XEngine_Source/XQueue_ProtocolHdr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#define ERROR_XENGINE_MESSAGE_XMQ_MODIFYMSG 0x117 //修改消息失败
8484

8585
#define ERROR_XENGINE_MESSAGE_HTTP_PARAMENT 0x201 //HTTP请求参数错误
86+
#define ERROR_XENGINE_MESSAGE_HTTP_AUTHORIZE 0x202 //验证失败没有权限
8687
///////////////////////////////////////////////////////////////////////////
8788
// 导出的数据结构
8889
///////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)