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 /src | |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/mir_app/src/mir_app.def | 3 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 3 | ||||
-rw-r--r-- | src/mir_app/src/netlib.cpp | 21 | ||||
-rw-r--r-- | src/mir_app/src/netlib.h | 15 | ||||
-rw-r--r-- | src/mir_app/src/netlibhttp.cpp | 26 | ||||
-rw-r--r-- | src/mir_app/src/netlibhttpproxy.cpp | 2 | ||||
-rw-r--r-- | src/mir_app/src/netliblog.cpp | 44 | ||||
-rw-r--r-- | src/mir_app/src/netlibopenconn.cpp | 20 | ||||
-rw-r--r-- | src/mir_app/src/netlibpktrecver.cpp | 2 | ||||
-rw-r--r-- | src/mir_app/src/netlibsock.cpp | 59 |
10 files changed, 91 insertions, 104 deletions
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;
|