diff options
-rw-r--r-- | include/m_netlib.h | 3 | ||||
-rw-r--r-- | libs/win32/mir_app.lib | bin | 220498 -> 220758 bytes | |||
-rw-r--r-- | libs/win64/mir_app.lib | bin | 216334 -> 216580 bytes | |||
-rw-r--r-- | protocols/Discord/src/gateway.cpp | 2 | ||||
-rw-r--r-- | src/mir_app/src/mir_app.def | 3 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 3 | ||||
-rw-r--r-- | src/mir_app/src/netlib_websocket.cpp | 57 |
7 files changed, 42 insertions, 26 deletions
diff --git a/include/m_netlib.h b/include/m_netlib.h index c11d0838db..7cc1524cb4 100644 --- a/include/m_netlib.h +++ b/include/m_netlib.h @@ -800,7 +800,8 @@ EXTERN_C MIR_APP_DLL(NETLIBHTTPREQUEST*) WebSocket_Connect(HNETLIBUSER, const ch EXTERN_C MIR_APP_DLL(bool) WebSocket_InitHeader(WSHeader &hdr, const void *pData, size_t bufSize);
// sends a packet to WebSocket
-EXTERN_C MIR_APP_DLL(void) WebSocket_Send(HNETLIBCONN nlc, const void *pData, size_t strLen);
+EXTERN_C MIR_APP_DLL(void) WebSocket_SendText(HNETLIBCONN nlc, const char *pData);
+EXTERN_C MIR_APP_DLL(void) WebSocket_SendBinary(HNETLIBCONN nlc, const void *pData, size_t strLen);
/////////////////////////////////////////////////////////////////////////////////////////
// Netlib hooks (0.8+)
diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib Binary files differindex 05fbbdb7dd..8b97a73f1e 100644 --- a/libs/win32/mir_app.lib +++ b/libs/win32/mir_app.lib diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib Binary files differindex 84938a21af..2a9408c8e0 100644 --- a/libs/win64/mir_app.lib +++ b/libs/win64/mir_app.lib diff --git a/protocols/Discord/src/gateway.cpp b/protocols/Discord/src/gateway.cpp index a8a0ca4efa..937cc11d89 100644 --- a/protocols/Discord/src/gateway.cpp +++ b/protocols/Discord/src/gateway.cpp @@ -27,7 +27,7 @@ bool CDiscordProto::GatewaySend(const JSONNode &pRoot) json_string szText = pRoot.write(); debugLogA("Gateway send: %s", szText.c_str()); - WebSocket_Send(m_hGatewayConnection, szText.c_str(), szText.length()); + WebSocket_SendText(m_hGatewayConnection, szText.c_str()); return true; } diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index a73b840389..053f1e6d95 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -717,7 +717,6 @@ UnregisterHppLogger @786 _RegisterSrmmLog@12 @805 NONAME
_UnregisterSrmmLog@4 @806 NONAME
?GetType@CRtfLogWindow@@UAEHXZ @807 NONAME
-_WebSocket_Send@12 @808 NONAME
_WebSocket_InitHeader@12 @809 NONAME
_WebSocket_Connect@12 @810 NONAME
?log@CSrmmBaseDialog@@QBEPAVCSrmmLogWindow@@XZ @811 NONAME
@@ -778,3 +777,5 @@ _Netlib_GetTlsUnique@8 @831 NONAME ?IsPluginOnWhiteList@@YG_NPBD@Z @866 NONAME
?SetPluginOnWhiteList@@YGXPBD_N@Z @867 NONAME
Chat_Mute @868
+_WebSocket_SendBinary@12 @869 NONAME
+_WebSocket_SendText@8 @870 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index eac93a9a4c..c33b8ede03 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -717,7 +717,6 @@ UnregisterHppLogger @786 RegisterSrmmLog @805 NONAME
UnregisterSrmmLog @806 NONAME
?GetType@CRtfLogWindow@@UEAAHXZ @807 NONAME
-WebSocket_Send @808 NONAME
WebSocket_InitHeader @809 NONAME
WebSocket_Connect @810 NONAME
?log@CSrmmBaseDialog@@QEBAPEAVCSrmmLogWindow@@XZ @811 NONAME
@@ -778,3 +777,5 @@ Netlib_GetTlsUnique @831 NONAME ?IsPluginOnWhiteList@@YA_NPEBD@Z @866 NONAME
?SetPluginOnWhiteList@@YAXPEBD_N@Z @867 NONAME
Chat_Mute @868
+WebSocket_SendBinary @869 NONAME
+WebSocket_SendText @870 NONAME
diff --git a/src/mir_app/src/netlib_websocket.cpp b/src/mir_app/src/netlib_websocket.cpp index ab75ee4970..dc516a2b5c 100644 --- a/src/mir_app/src/netlib_websocket.cpp +++ b/src/mir_app/src/netlib_websocket.cpp @@ -110,33 +110,34 @@ MIR_APP_DLL(bool) WebSocket_InitHeader(WSHeader &hdr, const void *pData, size_t return true; } -MIR_APP_DLL(void) WebSocket_Send(HNETLIBCONN nlc, const void *pData, size_t strLen) +///////////////////////////////////////////////////////////////////////////////////////// + +static void WebSocket_Send(HNETLIBCONN nlc, const void *pData, size_t dataLen, BYTE opCode) { BYTE header[20]; - int opCode = 1; size_t datalen; header[0] = 0x80 + (opCode & 0x7F); - if (strLen < 126) { - header[1] = (strLen & 0xFF); + if (dataLen < 126) { + header[1] = (dataLen & 0xFF); datalen = 2; } - else if (strLen < 65536) { + else if (dataLen < 65536) { header[1] = 0x7E; - header[2] = (strLen >> 8) & 0xFF; - header[3] = strLen & 0xFF; + header[2] = (dataLen >> 8) & 0xFF; + header[3] = dataLen & 0xFF; datalen = 4; } else { header[1] = 0x7F; - header[2] = (strLen >> 56) & 0xff; - header[3] = (strLen >> 48) & 0xff; - header[4] = (strLen >> 40) & 0xff; - header[5] = (strLen >> 32) & 0xff; - header[6] = (strLen >> 24) & 0xff; - header[7] = (strLen >> 16) & 0xff; - header[8] = (strLen >> 8) & 0xff; - header[9] = strLen & 0xff; + header[2] = (dataLen >> 56) & 0xff; + header[3] = (dataLen >> 48) & 0xff; + header[4] = (dataLen >> 40) & 0xff; + header[5] = (dataLen >> 32) & 0xff; + header[6] = (dataLen >> 24) & 0xff; + header[7] = (dataLen >> 16) & 0xff; + header[8] = (dataLen >> 8) & 0xff; + header[9] = dataLen & 0xff; datalen = 10; } @@ -144,18 +145,30 @@ MIR_APP_DLL(void) WebSocket_Send(HNETLIBCONN nlc, const void *pData, size_t strL uint32_t dwMask; uint8_t arMask[4]; }; - - dwMask = crc32(rand(), (uint8_t*)pData, (unsigned)strLen); + + dwMask = crc32(rand(), (uint8_t*)pData, (unsigned)dataLen); memcpy(header + datalen, arMask, _countof(arMask)); datalen += _countof(arMask); header[1] |= 0x80; - ptrA sendBuf((char*)mir_alloc(strLen + datalen)); + ptrA sendBuf((char*)mir_alloc(dataLen + datalen)); memcpy(sendBuf, header, datalen); - if (strLen) { - memcpy(sendBuf.get() + datalen, pData, strLen); - for (size_t i = 0; i < strLen; i++) + if (dataLen) { + memcpy(sendBuf.get() + datalen, pData, dataLen); + for (size_t i = 0; i < dataLen; i++) sendBuf[i + datalen] ^= arMask[i & 3]; } - Netlib_Send(nlc, sendBuf, int(strLen + datalen), MSG_NODUMP); + Netlib_Send(nlc, sendBuf, int(dataLen + datalen), MSG_NODUMP); +} + +MIR_APP_DLL(void) WebSocket_SendText(HNETLIBCONN nlc, const char *pData) +{ + if (nlc && pData) + WebSocket_Send(nlc, pData, strlen(pData), 1); +} + +MIR_APP_DLL(void) WebSocket_SendBinary(HNETLIBCONN nlc, const void *pData, size_t dataLen) +{ + if (nlc && pData) + WebSocket_Send(nlc, pData, dataLen, 2); } |