summaryrefslogtreecommitdiff
path: root/src/mir_app
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2021-04-24 11:07:00 +0300
committerGeorge Hazan <ghazan@miranda.im>2021-04-24 11:07:00 +0300
commit7c9e299626e8ce572d69c9af176df49a819b6cbb (patch)
treecdc059c34cc3b21925ed37190d61c7f66858bc0c /src/mir_app
parent8318809aa0961802fd12438330051d3ba91eb6c4 (diff)
WebSocket: different stubs for sending text & binary packets
Diffstat (limited to 'src/mir_app')
-rw-r--r--src/mir_app/src/mir_app.def3
-rw-r--r--src/mir_app/src/mir_app64.def3
-rw-r--r--src/mir_app/src/netlib_websocket.cpp57
3 files changed, 39 insertions, 24 deletions
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);
}