diff options
author | George Hazan <ghazan@miranda.im> | 2017-01-13 00:01:59 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-01-13 00:01:59 +0300 |
commit | e145db68fb5b7d0682a4b2be0174cebfe47dd74e (patch) | |
tree | c8f9edc907876d236eb16bc8ca8b592accb9846f /src | |
parent | 3cb3883908e3168e5f955be3143771721614307a (diff) |
a bit less netlib services
Diffstat (limited to 'src')
-rw-r--r-- | src/mir_app/src/mir_app.def | 11 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 11 | ||||
-rw-r--r-- | src/mir_app/src/netlib.cpp | 47 | ||||
-rw-r--r-- | src/mir_app/src/netlib.h | 23 | ||||
-rw-r--r-- | src/mir_app/src/netlibbind.cpp | 24 | ||||
-rw-r--r-- | src/mir_app/src/netlibhttp.cpp | 11 | ||||
-rw-r--r-- | src/mir_app/src/netlibhttpproxy.cpp | 2 | ||||
-rw-r--r-- | src/mir_app/src/netlibopenconn.cpp | 19 | ||||
-rw-r--r-- | src/mir_app/src/netlibopts.cpp | 16 | ||||
-rw-r--r-- | src/mir_app/src/netlibpktrecver.cpp | 30 | ||||
-rw-r--r-- | src/mir_app/src/netlibsock.cpp | 29 |
11 files changed, 95 insertions, 128 deletions
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);
|