From 20a9f536e44c3928ad8c3cf7a2959bce557dab8e Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 13 Jan 2017 17:47:33 +0300 Subject: (wiping blood from hands) no more netlib services --- bin10/lib/mir_app.lib | Bin 95274 -> 97410 bytes bin10/lib/mir_app64.lib | Bin 90770 -> 92734 bytes bin12/lib/mir_app.lib | Bin 95274 -> 97410 bytes bin12/lib/mir_app64.lib | Bin 90770 -> 92734 bytes bin14/lib/mir_app.lib | Bin 95274 -> 97410 bytes bin14/lib/mir_app64.lib | Bin 90770 -> 92734 bytes include/m_netlib.h | 64 ++++++++++-------------------- plugins/HTTPServer/src/FileShareNode.cpp | 2 +- plugins/Ping/src/utils.cpp | 2 +- plugins/YAMN/src/proto/netlib.cpp | 10 ++--- protocols/AimOscar/src/client.cpp | 4 +- protocols/AimOscar/src/connection.cpp | 5 +-- protocols/AimOscar/src/direct_connect.cpp | 4 +- protocols/AimOscar/src/file.cpp | 4 +- protocols/IRCG/src/irclib.cpp | 2 +- protocols/IRCG/src/tools.cpp | 2 +- protocols/IcqOscarJ/src/chan_04close.cpp | 2 +- protocols/IcqOscarJ/src/fam_01service.cpp | 4 +- protocols/IcqOscarJ/src/icq_http.cpp | 6 +-- protocols/IcqOscarJ/src/icq_server.cpp | 2 +- protocols/JabberG/src/jabber_byte.cpp | 6 +-- protocols/JabberG/src/jabber_file.cpp | 4 +- protocols/JabberG/src/jabber_thread.cpp | 12 ++---- protocols/MRA/src/MraAvatars.cpp | 4 +- protocols/MRA/src/MraFilesQueue.cpp | 3 +- protocols/MRA/src/MraMRIMProxy.cpp | 3 +- protocols/MRA/src/Mra_proto.cpp | 9 ++--- protocols/MSN/src/msn_commands.cpp | 4 +- protocols/MSN/src/msn_http.cpp | 5 +-- protocols/MSN/src/msn_misc.cpp | 2 +- protocols/MSN/src/msn_threads.cpp | 12 +++--- protocols/MSN/src/msn_ws.cpp | 12 +++--- protocols/Tlen/src/tlen_thread.cpp | 7 ++-- src/mir_app/src/mir_app.def | 10 +++++ src/mir_app/src/mir_app64.def | 10 +++++ src/mir_app/src/netlib.cpp | 33 +++------------ src/mir_app/src/netlib.h | 14 +------ src/mir_app/src/netlibhttpproxy.cpp | 35 +++++++++------- src/mir_app/src/netlibopenconn.cpp | 10 ++--- src/mir_app/src/netlibsock.cpp | 42 ++++++++++++-------- 40 files changed, 155 insertions(+), 195 deletions(-) diff --git a/bin10/lib/mir_app.lib b/bin10/lib/mir_app.lib index 99e0c072da..27ee166768 100644 Binary files a/bin10/lib/mir_app.lib and b/bin10/lib/mir_app.lib differ diff --git a/bin10/lib/mir_app64.lib b/bin10/lib/mir_app64.lib index 53d8c55b55..022371814b 100644 Binary files a/bin10/lib/mir_app64.lib and b/bin10/lib/mir_app64.lib differ diff --git a/bin12/lib/mir_app.lib b/bin12/lib/mir_app.lib index 99e0c072da..27ee166768 100644 Binary files a/bin12/lib/mir_app.lib and b/bin12/lib/mir_app.lib differ diff --git a/bin12/lib/mir_app64.lib b/bin12/lib/mir_app64.lib index 53d8c55b55..022371814b 100644 Binary files a/bin12/lib/mir_app64.lib and b/bin12/lib/mir_app64.lib differ diff --git a/bin14/lib/mir_app.lib b/bin14/lib/mir_app.lib index 99e0c072da..27ee166768 100644 Binary files a/bin14/lib/mir_app.lib and b/bin14/lib/mir_app.lib differ diff --git a/bin14/lib/mir_app64.lib b/bin14/lib/mir_app64.lib index 53d8c55b55..022371814b 100644 Binary files a/bin14/lib/mir_app64.lib and b/bin14/lib/mir_app64.lib differ diff --git a/include/m_netlib.h b/include/m_netlib.h index eb343ce4a1..6380c34e05 100644 --- a/include/m_netlib.h +++ b/include/m_netlib.h @@ -99,9 +99,6 @@ EXTERN_C MIR_APP_DLL(HNETLIBUSER) Netlib_RegisterUser(const NETLIBUSER *pDescr); // Once it has passed to Netlib, Netlib is the owner of it, the caller should not refer to the memory // In any way after this point. // -// wParam = (WPARAM)hNetLibUser -// lParam = (LPARAM)(char*)szHeaders -// // NOTE: The szHeaders parameter should be a NULL terminated string following the HTTP header syntax. // This string will be injected verbatim, thus the user should be aware of setting strings that are not // headers. This service is NOT THREAD SAFE, only a single thread is expected to set the headers and a single @@ -110,7 +107,7 @@ EXTERN_C MIR_APP_DLL(HNETLIBUSER) Netlib_RegisterUser(const NETLIBUSER *pDescr); // Version 0.3.2a+ (2003/10/27) // -#define MS_NETLIB_SETSTICKYHEADERS "Netlib/SetStickyHeaders" +EXTERN_C MIR_APP_DLL(int) Netlib_SetStickyHeaders(HNETLIBUSER nlu, const char *szHeaders); /* Notes on HTTP gateway usage When a connection is initiated through an HTTP proxy using @@ -336,8 +333,7 @@ EXTERN_C MIR_APP_DLL(HANDLE) Netlib_OpenConnection(HNETLIBUSER nlu, const NETLIB ///////////////////////////////////////////////////////////////////////////////////////// // Sets the required information for an HTTP proxy connection -// wParam = (WPARAM)(HANDLE)hConnection -// lParam = (LPARAM)(NETLIBHTTPPROXYINFO*)&nlhpi +// // Returns nonzero on success, 0 on failure (!! this is different to most of the rest of Miranda, but consistent with netlib) // This function is designed to be called from within pfnHttpGatewayInit // See notes below MS_NETLIB_REGISTERUSER. @@ -350,19 +346,18 @@ EXTERN_C MIR_APP_DLL(HANDLE) Netlib_OpenConnection(HNETLIBUSER nlu, const NETLIB struct NETLIBHTTPPROXYINFO { - int cbSize; DWORD flags; char *szHttpPostUrl; char *szHttpGetUrl; int firstGetSequence, firstPostSequence; int combinePackets; }; -#define MS_NETLIB_SETHTTPPROXYINFO "Netlib/SetHttpProxyInfo" + +EXTERN_C MIR_APP_DLL(int) Netlib_SetHttpProxyInfo(HANDLE hConnection, const NETLIBHTTPPROXYINFO *nlhpi); ///////////////////////////////////////////////////////////////////////////////////////// // Gets the SOCKET associated with a netlib handle -// wParam = (WPARAM)(HANDLE)hNetlibHandle -// lParam = 0 +// // Returns the SOCKET on success, INVALID_SOCKET on failure // hNetlibHandle should have been returned by MS_NETLIB_BINDPORT or // MS_NETLIB_OPENCONNECTION only. @@ -370,7 +365,9 @@ struct NETLIBHTTPPROXYINFO // HTTP proxy in which case calling send() or recv() will totally break things. // Errors: ERROR_INVALID_PARAMETER -#define MS_NETLIB_GETSOCKET "Netlib/GetSocket" +EXTERN_C MIR_APP_DLL(UINT_PTR) Netlib_GetSocket(HANDLE hConnection); + +///////////////////////////////////////////////////////////////////////////////////////// #define Netlib_GetBase64DecodedBufferSize(cchEncoded) (((cchEncoded)>>2)*3) #define Netlib_GetBase64EncodedBufferSize(cbDecoded) (((cbDecoded)*4+11)/12*4+1) @@ -394,23 +391,20 @@ EXTERN_C MIR_APP_DLL(bool) Netlib_StringToAddress(const char *str, sockaddr_in // Get connection Information // IPv4 will be supplied in formats address:port or address // IPv6 will be supplied in formats [address]:port or [address] -// wParam = (WPARAM)(HANDLE)hConnection -// lParam = (LPARAM)(NETLIBCONNINFO*) pointer to the connection information structure to fill // Returns 0 if successful struct NETLIBCONNINFO { - int cbSize; char szIpPort[64]; unsigned dwIpv4; WORD wPort; }; -#define MS_NETLIB_GETCONNECTIONINFO "Netlib/GetConnectionInfo" +EXTERN_C MIR_APP_DLL(int) Netlib_GetConnectionInfo(HANDLE hConnection, NETLIBCONNINFO *connInfo); ///////////////////////////////////////////////////////////////////////////////////////// -// Get connection Information -// wParam = (WPARAM)IP filter 1 - return global only IPv6 address, 0 all IPs +// Gets connection Information +// // Returns (INT_PTR)(NETLIBIPLIST*) numeric IP address address array // the last element of the array is all 0s, 0 if not successful @@ -420,7 +414,7 @@ struct NETLIBIPLIST char szIp[1][64]; }; -#define MS_NETLIB_GETMYIP "Netlib/GetMyIP" +EXTERN_C MIR_APP_DLL(NETLIBIPLIST*) Netlib_GetMyIp(bool bGlobalOnly); ///////////////////////////////////////////////////////////////////////////////////////// // Send an HTTP request over a connection @@ -620,41 +614,35 @@ EXTERN_C MIR_APP_DLL(int) Netlib_Recv(HANDLE hConn, char *buf, int len, int flag ///////////////////////////////////////////////////////////////////////////////////////// // Determine the status of one or more connections -// wParam = 0 -// lParam = (LPARAM)(NETLIBSELECT*)&nls -// Returns the number of ready connections, SOCKET_ERROR on failure, -// 0 if the timeout expired. +// Returns the number of ready connections, SOCKET_ERROR on failure, 0 if the timeout expired. // All handles passed to this function must have been returned by either // MS_NETLIB_OPENCONNECTION or MS_NETLIB_BINDPORT. -// The last handle in each list must be followed by either NULL or -// INVALID_HANDLE_VALUE. +// The last handle in each list must be followed by either NULL or INVALID_HANDLE_VALUE. // Errors: ERROR_INVALID_HANDLE, ERROR_INVALID_DATA, anything from select() struct NETLIBSELECT { - int cbSize; - DWORD dwTimeout; // in milliseconds, INFINITE is acceptable + DWORD dwTimeout; // in milliseconds, INFINITE is acceptable HANDLE hReadConns[FD_SETSIZE+1]; HANDLE hWriteConns[FD_SETSIZE+1]; HANDLE hExceptConns[FD_SETSIZE+1]; }; +EXTERN_C MIR_APP_DLL(int) Netlib_Select(NETLIBSELECT *nls); + struct NETLIBSELECTEX { - int cbSize; - DWORD dwTimeout; // in milliseconds, INFINITE is acceptable + DWORD dwTimeout; // in milliseconds, INFINITE is acceptable HANDLE hReadConns[FD_SETSIZE+1]; HANDLE hWriteConns[FD_SETSIZE+1]; HANDLE hExceptConns[FD_SETSIZE+1]; - /* Added in v0.3.3+ */ BOOL hReadStatus[FD_SETSIZE+1]; /* out, [in, expected to be FALSE] */ BOOL hWriteStatus[FD_SETSIZE+1]; /* out, [in, expected to be FALSE] */ BOOL hExceptStatus[FD_SETSIZE+1]; /* out, [in, expected to be FALSE] */ }; -#define MS_NETLIB_SELECT "Netlib/Select" -#define MS_NETLIB_SELECTEX "Netlib/SelectEx" +EXTERN_C MIR_APP_DLL(int) Netlib_SelectEx(NETLIBSELECTEX *nls); ///////////////////////////////////////////////////////////////////////////////////////// // Shutdown connection @@ -711,22 +699,14 @@ EXTERN_C MIR_APP_DLL(int) Netlib_GetMorePackets(HANDLE hReceiver, NETLIBPACKETRE // Returns previous timeout value // Errors: -1 -#define MS_NETLIB_SETPOLLINGTIMEOUT "Netlib/SetPollingTimeout" +EXTERN_C MIR_APP_DLL(int) Netlib_SetPollingTimeout(HANDLE hConnection, int iTimeout); ///////////////////////////////////////////////////////////////////////////////////////// // Makes connection SSL -// wParam = (WPARAM)(HANDLE)hConn -// lParam = (LPARAM)(NETLIBSSL*)&nlssl or null if no certficate validation required +// // Returns 0 on failure 1 on success -#define MS_NETLIB_STARTSSL "Netlib/StartSsl" - -struct NETLIBSSL -{ - int cbSize; - const char *host; // Expected host name - int flags; // Reserved -}; +EXTERN_C MIR_APP_DLL(int) Netlib_StartSsl(HANDLE hConnection, const char *host); ///////////////////////////////////////////////////////////////////////////////////////// // netlib log funcitons diff --git a/plugins/HTTPServer/src/FileShareNode.cpp b/plugins/HTTPServer/src/FileShareNode.cpp index 8584df5111..fbc2d43af6 100644 --- a/plugins/HTTPServer/src/FileShareNode.cpp +++ b/plugins/HTTPServer/src/FileShareNode.cpp @@ -83,7 +83,7 @@ CLShareUser::~CLShareUser() void CLShareUser::CloseSocket() { - SOCKET s = CallService(MS_NETLIB_GETSOCKET, (WPARAM)hConnection, 0); + SOCKET s = Netlib_GetSocket(hConnection); if (s != INVALID_SOCKET) { shutdown(s, SD_SEND); int nBytesRead; diff --git a/plugins/Ping/src/utils.cpp b/plugins/Ping/src/utils.cpp index 949c8cd1ee..e643b2423a 100644 --- a/plugins/Ping/src/utils.cpp +++ b/plugins/Ping/src/utils.cpp @@ -101,7 +101,7 @@ INT_PTR PluginPing(WPARAM, LPARAM lParam) if (s) { LINGER l; char buf[1024]; - SOCKET socket = (SOCKET)CallService(MS_NETLIB_GETSOCKET, (WPARAM)s, (LPARAM)NLOCF_HTTP); + SOCKET socket = Netlib_GetSocket(s); l.l_onoff = 1; l.l_linger = 0; setsockopt(socket, SOL_SOCKET, SO_LINGER, (char *)&l, sizeof(l)); diff --git a/plugins/YAMN/src/proto/netlib.cpp b/plugins/YAMN/src/proto/netlib.cpp index b6405b7e90..64da34ed8d 100644 --- a/plugins/YAMN/src/proto/netlib.cpp +++ b/plugins/YAMN/src/proto/netlib.cpp @@ -62,12 +62,12 @@ void CNLClient::SSLify() throw(DWORD) #ifdef DEBUG_COMM SSL_DebugLog("Staring SSL..."); #endif - int socket = CallService(MS_NETLIB_GETSOCKET, (WPARAM)hConnection, 0); + int socket = Netlib_GetSocket(hConnection); if (socket != INVALID_SOCKET) { #ifdef DEBUG_COMM SSL_DebugLog("Staring netlib core SSL"); #endif - if (CallService(MS_NETLIB_STARTSSL, (WPARAM)hConnection, 0)) { + if (Netlib_StartSsl(hConnection, NULL)) { #ifdef DEBUG_COMM SSL_DebugLog("Netlib core SSL started"); #endif @@ -180,12 +180,10 @@ char* CNLClient::Recv(char *buf, int buflen) throw(DWORD) throw NetworkError = (DWORD)ENL_RECVALLOC; if (!isTLSed) { - NETLIBSELECT nls; - memset(&nls, 0, sizeof(NETLIBSELECT)); - nls.cbSize = sizeof(NETLIBSELECT); + NETLIBSELECT nls = {}; nls.dwTimeout = 60000; nls.hReadConns[0] = hConnection; - switch (CallService(MS_NETLIB_SELECT, 0, (LPARAM)&nls)) { + switch (Netlib_Select(&nls)) { case SOCKET_ERROR: free(buf); SystemError = WSAGetLastError(); diff --git a/protocols/AimOscar/src/client.cpp b/protocols/AimOscar/src/client.cpp index d428154a0a..839698bb96 100755 --- a/protocols/AimOscar/src/client.cpp +++ b/protocols/AimOscar/src/client.cpp @@ -255,8 +255,8 @@ int CAimProto::aim_client_ready(HANDLE hServerConn, unsigned short &seqno) { unsigned short offset = 0; - NETLIBCONNINFO connInfo = { sizeof(connInfo) }; - CallService(MS_NETLIB_GETCONNECTIONINFO, (WPARAM)hServerConn, (LPARAM)&connInfo); + NETLIBCONNINFO connInfo = {}; + Netlib_GetConnectionInfo(hServerConn, &connInfo); m_internal_ip = connInfo.dwIpv4; diff --git a/protocols/AimOscar/src/connection.cpp b/protocols/AimOscar/src/connection.cpp index a3635cdcfc..03b51e2577 100755 --- a/protocols/AimOscar/src/connection.cpp +++ b/protocols/AimOscar/src/connection.cpp @@ -30,10 +30,7 @@ HANDLE CAimProto::aim_connect(const char* server, unsigned short port, bool use_ debugLogA("%s:%u", server, port); HANDLE con = Netlib_OpenConnection(m_hNetlibUser, &ncon); if (con && use_ssl) { - NETLIBSSL ssl = { 0 }; - ssl.cbSize = sizeof(ssl); - ssl.host = host; - if (!CallService(MS_NETLIB_STARTSSL, (WPARAM)con, (LPARAM)&ssl)) { + if (!Netlib_StartSsl(con, host)) { Netlib_CloseHandle(con); con = NULL; } diff --git a/protocols/AimOscar/src/direct_connect.cpp b/protocols/AimOscar/src/direct_connect.cpp index 2b4bcb9366..6f9eecf76b 100644 --- a/protocols/AimOscar/src/direct_connect.cpp +++ b/protocols/AimOscar/src/direct_connect.cpp @@ -65,8 +65,8 @@ void aim_direct_connection_initiated(HANDLE hNewConnection, DWORD, void* extra)/ { CAimProto *ppro = (CAimProto*)extra; - NETLIBCONNINFO connInfo = { sizeof(connInfo) }; - CallService(MS_NETLIB_GETCONNECTIONINFO, (WPARAM)hNewConnection, (LPARAM)&connInfo); + NETLIBCONNINFO connInfo = {}; + Netlib_GetConnectionInfo(hNewConnection, &connInfo); ppro->debugLogA("Buddy connected: %s", connInfo.szIpPort); diff --git a/protocols/AimOscar/src/file.cpp b/protocols/AimOscar/src/file.cpp index cdb81e03b6..42c2ae2b8d 100644 --- a/protocols/AimOscar/src/file.cpp +++ b/protocols/AimOscar/src/file.cpp @@ -186,7 +186,6 @@ int CAimProto::sending_file(file_transfer *ft, HANDLE hServerPacketRecver, NETLI if (ft->pfts.currentFileProgress) _lseeki64(fid, ft->pfts.currentFileProgress, SEEK_SET); NETLIBSELECT tSelect = { 0 }; - tSelect.cbSize = sizeof(tSelect); tSelect.hReadConns[0] = ft->hConn; ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->pfts); @@ -203,7 +202,8 @@ int CAimProto::sending_file(file_transfer *ft, HANDLE hServerPacketRecver, NETLI if (clock() >= lNotify) { ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->pfts); - if (CallService(MS_NETLIB_SELECT, 0, (LPARAM)&tSelect)) break; + if (Netlib_Select(&tSelect)) + break; lNotify = clock() + 500; } diff --git a/protocols/IRCG/src/irclib.cpp b/protocols/IRCG/src/irclib.cpp index 3235e06a76..cf6a7914d7 100644 --- a/protocols/IRCG/src/irclib.cpp +++ b/protocols/IRCG/src/irclib.cpp @@ -209,7 +209,7 @@ bool CIrcProto::Connect(const CIrcSessionInfo& info) FindLocalIP(con); // get the local ip used for filetransfers etc if (info.m_iSSL > 0) { - if (!CallService(MS_NETLIB_STARTSSL, (WPARAM)con, 0) && info.m_iSSL == 2) { + if (!Netlib_StartSsl(con, 0) && info.m_iSSL == 2) { Netlib_CloseHandle(con); con = NULL; m_info.Reset(); diff --git a/protocols/IRCG/src/tools.cpp b/protocols/IRCG/src/tools.cpp index b6e5344e4d..34b0148b96 100644 --- a/protocols/IRCG/src/tools.cpp +++ b/protocols/IRCG/src/tools.cpp @@ -592,7 +592,7 @@ bool CIrcProto::AddWindowItemData(CMStringW window, const wchar_t* pszLimit, con void CIrcProto::FindLocalIP(HANDLE hConn) // inspiration from jabber { // Determine local IP - int socket = CallService(MS_NETLIB_GETSOCKET, (WPARAM)hConn, 0); + int socket = Netlib_GetSocket(hConn); if (socket != INVALID_SOCKET) { struct sockaddr_in saddr; int len = sizeof(saddr); diff --git a/protocols/IcqOscarJ/src/chan_04close.cpp b/protocols/IcqOscarJ/src/chan_04close.cpp index 315b22c888..cc7ea7de46 100644 --- a/protocols/IcqOscarJ/src/chan_04close.cpp +++ b/protocols/IcqOscarJ/src/chan_04close.cpp @@ -137,7 +137,7 @@ int CIcqProto::connectNewServer(serverthread_info *info) hServerConn = NetLib_OpenConnection(m_hNetlibUser, NULL, &nloc); if (hServerConn && info->newServerSSL) /* Start SSL session if requested */ - if (!CallService(MS_NETLIB_STARTSSL, (WPARAM)hServerConn, 0)) + if (!Netlib_StartSsl(hServerConn, NULL)) NetLib_CloseConnection(&hServerConn, FALSE); if (hServerConn) { diff --git a/protocols/IcqOscarJ/src/fam_01service.cpp b/protocols/IcqOscarJ/src/fam_01service.cpp index a416b1b97a..72640bb168 100644 --- a/protocols/IcqOscarJ/src/fam_01service.cpp +++ b/protocols/IcqOscarJ/src/fam_01service.cpp @@ -369,9 +369,9 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, size_t wBufferLength, snac_heade debugLogA("Unable to connect to ICQ new family server."); // we want the handler to be called even if the connecting failed else if (bServerSSL) { /* Start SSL session if requested */ - debugLogA("(%p) Starting SSL negotiation", CallService(MS_NETLIB_GETSOCKET, (WPARAM)hConnection, 0)); + debugLogA("(%p) Starting SSL negotiation", Netlib_GetSocket(hConnection)); - if (!CallService(MS_NETLIB_STARTSSL, (WPARAM)hConnection, 0)) { + if (!Netlib_StartSsl(hConnection, NULL)) { debugLogA("Unable to connect to ICQ new family server, SSL could not be negotiated"); NetLib_CloseConnection(&hConnection, FALSE); } diff --git a/protocols/IcqOscarJ/src/icq_http.cpp b/protocols/IcqOscarJ/src/icq_http.cpp index d9a8e5378a..20d63bf75d 100644 --- a/protocols/IcqOscarJ/src/icq_http.cpp +++ b/protocols/IcqOscarJ/src/icq_http.cpp @@ -37,7 +37,6 @@ int icq_httpGatewayInit(HANDLE hConn, NETLIBOPENCONNECTION*, NETLIBHTTPREQUEST * DWORD dwSid1, dwSid2, dwSid3, dwSid4; BYTE *buf; char szSid[33], szHttpServer[256], szHttpGetUrl[300], szHttpPostUrl[300]; - NETLIBHTTPPROXYINFO nlhpi = {0}; if (nlhr->dataLength < 31) { @@ -68,15 +67,14 @@ int icq_httpGatewayInit(HANDLE hConn, NETLIBOPENCONNECTION*, NETLIBHTTPREQUEST * memcpy(szHttpServer, buf, wIpLen); szHttpServer[wIpLen] = '\0'; - nlhpi.cbSize = sizeof(nlhpi); + NETLIBHTTPPROXYINFO nlhpi = {}; nlhpi.flags = NLHPIF_USEPOSTSEQUENCE; nlhpi.szHttpGetUrl = szHttpGetUrl; nlhpi.szHttpPostUrl = szHttpPostUrl; nlhpi.firstPostSequence = 1; mir_snprintf(szHttpGetUrl, "http://%s/monitor?sid=%s", szHttpServer, szSid); mir_snprintf(szHttpPostUrl, "http://%s/data?sid=%s&seq=", szHttpServer, szSid); - - return CallService(MS_NETLIB_SETHTTPPROXYINFO, (WPARAM)hConn, (LPARAM)&nlhpi); + return Netlib_SetHttpProxyInfo(hConn, &nlhpi); } diff --git a/protocols/IcqOscarJ/src/icq_server.cpp b/protocols/IcqOscarJ/src/icq_server.cpp index 1de0a261e5..732c251ec3 100644 --- a/protocols/IcqOscarJ/src/icq_server.cpp +++ b/protocols/IcqOscarJ/src/icq_server.cpp @@ -63,7 +63,7 @@ void __cdecl CIcqProto::ServerThread(serverthread_start_info *infoParam) SAFE_FREE((void**)&infoParam); if (hServerConn && m_bSecureConnection) { - if (!CallService(MS_NETLIB_STARTSSL, (WPARAM)hServerConn, 0)) { + if (!Netlib_StartSsl(hServerConn, 0)) { icq_LogMessage(LOG_ERROR, LPGEN("Unable to connect to ICQ login server, SSL could not be negotiated")); SetCurrentStatus(ID_STATUS_OFFLINE); NetLib_CloseConnection(&hServerConn, TRUE); diff --git a/protocols/JabberG/src/jabber_byte.cpp b/protocols/JabberG/src/jabber_byte.cpp index deefa4ebe7..95a9976176 100644 --- a/protocols/JabberG/src/jabber_byte.cpp +++ b/protocols/JabberG/src/jabber_byte.cpp @@ -91,8 +91,8 @@ void JabberByteSendConnection(HANDLE hConn, DWORD /*dwRemoteIP*/, void* extra) char* buffer; int datalen; - NETLIBCONNINFO connInfo = { sizeof(connInfo) }; - CallService(MS_NETLIB_GETCONNECTIONINFO, (WPARAM)hConn, (LPARAM)&connInfo); + NETLIBCONNINFO connInfo = {}; + Netlib_GetConnectionInfo(hConn, &connInfo); mir_snwprintf(szPort, L"%u", connInfo.wPort); ppro->debugLogA("bytestream_send_connection incoming connection accepted: %s", connInfo.szIpPort); @@ -220,7 +220,7 @@ void CJabberProto::ByteSendThread(JABBER_BYTE_TRANSFER *jbt) jbt->hSendEvent = CreateEvent(NULL, FALSE, FALSE, NULL); query << XCHILD(L"streamhost") << XATTR(L"jid", m_ThreadInfo->fullJID) << XATTR(L"host", _A2T(localAddr)) << XATTRI(L"port", nlb.wPort); - NETLIBIPLIST* ihaddr = (NETLIBIPLIST*)CallService(MS_NETLIB_GETMYIP, 1, 0); + NETLIBIPLIST* ihaddr = Netlib_GetMyIp(true); for (unsigned i=0; i < ihaddr->cbNum; i++) if (mir_strcmp(localAddr, ihaddr->szIp[i])) query << XCHILD(L"streamhost") << XATTR(L"jid", m_ThreadInfo->fullJID) << XATTR(L"host", _A2T(ihaddr->szIp[i])) << XATTRI(L"port", nlb.wPort); diff --git a/protocols/JabberG/src/jabber_file.cpp b/protocols/JabberG/src/jabber_file.cpp index ff95251f6f..2ac8d9b0c3 100644 --- a/protocols/JabberG/src/jabber_file.cpp +++ b/protocols/JabberG/src/jabber_file.cpp @@ -175,8 +175,8 @@ void JabberFileServerConnection(JABBER_SOCKET hConnection, DWORD /*dwRemoteIP*/, { CJabberProto *ppro = (CJabberProto*)extra; - NETLIBCONNINFO connInfo = { sizeof(connInfo) }; - CallService(MS_NETLIB_GETCONNECTIONINFO, (WPARAM)hConnection, (LPARAM)&connInfo); + NETLIBCONNINFO connInfo = {}; + Netlib_GetConnectionInfo(hConnection, &connInfo); wchar_t szPort[10]; mir_snwprintf(szPort, L"%d", connInfo.wPort); diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index af32ff56cc..778a2b72e8 100755 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -375,7 +375,7 @@ LBL_FatalError: // Determine local IP if (info.conn.useSSL) { debugLogA("Intializing SSL connection"); - if (!CallService(MS_NETLIB_STARTSSL, (WPARAM)info.s, 0)) { + if (!Netlib_StartSsl(info.s, NULL)) { debugLogA("SSL intialization failed"); if (!info.bIsReg) ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_NONETWORK); @@ -413,11 +413,10 @@ LBL_FatalError: if (dwIdle >= dwConnectionKeepAliveInterval) dwIdle = dwConnectionKeepAliveInterval - 10; // now! - NETLIBSELECT nls = { 0 }; - nls.cbSize = sizeof(NETLIBSELECT); + NETLIBSELECT nls = {}; nls.dwTimeout = dwConnectionKeepAliveInterval - dwIdle; nls.hReadConns[0] = info.s; - int nSelRes = CallService(MS_NETLIB_SELECT, 0, (LPARAM)&nls); + int nSelRes = Netlib_Select(&nls); if (nSelRes == -1) // error break; else if (nSelRes == 0 && m_bSendKeepAlive) { @@ -905,10 +904,7 @@ void CJabberProto::OnProcessProceed(HXML node, ThreadData *info) bool isHosted = gtlk && !gtlk[10] && mir_strcmpi(info->conn.server, "gmail.com") && mir_strcmpi(info->conn.server, "googlemail.com"); - NETLIBSSL ssl = { 0 }; - ssl.cbSize = sizeof(ssl); - ssl.host = isHosted ? info->conn.manualHost : info->conn.server; - if (!CallService(MS_NETLIB_STARTSSL, (WPARAM)info->s, (LPARAM)&ssl)) { + if (!Netlib_StartSsl(info->s, isHosted ? info->conn.manualHost : info->conn.server)) { debugLogA("SSL initialization failed"); info->send(""); info->shutdown(); diff --git a/protocols/MRA/src/MraAvatars.cpp b/protocols/MRA/src/MraAvatars.cpp index 2979323977..20d7cb9770 100644 --- a/protocols/MRA/src/MraAvatars.cpp +++ b/protocols/MRA/src/MraAvatars.cpp @@ -157,8 +157,6 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter) INTERNET_TIME itAvatarLastModifiedTimeServer; WCHAR szErrorText[2048]; - nls.cbSize = sizeof(nls); - Thread_SetName("MRA: AvatarsThreadProc"); HANDLE hThreadEvent = CreateEvent(NULL, FALSE, FALSE, NULL); @@ -256,7 +254,7 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter) nls.hReadConns[0] = hConnection; while (bContinue) { - switch (CallService(MS_NETLIB_SELECT, 0, (LPARAM)&nls)) { + switch (Netlib_Select(&nls)) { case SOCKET_ERROR: case 0:// Time out dwErrorCode = GetLastError(); diff --git a/protocols/MRA/src/MraFilesQueue.cpp b/protocols/MRA/src/MraFilesQueue.cpp index bad116e95e..9b062e46c7 100644 --- a/protocols/MRA/src/MraFilesQueue.cpp +++ b/protocols/MRA/src/MraFilesQueue.cpp @@ -729,7 +729,6 @@ void CMraProto::MraFilesQueueRecvThreadProc(LPVOID lpParameter) bFailed = TRUE; bConnected = FALSE; - nls.cbSize = sizeof(nls); pfts.cbSize = sizeof(pfts); pfts.hContact = dat->hContact; pfts.flags = (PFTS_RECEIVING | PFTS_UNICODE);// pfts.sending = dat->bSending; //true if sending, false if receiving @@ -818,7 +817,7 @@ void CMraProto::MraFilesQueueRecvThreadProc(LPVOID lpParameter) ProtoBroadcastAck(dat->hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)dat->dwIDRequest, (LPARAM)&pfts); while (bContinue) { - switch (CallService(MS_NETLIB_SELECT, 0, (LPARAM)&nls)) { + switch (Netlib_Select(&nls)) { case SOCKET_ERROR: case 0:// Time out dwRetErrorCode = GetLastError(); diff --git a/protocols/MRA/src/MraMRIMProxy.cpp b/protocols/MRA/src/MraMRIMProxy.cpp index 2953356770..f29fd6e0e8 100644 --- a/protocols/MRA/src/MraMRIMProxy.cpp +++ b/protocols/MRA/src/MraMRIMProxy.cpp @@ -126,7 +126,6 @@ DWORD CMraProto::MraMrimProxyConnect(HANDLE hMraMrimProxyData, HANDLE *phConnect while (--dwCurConnectReTryCount && pmmpd->hConnection == NULL); if (pmmpd->hConnection) { - nls.cbSize = sizeof(nls); nls.dwTimeout = (MRA_TIMEOUT_DIRECT_CONN*1000*2); nls.hReadConns[0] = pmmpd->hConnection; bContinue = TRUE; @@ -137,7 +136,7 @@ DWORD CMraProto::MraMrimProxyConnect(HANDLE hMraMrimProxyData, HANDLE *phConnect MraSendPacket(nls.hReadConns[0], 0, MRIM_CS_PROXY_HELLO, &pmmpd->mguidSessionID, sizeof(MRA_GUID)); while (bContinue) { - switch (CallService(MS_NETLIB_SELECT, 0, (LPARAM)&nls)) { + switch (Netlib_Select(&nls)) { case SOCKET_ERROR: case 0:// Time out dwRetErrorCode = GetLastError(); diff --git a/protocols/MRA/src/Mra_proto.cpp b/protocols/MRA/src/Mra_proto.cpp index acd9977a65..8ee2d7101f 100644 --- a/protocols/MRA/src/Mra_proto.cpp +++ b/protocols/MRA/src/Mra_proto.cpp @@ -148,12 +148,11 @@ DWORD CMraProto::MraGetNLBData(CMStringA &szHost, WORD *pwPort) while (--dwCurConnectReTryCount && nls.hReadConns[0] == NULL); if (nls.hReadConns[0]) { - nls.cbSize = sizeof(nls); nls.dwTimeout = 1000 * getDword("TimeOutReceiveNLB", MRA_DEFAULT_TIMEOUT_RECV_NLB); InterlockedExchange((volatile LONG*)&m_dwThreadWorkerLastPingTime, GetTickCount()); while (m_iStatus != ID_STATUS_OFFLINE && bContinue) { - switch (CallService(MS_NETLIB_SELECT, 0, (LPARAM)&nls)) { + switch (Netlib_Select(&nls)) { case SOCKET_ERROR: case 0:// Time out bContinue = FALSE; @@ -218,8 +217,8 @@ DWORD CMraProto::MraNetworkDispatcher() dwCMDNum = 0; MraSendCMD(MRIM_CS_HELLO, NULL, 0); while (m_iStatus != ID_STATUS_OFFLINE && bContinue) { - DWORD dwSelectRet = CallService(MS_NETLIB_SELECT, 0, (LPARAM)&nls); - if (SOCKET_ERROR == dwSelectRet) { + int iSelectRet = Netlib_Select(&nls); + if (SOCKET_ERROR == iSelectRet) { if (m_iStatus != ID_STATUS_OFFLINE) { dwRetErrorCode = GetLastError(); ShowFormattedErrorMessage(L"Disconnected, socket error", dwRetErrorCode); @@ -267,7 +266,7 @@ DWORD CMraProto::MraNetworkDispatcher() } } - if (dwSelectRet == 0) // Time out + if (iSelectRet == 0) // Time out continue; // expand receive buffer dynamically diff --git a/protocols/MSN/src/msn_commands.cpp b/protocols/MSN/src/msn_commands.cpp index cdea188a44..58391b4b29 100644 --- a/protocols/MSN/src/msn_commands.cpp +++ b/protocols/MSN/src/msn_commands.cpp @@ -1410,8 +1410,8 @@ void MSN_ConnectionProc(HANDLE hNewConnection, DWORD /* dwRemoteIP */, void* ext proto->debugLogA("File transfer connection accepted"); - NETLIBCONNINFO connInfo = { sizeof(connInfo) }; - CallService(MS_NETLIB_GETCONNECTIONINFO, (WPARAM)hNewConnection, (LPARAM)&connInfo); + NETLIBCONNINFO connInfo = {}; + Netlib_GetConnectionInfo(hNewConnection, &connInfo); ThreadData* T = proto->MSN_GetThreadByPort(connInfo.wPort); if (T != NULL && T->s == NULL) { diff --git a/protocols/MSN/src/msn_http.cpp b/protocols/MSN/src/msn_http.cpp index 74a0f66fb7..f280daa823 100644 --- a/protocols/MSN/src/msn_http.cpp +++ b/protocols/MSN/src/msn_http.cpp @@ -38,13 +38,12 @@ static ThreadData* FindThreadConn(HANDLE hConn) int msn_httpGatewayInit(HANDLE hConn, NETLIBOPENCONNECTION*, NETLIBHTTPREQUEST*) { - NETLIBHTTPPROXYINFO nlhpi = { 0 }; - nlhpi.cbSize = sizeof(nlhpi); + NETLIBHTTPPROXYINFO nlhpi = {}; nlhpi.szHttpGetUrl = NULL; nlhpi.szHttpPostUrl = "messenger.hotmail.com"; nlhpi.flags = NLHPIF_HTTP11; nlhpi.combinePackets = MSN_PACKETS_COMBINE; - return CallService(MS_NETLIB_SETHTTPPROXYINFO, (WPARAM)hConn, (LPARAM)&nlhpi); + return Netlib_SetHttpProxyInfo(hConn, &nlhpi); } //======================================================================================= diff --git a/protocols/MSN/src/msn_misc.cpp b/protocols/MSN/src/msn_misc.cpp index 2f89d21fbe..cc620c1dc1 100644 --- a/protocols/MSN/src/msn_misc.cpp +++ b/protocols/MSN/src/msn_misc.cpp @@ -1396,7 +1396,7 @@ void MSN_MakeDigest(const char* chl, char* dgst) char* GetGlobalIp(void) { - NETLIBIPLIST* ihaddr = (NETLIBIPLIST*)CallService(MS_NETLIB_GETMYIP, 1, 0); + NETLIBIPLIST *ihaddr = Netlib_GetMyIp(true); for (unsigned i = 0; i < ihaddr->cbNum; ++i) if (strchr(ihaddr->szIp[i], ':')) return mir_strdup(ihaddr->szIp[i]); diff --git a/protocols/MSN/src/msn_threads.cpp b/protocols/MSN/src/msn_threads.cpp index de17faa243..c3888ba028 100644 --- a/protocols/MSN/src/msn_threads.cpp +++ b/protocols/MSN/src/msn_threads.cpp @@ -177,7 +177,7 @@ void __cdecl CMsnProto::MSNServerThread(void* arg) } if (usingGateway) - CallService(MS_NETLIB_SETPOLLINGTIMEOUT, WPARAM(info->s), info->mGatewayTimeout); + Netlib_SetPollingTimeout(info->s, info->mGatewayTimeout); debugLogA("Connected with handle=%08X", info->s); @@ -318,8 +318,7 @@ void CMsnProto::MSN_CloseConnections(void) { mir_cslockfull lck(m_csThreads); - NETLIBSELECTEX nls = { 0 }; - nls.cbSize = sizeof(nls); + NETLIBSELECTEX nls = {}; for (int i = 0; i < m_arThreads.getCount(); i++) { ThreadData &T = m_arThreads[i]; @@ -329,7 +328,7 @@ void CMsnProto::MSN_CloseConnections(void) case SERVER_SWITCHBOARD: if (T.s != NULL && !T.sessionClosed && !T.termPending) { nls.hReadConns[0] = T.s; - int res = CallService(MS_NETLIB_SELECTEX, 0, (LPARAM)&nls); + int res = Netlib_SelectEx(&nls); if (res >= 0 || nls.hReadStatus[0] == 0) T.sendTerminate(); } @@ -616,13 +615,12 @@ void ThreadData::applyGatewayData(HANDLE hConn, bool isPoll) proto->debugLogA("applying '%s' to %08X [%08X]", szHttpPostUrl, this, GetCurrentThreadId()); - NETLIBHTTPPROXYINFO nlhpi = { 0 }; - nlhpi.cbSize = sizeof(nlhpi); + NETLIBHTTPPROXYINFO nlhpi = {}; nlhpi.flags = NLHPIF_HTTP11; nlhpi.szHttpGetUrl = NULL; nlhpi.szHttpPostUrl = szHttpPostUrl; nlhpi.combinePackets = 5; - CallService(MS_NETLIB_SETHTTPPROXYINFO, (WPARAM)hConn, (LPARAM)&nlhpi); + Netlib_SetHttpProxyInfo(hConn, &nlhpi); } void ThreadData::getGatewayUrl(char* dest, int destlen, bool isPoll) diff --git a/protocols/MSN/src/msn_ws.cpp b/protocols/MSN/src/msn_ws.cpp index 1c7dcd07e9..c82c660e8f 100644 --- a/protocols/MSN/src/msn_ws.cpp +++ b/protocols/MSN/src/msn_ws.cpp @@ -31,7 +31,7 @@ int ThreadData::send(const char data[], size_t datalen) if (proto->usingGateway && !(mType == SERVER_FILETRANS || mType == SERVER_P2P_DIRECT)) { mGatewayTimeout = 2; - CallService(MS_NETLIB_SETPOLLINGTIMEOUT, WPARAM(s), mGatewayTimeout); + Netlib_SetPollingTimeout(s, mGatewayTimeout); } int rlen = Netlib_Send(s, data, (int)datalen); @@ -113,13 +113,13 @@ int ThreadData::recv(char* data, size_t datalen) { if (!proto->usingGateway) { resetTimeout(); - NETLIBSELECT nls = { 0 }; - nls.cbSize = sizeof(nls); + + NETLIBSELECT nls = {}; nls.dwTimeout = 1000; nls.hReadConns[0] = s; for (;;) { - int ret = CallService(MS_NETLIB_SELECT, 0, (LPARAM)&nls); + int ret = Netlib_Select(&nls); if (ret < 0) { proto->debugLogA("Connection abortively closed, error %d", WSAGetLastError()); return ret; @@ -149,13 +149,13 @@ LBL_RecvAgain: if (sessionClosed || isTimeout()) return 0; if ((mGatewayTimeout += 2) > 20) mGatewayTimeout = 20; - CallService(MS_NETLIB_SETPOLLINGTIMEOUT, WPARAM(s), mGatewayTimeout); + Netlib_SetPollingTimeout(s, mGatewayTimeout); goto LBL_RecvAgain; } else { resetTimeout(); mGatewayTimeout = 1; - CallService(MS_NETLIB_SETPOLLINGTIMEOUT, WPARAM(s), mGatewayTimeout); + Netlib_SetPollingTimeout(s, mGatewayTimeout); } } diff --git a/protocols/Tlen/src/tlen_thread.cpp b/protocols/Tlen/src/tlen_thread.cpp index b6956a3095..d5cd06e298 100644 --- a/protocols/Tlen/src/tlen_thread.cpp +++ b/protocols/Tlen/src/tlen_thread.cpp @@ -1305,14 +1305,13 @@ static void TlenProcessV(XmlNode *node, ThreadData *info) static void __cdecl TlenKeepAliveThread(void *ptr) { - NETLIBSELECT nls = {0}; - TlenProtocol *proto = (TlenProtocol *)ptr; - nls.cbSize = sizeof(NETLIBSELECT); + + NETLIBSELECT nls = {}; nls.dwTimeout = 60000; // 60000 millisecond (1 minute) nls.hExceptConns[0] = proto->threadData->s; for (;;) { - if (CallService(MS_NETLIB_SELECT, 0, (LPARAM) &nls) != 0) + if (Netlib_Select(&nls) != 0) break; if (proto->tlenOptions.sendKeepAlive) TlenSend(proto, " \t "); diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 4e95863c9f..6a1827cab6 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -367,3 +367,13 @@ Netlib_GetMorePackets @367 Netlib_FreeHttpRequest @368 Netlib_AddressToString @369 Netlib_StringToAddress @370 +Netlib_Select @371 +Netlib_SelectEx @372 +Netlib_SendHttpRequest @373 +Netlib_SetStickyHeaders @374 +Netlib_SetPollingTimeout @375 +Netlib_GetSocket @376 +Netlib_StartSsl @377 +Netlib_GetConnectionInfo @378 +Netlib_GetMyIp @379 +Netlib_SetHttpProxyInfo @380 diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index b274d440b7..5d65d1173e 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -367,3 +367,13 @@ Netlib_GetMorePackets @367 Netlib_FreeHttpRequest @368 Netlib_AddressToString @369 Netlib_StringToAddress @370 +Netlib_Select @371 +Netlib_SelectEx @372 +Netlib_SendHttpRequest @373 +Netlib_SetStickyHeaders @374 +Netlib_SetPollingTimeout @375 +Netlib_GetSocket @376 +Netlib_StartSsl @377 +Netlib_GetConnectionInfo @378 +Netlib_GetMyIp @379 +Netlib_SetHttpProxyInfo @380 diff --git a/src/mir_app/src/netlib.cpp b/src/mir_app/src/netlib.cpp index cecc32cb5b..fcde4a4056 100644 --- a/src/mir_app/src/netlib.cpp +++ b/src/mir_app/src/netlib.cpp @@ -123,7 +123,7 @@ static INT_PTR GetNetlibUserSettingInt(const char *szUserModule, const char *szS return dbv.dVal; } -static char *GetNetlibUserSettingString(const char *szUserModule, const char *szSetting) +static char* GetNetlibUserSettingString(const char *szUserModule, const char *szSetting) { char *szRet = db_get_sa(NULL, szUserModule, szSetting); if (szRet == NULL) @@ -316,21 +316,21 @@ MIR_APP_DLL(int) Netlib_CloseHandle(HANDLE hNetlib) ///////////////////////////////////////////////////////////////////////////////////////// -static INT_PTR NetlibGetSocket(WPARAM wParam, LPARAM) +MIR_APP_DLL(UINT_PTR) Netlib_GetSocket(HANDLE hConnection) { SOCKET s; - if (wParam == 0) { + if (hConnection == 0) { s = INVALID_SOCKET; SetLastError(ERROR_INVALID_PARAMETER); } else { WaitForSingleObject(hConnectionHeaderMutex, INFINITE); - switch (GetNetlibHandleType((void*)wParam)) { + switch (GetNetlibHandleType(hConnection)) { case NLH_CONNECTION: - s = ((NetlibConnection*)wParam)->s; + s = ((NetlibConnection*)hConnection)->s; break; case NLH_BOUNDPORT: - s = ((NetlibBoundPort*)wParam)->s; + s = ((NetlibBoundPort*)hConnection)->s; break; default: s = INVALID_SOCKET; @@ -344,17 +344,6 @@ static INT_PTR NetlibGetSocket(WPARAM wParam, LPARAM) ///////////////////////////////////////////////////////////////////////////////////////// -INT_PTR NetlibGetConnectionInfoSrv(WPARAM wParam, LPARAM lParam) -{ - NetlibGetConnectionInfo((NetlibConnection*)wParam, (NETLIBCONNINFO*)lParam); - return 0; -} - -INT_PTR NetlibGetMyIp(WPARAM wParam, LPARAM) -{ - return (INT_PTR)GetMyIp((unsigned)wParam); -} - MIR_APP_DLL(HNETLIBUSER) Netlib_GetConnNlu(HANDLE hConn) { if (GetNetlibHandleType(hConn) != NLH_CONNECTION) @@ -472,16 +461,6 @@ int LoadNetlibModule(void) hConnectionOpenMutex = connectionTimeout ? CreateMutex(NULL, FALSE, NULL) : NULL; g_LastConnectionTick = GetTickCount(); - CreateServiceFunction(MS_NETLIB_SETHTTPPROXYINFO, NetlibHttpGatewaySetInfo); - CreateServiceFunction(MS_NETLIB_SETSTICKYHEADERS, NetlibHttpSetSticky); - CreateServiceFunction(MS_NETLIB_GETSOCKET, NetlibGetSocket); - CreateServiceFunction(MS_NETLIB_SELECT, NetlibSelect); - CreateServiceFunction(MS_NETLIB_SELECTEX, NetlibSelectEx); - CreateServiceFunction(MS_NETLIB_SETPOLLINGTIMEOUT, NetlibHttpSetPollingTimeout); - CreateServiceFunction(MS_NETLIB_STARTSSL, NetlibStartSsl); - CreateServiceFunction(MS_NETLIB_GETCONNECTIONINFO, NetlibGetConnectionInfoSrv); - CreateServiceFunction(MS_NETLIB_GETMYIP, NetlibGetMyIp); - hRecvEvent = CreateHookableEvent(ME_NETLIB_FASTRECV); hSendEvent = CreateHookableEvent(ME_NETLIB_FASTSEND); diff --git a/src/mir_app/src/netlib.h b/src/mir_app/src/netlib.h index 28c1b549d0..7bb9d08c38 100644 --- a/src/mir_app/src/netlib.h +++ b/src/mir_app/src/netlib.h @@ -225,10 +225,6 @@ int NetlibHttpGatewayRecv(NetlibConnection *nlc, char *buf, int len, int flags); int NetlibHttpGatewayPost(NetlibConnection *nlc, const char *buf, int len, int flags); void HttpGatewayRemovePacket(NetlibConnection *nlc, int pck); -INT_PTR NetlibHttpGatewaySetInfo(WPARAM wParam, LPARAM lParam); -INT_PTR NetlibHttpSetPollingTimeout(WPARAM wParam, LPARAM lParam); -INT_PTR NetlibHttpSetSticky(WPARAM wParam, LPARAM lParam); - // netliblog.c void NetlibLogShowOptions(void); void NetlibDumpData(NetlibConnection *nlc, PBYTE buf, int len, int sent, int flags); @@ -241,7 +237,6 @@ int WaitUntilReadable(SOCKET s, DWORD dwTimeout, bool check = false); int WaitUntilWritable(SOCKET s, DWORD dwTimeout); bool NetlibDoConnect(NetlibConnection *nlc); bool NetlibReconnect(NetlibConnection *nlc); -INT_PTR NetlibStartSsl(WPARAM wParam, LPARAM lParam); // netlibopts.c int NetlibOptInitialise(WPARAM wParam, LPARAM lParam); @@ -252,15 +247,8 @@ void NetlibSaveUserSettingsStruct(const char *szSettingsModule, const NETLIBUSER #define NL_SELECT_WRITE 0x0002 #define NL_SELECT_ALL (NL_SELECT_READ+NL_SELECT_WRITE) -INT_PTR NetlibSelect(WPARAM wParam, LPARAM lParam); -INT_PTR NetlibSelectEx(WPARAM wParam, LPARAM lParam); - -void NetlibGetConnectionInfo(NetlibConnection* nlc, NETLIBCONNINFO *connInfo); -NETLIBIPLIST* GetMyIp(unsigned flags); - // netlibupnp.c -bool NetlibUPnPAddPortMapping(WORD intport, char *proto, - WORD *extport, DWORD *extip, bool search); +bool NetlibUPnPAddPortMapping(WORD intport, char *proto, WORD *extport, DWORD *extip, bool search); void NetlibUPnPDeletePortMapping(WORD extport, char* proto); void NetlibUPnPCleanup(void*); void NetlibUPnPInit(void); diff --git a/src/mir_app/src/netlibhttpproxy.cpp b/src/mir_app/src/netlibhttpproxy.cpp index f1535da21a..445193f1bd 100644 --- a/src/mir_app/src/netlibhttpproxy.cpp +++ b/src/mir_app/src/netlibhttpproxy.cpp @@ -243,6 +243,8 @@ int NetlibHttpGatewayPost(NetlibConnection *nlc, const char *buf, int len, int f return len; } +///////////////////////////////////////////////////////////////////////////////////////// + #define NETLIBHTTP_RETRYCOUNT 3 #define NETLIBHTTP_RETRYTIMEOUT 2000 @@ -353,6 +355,8 @@ int NetlibHttpGatewayRecv(NetlibConnection *nlc, char *buf, int len, int flags) return SOCKET_ERROR; } +///////////////////////////////////////////////////////////////////////////////////////// + int NetlibInitHttpConnection(NetlibConnection *nlc, NetlibUser *nlu, NETLIBOPENCONNECTION *nloc) { NETLIBHTTPREQUEST *nlhrReply = NULL; @@ -398,14 +402,12 @@ int NetlibInitHttpConnection(NetlibConnection *nlc, NetlibUser *nlu, NETLIBOPENC return 1; } -INT_PTR NetlibHttpGatewaySetInfo(WPARAM wParam, LPARAM lParam) -{ - NETLIBHTTPPROXYINFO *nlhpi = (NETLIBHTTPPROXYINFO*)lParam; - NetlibConnection *nlc = (NetlibConnection*)wParam; +///////////////////////////////////////////////////////////////////////////////////////// - if (GetNetlibHandleType(nlc) != NLH_CONNECTION || nlhpi == NULL || - nlhpi->cbSize < (sizeof(NETLIBHTTPPROXYINFO) - sizeof(int)) || - nlhpi->szHttpPostUrl == NULL) { +MIR_APP_DLL(int) Netlib_SetHttpProxyInfo(HANDLE hConnection, const NETLIBHTTPPROXYINFO *nlhpi) +{ + NetlibConnection *nlc = (NetlibConnection*)hConnection; + if (GetNetlibHandleType(nlc) != NLH_CONNECTION || nlhpi == NULL || nlhpi->szHttpPostUrl == NULL) { SetLastError(ERROR_INVALID_PARAMETER); return 0; } @@ -414,7 +416,7 @@ INT_PTR NetlibHttpGatewaySetInfo(WPARAM wParam, LPARAM lParam) mir_free(nlc->nlhpi.szHttpPostUrl); nlc->nlhpi.combinePackets = 1; - memcpy(&nlc->nlhpi, nlhpi, min(nlhpi->cbSize, sizeof(*nlhpi))); + memcpy(&nlc->nlhpi, nlhpi, sizeof(*nlhpi)); if (nlc->nlhpi.combinePackets == 0) nlc->nlhpi.combinePackets = 1; @@ -423,23 +425,26 @@ INT_PTR NetlibHttpGatewaySetInfo(WPARAM wParam, LPARAM lParam) return 1; } -INT_PTR NetlibHttpSetSticky(WPARAM wParam, LPARAM lParam) +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(int) Netlib_SetStickyHeaders(HNETLIBUSER nlu, const char *szHeaders) { - NetlibUser *nu = (NetlibUser*)wParam; - if (GetNetlibHandleType(nu) != NLH_USER) + if (GetNetlibHandleType(nlu) != NLH_USER) return ERROR_INVALID_PARAMETER; - replaceStr(nu->szStickyHeaders, (char*)lParam); // pointer is ours + replaceStr(nlu->szStickyHeaders, szHeaders); // pointer is ours return 0; } -INT_PTR NetlibHttpSetPollingTimeout(WPARAM wParam, LPARAM lParam) +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(int) Netlib_SetPollingTimeout(HANDLE hConnection, int iTimeout) { - NetlibConnection *nlc = (NetlibConnection*)wParam; + NetlibConnection *nlc = (NetlibConnection*)hConnection; if (GetNetlibHandleType(nlc) != NLH_CONNECTION) return -1; int oldTimeout = nlc->pollingTimeout; - nlc->pollingTimeout = lParam; + nlc->pollingTimeout = iTimeout; return oldTimeout; } diff --git a/src/mir_app/src/netlibopenconn.cpp b/src/mir_app/src/netlibopenconn.cpp index a044afba46..9d504b66ad 100644 --- a/src/mir_app/src/netlibopenconn.cpp +++ b/src/mir_app/src/netlibopenconn.cpp @@ -771,7 +771,7 @@ bool NetlibDoConnect(NetlibConnection *nlc) Netlib_Logf(nlu, "(%d) Connected to %s:%d", nlc->s, nloc->szHost, nloc->wPort); if (NLOCF_SSL & nloc->flags) - return NetlibStartSsl((WPARAM)nlc, 0) != 0; + return Netlib_StartSsl(nlc, 0) != 0; return true; } @@ -851,14 +851,14 @@ MIR_APP_DLL(HANDLE) Netlib_OpenConnection(NetlibUser *nlu, const NETLIBOPENCONNE return nlc; } -INT_PTR NetlibStartSsl(WPARAM wParam, LPARAM lParam) +MIR_APP_DLL(int) Netlib_StartSsl(HANDLE hConnection, const char *szHost) { - NetlibConnection *nlc = (NetlibConnection*)wParam; + NetlibConnection *nlc = (NetlibConnection*)hConnection; if (nlc == NULL) return 0; - NETLIBSSL *sp = (NETLIBSSL*)lParam; - const char *szHost = sp ? sp->host : nlc->nloc.szHost; + if (szHost == NULL) + szHost = nlc->nloc.szHost; Netlib_Logf(nlc->nlu, "(%d %s) Starting SSL negotiation", nlc->s, szHost); nlc->hSsl = sslApi.connect(nlc->s, szHost, nlc->nlu->settings.validateSSL); diff --git a/src/mir_app/src/netlibsock.cpp b/src/mir_app/src/netlibsock.cpp index e63ef33ef1..a920f7cd93 100644 --- a/src/mir_app/src/netlibsock.cpp +++ b/src/mir_app/src/netlibsock.cpp @@ -27,6 +27,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern HANDLE hConnectionHeaderMutex, hSendEvent, hRecvEvent; +///////////////////////////////////////////////////////////////////////////////////////// + MIR_APP_DLL(int) Netlib_Send(HANDLE hConn, const char *buf, int len, int flags) { NetlibConnection *nlc = (NetlibConnection*)hConn; @@ -56,6 +58,8 @@ MIR_APP_DLL(int) Netlib_Send(HANDLE hConn, const char *buf, int len, int flags) return result; } +///////////////////////////////////////////////////////////////////////////////////////// + MIR_APP_DLL(int) Netlib_Recv(HANDLE hConn, char *buf, int len, int flags) { NetlibConnection *nlc = (NetlibConnection*)hConn; @@ -89,7 +93,9 @@ MIR_APP_DLL(int) Netlib_Recv(HANDLE hConn, char *buf, int len, int flags) return recvResult; } -static int ConnectionListToSocketList(HANDLE *hConns, fd_set *fd, int& pending) +///////////////////////////////////////////////////////////////////////////////////////// + +static int ConnectionListToSocketList(const HANDLE *hConns, fd_set *fd, int& pending) { FD_ZERO(fd); for (int i = 0; hConns[i] && hConns[i] != INVALID_HANDLE_VALUE && i < FD_SETSIZE; i++) { @@ -105,10 +111,9 @@ static int ConnectionListToSocketList(HANDLE *hConns, fd_set *fd, int& pending) return 1; } -INT_PTR NetlibSelect(WPARAM, LPARAM lParam) +MIR_APP_DLL(int) Netlib_Select(NETLIBSELECT *nls) { - NETLIBSELECT *nls = (NETLIBSELECT*)lParam; - if (nls == NULL || nls->cbSize != sizeof(NETLIBSELECT)) { + if (nls == NULL) { SetLastError(ERROR_INVALID_PARAMETER); return SOCKET_ERROR; } @@ -133,10 +138,9 @@ INT_PTR NetlibSelect(WPARAM, LPARAM lParam) return select(0, &readfd, &writefd, &exceptfd, nls->dwTimeout == INFINITE ? NULL : &tv); } -INT_PTR NetlibSelectEx(WPARAM, LPARAM lParam) +MIR_APP_DLL(int) Netlib_SelectEx(NETLIBSELECTEX *nls) { - NETLIBSELECTEX *nls = (NETLIBSELECTEX*)lParam; - if (nls == NULL || nls->cbSize != sizeof(NETLIBSELECTEX)) { + if (nls == NULL) { SetLastError(ERROR_INVALID_PARAMETER); return SOCKET_ERROR; } @@ -190,6 +194,8 @@ INT_PTR NetlibSelectEx(WPARAM, LPARAM lParam) return rc; } +///////////////////////////////////////////////////////////////////////////////////////// + MIR_APP_DLL(bool) Netlib_StringToAddress(const char *str, SOCKADDR_INET_M *addr) { if (!str) return false; @@ -216,9 +222,13 @@ MIR_APP_DLL(char*) Netlib_AddressToString(sockaddr_in *addr) return NULL; } -void NetlibGetConnectionInfo(NetlibConnection *nlc, NETLIBCONNINFO *connInfo) +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(int) Netlib_GetConnectionInfo(HANDLE hConnection, NETLIBCONNINFO *connInfo) { - if (!nlc || !connInfo || connInfo->cbSize < sizeof(NETLIBCONNINFO)) return; + NetlibConnection *nlc = (NetlibConnection*)hConnection; + if (!nlc || !connInfo) + return 1; sockaddr_in sin = { 0 }; int len = sizeof(sin); @@ -227,15 +237,18 @@ void NetlibGetConnectionInfo(NetlibConnection *nlc, NETLIBCONNINFO *connInfo) connInfo->dwIpv4 = sin.sin_family == AF_INET ? htonl(sin.sin_addr.s_addr) : 0; strncpy_s(connInfo->szIpPort, ptrA(Netlib_AddressToString(&sin)), _TRUNCATE); } + return 0; } +///////////////////////////////////////////////////////////////////////////////////////// + inline bool IsAddrGlobal(const IN6_ADDR *a) { unsigned char High = a->s6_bytes[0] & 0xf0; return High != 0 && High != 0xf0; } -static NETLIBIPLIST* GetMyIpv6(unsigned flags) +MIR_APP_DLL(NETLIBIPLIST*) Netlib_GetMyIp(bool bGlobalOnly) { addrinfo *air = NULL, *ai, hints = { 0 }; const char *szMyHost = ""; @@ -249,7 +262,7 @@ static NETLIBIPLIST* GetMyIpv6(unsigned flags) unsigned n = 0; for (ai = air; ai; ai = ai->ai_next) { SOCKADDR_INET_M *iaddr = (SOCKADDR_INET_M*)ai->ai_addr; - if (ai->ai_family == AF_INET || (ai->ai_family == AF_INET6 && (!(flags & 1) || IsAddrGlobal(&iaddr->Ipv6.sin6_addr)))) + if (ai->ai_family == AF_INET || (ai->ai_family == AF_INET6 && (!bGlobalOnly || IsAddrGlobal(&iaddr->Ipv6.sin6_addr)))) ++n; } @@ -259,7 +272,7 @@ static NETLIBIPLIST* GetMyIpv6(unsigned flags) unsigned i = 0; for (ai = air; ai; ai = ai->ai_next) { sockaddr_in6 *iaddr = (sockaddr_in6*)ai->ai_addr; - if (ai->ai_family == AF_INET || (ai->ai_family == AF_INET6 && (!(flags & 1) || IsAddrGlobal(&iaddr->sin6_addr)))) { + if (ai->ai_family == AF_INET || (ai->ai_family == AF_INET6 && (!bGlobalOnly || IsAddrGlobal(&iaddr->sin6_addr)))) { char *szIp = Netlib_AddressToString((sockaddr_in*)iaddr); if (szIp) strncpy_s(addr->szIp[i++], szIp, _TRUNCATE); @@ -289,8 +302,3 @@ static NETLIBIPLIST* GetMyIpv4(void) return addr; } - -NETLIBIPLIST* GetMyIp(unsigned flags) -{ - return GetMyIpv6(flags); -} -- cgit v1.2.3