From e145db68fb5b7d0682a4b2be0174cebfe47dd74e Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 13 Jan 2017 00:01:59 +0300 Subject: a bit less netlib services --- protocols/JabberG/src/jabber_byte.cpp | 17 +++++++++++------ protocols/JabberG/src/jabber_file.cpp | 15 ++++++++++----- protocols/JabberG/src/jabber_util.cpp | 2 +- protocols/JabberG/src/jabber_ws.cpp | 4 ++-- 4 files changed, 24 insertions(+), 14 deletions(-) (limited to 'protocols/JabberG') diff --git a/protocols/JabberG/src/jabber_byte.cpp b/protocols/JabberG/src/jabber_byte.cpp index 90cf6c6894..deefa4ebe7 100644 --- a/protocols/JabberG/src/jabber_byte.cpp +++ b/protocols/JabberG/src/jabber_byte.cpp @@ -192,20 +192,25 @@ void CJabberProto::ByteSendThread(JABBER_BYTE_TRANSFER *jbt) if (m_options.BsDirectManual) localAddr = getStringA("BsDirectAddr"); - NETLIBBIND nlb = {0}; + NETLIBBIND nlb = {}; nlb.cbSize = sizeof(NETLIBBIND); nlb.pfnNewConnectionV2 = JabberByteSendConnection; nlb.pExtra = this; nlb.wPort = 0; // Use user-specified incoming port ranges, if available - jbt->hConn = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)m_hNetlibUser, (LPARAM)&nlb); + + jbt->hConn = Netlib_BindPort(m_hNetlibUser, &nlb); if (jbt->hConn == NULL) { debugLogA("Cannot allocate port for bytestream_send thread, thread ended."); delete jbt; return; } - if (localAddr == NULL) - localAddr = (char*)CallService(MS_NETLIB_ADDRESSTOSTRING, 1, nlb.dwExternalIP); + if (localAddr == NULL) { + sockaddr_in sin = {}; + sin.sin_family = AF_INET; + sin.sin_addr.S_un.S_addr = nlb.dwExternalIP; + localAddr = Netlib_AddressToString(&sin); + } mir_snwprintf(szPort, L"%d", nlb.wPort); JABBER_LIST_ITEM *item = ListAdd(LIST_BYTE, szPort); @@ -449,7 +454,7 @@ void CJabberProto::ByteSendViaProxy(JABBER_BYTE_TRANSFER *jbt) nloc.cbSize = sizeof(nloc); nloc.szHost = mir_u2a(szHost); nloc.wPort = port; - hConn = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc); + hConn = Netlib_OpenConnection(m_hNetlibUser, &nloc); mir_free((void*)nloc.szHost); if (hConn != NULL) { @@ -629,7 +634,7 @@ void __cdecl CJabberProto::ByteReceiveThread(JABBER_BYTE_TRANSFER *jbt) nloc.cbSize = sizeof(nloc); nloc.szHost = mir_u2a(szHost); nloc.wPort = port; - hConn = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc); + hConn = Netlib_OpenConnection(m_hNetlibUser, &nloc); mir_free((void*)nloc.szHost); if (hConn == NULL) { diff --git a/protocols/JabberG/src/jabber_file.cpp b/protocols/JabberG/src/jabber_file.cpp index bfd730a73c..ff95251f6f 100644 --- a/protocols/JabberG/src/jabber_file.cpp +++ b/protocols/JabberG/src/jabber_file.cpp @@ -40,7 +40,7 @@ void __cdecl CJabberProto::FileReceiveThread(filetransfer *ft) nloc.cbSize = sizeof(nloc); nloc.szHost = ft->httpHostName; nloc.wPort = ft->httpPort; - info.s = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc); + info.s = Netlib_OpenConnection(m_hNetlibUser, &nloc); if (info.s == NULL) { debugLogA("Connection failed (%d), thread ended", WSAGetLastError()); ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0); @@ -240,12 +240,13 @@ void __cdecl CJabberProto::FileServerThread(filetransfer *ft) ThreadData info(this, NULL); ft->type = FT_OOB; - NETLIBBIND nlb = { 0 }; + NETLIBBIND nlb = {}; nlb.cbSize = sizeof(NETLIBBIND); nlb.pfnNewConnectionV2 = JabberFileServerConnection; nlb.pExtra = this; nlb.wPort = 0; // Use user-specified incoming port ranges, if available - info.s = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)m_hNetlibUser, (LPARAM)&nlb); + + info.s = Netlib_BindPort(m_hNetlibUser, &nlb); if (info.s == NULL) { debugLogA("Cannot allocate port to bind for file server thread, thread ended."); ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0); @@ -286,8 +287,12 @@ void __cdecl CJabberProto::FileServerThread(filetransfer *ft) ptrA myAddr; if (m_options.BsDirect && m_options.BsDirectManual) myAddr = getStringA("BsDirectAddr"); - if (myAddr == NULL) - myAddr = (char*)CallService(MS_NETLIB_ADDRESSTOSTRING, 1, nlb.dwExternalIP); + if (myAddr == NULL) { + sockaddr_in sin = {}; + sin.sin_family = AF_INET; + sin.sin_addr.S_un.S_addr = nlb.dwExternalIP; + myAddr = Netlib_AddressToString(&sin); + } char szAddr[256]; mir_snprintf(szAddr, "http://%s:%d/%s", myAddr, nlb.wPort, pFileName); diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp index 4820aafc0d..86850775aa 100644 --- a/protocols/JabberG/src/jabber_util.cpp +++ b/protocols/JabberG/src/jabber_util.cpp @@ -898,7 +898,7 @@ void __cdecl CJabberProto::LoadHttpAvatars(void* param) nlhr.szUrl = avs[i].Url; nlhr.nlc = hHttpCon; - NETLIBHTTPREQUEST * res = Netlib_HttpTransaction(m_hNetlibUser, &nlhr); + NETLIBHTTPREQUEST *res = Netlib_HttpTransaction(m_hNetlibUser, &nlhr); if (res) { hHttpCon = res->nlc; if (res->resultCode == 200 && res->dataLength) { diff --git a/protocols/JabberG/src/jabber_ws.cpp b/protocols/JabberG/src/jabber_ws.cpp index 986d1620c1..92dab17061 100644 --- a/protocols/JabberG/src/jabber_ws.cpp +++ b/protocols/JabberG/src/jabber_ws.cpp @@ -47,12 +47,12 @@ void CJabberProto::WsUninit(void) JABBER_SOCKET CJabberProto::WsConnect(char* host, WORD port) { - NETLIBOPENCONNECTION nloc = { 0 }; + NETLIBOPENCONNECTION nloc = {}; nloc.cbSize = sizeof(nloc); nloc.szHost = host; nloc.wPort = port; nloc.timeout = 6; - return (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc); + return Netlib_OpenConnection(m_hNetlibUser, &nloc); } int CJabberProto::WsSend(JABBER_SOCKET hConn, char* data, int datalen, int flags) -- cgit v1.2.3