diff options
author | George Hazan <ghazan@miranda.im> | 2017-01-11 19:51:30 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-01-11 19:51:30 +0300 |
commit | bb03623fd3ba7b9cc456da2c9504bad87b80ace0 (patch) | |
tree | a48d6ead0275d8b8e34815e20c22c64dcb30538a | |
parent | e004a33b7853108b49f77ced20a460b3c8b78c35 (diff) |
- Netlib_Send & Netlib_Recv helpers became real functions, MS_NETLIB_SEND & MS_NETLIB_RECV died;
- fix for dumping chunked http replies into a network log
31 files changed, 131 insertions, 269 deletions
diff --git a/bin10/lib/mir_app.lib b/bin10/lib/mir_app.lib Binary files differindex d3189234bb..ce0d8b07db 100644 --- a/bin10/lib/mir_app.lib +++ b/bin10/lib/mir_app.lib diff --git a/bin10/lib/mir_app64.lib b/bin10/lib/mir_app64.lib Binary files differindex 7bb2057b6e..03c4754582 100644 --- a/bin10/lib/mir_app64.lib +++ b/bin10/lib/mir_app64.lib diff --git a/bin12/lib/mir_app.lib b/bin12/lib/mir_app.lib Binary files differindex d3189234bb..ce0d8b07db 100644 --- a/bin12/lib/mir_app.lib +++ b/bin12/lib/mir_app.lib diff --git a/bin12/lib/mir_app64.lib b/bin12/lib/mir_app64.lib Binary files differindex 7bb2057b6e..03c4754582 100644 --- a/bin12/lib/mir_app64.lib +++ b/bin12/lib/mir_app64.lib diff --git a/bin14/lib/mir_app.lib b/bin14/lib/mir_app.lib Binary files differindex d3189234bb..ce0d8b07db 100644 --- a/bin14/lib/mir_app.lib +++ b/bin14/lib/mir_app.lib diff --git a/bin14/lib/mir_app64.lib b/bin14/lib/mir_app64.lib Binary files differindex 7bb2057b6e..03c4754582 100644 --- a/bin14/lib/mir_app64.lib +++ b/bin14/lib/mir_app64.lib diff --git a/include/delphi/m_helpers.inc b/include/delphi/m_helpers.inc index 3e9d70b32f..0c98ecd947 100644 --- a/include/delphi/m_helpers.inc +++ b/include/delphi/m_helpers.inc @@ -16,11 +16,6 @@ function CreateVersionStringPlugin(pluginInfo:PPluginInfoEx;buf:PAnsiChar):PAnsi function PLUGIN_MAKE_VERSION(a,b,c,d: Cardinal): int;
function PLUGIN_CMP_VERSION(verA: LongInt; verB: LongInt): int;
-function Netlib_CloseHandle(Handle: THANDLE): int;
-function Netlib_GetBase64DecodedBufferSize(const cchEncoded: int): int;
-function Netlib_GetBase64EncodedBufferSize(const cbDecoded: int): int;
-function Netlib_Send(hConn: THANDLE; const buf: PAnsiChar; len: int; flags: int): int_ptr;
-function Netlib_Recv(hConn: THANDLE; const buf: PAnsiChar; len: int; flags: int): int_ptr;
procedure Netlib_Log(hNetLib: THANDLE; const sz: PAnsiChar);
function mir_hashstr (const key:PAnsiChar):uint; {inline;}
@@ -178,44 +173,6 @@ begin Inc(Result, (verA and $FF000000) - (verB and $FF000000));
end;
-function Netlib_CloseHandle(Handle: THANDLE): int;
- {$IFDEF AllowInline}inline;{$ENDIF}
-begin
- Result := CallService(MS_NETLIB_CLOSEHANDLE, Handle, 0);
-end;
-
-function Netlib_GetBase64DecodedBufferSize(const cchEncoded: int): int;
- {$IFDEF AllowInline}inline;{$ENDIF}
-begin
- Result := (cchEncoded shr 2) * 3;
-end;
-
-function Netlib_GetBase64EncodedBufferSize(const cbDecoded: int): int;
- {$IFDEF AllowInline}inline;{$ENDIF}
-begin
- Result := (cbDecoded * 4+11) div 12*4+1;
-end;
-
-function Netlib_Send(hConn: THANDLE; const buf: PAnsiChar; len: int; flags: int): int_ptr;
-var
- nlb: TNETLIBBUFFER;
-begin
- nlb.buf := buf;
- nlb.len := len;
- nlb.flags := flags;
- Result := CallService(MS_NETLIB_SEND, wParam(hConn), lParam(@nlb));
-end;
-
-function Netlib_Recv(hConn: THANDLE; const buf: PAnsiChar; len: int; flags: int): int_ptr;
-var
- nlb: TNETLIBBUFFER;
-begin
- nlb.buf := buf;
- nlb.len := len;
- nlb.flags := flags;
- Result := CallService(MS_NETLIB_RECV, wParam(hConn), lParam(@nlb));
-end;
-
procedure Netlib_Log(hNetLib: THANDLE; const sz: PAnsiChar);
{$IFDEF AllowInline}inline;{$ENDIF}
begin
diff --git a/include/delphi/m_netlib.inc b/include/delphi/m_netlib.inc index edbf277804..3a9512cb49 100644 --- a/include/delphi/m_netlib.inc +++ b/include/delphi/m_netlib.inc @@ -313,27 +313,6 @@ const }
MS_NETLIB_REGISTERUSER:PAnsiChar = 'Netlib/RegisterUser';
-{
- Assign a Netlib user handle a set of dynamic HTTP headers to be used with all
-
- HTTP connections that enable the HTTP-use-sticky headers flag.
- The headers persist until cleared with lParam=NULL.
-
- All memory should be allocated by the caller using malloc() from MS_SYSTEM_GET_MMI
- Once it has passed to Netlib, Netlib is the owner of it, the caller should not refer to the memory
- In any way after this point.
-
- wParam=(WPARAM)hNetLibUser
- lParam=(LPARAM)(AnsiChar*)szHeaders
-
- NOTE: The szHeaders parameter should be a NULL terminated string following the HTTP header syntax.
- This string will be injected verbatim, thus the user should be aware of setting strings that are not
- headers. This service is NOT THREAD SAFE, only a single thread is expected to set the headers and a single
- thread reading the pointer internally, stopping race conditions and mutual exclusion don't happen.
-
- Version 0.3.2a+ (2003/10/27)
-}
- MS_NETLIB_SETSTICKYHEADERS:PAnsiChar = 'Netlib/SetStickyHeaders';
{
wParam : HANDLE
@@ -348,20 +327,6 @@ const Errors : ERROR_INVALID_PARAMETER
}
MS_NETLIB_GETUSERSETTINGS:PAnsiChar = 'Netlib/GetUserSettings';
-
- {
- wParam : HANDLE
- lParam : Pointer to a initalised NETLIBUSERSETTINGS structure
- Affect : Changes the configurable settings for a Netlib user -- see notes
- Returns: [non zero] on success, NULL(0) on failure
- Notes : This service is only really useful for people that specify NUF_NOOPTIONS
- when registering and want to create their own options.
- Settings will be stored even if the option to enable it, is it not enabled,
- e.g. useProxyAuth is 0, szProxyAuthPassword will still be saved
- Errors : ERROR_INVALID_PARAMETER
- }
- MS_NETLIB_SETUSERSETTINGS:PAnsiChar = 'Netlib/SetUserSettings';
-
{
wParam : HANDLE / SOCKET
lParam : 0
@@ -371,7 +336,8 @@ const If a SOCKET type is passed instead of netlib handle type, it is closed
Errors : ERROR_INVALID_PARAMETER
}
- MS_NETLIB_CLOSEHANDLE:PAnsiChar = 'Netlib/CloseHandle';
+
+function Netlib_CloseHandle(pHandle:THANDLE) : int; stdcall; external AppDll;
{
wParam : HANDLE
@@ -390,6 +356,8 @@ const Errors : ERROR_INVALID_PARAMETER, any returned by socket(), bind(), listen()
getsockname()
}
+
+const
MS_NETLIB_BINDPORT:PAnsiChar = 'Netlib/BindPort';
{
@@ -602,8 +570,6 @@ const MS_NETLIB_HTTPTRANSACTION:PAnsiChar = 'Netlib/HttpTransaction';
{
- wParam : HANDLE
- lParam : Pointer to an initialised TNETLIBBUFFER structure
Affect : Send data over an open connection see notes
Returns: The number of bytes sent on success, SOCKET_ERROR on failure
Notes : see Netlib_Send() helper function
@@ -613,11 +579,10 @@ const (HTTP proxy): ERROR_GEN_FAILURE (http result code wasn't 2xx)
MS_NETLIB_SENDHTTPREQUEST, MS_NETLIB_RECVHTTPHEADERS
}
- MS_NETLIB_SEND:PAnsiChar = 'Netlib/Send';
+
+function Netlib_Send(hConn:THANDLE; pBuf:Pointer; len,flags:int) : int; stdcall; external AppDll;
{
- wParam : HANDLE
- lParam : Pointer to an initialised TNETLIBBUFFER structure
Affect : Receive data over a connection, see notes
Returns: The number of bytes read on success, SOCKET_ERROR on failure
Notes :
@@ -646,7 +611,8 @@ const connect(), MS_NETLIB_SENDHTTPREQUEST
}
- MS_NETLIB_RECV:PAnsiChar = 'Netlib/Recv';
+
+function Netlib_Recv(hConn:THANDLE; pBuf:Pointer; len,flags:int) : int; stdcall; external AppDll;
{
wParam : 0
@@ -659,6 +625,7 @@ const 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
diff --git a/include/m_netlib.h b/include/m_netlib.h index 1daf530be5..51b18adc48 100644 --- a/include/m_netlib.h +++ b/include/m_netlib.h @@ -61,7 +61,7 @@ struct NETLIBOPENCONNECTION; typedef int (*NETLIBHTTPGATEWAYINITPROC)(HANDLE hConn, NETLIBOPENCONNECTION *nloc, NETLIBHTTPREQUEST *nlhr);
typedef int (*NETLIBHTTPGATEWAYBEGINPROC)(HANDLE hConn, NETLIBOPENCONNECTION *nloc);
-typedef int (*NETLIBHTTPGATEWAYWRAPSENDPROC)(HANDLE hConn, PBYTE buf, int len, int flags, MIRANDASERVICE pfnNetlibSend);
+typedef int (*NETLIBHTTPGATEWAYWRAPSENDPROC)(HANDLE hConn, PBYTE buf, int len, int flags);
typedef PBYTE (*NETLIBHTTPGATEWAYUNWRAPRECVPROC)(NETLIBHTTPREQUEST *nlhr, PBYTE buf, int len, int *outBufLen, void *(*NetlibRealloc)(void*, size_t));
struct NETLIBUSER
@@ -223,18 +223,13 @@ struct NETLIBUSERSETTINGS #define MS_NETLIB_SETUSERSETTINGS "Netlib/SetUserSettings"
// Closes a netlib handle
-// wParam = (WPARAM)(HANDLE)hNetlibHandle
-// lParam = 0
// 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
// socket will be closed.
// Errors: ERROR_INVALID_PARAMETER
-#define MS_NETLIB_CLOSEHANDLE "Netlib/CloseHandle"
-__forceinline INT_PTR Netlib_CloseHandle(HANDLE h)
-{ return CallService(MS_NETLIB_CLOSEHANDLE, (WPARAM)h, 0);
-}
+EXTERN_C MIR_APP_DLL(int) Netlib_CloseHandle(HANDLE h);
/////////////////////////////////////////////////////////////////////////////////////////
// Open a port and wait for connections on it
@@ -599,8 +594,7 @@ public: /////////////////////////////////////////////////////////////////////////////////////////
// Send data over a connection
-// wParam = (WPARAM)(HANDLE)hConnection
-// lParam = (LPARAM)(NETLIBBUFFER*)&nlb
+//
// Returns the number of bytes sent on success, SOCKET_ERROR on failure
// Errors: ERROR_INVALID_PARAMETER
// anything from send(), nlu.pfnHttpGatewayWrapSend()
@@ -610,31 +604,18 @@ public: // flags:
#define MSG_NOHTTPGATEWAYWRAP 0x010000 // don't wrap the outgoing packet using nlu.pfnHttpGatewayWrapSend
-#define MSG_NODUMP 0x020000 // don't dump this packet to the log
+#define MSG_NODUMP 0x020000 // don't dump this packet to the log
#define MSG_DUMPPROXY 0x040000 // this is proxy communiciation. For dump filtering only.
-#define MSG_DUMPASTEXT 0x080000 // this is textual data, don't dump as hex
+#define MSG_DUMPASTEXT 0x080000 // this is textual data, don't dump as hex
#define MSG_RAW 0x100000 // send as raw data, bypass any HTTP proxy stuff
#define MSG_DUMPSSL 0x200000 // this is SSL traffic. For dump filtering only.
+#define MSG_NOTITLE 0x400000 // skip date, time & protocol from dump
-struct NETLIBBUFFER
-{
- char *buf;
- int len;
- int flags;
-};
-
-#define MS_NETLIB_SEND "Netlib/Send"
-
-__inline INT_PTR Netlib_Send(HANDLE hConn, const char *buf, int len, int flags)
-{
- NETLIBBUFFER nlb = {(char*)buf, len, flags};
- return CallService(MS_NETLIB_SEND, (WPARAM)hConn, (LPARAM)&nlb);
-}
+EXTERN_C MIR_APP_DLL(int) Netlib_Send(HANDLE hConn, const char *buf, int len, int flags = 0);
/////////////////////////////////////////////////////////////////////////////////////////
// Receive data over a connection
-// wParam = (WPARAM)(HANDLE)hConnection
-// lParam = (LPARAM)(NETLIBBUFFER*)&nlb
+//
// Returns the number of bytes read on success, SOCKET_ERROR on failure,
// 0 if the connection has been closed
// Flags supported: MSG_PEEK, MSG_NODUMP, MSG_DUMPPROXY, MSG_NOHTTPGATEWAYWRAP,
@@ -654,13 +635,7 @@ __inline INT_PTR Netlib_Send(HANDLE hConn, const char *buf, int len, int flags) // nlu.pfnHttpGatewayUnwrapRecv, socket(), connect(),
// MS_NETLIB_SENDHTTPREQUEST
-#define MS_NETLIB_RECV "Netlib/Recv"
-
-__inline INT_PTR Netlib_Recv(HANDLE hConn, char *buf, int len, int flags)
-{
- NETLIBBUFFER nlb = {buf, len, flags};
- return CallService(MS_NETLIB_RECV, (WPARAM)hConn, (LPARAM)&nlb);
-}
+EXTERN_C MIR_APP_DLL(int) Netlib_Recv(HANDLE hConn, char *buf, int len, int flags = 0);
/////////////////////////////////////////////////////////////////////////////////////////
// Determine the status of one or more connections
@@ -924,7 +899,9 @@ static __inline char* Netlib_NtlmCreateResponse2(HANDLE hProvider, char* szChall struct NETLIBNOTIFY
{
- NETLIBBUFFER* nlb; // pointer to the request buffer
+ const char *buf;
+ int len;
+ int flags;
int result; // amount of bytes really sent/received
};
diff --git a/plugins/CryptoPP/src/main.cpp b/plugins/CryptoPP/src/main.cpp index 22be7cadba..62a75b02b3 100644 --- a/plugins/CryptoPP/src/main.cpp +++ b/plugins/CryptoPP/src/main.cpp @@ -130,8 +130,7 @@ void InitNetlib() void DeinitNetlib()
{
- if (hNetlibUser)
- CallService(MS_NETLIB_CLOSEHANDLE, (WPARAM)hNetlibUser, 0);
+ Netlib_CloseHandle(hNetlibUser);
}
int Sent_NetLog(const char *fmt, ...)
diff --git a/plugins/SecureIM/src/commonheaders.cpp b/plugins/SecureIM/src/commonheaders.cpp index eca5257814..0ac3f749e3 100644 --- a/plugins/SecureIM/src/commonheaders.cpp +++ b/plugins/SecureIM/src/commonheaders.cpp @@ -107,8 +107,7 @@ void InitNetlib() void DeinitNetlib()
{
- if (hNetlibUser)
- CallService(MS_NETLIB_CLOSEHANDLE, (WPARAM)hNetlibUser, 0);
+ Netlib_CloseHandle(hNetlibUser);
}
int Sent_NetLog(const char *fmt, ...)
diff --git a/plugins/Utils.pas/mirutils.pas b/plugins/Utils.pas/mirutils.pas index 10f2ea2578..4ede3640a2 100644 --- a/plugins/Utils.pas/mirutils.pas +++ b/plugins/Utils.pas/mirutils.pas @@ -458,7 +458,7 @@ begin end;
if (hNetLib=0) and (nlu.cbSize<>0) then
- CallService(MS_NETLIB_CLOSEHANDLE,hTmpNetLib,0);
+ Netlib_CloseHandle(hTmpNetLib);
end;
(*
@@ -537,7 +537,7 @@ begin CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,lparam(resp));
if nlu.cbSize<>0 then
- CallService(MS_NETLIB_CLOSEHANDLE,hNetLib,0);
+ Netlib_CloseHandle(hNetLib);
end;
end;
@@ -640,7 +640,7 @@ begin end;
CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,lparam(resp));
end;
- CallService(MS_NETLIB_CLOSEHANDLE,hNetLib,0);
+ Netlib_CloseHandle(hNetLib);
end;
function RegisterSingleIcon(resname,ilname,descr,group:PAnsiChar):int;
diff --git a/plugins/Watrack/myshows/i_cookies.inc b/plugins/Watrack/myshows/i_cookies.inc index 1258490199..3241134cf3 100644 --- a/plugins/Watrack/myshows/i_cookies.inc +++ b/plugins/Watrack/myshows/i_cookies.inc @@ -87,5 +87,5 @@ begin CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,lparam(resp));
end;
- CallService(MS_NETLIB_CLOSEHANDLE,hTmpNetLib,0);
+ Netlib_CloseHandle(hTmpNetLib);
end;
diff --git a/plugins/YAMN/src/proto/netlib.cpp b/plugins/YAMN/src/proto/netlib.cpp index 0d8df55ab1..cc8f73a602 100644 --- a/plugins/YAMN/src/proto/netlib.cpp +++ b/plugins/YAMN/src/proto/netlib.cpp @@ -119,14 +119,7 @@ void CNLClient::Connect(const char* servername, const int port) throw(DWORD) // query- command to send
int CNLClient::LocalNetlib_Send(HANDLE hConn, const char *buf, int len, int flags)
{
- if (isTLSed) {
- #ifdef DEBUG_COMM
- SSL_DebugLog("SSL send: %s", buf);
- #endif
- }
-
- NETLIBBUFFER nlb = { (char*)buf,len,flags };
- return CallService(MS_NETLIB_SEND, (WPARAM)hConn, (LPARAM)&nlb);
+ return Netlib_Send(hConn, buf, len, flags);
}
void CNLClient::Send(const char *query) throw(DWORD)
@@ -166,8 +159,7 @@ void CNLClient::Send(const char *query) throw(DWORD) int CNLClient::LocalNetlib_Recv(HANDLE hConn, char *buf, int len, int flags)
{
- NETLIBBUFFER nlb = { buf,len,flags };
- int iReturn = CallService(MS_NETLIB_RECV, (WPARAM)hConn, (LPARAM)&nlb);
+ int iReturn = Netlib_Recv(hConn, buf, len, flags);
if (isTLSed) {
#ifdef DEBUG_COMM
SSL_DebugLog("SSL recv: %s", buf);
diff --git a/plugins/mRadio/mradio.dpr b/plugins/mRadio/mradio.dpr index 3843cf56cd..3c3a5c3050 100644 --- a/plugins/mRadio/mradio.dpr +++ b/plugins/mRadio/mradio.dpr @@ -130,7 +130,7 @@ begin DestroyHookableEvent(hhRadioStatus);
- CallService(MS_NETLIB_CLOSEHANDLE,hNetLib,0);
+ Netlib_CloseHandle(hNetLib);
mFreeMem(storage);
mFreeMem(storagep);
diff --git a/protocols/IcqOscarJ/src/icq_http.cpp b/protocols/IcqOscarJ/src/icq_http.cpp index 5c5492cbc3..d9a8e5378a 100644 --- a/protocols/IcqOscarJ/src/icq_http.cpp +++ b/protocols/IcqOscarJ/src/icq_http.cpp @@ -101,7 +101,7 @@ int icq_httpGatewayBegin(HANDLE hConn, NETLIBOPENCONNECTION* nloc) -int icq_httpGatewayWrapSend(HANDLE hConn, PBYTE buf, int len, int flags, MIRANDASERVICE pfnNetlibSend)
+int icq_httpGatewayWrapSend(HANDLE hConn, PBYTE buf, int len, int flags)
{
PBYTE sendBuf = buf;
int sendLen = len;
@@ -119,8 +119,7 @@ int icq_httpGatewayWrapSend(HANDLE hConn, PBYTE buf, int len, int flags, MIRANDA write_httphdr(&packet, HTTP_PACKETTYPE_FLAP, GetGatewayIndex(hConn));
packBuffer(&packet, sendBuf, curLen);
- NETLIBBUFFER nlb={ (char*)packet.pData, packet.wLen, flags };
- curResult = pfnNetlibSend((WPARAM)hConn, (LPARAM)&nlb);
+ curResult = Netlib_Send(hConn, (char*)packet.pData, packet.wLen, flags);
SAFE_FREE((void**)&packet.pData);
diff --git a/protocols/IcqOscarJ/src/icq_http.h b/protocols/IcqOscarJ/src/icq_http.h index fb4b948770..0f2eb6a394 100644 --- a/protocols/IcqOscarJ/src/icq_http.h +++ b/protocols/IcqOscarJ/src/icq_http.h @@ -37,7 +37,7 @@ int icq_httpGatewayInit(HANDLE hConn, NETLIBOPENCONNECTION *nloc, NETLIBHTTPREQUEST *nlhr);
int icq_httpGatewayBegin(HANDLE hConn, NETLIBOPENCONNECTION *nloc);
-int icq_httpGatewayWrapSend(HANDLE hConn, PBYTE buf, int len, int flags, MIRANDASERVICE pfnNetlibSend);
+int icq_httpGatewayWrapSend(HANDLE hConn, PBYTE buf, int len, int flags);
PBYTE icq_httpGatewayUnwrapRecv(NETLIBHTTPREQUEST *nlhr, PBYTE buf, int bufLen, int *outBufLen, void *(*NetlibRealloc)(void *, size_t));
int icq_httpGatewayWalkTo(HANDLE hConn, NETLIBOPENCONNECTION* nloc);
diff --git a/protocols/MSN/src/msn_http.cpp b/protocols/MSN/src/msn_http.cpp index 7ea45b5a8a..74a0f66fb7 100644 --- a/protocols/MSN/src/msn_http.cpp +++ b/protocols/MSN/src/msn_http.cpp @@ -52,7 +52,7 @@ int msn_httpGatewayInit(HANDLE hConn, NETLIBOPENCONNECTION*, NETLIBHTTPREQUEST*) // function generates the initial URL depending on a thread type
//=======================================================================================
-int msn_httpGatewayWrapSend(HANDLE hConn, PBYTE buf, int len, int flags, MIRANDASERVICE pfnNetlibSend)
+int msn_httpGatewayWrapSend(HANDLE hConn, PBYTE buf, int len, int flags)
{
ThreadData *T = FindThreadConn(hConn);
if (T != NULL) {
@@ -62,8 +62,7 @@ int msn_httpGatewayWrapSend(HANDLE hConn, PBYTE buf, int len, int flags, MIRANDA T->applyGatewayData(hConn, len == 0);
}
- NETLIBBUFFER tBuf = { (char*)buf, len, flags };
- return pfnNetlibSend((LPARAM)hConn, WPARAM(&tBuf));
+ return Netlib_Send(hConn, (char*)buf, len, flags);
}
//=======================================================================================
diff --git a/protocols/MSN/src/msn_proto.cpp b/protocols/MSN/src/msn_proto.cpp index ce4d563de3..1efe0b33d9 100644 --- a/protocols/MSN/src/msn_proto.cpp +++ b/protocols/MSN/src/msn_proto.cpp @@ -25,7 +25,7 @@ static const COLORREF crCols[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; int msn_httpGatewayInit(HANDLE hConn,NETLIBOPENCONNECTION *nloc,NETLIBHTTPREQUEST *nlhr);
int msn_httpGatewayBegin(HANDLE hConn,NETLIBOPENCONNECTION *nloc);
-int msn_httpGatewayWrapSend(HANDLE hConn,PBYTE buf,int len,int flags,MIRANDASERVICE pfnNetlibSend);
+int msn_httpGatewayWrapSend(HANDLE hConn,PBYTE buf,int len,int flags);
PBYTE msn_httpGatewayUnwrapRecv(NETLIBHTTPREQUEST *nlhr,PBYTE buf,int len,int *outBufLen,void *(*NetlibRealloc)(void*,size_t));
static int CompareLists(const MsnContact *p1, const MsnContact *p2)
diff --git a/protocols/MSN/src/msn_ws.cpp b/protocols/MSN/src/msn_ws.cpp index d087f579c0..1c7dcd07e9 100644 --- a/protocols/MSN/src/msn_ws.cpp +++ b/protocols/MSN/src/msn_ws.cpp @@ -27,8 +27,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. int ThreadData::send(const char data[], size_t datalen)
{
- NETLIBBUFFER nlb = { (char*)data, (int)datalen, 0 };
-
resetTimeout();
if (proto->usingGateway && !(mType == SERVER_FILETRANS || mType == SERVER_P2P_DIRECT)) {
@@ -36,7 +34,7 @@ int ThreadData::send(const char data[], size_t datalen) CallService(MS_NETLIB_SETPOLLINGTIMEOUT, WPARAM(s), mGatewayTimeout);
}
- int rlen = CallService(MS_NETLIB_SEND, (WPARAM)s, (LPARAM)&nlb);
+ int rlen = Netlib_Send(s, data, (int)datalen);
if (rlen == SOCKET_ERROR) {
// should really also check if sendlen is the same as datalen
proto->debugLogA("Send failed: %d", WSAGetLastError());
@@ -113,8 +111,6 @@ bool ThreadData::isTimeout(void) int ThreadData::recv(char* data, size_t datalen)
{
- NETLIBBUFFER nlb = { data, (int)datalen, 0 };
-
if (!proto->usingGateway) {
resetTimeout();
NETLIBSELECT nls = { 0 };
@@ -137,7 +133,7 @@ int ThreadData::recv(char* data, size_t datalen) }
LBL_RecvAgain:
- int ret = CallService(MS_NETLIB_RECV, (WPARAM)s, (LPARAM)&nlb);
+ int ret = Netlib_Recv(s, data, (int)datalen);
if (ret == 0) {
proto->debugLogA("Connection closed gracefully");
return 0;
diff --git a/protocols/WhatsApp/src/WASocketConnection.cpp b/protocols/WhatsApp/src/WASocketConnection.cpp index b6ec0c0998..03ebf84ea7 100644 --- a/protocols/WhatsApp/src/WASocketConnection.cpp +++ b/protocols/WhatsApp/src/WASocketConnection.cpp @@ -30,12 +30,7 @@ void WASocketConnection::write(int i) char buffer;
buffer = (char)i;
- NETLIBBUFFER nlb;
- nlb.buf = &buffer;
- nlb.len = 1;
- nlb.flags = MSG_NOHTTPGATEWAYWRAP | MSG_NODUMP;
-
- int result = CallService(MS_NETLIB_SEND, WPARAM(this->hConn), LPARAM(&nlb));
+ int result = Netlib_Send(this->hConn, &buffer, 1, MSG_NOHTTPGATEWAYWRAP | MSG_NODUMP);
if (result < 1)
throw WAException(getLastErrorMsg(), WAException::SOCKET_EX, WAException::SOCKET_EX_SEND);
}
@@ -49,13 +44,8 @@ void WASocketConnection::flush() {} void WASocketConnection::write(const std::vector<unsigned char> &bytes, int length)
{
- NETLIBBUFFER nlb;
std::string tmpBuf = std::string(bytes.begin(), bytes.end());
- nlb.buf = (char*)&(tmpBuf.c_str()[0]);
- nlb.len = length;
- nlb.flags = MSG_NODUMP;
-
- int result = CallService(MS_NETLIB_SEND, WPARAM(hConn), LPARAM(&nlb));
+ int result = Netlib_Send(hConn, tmpBuf.c_str(), length, MSG_NODUMP);
if (result < length)
throw WAException(getLastErrorMsg(), WAException::SOCKET_EX, WAException::SOCKET_EX_SEND);
}
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 7ad0d3650d..5c5bd98036 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -345,3 +345,6 @@ Miranda_GetVersion @345 Miranda_GetFileVersion @346
Miranda_GetVersionText @347
Srmm_CreateToolbarIcons @348
+Netlib_CloseHandle @349
+Netlib_Recv @350
+Netlib_Send @351
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 68a6b11090..f0a887610b 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -345,3 +345,6 @@ Miranda_GetVersion @345 Miranda_GetFileVersion @346
Miranda_GetVersionText @347
Srmm_CreateToolbarIcons @348
+Netlib_CloseHandle @349
+Netlib_Recv @350
+Netlib_Send @351
diff --git a/src/mir_app/src/netlib.cpp b/src/mir_app/src/netlib.cpp index a8f731000d..269c4ca5bf 100644 --- a/src/mir_app/src/netlib.cpp +++ b/src/mir_app/src/netlib.cpp @@ -244,15 +244,15 @@ void NetlibDoClose(NetlibConnection *nlc, bool noShutdown) nlc->s = INVALID_SOCKET;
}
-INT_PTR NetlibCloseHandle(WPARAM wParam, LPARAM)
+MIR_APP_DLL(int) Netlib_CloseHandle(HANDLE hNetlib)
{
- if (wParam == NULL)
+ if (hNetlib == NULL)
return 0;
- switch(GetNetlibHandleType((void*)wParam)) {
+ switch (GetNetlibHandleType(hNetlib)) {
case NLH_USER:
{
- NetlibUser *nlu = (NetlibUser*)wParam;
+ NetlibUser *nlu = (NetlibUser*)hNetlib;
{
mir_cslock lck(csNetlibUser);
int i = netlibUser.getIndex(nlu);
@@ -272,7 +272,7 @@ INT_PTR NetlibCloseHandle(WPARAM wParam, LPARAM) case NLH_CONNECTION:
WaitForSingleObject(hConnectionHeaderMutex, INFINITE);
{
- NetlibConnection *nlc = (NetlibConnection*)wParam;
+ NetlibConnection *nlc = (NetlibConnection*)hNetlib;
if (GetNetlibHandleType(nlc) == NLH_CONNECTION) {
if (nlc->usingHttpGateway)
HttpGatewayRemovePacket(nlc, -1);
@@ -301,11 +301,11 @@ INT_PTR NetlibCloseHandle(WPARAM wParam, LPARAM) return 1;
case NLH_BOUNDPORT:
- return NetlibFreeBoundPort((struct NetlibBoundPort*)wParam);
+ return NetlibFreeBoundPort((NetlibBoundPort*)hNetlib);
case NLH_PACKETRECVER:
{
- struct NetlibPacketRecver *nlpr = (struct NetlibPacketRecver*)wParam;
+ struct NetlibPacketRecver *nlpr = (NetlibPacketRecver*)hNetlib;
mir_free(nlpr->packetRecver.buffer);
}
break;
@@ -314,7 +314,7 @@ INT_PTR NetlibCloseHandle(WPARAM wParam, LPARAM) SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
- mir_free((void*)wParam);
+ mir_free(hNetlib);
return 1;
}
@@ -411,7 +411,7 @@ void UnloadNetlibModule(void) DestroyHookableEvent(hSendEvent); hSendEvent = NULL;
for (int i = netlibUser.getCount(); i > 0; i--)
- NetlibCloseHandle((WPARAM)netlibUser[i-1], 0);
+ Netlib_CloseHandle(netlibUser[i-1]);
CloseHandle(hConnectionHeaderMutex);
if (hConnectionOpenMutex)
@@ -482,7 +482,6 @@ int LoadNetlibModule(void) CreateServiceFunction(MS_NETLIB_REGISTERUSER, NetlibRegisterUser);
CreateServiceFunction(MS_NETLIB_GETUSERSETTINGS, NetlibGetUserSettings);
CreateServiceFunction(MS_NETLIB_SETUSERSETTINGS, NetlibSetUserSettings);
- CreateServiceFunction(MS_NETLIB_CLOSEHANDLE, NetlibCloseHandle);
CreateServiceFunction(MS_NETLIB_BINDPORT, NetlibBindPort);
CreateServiceFunction(MS_NETLIB_OPENCONNECTION, NetlibOpenConnection);
CreateServiceFunction(MS_NETLIB_SETHTTPPROXYINFO, NetlibHttpGatewaySetInfo);
@@ -492,8 +491,6 @@ int LoadNetlibModule(void) CreateServiceFunction(MS_NETLIB_RECVHTTPHEADERS, NetlibHttpRecvHeaders);
CreateServiceFunction(MS_NETLIB_FREEHTTPREQUESTSTRUCT, NetlibHttpFreeRequestStruct);
CreateServiceFunction(MS_NETLIB_HTTPTRANSACTION, NetlibHttpTransaction);
- CreateServiceFunction(MS_NETLIB_SEND, NetlibSend);
- CreateServiceFunction(MS_NETLIB_RECV, NetlibRecv);
CreateServiceFunction(MS_NETLIB_SELECT, NetlibSelect);
CreateServiceFunction(MS_NETLIB_SELECTEX, NetlibSelectEx);
CreateServiceFunction(MS_NETLIB_SHUTDOWN, NetlibShutdown);
diff --git a/src/mir_app/src/netlib.h b/src/mir_app/src/netlib.h index 7eb961fc7a..dddb69c7ed 100644 --- a/src/mir_app/src/netlib.h +++ b/src/mir_app/src/netlib.h @@ -38,7 +38,7 @@ struct NetlibUser int handleType;
NETLIBUSER user;
NETLIBUSERSETTINGS settings;
- char * szStickyHeaders;
+ char *szStickyHeaders;
int toLog;
int inportnum;
int outportnum;
@@ -188,7 +188,6 @@ struct NetlibPacketRecver { //netlib.c
void NetlibFreeUserSettingsStruct(NETLIBUSERSETTINGS *settings);
void NetlibDoClose(NetlibConnection *nlc, bool noShutdown = false);
-INT_PTR NetlibCloseHandle(WPARAM wParam, LPARAM lParam);
void NetlibInitializeNestedCS(NetlibNestedCriticalSection *nlncs);
void NetlibDeleteNestedCS(NetlibNestedCriticalSection *nlncs);
#define NLNCS_SEND 0
@@ -261,8 +260,6 @@ INT_PTR NetlibPacketRecverGetMore(WPARAM wParam, LPARAM lParam); #define NL_SELECT_WRITE 0x0002
#define NL_SELECT_ALL (NL_SELECT_READ+NL_SELECT_WRITE)
-INT_PTR NetlibSend(WPARAM wParam, LPARAM lParam);
-INT_PTR NetlibRecv(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);
@@ -287,13 +284,3 @@ HANDLE NetlibInitSecurityProvider(const wchar_t* szProvider, const wchar_t* szPr HANDLE NetlibInitSecurityProvider(const char* szProvider, const char* szPrincipal);
char* NtlmCreateResponseFromChallenge(HANDLE hSecurity, const char *szChallenge, const wchar_t* login, const wchar_t* psw,
bool http, unsigned& complete);
-
-static __inline INT_PTR NLSend(NetlibConnection *nlc, const char *buf, int len, int flags) {
- NETLIBBUFFER nlb = {(char*)buf, len, flags};
- return NetlibSend((WPARAM)nlc, (LPARAM)&nlb);
-}
-
-static __inline INT_PTR NLRecv(NetlibConnection *nlc, char *buf, int len, int flags) {
- NETLIBBUFFER nlb = {buf, len, flags};
- return NetlibRecv((WPARAM)nlc, (LPARAM)&nlb);
-}
diff --git a/src/mir_app/src/netlibhttp.cpp b/src/mir_app/src/netlibhttp.cpp index a6091180c0..4eaeb33475 100644 --- a/src/mir_app/src/netlibhttp.cpp +++ b/src/mir_app/src/netlibhttp.cpp @@ -94,7 +94,7 @@ static int RecvWithTimeoutTime(NetlibConnection *nlc, unsigned dwTimeoutTime, ch return SOCKET_ERROR;
case 1:
- return NLRecv(nlc, buf, len, flags);
+ return Netlib_Recv(nlc, buf, len, flags);
}
if (nlc->termRequested || Miranda_IsTerminated())
@@ -103,7 +103,7 @@ static int RecvWithTimeoutTime(NetlibConnection *nlc, unsigned dwTimeoutTime, ch SetLastError(ERROR_TIMEOUT);
return SOCKET_ERROR;
}
- return NLRecv(nlc, buf, len, flags);
+ return Netlib_Recv(nlc, buf, len, flags);
}
static char* NetlibHttpFindHeader(NETLIBHTTPREQUEST *nlhrReply, const char *hdr)
@@ -352,14 +352,14 @@ static int SendHttpRequestAndData(NetlibConnection *nlc, CMStringA &httpRequest, MSG_NODUMP : (nlhr->flags & NLHRF_DUMPPROXY ? MSG_DUMPPROXY : 0)) |
(nlhr->flags & NLHRF_NOPROXY ? MSG_RAW : 0);
- int bytesSent = NLSend(nlc, httpRequest, httpRequest.GetLength(), hflags);
+ int bytesSent = Netlib_Send(nlc, httpRequest, httpRequest.GetLength(), hflags);
if (bytesSent != SOCKET_ERROR && sendData && nlhr->dataLength) {
- DWORD sflags = (nlhr->flags & NLHRF_DUMPASTEXT ? MSG_DUMPASTEXT : 0) |
+ DWORD sflags = MSG_NOTITLE | (nlhr->flags & NLHRF_DUMPASTEXT ? MSG_DUMPASTEXT : 0) |
(nlhr->flags & (NLHRF_NODUMP | NLHRF_NODUMPSEND) ?
MSG_NODUMP : (nlhr->flags & NLHRF_DUMPPROXY ? MSG_DUMPPROXY : 0)) |
(nlhr->flags & NLHRF_NOPROXY ? MSG_RAW : 0);
- int sendResult = NLSend(nlc, nlhr->pData, nlhr->dataLength, sflags);
+ int sendResult = Netlib_Send(nlc, nlhr->pData, nlhr->dataLength, sflags);
bytesSent = sendResult != SOCKET_ERROR ? bytesSent + sendResult : SOCKET_ERROR;
}
@@ -739,7 +739,7 @@ INT_PTR NetlibHttpRecvHeaders(WPARAM wParam, LPARAM lParam) }
char *buffer = (char*)_alloca(NHRV_BUF_SIZE + 1);
- int bytesPeeked = NLRecv(nlc, buffer, min(firstLineLength, NHRV_BUF_SIZE), lParam | MSG_DUMPASTEXT);
+ int bytesPeeked = Netlib_Recv(nlc, buffer, min(firstLineLength, NHRV_BUF_SIZE), lParam | MSG_DUMPASTEXT);
if (bytesPeeked != firstLineLength) {
NetlibLeaveNestedCS(&nlc->ncsRecv);
NetlibHttpFreeRequestStruct(0, (LPARAM)nlhr);
@@ -753,7 +753,7 @@ INT_PTR NetlibHttpRecvHeaders(WPARAM wParam, LPARAM lParam) int headersCount = 0;
bytesPeeked = 0;
for (bool headersCompleted = false; !headersCompleted;) {
- bytesPeeked = RecvWithTimeoutTime(nlc, dwRequestTimeoutTime, buffer, NHRV_BUF_SIZE, lParam | MSG_DUMPASTEXT);
+ bytesPeeked = RecvWithTimeoutTime(nlc, dwRequestTimeoutTime, buffer, NHRV_BUF_SIZE, lParam | MSG_DUMPASTEXT | MSG_NOTITLE);
if (bytesPeeked == 0)
break;
@@ -874,7 +874,7 @@ INT_PTR NetlibHttpTransaction(WPARAM wParam, LPARAM lParam) if (NetlibHttpSendRequest((WPARAM)nlc, (LPARAM)&nlhrSend) == SOCKET_ERROR) {
if (!doneUserAgentHeader || !doneAcceptEncoding) mir_free(nlhrSend.headers);
nlhr->resultCode = nlhrSend.resultCode;
- NetlibCloseHandle((WPARAM)nlc, 0);
+ Netlib_CloseHandle(nlc);
return 0;
}
if (!doneUserAgentHeader || !doneAcceptEncoding)
@@ -899,7 +899,7 @@ INT_PTR NetlibHttpTransaction(WPARAM wParam, LPARAM lParam) }
if ((nlhr->flags & NLHRF_PERSISTENT) == 0 || nlhrReply == NULL) {
- NetlibCloseHandle((WPARAM)nlc, 0);
+ Netlib_CloseHandle(nlc);
if (nlhrReply)
nlhrReply->nlc = NULL;
}
@@ -975,7 +975,7 @@ static int NetlibHttpRecvChunkHeader(NetlibConnection *nlc, bool first, DWORD fl while (true) {
char data[1000];
- int recvResult = NLRecv(nlc, data, _countof(data) - 1, MSG_RAW | flags);
+ int recvResult = Netlib_Recv(nlc, data, _countof(data) - 1, MSG_RAW | flags);
if (recvResult <= 0 || recvResult >= _countof(data))
return SOCKET_ERROR;
@@ -1048,7 +1048,7 @@ next: int dataBufferAlloced;
if (chunked) {
- chunksz = NetlibHttpRecvChunkHeader(nlc, true, dflags);
+ chunksz = NetlibHttpRecvChunkHeader(nlc, true, dflags | (cenctype ? MSG_NODUMP : 0));
if (chunksz == SOCKET_ERROR) {
NetlibHttpFreeRequestStruct(0, (LPARAM)nlhrReply);
return NULL;
@@ -1091,7 +1091,7 @@ next: if (!chunked)
break;
- chunksz = NetlibHttpRecvChunkHeader(nlc, false, dflags);
+ chunksz = NetlibHttpRecvChunkHeader(nlc, false, dflags | MSG_NODUMP);
if (chunksz == SOCKET_ERROR) {
NetlibHttpFreeRequestStruct(0, (LPARAM)nlhrReply);
return NULL;
@@ -1132,7 +1132,7 @@ next: }
if (bufsz > 0) {
- NetlibDumpData(nlc, (PBYTE)szData, bufsz, 0, dflags);
+ NetlibDumpData(nlc, (PBYTE)szData, bufsz, 0, dflags | MSG_NOTITLE);
mir_free(nlhrReply->pData);
nlhrReply->pData = szData;
nlhrReply->dataLength = bufsz;
diff --git a/src/mir_app/src/netlibhttpproxy.cpp b/src/mir_app/src/netlibhttpproxy.cpp index 806e08d7ee..6caa8631bf 100644 --- a/src/mir_app/src/netlibhttpproxy.cpp +++ b/src/mir_app/src/netlibhttpproxy.cpp @@ -272,7 +272,7 @@ int NetlibHttpGatewayRecv(NetlibConnection *nlc, char *buf, int len, int flags) nlc->lastPost = GetTickCount();
if (nlc->pHttpProxyPacketQueue == NULL && nlu->user.pfnHttpGatewayWrapSend != NULL)
- if (nlu->user.pfnHttpGatewayWrapSend(nlc, (PBYTE)"", 0, MSG_NOHTTPGATEWAYWRAP, NetlibSend) == SOCKET_ERROR)
+ if (nlu->user.pfnHttpGatewayWrapSend(nlc, (PBYTE)"", 0, MSG_NOHTTPGATEWAYWRAP) == SOCKET_ERROR)
return SOCKET_ERROR;
}
diff --git a/src/mir_app/src/netliblog.cpp b/src/mir_app/src/netliblog.cpp index 5219a98994..d73c075a8a 100644 --- a/src/mir_app/src/netliblog.cpp +++ b/src/mir_app/src/netliblog.cpp @@ -278,15 +278,13 @@ static INT_PTR ShowOptions(WPARAM, LPARAM) return 0;
}
-static INT_PTR NetlibLog(WPARAM wParam, LPARAM lParam)
+int NetlibLog_Worker(NetlibUser *nlu, const char *pszMsg, int flags)
{
if (!bIsActive)
return 0;
DWORD dwOriginalLastError = GetLastError();
- NetlibUser *nlu = (NetlibUser*)wParam;
- const char *pszMsg = (const char*)lParam;
if ((nlu != NULL && GetNetlibHandleType(nlu) != NLH_USER) || pszMsg == NULL) {
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
@@ -323,11 +321,15 @@ static INT_PTR NetlibLog(WPARAM wParam, LPARAM lParam) break;
}
- char *szUser = (logOptions.showUser) ? (nlu == NULL ? NULL : nlu->user.szSettingsModule) : NULL;
- if (szUser)
- mir_snprintf(szHead, "[%s%04X] [%s] ", szTime, GetCurrentThreadId(), szUser);
- else
- mir_snprintf(szHead, "[%s%04X] ", szTime, GetCurrentThreadId());
+ if (flags & MSG_NOTITLE)
+ szHead[0] = 0;
+ else {
+ char *szUser = (logOptions.showUser) ? (nlu == NULL ? NULL : nlu->user.szSettingsModule) : NULL;
+ if (szUser)
+ mir_snprintf(szHead, "[%s%04X] [%s] ", szTime, GetCurrentThreadId(), szUser);
+ else
+ mir_snprintf(szHead, "[%s%04X] ", szTime, GetCurrentThreadId());
+ }
if (logOptions.toOutputDebugString) {
if (szHead[0])
@@ -348,13 +350,18 @@ static INT_PTR NetlibLog(WPARAM wParam, LPARAM lParam) return 1;
}
+static INT_PTR NetlibLog(WPARAM wParam, LPARAM lParam)
+{
+ NetlibUser *nlu = (NetlibUser*)wParam;
+ const char *pszMsg = (const char*)lParam;
+ return NetlibLog_Worker(nlu, pszMsg, 0);
+}
+
static INT_PTR NetlibLogW(WPARAM wParam, LPARAM lParam)
{
- const wchar_t *pszMsg = (const wchar_t*)lParam;
- char* szMsg = Utf8EncodeW(pszMsg);
- INT_PTR res = NetlibLog(wParam, (LPARAM)szMsg);
- mir_free(szMsg);
- return res;
+ NetlibUser *nlu = (NetlibUser*)wParam;
+ const wchar_t *pwszMsg = (const wchar_t*)lParam;
+ return NetlibLog_Worker(nlu, ptrA(Utf8EncodeW(pwszMsg)), 0);
}
void NetlibLogf(NetlibUser* nlu, const char *fmt, ...)
@@ -373,7 +380,7 @@ void NetlibLogf(NetlibUser* nlu, const char *fmt, ...) mir_vsnprintf(szText, sizeof(szText), fmt, va);
va_end(va);
- NetlibLog((WPARAM)nlu, (LPARAM)szText);
+ NetlibLog_Worker(nlu, szText, 0);
}
void NetlibDumpData(NetlibConnection *nlc, PBYTE buf, int len, int sent, int flags)
@@ -401,8 +408,11 @@ void NetlibDumpData(NetlibConnection *nlc, PBYTE buf, int len, int sent, int fla WaitForSingleObject(hConnectionHeaderMutex, INFINITE);
NetlibUser *nlu = nlc ? nlc->nlu : NULL;
- int titleLineLen = mir_snprintf(szTitleLine, "(%p:%u) Data %s%s\r\n",
- nlc, nlc ? nlc->s : 0, sent ? "sent" : "received", flags & MSG_DUMPPROXY ? " (proxy)" : "");
+ int titleLineLen;
+ if (flags & MSG_NOTITLE)
+ titleLineLen = 0;
+ else
+ titleLineLen = mir_snprintf(szTitleLine, "(%p:%u) Data %s%s\r\n", nlc, nlc ? nlc->s : 0, sent ? "sent" : "received", flags & MSG_DUMPPROXY ? " (proxy)" : "");
ReleaseMutex(hConnectionHeaderMutex);
// check filter settings
@@ -480,7 +490,7 @@ void NetlibDumpData(NetlibConnection *nlc, PBYTE buf, int len, int sent, int fla *pszBuf = '\0';
}
- NetlibLog((WPARAM)nlu, (LPARAM)szBuf);
+ NetlibLog_Worker(nlu, szBuf, flags);
if (!useStack)
mir_free(szBuf);
}
diff --git a/src/mir_app/src/netlibopenconn.cpp b/src/mir_app/src/netlibopenconn.cpp index 069da71d74..65482350ea 100644 --- a/src/mir_app/src/netlibopenconn.cpp +++ b/src/mir_app/src/netlibopenconn.cpp @@ -99,7 +99,7 @@ bool RecvUntilTimeout(NetlibConnection *nlc, char *buf, int len, int flags, DWOR while ((dwTimeNow = GetTickCount()) < dwCompleteTime) { if (WaitUntilReadable(nlc->s, dwCompleteTime - dwTimeNow) <= 0) return false; - nReceived = NLRecv(nlc, buf, len, flags); + nReceived = Netlib_Recv(nlc, buf, len, flags); if (nReceived <= 0) return false; buf += nReceived; @@ -135,8 +135,8 @@ static int NetlibInitSocks4Connection(NetlibConnection *nlc, NetlibUser *nlu, NE len += nHostLen; } - if (NLSend(nlc, pInit, (int)len, MSG_DUMPPROXY) == SOCKET_ERROR) { - NetlibLogf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "NLSend", GetLastError()); + if (Netlib_Send(nlc, pInit, (int)len, MSG_DUMPPROXY) == SOCKET_ERROR) { + NetlibLogf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "Netlib_Send", GetLastError()); return 0; } @@ -165,8 +165,8 @@ static int NetlibInitSocks5Connection(NetlibConnection *nlc, NetlibUser *nlu, NE buf[0] = 5; //yep, socks5 buf[1] = 1; //one auth method buf[2] = nlu->settings.useProxyAuth?2:0; - if (NLSend(nlc, (char*)buf, 3, MSG_DUMPPROXY) == SOCKET_ERROR) { - NetlibLogf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "NLSend", GetLastError()); + if (Netlib_Send(nlc, (char*)buf, 3, MSG_DUMPPROXY) == SOCKET_ERROR) { + NetlibLogf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "Netlib_Send", GetLastError()); return 0; } @@ -177,7 +177,7 @@ static int NetlibInitSocks5Connection(NetlibConnection *nlc, NetlibUser *nlu, NE } if ((buf[1] != 0 && buf[1] != 2)) { SetLastError(ERROR_INVALID_ID_AUTHORITY); - NetlibLogf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "NLRecv", GetLastError()); + NetlibLogf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "Netlib_Recv", GetLastError()); return 0; } @@ -190,8 +190,8 @@ static int NetlibInitSocks5Connection(NetlibConnection *nlc, NetlibUser *nlu, NE memcpy(pAuthBuf + 2, nlu->settings.szProxyAuthUser, nUserLen); pAuthBuf[2 + nUserLen] = (BYTE)nPassLen; memcpy(pAuthBuf + 3 + nUserLen, nlu->settings.szProxyAuthPassword, nPassLen); - if (NLSend(nlc, (char*)pAuthBuf, int(3 + nUserLen + nPassLen), MSG_DUMPPROXY) == SOCKET_ERROR) { - NetlibLogf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "NLSend", GetLastError()); + if (Netlib_Send(nlc, (char*)pAuthBuf, int(3 + nUserLen + nPassLen), MSG_DUMPPROXY) == SOCKET_ERROR) { + NetlibLogf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "Netlib_Send", GetLastError()); mir_free(pAuthBuf); return 0; } @@ -235,8 +235,8 @@ static int NetlibInitSocks5Connection(NetlibConnection *nlc, NetlibUser *nlu, NE *(PDWORD)(pInit + 4) = hostIP; } *(PWORD)(pInit + 4 + nHostLen) = htons(nloc->wPort); - if (NLSend(nlc, (char*)pInit, int(6 + nHostLen), MSG_DUMPPROXY) == SOCKET_ERROR) { - NetlibLogf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "NLSend", GetLastError()); + if (Netlib_Send(nlc, (char*)pInit, int(6 + nHostLen), MSG_DUMPPROXY) == SOCKET_ERROR) { + NetlibLogf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "Netlib_Send", GetLastError()); mir_free(pInit); return 0; } diff --git a/src/mir_app/src/netlibpktrecver.cpp b/src/mir_app/src/netlibpktrecver.cpp index b0449867aa..5281cc5dab 100644 --- a/src/mir_app/src/netlibpktrecver.cpp +++ b/src/mir_app/src/netlibpktrecver.cpp @@ -81,7 +81,7 @@ INT_PTR NetlibPacketRecverGetMore(WPARAM wParam, LPARAM lParam) }
}
- INT_PTR recvResult = NLRecv(nlpr->nlc, (char*)nlpr->packetRecver.buffer + nlpr->packetRecver.bytesAvailable, nlpr->packetRecver.bufferSize - nlpr->packetRecver.bytesAvailable, 0);
+ INT_PTR recvResult = Netlib_Recv(nlpr->nlc, (char*)nlpr->packetRecver.buffer + nlpr->packetRecver.bytesAvailable, nlpr->packetRecver.bufferSize - nlpr->packetRecver.bytesAvailable, 0);
if (recvResult > 0)
nlpr->packetRecver.bytesAvailable += recvResult;
*nlprParam = nlpr->packetRecver;
diff --git a/src/mir_app/src/netlibsock.cpp b/src/mir_app/src/netlibsock.cpp index e11049cf44..34d1739103 100644 --- a/src/mir_app/src/netlibsock.cpp +++ b/src/mir_app/src/netlibsock.cpp @@ -27,76 +27,63 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern HANDLE hConnectionHeaderMutex, hSendEvent, hRecvEvent;
-INT_PTR NetlibSend(WPARAM wParam, LPARAM lParam)
+MIR_APP_DLL(int) Netlib_Send(HANDLE hConn, const char *buf, int len, int flags)
{
- NetlibConnection *nlc = (NetlibConnection*)wParam;
- NETLIBBUFFER *nlb = (NETLIBBUFFER*)lParam;
- if (nlb == NULL) {
- SetLastError(ERROR_INVALID_PARAMETER);
- return SOCKET_ERROR;
- }
-
+ NetlibConnection *nlc = (NetlibConnection*)hConn;
if (!NetlibEnterNestedCS(nlc, NLNCS_SEND))
return SOCKET_ERROR;
int result;
- if (nlc->usingHttpGateway && !(nlb->flags & MSG_RAW)) {
- if (!(nlb->flags & MSG_NOHTTPGATEWAYWRAP) && nlc->nlu->user.pfnHttpGatewayWrapSend) {
- NetlibDumpData(nlc, (PBYTE)nlb->buf, nlb->len, 1, nlb->flags);
- result = nlc->nlu->user.pfnHttpGatewayWrapSend((HANDLE)nlc, (PBYTE)nlb->buf, nlb->len, nlb->flags | MSG_NOHTTPGATEWAYWRAP, NetlibSend);
+ if (nlc->usingHttpGateway && !(flags & MSG_RAW)) {
+ if (!(flags & MSG_NOHTTPGATEWAYWRAP) && nlc->nlu->user.pfnHttpGatewayWrapSend) {
+ NetlibDumpData(nlc, (PBYTE)buf, len, 1, flags);
+ result = nlc->nlu->user.pfnHttpGatewayWrapSend((HANDLE)nlc, (PBYTE)buf, len, flags | MSG_NOHTTPGATEWAYWRAP);
}
- else result = NetlibHttpGatewayPost(nlc, nlb->buf, nlb->len, nlb->flags);
+ else result = NetlibHttpGatewayPost(nlc, buf, len, flags);
}
else {
- NetlibDumpData(nlc, (PBYTE)nlb->buf, nlb->len, 1, nlb->flags);
+ NetlibDumpData(nlc, (PBYTE)buf, len, 1, flags);
if (nlc->hSsl)
- result = sslApi.write(nlc->hSsl, nlb->buf, nlb->len);
+ result = sslApi.write(nlc->hSsl, buf, len);
else
- result = send(nlc->s, nlb->buf, nlb->len, nlb->flags & 0xFFFF);
+ result = send(nlc->s, buf, len, flags & 0xFFFF);
}
NetlibLeaveNestedCS(&nlc->ncsSend);
- NETLIBNOTIFY nln = { nlb, result };
+ NETLIBNOTIFY nln = { buf, len, flags, result };
NotifyFastHook(hSendEvent, (WPARAM)&nln, (LPARAM)&nlc->nlu->user);
return result;
}
-INT_PTR NetlibRecv(WPARAM wParam, LPARAM lParam)
+MIR_APP_DLL(int) Netlib_Recv(HANDLE hConn, char *buf, int len, int flags)
{
- NetlibConnection *nlc = (NetlibConnection*)wParam;
- NETLIBBUFFER* nlb = (NETLIBBUFFER*)lParam;
- int recvResult;
-
- if (nlb == NULL) {
- SetLastError(ERROR_INVALID_PARAMETER);
- return SOCKET_ERROR;
- }
-
+ NetlibConnection *nlc = (NetlibConnection*)hConn;
if (!NetlibEnterNestedCS(nlc, NLNCS_RECV))
return SOCKET_ERROR;
- if (nlc->usingHttpGateway && !(nlb->flags & MSG_RAW))
- recvResult = NetlibHttpGatewayRecv(nlc, nlb->buf, nlb->len, nlb->flags);
+ int recvResult;
+ if (nlc->usingHttpGateway && !(flags & MSG_RAW))
+ recvResult = NetlibHttpGatewayRecv(nlc, buf, len, flags);
else {
if (!nlc->foreBuf.isEmpty()) {
- recvResult = min(nlb->len, nlc->foreBuf.length());
- memcpy(nlb->buf, nlc->foreBuf.data(), recvResult);
+ recvResult = min(len, nlc->foreBuf.length());
+ memcpy(buf, nlc->foreBuf.data(), recvResult);
nlc->foreBuf.remove(recvResult);
}
else if (nlc->hSsl)
- recvResult = sslApi.read(nlc->hSsl, nlb->buf, nlb->len, (nlb->flags & MSG_PEEK) != 0);
+ recvResult = sslApi.read(nlc->hSsl, buf, len, (flags & MSG_PEEK) != 0);
else
- recvResult = recv(nlc->s, nlb->buf, nlb->len, nlb->flags & 0xFFFF);
+ recvResult = recv(nlc->s, buf, len, flags & 0xFFFF);
}
NetlibLeaveNestedCS(&nlc->ncsRecv);
if (recvResult <= 0)
return recvResult;
- NetlibDumpData(nlc, (PBYTE)nlb->buf, recvResult, 0, nlb->flags);
+ NetlibDumpData(nlc, (PBYTE)buf, recvResult, 0, flags);
- if ((nlb->flags & MSG_PEEK) == 0) {
- NETLIBNOTIFY nln = { nlb, recvResult };
+ if ((flags & MSG_PEEK) == 0) {
+ NETLIBNOTIFY nln = { buf, len, flags, recvResult };
NotifyFastHook(hRecvEvent, (WPARAM)&nln, (LPARAM)&nlc->nlu->user);
}
return recvResult;
|