diff options
Diffstat (limited to 'protocols/JabberG')
-rw-r--r-- | protocols/JabberG/jabber.vcxproj | 1 | ||||
-rw-r--r-- | protocols/JabberG/jabber.vcxproj.filters | 3 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_byte.cpp | 16 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_file.cpp | 7 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_proto.cpp | 8 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_proto.h | 13 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_thread.cpp | 48 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_ws.cpp | 72 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_zstream.cpp | 8 | ||||
-rw-r--r-- | protocols/JabberG/src/stdafx.h | 4 |
10 files changed, 48 insertions, 132 deletions
diff --git a/protocols/JabberG/jabber.vcxproj b/protocols/JabberG/jabber.vcxproj index 7dc563d45a..632ea83ce6 100644 --- a/protocols/JabberG/jabber.vcxproj +++ b/protocols/JabberG/jabber.vcxproj @@ -76,7 +76,6 @@ <ClCompile Include="src\jabber_userinfo.cpp" />
<ClCompile Include="src\jabber_util.cpp" />
<ClCompile Include="src\jabber_vcard.cpp" />
- <ClCompile Include="src\jabber_ws.cpp" />
<ClCompile Include="src\jabber_xml.cpp" />
<ClCompile Include="src\jabber_xstatus.cpp" />
<ClCompile Include="src\jabber_zstream.cpp" />
diff --git a/protocols/JabberG/jabber.vcxproj.filters b/protocols/JabberG/jabber.vcxproj.filters index b7205778b0..8f8f5a9e4e 100644 --- a/protocols/JabberG/jabber.vcxproj.filters +++ b/protocols/JabberG/jabber.vcxproj.filters @@ -149,9 +149,6 @@ <ClCompile Include="src\jabber_vcard.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\jabber_ws.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="src\jabber_xml.cpp">
<Filter>Source Files</Filter>
</ClCompile>
diff --git a/protocols/JabberG/src/jabber_byte.cpp b/protocols/JabberG/src/jabber_byte.cpp index 48c3c02463..685174347d 100644 --- a/protocols/JabberG/src/jabber_byte.cpp +++ b/protocols/JabberG/src/jabber_byte.cpp @@ -438,15 +438,9 @@ void CJabberProto::ByteSendViaProxy(JABBER_BYTE_TRANSFER *jbt) char *szPort = jbt->szProxyPort;
char *szHost = jbt->szProxyHost;
- uint16_t port = (uint16_t)atoi(szPort);
replaceStr(jbt->streamhostJID, jbt->szProxyJid);
- NETLIBOPENCONNECTION nloc = {};
- nloc.szHost = szHost;
- nloc.wPort = port;
-
- HNETLIBCONN hConn = Netlib_OpenConnection(m_hNetlibUser, &nloc);
- mir_free((void*)nloc.szHost);
+ HNETLIBCONN hConn = Netlib_OpenConnection(m_hNetlibUser, szHost, atoi(szPort));
if (hConn != nullptr) {
jbt->hConn = hConn;
@@ -610,13 +604,7 @@ void __cdecl CJabberProto::ByteReceiveThread(JABBER_BYTE_TRANSFER *jbt) replaceStr(jbt->streamhostJID, str);
debugLogA("bytestream_recv connecting to %s:%d", szHost, port);
- NETLIBOPENCONNECTION nloc = { 0 };
- nloc.szHost = mir_strdup(szHost);
- nloc.wPort = port;
-
- HNETLIBCONN hConn = Netlib_OpenConnection(m_hNetlibUser, &nloc);
- mir_free((void*)nloc.szHost);
-
+ HNETLIBCONN hConn = Netlib_OpenConnection(m_hNetlibUser, szHost, port);
if (hConn == nullptr) {
debugLogA("bytestream_recv_connection connection failed (%d), try next streamhost", WSAGetLastError());
continue;
diff --git a/protocols/JabberG/src/jabber_file.cpp b/protocols/JabberG/src/jabber_file.cpp index f7d0cd0aac..b01b32f32a 100644 --- a/protocols/JabberG/src/jabber_file.cpp +++ b/protocols/JabberG/src/jabber_file.cpp @@ -36,10 +36,7 @@ void __cdecl CJabberProto::FileReceiveThread(filetransfer *ft) ft->type = FT_OOB;
- NETLIBOPENCONNECTION nloc = {};
- nloc.szHost = ft->httpHostName;
- nloc.wPort = ft->httpPort;
- info.s = Netlib_OpenConnection(m_hNetlibUser, &nloc);
+ info.s = Netlib_OpenConnection(m_hNetlibUser, ft->httpHostName, ft->httpPort);
if (info.s == nullptr) {
debugLogA("Connection failed (%d), thread ended", WSAGetLastError());
ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft);
@@ -401,7 +398,7 @@ int CJabberProto::FileSendParse(HNETLIBCONN s, filetransfer *ft, char* buffer, i char fileBuffer[2048];
int bytes = mir_snprintf(fileBuffer, "HTTP/1.1 200 OK\r\nContent-Length: %d\r\n\r\n", _filelength(fileId));
- WsSend(s, fileBuffer, bytes, MSG_DUMPASTEXT);
+ Netlib_Send(s, fileBuffer, bytes, MSG_DUMPASTEXT);
ft->std.flags |= PFTS_SENDING;
ft->std.currentFileProgress = 0;
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index c2dc2d50e5..fb6fee3ce1 100644 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -204,7 +204,6 @@ CJabberProto::CJabberProto(const char *aProtoName, const wchar_t *aUserName) : IconsInit();
InitPopups();
GlobalMenuInit();
- WsInit();
m_pepServices.insert(new CPepMood(this));
m_pepServices.insert(new CPepActivity(this));
@@ -214,6 +213,13 @@ CJabberProto::CJabberProto(const char *aProtoName, const wchar_t *aUserName) : OmemoInitDevice();
}
+ // network initialization
+ NETLIBUSER nlu = {};
+ nlu.flags = NUF_OUTGOING | NUF_INCOMING | NUF_HTTPCONNS | NUF_UNICODE;
+ nlu.szDescriptiveName.w = m_tszUserName;
+ nlu.szSettingsModule = m_szModuleName;
+ m_hNetlibUser = Netlib_RegisterUser(&nlu);
+
// group chats
GCREGISTER gcr = {};
gcr.dwFlags = GC_TYPNOTIF | GC_CHANMGR;
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index 823f17feff..9d87dbc775 100644 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -76,6 +76,8 @@ struct CChatMark struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
{
+ friend struct ThreadData;
+
class CJabberProtoImpl
{
friend struct CJabberProto;
@@ -240,6 +242,7 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface CMOption<uint32_t> m_iConnectionKeepAliveTimeout;
PVOID m_sslCtx;
+ mir_cs m_csSocket; // protects i/o operations
HANDLE m_hThreadHandle;
@@ -883,14 +886,6 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface void SetServerVcard(BOOL bPhotoChanged, wchar_t* szPhotoFileName);
void SaveVcardToDB(HWND hwndPage, int iPage);
- //---- jabber_ws.c -------------------------------------------------
-
- HNETLIBCONN WsConnect(char* host, uint16_t port);
-
- bool WsInit(void);
- int WsSend(HNETLIBCONN s, char* data, int datalen, int flags);
- int WsRecv(HNETLIBCONN s, char* data, long datalen, int flags);
-
//---- jabber_xml.c ------------------------------------------------------------------
void OnConsoleProcessXml(const TiXmlElement *node, uint32_t flags);
@@ -929,8 +924,6 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface private:
char *m_szXmlStreamToBeInitialized;
- uint32_t m_lastTicks;
-
HANDLE m_hPopupClass;
LONG m_nSerial;
diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index dcd5e5d6b7..0dbf3a1ba9 100644 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -141,16 +141,15 @@ void CJabberProto::JLoginFailed(int errorCode) void CJabberProto::CheckKeepAlive()
{
- if (GetTickCount() - m_lastTicks < m_iConnectionKeepAliveInterval)
- return;
-
- if (m_bKeepAlive && m_ThreadInfo) {
- if (m_ThreadInfo->jabberServerCaps & JABBER_CAPS_PING) {
- CJabberIqInfo *pInfo = AddIQ(&CJabberProto::OnPingReply, JABBER_IQ_TYPE_GET, nullptr, this);
- pInfo->SetTimeout(m_iConnectionKeepAliveTimeout);
- m_ThreadInfo->send(XmlNodeIq(pInfo) << XATTR("from", m_ThreadInfo->fullJID) << XCHILDNS("ping", JABBER_FEAT_PING));
+ if (m_ThreadInfo) {
+ if (m_bKeepAlive && ::GetTickCount() - m_ThreadInfo->lastWriteTime < m_iConnectionKeepAliveInterval) {
+ if (m_ThreadInfo->jabberServerCaps & JABBER_CAPS_PING) {
+ CJabberIqInfo *pInfo = AddIQ(&CJabberProto::OnPingReply, JABBER_IQ_TYPE_GET, nullptr, this);
+ pInfo->SetTimeout(m_iConnectionKeepAliveTimeout);
+ m_ThreadInfo->send(XmlNodeIq(pInfo) << XATTR("from", m_ThreadInfo->fullJID) << XCHILDNS("ping", JABBER_FEAT_PING));
+ }
+ else m_ThreadInfo->send(" \t ");
}
- else m_ThreadInfo->send(" \t ");
}
if (m_bEnableStreamMgmt)
@@ -192,7 +191,7 @@ void ThreadData::xmpp_client_query(void) char* dnsHost = it->pNameTarget;
proto->debugLogA("%s%s resolved to %s:%d", "_xmpp-client._tcp.", conn.server, dnsHost, dnsPort);
- s = proto->WsConnect(dnsHost, dnsPort);
+ s = Netlib_OpenConnection(proto->m_hNetlibUser, dnsHost, dnsPort);
if (s) {
strncpy_s(conn.manualHost, dnsHost, _TRUNCATE);
conn.port = dnsPort;
@@ -375,10 +374,10 @@ LBL_FatalError: info.xmpp_client_query();
if (info.s == nullptr) {
strncpy_s(info.conn.manualHost, info.conn.server, _TRUNCATE);
- info.s = WsConnect(info.conn.manualHost, info.conn.port);
+ info.s = Netlib_OpenConnection(m_hNetlibUser, info.conn.manualHost, info.conn.port);
}
}
- else info.s = WsConnect(info.conn.manualHost, info.conn.port);
+ else info.s = Netlib_OpenConnection(m_hNetlibUser, info.conn.manualHost, info.conn.port);
debugLogA("Thread type=%d server='%s' port='%d'", info.bIsReg, info.conn.manualHost, info.conn.port);
if (info.s == nullptr) {
@@ -424,7 +423,7 @@ LBL_FatalError: debugLogA("Entering main recv loop");
int datalen = 0;
- // cache values
+ // main socket reading cycle
for (;;) {
int recvResult = info.recv(info.buffer + datalen, jabberNetworkBufferSize - datalen);
debugLogA("recvResult = %d", recvResult);
@@ -1958,7 +1957,7 @@ ThreadData::ThreadData(CJabberProto *_pro, JABBER_CONN_DATA *param) resolveID = -1;
proto = _pro;
- iomutex = CreateMutex(nullptr, FALSE, nullptr);
+ lastWriteTime = ::GetTickCount();
if (param != nullptr) {
bIsReg = true;
@@ -1974,8 +1973,6 @@ ThreadData::~ThreadData() mir_free(gssapiHostName);
mir_free(zRecvData);
mir_free(buffer);
-
- CloseHandle(iomutex);
}
void ThreadData::close(void)
@@ -1997,10 +1994,20 @@ int ThreadData::recv(char* buf, size_t len) if (this == nullptr)
return 0;
+ // this select() is still required because shitty openssl is not thread safe
+ if (zRecvReady) {
+ NETLIBSELECT nls = {};
+ nls.dwTimeout = INFINITE;
+ nls.hReadConns[0] = s;
+ int nSelRes = Netlib_Select(&nls);
+ if (nSelRes == SOCKET_ERROR) // error
+ return SOCKET_ERROR;
+ }
+
if (useZlib)
return zlibRecv(buf, (long)len);
- return proto->WsRecv(s, buf, (long)len, MSG_DUMPASTEXT);
+ return Netlib_Recv(s, buf, (long)len, MSG_DUMPASTEXT);
}
int ThreadData::send(char* buf, int bufsize)
@@ -2008,22 +2015,21 @@ int ThreadData::send(char* buf, int bufsize) if (this == nullptr)
return 0;
+ lastWriteTime = ::GetTickCount();
if (bufsize == -1)
bufsize = (int)mir_strlen(buf);
- WaitForSingleObject(iomutex, 6000);
+ mir_cslock lck(proto->m_csSocket);
int result;
if (useZlib)
result = zlibSend(buf, bufsize);
else
- result = proto->WsSend(s, buf, bufsize, MSG_DUMPASTEXT);
+ result = Netlib_Send(s, buf, bufsize, MSG_DUMPASTEXT);
if (result == SOCKET_ERROR)
close();
- ReleaseMutex(iomutex);
-
return result;
}
diff --git a/protocols/JabberG/src/jabber_ws.cpp b/protocols/JabberG/src/jabber_ws.cpp deleted file mode 100644 index 3f70f1d6c1..0000000000 --- a/protocols/JabberG/src/jabber_ws.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/*
-
-Jabber Protocol Plugin for Miranda NG
-
-Copyright (c) 2002-04 Santithorn Bunchua
-Copyright (c) 2005-12 George Hazan
-Copyright (C) 2012-22 Miranda NG team
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-*/
-
-#include "stdafx.h"
-
-bool CJabberProto::WsInit(void)
-{
- m_lastTicks = ::GetTickCount();
-
-
- NETLIBUSER nlu = {};
- nlu.flags = NUF_OUTGOING | NUF_INCOMING | NUF_HTTPCONNS | NUF_UNICODE;
- nlu.szDescriptiveName.w = m_tszUserName;
- nlu.szSettingsModule = m_szModuleName;
- m_hNetlibUser = Netlib_RegisterUser(&nlu);
- return m_hNetlibUser != nullptr;
-}
-
-HNETLIBCONN CJabberProto::WsConnect(char* host, uint16_t port)
-{
- NETLIBOPENCONNECTION nloc = {};
- nloc.szHost = host;
- nloc.wPort = port;
- nloc.timeout = 6;
- return Netlib_OpenConnection(m_hNetlibUser, &nloc);
-}
-
-int CJabberProto::WsSend(HNETLIBCONN hConn, char* data, int datalen, int flags)
-{
- m_lastTicks = ::GetTickCount();
- int ret = Netlib_Send(hConn, data, datalen, flags);
- if (ret == SOCKET_ERROR || ret != datalen) {
- debugLogA("Netlib_Send() failed, error=%d", WSAGetLastError());
- return SOCKET_ERROR;
- }
- return ret;
-}
-
-int CJabberProto::WsRecv(HNETLIBCONN hConn, char* data, long datalen, int flags)
-{
- int ret = Netlib_Recv(hConn, data, datalen, flags);
- if (ret == SOCKET_ERROR) {
- debugLogA("Netlib_Recv() failed, error=%d", WSAGetLastError());
- return 0;
- }
- if (ret == 0) {
- debugLogA("Connection closed gracefully");
- return 0;
- }
- return ret;
-}
diff --git a/protocols/JabberG/src/jabber_zstream.cpp b/protocols/JabberG/src/jabber_zstream.cpp index ec3a7ca3b7..0931e4fc34 100644 --- a/protocols/JabberG/src/jabber_zstream.cpp +++ b/protocols/JabberG/src/jabber_zstream.cpp @@ -72,7 +72,7 @@ int ThreadData::zlibSend(char* data, int datalen) }
int send_datalen = ZLIB_CHUNK_SIZE - zStreamOut.avail_out;
- int len = proto->WsSend(s, send_data, send_datalen, MSG_NODUMP);
+ int len = Netlib_Send(s, send_data, send_datalen, MSG_NODUMP);
if (len == SOCKET_ERROR || len != send_datalen) {
proto->debugLogA("Netlib_Send() failed, error=%d", WSAGetLastError());
return SOCKET_ERROR;
@@ -92,13 +92,15 @@ int ThreadData::zlibRecv(char* data, long datalen) {
if (zRecvReady) {
retry:
- zRecvDatalen = proto->WsRecv(s, zRecvData, ZLIB_CHUNK_SIZE, MSG_NODUMP);
+ zRecvDatalen = Netlib_Recv(s, zRecvData, ZLIB_CHUNK_SIZE, MSG_NODUMP);
if (zRecvDatalen == SOCKET_ERROR) {
proto->debugLogA("Netlib_Recv() failed, error=%d", WSAGetLastError());
return SOCKET_ERROR;
}
- if (zRecvDatalen == 0)
+ if (zRecvDatalen == 0) {
+ proto->debugLogA("Connection closed gracefully");
return 0;
+ }
zStreamIn.avail_in = zRecvDatalen;
zStreamIn.next_in = (Bytef*)zRecvData;
diff --git a/protocols/JabberG/src/stdafx.h b/protocols/JabberG/src/stdafx.h index 8d56126b59..cf41737088 100644 --- a/protocols/JabberG/src/stdafx.h +++ b/protocols/JabberG/src/stdafx.h @@ -339,10 +339,10 @@ struct ThreadData ptrA szStreamId;
char* buffer;
+ uint32_t lastWriteTime; // in ticks
// network support
HNETLIBCONN s;
- HANDLE iomutex; // protects i/o operations
CJabberProto *proto;
// XEP-0138 (Compression support)
@@ -367,7 +367,7 @@ struct ThreadData bool bIsReg;
bool reg_done, bIsSessionAvailable;
bool bBookmarksLoaded;
- uint32_t dwLoginRqs;
+ uint32_t dwLoginRqs;
// connection & login data
JABBER_CONN_DATA conn;
|