summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-01-13 00:01:59 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-01-13 00:01:59 +0300
commite145db68fb5b7d0682a4b2be0174cebfe47dd74e (patch)
treec8f9edc907876d236eb16bc8ca8b592accb9846f
parent3cb3883908e3168e5f955be3143771721614307a (diff)
a bit less netlib services
-rw-r--r--bin10/lib/mir_app.libbin92634 -> 95274 bytes
-rw-r--r--bin10/lib/mir_app64.libbin88296 -> 90770 bytes
-rw-r--r--bin12/lib/mir_app.libbin92634 -> 95274 bytes
-rw-r--r--bin12/lib/mir_app64.libbin88296 -> 90770 bytes
-rw-r--r--bin14/lib/mir_app.libbin92634 -> 95274 bytes
-rw-r--r--bin14/lib/mir_app64.libbin88296 -> 90770 bytes
-rw-r--r--include/delphi/m_netlib.inc348
-rw-r--r--include/m_netlib.h136
-rw-r--r--plugins/HTTPServer/src/main.cpp9
-rw-r--r--plugins/Ping/src/utils.cpp2
-rw-r--r--plugins/Utils.pas/mirutils.pas2
-rwxr-xr-xplugins/Watrack_MPD/src/main.cpp29
-rw-r--r--plugins/Weather/src/weather.cpp2
-rw-r--r--plugins/YAMN/src/proto/netlib.cpp5
-rwxr-xr-xprotocols/AimOscar/src/connection.cpp55
-rw-r--r--protocols/AimOscar/src/defines.h2
-rw-r--r--protocols/AimOscar/src/direct_connect.cpp5
-rw-r--r--protocols/AimOscar/src/file.cpp8
-rwxr-xr-xprotocols/AimOscar/src/proto.h2
-rw-r--r--protocols/AimOscar/src/proxy.cpp7
-rw-r--r--protocols/Discord/src/gateway.cpp2
-rw-r--r--protocols/Discord/src/proto.h5
-rw-r--r--protocols/Gadu-Gadu/src/core.cpp2
-rw-r--r--protocols/IRCG/src/irclib.cpp35
-rw-r--r--protocols/IRCG/src/stdafx.h4
-rw-r--r--protocols/IcqOscarJ/src/chan_04close.cpp2
-rw-r--r--protocols/IcqOscarJ/src/icq_avatar.cpp8
-rw-r--r--protocols/IcqOscarJ/src/icq_direct.cpp9
-rw-r--r--protocols/IcqOscarJ/src/icq_server.cpp5
-rw-r--r--protocols/IcqOscarJ/src/init.cpp2
-rw-r--r--protocols/IcqOscarJ/src/oscar_filetransfer.cpp9
-rw-r--r--protocols/IcqOscarJ/src/utilities.cpp9
-rw-r--r--protocols/JabberG/src/jabber_byte.cpp17
-rw-r--r--protocols/JabberG/src/jabber_file.cpp15
-rw-r--r--protocols/JabberG/src/jabber_util.cpp2
-rw-r--r--protocols/JabberG/src/jabber_ws.cpp4
-rw-r--r--protocols/MRA/src/MraAvatars.cpp10
-rw-r--r--protocols/MRA/src/MraFilesQueue.cpp7
-rw-r--r--protocols/MRA/src/MraMRIMProxy.cpp2
-rw-r--r--protocols/MRA/src/Mra_functions.cpp4
-rw-r--r--protocols/MRA/src/Mra_proto.cpp6
-rw-r--r--protocols/MRA/src/stdafx.h2
-rw-r--r--protocols/MSN/src/msn_p2p.cpp2
-rw-r--r--protocols/MSN/src/msn_proto.cpp12
-rw-r--r--protocols/MSN/src/msn_threads.cpp6
-rw-r--r--protocols/Sametime/src/sametime_session.cpp10
-rw-r--r--protocols/Tlen/src/stdafx.h2
-rw-r--r--protocols/Tlen/src/tlen_file.cpp4
-rw-r--r--protocols/Tlen/src/tlen_p2p_old.cpp9
-rw-r--r--protocols/Tlen/src/tlen_voice.cpp7
-rw-r--r--protocols/Tlen/src/tlen_ws.cpp8
-rw-r--r--protocols/Tox/src/tox_core.cpp4
-rw-r--r--protocols/WhatsApp/src/WASocketConnection.cpp2
-rw-r--r--src/mir_app/src/mir_app.def11
-rw-r--r--src/mir_app/src/mir_app64.def11
-rw-r--r--src/mir_app/src/netlib.cpp47
-rw-r--r--src/mir_app/src/netlib.h23
-rw-r--r--src/mir_app/src/netlibbind.cpp24
-rw-r--r--src/mir_app/src/netlibhttp.cpp11
-rw-r--r--src/mir_app/src/netlibhttpproxy.cpp2
-rw-r--r--src/mir_app/src/netlibopenconn.cpp19
-rw-r--r--src/mir_app/src/netlibopts.cpp16
-rw-r--r--src/mir_app/src/netlibpktrecver.cpp30
-rw-r--r--src/mir_app/src/netlibsock.cpp29
64 files changed, 319 insertions, 743 deletions
diff --git a/bin10/lib/mir_app.lib b/bin10/lib/mir_app.lib
index 83b463beba..99e0c072da 100644
--- a/bin10/lib/mir_app.lib
+++ b/bin10/lib/mir_app.lib
Binary files differ
diff --git a/bin10/lib/mir_app64.lib b/bin10/lib/mir_app64.lib
index 9adefe94ee..53d8c55b55 100644
--- a/bin10/lib/mir_app64.lib
+++ b/bin10/lib/mir_app64.lib
Binary files differ
diff --git a/bin12/lib/mir_app.lib b/bin12/lib/mir_app.lib
index 83b463beba..99e0c072da 100644
--- a/bin12/lib/mir_app.lib
+++ b/bin12/lib/mir_app.lib
Binary files differ
diff --git a/bin12/lib/mir_app64.lib b/bin12/lib/mir_app64.lib
index 9adefe94ee..53d8c55b55 100644
--- a/bin12/lib/mir_app64.lib
+++ b/bin12/lib/mir_app64.lib
Binary files differ
diff --git a/bin14/lib/mir_app.lib b/bin14/lib/mir_app.lib
index 83b463beba..99e0c072da 100644
--- a/bin14/lib/mir_app.lib
+++ b/bin14/lib/mir_app.lib
Binary files differ
diff --git a/bin14/lib/mir_app64.lib b/bin14/lib/mir_app64.lib
index 9adefe94ee..53d8c55b55 100644
--- a/bin14/lib/mir_app64.lib
+++ b/bin14/lib/mir_app64.lib
Binary files differ
diff --git a/include/delphi/m_netlib.inc b/include/delphi/m_netlib.inc
index 3bfe107306..ab60822163 100644
--- a/include/delphi/m_netlib.inc
+++ b/include/delphi/m_netlib.inc
@@ -219,24 +219,6 @@ type
validateSSL :int;
end;
- TNetlibNewConnectionProc = procedure(hNewConnection:THANDLE; dwRemoveIP:dword); cdecl;
- TNetlibNewConnectionProc_V2 = procedure(hNewConnection:THANDLE; dwRemoveIP:dword; pExtra:pointer); cdecl;
-
- PNETLIBBIND = ^TNETLIBBIND;
- TNETLIBBIND = record
- cbSize:int;
- // new code should use V2
- pfnNewConnection:TNETLIBNEWCONNECTIONPROC;
- // or pfnNewConnectionV2:NETLIBNEWCONNECTIONPROC_V2;
- //function to call when there's a new connection. Params are: the
- //new connection, IP of remote machine (host byte order)
- dwInternalIP:dword; //set on return, host byte order
- wPort :word; //set on return, host byte order
- pExtra :^pointer; //argument is sent to callback, added during 0.3.4+
- dwExternalIP:dword; //set on return, host byte order
- wExPort :word; //set on return, host byte order
- end;
-
type
PNETLIBHTTPPROXYINFO = ^TNETLIBHTTPPROXYINFO;
TNETLIBHTTPPROXYINFO = record
@@ -249,49 +231,6 @@ type
combinePackets : int; // MIRANDA_VER >= 0x0900
end;
-type
- PNETLIBBUFFER = ^TNETLIBBUFFER;
- TNETLIBBUFFER = record
- buf : PAnsiChar;
- len : int;
- flags: int; // see MSG_* constants above
- end;
-
- PNETLIBSELECT = ^TNETLIBSELECT;
- TNETLIBSELECT = record
- cbSize : int;
- dwTimeout : dword; // in milliseconds, INFINITE is acceptable
- hReadConns : array [0..FD_SETSIZE] of THANDLE;
- hWriteConns : array [0..FD_SETSIZE] of THANDLE;
- hExceptConns: array [0..FD_SETSIZE] of THANDLE;
- end;
-
- PNETLIBSELECTEX = ^TNETLIBSELECTEX;
- TNETLIBSELECTEX = record
- cbSize : int;
- dwTimeout : dword; // in milliseconds, INFINITE is acceptable
- hReadConns : array [0..FD_SETSIZE] of THANDLE;
- hWriteConns : array [0..FD_SETSIZE] of THANDLE;
- hExceptConns: array [0..FD_SETSIZE] of THANDLE;
- // Added in v0.3.3+
- hReadStatus : array [0..FD_SETSIZE] of bool; // out, [in, expected to be FALSE]
- hWriteStatus : array [0..FD_SETSIZE] of bool; // out, [in, expected to be FALSE]
- hExceptStatus: array [0..FD_SETSIZE] of bool; // out, [in, expected to be FALSE]
- end;
-
- PNETLIBPACKETRECVER = ^TNETLIBPACKETRECVER;
- TNETLIBPACKETRECVER = record
- cbSize : int;
- dwTimeout : dword; // infinite is allowed -- initialise before use
- bytesUsed : int; // this many bytes are removed from the start of the
- // buffer, set to 0 on return -- initialise before use
- bytesAvailable: int; // equal the returnd value by service, unless the
- // return value is 0 (connection closed)
- bufferSize : int; // same as the parameter given to
- // MS_NETLIB_CREATEPACKETRECVER: wParam
- buffer : PByte; // contains the read data
- end;
-
{
Affects: Initialises the netlib for a set of connections, see notes
Returns: Returns a handle for future netlib calls, NULL on failure.
@@ -323,8 +262,7 @@ function Netlib_RegisterUser(pInfo:PNETLIBUSER) : THANDLE; stdcall; external App
Errors : ERROR_INVALID_PARAMETER
}
-const
- MS_NETLIB_GETUSERSETTINGS:PAnsiChar = 'Netlib/GetUserSettings';
+function Netlib_GetUserSettings(nlu:THANDLE; nlus:PNETLIBUSERSETTINGS) : int; stdcall; external AppDll;
{
Affects: Closes a handle, see notes
@@ -337,136 +275,6 @@ const
function Netlib_CloseHandle(pHandle:THANDLE) : int; stdcall; external AppDll;
{
- wParam : HANDLE
- lParam : Pointer to a initialised TNETLIBBIND
- Affects: Open a port and wait for connections on it -- see notes
- Returns: Returns a handle on success, NULL(0) on failure
- Notes : this function does the equivalent of socket(), bind(), getsockname(),
- listen(), accept() -- internally this function creates a new thread
- which waits around in accept() for new connections.
- When one is received, TNETLIBBIND.pfnNewConnection is called,
- from the context of the NEW thread and then it
- returns to waiting for connections.
- -
- Close the returned handle to end the thread and close the port.
- -
- Errors : ERROR_INVALID_PARAMETER, any returned by socket(), bind(), listen()
- getsockname()
- }
-
-const
- MS_NETLIB_BINDPORT:PAnsiChar = 'Netlib/BindPort';
-
- {
- wParam : HANDLE
- lParam : Pointer to an initalised TNETLIBOPENCONNECTION structure
- Affects: Opens a connection -- see notes
- Returns: Returns a Handle to a new connection on success, NULL(0) on failure
- Notes : internally this service is the equivalent of socket(), gethostbyname(),
- connect()
- -
- If NLOCF_HTTP is set and HANDLE is configured for HTTP(S) proxy
- then this function will connect() to that proxy server ONLY,
- without performing any initialisation conversation.
- -
- If HANDLE is configured for an HTTP proxy and does not support
- HTTP gateways and you try to open a connection without NLOCF_HTTP
- then this service will first attempt to open an HTTPS connection,
- if that fails, it will try a direct connection, if *that* fails
- then it will return failure with the error
- from connect() during the connection attempt
- Errors : ERROR_INVALID_PARAMETER, any returned by socket(), gethostbyname(),
- connect(), MS_NETLIB_SEND, MS_NETLIB_RECV, select()
- -
- ERROR_TIMEOUT (during proxy communication)
- ERROR_BAD_FORMAT (very invalid proxy reply)
- ERROR_ACCESS_DENIED (by proxy)
- ERROR_CONNECTION_UNAVAIL (socks proxy can't connect to identd)
- ERROR_INVALID_ACCESS (proxy refused identd auth)
- ERROR_INVALID_DATA (proxy returned invalid code)
- ERROR_INVALID_ID_AUTHORITY (proxy requires use of auth method that's not supported)
- ERROR_GEN_FAILURE (socks5/https general failure)
- ERROR_CALL_NOT_IMPLEMENTED (socks5 command not supported)
- ERROR_INVALID_ADDRESS (socks5 address type not supported)
- -
- HTTP: anything from TNETLIBUSER.pfnHttpGatewayInit, TNETLIBUSER.pfnHttpGatewayBegin,
- MS_NETLIB_SENDHTTPREQUEST or MS_NETLIB_RECVHTTPHEADERS
- }
- MS_NETLIB_OPENCONNECTION:PAnsiChar = 'Netlib/OpenConnection';
-
- {
- wParam : HANDLE
- lParam : Pointer to an initialised NETLIBHTTPPROXYINFO structure
- Affects: Sets the required information for an HTTP proxy connection -- see notes
- Returns: [non zero] on success, NULL(0) on failure
- Notes : This service is designed to be called from
- within TNETLIBUSER.pfnHttpGatewayInit (see notes in C header under
- MS_NETLIB_REGISTERUSER)
- Errors : ERROR_INVALID_PARAMETER
- }
- MS_NETLIB_SETHTTPPROXYINFO:PAnsiChar = 'Netlib/SetHttpProxyInfo';
-
- {
- wParam : HANDLE
- lParam : 0
- Affects: Get's the SOCKET associated with a handle -- see notes
- Returns: the SOCKET on success, INVALID_SOCKET on failure
- Notes : The Netlib handle passed to this service should only be passed
- if they were returned with MS_NETLIB_OPENCONNECTION or MS_NETLIB_BINDPORT
- -
- Be careful how you use this socket because you might be connected via an
- HTTP proxy, in which case calling send/recv() will break things
- -
- Errors : ERROR_INVALID_PARAMETER
- }
- MS_NETLIB_GETSOCKET:PAnsiChar = 'Netlib/GetSocket';
-
-{
- Converts string representation of IP and port into numerical SOCKADDR_INET
- IPv4 could supplied in formats address:port or address
- IPv6 could supplied in formats [address]:port or [address]
- wParam=(WPARAM)(char*) string to convert
- lParam=(LPARAM)(SOCKADDR_INET*) numeric IP address structure
- Returns 0 on success
-}
- MS_NETLIB_STRINGTOADDRESS:PAnsiChar = 'Netlib/StringToAddress';
-
-{
- Converts numerical representation of IP in SOCKADDR_INET into string representation with IP and port
- IPv4 will be supplied in formats address:port or address
- IPv6 will be supplied in formats [address]:port or [address]
- wParam=(WPARAM)(int) 0 - lParam - (SOCKADDR_INET*); 1 - lParam - (unsigned) in host byte order
- lParam=(LPARAM)(SOCKADDR_INET*) or (unsigned) numeric IP address structure
- Returns pointer to the string or NULL if not successful
-}
- MS_NETLIB_ADDRESSTOSTRING:PAnsiChar = 'Netlib/AddressToString';
-
-type
- TNETLIBCONNINFO = record
- cbSize :int;
- szIpPort:array [0..63] of AnsiChar;
- dwIpv4 :uint;
- wPort :word;
- end;
-
-const
-{
- 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
-}
- MS_NETLIB_GETCONNECTIONINFO:PAnsiChar = 'Netlib/GetConnectionInfo';
-
-type
- TNETLIBIPLIST = record
- cbNum:uint;
- szIp :array[0..0,0..63] of AnsiChar;
- end;
-
- {
Affect : Free the memory used by a TNETLIBHTTPREQUEST structure, see notes
Returns: [non zero] on success, NULL(0) on failure
Notes : This service should only be used with memory pointers returned
@@ -562,72 +370,6 @@ function Netlib_Send(hConn:THANDLE; pBuf:Pointer; len,flags:int) : int; stdcall;
function Netlib_Recv(hConn:THANDLE; pBuf:Pointer; len,flags:int) : int; stdcall; external AppDll;
{
- wParam : 0
- lParam : Pointer to an initialised TNETLIBSELECT structure
- Affect : Determine the status of one or more connections, see notes
- Returns: The numbe of ready connections, SOCKET_ERROR on failure
- Notes : All handles passed to this service must have been returned
- either by MS_NETLIB_OPENCONNECTION or MS_NETLIB_BINDPORT,
- 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()
- }
-const
- MS_NETLIB_SELECT :PAnsiChar = 'Netlib/Select';
- MS_NETLIB_SELECTEX:PAnsiChar = 'Netlib/SelectEx'; // added in v0.3.3
-
-{
- Shutdown connection
- wParam=(WPARAM)(HANDLE)hConnection
- lParam=(LPARAM)0
- Returns 0
-}
- MS_NETLIB_SHUTDOWN:PAnsiChar = 'Netlib/Shutdown';
-
- {
- wParam : HANDLE
- lParam : maxPacketSize
- Affect : Create a packet receiver, see notes
- Returns: A handle on success, NULL(0) on failure
- Notes : The packet receiver implements the common situation where
- you have a variable length of packets coming thru over a connection
- and you want them split up in order to handle them.
- -
- The major limiation is, that the buffer is created in memory,
- so you can't have arbitrarily large packets
- Errors : ERROR_INVALID_PARAMETER, ERROR_OUTOFMEMORY
- }
- MS_NETLIB_CREATEPACKETRECVER:PAnsiChar = 'Netlib/CreatePacketRecver';
-
- {
- wParam : Handle returned by MS_NETLIB_CREATEPACKETRECVER
- lParam : Pointer to an initialised TNETLIBPACKETRECVER
- Returns: The total number of bytes available in the buffer, NULL(0)
- if the connection was closed or SOCKET_ERROR.
- -
- If TNETLIBPACKETRECVER.bytesUsed is set to zero and the
- buffer is already full up to the maxPacketSize, it is assumed
- that a too large packet has been received, All data in
- the buffer is discarded and receiving has started anew.
- -
- This will probably cause alignment problem so if you think
- that tis iss likely to happen, then you should deal with it
- yourself.
- -
- Closing the packet receiver will not close the associated
- connection but will discard any bytes still in the buffer,
- so if you intend to carry on reading from that connection,
- make sure you have processed the buffer first.
- -
- This service is equivalent of memmove() to remove
- the first bytesUsed from the buffer, select(), if dwTimeOut
- is not INFINITE, then MS_NETLIB_RECV
- Errors : ERROR_INVALID_PARAMETER, ERROR_TIMEOUT, anything from select(),
- MS_NETLIB_RECV
- }
- MS_NETLIB_GETMOREPACKETS:PAnsiChar = 'Netlib/GetMorePackets';
-
- {
Affect : Add a message to the log (if it's running) see notes
Returns: non zeror on success, NULL(0) on failure
Notes : Don't include \r\n or #13#10 it's not needed,
@@ -641,92 +383,4 @@ const
function Netlib_Log(nlu:THANDLE; str:PAnsiChar) : int; stdcall; external AppDll;
function Netlib_LogW(nlu:THANDLE; str:PWideChar) : int; stdcall; external AppDll;
-{
- Makes connection SSL
- wParam=(WPARAM)(HANDLE)hConn
- lParam=0
- Returns 0 on failure 1 on success
-}
-
-const
- MS_NETLIB_STARTSSL:PAnsiChar = 'Netlib/StartSsl';
-
-type
- TNETLIBSSL = record
- cbSize:int;
- host :PAnsiChar; // Expected host name
- flags :int; // Reserved
- end;
-
-const
-/////////////////////////////////////////////////////////////////////////////////////////
-// Security providers (0.6+)
-
- NNR_UNICODE = 1;
-// Inits a required security provider. Right now only NTLM is supported
-// Returns HANDLE = NULL on error or non-null value on success
-// Known providers: Basic, NTLM, Negotiate, Kerberos, GSSAPI - (Kerberos SASL)
- MS_NETLIB_INITSECURITYPROVIDER:PAnsiChar = 'Netlib/InitSecurityProvider';
-
-type
- TNETLIBNTLMINIT2 = record
- cbSize :size_t;
- szProviderName:TChar;
- szPrincipal :TChar;
- flags :uint;
- end;
-
-const
- MS_NETLIB_INITSECURITYPROVIDER2:PAnsiChar = 'Netlib/InitSecurityProvider2';
-
-// Destroys a security provider's handle, provided by Netlib_InitSecurityProvider.
-// Right now only NTLM is supported
- MS_NETLIB_DESTROYSECURITYPROVIDER:PAnsiChar = 'Netlib/DestroySecurityProvider';
-
-// Returns the NTLM response string. The result value should be freed using mir_free
- MS_NETLIB_NTLMCREATERESPONSE:PAnsiChar = 'Netlib/NtlmCreateResponse';
-
-type
- TNETLIBNTLMREQUEST = record
- szChallenge:PAnsiChar;
- userName :PAnsiChar;
- password :PAnsiChar;
-// complete :int; // not present in last versions
- end;
-
-type
- TNETLIBNTLMREQUEST2 = record
- cbSize :size_t;
- szChallenge:PAnsiChar;
- szUserName :TChar;
- szPassword :TChar;
- complete :uint;
- flags :uint;
- end;
-
-const
- MS_NETLIB_NTLMCREATERESPONSE2 = 'Netlib/NtlmCreateResponse2';
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// Netlib hooks (0.8+)
-
-// WARNING: these hooks are being called in the context of the calling thread, without switching
-// to the first thread, like all another events do. The hook procedure should be ready for the
-// multithreaded mode
-//
-// Parameters:
-// wParam: NETLIBNOTIFY* - points to the data being sent/received
-// lParam: NETLIBUSER* - points to the protocol definition
-
-type
- TNETLIBNOTIFY = record
- nlb :PNETLIBBUFFER; // pointer to the request buffer
- result:int; // amount of bytes really sent/received
- end;
-
-const
- ME_NETLIB_FASTRECV :PAnsiChar = 'Netlib/OnRecv'; // being called on every receive
- ME_NETLIB_FASTSEND :PAnsiChar = 'Netlib/OnSend'; // being called on every send
- ME_NETLIB_FASTDUMP :PAnsiChar = 'Netlib/OnDump'; // being called on every dump
-
{$ENDIF}
diff --git a/include/m_netlib.h b/include/m_netlib.h
index 1ab848528c..eb343ce4a1 100644
--- a/include/m_netlib.h
+++ b/include/m_netlib.h
@@ -170,16 +170,6 @@ When you call MS_NETLIB_SEND or MS_NETLIB_RECV from any of these functions, you
should use the MSG_DUMPPROXY flag so that the logging is neat.
*/
-/////////////////////////////////////////////////////////////////////////////////////////
-// Gets the user-configured settings for a netlib user
-// wParam = (WPARAM)(HANDLE)hUser
-// lParam = (LPARAM)(NETLIBUSERSETTINGS*)&nlus
-// Returns nonzero on success, 0 on failure (!! this is different to most of the rest of Miranda, but consistent with netlib)
-// The pointers referred to in the returned struct will remain valid until
-// the hUser handle is closed, or until the user changes the settings in the
-// options page, so it's best not to rely on them for too long.
-// Errors: ERROR_INVALID_PARAMETER
-
#define PROXYTYPE_SOCKS4 1
#define PROXYTYPE_SOCKS5 2
#define PROXYTYPE_HTTP 3
@@ -206,11 +196,20 @@ struct NETLIBUSERSETTINGS
int validateSSL;
};
-#define MS_NETLIB_GETUSERSETTINGS "Netlib/GetUserSettings"
+/////////////////////////////////////////////////////////////////////////////////////////
+// Gets the user-configured settings for a netlib user
+//
+// Returns nonzero on success, 0 on failure (!! this is different to most of the rest of Miranda, but consistent with netlib)
+// The pointers referred to in the returned struct will remain valid until
+// the hUser handle is closed, or until the user changes the settings in the
+// options page, so it's best not to rely on them for too long.
+// Errors: ERROR_INVALID_PARAMETER
+
+EXTERN_C MIR_APP_DLL(int) Netlib_GetUserSettings(HNETLIBUSER nlu, NETLIBUSERSETTINGS *result);
+/////////////////////////////////////////////////////////////////////////////////////////
// Changes the user-configurable settings for a netlib user
-// wParam = (WPARAM)(HANDLE)hUser
-// lParam = (LPARAM)(NETLIBUSERSETTINGS*)&nlus
+//
// Returns nonzero on success, 0 on failure (!! this is different to most of the rest of Miranda, but consistent with netlib)
// This function is only really useful for people that specify NUF_NOOPTIONS
// and want to create their own options.
@@ -218,9 +217,11 @@ struct NETLIBUSERSETTINGS
// zero) that settings is still set for use in the options dialog.
// Errors: ERROR_INVALID_PARAMETER
-#define MS_NETLIB_SETUSERSETTINGS "Netlib/SetUserSettings"
+EXTERN_C MIR_APP_DLL(int) Netlib_SetUserSettings(HNETLIBUSER nlu, const NETLIBUSERSETTINGS *result);
+/////////////////////////////////////////////////////////////////////////////////////////
// Closes a netlib handle
+//
// Returns nonzero on success, 0 on failure (!! this is different to most of the rest of Miranda, but consistent with netlib)
// This function should be called on all handles returned by netlib functions
// once you are done with them. If it's called on a socket-type handle, the
@@ -231,8 +232,7 @@ EXTERN_C MIR_APP_DLL(int) Netlib_CloseHandle(HANDLE h);
/////////////////////////////////////////////////////////////////////////////////////////
// Open a port and wait for connections on it
-// wParam = (WPARAM)(HANDLE)hUser
-// lParam = (LPARAM)(NETLIBBIND*)&nlb
+//
// Returns a HANDLE on success, NULL on failure
// hUser should have been returned by MS_NETLIB_REGISTERUSER
// This function does the equivalent of socket(), bind(), getsockname(),
@@ -261,7 +261,7 @@ EXTERN_C MIR_APP_DLL(int) Netlib_CloseHandle(HANDLE h);
/* pExtra was added during 0.3.4+, prior its just two args, since we use the cdecl convention
it shouldnt matter */
-typedef void (*NETLIBNEWCONNECTIONPROC_V2)(HANDLE hNewConnection, DWORD dwRemoteIP, void * pExtra);
+typedef void (*NETLIBNEWCONNECTIONPROC_V2)(HANDLE hNewConnection, DWORD dwRemoteIP, void *pExtra);
typedef void (*NETLIBNEWCONNECTIONPROC)(HANDLE hNewConnection, DWORD dwRemoteIP);
struct NETLIBBIND
@@ -271,21 +271,21 @@ struct NETLIBBIND
NETLIBNEWCONNECTIONPROC pfnNewConnection;
NETLIBNEWCONNECTIONPROC_V2 pfnNewConnectionV2;
};
- // function to call when there's a new connection. Params are: the
- // new connection, IP of remote machine (host byte order)
+
+ // function to call when there's a new connection. Params are: the
+ // new connection, IP of remote machine (host byte order)
DWORD dwInternalIP; // set on return, host byte order
- WORD wPort; // set on return, host byte order
- void * pExtra; // argument is sent to callback, added during 0.3.4+
+ WORD wPort; // set on return, host byte order
+ void *pExtra; // argument is sent to callback
DWORD dwExternalIP; // set on return, host byte order
- WORD wExPort; // set on return, host byte order
+ WORD wExPort; // set on return, host byte order
};
-#define MS_NETLIB_BINDPORT "Netlib/BindPort"
+EXTERN_C MIR_APP_DLL(HANDLE) Netlib_BindPort(HNETLIBUSER nlu, NETLIBBIND *nlb);
/////////////////////////////////////////////////////////////////////////////////////////
// Open a connection
-// wParam = (WPARAM)(HANDLE)hUser
-// lParam = (LPARAM)(NETLIBOPENCONNECTION*)&nloc
+//
// Returns a HANDLE to the new connection on success, NULL on failure
// hUser must have been returned by MS_NETLIB_REGISTERUSER
// Internally this function is the equivalent of socket(), gethostbyname(),
@@ -320,12 +320,6 @@ struct NETLIBBIND
#define NLOCF_SSL 0x0010 // this connection is SSL
#define NLOCF_HTTPGATEWAY 0x0020 // this connection is HTTP Gateway
-/* Added during 0.4.0+ development!! (2004/11/29) prior to this, connect() blocks til a connection is made or
-a hard timeout is reached, this can be anywhere between 30-60 seconds, and it stops Miranda from unloading whilst
-this is attempted, clearing sucking - so now you can set a timeout of any value, there is still a hard limit which is
-always reached by Windows, If a timeout occurs, or Miranda is exiting then you will get ERROR_TIMEOUT as soon as possible.
-*/
-
struct NETLIBOPENCONNECTION
{
int cbSize;
@@ -338,7 +332,7 @@ struct NETLIBOPENCONNECTION
int (*waitcallback) (unsigned int * timeout);
};
-#define MS_NETLIB_OPENCONNECTION "Netlib/OpenConnection"
+EXTERN_C MIR_APP_DLL(HANDLE) Netlib_OpenConnection(HNETLIBUSER nlu, const NETLIBOPENCONNECTION *nloc);
/////////////////////////////////////////////////////////////////////////////////////////
// Sets the required information for an HTTP proxy connection
@@ -387,32 +381,14 @@ struct NETLIBHTTPPROXYINFO
EXTERN_C MIR_APP_DLL(HNETLIBUSER) Netlib_GetConnNlu(HANDLE hConn);
/////////////////////////////////////////////////////////////////////////////////////////
-// Converts string representation of IP and port into numerical SOCKADDR_INET
-// IPv4 could supplied in formats address:port or address
-// IPv6 could supplied in formats [address]:port or [address]
-// wParam = (WPARAM)(char*) string to convert
-// lParam = (LPARAM)(SOCKADDR_INET*) numeric IP address structure
-// Returns 0 on success
-
-#define MS_NETLIB_STRINGTOADDRESS "Netlib/StringToAddress"
-
-/////////////////////////////////////////////////////////////////////////////////////////
// Converts numerical representation of IP in SOCKADDR_INET into string representation with IP and port
// IPv4 will be supplied in formats address:port or address
// IPv6 will be supplied in formats [address]:port or [address]
-// wParam = (WPARAM)(int)0 - lParam - (sockaddr_gen*); 1 - lParam - (unsigned) in host byte order
-// lParam = (LPARAM)(sockaddr_gen*) or (unsigned) numeric IP address structure
// Returns pointer to the string or NULL if not successful
-#define MS_NETLIB_ADDRESSTOSTRING "Netlib/AddressToString"
-
-struct NETLIBCONNINFO
-{
- int cbSize;
- char szIpPort[64];
- unsigned dwIpv4;
- WORD wPort;
-};
+struct sockaddr_in;
+EXTERN_C MIR_APP_DLL(char*) Netlib_AddressToString(sockaddr_in *addr);
+EXTERN_C MIR_APP_DLL(bool) Netlib_StringToAddress(const char *str, sockaddr_in *addr);
/////////////////////////////////////////////////////////////////////////////////////////
// Get connection Information
@@ -422,26 +398,33 @@ struct NETLIBCONNINFO
// lParam = (LPARAM)(NETLIBCONNINFO*) pointer to the connection information structure to fill
// Returns 0 if successful
-#define MS_NETLIB_GETCONNECTIONINFO "Netlib/GetConnectionInfo"
-
-struct NETLIBIPLIST
+struct NETLIBCONNINFO
{
- unsigned cbNum;
- char szIp[1][64];
+ int cbSize;
+ char szIpPort[64];
+ unsigned dwIpv4;
+ WORD wPort;
};
+#define MS_NETLIB_GETCONNECTIONINFO "Netlib/GetConnectionInfo"
+
/////////////////////////////////////////////////////////////////////////////////////////
// Get connection Information
// wParam = (WPARAM)IP filter 1 - return global only IPv6 address, 0 all IPs
// Returns (INT_PTR)(NETLIBIPLIST*) numeric IP address address array
// the last element of the array is all 0s, 0 if not successful
+struct NETLIBIPLIST
+{
+ unsigned cbNum;
+ char szIp[1][64];
+};
+
#define MS_NETLIB_GETMYIP "Netlib/GetMyIP"
/////////////////////////////////////////////////////////////////////////////////////////
// Send an HTTP request over a connection
-// wParam = (WPARAM)(HANDLE)hConnection
-// lParam = (LPARAM)(NETLIBHTTPREQUEST*)&nlhr
+//
// Returns number of bytes sent on success, SOCKET_ERROR on failure
// hConnection must have been returned by MS_NETLIB_OPENCONNECTION
// Note that if you use NLHRF_SMARTAUTHHEADER and NTLM authentication is in use
@@ -495,7 +478,7 @@ struct NETLIBHTTPREQUEST
int timeout;
};
-#define MS_NETLIB_SENDHTTPREQUEST "Netlib/SendHttpRequest"
+EXTERN_C MIR_APP_DLL(int) Netlib_SendHttpRequest(HANDLE hConnection, NETLIBHTTPREQUEST *pRec);
/////////////////////////////////////////////////////////////////////////////////////////
// Receives HTTP headers
@@ -675,21 +658,12 @@ struct NETLIBSELECTEX
/////////////////////////////////////////////////////////////////////////////////////////
// Shutdown connection
-// wParam = (WPARAM)(HANDLE)hConnection
-// lParam = 0
-// Returns 0
-
-#define MS_NETLIB_SHUTDOWN "Netlib/Shutdown"
-__forceinline void Netlib_Shutdown(HANDLE h)
-{
- CallService(MS_NETLIB_SHUTDOWN, (WPARAM)h, 0);
-}
+EXTERN_C MIR_APP_DLL(void) Netlib_Shutdown(HANDLE h);
/////////////////////////////////////////////////////////////////////////////////////////
// Create a packet receiver
-// wParam = (WPARAM)(HANDLE)hConnection
-// lParam = (LPARAM)(int)maxPacketSize
+//
// Returns a HANDLE on success, NULL on failure
// The packet receiver implements the common situation where you have variable
// length packets coming in over a connection and you want to split them up
@@ -698,12 +672,11 @@ __forceinline void Netlib_Shutdown(HANDLE h)
// have arbitrarily large packets.
// Errors: ERROR_INVALID_PARAMETER, ERROR_OUTOFMEMORY
-#define MS_NETLIB_CREATEPACKETRECVER "Netlib/CreatePacketRecver"
+EXTERN_C MIR_APP_DLL(HANDLE) Netlib_CreatePacketReceiver(HANDLE hConnection, int iMaxSize);
/////////////////////////////////////////////////////////////////////////////////////////
// Get the next set of packets from a packet receiver
-// wParam = (WPARAM)(HANDLE)hPacketRecver
-// lParam = (LPARAM)(NETLIBPACKETRECVER*)&nlpr
+//
// Returns the total number of bytes available in the buffer, 0 if the
// connection was closed, SOCKET_ERROR on error.
// hPacketRecver must have been returned by MS_NETLIB_CREATEPACKETRECVER
@@ -722,15 +695,14 @@ __forceinline void Netlib_Shutdown(HANDLE h)
struct NETLIBPACKETRECVER
{
- int cbSize;
- DWORD dwTimeout; // fill before calling. In milliseconds. INFINITE is valid
- int bytesUsed; // fill before calling. This many bytes are removed from the start of the buffer. Set to 0 on return
- int bytesAvailable; // equal to the return value, unless the return value is 0
- int bufferSize; // same as parameter to MS_NETLIB_CREATEPACKETRECVER
- BYTE *buffer; // contains the recved data
+ DWORD dwTimeout; // fill before calling. In milliseconds. INFINITE is valid
+ int bytesUsed; // fill before calling. This many bytes are removed from the start of the buffer. Set to 0 on return
+ int bytesAvailable; // equal to the return value, unless the return value is 0
+ int bufferSize; // same as parameter to MS_NETLIB_CREATEPACKETRECVER
+ BYTE *buffer; // contains the recved data
};
-#define MS_NETLIB_GETMOREPACKETS "Netlib/GetMorePackets"
+EXTERN_C MIR_APP_DLL(int) Netlib_GetMorePackets(HANDLE hReceiver, NETLIBPACKETRECVER *nlprParam);
/////////////////////////////////////////////////////////////////////////////////////////
// Sets a gateway polling timeout interval
diff --git a/plugins/HTTPServer/src/main.cpp b/plugins/HTTPServer/src/main.cpp
index 1f9c89dc22..c9f69a61a6 100644
--- a/plugins/HTTPServer/src/main.cpp
+++ b/plugins/HTTPServer/src/main.cpp
@@ -634,12 +634,11 @@ static int nProtoAck(WPARAM /*wParam*/, LPARAM lParam)
INT_PTR nToggelAcceptConnections(WPARAM wparam, LPARAM /*lparam*/)
{
if (!hDirectBoundPort) {
- NETLIBUSERSETTINGS nus = { 0 };
+ NETLIBUSERSETTINGS nus = {};
nus.cbSize = sizeof(nus);
- if (!CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM)hNetlibUser, (LPARAM)&nus))
- Netlib_Logf(hNetlibUser, "Failed to get NETLIBUSERSETTINGS using MS_NETLIB_GETUSERSETTINGS");
+ Netlib_GetUserSettings(hNetlibUser, &nus);
- NETLIBBIND nlb = { 0 };
+ NETLIBBIND nlb = {};
nlb.cbSize = sizeof(NETLIBBIND);
nlb.pfnNewConnection = ConnectionOpen;
if (nus.specifyIncomingPorts && nus.szIncomingPorts && nus.szIncomingPorts[0])
@@ -647,7 +646,7 @@ INT_PTR nToggelAcceptConnections(WPARAM wparam, LPARAM /*lparam*/)
else
nlb.wPort = 80;
- hDirectBoundPort = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)hNetlibUser, (LPARAM)& nlb);
+ hDirectBoundPort = Netlib_BindPort(hNetlibUser, &nlb);
if (!hDirectBoundPort) {
char szTemp[200];
mir_snprintf(szTemp, Translate("Failed to bind to port %s\r\nThis is most likely because another program or service is using this port"),
diff --git a/plugins/Ping/src/utils.cpp b/plugins/Ping/src/utils.cpp
index f1882181dc..949c8cd1ee 100644
--- a/plugins/Ping/src/utils.cpp
+++ b/plugins/Ping/src/utils.cpp
@@ -93,7 +93,7 @@ INT_PTR PluginPing(WPARAM, LPARAM lParam)
conn.wPort = pa->port;
conn.timeout = options.ping_timeout;
- HANDLE s = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)hNetlibUser, (LPARAM)&conn);
+ HANDLE s = Netlib_OpenConnection(hNetlibUser, &conn);
mir_free((void*)conn.szHost);
clock_t end_tcp = clock();
diff --git a/plugins/Utils.pas/mirutils.pas b/plugins/Utils.pas/mirutils.pas
index 46cc56aa94..f6ffad2c6a 100644
--- a/plugins/Utils.pas/mirutils.pas
+++ b/plugins/Utils.pas/mirutils.pas
@@ -543,7 +543,7 @@ var
begin
result:=nil;
nlus.cbSize:=SizeOf(nlus);
- if CallService(MS_NETLIB_GETUSERSETTINGS,hNetLib,lparam(@nlus))<>0 then
+ if Netlib_GetUserSettings(hNetLib,@nlus)<>0 then
begin
if nlus.useProxy<>0 then
begin
diff --git a/plugins/Watrack_MPD/src/main.cpp b/plugins/Watrack_MPD/src/main.cpp
index a4ca0c1943..a923777982 100755
--- a/plugins/Watrack_MPD/src/main.cpp
+++ b/plugins/Watrack_MPD/src/main.cpp
@@ -31,9 +31,9 @@ void Start(void*)
nloc.flags = NLOCF_V2;
nloc.wPort = gbPort;
Connected = FALSE;
- ghConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)ghNetlibUser, (LPARAM)&nloc);
- if(ghConnection)
- ghPacketReciever = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER,(WPARAM)ghConnection,2048);
+ ghConnection = Netlib_OpenConnection(ghNetlibUser, &nloc);
+ if (ghConnection)
+ ghPacketReciever = Netlib_CreatePacketReceiver(ghConnection, 2048);
}
void ReStart(void*)
@@ -48,12 +48,11 @@ void ReStart(void*)
int Parser()
{
- static NETLIBPACKETRECVER nlpr = {0};
+ static NETLIBPACKETRECVER nlpr = {};
char *ptr;
int i;
char *buf;
static char ver[16];
- nlpr.cbSize = sizeof(nlpr);
nlpr.dwTimeout = 5;
if(!ghConnection)
{
@@ -62,21 +61,11 @@ int Parser()
if(ghConnection)
{
int recvResult;
-/* do
- {
- recvResult = CallService(MS_NETLIB_GETMOREPACKETS,(WPARAM)ghPacketReciever, (LPARAM)&nlpr);
- if(recvResult == SOCKET_ERROR)
- {
- ReStart();
- return 1;
- }
- }
- while(recvResult > 0);*/
if(!Connected)
{
char tmp[128];
char *tmp2 = mir_u2a(gbPassword);
- recvResult = CallService(MS_NETLIB_GETMOREPACKETS,(WPARAM)ghPacketReciever, (LPARAM)&nlpr);
+ recvResult = Netlib_GetMorePackets(ghPacketReciever, &nlpr);
if(recvResult == SOCKET_ERROR)
{
mir_forkthread(&ReStart, 0);
@@ -89,7 +78,7 @@ int Parser()
mir_strcat(tmp, tmp2);
mir_strcat(tmp, "\n");
Netlib_Send(ghConnection, tmp, (int)mir_strlen(tmp), 0);
- recvResult = CallService(MS_NETLIB_GETMOREPACKETS,(WPARAM)ghPacketReciever, (LPARAM)&nlpr);
+ recvResult = Netlib_GetMorePackets(ghPacketReciever, &nlpr);
if(recvResult == SOCKET_ERROR)
{
mir_forkthread(&ReStart, 0);
@@ -99,14 +88,14 @@ int Parser()
mir_free(tmp2);
}
Netlib_Send(ghConnection, "status\n", (int)mir_strlen("status\n"), 0);
- recvResult = CallService(MS_NETLIB_GETMOREPACKETS,(WPARAM)ghPacketReciever, (LPARAM)&nlpr);
+ recvResult = Netlib_GetMorePackets(ghPacketReciever, &nlpr);
if(recvResult == SOCKET_ERROR)
{
mir_forkthread(&ReStart, 0);
return 1;
}
Netlib_Send(ghConnection, "currentsong\n", (int)mir_strlen("currentsong\n"), 0);
- recvResult = CallService(MS_NETLIB_GETMOREPACKETS,(WPARAM)ghPacketReciever, (LPARAM)&nlpr);
+ recvResult = Netlib_GetMorePackets(ghPacketReciever, &nlpr);
if(recvResult == SOCKET_ERROR)
{
mir_forkthread(&ReStart, 0);
@@ -274,7 +263,7 @@ void Stop()
if(ghConnection)
Netlib_CloseHandle(ghConnection);
if(ghNetlibUser && (ghNetlibUser != INVALID_HANDLE_VALUE))
- CallService(MS_NETLIB_SHUTDOWN,(WPARAM)ghNetlibUser,0);
+ Netlib_Shutdown(ghNetlibUser);
}
int Init()
diff --git a/plugins/Weather/src/weather.cpp b/plugins/Weather/src/weather.cpp
index 75ef89f777..827b5514eb 100644
--- a/plugins/Weather/src/weather.cpp
+++ b/plugins/Weather/src/weather.cpp
@@ -92,7 +92,7 @@ int WeatherShutdown(WPARAM, LPARAM)
SaveOptions(); // save options once more
status = ID_STATUS_OFFLINE; // set status to offline
- CallService(MS_NETLIB_SHUTDOWN, (WPARAM)hNetlibHttp, 0);
+ Netlib_Shutdown(hNetlibHttp);
WindowList_Broadcast(hWindowList, WM_CLOSE, 0, 0);
WindowList_Broadcast(hDataWindowList, WM_CLOSE, 0, 0);
diff --git a/plugins/YAMN/src/proto/netlib.cpp b/plugins/YAMN/src/proto/netlib.cpp
index df4dc150e6..b6405b7e90 100644
--- a/plugins/YAMN/src/proto/netlib.cpp
+++ b/plugins/YAMN/src/proto/netlib.cpp
@@ -85,8 +85,6 @@ void CNLClient::SSLify() throw(DWORD)
//if not success, exception is throwed
void CNLClient::Connect(const char* servername, const int port) throw(DWORD)
{
- NETLIBOPENCONNECTION nloc;
-
NetworkError = SystemError = 0;
isTLSed = false;
@@ -94,11 +92,12 @@ void CNLClient::Connect(const char* servername, const int port) throw(DWORD)
DebugLog(CommFile, "<connect>\n");
#endif
try {
+ NETLIBOPENCONNECTION nloc;
nloc.cbSize = sizeof(NETLIBOPENCONNECTION);
nloc.szHost = servername;
nloc.wPort = port;
nloc.flags = 0;
- if (NULL == (hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)hNetlibUser, (LPARAM)&nloc))) {
+ if (NULL == (hConnection = Netlib_OpenConnection(hNetlibUser, &nloc))) {
SystemError = WSAGetLastError();
throw NetworkError = (DWORD)ENL_CONNECT;
}
diff --git a/protocols/AimOscar/src/connection.cpp b/protocols/AimOscar/src/connection.cpp
index 15e88e87af..a3635cdcfc 100755
--- a/protocols/AimOscar/src/connection.cpp
+++ b/protocols/AimOscar/src/connection.cpp
@@ -28,7 +28,7 @@ HANDLE CAimProto::aim_connect(const char* server, unsigned short port, bool use_
ncon.timeout = 6;
ncon.flags = NLOCF_V2;
debugLogA("%s:%u", server, port);
- HANDLE con = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&ncon);
+ HANDLE con = Netlib_OpenConnection(m_hNetlibUser, &ncon);
if (con && use_ssl) {
NETLIBSSL ssl = { 0 };
ssl.cbSize = sizeof(ssl);
@@ -49,7 +49,7 @@ HANDLE CAimProto::aim_peer_connect(const char* ip, unsigned short port)
ncon.szHost = ip;
ncon.wPort = port;
ncon.timeout = 3;
- return (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibPeer, (LPARAM)&ncon);
+ return Netlib_OpenConnection(m_hNetlibPeer, &ncon);
}
HANDLE CAimProto::aim_peer_connect(unsigned long ip, unsigned short port)
@@ -68,12 +68,12 @@ void CAimProto::aim_connection_authorization(void)
mir_free(m_username);
m_username = getStringA(AIM_KEY_SN);
if (m_username != NULL) {
- HANDLE hServerPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)m_hServerConn, 2048 * 4);
- NETLIBPACKETRECVER packetRecv = { 0 };
- packetRecv.cbSize = sizeof(packetRecv);
+ HANDLE hServerPacketRecver = Netlib_CreatePacketReceiver(m_hServerConn, 2048 * 4);
+
+ NETLIBPACKETRECVER packetRecv = {};
packetRecv.dwTimeout = 5000;
for (;;) {
- int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hServerPacketRecver, (LPARAM)& packetRecv);
+ int recvResult = Netlib_GetMorePackets(hServerPacketRecver, &packetRecv);
if (recvResult == 0) {
debugLogA("Connection Closed: No Error? during Connection Authorization");
break;
@@ -347,15 +347,12 @@ void CAimProto::aim_connection_clientlogin(void)
void __cdecl CAimProto::aim_protocol_negotiation(void*)
{
- HANDLE hServerPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)m_hServerConn, 2048 * 8);
-
-
+ HANDLE hServerPacketRecver = Netlib_CreatePacketReceiver(m_hServerConn, 2048 * 8);
- NETLIBPACKETRECVER packetRecv = { 0 };
- packetRecv.cbSize = sizeof(packetRecv);
+ NETLIBPACKETRECVER packetRecv = {};
packetRecv.dwTimeout = DEFAULT_KEEPALIVE_TIMER * 1000;
for (;;) {
- int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hServerPacketRecver, (LPARAM)&packetRecv);
+ int recvResult = Netlib_GetMorePackets(hServerPacketRecver, &packetRecv);
if (recvResult == 0) {
debugLogA("Connection Closed: No Error during Connection Negotiation?");
break;
@@ -477,13 +474,13 @@ exit:
void __cdecl CAimProto::aim_mail_negotiation(void*)
{
- HANDLE hServerPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)m_hMailConn, 2048 * 8);
+ HANDLE hServerPacketRecver = Netlib_CreatePacketReceiver(m_hMailConn, 2048 * 8);
NETLIBPACKETRECVER packetRecv = { 0 };
- packetRecv.cbSize = sizeof(packetRecv);
packetRecv.dwTimeout = DEFAULT_KEEPALIVE_TIMER * 1000;
+
while (m_iStatus != ID_STATUS_OFFLINE) {
- int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hServerPacketRecver, (LPARAM)&packetRecv);
+ int recvResult = Netlib_GetMorePackets(hServerPacketRecver, &packetRecv);
if (recvResult == 0)
break;
@@ -539,13 +536,13 @@ exit:
void __cdecl CAimProto::aim_avatar_negotiation(void*)
{
- HANDLE hServerPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)m_hAvatarConn, 2048 * 8);
+ HANDLE hServerPacketRecver = Netlib_CreatePacketReceiver(m_hAvatarConn, 2048 * 8);
NETLIBPACKETRECVER packetRecv = { 0 };
- packetRecv.cbSize = sizeof(packetRecv);
packetRecv.dwTimeout = 300000;//5 minutes connected
+
for (;;) {
- int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hServerPacketRecver, (LPARAM)& packetRecv);
+ int recvResult = Netlib_GetMorePackets(hServerPacketRecver, &packetRecv);
if (recvResult == 0)
break;
@@ -599,13 +596,13 @@ exit:
void __cdecl CAimProto::aim_chatnav_negotiation(void*)
{
unsigned idle_chat = 0;
- HANDLE hServerPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)m_hChatNavConn, 2048 * 8);
+ HANDLE hServerPacketRecver = Netlib_CreatePacketReceiver(m_hChatNavConn, 2048 * 8);
NETLIBPACKETRECVER packetRecv = { 0 };
- packetRecv.cbSize = sizeof(packetRecv);
packetRecv.dwTimeout = DEFAULT_KEEPALIVE_TIMER * 1000;
+
for (;;) {
- int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hServerPacketRecver, (LPARAM)&packetRecv);
+ int recvResult = Netlib_GetMorePackets(hServerPacketRecver, &packetRecv);
if (recvResult == 0)
break;
@@ -668,13 +665,13 @@ exit:
void __cdecl CAimProto::aim_chat_negotiation(void* param)
{
chat_list_item *item = (chat_list_item*)param;
- HANDLE hServerPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)item->hconn, 2048 * 8);
+ HANDLE hServerPacketRecver = Netlib_CreatePacketReceiver(item->hconn, 2048 * 8);
NETLIBPACKETRECVER packetRecv = { 0 };
- packetRecv.cbSize = sizeof(packetRecv);
packetRecv.dwTimeout = DEFAULT_KEEPALIVE_TIMER * 1000;
+
for (;;) {
- int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hServerPacketRecver, (LPARAM)&packetRecv);
+ int recvResult = Netlib_GetMorePackets(hServerPacketRecver, &packetRecv);
if (recvResult == 0)
break;
@@ -733,13 +730,13 @@ exit:
void __cdecl CAimProto::aim_admin_negotiation(void*)
{
- HANDLE hServerPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)m_hAdminConn, 2048 * 8);
+ HANDLE hServerPacketRecver = Netlib_CreatePacketReceiver(m_hAdminConn, 2048 * 8);
+
+ NETLIBPACKETRECVER packetRecv = {};
+ packetRecv.dwTimeout = 300000; // 5 minutes connected
- NETLIBPACKETRECVER packetRecv = { 0 };
- packetRecv.cbSize = sizeof(packetRecv);
- packetRecv.dwTimeout = 300000;//5 minutes connected
for (;;) {
- int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hServerPacketRecver, (LPARAM)& packetRecv);
+ int recvResult = Netlib_GetMorePackets(hServerPacketRecver, &packetRecv);
if (recvResult == 0)
break;
diff --git a/protocols/AimOscar/src/defines.h b/protocols/AimOscar/src/defines.h
index 2caf13aa05..11126ac2fb 100644
--- a/protocols/AimOscar/src/defines.h
+++ b/protocols/AimOscar/src/defines.h
@@ -305,7 +305,7 @@ public:
unsigned short LocalPort;// our port
//Peer connection stuff
- HANDLE m_hNetlibPeer;//handle to the peer netlib
+ HNETLIBUSER m_hNetlibPeer;//handle to the peer netlib
HANDLE hDirectBoundPort;//direct connection listening port
HANDLE current_rendezvous_accept_user;//hack
diff --git a/protocols/AimOscar/src/direct_connect.cpp b/protocols/AimOscar/src/direct_connect.cpp
index fa1f8ea22c..2b4bcb9366 100644
--- a/protocols/AimOscar/src/direct_connect.cpp
+++ b/protocols/AimOscar/src/direct_connect.cpp
@@ -25,11 +25,10 @@ void __cdecl CAimProto::aim_dc_helper(void* param) //only called when we are ini
ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, ft, 0);
- NETLIBPACKETRECVER packetRecv = { 0 };
- packetRecv.cbSize = sizeof(packetRecv);
+ NETLIBPACKETRECVER packetRecv = {};
packetRecv.dwTimeout = 350000;
- HANDLE hServerPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)ft->hConn, 2048 * 4);
+ HANDLE hServerPacketRecver = Netlib_CreatePacketReceiver(ft->hConn, 2048 * 4);
int result;
if (ft->sending)//we are sending
diff --git a/protocols/AimOscar/src/file.cpp b/protocols/AimOscar/src/file.cpp
index 007359eb8f..cdb81e03b6 100644
--- a/protocols/AimOscar/src/file.cpp
+++ b/protocols/AimOscar/src/file.cpp
@@ -154,7 +154,7 @@ int CAimProto::sending_file(file_transfer *ft, HANDLE hServerPacketRecver, NETLI
for (;;) {
int recvResult = packetRecv.bytesAvailable - packetRecv.bytesUsed;
if (recvResult <= 0)
- recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hServerPacketRecver, (LPARAM)&packetRecv);
+ recvResult = Netlib_GetMorePackets(hServerPacketRecver, &packetRecv);
if (recvResult == 0) {
debugLogA("P2P: File transfer connection Error: 0");
break;
@@ -272,7 +272,7 @@ int CAimProto::receiving_file(file_transfer *ft, HANDLE hServerPacketRecver, NET
for (;;) {
int recvResult = packetRecv.bytesAvailable - packetRecv.bytesUsed;
if (recvResult <= 0)
- recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hServerPacketRecver, (LPARAM)&packetRecv);
+ recvResult = Netlib_GetMorePackets(hServerPacketRecver, &packetRecv);
if (recvResult == 0) {
debugLogA("P2P: File transfer connection Error: 0");
break;
@@ -529,11 +529,11 @@ void file_transfer::listen(CAimProto* ppro)
{
if (hDirectBoundPort) return;
- NETLIBBIND nlb = { 0 };
+ NETLIBBIND nlb = {};
nlb.cbSize = sizeof(nlb);
nlb.pfnNewConnectionV2 = aim_direct_connection_initiated;
nlb.pExtra = ppro;
- hDirectBoundPort = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)ppro->m_hNetlibPeer, (LPARAM)&nlb);
+ hDirectBoundPort = Netlib_BindPort(ppro->m_hNetlibPeer, &nlb);
local_port = hDirectBoundPort ? nlb.wPort : 0;
}
diff --git a/protocols/AimOscar/src/proto.h b/protocols/AimOscar/src/proto.h
index 79980483eb..f2a31d60d6 100755
--- a/protocols/AimOscar/src/proto.h
+++ b/protocols/AimOscar/src/proto.h
@@ -129,7 +129,7 @@ struct CAimProto : public PROTO<CAimProto>
unsigned short m_local_port; // our port
//Peer connection stuff
- HANDLE m_hNetlibPeer;//handle to the peer netlib
+ HNETLIBUSER m_hNetlibPeer;//handle to the peer netlib
HANDLE m_hDirectBoundPort;//direct connection listening port
//Handles for the context menu items
diff --git a/protocols/AimOscar/src/proxy.cpp b/protocols/AimOscar/src/proxy.cpp
index 10e04df718..d3ac4deebe 100644
--- a/protocols/AimOscar/src/proxy.cpp
+++ b/protocols/AimOscar/src/proxy.cpp
@@ -34,14 +34,13 @@ void __cdecl CAimProto::aim_proxy_helper(void* param)
}
//start listen for packets stuff
- NETLIBPACKETRECVER packetRecv = {0};
- packetRecv.cbSize = sizeof(packetRecv);
+ NETLIBPACKETRECVER packetRecv = {};
packetRecv.dwTimeout = INFINITE;
- HANDLE hServerPacketRecver = (HANDLE) CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)ft->hConn, 2048 * 4);
+ HANDLE hServerPacketRecver = Netlib_CreatePacketReceiver(ft->hConn, 2048 * 4);
for (;;)
{
- int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hServerPacketRecver, (LPARAM)&packetRecv);
+ int recvResult = Netlib_GetMorePackets(hServerPacketRecver, &packetRecv);
if (recvResult == 0)
{
ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0);
diff --git a/protocols/Discord/src/gateway.cpp b/protocols/Discord/src/gateway.cpp
index 7454383878..d17ccf4952 100644
--- a/protocols/Discord/src/gateway.cpp
+++ b/protocols/Discord/src/gateway.cpp
@@ -102,7 +102,7 @@ void CDiscordProto::GatewayThreadWorker()
}
else conn.wPort = 443;
- m_hGatewayConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hGatewayNetlibUser, (LPARAM)&conn);
+ m_hGatewayConnection = Netlib_OpenConnection(m_hGatewayNetlibUser, &conn);
if (m_hGatewayConnection == NULL) {
debugLogA("Gateway connection failed to connect to %s:%d, exiting", m_szGateway.c_str(), conn.wPort);
return;
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index 15a6a9eeeb..22fe036f5b 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -145,9 +145,8 @@ class CDiscordProto : public PROTO<CDiscordProto>
m_szGateway, // gateway url
m_szGatewaySessionId; // current session id
- HANDLE
- m_hGatewayNetlibUser, // the separate netlib user handle for gateways
- m_hGatewayConnection; // gateway connection
+ HNETLIBUSER m_hGatewayNetlibUser; // the separate netlib user handle for gateways
+ HANDLE m_hGatewayConnection; // gateway connection
void __cdecl GatewayThread(void*);
void CDiscordProto::GatewayThreadWorker(void);
diff --git a/protocols/Gadu-Gadu/src/core.cpp b/protocols/Gadu-Gadu/src/core.cpp
index 000edf3ed9..f619bab6ea 100644
--- a/protocols/Gadu-Gadu/src/core.cpp
+++ b/protocols/Gadu-Gadu/src/core.cpp
@@ -284,7 +284,7 @@ void __cdecl GGPROTO::mainthread(void *)
// Setup proxy
nlus.cbSize = sizeof(nlus);
- if (CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM)m_hNetlibUser, (LPARAM)&nlus)) {
+ if (Netlib_GetUserSettings(m_hNetlibUser, &nlus)) {
if (nlus.useProxy)
debugLogA("mainthread() (%x): Using proxy %s:%d.", this, nlus.szProxyServer, nlus.wProxyPort);
gg_proxy_enabled = nlus.useProxy;
diff --git a/protocols/IRCG/src/irclib.cpp b/protocols/IRCG/src/irclib.cpp
index 84b5d6476e..3235e06a76 100644
--- a/protocols/IRCG/src/irclib.cpp
+++ b/protocols/IRCG/src/irclib.cpp
@@ -198,11 +198,10 @@ bool CIrcProto::Connect(const CIrcSessionInfo& info)
ncon.cbSize = sizeof(ncon);
ncon.szHost = info.sServer.c_str();
ncon.wPort = info.iPort;
- con = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&ncon);
+ con = Netlib_OpenConnection(m_hNetlibUser, &ncon);
if (con == NULL) {
wchar_t szTemp[300];
- mir_snwprintf(szTemp, L"\0035%s \002%s\002 (%S: %u).",
- TranslateT("Failed to connect to"), si.sNetwork.c_str(), si.sServer.c_str(), si.iPort);
+ mir_snwprintf(szTemp, L"\0035%s \002%s\002 (%S: %u).", TranslateT("Failed to connect to"), si.sNetwork.c_str(), si.sServer.c_str(), si.iPort);
DoEvent(GC_EVENT_INFORMATION, SERVERWINDOW, NULL, szTemp, NULL, NULL, NULL, true, false);
return false;
}
@@ -358,12 +357,13 @@ void CIrcProto::DoReceive()
int cbInBuf = 0;
if (m_info.bIdentServer && m_info.iIdentServerPort != NULL) {
- NETLIBBIND nb = { 0 };
+ NETLIBBIND nb = {};
nb.cbSize = sizeof(NETLIBBIND);
nb.pfnNewConnectionV2 = DoIdent;
nb.pExtra = this;
nb.wPort = m_info.iIdentServerPort;
- hBindPort = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)m_hNetlibUser, (LPARAM)&nb);
+
+ hBindPort = Netlib_BindPort(m_hNetlibUser, &nb);
if (!hBindPort || nb.wPort != m_info.iIdentServerPort) {
debugLogA("Error: unable to bind local port %u", m_info.iIdentServerPort);
KillIdent();
@@ -874,13 +874,13 @@ int CDccSession::SetupConnection()
// create a listening socket for outgoing chat/send requests. The remote computer connects to this computer. Used for both chat and filetransfer.
if (di->bSender && !di->bReverse) {
- NETLIBBIND nb = { 0 };
+ NETLIBBIND nb = {};
nb.cbSize = sizeof(NETLIBBIND);
nb.pfnNewConnectionV2 = DoIncomingDcc; // this is the (helper) function to be called once an incoming connection is made. The 'real' function that is called is IncomingConnection()
nb.pExtra = (void *)this;
nb.wPort = 0;
- hBindPort = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)m_proto->hNetlibDCC, (LPARAM)&nb);
-
+
+ hBindPort = Netlib_BindPort(m_proto->hNetlibDCC, &nb);
if (hBindPort == NULL) {
delete this; // dcc objects destroy themselves when the connection has been closed or failed for some reasson.
return 0;
@@ -897,7 +897,7 @@ int CDccSession::SetupConnection()
ncon.cbSize = sizeof(ncon);
ncon.szHost = ConvertIntegerToIP(di->dwAdr);
ncon.wPort = (WORD)di->iPort;
- con = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_proto->hNetlibDCC, (LPARAM)&ncon);
+ con = Netlib_OpenConnection(m_proto->hNetlibDCC, &ncon);
}
// If a remote computer initiates a filetransfer this is used to connect to that computer (the user has chosen to accept but it is possible the file exists/needs to be resumed etc still)
@@ -953,13 +953,13 @@ int CDccSession::SetupConnection()
// hack for passive filetransfers
if (di->iType == DCC_SEND && !di->bSender && di->bReverse) {
- NETLIBBIND nb = { 0 };
+ NETLIBBIND nb = {};
nb.cbSize = sizeof(NETLIBBIND);
nb.pfnNewConnectionV2 = DoIncomingDcc; // this is the (helper) function to be called once an incoming connection is made. The 'real' function that is called is IncomingConnection()
nb.pExtra = (void *)this;
nb.wPort = 0;
- hBindPort = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)m_proto->hNetlibDCC, (LPARAM)&nb);
+ hBindPort = Netlib_BindPort(m_proto->hNetlibDCC, &nb);
if (hBindPort == NULL) {
m_proto->DoEvent(GC_EVENT_INFORMATION, 0, m_proto->m_info.sNick.c_str(), LPGENW("DCC ERROR: Unable to bind local port for passive file transfer"), NULL, NULL, NULL, true, false);
delete this; // dcc objects destroy themselves when the connection has been closed or failed for some reasson.
@@ -995,7 +995,7 @@ int CDccSession::SetupConnection()
ncon.szHost = ConvertIntegerToIP(di->dwAdr);
ncon.wPort = (WORD)di->iPort;
- con = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_proto->hNetlibDCC, (LPARAM)&ncon);
+ con = Netlib_OpenConnection(m_proto->hNetlibDCC, &ncon);
}
// if for some reason the plugin has failed to connect to the remote computer the object is destroyed.
@@ -1097,12 +1097,11 @@ void CDccSession::DoSendFile()
tLastActivity = time(0);
// create a packet receiver to handle receiving ack's from the remote computer.
- HANDLE hPackrcver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)con, sizeof(DWORD));
- NETLIBPACKETRECVER npr;
- npr.cbSize = sizeof(NETLIBPACKETRECVER);
+ HANDLE hPackrcver = Netlib_CreatePacketReceiver(con, sizeof(DWORD));
+
+ NETLIBPACKETRECVER npr = {};
npr.dwTimeout = 60 * 1000;
npr.bufferSize = sizeof(DWORD);
- npr.bytesUsed = 0;
// until the connection is dropped it will spin around in this while() loop
while (con) {
@@ -1127,7 +1126,7 @@ void CDccSession::DoSendFile()
DWORD dwPacket = NULL;
do {
- dwRead = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hPackrcver, (LPARAM)&npr);
+ dwRead = Netlib_GetMorePackets(hPackrcver, &npr);
npr.bytesUsed = sizeof(DWORD);
if (dwRead <= 0)
@@ -1148,7 +1147,7 @@ void CDccSession::DoSendFile()
DWORD dwPacket = 0;
do {
- dwRead = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hPackrcver, (LPARAM)&npr);
+ dwRead = Netlib_GetMorePackets(hPackrcver, &npr);
npr.bytesUsed = sizeof(DWORD);
if (dwRead <= 0)
break; // connection closed, or a timeout occurred.
diff --git a/protocols/IRCG/src/stdafx.h b/protocols/IRCG/src/stdafx.h
index 7010ac4931..ca32a61167 100644
--- a/protocols/IRCG/src/stdafx.h
+++ b/protocols/IRCG/src/stdafx.h
@@ -343,8 +343,8 @@ struct CIrcProto : public PROTO<CIrcProto>
DWORD m_bConnectRequested;
DWORD m_bConnectThreadRunning;
- HGENMENU hMenuQuick, hMenuServer, hMenuJoin, hMenuNick, hMenuList;
- HANDLE hNetlibDCC;
+ HGENMENU hMenuQuick, hMenuServer, hMenuJoin, hMenuNick, hMenuList;
+ HNETLIBUSER hNetlibDCC;
bool bTempDisableCheck, bTempForceCheck, bEcho;
bool nickflag;
diff --git a/protocols/IcqOscarJ/src/chan_04close.cpp b/protocols/IcqOscarJ/src/chan_04close.cpp
index c9d4157f8e..315b22c888 100644
--- a/protocols/IcqOscarJ/src/chan_04close.cpp
+++ b/protocols/IcqOscarJ/src/chan_04close.cpp
@@ -142,7 +142,7 @@ int CIcqProto::connectNewServer(serverthread_info *info)
if (hServerConn) {
/* Time to recreate the packet receiver */
- info->hPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)hServerConn, 0x2400);
+ info->hPacketRecver = Netlib_CreatePacketReceiver(hServerConn, 0x2400);
if (!info->hPacketRecver)
debugLogA("Error: Failed to create packet receiver.");
else { // we need to reset receiving structs
diff --git a/protocols/IcqOscarJ/src/icq_avatar.cpp b/protocols/IcqOscarJ/src/icq_avatar.cpp
index 6fd71d67e0..ad93fb8065 100644
--- a/protocols/IcqOscarJ/src/icq_avatar.cpp
+++ b/protocols/IcqOscarJ/src/icq_avatar.cpp
@@ -879,14 +879,14 @@ void avatars_server_connection::checkRequestQueue()
void avatars_server_connection::connectionThread()
{
// This is the "infinite" loop that receives the packets from the ICQ avatar server
- NETLIBPACKETRECVER packetRecv = { 0 };
DWORD dwLastKeepAlive = time(0) + KEEPALIVE_INTERVAL;
- hPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)hConnection, 65536);
- packetRecv.cbSize = sizeof(packetRecv);
+ hPacketRecver = Netlib_CreatePacketReceiver(hConnection, 65536);
+
+ NETLIBPACKETRECVER packetRecv = {};
packetRecv.dwTimeout = 1000; // timeout - for stopThread to work
while (!stopThread) {
- int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hPacketRecver, (LPARAM)&packetRecv);
+ int recvResult = Netlib_GetMorePackets(hPacketRecver, &packetRecv);
if (recvResult == 0) {
ppro->debugLogA("Clean closure of avatar socket");
break;
diff --git a/protocols/IcqOscarJ/src/icq_direct.cpp b/protocols/IcqOscarJ/src/icq_direct.cpp
index 59cc9bc35b..d87b215704 100644
--- a/protocols/IcqOscarJ/src/icq_direct.cpp
+++ b/protocols/IcqOscarJ/src/icq_direct.cpp
@@ -194,9 +194,8 @@ void __cdecl CIcqProto::icq_directThread(directthreadstartinfo *dtsi)
{
Thread_SetName("ICQ: directThread");
+ NETLIBPACKETRECVER packetRecv = {};
directconnect dc = { 0 };
- NETLIBPACKETRECVER packetRecv = { 0 };
- HANDLE hPacketRecver;
BOOL bFirstPacket = TRUE;
size_t nSkipPacketBytes = 0;
DWORD dwReqMsgID1 = 0, dwReqMsgID2 = 0;
@@ -333,16 +332,14 @@ void __cdecl CIcqProto::icq_directThread(directthreadstartinfo *dtsi)
}
}
- hPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)dc.hConnection, 8192);
- packetRecv.cbSize = sizeof(packetRecv);
- packetRecv.bytesUsed = 0;
+ HANDLE hPacketRecver = Netlib_CreatePacketReceiver(dc.hConnection, 8192);
// Packet receiving loop
while (dc.hConnection) {
packetRecv.dwTimeout = dc.wantIdleTime ? 0 : 600000;
- int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hPacketRecver, (LPARAM)&packetRecv);
+ int recvResult = Netlib_GetMorePackets(hPacketRecver, &packetRecv);
if (recvResult == 0) {
NetLog_Direct("Clean closure of direct socket (%p)", dc.hConnection);
break;
diff --git a/protocols/IcqOscarJ/src/icq_server.cpp b/protocols/IcqOscarJ/src/icq_server.cpp
index 87e1007267..1de0a261e5 100644
--- a/protocols/IcqOscarJ/src/icq_server.cpp
+++ b/protocols/IcqOscarJ/src/icq_server.cpp
@@ -107,17 +107,16 @@ void __cdecl CIcqProto::ServerThread(serverthread_start_info *infoParam)
// This is the "infinite" loop that receives the packets from the ICQ server
NETLIBPACKETRECVER packetRecv;
- info.hPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)hServerConn, 0x2400);
+ info.hPacketRecver = Netlib_CreatePacketReceiver(hServerConn, 0x2400);
while (serverThreadHandle) {
if (info.bReinitRecver) { // we reconnected, reinit struct
info.bReinitRecver = false;
memset(&packetRecv, 0, sizeof(packetRecv));
- packetRecv.cbSize = sizeof(packetRecv);
packetRecv.dwTimeout = 1000;
}
- int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)info.hPacketRecver, (LPARAM)&packetRecv);
+ int recvResult = Netlib_GetMorePackets(info.hPacketRecver, &packetRecv);
if (recvResult == 0) {
debugLogA("Clean closure of server socket");
break;
diff --git a/protocols/IcqOscarJ/src/init.cpp b/protocols/IcqOscarJ/src/init.cpp
index 57277b4a51..20d7165643 100644
--- a/protocols/IcqOscarJ/src/init.cpp
+++ b/protocols/IcqOscarJ/src/init.cpp
@@ -157,7 +157,7 @@ void CIcqProto::UpdateGlobalSettings()
if (m_hNetlibUser) {
NETLIBUSERSETTINGS nlus = { sizeof(NETLIBUSERSETTINGS) };
- if ( !m_bSecureConnection && CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM)m_hNetlibUser, (LPARAM)&nlus)) {
+ if (!m_bSecureConnection && Netlib_GetUserSettings(m_hNetlibUser, &nlus)) {
if (nlus.useProxy && nlus.proxyType == PROXYTYPE_HTTP)
m_bGatewayMode = 1;
else
diff --git a/protocols/IcqOscarJ/src/oscar_filetransfer.cpp b/protocols/IcqOscarJ/src/oscar_filetransfer.cpp
index 5d5d480194..69ca05538a 100644
--- a/protocols/IcqOscarJ/src/oscar_filetransfer.cpp
+++ b/protocols/IcqOscarJ/src/oscar_filetransfer.cpp
@@ -1101,8 +1101,6 @@ void __cdecl CIcqProto::oft_connectionThread(oscarthreadstartinfo *otsi)
{
oscar_connection oc = { 0 };
oscar_listener *source;
- NETLIBPACKETRECVER packetRecv = { 0 };
- HANDLE hPacketRecver;
Thread_SetName("ICQ: oft_connectionThread");
@@ -1299,15 +1297,16 @@ void __cdecl CIcqProto::oft_connectionThread(oscarthreadstartinfo *otsi)
oft_sendPeerInit(&oc);
}
}
- hPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)oc.hConnection, 8192);
- packetRecv.cbSize = sizeof(packetRecv);
+
+ HANDLE hPacketRecver = Netlib_CreatePacketReceiver(oc.hConnection, 8192);
+ NETLIBPACKETRECVER packetRecv = {};
// Packet receiving loop
while (oc.hConnection) {
packetRecv.dwTimeout = oc.wantIdleTime ? 0 : 120000;
- int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hPacketRecver, (LPARAM)&packetRecv);
+ int recvResult = Netlib_GetMorePackets(hPacketRecver, &packetRecv);
if (!recvResult) {
NetLog_Direct("Clean closure of oscar socket (%p)", oc.hConnection);
break;
diff --git a/protocols/IcqOscarJ/src/utilities.cpp b/protocols/IcqOscarJ/src/utilities.cpp
index 7ad7f12dbf..85a34e4238 100644
--- a/protocols/IcqOscarJ/src/utilities.cpp
+++ b/protocols/IcqOscarJ/src/utilities.cpp
@@ -1367,20 +1367,19 @@ HANDLE NetLib_OpenConnection(HNETLIBUSER hUser, const char* szIdent, NETLIBOPENC
nloc->cbSize = sizeof(NETLIBOPENCONNECTION);
nloc->flags |= NLOCF_V2;
-
- return (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)hUser, (LPARAM)nloc);
+ return Netlib_OpenConnection(hUser, nloc);
}
HANDLE CIcqProto::NetLib_BindPort(NETLIBNEWCONNECTIONPROC_V2 pFunc, void* lParam, WORD* pwPort, DWORD* pdwIntIP)
{
- NETLIBBIND nlb = { 0 };
+ NETLIBBIND nlb = {};
nlb.cbSize = sizeof(NETLIBBIND);
nlb.pfnNewConnectionV2 = pFunc;
nlb.pExtra = lParam;
SetLastError(ERROR_INVALID_PARAMETER); // this must be here - NetLib does not set any error :((
-
- HANDLE hBoundPort = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)m_hDirectNetlibUser, (LPARAM)&nlb);
+
+ HANDLE hBoundPort = Netlib_BindPort(m_hDirectNetlibUser, &nlb);
if (pwPort) *pwPort = nlb.wPort;
if (pdwIntIP) *pdwIntIP = nlb.dwInternalIP;
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)
diff --git a/protocols/MRA/src/MraAvatars.cpp b/protocols/MRA/src/MraAvatars.cpp
index a14c976c64..2979323977 100644
--- a/protocols/MRA/src/MraAvatars.cpp
+++ b/protocols/MRA/src/MraAvatars.cpp
@@ -18,7 +18,7 @@ const LPSTR lpcszContentType[9] =
struct MRA_AVATARS_QUEUE : public FIFO_MT
{
- HANDLE hNetlibUser;
+ HNETLIBUSER hNetlibUser;
HANDLE hThreadEvents[64];
int iThreadsCount, iThreadsRunning;
};
@@ -37,7 +37,7 @@ struct MRA_AVATARS_QUEUE_ITEM : public FIFO_MT_ITEM
char szAvtSectName[MAX_PATH];
#define MRA_AVT_SECT_NAME szAvtSectName
-HANDLE MraAvatarsHttpConnect(HANDLE hNetlibUser, LPCSTR lpszHost, DWORD dwPort);
+HANDLE MraAvatarsHttpConnect(HNETLIBUSER hNetlibUser, LPCSTR lpszHost, DWORD dwPort);
#define MAHTRO_AVT 0
#define MAHTRO_AVTMRIM 1
@@ -333,7 +333,7 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter)
CloseHandle(hThreadEvent);
}
-HANDLE MraAvatarsHttpConnect(HANDLE hNetlibUser, LPCSTR lpszHost, DWORD dwPort)
+HANDLE MraAvatarsHttpConnect(HNETLIBUSER hNetlibUser, LPCSTR lpszHost, DWORD dwPort)
{
NETLIBOPENCONNECTION nloc = { 0 };
nloc.cbSize = sizeof(nloc);
@@ -348,7 +348,7 @@ HANDLE MraAvatarsHttpConnect(HANDLE hNetlibUser, LPCSTR lpszHost, DWORD dwPort)
DWORD dwCurConnectReTryCount = dwConnectReTryCount;
HANDLE hConnection;
do {
- hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)hNetlibUser, (LPARAM)&nloc);
+ hConnection = Netlib_OpenConnection(hNetlibUser, &nloc);
}
while (--dwCurConnectReTryCount && hConnection == NULL);
@@ -393,7 +393,7 @@ DWORD MraAvatarsHttpTransaction(HANDLE hConnection, DWORD dwRequestType, LPCSTR
nlhr.headers = (NETLIBHTTPHEADER*)&nlbhHeaders;
nlhr.headersCount = 4;
- DWORD dwSent = CallService(MS_NETLIB_SENDHTTPREQUEST, (WPARAM)hConnection, (LPARAM)&nlhr);
+ DWORD dwSent = Netlib_SendHttpRequest(hConnection, &nlhr);
if (dwSent == SOCKET_ERROR || !dwSent)
return GetLastError();
diff --git a/protocols/MRA/src/MraFilesQueue.cpp b/protocols/MRA/src/MraFilesQueue.cpp
index 83234d5adf..bad116e95e 100644
--- a/protocols/MRA/src/MraFilesQueue.cpp
+++ b/protocols/MRA/src/MraFilesQueue.cpp
@@ -471,7 +471,7 @@ HANDLE CMraProto::MraFilesQueueConnectOut(MRA_FILES_QUEUE_ITEM *dat)
dwCurConnectReTryCount = dwConnectReTryCount;
do {
- dat->hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
+ dat->hConnection = Netlib_OpenConnection(m_hNetlibUser, &nloc);
}
while (--dwCurConnectReTryCount && dat->hConnection == NULL);
@@ -521,14 +521,13 @@ HANDLE CMraProto::MraFilesQueueConnectIn(MRA_FILES_QUEUE_ITEM *dat)
// êîïèðóåì àäðåñà â ñîîòâåòñòâèè ñ ïðàâèëàìè è íà÷èíàåì ñëóøàòü ïîðò
if (getByte("FileSendEnableDirectConn", MRA_DEF_FS_ENABLE_DIRECT_CONN)) {
- NETLIBBIND nlbBind = { 0 };
-
+ NETLIBBIND nlbBind = {};
nlbBind.cbSize = sizeof(nlbBind);
nlbBind.pfnNewConnectionV2 = MraFilesQueueConnectionReceived;
nlbBind.wPort = 0;
nlbBind.pExtra = (LPVOID)dat;
- dat->hListen = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)m_hNetlibUser, (LPARAM)&nlbBind);
+ dat->hListen = Netlib_BindPort(m_hNetlibUser, &nlbBind);
if (dat->hListen) {
ProtoBroadcastAck(dat->hContact, ACKTYPE_FILE, ACKRESULT_LISTENING, (HANDLE)dat->dwIDRequest, 0);
dwAddrListSize = MraFilesQueueGetLocalAddressesList(szAddrList, sizeof(szAddrList), nlbBind.wPort);
diff --git a/protocols/MRA/src/MraMRIMProxy.cpp b/protocols/MRA/src/MraMRIMProxy.cpp
index e3789af1e2..2953356770 100644
--- a/protocols/MRA/src/MraMRIMProxy.cpp
+++ b/protocols/MRA/src/MraMRIMProxy.cpp
@@ -121,7 +121,7 @@ DWORD CMraProto::MraMrimProxyConnect(HANDLE hMraMrimProxyData, HANDLE *phConnect
dwCurConnectReTryCount = dwConnectReTryCount;
do {
- pmmpd->hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
+ pmmpd->hConnection = Netlib_OpenConnection(m_hNetlibUser, &nloc);
}
while (--dwCurConnectReTryCount && pmmpd->hConnection == NULL);
diff --git a/protocols/MRA/src/Mra_functions.cpp b/protocols/MRA/src/Mra_functions.cpp
index a63493bfc3..da0f03fd69 100644
--- a/protocols/MRA/src/Mra_functions.cpp
+++ b/protocols/MRA/src/Mra_functions.cpp
@@ -693,10 +693,10 @@ void CMraProto::MraUpdateEmailStatus(const CMStringA &pszFrom, const CMStringA &
}
}
-bool IsHTTPSProxyUsed(HANDLE hNetlibUser)
+bool IsHTTPSProxyUsed(HNETLIBUSER hNetlibUser)
{
NETLIBUSERSETTINGS nlus = { sizeof(nlus) };
- if (CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM)hNetlibUser, (LPARAM)&nlus))
+ Netlib_GetUserSettings(hNetlibUser, &nlus);
if (nlus.useProxy && nlus.proxyType == PROXYTYPE_HTTPS)
return true;
diff --git a/protocols/MRA/src/Mra_proto.cpp b/protocols/MRA/src/Mra_proto.cpp
index 2245fd2604..acd9977a65 100644
--- a/protocols/MRA/src/Mra_proto.cpp
+++ b/protocols/MRA/src/Mra_proto.cpp
@@ -59,7 +59,7 @@ void CMraProto::MraThreadProc(LPVOID)
dwCurConnectReTryCount = dwConnectReTryCount;
do {
InterlockedExchange((volatile LONG*)&m_dwThreadWorkerLastPingTime, GetTickCount());
- m_hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
+ m_hConnection = Netlib_OpenConnection(m_hNetlibUser, &nloc);
}
while (--dwCurConnectReTryCount && m_hConnection == NULL);
@@ -82,7 +82,7 @@ void CMraProto::MraThreadProc(LPVOID)
dwCurConnectReTryCount = dwConnectReTryCount;
do {
InterlockedExchange((volatile LONG*)&m_dwThreadWorkerLastPingTime, GetTickCount());
- m_hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
+ m_hConnection = Netlib_OpenConnection(m_hNetlibUser, &nloc);
}
while (--dwCurConnectReTryCount && m_hConnection == NULL);
@@ -143,7 +143,7 @@ DWORD CMraProto::MraGetNLBData(CMStringA &szHost, WORD *pwPort)
dwCurConnectReTryCount = dwConnectReTryCount;
do {
InterlockedExchange((volatile LONG*)&m_dwThreadWorkerLastPingTime, GetTickCount());
- nls.hReadConns[0] = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
+ nls.hReadConns[0] = Netlib_OpenConnection(m_hNetlibUser, &nloc);
}
while (--dwCurConnectReTryCount && nls.hReadConns[0] == NULL);
diff --git a/protocols/MRA/src/stdafx.h b/protocols/MRA/src/stdafx.h
index 6fd37937ae..29dfaa5fe9 100644
--- a/protocols/MRA/src/stdafx.h
+++ b/protocols/MRA/src/stdafx.h
@@ -199,7 +199,7 @@ CMStringA CopyNumber(const CMStringA&);
CMStringW DecodeXML(const CMStringW &lptszMessage);
CMStringW EncodeXML(const CMStringW &lptszMessage);
-bool IsHTTPSProxyUsed(HANDLE hConnection);
+bool IsHTTPSProxyUsed(HNETLIBUSER hConnection);
bool IsContactMraProto(MCONTACT hContact);
bool IsEMailMR(const CMStringA& szEmail);
bool GetEMailFromString(const CMStringA& szBuff, CMStringA& szEmail);
diff --git a/protocols/MSN/src/msn_p2p.cpp b/protocols/MSN/src/msn_p2p.cpp
index 9785717103..2c81a6ecc0 100644
--- a/protocols/MSN/src/msn_p2p.cpp
+++ b/protocols/MSN/src/msn_p2p.cpp
@@ -682,7 +682,7 @@ bool CMsnProto::p2p_connectTo(ThreadData* info, directconnection *dc)
debugLogA("Connecting to %s:%d", tConn.szHost, tConn.wPort);
- info->s = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&tConn);
+ info->s = (HANDLE)Netlib_OpenConnection(m_hNetlibUser, (LPARAM)&tConn);
if (info->s == NULL) {
TWinErrorCode err;
debugLogA("Connection Failed (%d): %s", err.mErrorCode, err.getText());
diff --git a/protocols/MSN/src/msn_proto.cpp b/protocols/MSN/src/msn_proto.cpp
index 0f1a20f5fd..a938b42be9 100644
--- a/protocols/MSN/src/msn_proto.cpp
+++ b/protocols/MSN/src/msn_proto.cpp
@@ -538,10 +538,11 @@ void __cdecl CMsnProto::MsnFileAckThread(void* arg)
NETLIBOPENCONNECTION nloc = { 0 };
MyNetlibConnFromUrl(nlhr.szUrl, nloc);
nloc.flags |= NLOCF_HTTP;
- if (nloc.flags & NLOCF_SSL) nlhr.flags |= NLHRF_SSL;
- HANDLE nlc = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
-
- if (nlc && CallService(MS_NETLIB_SENDHTTPREQUEST, (WPARAM)nlc, (LPARAM)&nlhr) != SOCKET_ERROR && (nlhrReply = Netlib_RecvHttpHeaders(nlc))) {
+ if (nloc.flags & NLOCF_SSL)
+ nlhr.flags |= NLHRF_SSL;
+
+ HANDLE nlc = Netlib_OpenConnection(m_hNetlibUser, &nloc);
+ if (nlc && Netlib_SendHttpRequest(nlc, &nlhr) != SOCKET_ERROR && (nlhrReply = Netlib_RecvHttpHeaders(nlc))) {
if (nlhrReply->resultCode == 200 || nlhrReply->resultCode == 206) {
INT_PTR dw;
char buf[1024];
@@ -562,7 +563,8 @@ void __cdecl CMsnProto::MsnFileAckThread(void* arg)
}
Netlib_CloseHandle(nlc);
mir_free((char*)nloc.szHost);
- if (ft->std.currentFileNumber >= ft->std.totalFiles) ft->complete();
+ if (ft->std.currentFileNumber >= ft->std.totalFiles)
+ ft->complete();
}
delete ft;
}
diff --git a/protocols/MSN/src/msn_threads.cpp b/protocols/MSN/src/msn_threads.cpp
index 2bddaea516..de17faa243 100644
--- a/protocols/MSN/src/msn_threads.cpp
+++ b/protocols/MSN/src/msn_threads.cpp
@@ -160,7 +160,7 @@ void __cdecl CMsnProto::MSNServerThread(void* arg)
debugLogA("Thread started: server='%s:%d', type=%d", tConn.szHost, tConn.wPort, info->mType);
- info->s = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&tConn);
+ info->s = Netlib_OpenConnection(m_hNetlibUser, &tConn);
if (info->s == NULL) {
debugLogA("Connection Failed (%d) server='%s:%d'", WSAGetLastError(), tConn.szHost, tConn.wPort);
@@ -336,7 +336,7 @@ void CMsnProto::MSN_CloseConnections(void)
break;
case SERVER_P2P_DIRECT:
- CallService(MS_NETLIB_SHUTDOWN, (WPARAM)T.s, 0);
+ Netlib_Shutdown(T.s);
break;
}
}
@@ -344,7 +344,7 @@ void CMsnProto::MSN_CloseConnections(void)
lck.unlock();
if (hHttpsConnection)
- CallService(MS_NETLIB_SHUTDOWN, (WPARAM)hHttpsConnection, 0);
+ Netlib_Shutdown(hHttpsConnection);
}
void CMsnProto::Threads_Uninit(void)
diff --git a/protocols/Sametime/src/sametime_session.cpp b/protocols/Sametime/src/sametime_session.cpp
index e492bdaa94..154a165f83 100644
--- a/protocols/Sametime/src/sametime_session.cpp
+++ b/protocols/Sametime/src/sametime_session.cpp
@@ -379,12 +379,13 @@ int waitcallback(unsigned int* timeout)
void __cdecl SessionThread(LPVOID param)
{
CSametimeProto* proto = (CSametimeProto*)param;
- HANDLE hNetlibUser = proto->m_hNetlibUser;
proto->debugLogW(L"SessionThread() start");
continue_connect = true;
- //setup
+ proto->BroadcastNewStatus(ID_STATUS_CONNECTING);
+
+ // setup
NETLIBOPENCONNECTION conn_data = { 0 };
conn_data.cbSize = sizeof(NETLIBOPENCONNECTION);
conn_data.flags = NLOCF_V2;
@@ -392,10 +393,7 @@ void __cdecl SessionThread(LPVOID param)
conn_data.wPort = proto->options.port;
conn_data.timeout = 20;
conn_data.waitcallback = waitcallback;
-
- proto->BroadcastNewStatus(ID_STATUS_CONNECTING);
-
- proto->server_connection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)hNetlibUser, (LPARAM)&conn_data);
+ proto->server_connection = Netlib_OpenConnection(proto->m_hNetlibUser, &conn_data);
if (!proto->server_connection) {
diff --git a/protocols/Tlen/src/stdafx.h b/protocols/Tlen/src/stdafx.h
index d0b6031d7a..67f085a708 100644
--- a/protocols/Tlen/src/stdafx.h
+++ b/protocols/Tlen/src/stdafx.h
@@ -281,7 +281,7 @@ struct TlenProtocol : public PROTO<TlenProtocol>
int __cdecl MUCHandleEvent(WPARAM wParam, LPARAM lParam);
//====================================================================================
- HANDLE hFileNetlibUser;
+ HNETLIBUSER hFileNetlibUser;
TLEN_MODEMSGS modeMsgs;
diff --git a/protocols/Tlen/src/tlen_file.cpp b/protocols/Tlen/src/tlen_file.cpp
index 11a269f377..dcbc77d8c0 100644
--- a/protocols/Tlen/src/tlen_file.cpp
+++ b/protocols/Tlen/src/tlen_file.cpp
@@ -182,7 +182,7 @@ static void __cdecl TlenFileReceiveThread(void *arg)
nloc.szHost = ft->hostName;
nloc.wPort = ft->wPort;
ProtoBroadcastAck(ft->proto->m_szModuleName, ft->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTING, ft, 0);
- HANDLE s = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)ft->proto->m_hNetlibUser, (LPARAM)&nloc);
+ HANDLE s = Netlib_OpenConnection(ft->proto->m_hNetlibUser, &nloc);
if (s != NULL) {
ft->s = s;
ft->proto->debugLogA("Entering file receive loop");
@@ -481,7 +481,7 @@ static void __cdecl TlenFileSendingThread(void *arg)
NETLIBOPENCONNECTION nloc = { sizeof(nloc) };
nloc.szHost = ft->hostName;
nloc.wPort = ft->wPort;
- HANDLE hConn = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)ft->proto->m_hNetlibUser, (LPARAM)&nloc);
+ HANDLE hConn = Netlib_OpenConnection(ft->proto->m_hNetlibUser, &nloc);
if (hConn != NULL) {
ProtoBroadcastAck(ft->proto->m_szModuleName, ft->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTING, ft, 0);
ft->s = hConn;
diff --git a/protocols/Tlen/src/tlen_p2p_old.cpp b/protocols/Tlen/src/tlen_p2p_old.cpp
index a2265f6e8a..71eee92fc8 100644
--- a/protocols/Tlen/src/tlen_p2p_old.cpp
+++ b/protocols/Tlen/src/tlen_p2p_old.cpp
@@ -300,7 +300,7 @@ static HANDLE TlenP2PBindSocks4(SOCKSBIND * sb, TLEN_FILE_TRANSFER *ft)
NETLIBOPENCONNECTION nloc = { sizeof(nloc) };
nloc.szHost = sb->szHost;
nloc.wPort = sb->wPort;
- HANDLE s = (HANDLE) CallService(MS_NETLIB_OPENCONNECTION, (WPARAM) ft->proto->hFileNetlibUser, (LPARAM) &nloc);
+ HANDLE s = Netlib_OpenConnection(ft->proto->hFileNetlibUser, &nloc);
if (s == NULL) {
// TlenLog("Connection failed (%d), thread ended", WSAGetLastError());
return NULL;
@@ -352,7 +352,7 @@ static HANDLE TlenP2PBindSocks5(SOCKSBIND * sb, TLEN_FILE_TRANSFER *ft)
NETLIBOPENCONNECTION nloc = { sizeof(nloc) };
nloc.szHost = sb->szHost;
nloc.wPort = sb->wPort;
- HANDLE s = (HANDLE) CallService(MS_NETLIB_OPENCONNECTION, (WPARAM) ft->proto->hFileNetlibUser, (LPARAM) &nloc);
+ HANDLE s = Netlib_OpenConnection(ft->proto->hFileNetlibUser, &nloc);
if (s == NULL) {
ft->proto->debugLogA("Connection failed (%d), thread ended", WSAGetLastError());
return NULL;
@@ -443,7 +443,6 @@ static HANDLE TlenP2PBindSocks5(SOCKSBIND * sb, TLEN_FILE_TRANSFER *ft)
HANDLE TlenP2PListen(TLEN_FILE_TRANSFER *ft)
{
- NETLIBBIND nlb = {0};
HANDLE s = NULL;
int useProxy;
DBVARIANT dbv;
@@ -491,13 +490,15 @@ HANDLE TlenP2PListen(TLEN_FILE_TRANSFER *ft)
ft->wLocalPort = sb.wPort;
}
}
+
+ NETLIBBIND nlb = {};
if (useProxy<2) {
nlb.cbSize = sizeof(NETLIBBIND);
nlb.pfnNewConnectionV2 = ft->pfnNewConnectionV2;
nlb.wPort = 0; // Use user-specified incoming port ranges, if available
nlb.pExtra = proto;
ft->proto->debugLogA("Calling MS_NETLIB_BINDPORT");
- s = (HANDLE) CallService(MS_NETLIB_BINDPORT, (WPARAM) ft->proto->m_hNetlibUser, (LPARAM) &nlb);
+ s = Netlib_BindPort(ft->proto->m_hNetlibUser, &nlb);
ft->proto->debugLogA("listening on %d",s);
}
if (useProxy == 0) {
diff --git a/protocols/Tlen/src/tlen_voice.cpp b/protocols/Tlen/src/tlen_voice.cpp
index 6dfb47e3f8..eb52fb034b 100644
--- a/protocols/Tlen/src/tlen_voice.cpp
+++ b/protocols/Tlen/src/tlen_voice.cpp
@@ -292,11 +292,12 @@ static void __cdecl TlenVoiceReceiveThread(void *arg)
TLEN_FILE_TRANSFER *ft = (TLEN_FILE_TRANSFER *)arg;
ft->proto->debugLogA("Thread started: type=file_receive server='%s' port='%d'", ft->hostName, ft->wPort);
+ SetDlgItemText(ft->proto->voiceDlgHWND, IDC_STATUS, TranslateT("...Connecting..."));
+
NETLIBOPENCONNECTION nloc = { sizeof(nloc) };
nloc.szHost = ft->hostName;
nloc.wPort = ft->wPort;
- SetDlgItemText(ft->proto->voiceDlgHWND, IDC_STATUS, TranslateT("...Connecting..."));
- HANDLE s = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)ft->proto->m_hNetlibUser, (LPARAM)&nloc);
+ HANDLE s = Netlib_OpenConnection(ft->proto->m_hNetlibUser, &nloc);
if (s != NULL) {
ft->s = s;
ft->proto->debugLogA("Entering file receive loop");
@@ -548,7 +549,7 @@ static void __cdecl TlenVoiceSendingThread(void *arg)
NETLIBOPENCONNECTION nloc = { sizeof(nloc) };
nloc.szHost = ft->hostName;
nloc.wPort = ft->wPort;
- HANDLE sock = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)ft->proto->m_hNetlibUser, (LPARAM)&nloc);
+ HANDLE sock = Netlib_OpenConnection(ft->proto->m_hNetlibUser, &nloc);
if (sock != NULL) {
SetDlgItemText(ft->proto->voiceDlgHWND, IDC_STATUS, TranslateT("...Connecting..."));
//ProtoBroadcastAck(ft->proto->m_szModuleName, ft->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTING, ft, 0);
diff --git a/protocols/Tlen/src/tlen_ws.cpp b/protocols/Tlen/src/tlen_ws.cpp
index 1bed6c9865..eaa952d33b 100644
--- a/protocols/Tlen/src/tlen_ws.cpp
+++ b/protocols/Tlen/src/tlen_ws.cpp
@@ -42,7 +42,7 @@ BOOL TlenWsInit(TlenProtocol *proto)
NETLIBUSERSETTINGS nlus = {0};
nlus.cbSize = sizeof(nlus);
nlus.useProxy = 0;
- CallService(MS_NETLIB_SETUSERSETTINGS, (WPARAM) proto->hFileNetlibUser, (LPARAM) &nlus);
+ Netlib_SetUserSettings(proto->hFileNetlibUser, &nlus);
return (proto->m_hNetlibUser != NULL)?TRUE:FALSE;
}
@@ -57,17 +57,15 @@ void TlenWsUninit(TlenProtocol *proto)
HANDLE TlenWsConnect(TlenProtocol *proto, char *host, WORD port)
{
- NETLIBOPENCONNECTION nloc = {0};
-
+ NETLIBOPENCONNECTION nloc = {};
nloc.cbSize = sizeof(NETLIBOPENCONNECTION); //NETLIBOPENCONNECTION_V1_SIZE;
nloc.szHost = host;
nloc.wPort = port;
nloc.flags = 0;
nloc.timeout = 6;
- return (HANDLE) CallService(MS_NETLIB_OPENCONNECTION, (WPARAM) proto->m_hNetlibUser, (LPARAM) &nloc);
+ return Netlib_OpenConnection(proto->m_hNetlibUser, &nloc);
}
-
int TlenWsSend(TlenProtocol *proto, HANDLE s, char *data, int datalen)
{
int len;
diff --git a/protocols/Tox/src/tox_core.cpp b/protocols/Tox/src/tox_core.cpp
index 89687f69d4..7ac8d3a55b 100644
--- a/protocols/Tox/src/tox_core.cpp
+++ b/protocols/Tox/src/tox_core.cpp
@@ -15,8 +15,8 @@ Tox_Options* CToxProto::GetToxOptions()
if (m_hNetlibUser != NULL)
{
- NETLIBUSERSETTINGS nlus = { sizeof(NETLIBUSERSETTINGS) };
- CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM)m_hNetlibUser, (LPARAM)&nlus);
+ NETLIBUSERSETTINGS nlus = { sizeof(nlus) };
+ Netlib_GetUserSettings(m_hNetlibUser, &nlus);
if (nlus.useProxy)
{
diff --git a/protocols/WhatsApp/src/WASocketConnection.cpp b/protocols/WhatsApp/src/WASocketConnection.cpp
index 78957b21c6..5ba6c781eb 100644
--- a/protocols/WhatsApp/src/WASocketConnection.cpp
+++ b/protocols/WhatsApp/src/WASocketConnection.cpp
@@ -18,7 +18,7 @@ WASocketConnection::WASocketConnection(const std::string &dir, int port) throw (
noc.szHost = dir.c_str();
noc.wPort = port;
noc.flags = NLOCF_V2; // | NLOCF_SSL;
- this->hConn = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, WPARAM(g_hNetlibUser), LPARAM(&noc));
+ this->hConn = Netlib_OpenConnection(g_hNetlibUser, &noc);
if (this->hConn == NULL)
throw WAException(getLastErrorMsg(), WAException::SOCKET_EX, WAException::SOCKET_EX_OPEN);
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index 430ecaa097..4e95863c9f 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -356,3 +356,14 @@ Netlib_LogfW @356
Netlib_GetConnNlu @357
Netlib_RecvHttpHeaders @358
Netlib_HttpTransaction @359
+Netlib_SendHttpRequest @360
+Netlib_GetUserSettings @361
+Netlib_SetUserSettings @362
+Netlib_OpenConnection @363
+Netlib_BindPort @364
+Netlib_Shutdown @365
+Netlib_CreatePacketReceiver @366
+Netlib_GetMorePackets @367
+Netlib_FreeHttpRequest @368
+Netlib_AddressToString @369
+Netlib_StringToAddress @370
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index d3bff9758a..b274d440b7 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -356,3 +356,14 @@ Netlib_LogfW @356
Netlib_GetConnNlu @357
Netlib_RecvHttpHeaders @358
Netlib_HttpTransaction @359
+Netlib_SendHttpRequest @360
+Netlib_GetUserSettings @361
+Netlib_SetUserSettings @362
+Netlib_OpenConnection @363
+Netlib_BindPort @364
+Netlib_Shutdown @365
+Netlib_CreatePacketReceiver @366
+Netlib_GetMorePackets @367
+Netlib_FreeHttpRequest @368
+Netlib_AddressToString @369
+Netlib_StringToAddress @370
diff --git a/src/mir_app/src/netlib.cpp b/src/mir_app/src/netlib.cpp
index 0ae2a3a7d4..cecc32cb5b 100644
--- a/src/mir_app/src/netlib.cpp
+++ b/src/mir_app/src/netlib.cpp
@@ -204,11 +204,8 @@ MIR_APP_DLL(HNETLIBUSER) Netlib_RegisterUser(const NETLIBUSER *nlu)
/////////////////////////////////////////////////////////////////////////////////////////
-static INT_PTR NetlibGetUserSettings(WPARAM wParam, LPARAM lParam)
+MIR_APP_DLL(int) Netlib_GetUserSettings(HNETLIBUSER nlu, NETLIBUSERSETTINGS *nlus)
{
- NETLIBUSERSETTINGS *nlus = (NETLIBUSERSETTINGS*)lParam;
- NetlibUser *nlu = (NetlibUser*)wParam;
-
if (GetNetlibHandleType(nlu) != NLH_USER || nlus == NULL || nlus->cbSize != sizeof(NETLIBUSERSETTINGS)) {
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
@@ -217,11 +214,8 @@ static INT_PTR NetlibGetUserSettings(WPARAM wParam, LPARAM lParam)
return 1;
}
-static INT_PTR NetlibSetUserSettings(WPARAM wParam, LPARAM lParam)
+MIR_APP_DLL(int) Netlib_SetUserSettings(HNETLIBUSER nlu, const NETLIBUSERSETTINGS *nlus)
{
- NETLIBUSERSETTINGS *nlus = (NETLIBUSERSETTINGS*)lParam;
- NetlibUser *nlu = (NetlibUser*)wParam;
-
if (GetNetlibHandleType(nlu) != NLH_USER || nlus == NULL || nlus->cbSize != sizeof(NETLIBUSERSETTINGS)) {
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
@@ -350,22 +344,6 @@ static INT_PTR NetlibGetSocket(WPARAM wParam, LPARAM)
/////////////////////////////////////////////////////////////////////////////////////////
-INT_PTR NetlibStringToAddressSrv(WPARAM wParam, LPARAM lParam)
-{
- return (INT_PTR)!NetlibStringToAddress((char*)wParam, (SOCKADDR_INET_M*)lParam);
-}
-
-INT_PTR NetlibAddressToStringSrv(WPARAM wParam, LPARAM lParam)
-{
- if (wParam) {
- SOCKADDR_INET_M iaddr = {0};
- iaddr.Ipv4.sin_family = AF_INET;
- iaddr.Ipv4.sin_addr.s_addr = htonl((unsigned)lParam);
- return (INT_PTR)NetlibAddressToString(&iaddr);
- }
- return (INT_PTR)NetlibAddressToString((SOCKADDR_INET_M*)lParam);
-}
-
INT_PTR NetlibGetConnectionInfoSrv(WPARAM wParam, LPARAM lParam)
{
NetlibGetConnectionInfo((NetlibConnection*)wParam, (NETLIBCONNINFO*)lParam);
@@ -387,14 +365,14 @@ MIR_APP_DLL(HNETLIBUSER) Netlib_GetConnNlu(HANDLE hConn)
/////////////////////////////////////////////////////////////////////////////////////////
-INT_PTR NetlibShutdown(WPARAM wParam, LPARAM)
+MIR_APP_DLL(void) Netlib_Shutdown(HANDLE h)
{
- if (wParam) {
+ if (h) {
WaitForSingleObject(hConnectionHeaderMutex, INFINITE);
- switch(GetNetlibHandleType((void*)wParam)) {
+ switch (GetNetlibHandleType(h)) {
case NLH_CONNECTION:
{
- NetlibConnection *nlc = (NetlibConnection*)wParam;
+ NetlibConnection *nlc = (NetlibConnection*)h;
if (!nlc->termRequested) {
if (nlc->hSsl) sslApi.shutdown(nlc->hSsl);
if (nlc->s != INVALID_SOCKET) shutdown(nlc->s, 2);
@@ -405,14 +383,13 @@ INT_PTR NetlibShutdown(WPARAM wParam, LPARAM)
break;
case NLH_BOUNDPORT:
- struct NetlibBoundPort* nlb = (struct NetlibBoundPort*)wParam;
+ struct NetlibBoundPort *nlb = (NetlibBoundPort*)h;
if (nlb->s != INVALID_SOCKET)
shutdown(nlb->s, 2);
break;
}
ReleaseMutex(hConnectionHeaderMutex);
}
- return 0;
}
void UnloadNetlibModule(void)
@@ -495,23 +472,13 @@ int LoadNetlibModule(void)
hConnectionOpenMutex = connectionTimeout ? CreateMutex(NULL, FALSE, NULL) : NULL;
g_LastConnectionTick = GetTickCount();
- CreateServiceFunction(MS_NETLIB_GETUSERSETTINGS, NetlibGetUserSettings);
- CreateServiceFunction(MS_NETLIB_SETUSERSETTINGS, NetlibSetUserSettings);
- CreateServiceFunction(MS_NETLIB_BINDPORT, NetlibBindPort);
- CreateServiceFunction(MS_NETLIB_OPENCONNECTION, NetlibOpenConnection);
CreateServiceFunction(MS_NETLIB_SETHTTPPROXYINFO, NetlibHttpGatewaySetInfo);
CreateServiceFunction(MS_NETLIB_SETSTICKYHEADERS, NetlibHttpSetSticky);
CreateServiceFunction(MS_NETLIB_GETSOCKET, NetlibGetSocket);
- CreateServiceFunction(MS_NETLIB_SENDHTTPREQUEST, NetlibHttpSendRequest);
CreateServiceFunction(MS_NETLIB_SELECT, NetlibSelect);
CreateServiceFunction(MS_NETLIB_SELECTEX, NetlibSelectEx);
- CreateServiceFunction(MS_NETLIB_SHUTDOWN, NetlibShutdown);
- CreateServiceFunction(MS_NETLIB_CREATEPACKETRECVER, NetlibPacketRecverCreate);
- CreateServiceFunction(MS_NETLIB_GETMOREPACKETS, NetlibPacketRecverGetMore);
CreateServiceFunction(MS_NETLIB_SETPOLLINGTIMEOUT, NetlibHttpSetPollingTimeout);
CreateServiceFunction(MS_NETLIB_STARTSSL, NetlibStartSsl);
- CreateServiceFunction(MS_NETLIB_STRINGTOADDRESS, NetlibStringToAddressSrv);
- CreateServiceFunction(MS_NETLIB_ADDRESSTOSTRING, NetlibAddressToStringSrv);
CreateServiceFunction(MS_NETLIB_GETCONNECTIONINFO, NetlibGetConnectionInfoSrv);
CreateServiceFunction(MS_NETLIB_GETMYIP, NetlibGetMyIp);
diff --git a/src/mir_app/src/netlib.h b/src/mir_app/src/netlib.h
index c327339945..28c1b549d0 100644
--- a/src/mir_app/src/netlib.h
+++ b/src/mir_app/src/netlib.h
@@ -58,11 +58,12 @@ struct NetlibHTTPProxyPacketQueue
int dataBufferLen;
};
-typedef union _SOCKADDR_INET_M {
+union SOCKADDR_INET_M
+{
SOCKADDR_IN Ipv4;
SOCKADDR_IN6 Ipv6;
USHORT si_family;
-} SOCKADDR_INET_M, *PSOCKADDR_INET_M;
+};
class NetlibBinBuffer
{
@@ -167,7 +168,8 @@ struct NetlibConnection : public MZeroedObject
unsigned lastPost;
};
-struct NetlibBoundPort {
+struct NetlibBoundPort
+{
int handleType;
SOCKET s;
SOCKET s6;
@@ -179,7 +181,8 @@ struct NetlibBoundPort {
void *pExtra;
};
-struct NetlibPacketRecver {
+struct NetlibPacketRecver
+{
int handleType;
NetlibConnection *nlc;
NETLIBPACKETRECVER packetRecver;
@@ -209,11 +212,9 @@ bool NetlibGetIeProxyConn(NetlibConnection *nlc, bool forceHttps);
// netlibbind.c
int NetlibFreeBoundPort(NetlibBoundPort *nlbp);
-INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam);
bool BindSocketToPort(const char *szPorts, SOCKET s, SOCKET s6, int* portn);
// netlibhttp.c
-INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam);
void NetlibHttpSetLastErrorUsingHttpResult(int result);
NETLIBHTTPREQUEST* NetlibHttpRecv(NetlibConnection* nlc, DWORD hflags, DWORD dflags, bool isConnect = false);
void NetlibConnFromUrl(const char* szUrl, bool secur, NETLIBOPENCONNECTION &nloc);
@@ -240,16 +241,11 @@ 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 NetlibOpenConnection(WPARAM wParam, LPARAM lParam);
INT_PTR NetlibStartSsl(WPARAM wParam, LPARAM lParam);
// netlibopts.c
int NetlibOptInitialise(WPARAM wParam, LPARAM lParam);
-void NetlibSaveUserSettingsStruct(const char *szSettingsModule, NETLIBUSERSETTINGS *settings);
-
-// netlibpktrecver.c
-INT_PTR NetlibPacketRecverCreate(WPARAM wParam, LPARAM lParam);
-INT_PTR NetlibPacketRecverGetMore(WPARAM wParam, LPARAM lParam);
+void NetlibSaveUserSettingsStruct(const char *szSettingsModule, const NETLIBUSERSETTINGS *settings);
// netlibsock.c
#define NL_SELECT_READ 0x0001
@@ -258,10 +254,7 @@ INT_PTR NetlibPacketRecverGetMore(WPARAM wParam, LPARAM lParam);
INT_PTR NetlibSelect(WPARAM wParam, LPARAM lParam);
INT_PTR NetlibSelectEx(WPARAM wParam, LPARAM lParam);
-INT_PTR NetlibShutdown(WPARAM wParam, LPARAM lParam);
-bool NetlibStringToAddress(const char* str, SOCKADDR_INET_M* addr);
-char* NetlibAddressToString(SOCKADDR_INET_M* addr);
void NetlibGetConnectionInfo(NetlibConnection* nlc, NETLIBCONNINFO *connInfo);
NETLIBIPLIST* GetMyIp(unsigned flags);
diff --git a/src/mir_app/src/netlibbind.cpp b/src/mir_app/src/netlibbind.cpp
index 802c51b561..b5dcc6b6c3 100644
--- a/src/mir_app/src/netlibbind.cpp
+++ b/src/mir_app/src/netlibbind.cpp
@@ -137,7 +137,7 @@ static void NetlibBindAcceptThread(void* param)
break;
}
- SOCKADDR_INET_M sin;
+ sockaddr_in sin;
int sinLen = sizeof(sin);
memset(&sin, 0, sizeof(sin));
@@ -158,14 +158,14 @@ static void NetlibBindAcceptThread(void* param)
}
else s = NULL;
- Netlib_Logf(nlbp->nlu, "New incoming connection on port %u from %s (%p)", nlbp->wPort, ptrA(NetlibAddressToString(&sin)), s);
+ Netlib_Logf(nlbp->nlu, "New incoming connection on port %u from %s (%p)", nlbp->wPort, ptrA(Netlib_AddressToString(&sin)), s);
NetlibConnection *nlc = new NetlibConnection();
nlc->nlu = nlbp->nlu;
nlc->s = s;
if (nlbp->pfnNewConnectionV2)
- nlbp->pfnNewConnectionV2(nlc, ntohl(sin.Ipv4.sin_addr.S_un.S_addr), nlbp->pExtra);
+ nlbp->pfnNewConnectionV2(nlc, ntohl(sin.sin_addr.S_un.S_addr), nlbp->pExtra);
}
NetlibUPnPDeletePortMapping(nlbp->wExPort, "TCP");
@@ -174,15 +174,8 @@ static void NetlibBindAcceptThread(void* param)
Netlib_Logf(nlbp->nlu, "NetlibBindAcceptThread: (%p) thread for port %u closed", nlbp->s, nlbp->wPort);
}
-INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam)
+MIR_APP_DLL(HANDLE) Netlib_BindPort(HNETLIBUSER nlu, NETLIBBIND *nlb)
{
- NETLIBBIND *nlb = (NETLIBBIND*)lParam;
- NetlibUser *nlu = (NetlibUser*)wParam;
- struct NetlibBoundPort *nlbp;
- SOCKADDR_IN sin = { 0 };
- SOCKADDR_IN6 sin6 = { 0 };
- int foundPort = 0;
-
if (GetNetlibHandleType(nlu) != NLH_USER || !(nlu->user.flags & NUF_INCOMING) ||
nlb == NULL || nlb->pfnNewConnection == NULL) {
SetLastError(ERROR_INVALID_PARAMETER);
@@ -191,7 +184,7 @@ INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam)
if (nlb->cbSize != sizeof(NETLIBBIND))
return 0;
- nlbp = (NetlibBoundPort*)mir_calloc(sizeof(NetlibBoundPort));
+ NetlibBoundPort *nlbp = (NetlibBoundPort*)mir_calloc(sizeof(NetlibBoundPort));
nlbp->handleType = NLH_BOUNDPORT;
nlbp->nlu = nlu;
nlbp->pfnNewConnectionV2 = nlb->pfnNewConnectionV2;
@@ -204,11 +197,16 @@ INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam)
mir_free(nlbp);
return 0;
}
+
+ SOCKADDR_IN sin = { 0 };
sin.sin_family = AF_INET;
+
+ SOCKADDR_IN6 sin6 = { 0 };
sin6.sin6_family = AF_INET6;
/* if the netlib user wanted a free port given in the range, then
they better have given wPort == 0, let's hope so */
+ int foundPort = 0;
if (nlu->settings.specifyIncomingPorts && nlu->settings.szIncomingPorts && nlb->wPort == 0) {
if (!BindSocketToPort(nlu->settings.szIncomingPorts, nlbp->s, nlbp->s6, &nlu->outportnum)) {
Netlib_Logf(nlu, "Netlib bind: Not enough ports for incoming connections specified");
@@ -298,5 +296,5 @@ LBL_Error:
}
nlbp->hThread = mir_forkthread(NetlibBindAcceptThread, nlbp);
- return (INT_PTR)nlbp;
+ return nlbp;
}
diff --git a/src/mir_app/src/netlibhttp.cpp b/src/mir_app/src/netlibhttp.cpp
index 3ff0e83ba4..d9f33aa3c0 100644
--- a/src/mir_app/src/netlibhttp.cpp
+++ b/src/mir_app/src/netlibhttp.cpp
@@ -191,7 +191,7 @@ static NetlibConnection* NetlibHttpProcessUrl(NETLIBHTTPREQUEST *nlhr, NetlibUse
return NetlibDoConnect(nlc) ? nlc : NULL;
}
}
- else nlc = (NetlibConnection*)NetlibOpenConnection((WPARAM)nlu, (LPARAM)&nloc);
+ else nlc = (NetlibConnection*)Netlib_OpenConnection(nlu, &nloc);
mir_free((char*)nloc.szHost);
@@ -367,10 +367,9 @@ static int SendHttpRequestAndData(NetlibConnection *nlc, CMStringA &httpRequest,
return bytesSent;
}
-INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam)
+MIR_APP_DLL(int) Netlib_SendHttpRequest(HANDLE hConnection, NETLIBHTTPREQUEST *nlhr)
{
- NetlibConnection *nlc = (NetlibConnection*)wParam;
- NETLIBHTTPREQUEST *nlhr = (NETLIBHTTPREQUEST*)lParam;
+ NetlibConnection *nlc = (NetlibConnection*)hConnection;
NETLIBHTTPREQUEST *nlhrReply = NULL;
HttpSecurityContext httpSecurity;
@@ -486,7 +485,7 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam)
// HTTP headers
doneHostHeader = doneContentLengthHeader = doneProxyAuthHeader = doneAuthHeader = 0;
- for (i=0; i < nlhr->headersCount; i++) {
+ for (i = 0; i < nlhr->headersCount; i++) {
NETLIBHTTPHEADER &p = nlhr->headers[i];
if (!mir_strcmpi(p.szName, "Host")) doneHostHeader = 1;
else if (!mir_strcmpi(p.szName, "Content-Length")) doneContentLengthHeader = 1;
@@ -867,7 +866,7 @@ MIR_APP_DLL(NETLIBHTTPREQUEST*) Netlib_HttpTransaction(HNETLIBUSER nlu, NETLIBHT
nlhrSend.headers[nlhrSend.headersCount].szValue = "deflate, gzip";
++nlhrSend.headersCount;
}
- if (NetlibHttpSendRequest((WPARAM)nlc, (LPARAM)&nlhrSend) == SOCKET_ERROR) {
+ if (Netlib_SendHttpRequest(nlc, &nlhrSend) == SOCKET_ERROR) {
if (!doneUserAgentHeader || !doneAcceptEncoding) mir_free(nlhrSend.headers);
nlhr->resultCode = nlhrSend.resultCode;
Netlib_CloseHandle(nlc);
diff --git a/src/mir_app/src/netlibhttpproxy.cpp b/src/mir_app/src/netlibhttpproxy.cpp
index db4cdcb70e..f1535da21a 100644
--- a/src/mir_app/src/netlibhttpproxy.cpp
+++ b/src/mir_app/src/netlibhttpproxy.cpp
@@ -131,7 +131,7 @@ static bool NetlibHttpGatewaySend(NetlibConnection *nlc, RequestType reqType, co
nlhrSend.headers[1].szValue = "no-cache, no-store ";
nlhrSend.headers[2].szName = "Pragma";
nlhrSend.headers[2].szValue = "no-cache";
- return NetlibHttpSendRequest((WPARAM)nlc, (LPARAM)&nlhrSend) != SOCKET_ERROR;
+ return Netlib_SendHttpRequest(nlc, &nlhrSend) != SOCKET_ERROR;
}
static bool NetlibHttpGatewayStdPost(NetlibConnection *nlc, int &numPackets)
diff --git a/src/mir_app/src/netlibopenconn.cpp b/src/mir_app/src/netlibopenconn.cpp
index de29ab3b44..a044afba46 100644
--- a/src/mir_app/src/netlibopenconn.cpp
+++ b/src/mir_app/src/netlibopenconn.cpp
@@ -312,7 +312,7 @@ static bool NetlibInitHttpsConnection(NetlibConnection *nlc, NetlibUser *nlu, NE
nlc->usingHttpGateway = true;
- if (NetlibHttpSendRequest((WPARAM)nlc, (LPARAM)&nlhrSend) == SOCKET_ERROR) {
+ if (Netlib_SendHttpRequest(nlc, &nlhrSend) == SOCKET_ERROR) {
nlc->usingHttpGateway = false;
return false;
}
@@ -371,7 +371,7 @@ static bool my_connectIPv4(NetlibConnection *nlc, NETLIBOPENCONNECTION *nloc)
}
PHOSTENT he;
- SOCKADDR_IN sin = { 0 };
+ sockaddr_in sin = { 0 };
sin.sin_family = AF_INET;
if (nlc->proxyType) {
@@ -396,7 +396,7 @@ static bool my_connectIPv4(NetlibConnection *nlc, NETLIBOPENCONNECTION *nloc)
for (char** har = he->h_addr_list; *har && !Miranda_IsTerminated(); ++har) {
sin.sin_addr.s_addr = *(u_long*)*har;
- char* szIp = NetlibAddressToString((SOCKADDR_INET_M*)&sin);
+ char *szIp = Netlib_AddressToString(&sin);
Netlib_Logf(nlc->nlu, "(%p) Connecting to ip %s ....", nlc, szIp);
mir_free(szIp);
@@ -554,7 +554,7 @@ static bool my_connectIPv6(NetlibConnection *nlc, NETLIBOPENCONNECTION *nloc)
}
for (ai = air; ai && !Miranda_IsTerminated(); ai = ai->ai_next) {
- Netlib_Logf(nlc->nlu, "(%p) Connecting to ip %s ....", nlc, ptrA(NetlibAddressToString((SOCKADDR_INET_M*)ai->ai_addr)));
+ Netlib_Logf(nlc->nlu, "(%p) Connecting to ip %s ....", nlc, ptrA(Netlib_AddressToString((sockaddr_in*)ai->ai_addr)));
retry:
nlc->s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (nlc->s == INVALID_SOCKET) {
@@ -816,17 +816,16 @@ bool NetlibReconnect(NetlibConnection *nlc)
return true;
}
-INT_PTR NetlibOpenConnection(WPARAM wParam, LPARAM lParam)
+MIR_APP_DLL(HANDLE) Netlib_OpenConnection(NetlibUser *nlu, const NETLIBOPENCONNECTION *nloc)
{
- NETLIBOPENCONNECTION *nloc = (NETLIBOPENCONNECTION*)lParam;
if (nloc == NULL || nloc->cbSize != sizeof(NETLIBOPENCONNECTION) || nloc->szHost == NULL || nloc->wPort == 0) {
+
SetLastError(ERROR_INVALID_PARAMETER);
- return 0;
+ return NULL;
}
- NetlibUser *nlu = (NetlibUser*)wParam;
if (GetNetlibHandleType(nlu) != NLH_USER || !(nlu->user.flags & NUF_OUTGOING))
- return 0;
+ return NULL;
Netlib_Logf(nlu, "Connection request to %s:%d (Flags %x)....", nloc->szHost, nloc->wPort, nloc->flags);
@@ -849,7 +848,7 @@ INT_PTR NetlibOpenConnection(WPARAM wParam, LPARAM lParam)
}
}
- return (INT_PTR)nlc;
+ return nlc;
}
INT_PTR NetlibStartSsl(WPARAM wParam, LPARAM lParam)
diff --git a/src/mir_app/src/netlibopts.cpp b/src/mir_app/src/netlibopts.cpp
index f5105941ed..5e66c66d21 100644
--- a/src/mir_app/src/netlibopts.cpp
+++ b/src/mir_app/src/netlibopts.cpp
@@ -93,7 +93,7 @@ static void AddProxyTypeItem(HWND hwndDlg, int type, int selectType)
SendDlgItemMessage(hwndDlg, IDC_PROXYTYPE, CB_SETCURSEL, i, 0);
}
-static void CopySettingsStruct(NETLIBUSERSETTINGS *dest, NETLIBUSERSETTINGS *source)
+static void CopySettingsStruct(NETLIBUSERSETTINGS *dest, const NETLIBUSERSETTINGS *source)
{
*dest = *source;
if (dest->szIncomingPorts) dest->szIncomingPorts = mir_strdup(dest->szIncomingPorts);
@@ -110,8 +110,8 @@ static void CombineSettingsStrings(char **dest, char **source)
static void CombineSettingsStructs(NETLIBUSERSETTINGS *dest, DWORD *destFlags, NETLIBUSERSETTINGS *source, DWORD sourceFlags)
{
- if (sourceFlags&NUF_OUTGOING) {
- if (*destFlags&NUF_OUTGOING) {
+ if (sourceFlags & NUF_OUTGOING) {
+ if (*destFlags & NUF_OUTGOING) {
if (dest->validateSSL != source->validateSSL) dest->validateSSL = 2;
if (dest->useProxy != source->useProxy) dest->useProxy = 2;
if (dest->proxyType != source->proxyType) dest->proxyType = 0;
@@ -142,8 +142,8 @@ static void CombineSettingsStructs(NETLIBUSERSETTINGS *dest, DWORD *destFlags, N
if (dest->szOutgoingPorts) dest->szOutgoingPorts = mir_strdup(dest->szOutgoingPorts);
}
}
- if (sourceFlags&NUF_INCOMING) {
- if (*destFlags&NUF_INCOMING) {
+ if (sourceFlags & NUF_INCOMING) {
+ if (*destFlags & NUF_INCOMING) {
if (dest->enableUPnP != source->enableUPnP) dest->enableUPnP = 2;
if (dest->specifyIncomingPorts != source->specifyIncomingPorts) dest->specifyIncomingPorts = 2;
CombineSettingsStrings(&dest->szIncomingPorts, &source->szIncomingPorts);
@@ -155,8 +155,8 @@ static void CombineSettingsStructs(NETLIBUSERSETTINGS *dest, DWORD *destFlags, N
if (dest->szIncomingPorts) dest->szIncomingPorts = mir_strdup(dest->szIncomingPorts);
}
}
- if ((*destFlags&NUF_NOHTTPSOPTION) != (sourceFlags&NUF_NOHTTPSOPTION))
- *destFlags = (*destFlags | sourceFlags)&~NUF_NOHTTPSOPTION;
+ if ((*destFlags & NUF_NOHTTPSOPTION) != (sourceFlags & NUF_NOHTTPSOPTION))
+ *destFlags = (*destFlags | sourceFlags) & ~NUF_NOHTTPSOPTION;
else *destFlags |= sourceFlags;
}
@@ -220,7 +220,7 @@ static void WriteSettingsStructToDb(const char *szSettingsModule, NETLIBUSERSETT
}
}
-void NetlibSaveUserSettingsStruct(const char *szSettingsModule, NETLIBUSERSETTINGS *settings)
+void NetlibSaveUserSettingsStruct(const char *szSettingsModule, const NETLIBUSERSETTINGS *settings)
{
mir_cslock lck(csNetlibUser);
diff --git a/src/mir_app/src/netlibpktrecver.cpp b/src/mir_app/src/netlibpktrecver.cpp
index fafee80be3..c7d90dc058 100644
--- a/src/mir_app/src/netlibpktrecver.cpp
+++ b/src/mir_app/src/netlibpktrecver.cpp
@@ -25,36 +25,28 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
#include "netlib.h"
-INT_PTR NetlibPacketRecverCreate(WPARAM wParam, LPARAM lParam)
+MIR_APP_DLL(HANDLE) Netlib_CreatePacketReceiver(HANDLE hConnection, int iMaxSize)
{
- NetlibConnection *nlc = (NetlibConnection*)wParam;
- struct NetlibPacketRecver *nlpr;
-
- if (GetNetlibHandleType(nlc) != NLH_CONNECTION || lParam == 0) {
+ NetlibConnection *nlc = (NetlibConnection*)hConnection;
+ if (GetNetlibHandleType(nlc) != NLH_CONNECTION || iMaxSize == 0) {
SetLastError(ERROR_INVALID_PARAMETER);
- return (INT_PTR)(struct NetlibPacketRecver*)NULL;
- }
- nlpr = (struct NetlibPacketRecver*)mir_calloc(sizeof(struct NetlibPacketRecver));
- if (nlpr == NULL) {
- SetLastError(ERROR_OUTOFMEMORY);
- return (INT_PTR)(struct NetlibPacketRecver*)NULL;
+ return NULL;
}
+
+ NetlibPacketRecver *nlpr = (struct NetlibPacketRecver*)mir_calloc(sizeof(struct NetlibPacketRecver));
nlpr->handleType = NLH_PACKETRECVER;
nlpr->nlc = nlc;
- nlpr->packetRecver.cbSize = sizeof(nlpr->packetRecver);
- nlpr->packetRecver.bufferSize = lParam;
+ nlpr->packetRecver.bufferSize = iMaxSize;
nlpr->packetRecver.buffer = (PBYTE)mir_alloc(nlpr->packetRecver.bufferSize);
nlpr->packetRecver.bytesUsed = 0;
nlpr->packetRecver.bytesAvailable = 0;
- return (INT_PTR)nlpr;
+ return nlpr;
}
-INT_PTR NetlibPacketRecverGetMore(WPARAM wParam, LPARAM lParam)
+MIR_APP_DLL(int) Netlib_GetMorePackets(HANDLE hReceiver, NETLIBPACKETRECVER *nlprParam)
{
- struct NetlibPacketRecver *nlpr = (struct NetlibPacketRecver*)wParam;
- NETLIBPACKETRECVER *nlprParam = (NETLIBPACKETRECVER*)lParam;
-
- if (GetNetlibHandleType(nlpr) != NLH_PACKETRECVER || nlprParam == NULL || nlprParam->cbSize != sizeof(NETLIBPACKETRECVER) || nlprParam->bytesUsed > nlpr->packetRecver.bytesAvailable) {
+ NetlibPacketRecver *nlpr = (NetlibPacketRecver*)hReceiver;
+ if (GetNetlibHandleType(nlpr) != NLH_PACKETRECVER || nlprParam == NULL || nlprParam->bytesUsed > nlpr->packetRecver.bytesAvailable) {
SetLastError(ERROR_INVALID_PARAMETER);
return SOCKET_ERROR;
}
diff --git a/src/mir_app/src/netlibsock.cpp b/src/mir_app/src/netlibsock.cpp
index 34d1739103..e63ef33ef1 100644
--- a/src/mir_app/src/netlibsock.cpp
+++ b/src/mir_app/src/netlibsock.cpp
@@ -190,7 +190,7 @@ INT_PTR NetlibSelectEx(WPARAM, LPARAM lParam)
return rc;
}
-bool NetlibStringToAddress(const char* str, SOCKADDR_INET_M* addr)
+MIR_APP_DLL(bool) Netlib_StringToAddress(const char *str, SOCKADDR_INET_M *addr)
{
if (!str) return false;
@@ -198,17 +198,17 @@ bool NetlibStringToAddress(const char* str, SOCKADDR_INET_M* addr)
return !WSAStringToAddressA((char*)str, AF_INET6, NULL, (PSOCKADDR)addr, &len);
}
-char* NetlibAddressToString(SOCKADDR_INET_M* addr)
+MIR_APP_DLL(char*) Netlib_AddressToString(sockaddr_in *addr)
{
char saddr[128];
DWORD len = sizeof(saddr);
if (!WSAAddressToStringA((PSOCKADDR)addr, sizeof(*addr), NULL, saddr, &len))
return mir_strdup(saddr);
- if (addr->si_family == AF_INET) {
- char *szIp = inet_ntoa(addr->Ipv4.sin_addr);
- if (addr->Ipv4.sin_port != 0) {
- mir_snprintf(saddr, "%s:%d", szIp, htons(addr->Ipv4.sin_port));
+ if (addr->sin_family == AF_INET) {
+ char *szIp = inet_ntoa(addr->sin_addr);
+ if (addr->sin_port != 0) {
+ mir_snprintf(saddr, "%s:%d", szIp, htons(addr->sin_port));
return mir_strdup(saddr);
}
return mir_strdup(szIp);
@@ -220,12 +220,12 @@ void NetlibGetConnectionInfo(NetlibConnection *nlc, NETLIBCONNINFO *connInfo)
{
if (!nlc || !connInfo || connInfo->cbSize < sizeof(NETLIBCONNINFO)) return;
- SOCKADDR_INET_M sin = { 0 };
+ sockaddr_in sin = { 0 };
int len = sizeof(sin);
if (!getsockname(nlc->s, (PSOCKADDR)&sin, &len)) {
- connInfo->wPort = ntohs(sin.Ipv4.sin_port);
- connInfo->dwIpv4 = sin.si_family == AF_INET ? htonl(sin.Ipv4.sin_addr.s_addr) : 0;
- strncpy_s(connInfo->szIpPort, ptrA(NetlibAddressToString(&sin)), _TRUNCATE);
+ connInfo->wPort = ntohs(sin.sin_port);
+ connInfo->dwIpv4 = sin.sin_family == AF_INET ? htonl(sin.sin_addr.s_addr) : 0;
+ strncpy_s(connInfo->szIpPort, ptrA(Netlib_AddressToString(&sin)), _TRUNCATE);
}
}
@@ -258,12 +258,9 @@ static NETLIBIPLIST* GetMyIpv6(unsigned flags)
unsigned i = 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))))
- {
- char *szIp = NetlibAddressToString(iaddr);
+ 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)))) {
+ char *szIp = Netlib_AddressToString((sockaddr_in*)iaddr);
if (szIp)
strncpy_s(addr->szIp[i++], szIp, _TRUNCATE);
mir_free(szIp);