提交 b6c3c1ad 编写于 作者: xengine-qyt's avatar xengine-qyt 提交者: Gitee

!8 V2.1 Merge

Merge pull request !8 from qyt/develop
......@@ -22,7 +22,7 @@ this software support following features
7. load balanc(planning)
8. message get time
9. message subcribe
10. support Permission Validation(planning)
10. support Permission Validation
11. support multi protocol(TCP,HTTP,WEBSOCKET)
12. Active delivery acquisition mode or passive subscription notification module
13. get order and start serial pos setting
......@@ -33,7 +33,7 @@ this software support following features
#### Requirements
support system above windows 7sp1 and linux(ubuntu20.04,centos8)
XEngine need V7.18 or above
XEngine need V7.23 or above
vcpkg need 2021.05.11 or above
#### Windows
......@@ -46,11 +46,6 @@ vcpkg.exe install jsoncpp
vcpkg integrate install
you can not use vcpkg and config jsoncpp development for youself
##### XEngine
XEngine can be download with mine repository,whe you downloaded xengine,you have to add value to you user environment
- XEngine_Include header file path
- XEngine_Library library file path
#### Linux
Linux use Makefile to complie
supproted ubuntu x64 or centos x64
......@@ -71,6 +66,11 @@ make complie
make FLAGS=InstallAll install
make FLAGS=CleanAll clear
#### XEngine Env
install XEngine can be refer to xengine Readme docment
GITEE:https://gitee.com/xyry/libxengine
GITHUB:https://github.com/libxengine/xengine
#### use
1. Switch to the MASTER branch
......@@ -89,6 +89,10 @@ make FLAGS=CleanAll clear
## other problems
You can refer to the document under the docment directory. It contains API protocol and service description.
## Test Server Address
Address:app.xyry.org or 159.75.200.173
Port:TCP 5200,HTTP 5201,WEBSOCKET 5202
## Participate in contribution
1. Fork this code
......
......@@ -21,7 +21,7 @@ c c++Message Service
7. 负载均衡(planning)
8. 消息次数
9. 消息订阅
10. 支持权限验证(planning)
10. 支持权限验证
11. 支持多种协议(TCP,HTTP,WEBSOCKET)
12. 主动投递获取模式或者被动订阅通知模块
13. 获取顺序与开始序列号设置
......@@ -32,7 +32,7 @@ c c++Message Service
#### 版本需求
支持WINDOWS 7SP1和LINUX(UBUNT20.04,CENTOS8)以上系统
XEngine版本需要V7.18或者以上版本
XEngine版本需要V7.23或者以上版本
vcpkg 需要2021.05.11以上版本
#### Windows
......@@ -45,11 +45,6 @@ vcpkg 需要2021.05.11以上版本
集成VS环境: vcpkg integrate install
vcpkg 主要为了方便安装jsoncpp,如果你想自己配置jsoncpp的环境,可以不使用vcpkg...
##### XEngine环境
XEngine可以直接下载,下载完毕后添加用户环境变量,需要下面两个
- XEngine_Include 指向头文件目录地址
- XEngine_Library 指向库文件目录地址
#### Linux
Linux使用Makefile编译
UBUNTU20.04 x64或者CENTOS8 x64均可
......@@ -60,14 +55,17 @@ sudo apt install libjsoncpp-devel
Centos8.x
sudo dnf install jsoncpp-devel
##### XEngine环境
XEngine可以通过脚本文件安装sudo XEngine_RunEnv.sh -i 3
##### 编译命令
在XEngine_Source目录下执行命令
make 编译
make FLAGS=InstallAll 安装库程序
make FLAGS=CleanAll 清理编译
#### XEngine环境
安装XEngine可以参考其Readme文档
GITEE:https://gitee.com/xyry/libxengine
GITHUB:https://github.com/libxengine/xengine
#### 使用说明
1. 切换到MASTER分支
......@@ -86,6 +84,10 @@ make FLAGS=CleanAll 清理编译
## 其他问题
你可以参考docment目录下的文档.里面包含了API协议和服务说明.
## 测试服务器
地址:app.xyry.org 或者 159.75.200.173
端口:TCP 5200,HTTP 5201,WEBSOCKET 5202
## 参与贡献
1. Fork 本仓库
......
......@@ -27,7 +27,37 @@
SOCKET m_Socket;
LPCTSTR lpszKey = _T("XEngine_Notify"); //主题
LPCTSTR lpszPostUrl = _T("http://192.168.1.7:5201");
LPCTSTR lpszPostUrl = _T("http://127.0.0.1:5201");
void MQ_Authorize()
{
int nLen = 0;
TCHAR tszMsgBuffer[2048];
memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
Json::Value st_JsonRoot;
Json::Value st_JsonAuth;
st_JsonRoot["unOperatorType"] = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_AUTH;
st_JsonRoot["unOperatorCode"] = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_AUTH_REQLOGIN;
st_JsonRoot["byVersion"] = ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE_JSON;
st_JsonAuth["tszUserName"] = "123123aa";
st_JsonAuth["tszUserPass"] = "123123";
st_JsonRoot["st_Auth"] = st_JsonAuth;
nLen = st_JsonRoot.toStyledString().length();
memcpy(tszMsgBuffer, st_JsonRoot.toStyledString().c_str(), nLen);
TCHAR* ptszMsgBody = NULL;
if (!APIHelp_HttpRequest_Post(lpszPostUrl, tszMsgBuffer, NULL, &ptszMsgBody))
{
printf("发送投递失败!\n");
return;
}
printf("MQ_Authorize:%s\n", ptszMsgBody);
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBody);
}
void MQ_Create()
{
......@@ -198,6 +228,7 @@ int main()
WSAStartup(MAKEWORD(2, 2), &st_WSAData);
#endif
MQ_Authorize();
MQ_Create();
MQ_Post("123hello");
MQ_GetNumber();
......
......@@ -2,6 +2,7 @@
#include <Windows.h>
#include <tchar.h>
#pragma comment(lib,"Ws2_32.lib")
#pragma comment(lib,"x86/XEngine_BaseLib/XEngine_BaseLib.lib")
#pragma comment(lib,"x86/XEngine_Client/XClient_Socket.lib")
#else
#include <stdio.h>
......@@ -12,6 +13,8 @@
using namespace std;
#include <XEngine_Include/XEngine_CommHdr.h>
#include <XEngine_Include/XEngine_ProtocolHdr.h>
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Define.h>
#include <XEngine_Include/XEngine_BaseLib/Algorithm_Error.h>
#include <XEngine_Include/XEngine_Client/XClient_Define.h>
#include <XEngine_Include/XEngine_Client/XClient_Error.h>
#include "../../XEngine_Source/XQueue_ProtocolHdr.h"
......@@ -21,6 +24,53 @@ SOCKET m_Socket;
__int64x nLastNumber = 0;
LPCTSTR lpszKey = _T("XEngine_Notify"); //主题
void MQ_Authorize()
{
int nLen = 0;
XENGINE_PROTOCOLHDR st_ProtocolHdr;
XENGINE_PROTOCOL_USERAUTH st_ProtocolAuth;
TCHAR tszMsgBuffer[2048];
memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
memset(&st_ProtocolHdr, '\0', sizeof(XENGINE_PROTOCOLHDR));
memset(&st_ProtocolAuth, '\0', sizeof(XENGINE_PROTOCOL_USERAUTH));
st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER;
st_ProtocolHdr.unOperatorType = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_AUTH;
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_AUTH_REQLOGIN;
st_ProtocolHdr.byVersion = 1;
st_ProtocolHdr.byIsReply = TRUE; //获得处理返回结果
st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL;
_tcscpy(st_ProtocolAuth.tszUserName, "123123aa");
_tcscpy(st_ProtocolAuth.tszUserPass, "123123");
st_ProtocolHdr.unPacketSize = sizeof(XENGINE_PROTOCOL_USERAUTH);
nLen = sizeof(XENGINE_PROTOCOLHDR) + st_ProtocolHdr.unPacketSize;
memcpy(tszMsgBuffer, &st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR));
memcpy(tszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR), &st_ProtocolAuth, sizeof(XENGINE_PROTOCOL_USERAUTH));
if (!XClient_TCPSelect_SendMsg(m_Socket, tszMsgBuffer, nLen))
{
printf("发送投递失败!\n");
return;
}
nLen = 0;
TCHAR* ptszMsgBuffer;
memset(&st_ProtocolHdr, '\0', sizeof(XENGINE_PROTOCOLHDR));
if (!XClient_TCPSelect_RecvPkt(m_Socket, &ptszMsgBuffer, &nLen, &st_ProtocolHdr))
{
printf("接受数据失败!\n");
return;
}
printf("%d\n", st_ProtocolHdr.wReserve);
if (nLen > 0)
{
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
}
}
void MQ_Create()
{
int nLen = 0;
......@@ -434,6 +484,7 @@ int main(int argc, char** argv)
}
printf("连接成功!\n");
//MQ_Authorize();
if (argc > 1)
{
MQ_Create();
......
......@@ -63,6 +63,42 @@ BOOL MQ_RecvPacket(TCHAR* ptszMsgBuffer, int* pInt_MsgLen)
*pInt_MsgLen = nRVLen;
return TRUE;
}
void MQ_Authorize()
{
int nLen = 0;
TCHAR tszMsgBuffer[2048];
memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
Json::Value st_JsonRoot;
Json::Value st_JsonAuth;
st_JsonRoot["unOperatorType"] = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_AUTH;
st_JsonRoot["unOperatorCode"] = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_AUTH_REQLOGIN;
st_JsonRoot["byVersion"] = ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE_JSON;
st_JsonAuth["tszUserName"] = "123123aa";
st_JsonAuth["tszUserPass"] = "123123";
st_JsonRoot["st_Auth"] = st_JsonAuth;
nLen = st_JsonRoot.toStyledString().length();
memcpy(tszMsgBuffer, st_JsonRoot.toStyledString().c_str(), nLen);
if (!MQ_SendPacket(tszMsgBuffer, nLen))
{
printf("发送投递失败!\n");
return;
}
nLen = 2048;
memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
if (!MQ_RecvPacket(tszMsgBuffer, &nLen))
{
printf("接受数据失败!\n");
return;
}
printf("MQ_Authorize:%s\n", tszMsgBuffer);
}
void MQ_Create()
{
int nLen = 0;
......@@ -341,7 +377,7 @@ int main()
printf("RfcComponents_WSConnector_Connect:%lX", WSFrame_GetLastError());
return -1;
}
if (!XClient_TCPSelect_Create(&m_Socket, _T("192.168.1.7"), 5202))
if (!XClient_TCPSelect_Create(&m_Socket, _T("127.0.0.1"), 5202))
{
printf("NetClient_TCPSelect_Create:%lX", XClient_GetLastError());
return -1;
......@@ -370,7 +406,7 @@ int main()
{
printf("%s\n", tszMsgBuffer + nPos);
}
MQ_Authorize();
MQ_Create();
MQ_Post("123hello");
MQ_GetSerial();
......
{
"CodeMessage":[
{
"100":"HTTP/1.1 100 Continue",
"101":"HTTP/1.1 101 Switching Protocols",
"102":"HTTP/1.1 102 Processing"
}
],
"CodeSuccess":[
{
"200":"HTTP/1.1 200 OK",
"201":"HTTP/1.1 201 Created",
"202":"HTTP/1.1 202 Accepted",
"203":"HTTP/1.1 203 Non-Authoritative Information",
"204":"HTTP/1.1 204 No Content",
"205":"HTTP/1.1 205 Reset Content",
"206":"HTTP/1.1 206 Partial Content"
}
],
"CodeRedirect":[
{
"300":"HTTP/1.1 300 Multiple Choices",
"301":"HTTP/1.1 301 Moved Permanently",
"302":"HTTP/1.1 302 Move temporarily",
"303":"HTTP/1.1 303 See Other",
"304":"HTTP/1.1 304 Not Modified",
"305":"HTTP/1.1 305 Use Proxy",
"306":"HTTP/1.1 306 Switch Proxy"
}
],
"CodeRequestFail":[
{
"400":"HTTP/1.1 400 Bad Request",
"401":"HTTP/1.1 401 Payment Required",
"402":"HTTP/1.1 402 Unauthorized",
"403":"HTTP/1.1 403 Forbidden",
"404":"HTTP/1.1 404 Not Found",
"405":"HTTP/1.1 405 Method Not Allowed",
"406":"HTTP/1.1 406 Not Acceptable",
"407":"HTTP/1.1 407 Proxy Authentication Required",
"408":"HTTP/1.1 408 Request Timeout",
"409":"HTTP/1.1 409 Conflict",
"410":"HTTP/1.1 410 Gone",
"411":"HTTP/1.1 411 Length Required",
"412":"HTTP/1.1 412 Precondition Failed",
"413":"HTTP/1.1 413 Request Entity Too Large",
"414":"HTTP/1.1 414 Request-URI Too Long",
"415":"HTTP/1.1 415 Unsupported Media Type",
"416":"HTTP/1.1 416 Requested Range Not Satisfiable",
"417":"HTTP/1.1 417 Expectation Failed",
"421":"HTTP/1.1 421 too many connections",
"422":"HTTP/1.1 422 Unprocessable Entity",
"423":"HTTP/1.1 423 Locked",
"424":"HTTP/1.1 424 Failed Dependency",
"425":"HTTP/1.1 425 Unordered Collection",
"426":"HTTP/1.1 426 Upgrade Required",
"449":"HTTP/1.1 449 Retry With",
"451":"HTTP/1.1 451 Unavailable For Legal Reasons"
}
],
"CodeServerFail":[
{
"500":"HTTP/1.1 500 Internal Server Error",
"501":"HTTP/1.1 501 Not Implemented",
"502":"HTTP/1.1 502 Bad Gateway",
"503":"HTTP/1.1 503 Service Unavailable",
"504":"HTTP/1.1 504 Gateway Timeout",
"505":"HTTP/1.1 505 HTTP Version Not Supported",
"506":"HTTP/1.1 506 Variant Also Negotiates",
"507":"HTTP/1.1 507 Insufficient Storage",
"508":"HTTP/1.1 509 Bandwidth Limit Exceeded",
"600":"HTTP/1.1 600 Unparseable Response Headers"
}
],
"CodeUser":[
{
"1001":"HTTP/1.1 1001 XyRy Auth Ok",
"1002":"HTTP/1.1 1002 XyRy Auth Failed"
}
]
}
//CodeMessage
100:HTTP/1.1 100 Continue
101:HTTP/1.1 101 Switching Protocols
102:HTTP/1.1 102 Processing
//CodeSuccess
200:HTTP/1.1 200 OK
201:HTTP/1.1 201 Created
202:HTTP/1.1 202 Accepted
203:HTTP/1.1 203 Non-Authoritative Information
204:HTTP/1.1 204 No Content
205:HTTP/1.1 205 Reset Content
206:HTTP/1.1 206 Partial Content
//CodeRedirect
300:HTTP/1.1 300 Multiple Choices
301:HTTP/1.1 301 Moved Permanently
302:HTTP/1.1 302 Move temporarily
303:HTTP/1.1 303 See Other
304:HTTP/1.1 304 Not Modified
305:HTTP/1.1 305 Use Proxy
306:HTTP/1.1 306 Switch Proxy
//CodeRequestFail
400:HTTP/1.1 400 Bad Request
401:HTTP/1.1 401 Payment Required
402:HTTP/1.1 402 Unauthorized
403:HTTP/1.1 403 Forbidden
404:HTTP/1.1 404 Not Found
405:HTTP/1.1 405 Method Not Allowed
406:HTTP/1.1 406 Not Acceptable
407:HTTP/1.1 407 Proxy Authentication Required
408:HTTP/1.1 408 Request Timeout
409:HTTP/1.1 409 Conflict
410:HTTP/1.1 410 Gone
411:HTTP/1.1 411 Length Required
412:HTTP/1.1 412 Precondition Failed
413:HTTP/1.1 413 Request Entity Too Large
414:HTTP/1.1 414 Request-URI Too Long
415:HTTP/1.1 415 Unsupported Media Type
416:HTTP/1.1 416 Requested Range Not Satisfiable
417:HTTP/1.1 417 Expectation Failed
421:HTTP/1.1 421 too many connections
422:HTTP/1.1 422 Unprocessable Entity
423:HTTP/1.1 423 Locked
424:HTTP/1.1 424 Failed Dependency
425:HTTP/1.1 425 Unordered Collection
426:HTTP/1.1 426 Upgrade Required
449:HTTP/1.1 449 Retry With
451:HTTP/1.1 451 Unavailable For Legal Reasons
//CodeServerFail
500:HTTP/1.1 500 Internal Server Error
501:HTTP/1.1 501 Not Implemented
502:HTTP/1.1 502 Bad Gateway
503:HTTP/1.1 503 Service Unavailable
504:HTTP/1.1 504 Gateway Timeout
505:HTTP/1.1 505 HTTP Version Not Supported
506:HTTP/1.1 506 Variant Also Negotiates
507:HTTP/1.1 507 Insufficient Storage
508:HTTP/1.1 509 Bandwidth Limit Exceeded
600:HTTP/1.1 600 Unparseable Response Headers
//CodeUser
1001:HTTP/1.1 1001 XEngine Auth Ok
1002:HTTP/1.1 1002 XEngine Auth Failed
\ No newline at end of file
123123aa 123123
aaadddzxc 123123
\ No newline at end of file
{
"tszIPAddr": "192.168.1.12",
"tszTopic": "XEngine_CommKey",
"bDeamon": 0,
"nTCPPort": 5200,
"nHttpPort": 5201,
"nWSPort": 5202,
"nBroadRVPort": 5210,
"nBroadSDPort": 5211,
"XMax": {
"nMaxClient": 10000,
"nMaxQueue": 10000,
"nIOThread": 2,
"nTCPThread": 2,
"nHttpThread": 2,
"nWSThread": 2
"tszIPAddr":"192.168.1.12",
"tszTopic":"XEngine_CommKey",
"bDeamon":0,
"nTCPPort":5200,
"nHttpPort":5201,
"nWSPort":5202,
"nRPCPort":5203,
"nBroadRVPort":5210,
"nBroadSDPort":5211,
"XMax":{
"nMaxClient":10000,
"nMaxQueue":10000,
"nIOThread":2,
"nTCPThread":2,
"nHttpThread":2,
"nWSThread":2
},
"XTime": {
"bHBTime": 0,
"nDBMonth": 3,
"nTimeCheck": 3,
"nTCPTimeOut": 5,
"nHttpTimeOut": 5,
"nWSTimeOut": 5
"XTime":{
"bHBTime":0,
"nDBMonth":3,
"nTimeCheck":3,
"nTCPTimeOut":5,
"nHttpTimeOut":5,
"nWSTimeOut":5
},
"XLog": {
"MaxSize": 1024000,
"MaxCount": 10,
"LogLeave": 32
"XLog":{
"MaxSize":1024000,
"MaxCount":10,
"LogLeave":32
},
"XSql": {
"SQLAddr": "192.168.1.9",
"SQLPort": 3306,
"SQLUser": "root",
"SQLPass": "123123Ruiyue"
"XSql":{
"SQLAddr":"192.168.1.9",
"SQLPort":3306,
"SQLUser":"root",
"SQLPass":"123123Ruiyue"
},
"XVer": {
"StorageVersion": [
"2.0.0.1001 Build20210930",
"1.4.0.1001 Build20210806",
"1.3.0.1001 Build20210723",
"1.2.0.1001 Build20210716",
"1.1.0.1001 Build20210702"
]
"XAuth":{
"nAuth":0,
"AuthUser":"./XEngine_Config/UserList.txt",
"AuthHttp":"http://app.xyry.org:5500/api/pass/auth"
},
"XVer":{
"StorageVersion":[
"2.1.0.1001 Build20211119",
"2.0.0.1001 Build20210930",
"1.4.0.1001 Build20210806",
"1.3.0.1001 Build20210723",
"1.2.0.1001 Build20210716",
"1.1.0.1001 Build20210702"
]
}
}
\ No newline at end of file
......@@ -55,6 +55,12 @@ typedef struct tag_XEngine_ServerConfig
TCHAR tszDBName[128];
int nSQLPort;
}st_XSql;
struct
{
int nAuth;
TCHAR tszAuthUser[MAX_PATH];
TCHAR tszAuthHttp[MAX_PATH];
}st_XAuth;
struct
{
list<tstring> *pStl_ListStorage;
......
......@@ -19,4 +19,5 @@
#define ERROR_MQ_MODULE_CONFIG_JSON_XTIME 0x0020004
#define ERROR_MQ_MODULE_CONFIG_JSON_XLOG 0x0020005
#define ERROR_MQ_MODULE_CONFIG_JSON_XSQL 0x0020006
#define ERROR_MQ_MODULE_CONFIG_JSON_XAUTH 0x0020007
#define ERROR_MQ_MODULE_CONFIG_JSON_XVER 0x0020008
\ No newline at end of file
......@@ -123,6 +123,17 @@ BOOL CConfig_Json::Config_Json_File(LPCTSTR lpszConfigFile,XENGINE_SERVERCONFIG
_tcscpy(pSt_ServerConfig->st_XSql.tszSQLUser,st_JsonXSql["SQLUser"].asCString());
_tcscpy(pSt_ServerConfig->st_XSql.tszSQLPass,st_JsonXSql["SQLPass"].asCString());
if (st_JsonRoot["XSql"].empty() || (3 != st_JsonRoot["XAuth"].size()))
{
Config_IsErrorOccur = TRUE;
Config_dwErrorCode = ERROR_MQ_MODULE_CONFIG_JSON_XAUTH;
return FALSE;
}
Json::Value st_JsonXAuth = st_JsonRoot["XAuth"];
pSt_ServerConfig->st_XAuth.nAuth = st_JsonXAuth["nAuth"].asInt();
_tcscpy(pSt_ServerConfig->st_XAuth.tszAuthUser, st_JsonXAuth["AuthUser"].asCString());
_tcscpy(pSt_ServerConfig->st_XAuth.tszAuthHttp, st_JsonXAuth["AuthHttp"].asCString());
if (st_JsonRoot["XVer"].empty())
{
Config_IsErrorOccur = TRUE;
......
......@@ -3,9 +3,9 @@ LIBRARY
EXPORTS
Protocol_GetLastError
ProtocolModule_Packet_TCPCommon
ProtocolModule_Packet_HttpCommon
ProtocolModule_Packet_Common
ProtocolModule_Packet_MQNumber
ProtocolModule_Packet_PassAuth
ProtocolModule_Packet_DDSTopic
ProtocolModule_Packet_DDSQuery
......
......@@ -22,6 +22,63 @@ CProtocolModule_Packet::~CProtocolModule_Packet()
///////////////////////////////////////////////////////////////////////////////
/********************************************************************
函数名称:ProtocolModule_Packet_TCPCommon
函数功能:通用封包类
参数.一:nNetType
In/Out:In
类型:整数型
可空:N
意思:输入网络类型
参数.二:pSt_ProtocolHdr
In/Out:In
类型:数据结构指针
可空:N
意思:协议头
参数.三:pSt_MQProtocol
In/Out:In
类型:数据结构指针
可空:N
意思:消息头
参数.四:ptszMsgBuffer
In/Out:Out
类型:字符指针
可空:N
意思:导出封装号的协议
参数.五:pInt_MsgLen
In/Out:Out
类型:整数型指针
可空:N
意思:导出封装的协议的长度
参数.六:lpszMsgBuffer
In/Out:In
类型:常量字符指针
可空:Y
意思:要封装的数据
参数.七:nMsgLen
In/Out:In
类型:整数型
可空:Y
意思:要封装数据的长度
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
BOOL CProtocolModule_Packet::ProtocolModule_Packet_Common(int nNetType, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszMsgBuffer /* = NULL */, int nMsgLen /* = 0 */)
{
Protocol_IsErrorOccur = FALSE;
if (XENGINE_MQAPP_NETTYPE_TCP == nNetType)
{
ProtocolModule_Packet_TCPCommon(pSt_ProtocolHdr, pSt_MQProtocol, ptszMsgBuffer, pInt_MsgLen, lpszMsgBuffer, nMsgLen);
}
else
{
ProtocolModule_Packet_HttpCommon(pSt_ProtocolHdr, pSt_MQProtocol, ptszMsgBuffer, pInt_MsgLen, lpszMsgBuffer, nMsgLen);
}
return TRUE;
}
/********************************************************************
函数名称:ProtocolModule_Packet_TCPCommon
函数功能:通用封包类
参数.一:pSt_ProtocolHdr
In/Out:In
......@@ -53,17 +110,12 @@ CProtocolModule_Packet::~CProtocolModule_Packet()
类型:整数型
可空:Y
意思:要封装数据的长度
参数.七:enPayType
In/Out:In
类型:枚举型
可空:Y
意思:消息类型
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
BOOL CProtocolModule_Packet::ProtocolModule_Packet_TCPCommon(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszMsgBuffer /* = NULL */, int nMsgLen /* = 0 */, ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE enPayType /* = ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE_STRING */)
BOOL CProtocolModule_Packet::ProtocolModule_Packet_TCPCommon(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszMsgBuffer /* = NULL */, int nMsgLen /* = 0 */)
{
Protocol_IsErrorOccur = FALSE;
......@@ -73,44 +125,26 @@ BOOL CProtocolModule_Packet::ProtocolModule_Packet_TCPCommon(XENGINE_PROTOCOLHDR
Protocol_dwErrorCode = ERROR_MQ_MODULE_PROTOCOL_PARAMENT;
return FALSE;
}
if (NULL == pSt_MQProtocol)
{
pSt_ProtocolHdr->unPacketSize = nMsgLen;
memcpy(ptszMsgBuffer, pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR));
if (ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE_BIN == pSt_ProtocolHdr->byVersion)
{
*pInt_MsgLen = sizeof(XENGINE_PROTOCOLHDR) + nMsgLen;
}
else
{
pSt_ProtocolHdr->unPacketSize = sizeof(XENGINE_PROTOCOL_XMQ) + nMsgLen;
memcpy(ptszMsgBuffer, pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR));
memcpy(ptszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR), pSt_MQProtocol, sizeof(XENGINE_PROTOCOL_XMQ));
if (nMsgLen)
if (NULL != lpszMsgBuffer)
{
memcpy(ptszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR) + sizeof(XENGINE_PROTOCOL_XMQ), lpszMsgBuffer, nMsgLen);
}
*pInt_MsgLen = sizeof(XENGINE_PROTOCOLHDR) + sizeof(XENGINE_PROTOCOL_XMQ) + nMsgLen;
}
else
{
Json::Value st_JsonRoot;
Json::Value st_JsonPayload;
Json::StreamWriterBuilder st_JsonBuilder;
st_JsonRoot["tszMQKey"] = pSt_MQProtocol->tszMQKey;
st_JsonRoot["nSerial"] = pSt_MQProtocol->nSerial;
st_JsonRoot["nKeepTime"] = pSt_MQProtocol->nKeepTime;
st_JsonRoot["nGetTimer"] = pSt_MQProtocol->nGetTimer;
if (nMsgLen > 0)
{
st_JsonPayload["nPayType"] = (ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE)enPayType;
st_JsonPayload["nPayLen"] = nMsgLen;
st_JsonPayload["tszPayData"] = lpszMsgBuffer;
st_JsonRoot["st_Payload"] = st_JsonPayload;
}
st_JsonBuilder["emitUTF8"] = true;
pSt_ProtocolHdr->unPacketSize = Json::writeString(st_JsonBuilder, st_JsonRoot).length();
memcpy(ptszMsgBuffer, pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR));
memcpy(ptszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR), Json::writeString(st_JsonBuilder, st_JsonRoot).c_str(), pSt_ProtocolHdr->unPacketSize);
*pInt_MsgLen = sizeof(XENGINE_PROTOCOLHDR) + pSt_ProtocolHdr->unPacketSize;
}
}
return TRUE;
}
......@@ -147,36 +181,35 @@ BOOL CProtocolModule_Packet::ProtocolModule_Packet_TCPCommon(XENGINE_PROTOCOLHDR
类型:整数型
可空:Y
意思:要封装数据的长度
参数.七:enPayType
In/Out:In
类型:枚举型
可空:Y
意思:消息类型
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
BOOL CProtocolModule_Packet::ProtocolModule_Packet_HttpCommon(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszMsgBuffer /* = NULL */, int nMsgLen /* = 0 */, ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE enPayType /* = ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE_STRING */)
BOOL CProtocolModule_Packet::ProtocolModule_Packet_HttpCommon(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszMsgBuffer /* = NULL */, int nMsgLen /* = 0 */)
{
Json::Value st_JsonRoot;
Json::Value st_JsonMQProtocol;
Json::Value st_JsonPayload;
Json::StreamWriterBuilder st_JsonBuilder;
st_JsonMQProtocol["tszMQKey"] = pSt_MQProtocol->tszMQKey;
st_JsonMQProtocol["nSerial"] = pSt_MQProtocol->nSerial;
st_JsonMQProtocol["nKeepTime"] = pSt_MQProtocol->nKeepTime;
st_JsonMQProtocol["nGetTimer"] = pSt_MQProtocol->nGetTimer;
st_JsonRoot["unOperatorType"] = pSt_ProtocolHdr->unOperatorType;
st_JsonRoot["unOperatorCode"] = pSt_ProtocolHdr->unOperatorCode;
st_JsonRoot["wReserve"] = pSt_ProtocolHdr->wReserve;
st_JsonRoot["st_MQProtocol"] = st_JsonMQProtocol;
if (NULL != pSt_MQProtocol)
{
st_JsonMQProtocol["tszMQKey"] = pSt_MQProtocol->tszMQKey;
st_JsonMQProtocol["nSerial"] = pSt_MQProtocol->nSerial;
st_JsonMQProtocol["nKeepTime"] = pSt_MQProtocol->nKeepTime;
st_JsonMQProtocol["nGetTimer"] = pSt_MQProtocol->nGetTimer;
st_JsonRoot["st_MQProtocol"] = st_JsonMQProtocol;
}
if (nMsgLen > 0)
{
st_JsonPayload["nPayType"] = (ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE)enPayType;
st_JsonPayload["nPayType"] = (ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE)pSt_ProtocolHdr->byVersion;
st_JsonPayload["nPayLen"] = nMsgLen;
st_JsonPayload["tszPayData"] = lpszMsgBuffer;
......@@ -212,12 +245,17 @@ BOOL CProtocolModule_Packet::ProtocolModule_Packet_HttpCommon(XENGINE_PROTOCOLHD
类型:整数型指针
可空:N
意思:输出缓冲区大小
参数.五:nNetType
In/Out:Out
类型:整数型
可空:N
意思:输入网络类型
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
BOOL CProtocolModule_Packet::ProtocolModule_Packet_MQNumber(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_MQNUMBER* pSt_MQNumber, TCHAR* ptszMsgBuffer, int* pInt_MsgLen)
BOOL CProtocolModule_Packet::ProtocolModule_Packet_MQNumber(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_MQNUMBER* pSt_MQNumber, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, int nNetType)
{
Protocol_IsErrorOccur = FALSE;
......@@ -228,7 +266,7 @@ BOOL CProtocolModule_Packet::ProtocolModule_Packet_MQNumber(XENGINE_PROTOCOLHDR*
return FALSE;
}
if (ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE_BIN == pSt_ProtocolHdr->byVersion)
if (XENGINE_MQAPP_NETTYPE_TCP == nNetType)
{
pSt_ProtocolHdr->unPacketSize = sizeof(XENGINE_MQNUMBER);
memcpy(ptszMsgBuffer, pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR));
......@@ -238,19 +276,71 @@ BOOL CProtocolModule_Packet::ProtocolModule_Packet_MQNumber(XENGINE_PROTOCOLHDR*
else
{
Json::Value st_JsonRoot;
Json::Value st_JsonPayload;
Json::Value st_JsonObject;
Json::StreamWriterBuilder st_JsonBuilder;
st_JsonRoot["tszMQKey"] = pSt_MQNumber->tszMQKey;
st_JsonRoot["nCount"] = pSt_MQNumber->nCount;
st_JsonRoot["nFirstNumber"] = pSt_MQNumber->nFirstNumber;
st_JsonRoot["nLastNumber"] = pSt_MQNumber->nLastNumber;
st_JsonRoot["unOperatorType"] = pSt_ProtocolHdr->unOperatorType;
st_JsonRoot["unOperatorCode"] = pSt_ProtocolHdr->unOperatorCode;
st_JsonRoot["wReserve"] = pSt_ProtocolHdr->wReserve;
st_JsonObject["tszMQKey"] = pSt_MQNumber->tszMQKey;
st_JsonObject["nCount"] = pSt_MQNumber->nCount;
st_JsonObject["nFirstNumber"] = pSt_MQNumber->nFirstNumber;
st_JsonObject["nLastNumber"] = pSt_MQNumber->nLastNumber;
st_JsonRoot["st_MQNumber"] = st_JsonObject;
st_JsonBuilder["emitUTF8"] = true;
*pInt_MsgLen = Json::writeString(st_JsonBuilder, st_JsonRoot).length();
memcpy(ptszMsgBuffer, Json::writeString(st_JsonBuilder, st_JsonRoot).c_str(), *pInt_MsgLen);
}
return TRUE;
}
/********************************************************************
函数名称:ProtocolModule_Packet_PassAuth
函数功能:HTTP代理打包函数
参数.一:pSt_ProtocolAuth
In/Out:In
类型:数据结构指针
可空:N
意思:输入要打包的内容
参数.二:ptszMsgBuffer
In/Out:Out
类型:字符指针
可空:N
意思:输出打好包的缓冲区
参数.三:pInt_MsgLen
In/Out:Out
类型:整数型指针
可空:N
意思:输出缓冲区大小
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
BOOL CProtocolModule_Packet::ProtocolModule_Packet_PassAuth(XENGINE_PROTOCOL_USERAUTH* pSt_ProtocolAuth, TCHAR* ptszMsgBuffer, int* pInt_MsgLen)
{
Protocol_IsErrorOccur = FALSE;
if ((NULL == pSt_ProtocolAuth) || (NULL == ptszMsgBuffer) || (NULL == pInt_MsgLen))
{
Protocol_IsErrorOccur = TRUE;
Protocol_dwErrorCode = ERROR_MQ_MODULE_PROTOCOL_PARAMENT;
return FALSE;
}
Json::Value st_JsonRoot;
Json::StreamWriterBuilder st_JsonBuilder;
st_JsonRoot["tszUserName"] = pSt_ProtocolAuth->tszUserName;
st_JsonRoot["tszUserPass"] = pSt_ProtocolAuth->tszUserPass;
st_JsonRoot["enClientType"] = pSt_ProtocolAuth->enClientType;
st_JsonRoot["enDeviceType"] = pSt_ProtocolAuth->enDeviceType;
st_JsonBuilder["emitUTF8"] = true;
*pInt_MsgLen = Json::writeString(st_JsonBuilder, st_JsonRoot).length();
memcpy(ptszMsgBuffer, Json::writeString(st_JsonBuilder, st_JsonRoot).c_str(), *pInt_MsgLen);
return TRUE;
}
/********************************************************************
......
......@@ -17,9 +17,11 @@ public:
CProtocolModule_Packet();
~CProtocolModule_Packet();
public:
BOOL ProtocolModule_Packet_TCPCommon(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszMsgBuffer = NULL, int nMsgLen = 0, ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE enPayType = ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE_STRING);
BOOL ProtocolModule_Packet_HttpCommon(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszMsgBuffer = NULL, int nMsgLen = 0, ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE enPayType = ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE_STRING);
BOOL ProtocolModule_Packet_MQNumber(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_MQNUMBER* pSt_MQNumber, TCHAR* ptszMsgBuffer, int* pInt_MsgLen);
BOOL ProtocolModule_Packet_Common(int nNetType, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszMsgBuffer = NULL, int nMsgLen = 0);
BOOL ProtocolModule_Packet_TCPCommon(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszMsgBuffer = NULL, int nMsgLen = 0);
BOOL ProtocolModule_Packet_HttpCommon(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszMsgBuffer = NULL, int nMsgLen = 0);
BOOL ProtocolModule_Packet_MQNumber(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_MQNUMBER* pSt_MQNumber, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, int nNetType);
BOOL ProtocolModule_Packet_PassAuth(XENGINE_PROTOCOL_USERAUTH* pSt_ProtocolAuth, TCHAR* ptszMsgBuffer, int* pInt_MsgLen);
public:
BOOL ProtocolModule_Packet_DDSTopic(XENGINE_PROTOCOL_XDDS* pSt_DDSProtocol, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, DWORD dwOPeratorCode);
BOOL ProtocolModule_Packet_DDSQuery(XENGINE_PROTOCOL_XDDS*** pppSt_DDSProtocol, int nListCount, TCHAR* ptszMsgBuffer, int* pInt_MsgLen);
......
......@@ -36,38 +36,28 @@ CProtocolModule_Parse::~CProtocolModule_Parse()
参数.三:pSt_ProtocolHdr
In/Out:Out
类型:数据结构指针
可空:N
可空:Y
意思:输出解析到的头协议
参数.四:pSt_MQProtocol
In/Out:Out
类型:数据结构指针
可空:N
意思:输出消息协议
参数.五:pptszMsgBuffer
参数.四:pptszMsgBuffer
In/Out:Out
类型:二级指针
可空:Y
意思:输出消息内容,需要释放内存
参数.:pInt_MsgLen
参数.:pInt_MsgLen
In/Out:Out
类型:整数型指针
可空:Y
意思:输出内容大小
参数.七:pInt_Type
In/Out:Out
类型:整数型指针
可空:Y
意思:输出负载类型
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
BOOL CProtocolModule_Parse::ProtocolModule_Parse_Http(LPCTSTR lpszMsgBuffer, int nMsgLen, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr /* = NULL */, TCHAR** pptszMsgBuffer /* = NULL */, int* pInt_MsgLen /* = NULL */, int* pInt_Type /* = NULL */)
BOOL CProtocolModule_Parse::ProtocolModule_Parse_Http(LPCTSTR lpszMsgBuffer, int nMsgLen, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, TCHAR** pptszMsgBuffer, int* pInt_MsgLen)
{
Protocol_IsErrorOccur = FALSE;
if ((NULL == lpszMsgBuffer) || (NULL == pSt_MQProtocol))
if (NULL == lpszMsgBuffer)
{
Protocol_IsErrorOccur = TRUE;
Protocol_dwErrorCode = ERROR_MQ_MODULE_PROTOCOL_PARAMENT;
......@@ -86,45 +76,83 @@ BOOL CProtocolModule_Parse::ProtocolModule_Parse_Http(LPCTSTR lpszMsgBuffer, int
}
Json::Value st_JsonMQProtocol = st_JsonRoot["st_MQProtocol"];
if (NULL != pSt_ProtocolHdr)
if (!st_JsonRoot["unOperatorType"].isNull())
{
if (!st_JsonRoot["unOperatorType"].isNull())
{
pSt_ProtocolHdr->unOperatorType = st_JsonRoot["unOperatorType"].asInt();
}
if (!st_JsonRoot["unOperatorCode"].isNull())
{
pSt_ProtocolHdr->unOperatorCode = st_JsonRoot["unOperatorCode"].asInt();
}
if (!st_JsonRoot["wReserve"].isNull())
pSt_ProtocolHdr->unOperatorType = st_JsonRoot["unOperatorType"].asInt();
}
if (!st_JsonRoot["unOperatorCode"].isNull())
{
pSt_ProtocolHdr->unOperatorCode = st_JsonRoot["unOperatorCode"].asInt();
}
if (!st_JsonRoot["wReserve"].isNull())
{
pSt_ProtocolHdr->wReserve = st_JsonRoot["wReserve"].asInt();
}
if (!st_JsonRoot["byVersion"].isNull())
{
pSt_ProtocolHdr->byVersion = st_JsonRoot["byVersion"].asInt();
}
*pInt_MsgLen = 0;
XENGINE_PROTOCOL_XMQ st_MQProtocol;
XENGINE_PROTOCOL_USERAUTH st_ProtocolAuth;
memset(&st_ProtocolAuth, '\0', sizeof(XENGINE_PROTOCOL_USERAUTH));
memset(&st_MQProtocol, '\0', sizeof(XENGINE_PROTOCOL_XMQ));
//如果负载的是消息
if (!st_JsonRoot["st_MQProtocol"].isNull())
{
_tcscpy(st_MQProtocol.tszMQKey, st_JsonMQProtocol["tszMQKey"].asCString());
st_MQProtocol.nSerial = st_JsonMQProtocol["nSerial"].asInt();
st_MQProtocol.nKeepTime = st_JsonMQProtocol["nKeepTime"].asInt();
st_MQProtocol.nGetTimer = st_JsonMQProtocol["nGetTimer"].asInt();
*pInt_MsgLen += sizeof(XENGINE_PROTOCOL_XMQ);
}
//后者负载的是验证协议
if (!st_JsonRoot["st_Auth"].isNull())
{
Json::Value st_JsonAuth = st_JsonRoot["st_Auth"];
_tcscpy(st_ProtocolAuth.tszUserName, st_JsonAuth["tszUserName"].asCString());
_tcscpy(st_ProtocolAuth.tszUserPass, st_JsonAuth["tszUserPass"].asCString());
if (!st_JsonAuth["enClientType"].isNull())
{
pSt_ProtocolHdr->wReserve = st_JsonRoot["wReserve"].asInt();
st_ProtocolAuth.enClientType = (ENUM_PROTOCOLCLIENT_TYPE)st_JsonAuth["enClientType"].asInt();
}
if (!st_JsonRoot["byVersion"].isNull())
if (!st_JsonAuth["enDeviceType"].isNull())
{
pSt_ProtocolHdr->byVersion = st_JsonRoot["byVersion"].asInt();
st_ProtocolAuth.enDeviceType = (ENUM_PROTOCOLDEVICE_TYPE)st_JsonAuth["enDeviceType"].asInt();
}
*pInt_MsgLen += sizeof(XENGINE_PROTOCOL_USERAUTH);
}
_tcscpy(pSt_MQProtocol->tszMQKey, st_JsonMQProtocol["tszMQKey"].asCString());
pSt_MQProtocol->nSerial = st_JsonMQProtocol["nSerial"].asInt();
pSt_MQProtocol->nKeepTime = st_JsonMQProtocol["nKeepTime"].asInt();
pSt_MQProtocol->nGetTimer = st_JsonMQProtocol["nGetTimer"].asInt();
//或者包含附加内容
if (!st_JsonRoot["st_Payload"].isNull())
{
Json::Value st_JsonPayLoad = st_JsonRoot["st_Payload"];
*pInt_MsgLen += st_JsonPayLoad["nPayLen"].asInt();
}
*pInt_Type = st_JsonPayLoad["nPayType"].asInt();
*pInt_MsgLen = st_JsonPayLoad["nPayLen"].asInt();
*pptszMsgBuffer = (TCHAR*)malloc(*pInt_MsgLen);
if (NULL == *pptszMsgBuffer)
{
Protocol_IsErrorOccur = TRUE;
Protocol_dwErrorCode = ERROR_MQ_MODULE_PROTOCOL_MALLOC;
return FALSE;
}
memset(*pptszMsgBuffer, '\0', *pInt_MsgLen);
*pptszMsgBuffer = (TCHAR*)malloc(*pInt_MsgLen);
if (NULL != *pptszMsgBuffer)
if (st_JsonRoot["st_MQProtocol"].isNull())
{
memcpy(*pptszMsgBuffer, &st_ProtocolAuth, sizeof(XENGINE_PROTOCOL_USERAUTH));
}
else
{
memcpy(*pptszMsgBuffer, &st_MQProtocol, sizeof(XENGINE_PROTOCOL_XMQ));
if (!st_JsonRoot["st_Payload"].isNull())
{
Protocol_IsErrorOccur = TRUE;
Protocol_dwErrorCode = ERROR_MQ_MODULE_PROTOCOL_MALLOC;
return FALSE;
Json::Value st_JsonPayLoad = st_JsonRoot["st_Payload"];
memcpy(*pptszMsgBuffer + sizeof(XENGINE_PROTOCOL_XMQ), st_JsonPayLoad["tszPayData"].asCString(), st_JsonPayLoad["nPayLen"].asInt());
}
memcpy(*pptszMsgBuffer, st_JsonPayLoad["tszPayData"].asCString(), *pInt_MsgLen);
}
return TRUE;
}
......
......@@ -17,7 +17,7 @@ public:
CProtocolModule_Parse();
~CProtocolModule_Parse();
public:
BOOL ProtocolModule_Parse_Http(LPCTSTR lpszMsgBuffer, int nMsgLen, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr = NULL, TCHAR** pptszMsgBuffer = NULL, int* pInt_MsgLen = NULL, int* pInt_Type = NULL);
BOOL ProtocolModule_Parse_Http(LPCTSTR lpszMsgBuffer, int nMsgLen, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, TCHAR** pptszMsgBuffer, int* pInt_MsgLen);
BOOL ProtocolModule_Parse_DDSQuery(LPCTSTR lpszMsgBuffer, int nMsgLen, XENGINE_PROTOCOL_XDDS*** pppSt_DDSProtocol, int* pInt_ListCount);
protected:
private:
......
......@@ -20,110 +20,95 @@ extern "C" DWORD Protocol_GetLastError(int* pInt_SysError = NULL);
/********************************************************************
函数名称:ProtocolModule_Packet_TCPCommon
函数功能:通用封包类
参数.一:pSt_ProtocolHdr
参数.一:nNetType
In/Out:In
类型:整数型
可空:N
意思:输入网络类型
参数.二:pSt_ProtocolHdr
In/Out:In
类型:数据结构指针
可空:N
意思:协议头
参数.:pSt_MQProtocol
参数.:pSt_MQProtocol
In/Out:In
类型:数据结构指针
可空:N
意思:消息头
参数.:ptszMsgBuffer
参数.:ptszMsgBuffer
In/Out:Out
类型:字符指针
可空:N
意思:导出封装号的协议
参数.:pInt_MsgLen
参数.:pInt_MsgLen
In/Out:Out
类型:整数型指针
可空:N
意思:导出封装的协议的长度
参数.:lpszMsgBuffer
参数.:lpszMsgBuffer
In/Out:In
类型:常量字符指针
可空:Y
意思:要封装的数据
参数.:nMsgLen
参数.:nMsgLen
In/Out:In
类型:整数型
可空:Y
意思:要封装数据的长度
参数.七:enPayType
In/Out:In
类型:枚举型
可空:Y
意思:消息类型
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
extern "C" BOOL ProtocolModule_Packet_TCPCommon(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_PROTOCOL_XMQ * pSt_MQProtocol, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszMsgBuffer = NULL, int nMsgLen = 0, ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE enPayType = ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE_STRING);
extern "C" BOOL ProtocolModule_Packet_Common(int nNetType, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszMsgBuffer = NULL, int nMsgLen = 0);
/********************************************************************
函数名称:ProtocolModule_Packet_HttpCommon
函数功能:HTTP通用封包类
函数名称:ProtocolModule_Packet_MQNumber
函数功能:获取序列打包函数
参数.一:pSt_ProtocolHdr
In/Out:In
类型:数据结构指针
可空:N
意思:协议头
参数.二:pSt_MQProtocol
意思:输入协议头
参数.二:pSt_MQNumber
In/Out:In
类型:数据结构指针
可空:N
意思:消息头
意思:输入要打包的序列号信息
参数.三:ptszMsgBuffer
In/Out:Out
类型:字符指针
可空:N
意思:导出封装号的协议
意思:输出打好包的缓冲区
参数.四:pInt_MsgLen
In/Out:Out
类型:整数型指针
可空:N
意思:导出封装的协议的长度
参数.五:lpszMsgBuffer
In/Out:In
类型:常量字符指针
可空:Y
意思:要封装的数据
参数.六:nMsgLen
In/Out:In
意思:输出缓冲区大小
参数.五:nNetType
In/Out:Out
类型:整数型
可空:Y
意思:要封装数据的长度
参数.七:enPayType
In/Out:In
类型:枚举型
可空:Y
意思:消息类型
可空:N
意思:输入网络类型
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
extern "C" BOOL ProtocolModule_Packet_HttpCommon(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszMsgBuffer = NULL, int nMsgLen = 0, ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE enPayType = ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE_STRING);
extern "C" BOOL ProtocolModule_Packet_MQNumber(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_MQNUMBER* pSt_MQNumber, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, int nNetType);
/********************************************************************
函数名称:ProtocolModule_Packet_MQNumber
函数功能:获取序列打包函数
参数.一:pSt_ProtocolHdr
In/Out:In
类型:数据结构指针
可空:N
意思:输入协议头
参数.二:pSt_MQNumber
函数名称:ProtocolModule_Packet_PassAuth
函数功能:HTTP代理打包函数
参数.一:pSt_ProtocolAuth
In/Out:In
类型:数据结构指针
可空:N
意思:输入要打包的序列号信息
参数.:ptszMsgBuffer
意思:输入要打包的内容
参数.:ptszMsgBuffer
In/Out:Out
类型:字符指针
可空:N
意思:输出打好包的缓冲区
参数.:pInt_MsgLen
参数.:pInt_MsgLen
In/Out:Out
类型:整数型指针
可空:N
......@@ -133,7 +118,7 @@ extern "C" BOOL ProtocolModule_Packet_HttpCommon(XENGINE_PROTOCOLHDR* pSt_Protoc
意思:是否成功
备注:
*********************************************************************/
extern "C" BOOL ProtocolModule_Packet_MQNumber(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_MQNUMBER* pSt_MQNumber, TCHAR* ptszMsgBuffer, int* pInt_MsgLen);
extern "C" BOOL ProtocolModule_Packet_PassAuth(XENGINE_PROTOCOL_USERAUTH* pSt_ProtocolAuth, TCHAR* ptszMsgBuffer, int* pInt_MsgLen);
/********************************************************************
函数名称:ProtocolModule_Packet_DDSTopic
函数功能:DDS主题协议打包函数
......@@ -208,37 +193,27 @@ extern "C" BOOL ProtocolModule_Packet_DDSQuery(XENGINE_PROTOCOL_XDDS*** pppSt_DD
类型:整数型
可空:N
意思:输入缓冲区大小
参数.三:pSt_MQProtocol
In/Out:Out
类型:数据结构指针
可空:N
意思:输出消息协议
参数.四:pSt_ProtocolHdr
参数.三:pSt_ProtocolHdr
In/Out:Out
类型:数据结构指针
可空:Y
意思:输出解析到的头协议
参数.:pptszMsgBuffer
参数.:pptszMsgBuffer
In/Out:Out
类型:二级指针
可空:Y
意思:输出消息内容,需要释放内存
参数.:pInt_MsgLen
参数.:pInt_MsgLen
In/Out:Out
类型:整数型指针
可空:Y
意思:输出内容大小
参数.七:pInt_Type
In/Out:Out
类型:整数型指针
可空:Y
意思:输出负载类型
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
extern "C" BOOL ProtocolModule_Parse_Http(LPCTSTR lpszMsgBuffer, int nMsgLen, XENGINE_PROTOCOL_XMQ * pSt_MQProtocol, XENGINE_PROTOCOLHDR * pSt_ProtocolHdr = NULL, TCHAR * *pptszMsgBuffer = NULL, int* pInt_MsgLen = NULL, int* pInt_Type = NULL);
extern "C" BOOL ProtocolModule_Parse_Http(LPCTSTR lpszMsgBuffer, int nMsgLen, XENGINE_PROTOCOLHDR * pSt_ProtocolHdr = NULL, TCHAR * *pptszMsgBuffer = NULL, int* pInt_MsgLen = NULL);
/********************************************************************
函数名称:ProtocolModule_Parse_DDSQuery
函数功能:DDS查询解析协议
......
......@@ -31,17 +31,17 @@ extern "C" DWORD Protocol_GetLastError(int* pInt_SysError)
/************************************************************************/
/* 封装类函数 */
/************************************************************************/
extern "C" BOOL ProtocolModule_Packet_TCPCommon(XENGINE_PROTOCOLHDR * pSt_ProtocolHdr, XENGINE_PROTOCOL_XMQ * pSt_MQProtocol, TCHAR * ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszMsgBuffer, int nMsgLen, ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE enPayType)
extern "C" BOOL ProtocolModule_Packet_Common(int nNetType, XENGINE_PROTOCOLHDR * pSt_ProtocolHdr, XENGINE_PROTOCOL_XMQ * pSt_MQProtocol, TCHAR * ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszMsgBuffer, int nMsgLen)
{
return m_ProtocolPacket.ProtocolModule_Packet_TCPCommon(pSt_ProtocolHdr, pSt_MQProtocol, ptszMsgBuffer, pInt_MsgLen, lpszMsgBuffer, nMsgLen, enPayType);
return m_ProtocolPacket.ProtocolModule_Packet_Common(nNetType, pSt_ProtocolHdr, pSt_MQProtocol, ptszMsgBuffer, pInt_MsgLen, lpszMsgBuffer, nMsgLen);
}
extern "C" BOOL ProtocolModule_Packet_HttpCommon(XENGINE_PROTOCOLHDR * pSt_ProtocolHdr, XENGINE_PROTOCOL_XMQ * pSt_MQProtocol, TCHAR * ptszMsgBuffer, int* pInt_MsgLen, LPCTSTR lpszMsgBuffer, int nMsgLen, ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE enPayType)
extern "C" BOOL ProtocolModule_Packet_MQNumber(XENGINE_PROTOCOLHDR * pSt_ProtocolHdr, XENGINE_MQNUMBER * pSt_MQNumber, TCHAR * ptszMsgBuffer, int* pInt_MsgLen, int nNetType)
{
return m_ProtocolPacket.ProtocolModule_Packet_HttpCommon(pSt_ProtocolHdr, pSt_MQProtocol, ptszMsgBuffer, pInt_MsgLen, lpszMsgBuffer, nMsgLen, enPayType);
return m_ProtocolPacket.ProtocolModule_Packet_MQNumber(pSt_ProtocolHdr, pSt_MQNumber, ptszMsgBuffer, pInt_MsgLen, nNetType);
}
extern "C" BOOL ProtocolModule_Packet_MQNumber(XENGINE_PROTOCOLHDR * pSt_ProtocolHdr, XENGINE_MQNUMBER * pSt_MQNumber, TCHAR * ptszMsgBuffer, int* pInt_MsgLen)
extern "C" BOOL ProtocolModule_Packet_PassAuth(XENGINE_PROTOCOL_USERAUTH * pSt_ProtocolAuth, TCHAR * ptszMsgBuffer, int* pInt_MsgLen)
{
return m_ProtocolPacket.ProtocolModule_Packet_MQNumber(pSt_ProtocolHdr, pSt_MQNumber, ptszMsgBuffer, pInt_MsgLen);
return m_ProtocolPacket.ProtocolModule_Packet_PassAuth(pSt_ProtocolAuth, ptszMsgBuffer, pInt_MsgLen);
}
extern "C" BOOL ProtocolModule_Packet_DDSTopic(XENGINE_PROTOCOL_XDDS * pSt_DDSProtocol, TCHAR * ptszMsgBuffer, int* pInt_MsgLen, DWORD dwOPeratorCode)
{
......@@ -54,9 +54,9 @@ extern "C" BOOL ProtocolModule_Packet_DDSQuery(XENGINE_PROTOCOL_XDDS * **pppSt_D
/************************************************************************/
/* 解析类函数 */
/************************************************************************/
extern "C" BOOL ProtocolModule_Parse_Http(LPCTSTR lpszMsgBuffer, int nMsgLen, XENGINE_PROTOCOL_XMQ * pSt_MQProtocol, XENGINE_PROTOCOLHDR * pSt_ProtocolHdr, TCHAR * *pptszMsgBuffer, int* pInt_MsgLen, int* pInt_Type)
extern "C" BOOL ProtocolModule_Parse_Http(LPCTSTR lpszMsgBuffer, int nMsgLen, XENGINE_PROTOCOLHDR * pSt_ProtocolHdr, TCHAR * *pptszMsgBuffer, int* pInt_MsgLen)
{
return m_ProtocolParse.ProtocolModule_Parse_Http(lpszMsgBuffer, nMsgLen, pSt_MQProtocol, pSt_ProtocolHdr, pptszMsgBuffer, pInt_MsgLen, pInt_Type);
return m_ProtocolParse.ProtocolModule_Parse_Http(lpszMsgBuffer, nMsgLen, pSt_ProtocolHdr, pptszMsgBuffer, pInt_MsgLen);
}
extern "C" BOOL ProtocolModule_Parse_DDSQuery(LPCTSTR lpszMsgBuffer, int nMsgLen, XENGINE_PROTOCOL_XDDS * **pppSt_DDSProtocol, int* pInt_ListCount)
{
......
......@@ -11,9 +11,14 @@ EXPORTS
SessionModule_Client_Set
SessionModule_Client_SetOrder
SessionModule_Client_ADDDelSerial
SessionModule_Client_SetAuth
SessionModule_Notify_Create
SessionModule_Notify_Destory
SessionModule_Notify_Insert
SessionModule_Notify_Delete
SessionModule_Notify_GetList
\ No newline at end of file
SessionModule_Notify_GetList
SessionModule_Auth_Init
SessionModule_Auth_Destory
SessionModule_Auth_Exist
\ No newline at end of file
......@@ -168,6 +168,7 @@
<ItemGroup>
<ClInclude Include="framework.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="SessionModule_Auth\SessionModule_Auth.h" />
<ClInclude Include="SessionModule_Client\SessionModule_Client.h" />
<ClInclude Include="SessionModule_Notify\SessionModule_Notify.h" />
<ClInclude Include="Session_Define.h" />
......@@ -181,6 +182,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="SessionModule_Auth\SessionModule_Auth.cpp" />
<ClCompile Include="SessionModule_Client\SessionModule_Client.cpp" />
<ClCompile Include="SessionModule_Notify\SessionModule_Notify.cpp" />
</ItemGroup>
......
......@@ -25,6 +25,12 @@
<Filter Include="头文件\SessionModule_Notify">
<UniqueIdentifier>{0d02b2a6-4fc5-4c48-afeb-28053ac7e1df}</UniqueIdentifier>
</Filter>
<Filter Include="头文件\SessionModule_Auth">
<UniqueIdentifier>{626b0ed9-1642-412d-b656-537734ef930c}</UniqueIdentifier>
</Filter>
<Filter Include="源文件\SessionModule_Auth">
<UniqueIdentifier>{a44c921b-25c4-4a88-abe7-bce77c590314}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="framework.h">
......@@ -45,6 +51,9 @@
<ClInclude Include="SessionModule_Notify\SessionModule_Notify.h">
<Filter>头文件\SessionModule_Notify</Filter>
</ClInclude>
<ClInclude Include="SessionModule_Auth\SessionModule_Auth.h">
<Filter>头文件\SessionModule_Auth</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
......@@ -59,6 +68,9 @@
<ClCompile Include="SessionModule_Notify\SessionModule_Notify.cpp">
<Filter>源文件\SessionModule_Notify</Filter>
</ClCompile>
<ClCompile Include="SessionModule_Auth\SessionModule_Auth.cpp">
<Filter>源文件\SessionModule_Auth</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="MQCore_SessionModule.def">
......
......@@ -6,7 +6,7 @@ LOADBIN =
LIB =
LIBEX = -static-libgcc -lrt -ldl -lpthread
LOADSO = -Wl,-rpath=
LIBINCLUDE = SessionModule_Client.o SessionModule_Notify.o pch.o
LIBINCLUDE = SessionModule_Client.o SessionModule_Notify.o SessionModule_Auth.o pch.o
ifeq ($(RELEASE),1)
FLAGS = -c -O2
......@@ -30,7 +30,9 @@ SessionModule_Client.o:./SessionModule_Client/SessionModule_Client.cpp
$(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(INCLUDE) ./SessionModule_Client/SessionModule_Client.cpp
SessionModule_Notify.o:./SessionModule_Notify/SessionModule_Notify.cpp
$(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(INCLUDE) ./SessionModule_Notify/SessionModule_Notify.cpp
SessionModule_Auth.o:./SessionModule_Auth/SessionModule_Auth.cpp
$(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(INCLUDE) ./SessionModule_Auth/SessionModule_Auth.cpp
pch.o:./pch.cpp
$(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(INCLUDE) ./pch.cpp
......
#include "pch.h"
#include "SessionModule_Auth.h"
/********************************************************************
// Created: 2021/11/16 15:33:13
// File Name: D:\XEngine_MQService\XEngine_Source\MQCore_SessionModule\SessionModule_Auth\SessionModule_Auth.cpp
// File Path: D:\XEngine_MQService\XEngine_Source\MQCore_SessionModule\SessionModule_Auth
// File Base: SessionModule_Auth
// File Ext: cpp
// Project: XEngine(网络通信引擎)
// Author: qyt
// Purpose: 授权验证
// History:
*********************************************************************/
CSessionModule_Auth::CSessionModule_Auth()
{
}
CSessionModule_Auth::~CSessionModule_Auth()
{
}
///////////////////////////////////////////////////////////////////////////////
// 公有函数
///////////////////////////////////////////////////////////////////////////////
/********************************************************************
函数名称:SessionModule_Auth_Init
函数功能:初始化授权会话管理器
参数.一:lpszAuthFile
In/Out:In
类型:常量字符指针
可空:N
意思:输入授权文件地址
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
BOOL CSessionModule_Auth::SessionModule_Auth_Init(LPCTSTR lpszAuthFile)
{
Session_IsErrorOccur = FALSE;
FILE* pSt_File = _tfopen(lpszAuthFile, _T("rb"));
if (NULL == pSt_File)
{
Session_IsErrorOccur = TRUE;
Session_dwErrorCode = ERROR_MQ_MODULE_SESSION_OPENFILE;
return FALSE;
}
int nCount = 0;
TCHAR tszMsgBuffer[4096];
memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
while (TRUE)
{
int nRet = fread(tszMsgBuffer + nCount, 1, 1024, pSt_File);
if (nRet <= 0)
{
break;
}
nCount += nRet;
}
fclose(pSt_File);
LPCTSTR lpszLineStr = _T("\r\n");
TCHAR* ptszTokStr = _tcstok(tszMsgBuffer, lpszLineStr);
while (1)
{
if (NULL == ptszTokStr)
{
break;
}
XENGINE_SESSIONAUTH st_UserInfo;
memset(&st_UserInfo, '\0', sizeof(XENGINE_SESSIONAUTH));
_stscanf(ptszTokStr, _T("%s %s"), st_UserInfo.tszUserName, st_UserInfo.tszUserPass);
stl_MapSession.insert(make_pair(st_UserInfo.tszUserName, st_UserInfo));
ptszTokStr = _tcstok(NULL, lpszLineStr);
}
return TRUE;
}
/************************************************************************
函数名称:SessionModule_Auth_Destory
函数功能:销毁授权管理器
返回值
类型:逻辑型
意思:是否销毁成功
备注:
************************************************************************/
BOOL CSessionModule_Auth::SessionModule_Auth_Destory()
{
Session_IsErrorOccur = FALSE;
stl_MapSession.clear();
return TRUE;
}
/********************************************************************
函数名称:SessionModule_Auth_Exist
函数功能:是否验证通过
参数.一:lpszUser
In/Out:In
类型:常量字符指针
可空:N
意思:输入用户名
参数.二:lpszPass
In/Out:In
类型:常量字符指针
可空:N
意思:输入密码
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
BOOL CSessionModule_Auth::SessionModule_Auth_Exist(LPCTSTR lpszUser, LPCTSTR lpszPass)
{
Session_IsErrorOccur = FALSE;
unordered_map<string, XENGINE_SESSIONAUTH>::const_iterator stl_MapIterator = stl_MapSession.find(lpszUser);
if (stl_MapIterator == stl_MapSession.end())
{
Session_IsErrorOccur = TRUE;
Session_dwErrorCode = ERROR_MQ_MODULE_SESSION_NOTFOUND;
return FALSE;
}
if (_tcslen(lpszPass) != _tcslen(stl_MapIterator->second.tszUserPass))
{
Session_IsErrorOccur = TRUE;
Session_dwErrorCode = ERROR_MQ_MODULE_SESSION_PASSWORD;
return FALSE;
}
if (0 != _tcsncmp(lpszPass, stl_MapIterator->second.tszUserPass, _tcslen(lpszPass)))
{
Session_IsErrorOccur = TRUE;
Session_dwErrorCode = ERROR_MQ_MODULE_SESSION_PASSWORD;
return FALSE;
}
return TRUE;
}
\ No newline at end of file
#pragma once
/********************************************************************
// Created: 2021/11/16 15:30:48
// File Name: D:\XEngine_MQService\XEngine_Source\MQCore_SessionModule\SessionModule_Auth\SessionModule_Auth.h
// File Path: D:\XEngine_MQService\XEngine_Source\MQCore_SessionModule\SessionModule_Auth
// File Base: SessionModule_Auth
// File Ext: h
// Project: XEngine(网络通信引擎)
// Author: qyt
// Purpose: 授权验证
// History:
*********************************************************************/
typedef struct
{
TCHAR tszUserName[64];
TCHAR tszUserPass[64];
}XENGINE_SESSIONAUTH, * LPXENGINE_SESSIONAUTH;
class CSessionModule_Auth
{
public:
CSessionModule_Auth();
~CSessionModule_Auth();
public:
BOOL SessionModule_Auth_Init(LPCTSTR lpszAuthFile);
BOOL SessionModule_Auth_Destory();
BOOL SessionModule_Auth_Exist(LPCTSTR lpszUser, LPCTSTR lpszPass);
private:
unordered_map<tstring, XENGINE_SESSIONAUTH> stl_MapSession;
};
......@@ -56,12 +56,17 @@ BOOL CSessionModule_Client::SessionModule_Client_Destory()
类型:常量字符指针
可空:N
意思:输入用户名
参数.二:nNetType
In/Out:In
类型:整数型
可空:N
意思:客户端的网络连接类型
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
BOOL CSessionModule_Client::SessionModule_Client_Create(LPCTSTR lpszClientAddr)
BOOL CSessionModule_Client::SessionModule_Client_Create(LPCTSTR lpszClientAddr, int nNetType)
{
Session_IsErrorOccur = FALSE;
......@@ -76,6 +81,7 @@ BOOL CSessionModule_Client::SessionModule_Client_Create(LPCTSTR lpszClientAddr)
st_SessionInfo.bOrder = TRUE;
st_SessionInfo.nSerialPos = 1;
st_SessionInfo.nNetType = nNetType;
st_SessionInfo.nStartTime = time(NULL);
st_Locker.lock();
......@@ -123,12 +129,17 @@ BOOL CSessionModule_Client::SessionModule_Client_Delete(LPCTSTR lpszClientAddr)
类型:数据结构指针
可空:N
意思:输出消息内容
参数.三:pbAuth
In/Out:Out
类型:逻辑型
可空:N
意思:输出是否通过了验证
返回值
类型:逻辑型
意思:是否成功
备注:
************************************************************************/
BOOL CSessionModule_Client::SessionModule_Client_Get(LPCTSTR lpszClientAddr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol)
BOOL CSessionModule_Client::SessionModule_Client_Get(LPCTSTR lpszClientAddr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol, BOOL* pbAuth)
{
Session_IsErrorOccur = FALSE;
......@@ -147,6 +158,7 @@ BOOL CSessionModule_Client::SessionModule_Client_Get(LPCTSTR lpszClientAddr, XEN
st_Locker.unlock_shared();
return FALSE;
}
*pbAuth = stl_MapIterator->second.bAuth;
pSt_MQProtocol->nSerial = stl_MapIterator->second.nSerialPos;
_tcscpy(pSt_MQProtocol->tszMQKey, stl_MapIterator->second.tszKeyStr);
st_Locker.unlock_shared();
......@@ -292,4 +304,46 @@ BOOL CSessionModule_Client::SessionModule_Client_ADDDelSerial(LPCTSTR lpszClient
}
st_Locker.unlock_shared();
return TRUE;
}
/********************************************************************
函数名称:SessionModule_Client_SetAuth
函数功能:设置会话验证信息
参数.一:lpszClientAddr
In/Out:In
类型:常量字符指针
可空:N
意思:输入要操作的客户端
参数.二:bAuth
In/Out:In
类型:逻辑型
可空:Y
意思:验证结果
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
BOOL CSessionModule_Client::SessionModule_Client_SetAuth(LPCTSTR lpszClientAddr, BOOL bAuth /* = TRUE */)
{
Session_IsErrorOccur = FALSE;
if (NULL == lpszClientAddr)
{
Session_IsErrorOccur = TRUE;
Session_dwErrorCode = ERROR_MQ_MODULE_SESSION_PARAMENT;
return FALSE;
}
st_Locker.lock_shared();
unordered_map<tstring, XENGINE_SESSIONINFO>::iterator stl_MapIterator = stl_MapSession.find(lpszClientAddr);
if (stl_MapIterator == stl_MapSession.end())
{
Session_IsErrorOccur = TRUE;
Session_dwErrorCode = ERROR_MQ_MODULE_SESSION_NOTFOUND;
st_Locker.unlock_shared();
return FALSE;
}
stl_MapIterator->second.bAuth = bAuth;
st_Locker.unlock_shared();
return TRUE;
}
\ No newline at end of file
......@@ -14,6 +14,8 @@ typedef struct
{
TCHAR tszKeyStr[128]; //主题名称
__int64x nSerialPos; //当前序列号标记
int nNetType; //网络类型
BOOL bAuth; //是否通过验证
BOOL bOrder; //顺序还是倒序
time_t nStartTime; //时间
}XENGINE_SESSIONINFO, * LPXENGINE_SESSIONINFO;
......@@ -26,12 +28,13 @@ public:
public:
BOOL SessionModule_Client_Init();
BOOL SessionModule_Client_Destory();
BOOL SessionModule_Client_Create(LPCTSTR lpszClientAddr);
BOOL SessionModule_Client_Create(LPCTSTR lpszClientAddr, int nNetType);
BOOL SessionModule_Client_Delete(LPCTSTR lpszClientAddr);
BOOL SessionModule_Client_Get(LPCTSTR lpszClientAddr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol);
BOOL SessionModule_Client_Get(LPCTSTR lpszClientAddr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol, BOOL *pbAuth);
BOOL SessionModule_Client_Set(LPCTSTR lpszClientAddr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol);
BOOL SessionModule_Client_SetOrder(LPCTSTR lpszClientAddr, LPCTSTR lpszKeyStr, BOOL bOrder, __int64x nMQSerial);
BOOL SessionModule_Client_ADDDelSerial(LPCTSTR lpszClientAddr);
BOOL SessionModule_Client_SetAuth(LPCTSTR lpszClientAddr, BOOL bAuth = TRUE);
private:
shared_mutex st_Locker;
private:
......
......@@ -61,12 +61,17 @@ extern "C" BOOL SessionModule_Client_Destory();
类型:常量字符指针
可空:N
意思:输入用户名
参数.二:nNetType
In/Out:In
类型:整数型
可空:N
意思:客户端的网络连接类型
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
extern "C" BOOL SessionModule_Client_Create(LPCTSTR lpszClientAddr);
extern "C" BOOL SessionModule_Client_Create(LPCTSTR lpszClientAddr, int nNetType);
/********************************************************************
函数名称:SessionModule_Client_Delete
函数功能:删除一个用户
......@@ -94,12 +99,17 @@ extern "C" BOOL SessionModule_Client_Delete(LPCTSTR lpszClientAddr);
类型:数据结构指针
可空:N
意思:输出消息内容
参数.三:pbAuth
In/Out:Out
类型:逻辑型
可空:N
意思:输出是否通过了验证
返回值
类型:逻辑型
意思:是否成功
备注:
************************************************************************/
extern "C" BOOL SessionModule_Client_Get(LPCTSTR lpszClientAddr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol);
extern "C" BOOL SessionModule_Client_Get(LPCTSTR lpszClientAddr, XENGINE_PROTOCOL_XMQ* pSt_MQProtocol, BOOL * pbAuth);
/************************************************************************
函数名称:SessionModule_Client_Set
函数功能:设置客户端信息
......@@ -162,6 +172,25 @@ extern "C" BOOL SessionModule_Client_SetOrder(LPCTSTR lpszClientAddr, LPCTSTR lp
备注:
*********************************************************************/
extern "C" BOOL SessionModule_Client_ADDDelSerial(LPCTSTR lpszClientAddr);
/********************************************************************
函数名称:SessionModule_Client_SetAuth
函数功能:设置会话验证信息
参数.一:lpszClientAddr
In/Out:In
类型:常量字符指针
可空:N
意思:输入要操作的客户端
参数.二:bAuth
In/Out:In
类型:逻辑型
可空:Y
意思:验证结果
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
extern "C" BOOL SessionModule_Client_SetAuth(LPCTSTR lpszClientAddr, BOOL bAuth = TRUE);
/************************************************************************/
/* 订阅 */
/************************************************************************/
......@@ -264,4 +293,49 @@ extern "C" BOOL SessionModule_Notify_Delete(LPCTSTR lpszTopicStr, LPCTSTR lpszCl
意思:是否成功
备注:
*********************************************************************/
extern "C" BOOL SessionModule_Notify_GetList(LPCTSTR lpszTopicStr, SESSION_NOTIFYCLIENT *** pppSt_ListClient, int* pInt_ListCount);
\ No newline at end of file
extern "C" BOOL SessionModule_Notify_GetList(LPCTSTR lpszTopicStr, SESSION_NOTIFYCLIENT *** pppSt_ListClient, int* pInt_ListCount);
/************************************************************************/
/* 验证 */
/************************************************************************/
/********************************************************************
函数名称:SessionModule_Auth_Init
函数功能:初始化授权会话管理器
参数.一:lpszAuthFile
In/Out:In
类型:常量字符指针
可空:N
意思:输入授权文件地址
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
extern "C" BOOL SessionModule_Auth_Init(LPCTSTR lpszAuthFile);
/************************************************************************
函数名称:SessionModule_Auth_Destory
函数功能:销毁授权管理器
返回值
类型:逻辑型
意思:是否销毁成功
备注:
************************************************************************/
extern "C" BOOL SessionModule_Auth_Destory();
/********************************************************************
函数名称:SessionModule_Auth_Exist
函数功能:是否验证通过
参数.一:lpszUser
In/Out:In
类型:常量字符指针
可空:N
意思:输入用户名
参数.二:lpszPass
In/Out:In
类型:常量字符指针
可空:N
意思:输入密码
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
extern "C" BOOL SessionModule_Auth_Exist(LPCTSTR lpszUser, LPCTSTR lpszPass);
\ No newline at end of file
......@@ -11,4 +11,6 @@
// History:
*********************************************************************/
#define ERROR_MQ_MODULE_SESSION_PARAMENT 0x0040001
#define ERROR_MQ_MODULE_SESSION_NOTFOUND 0x0040002
\ No newline at end of file
#define ERROR_MQ_MODULE_SESSION_NOTFOUND 0x0040002
#define ERROR_MQ_MODULE_SESSION_OPENFILE 0x0040003
#define ERROR_MQ_MODULE_SESSION_PASSWORD 0x0040004
\ No newline at end of file
#include "pch.h"
#include "SessionModule_Client/SessionModule_Client.h"
#include "SessionModule_Notify/SessionModule_Notify.h"
#include "SessionModule_Auth/SessionModule_Auth.h"
/********************************************************************
// Created: 2021/07/02 10:39:24
// File Name: D:\XEngine_MQService\XEngine_Source\MQCore_SessionModule\pch.cpp
......@@ -17,6 +18,7 @@ DWORD Session_dwErrorCode = 0;
//////////////////////////////////////////////////////////////////////////
CSessionModule_Client m_SessionClient;
CSessionModule_Notify m_SessionNotify;
CSessionModule_Auth m_SessionAuth;
//////////////////////////////////////////////////////////////////////////
// 导出函数实现
//////////////////////////////////////////////////////////////////////////
......@@ -39,17 +41,17 @@ extern "C" BOOL SessionModule_Client_Destory()
{
return m_SessionClient.SessionModule_Client_Destory();
}
extern "C" BOOL SessionModule_Client_Create(LPCTSTR lpszClientAddr)
extern "C" BOOL SessionModule_Client_Create(LPCTSTR lpszClientAddr, int nNetType)
{
return m_SessionClient.SessionModule_Client_Create(lpszClientAddr);
return m_SessionClient.SessionModule_Client_Create(lpszClientAddr, nNetType);
}
extern "C" BOOL SessionModule_Client_Delete(LPCTSTR lpszClientAddr)
{
return m_SessionClient.SessionModule_Client_Delete(lpszClientAddr);
}
extern "C" BOOL SessionModule_Client_Get(LPCTSTR lpszClientAddr, XENGINE_PROTOCOL_XMQ * pSt_MQProtocol)
extern "C" BOOL SessionModule_Client_Get(LPCTSTR lpszClientAddr, XENGINE_PROTOCOL_XMQ * pSt_MQProtocol, BOOL * pbAuth)
{
return m_SessionClient.SessionModule_Client_Get(lpszClientAddr, pSt_MQProtocol);
return m_SessionClient.SessionModule_Client_Get(lpszClientAddr, pSt_MQProtocol, pbAuth);
}
extern "C" BOOL SessionModule_Client_Set(LPCTSTR lpszClientAddr, XENGINE_PROTOCOL_XMQ * pSt_MQProtocol)
{
......@@ -63,6 +65,10 @@ extern "C" BOOL SessionModule_Client_ADDDelSerial(LPCTSTR lpszClientAddr)
{
return m_SessionClient.SessionModule_Client_ADDDelSerial(lpszClientAddr);
}
extern "C" BOOL SessionModule_Client_SetAuth(LPCTSTR lpszClientAddr, BOOL bAuth)
{
return m_SessionClient.SessionModule_Client_SetAuth(lpszClientAddr, bAuth);
}
/************************************************************************/
/* 订阅 */
/************************************************************************/
......@@ -85,4 +91,19 @@ extern "C" BOOL SessionModule_Notify_Delete(LPCTSTR lpszTopicStr, LPCTSTR lpszCl
extern "C" BOOL SessionModule_Notify_GetList(LPCTSTR lpszTopicStr, SESSION_NOTIFYCLIENT * **pppSt_ListClient, int* pInt_ListCount)
{
return m_SessionNotify.SessionModule_Notify_GetList(lpszTopicStr, pppSt_ListClient, pInt_ListCount);
}
/************************************************************************/
/* 验证 */
/************************************************************************/
extern "C" BOOL SessionModule_Auth_Init(LPCTSTR lpszAuthFile)
{
return m_SessionAuth.SessionModule_Auth_Init(lpszAuthFile);
}
extern "C" BOOL SessionModule_Auth_Destory()
{
return m_SessionAuth.SessionModule_Auth_Destory();
}
extern "C" BOOL SessionModule_Auth_Exist(LPCTSTR lpszUser, LPCTSTR lpszPass)
{
return m_SessionAuth.SessionModule_Auth_Exist(lpszUser, lpszPass);
}
\ No newline at end of file
......@@ -10,6 +10,8 @@
// Purpose: 消息队列服务
// History:
*********************************************************************/
#define XENGINE_INT64X_MAX_VALUE 102400000
typedef struct
{
XENGINE_PROTOCOL_XMQ st_XMQProtocol; //XMQ子协议
......
......@@ -12,5 +12,9 @@ copy /y "%XEngine_Library%\x86\XEngine_HelpComponents\HelpComponents_XLog.dll" "
copy /y "%XEngine_Library%\x86\XEngine_RfcComponents\RfcComponents_HttpServer.dll" "./"
copy /y "%XEngine_Library%\x86\XEngine_RfcComponents\RfcComponents_WSProtocol.dll" "./"
copy /y "%XEngine_Library%\x86\XEngine_NetHelp\NetHelp_APIHelp.dll" "./"
copy /y "%XEngine_Library%\x86\XEngine_LibEx\libcrypto-1_1.dll" "./"
copy /y "%XEngine_Library%\x86\XEngine_LibEx\libssl-1_1.dll" "./"
\ No newline at end of file
copy /y "%XEngine_Library%\x86\XEngine_LibEx\libssl-1_1.dll" "./"
copy /y "%XEngine_Library%\x86\XEngine_LibEx\libcurl.dll" "./"
copy /y "%XEngine_Library%\x86\XEngine_HelpComponents\zlib1.dll" "./"
\ No newline at end of file
......@@ -10,4 +10,6 @@ copy /y "D:\XEngine\XEngine_SourceCode\Debug\HelpComponents_Packets.dll" "./"
copy /y "D:\XEngine\XEngine_SourceCode\Debug\HelpComponents_XLog.dll" "./"
copy /y "D:\XEngine\XEngine_SourceCode\Debug\RfcComponents_HttpServer.dll" "./"
copy /y "D:\XEngine\XEngine_SourceCode\Debug\RfcComponents_WSProtocol.dll" "./"
\ No newline at end of file
copy /y "D:\XEngine\XEngine_SourceCode\Debug\RfcComponents_WSProtocol.dll" "./"
copy /y "D:\XEngine\XEngine_SourceCode\Debug\NetHelp_APIHelp.dll" "./"
\ No newline at end of file
......@@ -3,6 +3,10 @@
#include <Windows.h>
#include <tchar.h>
#include <io.h>
#else
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#endif
#include <stdio.h>
#include <stdlib.h>
......@@ -31,6 +35,9 @@ using namespace std;
#include <XEngine_Include/XEngine_RfcComponents/HttpServer_Error.h>
#include <XEngine_Include/XEngine_RfcComponents/WSProtocol_Define.h>
#include <XEngine_Include/XEngine_RfcComponents/WSProtocol_Error.h>
#include <XEngine_Include/XEngine_NetHelp/APIHelp_Define.h>
#include <XEngine_Include/XEngine_NetHelp/APIHelp_Error.h>
#ifdef _UNICODE
typedef std::wstring tstring;
#else
......@@ -48,10 +55,6 @@ typedef std::string tstring;
#include "../MQCore_SessionModule/Session_Define.h"
#include "../MQCore_SessionModule/Session_Error.h"
#define XENGINE_MQAPP_NETTYPE_TCP 1
#define XENGINE_MQAPP_NETTYPE_HTTP 2
#define XENGINE_MQAPP_NETTYPE_WEBSOCKET 3
extern BOOL bIsRun;
extern XLOG xhLog;
extern XNETHANDLE xhTCPSocket;
......@@ -61,8 +64,9 @@ extern XNETHANDLE xhWSSocket;
extern XNETHANDLE xhTCPHeart;
extern XNETHANDLE xhWSHeart;
extern XNETHANDLE xhTCPPacket;
extern XHANDLE xhTCPPacket;
extern XHANDLE xhHTTPPacket;
extern XHANDLE xhWSPacket;
extern XNETHANDLE xhTCPPool;
extern XNETHANDLE xhHttpPool;
......@@ -72,7 +76,6 @@ extern SOCKET hSDSocket;
extern SOCKET hRVSocket;
extern XENGINE_SERVERCONFIG st_ServiceCfg;
extern shared_ptr<std::thread> pSTDThread;
void ServiceApp_Stop(int signo);
......@@ -113,5 +116,6 @@ void ServiceApp_Stop(int signo);
#pragma comment(lib,"XEngine_HelpComponents/HelpComponents_Packets.lib")
#pragma comment(lib,"XEngine_RfcComponents/RfcComponents_HttpServer.lib")
#pragma comment(lib,"XEngine_RfcComponents/RfcComponents_WSProtocol.lib")
#pragma comment(lib,"XEngine_NetHelp/NetHelp_APIHelp.lib")
#pragma comment(lib,"Ws2_32.lib")
#endif
\ No newline at end of file
......@@ -45,180 +45,17 @@ XHTHREAD CALLBACK MessageQueue_HttpThread(LPVOID lParam)
}
BOOL MessageQueue_Http_Handle(RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam, LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen, TCHAR** pptszListHdr, int nHdrCount)
{
int nSDLen = 2048;
int nRVLen = 2048;
int nJSLen = 0;
int nMsgType = 0;
TCHAR tszSDBuffer[2048];
TCHAR tszRVBuffer[2048];
TCHAR* ptszMsgBuffer = NULL;
LPCTSTR lpszMethod = _T("POST");
memset(tszSDBuffer, '\0', sizeof(tszSDBuffer));
memset(tszRVBuffer, '\0', sizeof(tszRVBuffer));
if (0 == _tcsnicmp(lpszMethod, pSt_HTTPParam->tszHttpMethod, _tcslen(lpszMethod)))
{
int nPLen = 0;
TCHAR* ptszMsgBuffer = NULL;
XENGINE_PROTOCOLHDR st_ProtocolHdr;
XENGINE_PROTOCOL_XMQ st_MQProtocol;
memset(&st_ProtocolHdr, '\0', sizeof(XENGINE_PROTOCOLHDR));
memset(&st_MQProtocol, '\0', sizeof(XENGINE_PROTOCOL_XMQ));
ProtocolModule_Parse_Http(lpszMsgBuffer, nMsgLen, &st_MQProtocol, &st_ProtocolHdr, &ptszMsgBuffer, &nRVLen, &nMsgType);
if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQPOST == st_ProtocolHdr.unOperatorCode)
{
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REPPOST;
if (!XMQModule_Packet_Post(&st_MQProtocol, ptszMsgBuffer, nJSLen))
{
st_ProtocolHdr.wReserve = 701;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_HTTP);
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("HTTP消息端:%s,主题:%s,序列:%lld,投递数据报失败,无法继续,错误:%lX"), lpszClientAddr, st_MQProtocol.tszMQKey, st_MQProtocol.nSerial, XMQModule_GetLastError());
return FALSE;
}
st_ProtocolHdr.wReserve = 0;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_HTTP);
int nListCount = 0;
SESSION_NOTIFYCLIENT** ppSt_ListAddr;
if (SessionModule_Notify_GetList(st_MQProtocol.tszMQKey, &ppSt_ListAddr, &nListCount))
{
int nTCPLen = 0;
int nWSLen = 0;
TCHAR tszTCPBuffer[4096];
TCHAR tszWSBuffer[4096];
memset(tszTCPBuffer, '\0', sizeof(tszTCPBuffer));
memset(tszWSBuffer, '\0', sizeof(tszWSBuffer));
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_MSGNOTIFY;
ProtocolModule_Packet_TCPCommon(&st_ProtocolHdr, &st_MQProtocol, tszTCPBuffer, &nTCPLen, ptszMsgBuffer, nJSLen);
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszWSBuffer, &nWSLen, ptszMsgBuffer, nJSLen);
for (int i = 0; i < nListCount; i++)
{
if (ENUM_MQCORE_SESSION_CLIENT_TYPE_TCP == ppSt_ListAddr[i]->enClientType)
{
XEngine_MQXService_Send(ppSt_ListAddr[i]->tszNotifyAddr, tszTCPBuffer, nTCPLen, XENGINE_MQAPP_NETTYPE_TCP);
}
else if (ENUM_MQCORE_SESSION_CLIENT_TYPE_WEBSOCKET == ppSt_ListAddr[i]->enClientType)
{
XEngine_MQXService_Send(ppSt_ListAddr[i]->tszNotifyAddr, tszWSBuffer, nWSLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
}
}
BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListAddr, nListCount);
}
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("HTTP消息端:%s,主题:%s,序列:%lld,投递数据到消息队列成功,通知客户端个数:%d"), lpszClientAddr, st_MQProtocol.tszMQKey, st_MQProtocol.nSerial, nListCount);
}
else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQGET == st_ProtocolHdr.unOperatorCode)
{
TCHAR tszMsgBuffer[8196];
memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REPGET;
if ((st_MQProtocol.nSerial <= 0))
{
st_ProtocolHdr.wReserve = 721;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_HTTP);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("HTTP消息端:%s,主题:%s,获取消息数据失败,序列号为0,无法继续"), lpszClientAddr, st_MQProtocol.tszMQKey);
return FALSE;
}
if (!XMQModule_Packet_Get(&st_MQProtocol, tszMsgBuffer, &nRVLen))
{
st_ProtocolHdr.wReserve = 722;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_HTTP);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("HTTP消息端:%s,主题:%s,序列:%lld,获取消息数据失败,无法继续,错误:%lX"), lpszClientAddr, st_MQProtocol.tszMQKey, st_MQProtocol.nSerial, XMQModule_GetLastError());
return FALSE;
}
st_ProtocolHdr.wReserve = 0;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen, tszMsgBuffer, nRVLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_HTTP);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("HTTP消息端:%s,主题:%s,序列:%lld,获取消息数据成功,消息大小:%d"), lpszClientAddr, st_MQProtocol.tszMQKey, st_MQProtocol.nSerial, nRVLen);
}
else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQDEL == st_ProtocolHdr.unOperatorCode)
{
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REPDEL;
if (!XMQModule_Packet_Del(&st_MQProtocol))
{
st_ProtocolHdr.wReserve = 741;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_HTTP);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("HTTP消息端:%s,主题:%s,序列:%lld,删除消息队列中的数据失败,错误:%lX"), lpszClientAddr, st_MQProtocol.tszMQKey, st_MQProtocol.nSerial, XMQModule_GetLastError());
return FALSE;
}
st_ProtocolHdr.wReserve = 0;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_HTTP);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("HTTP消息端:%s,主题:%s,序列:%lld,删除消息队列中的数据成功"), lpszClientAddr, st_MQProtocol.tszMQKey, st_MQProtocol.nSerial);
}
else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQCREATE == st_ProtocolHdr.unOperatorCode)
{
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REPCREATE;
if (!XMQModule_Packet_TopicCreate(st_MQProtocol.tszMQKey))
{
st_ProtocolHdr.wReserve = 761;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_HTTP);
DWORD dwRet = XMQModule_GetLastError();
if (ERROR_MQ_MODULE_PACKET_CREATE_EXIST == dwRet)
{
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("HTTP消息端:%s,创建主题名称:%s,已经存在.无法继续创建"), lpszClientAddr, st_MQProtocol.tszMQKey);
}
else
{
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("HTTP消息端:%s,创建主题失败,主题名称:%s,无法继续,错误:%lX"), lpszClientAddr, st_MQProtocol.tszMQKey, XMQModule_GetLastError());
}
return FALSE;
}
st_ProtocolHdr.wReserve = 0;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_HTTP);
SessionModule_Notify_Create(st_MQProtocol.tszMQKey);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("HTTP消息端:%s,主题:%s,创建主题成功"), lpszClientAddr, st_MQProtocol.tszMQKey);
}
else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQDELETE == st_ProtocolHdr.unOperatorCode)
{
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REPDELETE;
if (!XMQModule_Packet_TopicDelete(st_MQProtocol.tszMQKey))
{
st_ProtocolHdr.wReserve = 781;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_HTTP);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("HTTP消息端:%s,删除主题失败,主题名称:%s,无法继续,错误:%lX"), lpszClientAddr, st_MQProtocol.tszMQKey, XMQModule_GetLastError());
return FALSE;
}
st_ProtocolHdr.wReserve = 0;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_HTTP);
SessionModule_Notify_Destory(st_MQProtocol.tszMQKey);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("HTTP消息端:%s,主题:%s,删除主题成功"), lpszClientAddr, st_MQProtocol.tszMQKey);
}
else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQNUMBER == st_ProtocolHdr.unOperatorCode)
{
XENGINE_MQNUMBER st_MQNumber;
memset(&st_MQNumber, '\0', sizeof(XENGINE_MQNUMBER));
st_ProtocolHdr.wReserve = 0;
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REPNUMBER;
_tcscpy(st_MQNumber.tszMQKey, st_MQProtocol.tszMQKey);
if (!XMQModule_Packet_GetSerial(st_MQNumber.tszMQKey, &st_MQNumber.nFirstNumber, &st_MQNumber.nLastNumber))
{
st_ProtocolHdr.wReserve = 714;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_HTTP);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("HTTP消息端:%s,获取主题序列编号失败,主题名称:%s,错误:%lX"), lpszClientAddr, st_MQProtocol.tszMQKey, SessionModule_GetLastError());
return FALSE;
}
XMQModule_Packet_GetCount(st_MQNumber.tszMQKey, &st_MQNumber.nCount);
ProtocolModule_Packet_MQNumber(&st_ProtocolHdr, &st_MQNumber, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_HTTP);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("HTTP消息端:%s,获取主题序列编号成功,主题名称:%s,队列个数:%lld,开始编号:%lld,结尾编号:%lld"), lpszClientAddr, st_MQNumber.tszMQKey, st_MQNumber.nCount, st_MQNumber.nFirstNumber, st_MQNumber.nLastNumber);
}
ProtocolModule_Parse_Http(lpszMsgBuffer, nMsgLen, &st_ProtocolHdr, &ptszMsgBuffer, &nPLen);
MessageQueue_TCP_Handle(&st_ProtocolHdr, lpszClientAddr, ptszMsgBuffer, nPLen, XENGINE_MQAPP_NETTYPE_HTTP);
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
}
else
{
......
......@@ -2,7 +2,7 @@
//////////////////////////////////////////////////////////////////////////
BOOL __stdcall MessageQueue_Callback_TCPLogin(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam)
{
SessionModule_Client_Create(lpszClientAddr);
SessionModule_Client_Create(lpszClientAddr, XENGINE_MQAPP_NETTYPE_TCP);
SocketOpt_HeartBeat_InsertAddrEx(xhTCPHeart, lpszClientAddr);
HelpComponents_Datas_CreateEx(xhTCPPacket, lpszClientAddr, 0);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO,_T("TCP客户端连接,TCP客户端地址:%s"),lpszClientAddr);
......@@ -28,6 +28,7 @@ void __stdcall MessageQueue_Callback_TCPHeart(LPCSTR lpszClientAddr, SOCKET hSoc
//////////////////////////////////////////////////////////////////////////
BOOL __stdcall MessageQueue_Callback_HttpLogin(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam)
{
SessionModule_Client_Create(lpszClientAddr, XENGINE_MQAPP_NETTYPE_HTTP);
RfcComponents_HttpServer_CreateClientEx(xhHTTPPacket, lpszClientAddr, 0);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("HTTP客户端连接,HTTP客户端地址:%s"), lpszClientAddr);
return TRUE;
......@@ -47,19 +48,19 @@ void __stdcall MessageQueue_Callback_HttpLeave(LPCTSTR lpszClientAddr, SOCKET hS
//////////////////////////////////////////////////////////////////////////
BOOL __stdcall MessageQueue_Callback_WSLogin(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam)
{
SessionModule_Client_Create(lpszClientAddr);
SessionModule_Client_Create(lpszClientAddr, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
SocketOpt_HeartBeat_InsertAddrEx(xhWSHeart, lpszClientAddr);
RfcComponents_WSPacket_Create(lpszClientAddr, 0);
RfcComponents_WSPacket_CreateEx(xhWSPacket, lpszClientAddr, 0);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Websocket客户端连接,Websocket客户端地址:%s"), lpszClientAddr);
return TRUE;
}
void __stdcall MessageQueue_Callback_WSRecv(LPCTSTR lpszClientAddr, SOCKET hSocket, LPCTSTR lpszRecvMsg, int nMsgLen, LPVOID lParam)
{
BOOL bLogin = FALSE;
RfcComponents_WSPacket_GetLogin(lpszClientAddr, &bLogin);
RfcComponents_WSPacket_GetLoginEx(xhWSPacket, lpszClientAddr, &bLogin);
if (bLogin)
{
if (!RfcComponents_WSPacket_Post(lpszClientAddr, lpszRecvMsg, nMsgLen))
if (!RfcComponents_WSPacket_PostEx(xhWSPacket, lpszClientAddr, lpszRecvMsg, nMsgLen))
{
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("投递Websocket数据包到消息队列失败,错误:%lX"), WSFrame_GetLastError());
return;
......@@ -73,7 +74,7 @@ void __stdcall MessageQueue_Callback_WSRecv(LPCTSTR lpszClientAddr, SOCKET hSock
memset(tszHandsBuffer, '\0', sizeof(tszHandsBuffer));
RfcComponents_WSConnector_HandShake(lpszRecvMsg, &nSDLen, tszHandsBuffer);
RfcComponents_WSPacket_SetLogin(lpszClientAddr);
RfcComponents_WSPacket_SetLoginEx(xhWSPacket, lpszClientAddr);
NetCore_TCPXCore_SendEx(xhWSSocket, lpszClientAddr, tszHandsBuffer, nSDLen);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("WEBSOCKET客户端:%s 与服务器握手成功"), lpszClientAddr);
}
......@@ -92,7 +93,6 @@ void XEngine_MQXService_Close(LPCTSTR lpszClientAddr, int nIPProto, BOOL bHeart)
if (XENGINE_MQAPP_NETTYPE_TCP == nIPProto)
{
HelpComponents_Datas_DeleteEx(xhTCPPacket, lpszClientAddr);
SessionModule_Client_Delete(lpszClientAddr);
if (bHeart)
{
......@@ -106,8 +106,7 @@ void XEngine_MQXService_Close(LPCTSTR lpszClientAddr, int nIPProto, BOOL bHeart)
}
else if (XENGINE_MQAPP_NETTYPE_WEBSOCKET == nIPProto)
{
RfcComponents_WSPacket_Delete(lpszClientAddr);
SessionModule_Client_Delete(lpszClientAddr);
RfcComponents_WSPacket_DeleteEx(xhWSPacket, lpszClientAddr);
if (bHeart)
{
......@@ -124,6 +123,7 @@ void XEngine_MQXService_Close(LPCTSTR lpszClientAddr, int nIPProto, BOOL bHeart)
RfcComponents_HttpServer_CloseClinetEx(xhHTTPPacket, lpszClientAddr);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("HTTP客户端离开,HTTP客户端地址:%s"), lpszClientAddr);
}
SessionModule_Client_Delete(lpszClientAddr);
}
//////////////////////////////////////////////////////////////////////////
BOOL XEngine_MQXService_Send(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen, int nIPProto)
......
#pragma once
XHTHREAD CALLBACK MessageQueue_TCPThread(LPVOID lParam);
BOOL MessageQueue_TCP_Handle(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen);
\ No newline at end of file
BOOL MessageQueue_TCP_Handle(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen, int nNetType);
\ No newline at end of file
......@@ -6,14 +6,14 @@ XHTHREAD CALLBACK MessageQueue_WebsocketThread(LPVOID lParam)
nThreadPos++;
while (bIsRun)
{
if (!RfcComponents_WSPacket_WaitEvent(nThreadPos))
if (!RfcComponents_WSPacket_WaitEventEx(xhWSPacket, nThreadPos))
{
continue;
}
int nListCount = 0;
RFCCOMPONENTS_WSPKT_CLIENT** ppSst_ListAddr;
RfcComponents_WSPacket_GetPool(nThreadPos, &ppSst_ListAddr, &nListCount);
RfcComponents_WSPacket_GetPoolEx(xhWSPacket, nThreadPos, &ppSst_ListAddr, &nListCount);
for (int i = 0; i < nListCount; i++)
{
for (int j = 0; j < ppSst_ListAddr[i]->nPktCount; j++)
......@@ -21,7 +21,7 @@ XHTHREAD CALLBACK MessageQueue_WebsocketThread(LPVOID lParam)
int nMsgLen = 0;
TCHAR* ptszMsgBuffer = NULL;
ENUM_XENGINE_RFCOMPONENTS_WEBSOCKET_OPCODE enOPCode;
if (!RfcComponents_WSPacket_GetMemory(ppSst_ListAddr[i]->tszClientAddr, &ptszMsgBuffer, &nMsgLen, &enOPCode))
if (!RfcComponents_WSPacket_GetMemoryEx(xhWSPacket, ppSst_ListAddr[i]->tszClientAddr, &ptszMsgBuffer, &nMsgLen, &enOPCode))
{
DWORD dwRet = WSFrame_GetLastError();
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Websocket服务器获取消息失败,获取数据包失败,错误:%lX"), dwRet);
......@@ -37,247 +37,16 @@ XHTHREAD CALLBACK MessageQueue_WebsocketThread(LPVOID lParam)
}
BOOL MessageQueue_Websocket_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen, ENUM_XENGINE_RFCOMPONENTS_WEBSOCKET_OPCODE enOPCode)
{
int nSDLen = 2048;
int nRVLen = 2048;
int nJSLen = 0;
int nMsgType = 0;
TCHAR tszSDBuffer[2048];
TCHAR tszRVBuffer[2048];
TCHAR* ptszMsgBuffer = NULL;
memset(tszSDBuffer, '\0', sizeof(tszSDBuffer));
memset(tszRVBuffer, '\0', sizeof(tszRVBuffer));
if (ENUM_XENGINE_RFCOMPONENTS_WEBSOCKET_OPCODE_TEXT == enOPCode)
{
int nPLen = 0;
TCHAR* ptszMsgBuffer = NULL;
XENGINE_PROTOCOLHDR st_ProtocolHdr;
XENGINE_PROTOCOL_XMQ st_MQProtocol;
XENGINE_PROTOCOL_XMQ st_MQClient;
memset(&st_ProtocolHdr, '\0', sizeof(XENGINE_PROTOCOLHDR));
memset(&st_MQProtocol, '\0', sizeof(XENGINE_PROTOCOL_XMQ));
memset(&st_MQClient, '\0', sizeof(XENGINE_PROTOCOL_XMQ));
SessionModule_Client_Get(lpszClientAddr, &st_MQClient);
ProtocolModule_Parse_Http(lpszMsgBuffer, nMsgLen, &st_MQProtocol, &st_ProtocolHdr, &ptszMsgBuffer, &nJSLen, &nMsgType);
if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQPOST == st_ProtocolHdr.unOperatorCode)
{
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REPPOST;
if (!XMQModule_Packet_Post(&st_MQProtocol, ptszMsgBuffer, nJSLen))
{
st_ProtocolHdr.wReserve = 701;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Websocket客户端:%s,主题:%s,序列:%lld,投递数据报失败,无法继续,错误:%lX"), lpszClientAddr, st_MQProtocol.tszMQKey, st_MQProtocol.nSerial, XMQModule_GetLastError());
return FALSE;
}
st_ProtocolHdr.wReserve = 0;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
int nListCount = 0;
SESSION_NOTIFYCLIENT** ppSt_ListAddr;
if (SessionModule_Notify_GetList(st_MQProtocol.tszMQKey, &ppSt_ListAddr, &nListCount))
{
int nTCPLen = 0;
int nWSLen = 0;
TCHAR tszTCPBuffer[4096];
TCHAR tszWSBuffer[4096];
memset(tszTCPBuffer, '\0', sizeof(tszTCPBuffer));
memset(tszWSBuffer, '\0', sizeof(tszWSBuffer));
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_MSGNOTIFY;
ProtocolModule_Packet_TCPCommon(&st_ProtocolHdr, &st_MQProtocol, tszTCPBuffer, &nTCPLen, ptszMsgBuffer, nJSLen);
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszWSBuffer, &nWSLen, ptszMsgBuffer, nJSLen);
for (int i = 0; i < nListCount; i++)
{
if (ENUM_MQCORE_SESSION_CLIENT_TYPE_TCP == ppSt_ListAddr[i]->enClientType)
{
XEngine_MQXService_Send(ppSt_ListAddr[i]->tszNotifyAddr, tszTCPBuffer, nTCPLen, XENGINE_MQAPP_NETTYPE_TCP);
}
else if (ENUM_MQCORE_SESSION_CLIENT_TYPE_WEBSOCKET == ppSt_ListAddr[i]->enClientType)
{
XEngine_MQXService_Send(ppSt_ListAddr[i]->tszNotifyAddr, tszWSBuffer, nWSLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
}
}
BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListAddr, nListCount);
}
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Websocket客户端:%s,主题:%s,序列:%lld,投递数据到消息队列成功,通知客户端个数:%d"), lpszClientAddr, st_MQProtocol.tszMQKey, st_MQProtocol.nSerial, nListCount);
}
else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQGET == st_ProtocolHdr.unOperatorCode)
{
TCHAR tszMsgBuffer[8196];
memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REPGET;
if ((st_MQProtocol.nSerial > 0) || (0 != _tcsnicmp(st_MQClient.tszMQKey, st_MQProtocol.tszMQKey, _tcslen(st_MQProtocol.tszMQKey))))
{
//如果序列号和主题有修改
if (0 == st_MQProtocol.nSerial)
{
st_MQProtocol.nSerial = 1; //不能以0为序列号
}
SessionModule_Client_Set(lpszClientAddr, &st_MQProtocol);
}
else
{
st_MQProtocol.nSerial = st_MQClient.nSerial;
}
if (!XMQModule_Packet_Get(&st_MQProtocol, tszMsgBuffer, &nRVLen))
{
st_ProtocolHdr.wReserve = 722;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Websocket客户端:%s,主题:%s,序列:%lld,获取消息数据失败,无法继续,错误:%lX"), lpszClientAddr, st_MQProtocol.tszMQKey, st_MQProtocol.nSerial, XMQModule_GetLastError());
return FALSE;
}
st_ProtocolHdr.wReserve = 0;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen, tszMsgBuffer, nRVLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
SessionModule_Client_ADDDelSerial(lpszClientAddr); //移动序列号
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Websocket客户端:%s,主题:%s,序列:%lld,获取消息数据成功,消息大小:%d"), lpszClientAddr, st_MQProtocol.tszMQKey, st_MQProtocol.nSerial, nRVLen);
}
else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQDEL == st_ProtocolHdr.unOperatorCode)
{
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REPDEL;
if (!XMQModule_Packet_Del(&st_MQProtocol))
{
st_ProtocolHdr.wReserve = 741;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Websocket客户端:%s,主题:%s,序列:%lld,删除消息队列中的数据失败,错误:%lX"), lpszClientAddr, st_MQProtocol.tszMQKey, st_MQProtocol.nSerial, XMQModule_GetLastError());
return FALSE;
}
st_ProtocolHdr.wReserve = 0;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Websocket客户端:%s,主题:%s,序列:%lld,删除消息队列中的数据成功"), lpszClientAddr, st_MQProtocol.tszMQKey, st_MQProtocol.nSerial);
}
else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQCREATE == st_ProtocolHdr.unOperatorCode)
{
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REPCREATE;
if (!XMQModule_Packet_TopicCreate(st_MQProtocol.tszMQKey))
{
st_ProtocolHdr.wReserve = 761;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
DWORD dwRet = XMQModule_GetLastError();
if (ERROR_MQ_MODULE_PACKET_CREATE_EXIST == dwRet)
{
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Websocket客户端:%s,创建主题名称:%s,已经存在.无法继续创建"), lpszClientAddr, st_MQProtocol.tszMQKey);
}
else
{
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Websocket客户端:%s,创建主题失败,主题名称:%s,无法继续,错误:%lX"), lpszClientAddr, st_MQProtocol.tszMQKey, XMQModule_GetLastError());
}
return FALSE;
}
st_ProtocolHdr.wReserve = 0;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
SessionModule_Notify_Create(st_MQProtocol.tszMQKey);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Websocket客户端:%s,主题:%s,创建主题成功"), lpszClientAddr, st_MQProtocol.tszMQKey);
}
else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQDELETE == st_ProtocolHdr.unOperatorCode)
{
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REPDELETE;
if (!XMQModule_Packet_TopicDelete(st_MQProtocol.tszMQKey))
{
st_ProtocolHdr.wReserve = 781;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Websocket客户端:%s,删除主题失败,主题名称:%s,无法继续,错误:%lX"), lpszClientAddr, st_MQProtocol.tszMQKey, XMQModule_GetLastError());
return FALSE;
}
st_ProtocolHdr.wReserve = 0;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
SessionModule_Notify_Destory(st_MQProtocol.tszMQKey);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Websocket客户端:%s,主题:%s,删除主题成功"), lpszClientAddr, st_MQProtocol.tszMQKey);
}
else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQNOTIFY == st_ProtocolHdr.unOperatorCode)
{
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REPNOTIFY;
if (0 == st_ProtocolHdr.wReserve)
{
SessionModule_Notify_Delete(st_MQProtocol.tszMQKey, lpszClientAddr, ENUM_MQCORE_SESSION_CLIENT_TYPE_WEBSOCKET);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Websocket客户端:%s,取消订阅成功,主题名称:%s"), lpszClientAddr, st_MQProtocol.tszMQKey);
}
else
{
if (!SessionModule_Notify_Insert(st_MQProtocol.tszMQKey, lpszClientAddr, ENUM_MQCORE_SESSION_CLIENT_TYPE_WEBSOCKET))
{
st_ProtocolHdr.wReserve = 710;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Websocket客户端:%s,订阅主题失败,主题名称:%s,错误:%lX"), lpszClientAddr, st_MQProtocol.tszMQKey, SessionModule_GetLastError());
return FALSE;
}
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Websocket客户端:%s,订阅主题成功,主题名称:%s"), lpszClientAddr, st_MQProtocol.tszMQKey);
}
st_ProtocolHdr.wReserve = 0;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
}
else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQSERIAL == st_ProtocolHdr.unOperatorCode)
{
st_ProtocolHdr.wReserve = 0;
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REPSERIAL;
if (0 == st_MQProtocol.nSerial)
{
__int64x nFirstNumber = 0;
__int64x nLastNumber = 0;
if (!XMQModule_Packet_GetSerial(st_MQProtocol.tszMQKey, &nFirstNumber, &nLastNumber))
{
st_ProtocolHdr.wReserve = 712;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Websocket消息端:%s,获取主题序列编号失败,主题名称:%s,错误:%lX"), lpszClientAddr, st_MQProtocol.tszMQKey, SessionModule_GetLastError());
return FALSE;
}
st_MQProtocol.nKeepTime == 1 ? st_MQProtocol.nSerial = nFirstNumber : st_MQProtocol.nSerial = nLastNumber;
}
if (!SessionModule_Client_SetOrder(lpszClientAddr, st_MQProtocol.tszMQKey, st_MQProtocol.nKeepTime, st_MQProtocol.nSerial))
{
st_ProtocolHdr.wReserve = 712;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Websocket消息端:%s,设置消息队列读取模式失败,主题名称:%s,读取模式:%s,序列号:%lld,错误:%lX"), lpszClientAddr, st_MQProtocol.tszMQKey, st_MQProtocol.nKeepTime == 1 ? "顺序" : "倒序", st_MQProtocol.nSerial, SessionModule_GetLastError());
return FALSE;
}
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Websocket消息端:%s,请求设置序列号成功,主题名称:%s,读取模式:%s,序列号:%lld"), lpszClientAddr, st_MQProtocol.tszMQKey, st_MQProtocol.nKeepTime == 1 ? "顺序" : "倒序", st_MQProtocol.nSerial);
}
else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQNUMBER == st_ProtocolHdr.unOperatorCode)
{
XENGINE_MQNUMBER st_MQNumber;
memset(&st_MQNumber, '\0', sizeof(XENGINE_MQNUMBER));
st_ProtocolHdr.wReserve = 0;
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REPNUMBER;
_tcscpy(st_MQNumber.tszMQKey, st_MQProtocol.tszMQKey);
if (!XMQModule_Packet_GetSerial(st_MQNumber.tszMQKey, &st_MQNumber.nFirstNumber, &st_MQNumber.nLastNumber))
{
st_ProtocolHdr.wReserve = 714;
ProtocolModule_Packet_HttpCommon(&st_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Websocket消息端:%s,获取主题序列编号失败,主题名称:%s,错误:%lX"), lpszClientAddr, st_MQProtocol.tszMQKey, SessionModule_GetLastError());
return FALSE;
}
XMQModule_Packet_GetCount(st_MQNumber.tszMQKey, &st_MQNumber.nCount);
ProtocolModule_Packet_MQNumber(&st_ProtocolHdr, &st_MQNumber, tszSDBuffer, &nSDLen);
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Websocket消息端:%s,获取主题序列编号成功,主题名称:%s,队列个数:%lld,开始编号:%lld,结尾编号:%lld"), lpszClientAddr, st_MQNumber.tszMQKey, st_MQNumber.nCount, st_MQNumber.nFirstNumber, st_MQNumber.nLastNumber);
}
else
{
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("Websocket客户端:%s,子协议错误,子协议:%x"), lpszClientAddr, st_ProtocolHdr.unOperatorCode);
}
ProtocolModule_Parse_Http(lpszMsgBuffer, nMsgLen, &st_ProtocolHdr, &ptszMsgBuffer, &nPLen);
MessageQueue_TCP_Handle(&st_ProtocolHdr, lpszClientAddr, ptszMsgBuffer, nPLen, XENGINE_MQAPP_NETTYPE_WEBSOCKET);
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
}
else
{
......
CC = g++ -Wall
RELEASE = 0
UNICODE = 0
LOADBIN = -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_Core -L /usr/local/lib/XEngine_Release/XEngine_SystemSdk -L /usr/local/lib/XEngine_Release/XEngine_HelpComponents -L /usr/local/lib/XEngine_Release/XEngine_RfcComponents -L ../MQCore_ConfigModule -L ../MQCore_XMQModule -L ../MQCore_DDSMessage -L ../MQCore_ProtocolModule -L ../MQCore_SessionModule
LIB = -lXEngine_BaseLib -lXEngine_Algorithm -lXEngine_Core -lXEngine_ManagePool -lXEngine_SystemApi -lHelpComponents_XLog -lHelpComponents_Packets -lRfcComponents_WSProtocol -lRfcComponents_HttpServer -lMQCore_XMQModule -lMQCore_DDSMessage -lMQCore_ConfigModule -lMQCore_ProtocolModule -lMQCore_SessionModule
LOADBIN = -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_Core -L /usr/local/lib/XEngine_Release/XEngine_SystemSdk -L /usr/local/lib/XEngine_Release/XEngine_HelpComponents -L /usr/local/lib/XEngine_Release/XEngine_RfcComponents -L /usr/local/lib/XEngine_Release/XEngine_NetHelp -L ../MQCore_ConfigModule -L ../MQCore_XMQModule -L ../MQCore_DDSMessage -L ../MQCore_ProtocolModule -L ../MQCore_SessionModule
LIB = -lXEngine_BaseLib -lXEngine_Algorithm -lXEngine_Core -lXEngine_ManagePool -lXEngine_SystemApi -lHelpComponents_XLog -lHelpComponents_Packets -lRfcComponents_WSProtocol -lRfcComponents_HttpServer -lNetHelp_APIHelp -lMQCore_XMQModule -lMQCore_DDSMessage -lMQCore_ConfigModule -lMQCore_ProtocolModule -lMQCore_SessionModule
LIBEX = -static-libgcc -ldl -lrt -lpthread
LOADSO = -Wl,-rpath=./,--disable-new-dtags
LIBINCLUDE = MQService_Net.o MQService_Config.o MQService_TCPTask.o MQService_HttpTask.o MQService_WSTask.o MQService_DDSTask.o XEngine_MQServiceApp.o
......
......@@ -9,8 +9,9 @@ XNETHANDLE xhWSSocket = 0;
XNETHANDLE xhTCPHeart = 0;
XNETHANDLE xhWSHeart = 0;
XNETHANDLE xhTCPPacket = 0;
XHANDLE xhHTTPPacket = 0;
XHANDLE xhTCPPacket = NULL;
XHANDLE xhHTTPPacket = NULL;
XHANDLE xhWSPacket = NULL;
XNETHANDLE xhTCPPool = 0;
XNETHANDLE xhHttpPool = 0;
......@@ -39,7 +40,7 @@ void ServiceApp_Stop(int signo)
HelpComponents_Datas_Destory(xhTCPPacket);
RfcComponents_HttpServer_DestroyEx(xhHTTPPacket);
RfcComponents_WSPacket_Destory();
RfcComponents_WSPacket_DestoryEx(xhWSPacket);
NetCore_TCPXCore_DestroyEx(xhTCPSocket);
NetCore_TCPXCore_DestroyEx(xhHTTPSocket);
NetCore_TCPXCore_DestroyEx(xhWSSocket);
......@@ -49,6 +50,7 @@ void ServiceApp_Stop(int signo)
ManagePool_Thread_NQDestroy(xhHttpPool);
ManagePool_Thread_NQDestroy(xhWSPool);
XMQModule_Packet_Destory();
SessionModule_Auth_Destory();
SessionModule_Client_Destory();
HelpComponents_XLog_Destroy(xhLog);
}
......@@ -58,6 +60,37 @@ void ServiceApp_Stop(int signo)
exit(0);
}
static int ServiceApp_Deamon(int wait)
{
#ifndef _WINDOWS
pid_t pid = 0;
int status;
pid = fork();
if (pid > 0)
{
exit(0);
}
close(2);
while (1)
{
pid = fork();
if (pid < 0)
exit(1);
if (pid == 0)
{
return 0;
}
waitpid(pid, &status, 0);
if (wait > 0)
sleep(wait);
}
#endif
return 0;
}
int main(int argc, char** argv)
{
#ifdef _WINDOWS
......@@ -103,6 +136,7 @@ int main(int argc, char** argv)
if (st_ServiceCfg.bDeamon)
{
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("初始化守护进程..."));
ServiceApp_Deamon(1);
}
if (!SessionModule_Client_Init())
......@@ -119,10 +153,29 @@ int main(int argc, char** argv)
}
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,初始化消息队列服务成功"));
if (0 == st_ServiceCfg.st_XAuth.nAuth)
{
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中,用户验证没有启用"));
}
else if (1 == st_ServiceCfg.st_XAuth.nAuth)
{
if (!SessionModule_Auth_Init(st_ServiceCfg.st_XAuth.tszAuthUser))
{
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中,本地用户验证启动失败,错误:%lX"), SessionModule_GetLastError());
goto NETSERVICEEXIT;
}
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,本地验证启动成功,用户列表地址:%s"), st_ServiceCfg.st_XAuth.tszAuthUser);
}
else
{
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,网络验证启动成功,HTTP网络地址:%s"), st_ServiceCfg.st_XAuth.tszAuthHttp);
}
if (st_ServiceCfg.nTCPPort > 0)
{
//组包器
if (!HelpComponents_Datas_Init(&xhTCPPacket, st_ServiceCfg.st_XMax.nMaxQueue, 0, st_ServiceCfg.st_XMax.nTCPThread))
xhTCPPacket = HelpComponents_Datas_Init(st_ServiceCfg.st_XMax.nMaxQueue, 0, st_ServiceCfg.st_XMax.nTCPThread);
if (NULL == xhTCPPacket)
{
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("初始化TCP组包器失败,错误:%lX"), Packets_GetLastError());
goto NETSERVICEEXIT;
......@@ -215,7 +268,8 @@ int main(int argc, char** argv)
if (st_ServiceCfg.nWSPort > 0)
{
if (!RfcComponents_WSPacket_Init(st_ServiceCfg.st_XMax.nMaxClient, 0, st_ServiceCfg.st_XMax.nWSThread))
xhWSPacket = RfcComponents_WSPacket_InitEx(st_ServiceCfg.st_XMax.nMaxClient, 0, st_ServiceCfg.st_XMax.nWSThread);
if (NULL == xhWSPacket)
{
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务器中,初始化Websocket组包失败,错误:%lX"), WSFrame_GetLastError());
goto NETSERVICEEXIT;
......@@ -268,26 +322,27 @@ int main(int argc, char** argv)
if (st_ServiceCfg.nBroadRVPort > 0)
{
//初始化广播接受者
if (!NetCore_BroadCast_RecvInit(&hRVSocket, st_ServiceCfg.nBroadRVPort))
{
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中.启动广播接受服务器失败,错误:%lX"), NetCore_GetLastError());
goto NETSERVICEEXIT;
}
//初始化广播发送服务
if (!NetCore_BroadCast_SendInit(&hSDSocket, st_ServiceCfg.nBroadSDPort, st_ServiceCfg.tszIPAddr))
if (NetCore_BroadCast_SendInit(&hSDSocket, st_ServiceCfg.nBroadSDPort, st_ServiceCfg.tszIPAddr))
{
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中.启动广播发送服务器失败,错误:%lX"), NetCore_GetLastError());
goto NETSERVICEEXIT;
//初始化广播接受者
if (!NetCore_BroadCast_RecvInit(&hRVSocket, st_ServiceCfg.nBroadRVPort))
{
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中.启动广播接受服务器失败,错误:%lX"), NetCore_GetLastError());
goto NETSERVICEEXIT;
}
pSTDThread = make_shared<std::thread>(MessageQueue_DDSMessage_ThreadDomain);
if (NULL == pSTDThread)
{
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中.启动消息分发线程处理程序失败"));
goto NETSERVICEEXIT;
}
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,启动数据分发服务成功,接受端口:%d,发送端口:%d"), st_ServiceCfg.nBroadRVPort, st_ServiceCfg.nBroadSDPort);
}
pSTDThread = make_shared<std::thread>(MessageQueue_DDSMessage_ThreadDomain);
if (NULL == pSTDThread)
else
{
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中.启动消息分发线程处理程序失败"));
goto NETSERVICEEXIT;
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中.启动广播发送服务器失败,可能配置文件本地IP地址:%s 不正确,已经关闭,错误:%lX"), st_ServiceCfg.tszIPAddr, NetCore_GetLastError());
}
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,启动数据分发服务成功,接受端口:%d,发送端口:%d"), st_ServiceCfg.nBroadRVPort, st_ServiceCfg.nBroadSDPort);
}
else
{
......@@ -315,7 +370,7 @@ NETSERVICEEXIT:
HelpComponents_Datas_Destory(xhTCPPacket);
RfcComponents_HttpServer_DestroyEx(xhHTTPPacket);
RfcComponents_WSPacket_Destory();
RfcComponents_WSPacket_DestoryEx(xhWSPacket);
NetCore_TCPXCore_DestroyEx(xhTCPSocket);
NetCore_TCPXCore_DestroyEx(xhHTTPSocket);
NetCore_TCPXCore_DestroyEx(xhWSSocket);
......@@ -325,6 +380,7 @@ NETSERVICEEXIT:
ManagePool_Thread_NQDestroy(xhHttpPool);
ManagePool_Thread_NQDestroy(xhWSPool);
XMQModule_Packet_Destory();
SessionModule_Auth_Destory();
SessionModule_Client_Destory();
HelpComponents_XLog_Destroy(xhLog);
}
......
......@@ -10,6 +10,9 @@
// Purpose: 消息队列协议
// History:
*********************************************************************/
#define XENGINE_MQAPP_NETTYPE_TCP 1
#define XENGINE_MQAPP_NETTYPE_HTTP 2
#define XENGINE_MQAPP_NETTYPE_WEBSOCKET 3
///////////////////////////////////////////////////////////////////////////
// 导出的数据定义
///////////////////////////////////////////////////////////////////////////
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册