diff options
author | Kirill Volinsky <mataes2007@gmail.com> | 2012-11-13 13:38:47 +0000 |
---|---|---|
committer | Kirill Volinsky <mataes2007@gmail.com> | 2012-11-13 13:38:47 +0000 |
commit | 2fc2fe879bcd82fde1762b780691a358a9addc48 (patch) | |
tree | 929daf1f2bc58666859bf564e34cd57df0b6469e /src/modules | |
parent | 1456f2f9d1a79d7da925551b8947ff1e6140feed (diff) |
tabs and spaces cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@2305 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/netlib/netlib.cpp | 28 | ||||
-rw-r--r-- | src/modules/netlib/netlib.h | 10 | ||||
-rw-r--r-- | src/modules/netlib/netlibautoproxy.cpp | 18 | ||||
-rw-r--r-- | src/modules/netlib/netlibbind.cpp | 36 | ||||
-rw-r--r-- | src/modules/netlib/netlibhttp.cpp | 160 | ||||
-rw-r--r-- | src/modules/netlib/netlibhttpproxy.cpp | 52 | ||||
-rw-r--r-- | src/modules/netlib/netliblog.cpp | 20 | ||||
-rw-r--r-- | src/modules/netlib/netlibopenconn.cpp | 22 | ||||
-rw-r--r-- | src/modules/netlib/netlibopts.cpp | 48 | ||||
-rw-r--r-- | src/modules/netlib/netlibsecurity.cpp | 40 | ||||
-rw-r--r-- | src/modules/netlib/netlibssl.cpp | 93 | ||||
-rw-r--r-- | src/modules/netlib/netlibupnp.cpp | 7 |
12 files changed, 260 insertions, 274 deletions
diff --git a/src/modules/netlib/netlib.cpp b/src/modules/netlib/netlib.cpp index 670a882d90..4c4328b6d7 100644 --- a/src/modules/netlib/netlib.cpp +++ b/src/modules/netlib/netlib.cpp @@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static BOOL bModuleInitialized = FALSE;
-HANDLE hConnectionHeaderMutex, hConnectionOpenMutex;
+HANDLE hConnectionHeaderMutex, hConnectionOpenMutex;
DWORD g_LastConnectionTick;
int connectionTimeout;
HANDLE hSendEvent = NULL, hRecvEvent = NULL;
@@ -157,7 +157,7 @@ static INT_PTR NetlibRegisterUser(WPARAM, LPARAM lParam) }
if ((thisUser->user.szSettingsModule = mir_strdup(nlu->szSettingsModule)) == NULL
|| (nlu->szDescriptiveName && thisUser->user.ptszDescriptiveName == NULL)
- || (nlu->szHttpGatewayUserAgent && (thisUser->user.szHttpGatewayUserAgent = mir_strdup(nlu->szHttpGatewayUserAgent)) == NULL))
+ || (nlu->szHttpGatewayUserAgent && (thisUser->user.szHttpGatewayUserAgent = mir_strdup(nlu->szHttpGatewayUserAgent)) == NULL))
{
mir_free(thisUser);
SetLastError(ERROR_OUTOFMEMORY);
@@ -243,7 +243,7 @@ INT_PTR NetlibCloseHandle(WPARAM wParam, LPARAM) switch(GetNetlibHandleType(wParam))
{
case NLH_USER:
- {
+ {
struct NetlibUser *nlu = (struct NetlibUser*)wParam;
{
mir_cslock lck(csNetlibUser);
@@ -261,7 +261,8 @@ INT_PTR NetlibCloseHandle(WPARAM wParam, LPARAM) break;
}
case NLH_CONNECTION:
- { struct NetlibConnection *nlc = (struct NetlibConnection*)wParam;
+ {
+ struct NetlibConnection *nlc = (struct NetlibConnection*)wParam;
HANDLE waitHandles[4];
DWORD waitResult;
@@ -287,7 +288,7 @@ INT_PTR NetlibCloseHandle(WPARAM wParam, LPARAM) waitResult = WaitForMultipleObjects(SIZEOF(waitHandles), waitHandles, TRUE, INFINITE);
if (waitResult<WAIT_OBJECT_0 || waitResult >= WAIT_OBJECT_0 + SIZEOF(waitHandles)) {
ReleaseMutex(hConnectionHeaderMutex);
- SetLastError(ERROR_INVALID_PARAMETER); //already been closed
+ SetLastError(ERROR_INVALID_PARAMETER); //already been closed
return 0;
}
nlc->handleType = 0;
@@ -308,7 +309,8 @@ INT_PTR NetlibCloseHandle(WPARAM wParam, LPARAM) case NLH_BOUNDPORT:
return NetlibFreeBoundPort((struct NetlibBoundPort*)wParam);
case NLH_PACKETRECVER:
- { struct NetlibPacketRecver *nlpr = (struct NetlibPacketRecver*)wParam;
+ {
+ struct NetlibPacketRecver *nlpr = (struct NetlibPacketRecver*)wParam;
mir_free(nlpr->packetRecver.buffer);
break;
}
@@ -380,7 +382,7 @@ INT_PTR NetlibGetMyIp(WPARAM wParam, LPARAM) INT_PTR NetlibShutdown(WPARAM wParam, LPARAM)
{
- if (wParam)
+ if (wParam)
{
WaitForSingleObject(hConnectionHeaderMutex, INFINITE);
switch(GetNetlibHandleType(wParam)) {
@@ -560,7 +562,7 @@ void UnloadNetlibModule(void) if (hConnectionOpenMutex) CloseHandle(hConnectionOpenMutex);
DeleteCriticalSection(&csNetlibUser);
WSACleanup();
- }
+ }
}
int LoadNetlibModule(void)
@@ -568,7 +570,7 @@ int LoadNetlibModule(void) WSADATA wsadata;
bModuleInitialized = TRUE;
-
+
WSAStartup(MAKEWORD(2, 2), &wsadata);
HookEvent(ME_OPT_INITIALISE, NetlibOptInitialise);
@@ -584,7 +586,7 @@ int LoadNetlibModule(void) if (GetVersionEx((LPOSVERSIONINFO)&osvi))
{
// Connection limiting was introduced in Windows XP SP2 and later and set to 10 / sec
- if (osvi.dwMajorVersion == 5 && ((osvi.dwMinorVersion == 1 && osvi.wServicePackMajor >= 2) || osvi.dwMinorVersion > 1))
+ if (osvi.dwMajorVersion == 5 && ((osvi.dwMinorVersion == 1 && osvi.wServicePackMajor >= 2) || osvi.dwMinorVersion > 1))
connectionTimeout = 150;
// Connection limiting has limits based on addition Windows Vista pre SP2
else if (osvi.dwMajorVersion == 6 && osvi.wServicePackMajor < 2)
@@ -596,12 +598,12 @@ int LoadNetlibModule(void) {
case 0x01: // Vista Ultimate edition have connection limit of 25 / sec - plenty for Miranda
case 0x1c:
- break;
+ break;
case 0x02: // Vista Home Basic edition have connection limit of 2 / sec
case 0x05:
- connectionTimeout = 1000;
- break;
+ connectionTimeout = 1000;
+ break;
default: // all other editions have connection limit of 10 / sec
connectionTimeout = 150;
diff --git a/src/modules/netlib/netlib.h b/src/modules/netlib/netlib.h index f20d123fee..16e711df05 100644 --- a/src/modules/netlib/netlib.h +++ b/src/modules/netlib/netlib.h @@ -34,8 +34,8 @@ struct NetlibUser NETLIBUSERSETTINGS settings;
char * szStickyHeaders;
int toLog;
- int inportnum;
- int outportnum;
+ int inportnum;
+ int outportnum;
};
struct NetlibNestedCriticalSection
@@ -53,9 +53,9 @@ struct NetlibHTTPProxyPacketQueue };
typedef union _SOCKADDR_INET_M {
- SOCKADDR_IN Ipv4;
- SOCKADDR_IN6 Ipv6;
- USHORT si_family;
+ SOCKADDR_IN Ipv4;
+ SOCKADDR_IN6 Ipv6;
+ USHORT si_family;
} SOCKADDR_INET_M, *PSOCKADDR_INET_M;
struct NetlibConnection
diff --git a/src/modules/netlib/netlibautoproxy.cpp b/src/modules/netlib/netlibautoproxy.cpp index e25b1ef17e..33992028dc 100644 --- a/src/modules/netlib/netlibautoproxy.cpp +++ b/src/modules/netlib/netlibautoproxy.cpp @@ -123,7 +123,7 @@ static pfnInternetGetProxyInfo pInternetGetProxyInfo; static bool bEnabled, bOneProxy;
-static void GetFile(char* szUrl, AUTO_PROXY_SCRIPT_BUFFER &buf)
+static void GetFile(char* szUrl, AUTO_PROXY_SCRIPT_BUFFER &buf)
{
NetlibUser nlu = {0};
NETLIBHTTPREQUEST nlhr = {0};
@@ -142,7 +142,7 @@ static void GetFile(char* szUrl, AUTO_PROXY_SCRIPT_BUFFER &buf) // download the page
NETLIBHTTPREQUEST *nlhrReply = (NETLIBHTTPREQUEST*)NetlibHttpTransaction((WPARAM)&nlu, (LPARAM)&nlhr);
- if (nlhrReply)
+ if (nlhrReply)
{
if (nlhrReply->resultCode == 200)
{
@@ -181,7 +181,7 @@ bool NetlibGetIeProxyConn(NetlibConnection *nlc, bool forceHttps) nlc->proxyType = 0;
char *mt = NetlibGetIeProxy(szUrl);
- char *m = NEWSTR_ALLOCA(mt);
+ char *m = NEWSTR_ALLOCA(mt);
mir_free(mt);
if (m == NULL) return false;
@@ -190,7 +190,7 @@ bool NetlibGetIeProxyConn(NetlibConnection *nlc, bool forceHttps) char *c = strchr(m, ';'); if (c) *c = 0;
// if 'direct' no proxy
- if (_stricmp(lrtrim(m), "direct") == 0) return false;
+ if (_stricmp(lrtrim(m), "direct") == 0) return false;
// find proxy address
char *h = strchr(m, ' ');
@@ -249,7 +249,7 @@ static void NetlibInitAutoProxy(void) GetProcAddress(hModJS, "InternetGetProxyInfo");
}
- if (strstr(szAutoUrlStr, "file://") == NULL && strstr(szAutoUrlStr, "://") != NULL)
+ if (strstr(szAutoUrlStr, "file://") == NULL && strstr(szAutoUrlStr, "://") != NULL)
{
abuf.dwStructSize = sizeof(abuf);
GetFile(szAutoUrlStr, abuf);
@@ -278,7 +278,7 @@ static unsigned __stdcall NetlibIeProxyThread(void * arg) BOOL res;
char *loc = strstr(szAutoUrlStr, "file://");
- if (loc || strstr(szAutoUrlStr, "://") == NULL)
+ if (loc || strstr(szAutoUrlStr, "://") == NULL)
{
NetlibLogf(NULL, "Autoproxy Init file: %s", loc);
loc = loc ? loc + 7 : szAutoUrlStr;
@@ -335,7 +335,7 @@ char* NetlibGetIeProxy(char *szUrl) }
int ind = -1;
- if (strstr(szUrl, "http://"))
+ if (strstr(szUrl, "http://"))
ind = szProxyHost[0] ? 0 : 2;
else if (strstr(szUrl, "https://"))
ind = bOneProxy ? 0 : (szProxyHost[1] ? 1 : 2);
@@ -410,13 +410,13 @@ void NetlibLoadIeProxy(void) lrtrim(szProxy);
- if (strchr(szProxy, ':'))
+ if (strchr(szProxy, ':'))
szProxyHost[ind] = mir_strdup(szProxy);
else
{
size_t len = strlen(szProxy) + 10;
szProxyHost[ind] = (char*)mir_alloc(len);
- mir_snprintf(szProxyHost[ind], len, "%s:%u", szProxy, ind == 2 ? 1080 : 8080);
+ mir_snprintf(szProxyHost[ind], len, "%s:%u", szProxy, ind == 2 ? 1080 : 8080);
}
if (bOneProxy) break;
}
diff --git a/src/modules/netlib/netlibbind.cpp b/src/modules/netlib/netlibbind.cpp index 1a4970fe64..86bbc70b20 100644 --- a/src/modules/netlib/netlibbind.cpp +++ b/src/modules/netlib/netlibbind.cpp @@ -49,7 +49,7 @@ bool BindSocketToPort(const char *szPorts, SOCKET s, SOCKET s6, int* portn) char *pszEnd;
int portMin, portMax, port, portnum = 0;
- for (psz = szPorts;*psz;) {
+ for (psz = szPorts;*psz;) {
while (*psz == ' ' || *psz == ',') psz++;
portMin = strtol(psz, &pszEnd, 0);
if (pszEnd == psz)
@@ -127,14 +127,14 @@ static unsigned __stdcall NetlibBindAcceptThread(void* param) struct NetlibBoundPort *nlbp = (NetlibBoundPort*)param;
NetlibLogf(nlbp->nlu, "(%u) Port %u opened for incoming connections", nlbp->s, nlbp->wPort);
- for (;;)
+ for (;;)
{
fd_set r;
FD_ZERO(&r);
FD_SET(nlbp->s, &r);
FD_SET(nlbp->s6, &r);
- if (select(0, &r, NULL, NULL, NULL) == SOCKET_ERROR)
+ if (select(0, &r, NULL, NULL, NULL) == SOCKET_ERROR)
break;
sinLen = sizeof(sin);
@@ -182,7 +182,7 @@ INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam) UINT dwThreadId;
if (GetNetlibHandleType(nlu) != NLH_USER || !(nlu->user.flags & NUF_INCOMING) ||
- nlb == NULL || nlb->pfnNewConnection == NULL)
+ nlb == NULL || nlb->pfnNewConnection == NULL)
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
@@ -198,7 +198,7 @@ INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam) nlbp->s = socket(PF_INET, SOCK_STREAM, 0);
nlbp->s6 = socket(PF_INET6, SOCK_STREAM, 0);
nlbp->pExtra = (nlb->cbSize != NETLIBBIND_SIZEOF_V1) ? nlb->pExtra : NULL;
- if (nlbp->s == INVALID_SOCKET && nlbp->s6 == INVALID_SOCKET)
+ if (nlbp->s == INVALID_SOCKET && nlbp->s6 == INVALID_SOCKET)
{
NetlibLogf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "socket", WSAGetLastError());
mir_free(nlbp);
@@ -209,7 +209,7 @@ INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam) /* if the netlib user wanted a free port given in the range, then
they better have given wPort == 0, let's hope so */
- if (nlu->settings.specifyIncomingPorts && nlu->settings.szIncomingPorts && nlb->wPort == 0)
+ if (nlu->settings.specifyIncomingPorts && nlu->settings.szIncomingPorts && nlb->wPort == 0)
{
if ( !BindSocketToPort(nlu->settings.szIncomingPorts, nlbp->s, nlbp->s6, &nlu->outportnum))
{
@@ -219,17 +219,17 @@ INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam) else
foundPort = 1;
}
- else
+ else
{
/* if ->wPort == 0 then they'll get any free port, otherwise they'll
be asking for whatever was in nlb->wPort*/
- if (nlb->wPort != 0)
+ if (nlb->wPort != 0)
{
NetlibLogf(nlu, "%s %d: trying to bind port %d, this 'feature' can be abused, please be sure you want to allow it.", __FILE__, __LINE__, nlb->wPort);
sin.sin_port = htons(nlb->wPort);
sin6.sin6_port = htons(nlb->wPort);
}
- if (bind(nlbp->s, (PSOCKADDR)&sin, sizeof(sin)) == 0)
+ if (bind(nlbp->s, (PSOCKADDR)&sin, sizeof(sin)) == 0)
{
SOCKADDR_IN sin = {0};
int len = sizeof(sin);
@@ -238,10 +238,10 @@ INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam) foundPort = 1;
}
- if (bind(nlbp->s6, (PSOCKADDR)&sin6, sizeof(sin6)) == 0)
+ if (bind(nlbp->s6, (PSOCKADDR)&sin6, sizeof(sin6)) == 0)
foundPort = 1;
}
- if ( !foundPort)
+ if ( !foundPort)
{
NetlibLogf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "bind", WSAGetLastError());
closesocket(nlbp->s);
@@ -250,7 +250,7 @@ INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam) return 0;
}
- if (nlbp->s != INVALID_SOCKET && listen(nlbp->s, 5))
+ if (nlbp->s != INVALID_SOCKET && listen(nlbp->s, 5))
{
NetlibLogf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "listen", WSAGetLastError());
closesocket(nlbp->s);
@@ -259,7 +259,7 @@ INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam) return 0;
}
- if (nlbp->s6 != INVALID_SOCKET && listen(nlbp->s6, 5))
+ if (nlbp->s6 != INVALID_SOCKET && listen(nlbp->s6, 5))
{
NetlibLogf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "listen", WSAGetLastError());
closesocket(nlbp->s);
@@ -268,7 +268,7 @@ INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam) return 0;
}
- {
+ {
SOCKADDR_INET_M sin = {0};
int len = sizeof(sin);
if ( !getsockname(nlbp->s, (PSOCKADDR)&sin, &len))
@@ -296,14 +296,14 @@ INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam) PHOSTENT he = gethostbyname(hostname);
if (he && he->h_addr)
nlb->dwInternalIP = ntohl(*(PDWORD)he->h_addr);
- }
+ }
DWORD extIP;
if (nlu->settings.enableUPnP &&
NetlibUPnPAddPortMapping(nlb->wPort, "TCP", &nlbp->wExPort, &extIP, nlb->cbSize > NETLIBBIND_SIZEOF_V2))
{
NetlibLogf(NULL, "UPnP port mapping succeeded. Internal Port: %u External Port: %u\n",
- nlb->wPort, nlbp->wExPort);
+ nlb->wPort, nlbp->wExPort);
if (nlb->cbSize > NETLIBBIND_SIZEOF_V2)
{
nlb->wExPort = nlbp->wExPort;
@@ -313,9 +313,9 @@ INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam) else
{
if (nlu->settings.enableUPnP)
- NetlibLogf(NULL, "UPnP port mapping failed. Internal Port: %u\n", nlb->wPort);
+ NetlibLogf(NULL, "UPnP port mapping failed. Internal Port: %u\n", nlb->wPort);
else
- NetlibLogf(NULL, "UPnP disabled. Internal Port: %u\n", nlb->wPort);
+ NetlibLogf(NULL, "UPnP disabled. Internal Port: %u\n", nlb->wPort);
nlbp->wExPort = 0;
if (nlb->cbSize > NETLIBBIND_SIZEOF_V2)
diff --git a/src/modules/netlib/netlibhttp.cpp b/src/modules/netlib/netlibhttp.cpp index 895467ab24..a871f6957a 100644 --- a/src/modules/netlib/netlibhttp.cpp +++ b/src/modules/netlib/netlibhttp.cpp @@ -51,7 +51,7 @@ struct ProxyAuth mir_free(szMethod);
}
static int Compare(const ProxyAuth* p1, const ProxyAuth* p2)
- { return lstrcmpiA(p1->szServer, p2->szServer); }
+ { return lstrcmpiA(p1->szServer, p2->szServer); }
};
struct ProxyAuthList : OBJLIST<ProxyAuth>
@@ -63,13 +63,13 @@ struct ProxyAuthList : OBJLIST<ProxyAuth> if (szServer == NULL) return;
int i = getIndex((ProxyAuth*)&szServer);
if (i >= 0)
- {
+ {
ProxyAuth &rec = (*this)[i];
if (szMethod == NULL)
remove(i);
else if (_stricmp(rec.szMethod, szMethod))
{
- mir_free(rec.szMethod);
+ mir_free(rec.szMethod);
rec.szMethod = mir_strdup(szMethod);
}
}
@@ -91,13 +91,13 @@ static void AppendToCharBuffer(struct ResizableCharBuffer *rcb, const char *fmt, va_list va;
int charsDone;
- if (rcb->cbAlloced == 0)
+ if (rcb->cbAlloced == 0)
{
rcb->cbAlloced = 512;
rcb->sz = (char*)mir_alloc(rcb->cbAlloced);
}
va_start(va, fmt);
- for (;;)
+ for (;;)
{
charsDone = mir_vsnprintf(rcb->sz + rcb->iEnd, rcb->cbAlloced-rcb->iEnd, fmt, va);
if (charsDone >= 0) break;
@@ -121,9 +121,9 @@ static int RecvWithTimeoutTime(struct NetlibConnection *nlc, unsigned dwTimeoutT switch (res)
{
- case SOCKET_ERROR:
+ case SOCKET_ERROR:
return SOCKET_ERROR;
-
+
case 1:
return NLRecv(nlc, buf, len, flags);
}
@@ -140,7 +140,7 @@ static char* NetlibHttpFindHeader(NETLIBHTTPREQUEST *nlhrReply, const char *hdr) {
for (int i=0; i < nlhrReply->headersCount; i++)
{
- if (_stricmp(nlhrReply->headers[i].szName, hdr) == 0)
+ if (_stricmp(nlhrReply->headers[i].szName, hdr) == 0)
{
return nlhrReply->headers[i].szValue;
}
@@ -154,9 +154,9 @@ static char* NetlibHttpFindAuthHeader(NETLIBHTTPREQUEST *nlhrReply, const char * char *szNegoHdr = NULL;
char *szNtlmHdr = NULL;
- for (int i=0; i < nlhrReply->headersCount; i++)
+ for (int i=0; i < nlhrReply->headersCount; i++)
{
- if (_stricmp(nlhrReply->headers[i].szName, hdr) == 0)
+ if (_stricmp(nlhrReply->headers[i].szName, hdr) == 0)
{
if (_strnicmp(nlhrReply->headers[i].szValue, "Negotiate", 9) == 0)
szNegoHdr = nlhrReply->headers[i].szValue;
@@ -177,7 +177,7 @@ void NetlibConnFromUrl(const char* szUrl, bool secur, NETLIBOPENCONNECTION &nloc {
secur = secur || _strnicmp(szUrl, "https", 5) == 0;
const char* phost = strstr(szUrl, "://");
-
+
char* szHost = mir_strdup(phost ? phost + 3 : szUrl);
char* ppath = strchr(szHost, '/');
@@ -188,7 +188,7 @@ void NetlibConnFromUrl(const char* szUrl, bool secur, NETLIBOPENCONNECTION &nloc nloc.szHost = szHost;
char* pcolon = strrchr(szHost, ':');
- if (pcolon)
+ if (pcolon)
{
*pcolon = '\0';
nloc.wPort = (WORD)strtol(pcolon+1, NULL, 10);
@@ -197,16 +197,15 @@ void NetlibConnFromUrl(const char* szUrl, bool secur, NETLIBOPENCONNECTION &nloc nloc.flags = (secur ? NLOCF_SSL : 0);
}
-static NetlibConnection* NetlibHttpProcessUrl(NETLIBHTTPREQUEST *nlhr, NetlibUser *nlu, NetlibConnection* nlc,
- const char* szUrl = NULL)
+static NetlibConnection* NetlibHttpProcessUrl(NETLIBHTTPREQUEST *nlhr, NetlibUser *nlu, NetlibConnection* nlc, const char* szUrl = NULL)
{
NETLIBOPENCONNECTION nloc;
- if (szUrl == NULL)
+ if (szUrl == NULL)
NetlibConnFromUrl(nlhr->szUrl, (nlhr->flags & NLHRF_SSL) != 0, nloc);
else
NetlibConnFromUrl(szUrl, false, nloc);
-
+
nloc.flags |= NLOCF_HTTP;
if (nloc.flags & NLOCF_SSL) nlhr->flags |= NLHRF_SSL; else nlhr->flags &= ~NLHRF_SSL;
@@ -238,7 +237,7 @@ struct HttpSecurityContext char *m_szHost;
char *m_szProvider;
- HttpSecurityContext()
+ HttpSecurityContext()
{ m_hNtlmSecurity = NULL; m_szHost = NULL; m_szProvider = NULL; }
~HttpSecurityContext() { Destroy(); }
@@ -324,7 +323,7 @@ static int HttpPeekFirstResponseLine(NetlibConnection *nlc, DWORD dwTimeoutTime, char buffer[2048];
char *peol;
- for (;;)
+ for (;;)
{
bytesPeeked = RecvWithTimeoutTime(nlc, dwTimeoutTime, buffer, SIZEOF(buffer) - 1,
MSG_PEEK | recvFlags);
@@ -334,19 +333,19 @@ static int HttpPeekFirstResponseLine(NetlibConnection *nlc, DWORD dwTimeoutTime, SetLastError(ERROR_HANDLE_EOF);
return 0;
}
- if (bytesPeeked == SOCKET_ERROR)
+ if (bytesPeeked == SOCKET_ERROR)
return 0;
buffer[bytesPeeked] = '\0';
peol = strchr(buffer, '\n');
- if (peol == NULL)
+ if (peol == NULL)
{
- if ((int)strlen(buffer) < bytesPeeked)
+ if ((int)strlen(buffer) < bytesPeeked)
{
SetLastError(ERROR_BAD_FORMAT);
return 0;
}
- if (bytesPeeked == SIZEOF(buffer) - 1)
+ if (bytesPeeked == SIZEOF(buffer) - 1)
{
SetLastError(ERROR_BUFFER_OVERFLOW);
return 0;
@@ -357,8 +356,8 @@ static int HttpPeekFirstResponseLine(NetlibConnection *nlc, DWORD dwTimeoutTime, else
break;
}
-
- if (peol == buffer)
+
+ if (peol == buffer)
{
SetLastError(ERROR_BAD_FORMAT);
return 0;
@@ -366,14 +365,14 @@ static int HttpPeekFirstResponseLine(NetlibConnection *nlc, DWORD dwTimeoutTime, *peol = '\0';
- if (_strnicmp(buffer, "HTTP/", 5))
+ if (_strnicmp(buffer, "HTTP/", 5))
{
SetLastError(ERROR_BAD_FORMAT);
return 0;
}
size_t off = strcspn(buffer, " \t");
- if (off >= (unsigned)bytesPeeked)
+ if (off >= (unsigned)bytesPeeked)
return 0;
char* pResultCode = buffer + off;
@@ -404,7 +403,7 @@ static int SendHttpRequestAndData(struct NetlibConnection *nlc, struct Resizable (nlhr->flags & NLHRF_NOPROXY ? MSG_RAW : 0);
int bytesSent = NLSend(nlc, httpRequest->sz, httpRequest->iEnd, hflags);
- if (bytesSent != SOCKET_ERROR && sendData && nlhr->dataLength)
+ if (bytesSent != SOCKET_ERROR && sendData && nlhr->dataLength)
{
DWORD sflags = (nlhr->flags & NLHRF_DUMPASTEXT ? MSG_DUMPASTEXT : 0) |
(nlhr->flags & (NLHRF_NODUMP | NLHRF_NODUMPSEND) ?
@@ -436,15 +435,15 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) int bytesSent;
bool lastFirstLineFail = false;
- if (nlhr == NULL || nlhr->cbSize < NETLIBHTTPREQUEST_V1_SIZE || nlhr->szUrl == NULL || nlhr->szUrl[0] == '\0')
+ if (nlhr == NULL || nlhr->cbSize < NETLIBHTTPREQUEST_V1_SIZE || nlhr->szUrl == NULL || nlhr->szUrl[0] == '\0')
{
SetLastError(ERROR_INVALID_PARAMETER);
return SOCKET_ERROR;
}
- int hdrTimeout = nlhr->cbSize > NETLIBHTTPREQUEST_V1_SIZE && nlhr->timeout ? nlhr->timeout : HTTPRECVHEADERSTIMEOUT;
+ int hdrTimeout = nlhr->cbSize > NETLIBHTTPREQUEST_V1_SIZE && nlhr->timeout ? nlhr->timeout : HTTPRECVHEADERSTIMEOUT;
- switch(nlhr->requestType)
+ switch(nlhr->requestType)
{
case REQUEST_GET: pszRequest = "GET"; break;
case REQUEST_POST: pszRequest = "POST"; break;
@@ -459,7 +458,7 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) if ( !nlc->usingHttpGateway)
{
- if ( !NetlibEnterNestedCS(nlc, NLNCS_SEND))
+ if ( !NetlibEnterNestedCS(nlc, NLNCS_SEND))
return SOCKET_ERROR;
}
@@ -470,10 +469,10 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) int count = 11;
while (--count)
{
- if ( !NetlibReconnect(nlc))
- {
- bytesSent = SOCKET_ERROR;
- break;
+ if ( !NetlibReconnect(nlc))
+ {
+ bytesSent = SOCKET_ERROR;
+ break;
}
if ( !pszUrl)
@@ -493,7 +492,7 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) ppath = strchr(phost, '/');
if (ppath == phost) phost = NULL;
- if (nlhr->flags & NLHRF_GENERATEHOST)
+ if (nlhr->flags & NLHRF_GENERATEHOST)
{
szHost = mir_strdup(phost);
if (ppath && phost) szHost[ppath - phost] = 0;
@@ -504,7 +503,7 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) pszUrl = ppath ? ppath : "/";
}
- if (usingProxy && phost && !nlc->dnsThroughProxy)
+ if (usingProxy && phost && !nlc->dnsThroughProxy)
{
char* tszHost = mir_strdup(phost);
if (ppath && phost) tszHost[ppath - phost] = 0;
@@ -513,7 +512,7 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) if (inet_addr(tszHost) == INADDR_NONE)
{
DWORD ip = DnsLookup(nlc->nlu, tszHost);
- if (ip && szHost)
+ if (ip && szHost)
{
mir_free(szHost);
szHost = (char*)mir_alloc(64);
@@ -549,7 +548,7 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) if (nlc->proxyAuthNeeded && proxyAuthList.getCount())
{
- if (httpSecurity.m_szProvider == NULL && nlc->szProxyServer)
+ if (httpSecurity.m_szProvider == NULL && nlc->szProxyServer)
{
const char* szAuthMethodNlu = proxyAuthList.find(nlc->szProxyServer);
@@ -576,7 +575,7 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) if (nlhr->headers[i].szValue == NULL) continue;
AppendToCharBuffer(&httpRequest, "%s: %s\r\n", nlhr->headers[i].szName, nlhr->headers[i].szValue);
}
- if (szHost && !doneHostHeader)
+ if (szHost && !doneHostHeader)
AppendToCharBuffer(&httpRequest, "%s: %s\r\n", "Host", szHost);
if (pszProxyAuthHdr && !doneProxyAuthHeader)
AppendToCharBuffer(&httpRequest, "%s: %s\r\n", "Proxy-Authorization", pszProxyAuthHdr);
@@ -640,7 +639,7 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) else
nlhrReply = NetlibHttpRecv(nlc, hflags, dflags);
- if (nlhrReply)
+ if (nlhrReply)
{
char* tmpUrl = NetlibHttpFindHeader(nlhrReply, "Location");
if (tmpUrl)
@@ -658,7 +657,7 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) nlc->szNewUrl = (char*)mir_realloc(nlc->szNewUrl, rlen + strlen(tmpUrl) * 3 + 1);
strncpy(nlc->szNewUrl, pszFullUrl, rlen);
- strcpy(nlc->szNewUrl + rlen, tmpUrl);
+ strcpy(nlc->szNewUrl + rlen, tmpUrl);
pszFullUrl = nlc->szNewUrl;
pszUrl = NULL;
@@ -682,7 +681,7 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) break;
}
}
- else if (resultCode == 401 && !doneAuthHeader) //auth required
+ else if (resultCode == 401 && !doneAuthHeader) //auth required
{
if (nlhr->requestType == REQUEST_HEAD)
nlhrReply = (NETLIBHTTPREQUEST*)NetlibHttpRecvHeaders((WPARAM)nlc, hflags);
@@ -690,7 +689,7 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) nlhrReply = NetlibHttpRecv(nlc, hflags, dflags);
mir_free(pszAuthHdr); pszAuthHdr = NULL;
- if (nlhrReply)
+ if (nlhrReply)
{
char *szAuthStr = NULL;
if ( !complete)
@@ -699,7 +698,7 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) httpSecurity.m_szProvider);
if (szAuthStr)
{
- char *szChallenge = strchr(szAuthStr, ' ');
+ char *szChallenge = strchr(szAuthStr, ' ');
if ( !szChallenge || !*lrtrimp(szChallenge)) complete = true;
}
}
@@ -711,13 +710,13 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) if (szAuthStr)
{
- char *szChallenge = strchr(szAuthStr, ' ');
+ char *szChallenge = strchr(szAuthStr, ' ');
if (szChallenge) { *szChallenge = 0; szChallenge = lrtrimp(szChallenge + 1); }
- pszAuthHdr = httpSecurity.Execute(nlc, szHost, szAuthStr, szChallenge, complete);
+ pszAuthHdr = httpSecurity.Execute(nlc, szHost, szAuthStr, szChallenge, complete);
}
}
- if (pszAuthHdr == NULL)
+ if (pszAuthHdr == NULL)
{
proxyAuthList.add(szHost, NULL);
NetlibHttpSetLastErrorUsingHttpResult(resultCode);
@@ -725,7 +724,7 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) break;
}
}
- else if (resultCode == 407 && !doneProxyAuthHeader) //proxy auth required
+ else if (resultCode == 407 && !doneProxyAuthHeader) //proxy auth required
{
if (nlhr->requestType == REQUEST_HEAD)
nlhrReply = (NETLIBHTTPREQUEST*)NetlibHttpRecvHeaders((WPARAM)nlc, hflags);
@@ -733,7 +732,7 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) nlhrReply = NetlibHttpRecv(nlc, hflags, dflags);
mir_free(pszProxyAuthHdr); pszProxyAuthHdr = NULL;
- if (nlhrReply)
+ if (nlhrReply)
{
char *szAuthStr = NULL;
if ( !complete)
@@ -742,7 +741,7 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) httpSecurity.m_szProvider);
if (szAuthStr)
{
- char *szChallenge = strchr(szAuthStr, ' ');
+ char *szChallenge = strchr(szAuthStr, ' ');
if ( !szChallenge || !*lrtrimp(szChallenge + 1)) complete = true;
}
}
@@ -754,13 +753,13 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) if (szAuthStr)
{
- char *szChallenge = strchr(szAuthStr, ' ');
+ char *szChallenge = strchr(szAuthStr, ' ');
if (szChallenge) { *szChallenge = 0; szChallenge = lrtrimp(szChallenge + 1); }
- pszProxyAuthHdr = httpSecurity.Execute(nlc, nlc->szProxyServer, szAuthStr, szChallenge, complete);
+ pszProxyAuthHdr = httpSecurity.Execute(nlc, nlc->szProxyServer, szAuthStr, szChallenge, complete);
}
}
- if (pszProxyAuthHdr == NULL)
+ if (pszProxyAuthHdr == NULL)
{
proxyAuthList.add(nlc->szProxyServer, NULL);
NetlibHttpSetLastErrorUsingHttpResult(resultCode);
@@ -770,7 +769,7 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) }
else
break;
-
+
if (pszProxyAuthHdr && resultCode != 407 && !doneProxyAuthHeader)
{
mir_free(pszProxyAuthHdr); pszProxyAuthHdr = NULL;
@@ -789,7 +788,7 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) else
break;
}
- if (count == 0) bytesSent = SOCKET_ERROR;
+ if (count == 0) bytesSent = SOCKET_ERROR;
if (nlhrReply) NetlibHttpFreeRequestStruct(0, (LPARAM)nlhrReply);
//clean up
@@ -813,7 +812,7 @@ INT_PTR NetlibHttpFreeRequestStruct(WPARAM, LPARAM lParam) SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
- if (nlhr->headers)
+ if (nlhr->headers)
{
int i;
for (i=0; i<nlhr->headersCount; i++)
@@ -849,7 +848,7 @@ INT_PTR NetlibHttpRecvHeaders(WPARAM wParam, LPARAM lParam) nlhr->cbSize = sizeof(NETLIBHTTPREQUEST);
nlhr->nlc = nlc; // Needed to id connection in the protocol HTTP gateway wrapper functions
nlhr->requestType = REQUEST_RESPONSE;
-
+
if ( !HttpPeekFirstResponseLine(nlc, dwRequestTimeoutTime, lParam | MSG_PEEK,
&nlhr->resultCode, &nlhr->szResultDescr, &firstLineLength))
{
@@ -860,7 +859,7 @@ INT_PTR NetlibHttpRecvHeaders(WPARAM wParam, LPARAM lParam) buffer = (char*)mir_alloc(bufferSize + 1);
bytesPeeked = NLRecv(nlc, buffer, min(firstLineLength, bufferSize), lParam | MSG_DUMPASTEXT);
- if (bytesPeeked != firstLineLength)
+ if (bytesPeeked != firstLineLength)
{
NetlibLeaveNestedCS(&nlc->ncsRecv);
NetlibHttpFreeRequestStruct(0, (LPARAM)nlhr);
@@ -931,7 +930,7 @@ INT_PTR NetlibHttpRecvHeaders(WPARAM wParam, LPARAM lParam) *peol = 0;
char *pColon = strchr(pbuffer, ':');
- if (pColon == NULL)
+ if (pColon == NULL)
{
NetlibHttpFreeRequestStruct(0, (LPARAM)nlhr); nlhr = NULL;
SetLastError(ERROR_INVALID_DATA);
@@ -956,13 +955,13 @@ INT_PTR NetlibHttpTransaction(WPARAM wParam, LPARAM lParam) if (GetNetlibHandleType(nlu) != NLH_USER || !(nlu->user.flags & NUF_OUTGOING) ||
nlhr == NULL || nlhr->cbSize < NETLIBHTTPREQUEST_V1_SIZE ||
- nlhr->szUrl == NULL || nlhr->szUrl[0] == 0)
+ nlhr->szUrl == NULL || nlhr->szUrl[0] == 0)
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
- NetlibConnection* nlc = NetlibHttpProcessUrl(nlhr, nlu, (NetlibConnection*)nlhr->nlc);
+ NetlibConnection* nlc = NetlibHttpProcessUrl(nlhr, nlu, (NetlibConnection*)nlhr->nlc);
if (nlc == NULL) return 0;
{
@@ -976,12 +975,12 @@ INT_PTR NetlibHttpTransaction(WPARAM wParam, LPARAM lParam) bool doneUserAgentHeader = NetlibHttpFindHeader(nlhr, "User-Agent") != NULL;
bool doneAcceptEncoding = NetlibHttpFindHeader(nlhr, "Accept-Encoding") != NULL;
- if ( !doneUserAgentHeader || !doneAcceptEncoding)
+ if ( !doneUserAgentHeader || !doneAcceptEncoding)
{
nlhrSend.headers = (NETLIBHTTPHEADER*)mir_alloc(sizeof(NETLIBHTTPHEADER) * (nlhrSend.headersCount + 2));
memcpy(nlhrSend.headers, nlhr->headers, sizeof(NETLIBHTTPHEADER) * nlhr->headersCount);
}
- if ( !doneUserAgentHeader)
+ if ( !doneUserAgentHeader)
{
char *pspace, szMirandaVer[64];
@@ -990,12 +989,12 @@ INT_PTR NetlibHttpTransaction(WPARAM wParam, LPARAM lParam) ++nlhrSend.headersCount;
CallService(MS_SYSTEM_GETVERSIONTEXT, SIZEOF(szMirandaVer), (LPARAM)szMirandaVer);
pspace = strchr(szMirandaVer, ' ');
- if (pspace)
+ if (pspace)
{
*pspace++='\0';
mir_snprintf(szUserAgent, SIZEOF(szUserAgent), "Miranda/%s (%s)", szMirandaVer, pspace);
}
- else
+ else
mir_snprintf(szUserAgent, SIZEOF(szUserAgent), "Miranda/%s", szMirandaVer);
}
if ( !doneAcceptEncoding)
@@ -1004,7 +1003,7 @@ INT_PTR NetlibHttpTransaction(WPARAM wParam, LPARAM lParam) nlhrSend.headers[nlhrSend.headersCount].szValue = "deflate, gzip";
++nlhrSend.headersCount;
}
- if (NetlibHttpSendRequest((WPARAM)nlc, (LPARAM)&nlhrSend) == SOCKET_ERROR)
+ if (NetlibHttpSendRequest((WPARAM)nlc, (LPARAM)&nlhrSend) == SOCKET_ERROR)
{
if ( !doneUserAgentHeader || !doneAcceptEncoding) mir_free(nlhrSend.headers);
NetlibCloseHandle((WPARAM)nlc, 0);
@@ -1021,7 +1020,6 @@ INT_PTR NetlibHttpTransaction(WPARAM wParam, LPARAM lParam) (nlhr->flags & NLHRF_NODUMP ? MSG_NODUMP : (nlhr->flags & NLHRF_DUMPPROXY ? MSG_DUMPPROXY : 0)) |
(nlhr->flags & NLHRF_NOPROXY ? MSG_RAW : 0);
-
if (nlhr->requestType == REQUEST_HEAD)
nlhrReply = (NETLIBHTTPREQUEST*)NetlibHttpRecvHeaders((WPARAM)nlc, 0);
else
@@ -1051,7 +1049,7 @@ void NetlibHttpSetLastErrorUsingHttpResult(int result) SetLastError(ERROR_SUCCESS);
return;
}
- switch(result)
+ switch(result)
{
case 400: SetLastError(ERROR_BAD_FORMAT); break;
case 401:
@@ -1096,9 +1094,9 @@ char* gzip_decode(char *gzip_data, int *len_ptr, int window) gzip_len *= 2;
}
while (gzip_err == Z_BUF_ERROR);
-
+
gzip_len = gzip_err == Z_STREAM_END ? zstr.total_out : -1;
-
+
if (gzip_len <= 0) {
mir_free(output_data);
output_data = NULL;
@@ -1159,14 +1157,14 @@ next: {
NetlibHttpFreeRequestStruct(0, (LPARAM)nlhrReply);
goto next;
- }
+ }
- for (i=0; i<nlhrReply->headersCount; i++)
+ for (i=0; i<nlhrReply->headersCount; i++)
{
- if ( !lstrcmpiA(nlhrReply->headers[i].szName, "Content-Length"))
+ if ( !lstrcmpiA(nlhrReply->headers[i].szName, "Content-Length"))
dataLen = atoi(nlhrReply->headers[i].szValue);
- if ( !lstrcmpiA(nlhrReply->headers[i].szName, "Content-Encoding"))
+ if ( !lstrcmpiA(nlhrReply->headers[i].szName, "Content-Encoding"))
{
cenc = i;
if (strstr(nlhrReply->headers[i].szValue, "gzip"))
@@ -1205,9 +1203,9 @@ next: dataBufferAlloced = dataLen < 0 ? 2048 : dataLen + 1;
nlhrReply->pData = (char*)mir_realloc(nlhrReply->pData, dataBufferAlloced);
- while (chunksz != 0)
+ while (chunksz != 0)
{
- for (;;)
+ for (;;)
{
recvResult = RecvWithTimeoutTime(nlc, GetTickCount() + HTTPRECVDATATIMEOUT,
nlhrReply->pData + nlhrReply->dataLength,
@@ -1215,7 +1213,7 @@ next: dflags | (cenctype ? MSG_NODUMP : 0));
if (recvResult == 0) break;
- if (recvResult == SOCKET_ERROR)
+ if (recvResult == SOCKET_ERROR)
{
NetlibHttpFreeRequestStruct(0, (LPARAM)nlhrReply);
return NULL;
@@ -1228,11 +1226,11 @@ next: }
else
{
- if ((dataBufferAlloced - nlhrReply->dataLength) < 256)
+ if ((dataBufferAlloced - nlhrReply->dataLength) < 256)
{
dataBufferAlloced += 2048;
nlhrReply->pData = (char*)mir_realloc(nlhrReply->pData, dataBufferAlloced);
- if (nlhrReply->pData == NULL)
+ if (nlhrReply->pData == NULL)
{
SetLastError(ERROR_OUTOFMEMORY);
NetlibHttpFreeRequestStruct(0, (LPARAM)nlhrReply);
@@ -1246,7 +1244,7 @@ next: if (chunked)
{
chunksz = NetlibHttpRecvChunkHeader(nlc, false, dflags);
- if (chunksz == SOCKET_ERROR)
+ if (chunksz == SOCKET_ERROR)
{
NetlibHttpFreeRequestStruct(0, (LPARAM)nlhrReply);
return NULL;
diff --git a/src/modules/netlib/netlibhttpproxy.cpp b/src/modules/netlib/netlibhttpproxy.cpp index 7c1ddd53c9..78e3d31491 100644 --- a/src/modules/netlib/netlibhttpproxy.cpp +++ b/src/modules/netlib/netlibhttpproxy.cpp @@ -32,8 +32,7 @@ typedef enum }
RequestType;
-
-static int HttpGatewayReadSetResult(NetlibConnection *nlc, char *buf, int num, int peek)
+static int HttpGatewayReadSetResult(NetlibConnection *nlc, char *buf, int num, int peek)
{
if (nlc->dataBufferLen == 0) return 0;
@@ -41,7 +40,7 @@ static int HttpGatewayReadSetResult(NetlibConnection *nlc, char *buf, int num, i int rbytes = nlc->dataBufferLen - bytes;
memcpy(buf, nlc->dataBuffer, bytes);
- if ( !peek)
+ if ( !peek)
{
memmove(nlc->dataBuffer, nlc->dataBuffer + bytes, rbytes);
nlc->dataBufferLen = rbytes;
@@ -56,13 +55,12 @@ void HttpGatewayRemovePacket(NetlibConnection *nlc, int pck) while (pck-- && nlc->pHttpProxyPacketQueue != NULL) {
NetlibHTTPProxyPacketQueue *p = nlc->pHttpProxyPacketQueue;
nlc->pHttpProxyPacketQueue = nlc->pHttpProxyPacketQueue->next;
-
+
mir_free(p->dataBuffer);
mir_free(p);
}
}
-
static bool NetlibHttpGatewaySend(struct NetlibConnection *nlc, RequestType reqType, const char *buf, int len)
{
NETLIBHTTPREQUEST nlhrSend = {0};
@@ -104,14 +102,14 @@ static bool NetlibHttpGatewaySend(struct NetlibConnection *nlc, RequestType reqT mir_snprintf(szUrl, SIZEOF(szUrl), "%s%u", nlc->nlhpi.szHttpPostUrl, nlc->nlhpi.firstPostSequence);
nlhrSend.szUrl = szUrl;
}
- else
+ else
nlhrSend.szUrl = nlc->nlhpi.szHttpPostUrl;
break;
case reqNewPost:
nlhrSend.requestType = REQUEST_POST;
nlhrSend.szUrl = nlc->nlhpi.szHttpPostUrl;
- break;
+ break;
}
if (nlc->usingDirectHttpGateway)
@@ -127,7 +125,7 @@ static bool NetlibHttpGatewaySend(struct NetlibConnection *nlc, RequestType reqT mir_free((char*)nlc->nloc.szHost);
nlc->nloc = nloc;
- if ( !NetlibDoConnect(nlc))
+ if ( !NetlibDoConnect(nlc))
return false;
}
else
@@ -159,7 +157,7 @@ static bool NetlibHttpGatewayStdPost(NetlibConnection *nlc, int& numPackets) while (p != NULL && np < nlc->nlhpi.combinePackets) { ++np; len += p->dataBufferLen; p = p->next;}
buf = (char*)alloca(len);
-
+
numPackets = np;
int dlen = 0;
@@ -217,7 +215,7 @@ static bool NetlibHttpGatewayOscarPost(NetlibConnection *nlc, const char *buf, i mir_cslock lck(nlc->csHttpSequenceNums);
nlc->nlhpi.firstPostSequence++;
- if (nlc->nlhpi.flags & NLHPIF_GETPOSTSAMESEQUENCE)
+ if (nlc->nlhpi.flags & NLHPIF_GETPOSTSAMESEQUENCE)
nlc->nlhpi.firstGetSequence++;
return res;
@@ -239,18 +237,18 @@ static bool NetlibHttpGatewayOscarPost(NetlibConnection *nlc, const char *buf, i * with the new plugins that use this code.
*/
- NetlibHTTPProxyPacketQueue *p = (NetlibHTTPProxyPacketQueue*)mir_alloc(sizeof(struct NetlibHTTPProxyPacketQueue));
- p->dataBuffer = (PBYTE)mir_alloc(len);
- memcpy(p->dataBuffer, buf, len);
- p->dataBufferLen = len;
- p->next = NULL;
+ NetlibHTTPProxyPacketQueue *p = (NetlibHTTPProxyPacketQueue*)mir_alloc(sizeof(struct NetlibHTTPProxyPacketQueue));
+ p->dataBuffer = (PBYTE)mir_alloc(len);
+ memcpy(p->dataBuffer, buf, len);
+ p->dataBufferLen = len;
+ p->next = NULL;
- /*
- * Now check to see where to insert this in our queue
- */
+ /*
+ * Now check to see where to insert this in our queue
+ */
mir_cslock lck(nlc->csHttpSequenceNums);
- if (nlc->pHttpProxyPacketQueue == NULL)
+ if (nlc->pHttpProxyPacketQueue == NULL)
nlc->pHttpProxyPacketQueue = p;
else {
NetlibHTTPProxyPacketQueue *t = nlc->pHttpProxyPacketQueue;
@@ -315,7 +313,7 @@ int NetlibHttpGatewayRecv(struct NetlibConnection *nlc, char *buf, int len, int }
else
{
- if ( !NetlibHttpGatewayStdPost(nlc, numPackets))
+ if ( !NetlibHttpGatewayStdPost(nlc, numPackets))
{
if (GetLastError() == ERROR_ACCESS_DENIED || nlc->termRequested)
break;
@@ -327,7 +325,7 @@ int NetlibHttpGatewayRecv(struct NetlibConnection *nlc, char *buf, int len, int NETLIBHTTPREQUEST *nlhrReply = NetlibHttpRecv(nlc, flags | MSG_RAW | MSG_DUMPPROXY, MSG_RAW | MSG_DUMPPROXY);
if (nlhrReply == NULL) return SOCKET_ERROR;
- if (nlc->nlu->user.pfnHttpGatewayUnwrapRecv && !(flags & MSG_NOHTTPGATEWAYWRAP))
+ if (nlc->nlu->user.pfnHttpGatewayUnwrapRecv && !(flags & MSG_NOHTTPGATEWAYWRAP))
{
nlhrReply->pData = (char*)nlc->nlu->user.pfnHttpGatewayUnwrapRecv(nlhrReply,
(PBYTE)nlhrReply->pData, nlhrReply->dataLength, &nlhrReply->dataLength, mir_realloc);
@@ -404,10 +402,10 @@ int NetlibInitHttpConnection(struct NetlibConnection *nlc, struct NetlibUser *nl {
NETLIBHTTPREQUEST *nlhrReply = NULL;
- nlc->nlhpi.firstGetSequence = 1;
+ nlc->nlhpi.firstGetSequence = 1;
nlc->nlhpi.firstPostSequence = 1;
- if (nlu->user.szHttpGatewayHello != NULL)
+ if (nlu->user.szHttpGatewayHello != NULL)
{
nlc->usingHttpGateway = true;
if (NetlibHttpGatewaySend(nlc, reqHelloGet, NULL, 0))
@@ -415,14 +413,14 @@ int NetlibInitHttpConnection(struct NetlibConnection *nlc, struct NetlibUser *nl nlc->usingHttpGateway = false;
if (nlhrReply == NULL) return 0;
- if (nlhrReply->resultCode != 200)
+ if (nlhrReply->resultCode != 200)
{
NetlibHttpSetLastErrorUsingHttpResult(nlhrReply->resultCode);
NetlibHttpFreeRequestStruct(0, (LPARAM)nlhrReply);
return 0;
}
}
- if ( !nlu->user.pfnHttpGatewayInit(nlc, nloc, nlhrReply))
+ if ( !nlu->user.pfnHttpGatewayInit(nlc, nloc, nlhrReply))
{
NetlibHttpFreeRequestStruct(0, (LPARAM)nlhrReply);
return 0;
@@ -432,7 +430,7 @@ int NetlibInitHttpConnection(struct NetlibConnection *nlc, struct NetlibUser *nl /*
* Gena01 - Ok, we should be able to use just POST. Needed for Yahoo, NO GET requests
*/
- if (nlc->nlhpi.szHttpPostUrl == NULL)
+ if (nlc->nlhpi.szHttpPostUrl == NULL)
{
SetLastError(ERROR_BAD_FORMAT);
return 0;
@@ -477,7 +475,7 @@ INT_PTR NetlibHttpSetSticky(WPARAM wParam, LPARAM lParam) {
struct NetlibUser * nu = (struct NetlibUser*)wParam;
if (GetNetlibHandleType(nu) != NLH_USER) return ERROR_INVALID_PARAMETER;
- mir_free(nu->szStickyHeaders);
+ mir_free(nu->szStickyHeaders);
nu->szStickyHeaders = mir_strdup((char*)lParam); // pointer is ours
return 0;
}
diff --git a/src/modules/netlib/netliblog.cpp b/src/modules/netlib/netliblog.cpp index 6c7c63e2bd..4eac00a0c4 100644 --- a/src/modules/netlib/netliblog.cpp +++ b/src/modules/netlib/netliblog.cpp @@ -76,7 +76,7 @@ static INT_PTR CALLBACK LogOptionsDlgProc(HWND hwndDlg, UINT message, WPARAM wPa CheckDlgButton(hwndDlg, IDC_DUMPSSL, logOptions.dumpSsl?BST_CHECKED:BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_TEXTDUMPS, logOptions.textDumps?BST_CHECKED:BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_AUTODETECTTEXT, logOptions.autoDetectText?BST_CHECKED:BST_UNCHECKED);
- {
+ {
int i;
for (i=0; i < SIZEOF(szTimeFormats); i++)
SendDlgItemMessage(hwndDlg, IDC_TIMEFORMAT, CB_ADDSTRING, 0, (LPARAM)TranslateTS(szTimeFormats[i]));
@@ -88,7 +88,8 @@ static INT_PTR CALLBACK LogOptionsDlgProc(HWND hwndDlg, UINT message, WPARAM wPa SetDlgItemText(hwndDlg, IDC_FILENAME, logOptions.szUserFile);
SetDlgItemText(hwndDlg, IDC_PATH, logOptions.szFile);
CheckDlgButton(hwndDlg, IDC_SHOWTHISDLGATSTART, db_get_b(NULL, "Netlib", "ShowLogOptsAtStart", 0)?BST_CHECKED:BST_UNCHECKED);
- { DBVARIANT dbv;
+ {
+ DBVARIANT dbv;
if ( !DBGetContactSettingString(NULL, "Netlib", "RunAtStart", &dbv)) {
SetDlgItemTextA(hwndDlg, IDC_RUNATSTART, dbv.pszVal);
DBFreeVariant(&dbv);
@@ -141,7 +142,7 @@ static INT_PTR CALLBACK LogOptionsDlgProc(HWND hwndDlg, UINT message, WPARAM wPa if ((HWND)lParam == GetFocus())
CheckDlgButton(hwndDlg, IDC_TOFILE, BST_CHECKED);
- {
+ {
TCHAR path[MAX_PATH];
GetWindowText((HWND)lParam, path, MAX_PATH);
@@ -153,7 +154,8 @@ static INT_PTR CALLBACK LogOptionsDlgProc(HWND hwndDlg, UINT message, WPARAM wPa break;
case IDC_FILENAMEBROWSE:
case IDC_RUNATSTARTBROWSE:
- { TCHAR str[MAX_PATH+2];
+ {
+ TCHAR str[MAX_PATH+2];
OPENFILENAME ofn = {0};
TCHAR filter[512], *pfilter;
@@ -191,7 +193,8 @@ static INT_PTR CALLBACK LogOptionsDlgProc(HWND hwndDlg, UINT message, WPARAM wPa break;
}
case IDC_RUNNOW:
- { TCHAR str[MAX_PATH+1];
+ {
+ TCHAR str[MAX_PATH+1];
STARTUPINFO si = {0};
PROCESS_INFORMATION pi;
GetDlgItemText(hwndDlg, IDC_RUNATSTART, str, MAX_PATH);
@@ -325,7 +328,7 @@ static INT_PTR NetlibLog(WPARAM wParam, LPARAM lParam) }
/* if the Netlib user handle is NULL, just pretend its not */
- if (nlu == NULL) {
+ if (nlu == NULL) {
if ( !logOptions.toLog)
return 1;
nlu = &nludummy;
@@ -385,7 +388,7 @@ static INT_PTR NetlibLog(WPARAM wParam, LPARAM lParam) size_t len = strlen(pszMsg);
fprintf(fp, "%s%s%s", szHead, pszMsg, pszMsg[len-1] == '\n' ? "" : "\r\n");
fclose(fp);
- }
+ }
}
LOGMSG logMsg = { szHead, pszMsg };
@@ -406,7 +409,7 @@ static INT_PTR NetlibLogW(WPARAM wParam, LPARAM lParam) void NetlibLogf(NetlibUser* nlu, const char *fmt, ...)
{
- if (nlu == NULL)
+ if (nlu == NULL)
{
if ( !logOptions.toLog)
return;
@@ -424,7 +427,6 @@ void NetlibLogf(NetlibUser* nlu, const char *fmt, ...) NetlibLog((WPARAM)nlu, (LPARAM)szText);
}
-
void NetlibDumpData(struct NetlibConnection *nlc, PBYTE buf, int len, int sent, int flags)
{
int isText = 1;
diff --git a/src/modules/netlib/netlibopenconn.cpp b/src/modules/netlib/netlibopenconn.cpp index ae4526f70f..8d2a5e74fc 100644 --- a/src/modules/netlib/netlibopenconn.cpp +++ b/src/modules/netlib/netlibopenconn.cpp @@ -109,7 +109,7 @@ bool RecvUntilTimeout(struct NetlibConnection *nlc, char *buf, int len, int flag }
static int NetlibInitSocks4Connection(NetlibConnection *nlc, NetlibUser *nlu, NETLIBOPENCONNECTION *nloc)
-{
+{
// http://www.socks.nec.com/protocol/socks4.protocol and http://www.socks.nec.com/protocol/socks4a.protocol
if ( !nloc->szHost || !nloc->szHost[0]) return 0;
@@ -441,7 +441,7 @@ retry: continue;
}
- while (true) {
+ while (true) {
fd_set r, w, e;
FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
FD_SET(nlc->s, &r);
@@ -450,7 +450,7 @@ retry: if ((rc = select(0, &r, &w, &e, &tv)) == SOCKET_ERROR)
break;
- if (rc > 0) {
+ if (rc > 0) {
if (FD_ISSET(nlc->s, &w)){
// connection was successful
rc = 0;
@@ -585,7 +585,7 @@ retry: SOCKET s6 = ai->ai_family == AF_INET6 ? nlc->s : INVALID_SOCKET;
if ( !BindSocketToPort(nlc->nlu->settings.szOutgoingPorts, s, s6, &nlc->nlu->inportnum))
NetlibLogf(nlc->nlu, "Netlib connect: Not enough ports for outgoing connections specified");
- }
+ }
// try a connect
if (connect(nlc->s, ai->ai_addr, (int)ai->ai_addrlen) == 0) {
@@ -606,11 +606,11 @@ retry: FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
FD_SET(nlc->s, &r);
FD_SET(nlc->s, &w);
- FD_SET(nlc->s, &e);
- if ((rc = select(0, &r, &w, &e, &tv)) == SOCKET_ERROR)
+ FD_SET(nlc->s, &e);
+ if ((rc = select(0, &r, &w, &e, &tv)) == SOCKET_ERROR)
break;
- if (rc > 0) {
+ if (rc > 0) {
if (FD_ISSET(nlc->s, &w)){
// connection was successful
rc = 0;
@@ -626,7 +626,7 @@ retry: int len = sizeof(lasterr);
rc = SOCKET_ERROR;
getsockopt(nlc->s, SOL_SOCKET, SO_ERROR, (char*)&lasterr, &len);
- if (lasterr == WSAEADDRINUSE && ++retrycnt <= 2)
+ if (lasterr == WSAEADDRINUSE && ++retrycnt <= 2)
{
closesocket(nlc->s);
nlc->s = INVALID_SOCKET;
@@ -634,12 +634,12 @@ retry: }
}
break;
- }
+ }
else if (Miranda_Terminated()) {
rc = SOCKET_ERROR;
lasterr = ERROR_TIMEOUT;
break;
- }
+ }
else if (nloc->cbSize == sizeof(NETLIBOPENCONNECTION) && nloc->flags & NLOCF_V2 && nloc->waitcallback != NULL && nloc->waitcallback(&dwTimeout) == 0) {
rc = SOCKET_ERROR;
lasterr = ERROR_TIMEOUT;
@@ -851,7 +851,7 @@ INT_PTR NetlibOpenConnection(WPARAM wParam, LPARAM lParam) NetlibInitializeNestedCS(&nlc->ncsRecv);
if ( !NetlibDoConnect(nlc)) {
- FreePartiallyInitedConnection(nlc);
+ FreePartiallyInitedConnection(nlc);
return 0;
}
diff --git a/src/modules/netlib/netlibopts.cpp b/src/modules/netlib/netlibopts.cpp index c2427c951e..19548210b5 100644 --- a/src/modules/netlib/netlibopts.cpp +++ b/src/modules/netlib/netlibopts.cpp @@ -36,31 +36,31 @@ static const UINT outgoingConnectionsControls[] = {
IDC_STATIC12,
IDC_USEPROXY,
- IDC_STATIC21, IDC_PROXYTYPE,
- IDC_STATIC22, IDC_PROXYHOST, IDC_STATIC23, IDC_PROXYPORT, IDC_STOFTENPORT,
- IDC_PROXYAUTH,
- IDC_STATIC31, IDC_PROXYUSER, IDC_STATIC32, IDC_PROXYPASS,
- IDC_PROXYDNS,
+ IDC_STATIC21, IDC_PROXYTYPE,
+ IDC_STATIC22, IDC_PROXYHOST, IDC_STATIC23, IDC_PROXYPORT, IDC_STOFTENPORT,
+ IDC_PROXYAUTH,
+ IDC_STATIC31, IDC_PROXYUSER, IDC_STATIC32, IDC_PROXYPASS,
+ IDC_PROXYDNS,
IDC_SPECIFYPORTSO,
- IDC_PORTSRANGEO,
- IDC_STATIC54,
- IDC_VALIDATESSL};
+ IDC_PORTSRANGEO,
+ IDC_STATIC54,
+ IDC_VALIDATESSL};
static const UINT useProxyControls[] = {
IDC_STATIC21, IDC_PROXYTYPE,
IDC_STATIC22, IDC_PROXYHOST, IDC_STATIC23, IDC_PROXYPORT, IDC_STOFTENPORT,
IDC_PROXYAUTH,
- IDC_STATIC31, IDC_PROXYUSER, IDC_STATIC32, IDC_PROXYPASS,
+ IDC_STATIC31, IDC_PROXYUSER, IDC_STATIC32, IDC_PROXYPASS,
IDC_PROXYDNS};
static const UINT specifyOPortsControls[] = {
IDC_PORTSRANGEO,
- IDC_STATIC54
+ IDC_STATIC54
};
static const UINT incomingConnectionsControls[] = {
IDC_STATIC43,
IDC_SPECIFYPORTS,
IDC_PORTSRANGE,
IDC_STATIC52,
- IDC_ENABLEUPNP};
+ IDC_ENABLEUPNP};
static const UINT specifyPortsControls[] = {
IDC_PORTSRANGE,
IDC_STATIC52};
@@ -142,7 +142,7 @@ static void CombineSettingsStructs(NETLIBUSERSETTINGS *dest, DWORD *destFlags, N }
if (sourceFlags&NUF_INCOMING) {
if (*destFlags&NUF_INCOMING) {
- if (dest->enableUPnP != source->enableUPnP) dest->enableUPnP = 2;
+ if (dest->enableUPnP != source->enableUPnP) dest->enableUPnP = 2;
if (dest->specifyIncomingPorts != source->specifyIncomingPorts) dest->specifyIncomingPorts = 2;
CombineSettingsStrings(&dest->szIncomingPorts, &source->szIncomingPorts);
}
@@ -258,7 +258,7 @@ static INT_PTR CALLBACK DlgProcNetlibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
- {
+ {
int iItem = SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_ADDSTRING, 0, (LPARAM)TranslateT("<All connections>"));
SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_SETITEMDATA, iItem, (LPARAM)-1);
SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_SETCURSEL, iItem, 0);
@@ -278,7 +278,7 @@ static INT_PTR CALLBACK DlgProcNetlibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, }
}
}
-
+
SendMessage(hwndDlg, M_REFRESHALL, 0, 0);
return TRUE;
@@ -308,7 +308,7 @@ static INT_PTR CALLBACK DlgProcNetlibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, AddProxyTypeItem(hwndDlg, PROXYTYPE_SOCKS5, settings.proxyType);
if (flags & (NUF_HTTPCONNS | NUF_HTTPGATEWAY)) AddProxyTypeItem(hwndDlg, PROXYTYPE_HTTP, settings.proxyType);
if ( !(flags & NUF_NOHTTPSOPTION)) AddProxyTypeItem(hwndDlg, PROXYTYPE_HTTPS, settings.proxyType);
- if (flags & (NUF_HTTPCONNS | NUF_HTTPGATEWAY) || !(flags & NUF_NOHTTPSOPTION))
+ if (flags & (NUF_HTTPCONNS | NUF_HTTPGATEWAY) || !(flags & NUF_NOHTTPSOPTION))
AddProxyTypeItem(hwndDlg, PROXYTYPE_IE, settings.proxyType);
SetDlgItemTextA(hwndDlg, IDC_PROXYHOST, settings.szProxyServer?settings.szProxyServer:"");
if (settings.wProxyPort) SetDlgItemInt(hwndDlg, IDC_PROXYPORT, settings.wProxyPort, FALSE);
@@ -393,7 +393,7 @@ static INT_PTR CALLBACK DlgProcNetlibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, case IDC_PROXYTYPE:
if (HIWORD(wParam) != CBN_SELCHANGE) return 0;
- {
+ {
int newValue = SendDlgItemMessage(hwndDlg, IDC_PROXYTYPE, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_PROXYTYPE, CB_GETCURSEL, 0, 0), 0);
if (iUser == -1) {
if (newValue == 0) return 0;
@@ -407,7 +407,7 @@ static INT_PTR CALLBACK DlgProcNetlibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, }
SendMessage(hwndDlg, M_REFRESHALL, 0, 0);
}
- else
+ else
{
tempSettings[iUser]->settings.proxyType = newValue;
SendMessage(hwndDlg, M_REFRESHENABLING, 0, 0);
@@ -429,19 +429,19 @@ static INT_PTR CALLBACK DlgProcNetlibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, case IDC_SPECIFYPORTSO:
ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, specifyOutgoingPorts));
break;
- case IDC_ENABLEUPNP:
+ case IDC_ENABLEUPNP:
ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, enableUPnP));
- break;
- case IDC_VALIDATESSL:
+ break;
+ case IDC_VALIDATESSL:
ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, validateSSL));
- break;
- case IDC_PROXYHOST:
+ break;
+ case IDC_PROXYHOST:
if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0;
ChangeSettingStringByEdit(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, szProxyServer));
break;
case IDC_PROXYPORT:
if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0;
- {
+ {
int newValue = GetDlgItemInt(hwndDlg, LOWORD(wParam), NULL, FALSE);
if (iUser == -1) {
for (int i=0; i < tempSettings.getCount(); i++)
@@ -471,7 +471,7 @@ static INT_PTR CALLBACK DlgProcNetlibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, ShowWindow( GetDlgItem(hwndDlg, IDC_RECONNECTREQD), SW_SHOW);
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
break;
-
+
case WM_NOTIFY:
switch(((LPNMHDR)lParam)->idFrom) {
case 0:
diff --git a/src/modules/netlib/netlibsecurity.cpp b/src/modules/netlib/netlibsecurity.cpp index c95b4fd7ab..05ee106aa7 100644 --- a/src/modules/netlib/netlibsecurity.cpp +++ b/src/modules/netlib/netlibsecurity.cpp @@ -92,7 +92,7 @@ static void LoadSecurityLibrary(void) g_pSSPI = pInitSecurityInterface();
}
- if (g_pSSPI == NULL)
+ if (g_pSSPI == NULL)
{
FreeLibrary(g_hSecurity);
g_hSecurity = NULL;
@@ -130,7 +130,7 @@ HANDLE NetlibInitSecurityProvider(const TCHAR* szProvider, const TCHAR* szPrinci }
else secCnt++;
- if (g_pSSPI != NULL)
+ if (g_pSSPI != NULL)
{
PSecPkgInfo ntlmSecurityPackageInfo;
bool isGSSAPI = _tcsicmp(szProvider, _T("GSSAPI")) == 0;
@@ -167,7 +167,7 @@ void NetlibDestroySecurityProvider(HANDLE hSecurity) WaitForSingleObject(hSecMutex, INFINITE);
- if (ntlmCnt != 0)
+ if (ntlmCnt != 0)
{
NtlmHandleType* hNtlm = (NtlmHandleType*)hSecurity;
if (SecIsValidHandle(&hNtlm->hClientContext)) g_pSSPI->DeleteSecurityContext(&hNtlm->hClientContext);
@@ -214,7 +214,7 @@ char* CompleteGssapi(HANDLE hSecurity, unsigned char *szChallenge, unsigned chls SecPkgContext_Sizes sizes;
sc = g_pSSPI->QueryContextAttributes(&hNtlm->hClientContext, SECPKG_ATTR_SIZES, &sizes);
- if (sc != SEC_E_OK)
+ if (sc != SEC_E_OK)
{
ReportSecError(sc, __LINE__);
return NULL;
@@ -234,17 +234,16 @@ char* CompleteGssapi(HANDLE hSecurity, unsigned char *szChallenge, unsigned chls SecBufferDesc outBuffersDesc = { SECBUFFER_VERSION, 3, outBuffers };
sc = g_pSSPI->EncryptMessage(&hNtlm->hClientContext, SECQOP_WRAP_NO_ENCRYPT, &outBuffersDesc, 0);
- if (sc != SEC_E_OK)
+ if (sc != SEC_E_OK)
{
ReportSecError(sc, __LINE__);
return NULL;
}
unsigned i, ressz = 0;
- for (i=0; i < outBuffersDesc.cBuffers; i++)
+ for (i=0; i < outBuffersDesc.cBuffers; i++)
ressz += outBuffersDesc.pBuffers[i].cbBuffer;
-
unsigned char *response = (unsigned char*)alloca(ressz), *p = response;
for (i=0; i < outBuffersDesc.cBuffers; i++)
{
@@ -262,8 +261,7 @@ char* CompleteGssapi(HANDLE hSecurity, unsigned char *szChallenge, unsigned chls return mir_strdup(nlb64.pszEncoded);
}
-char* NtlmCreateResponseFromChallenge(HANDLE hSecurity, const char *szChallenge, const TCHAR* login, const TCHAR* psw,
- bool http, unsigned& complete)
+char* NtlmCreateResponseFromChallenge(HANDLE hSecurity, const char *szChallenge, const TCHAR* login, const TCHAR* psw, bool http, unsigned& complete)
{
SECURITY_STATUS sc;
SecBufferDesc outputBufferDescriptor, inputBufferDescriptor;
@@ -276,12 +274,12 @@ char* NtlmCreateResponseFromChallenge(HANDLE hSecurity, const char *szChallenge, if (hSecurity == NULL || ntlmCnt == 0) return NULL;
- if (_tcsicmp(hNtlm->szProvider, _T("Basic")))
+ if (_tcsicmp(hNtlm->szProvider, _T("Basic")))
{
bool isGSSAPI = _tcsicmp(hNtlm->szProvider, _T("GSSAPI")) == 0;
TCHAR *szProvider = isGSSAPI ? _T("Kerberos") : hNtlm->szProvider;
bool hasChallenge = szChallenge != NULL && szChallenge[0] != '\0';
- if (hasChallenge)
+ if (hasChallenge)
{
nlb64.cchEncoded = lstrlenA(szChallenge);
nlb64.pszEncoded = (char*)szChallenge;
@@ -300,17 +298,17 @@ char* NtlmCreateResponseFromChallenge(HANDLE hSecurity, const char *szChallenge, inputSecurityToken.pvBuffer = nlb64.pbDecoded;
// try to decode the domain name from the NTLM challenge
- if (login != NULL && login[0] != '\0' && !hNtlm->hasDomain)
+ if (login != NULL && login[0] != '\0' && !hNtlm->hasDomain)
{
NtlmType2packet* pkt = (NtlmType2packet*)nlb64.pbDecoded;
- if ( !strncmp(pkt->sign, "NTLMSSP", 8) && pkt->type == 2)
+ if ( !strncmp(pkt->sign, "NTLMSSP", 8) && pkt->type == 2)
{
wchar_t* domainName = (wchar_t*)&nlb64.pbDecoded[pkt->targetName.offset];
int domainLen = pkt->targetName.len;
// Negotiate ANSI? if yes, convert the ANSI name to unicode
- if ((pkt->flags & 1) == 0)
+ if ((pkt->flags & 1) == 0)
{
int bufsz = MultiByteToWideChar(CP_ACP, 0, (char*)domainName, domainLen, NULL, 0);
wchar_t* buf = (wchar_t*)alloca(bufsz * sizeof(wchar_t));
@@ -320,7 +318,7 @@ char* NtlmCreateResponseFromChallenge(HANDLE hSecurity, const char *szChallenge, else
domainLen /= sizeof(wchar_t);
- if (domainLen)
+ if (domainLen)
{
size_t newLoginLen = _tcslen(login) + domainLen + 1;
TCHAR *newLogin = (TCHAR*)alloca(newLoginLen * sizeof(TCHAR));
@@ -348,12 +346,11 @@ char* NtlmCreateResponseFromChallenge(HANDLE hSecurity, const char *szChallenge, NetlibLogf(NULL, "Security login requested, user: %S pssw: %s", login, psw ? "(exist)" : "(no psw)");
-
const TCHAR* loginName = login;
const TCHAR* domainName = _tcschr(login, '\\');
int domainLen = 0;
int loginLen = lstrlen(loginName);
- if (domainName != NULL)
+ if (domainName != NULL)
{
loginName = domainName + 1;
loginLen = lstrlen(loginName);
@@ -367,7 +364,6 @@ char* NtlmCreateResponseFromChallenge(HANDLE hSecurity, const char *szChallenge, domainLen = lstrlen(++domainName);
}
-
auth.User = (PWORD)loginName;
auth.UserLength = loginLen;
auth.Password = (PWORD)psw;
@@ -376,14 +372,13 @@ char* NtlmCreateResponseFromChallenge(HANDLE hSecurity, const char *szChallenge, auth.DomainLength = domainLen;
auth.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
-
hNtlm->hasDomain = domainLen != 0;
}
sc = g_pSSPI->AcquireCredentialsHandle(NULL, szProvider,
SECPKG_CRED_OUTBOUND, NULL, hNtlm->hasDomain ? &auth : NULL, NULL, NULL,
&hNtlm->hClientCredential, &tokenExpiration);
- if (sc != SEC_E_OK)
+ if (sc != SEC_E_OK)
{
ReportSecError(sc, __LINE__);
return NULL;
@@ -428,7 +423,7 @@ char* NtlmCreateResponseFromChallenge(HANDLE hSecurity, const char *szChallenge, size_t authLen = strlen(szLogin) + strlen(szPassw) + 5;
char *szAuth = (char*)alloca(authLen);
-
+
nlb64.cbDecoded = mir_snprintf(szAuth, authLen, "%s:%s", szLogin, szPassw);
nlb64.pbDecoded = (PBYTE)szAuth;
complete = true;
@@ -471,7 +466,6 @@ static INT_PTR InitSecurityProviderService2(WPARAM, LPARAM lParam) HANDLE hSecurity;
-
if (req->flags & NNR_UNICODE)
hSecurity = NetlibInitSecurityProvider(req->szProviderName, req->szPrincipal);
else
@@ -505,7 +499,6 @@ static INT_PTR NtlmCreateResponseService2(WPARAM wParam, LPARAM lParam) char* response;
-
if (req->flags & NNR_UNICODE)
{
response = NtlmCreateResponseFromChallenge((HANDLE)wParam, req->szChallenge,
@@ -521,7 +514,6 @@ static INT_PTR NtlmCreateResponseService2(WPARAM wParam, LPARAM lParam) mir_free(szPassw);
}
-
return (INT_PTR)response;
}
diff --git a/src/modules/netlib/netlibssl.cpp b/src/modules/netlib/netlibssl.cpp index a1910f3ca6..6327edb459 100644 --- a/src/modules/netlib/netlibssl.cpp +++ b/src/modules/netlib/netlibssl.cpp @@ -153,13 +153,13 @@ static bool SSL_library_init(void) {
INIT_SECURITY_INTERFACE_A pInitSecurityInterface;
pInitSecurityInterface = (INIT_SECURITY_INTERFACE_A)GetProcAddress(g_hSchannel, SECURITY_ENTRYPOINT_ANSIA);
- if (pInitSecurityInterface != NULL)
+ if (pInitSecurityInterface != NULL)
g_pSSPI = pInitSecurityInterface();
- if (g_pSSPI)
+ if (g_pSSPI)
{
HINSTANCE hCrypt = LoadLibraryA("crypt32.dll");
- if (hCrypt)
+ if (hCrypt)
{
fnCertGetCertificateChain = (pfnCertGetCertificateChain)GetProcAddress(hCrypt, "CertGetCertificateChain");
fnCertFreeCertificateChain = (pfnCertFreeCertificateChain)GetProcAddress(hCrypt, "CertFreeCertificateChain");
@@ -206,7 +206,7 @@ static bool VerifyCertificate(SslHandle *ssl, PCSTR pszServerName, DWORD dwCertF return true;
static LPSTR rgszUsages[] =
- {
+ {
szOID_PKIX_KP_SERVER_AUTH,
szOID_SERVER_GATED_CRYPTO,
szOID_SGC_NETSCAPE
@@ -313,15 +313,15 @@ static SECURITY_STATUS ClientHandshakeLoop(SslHandle *ssl, BOOL fDoInitialRead) while (scRet == SEC_I_CONTINUE_NEEDED || scRet == SEC_E_INCOMPLETE_MESSAGE || scRet == SEC_I_INCOMPLETE_CREDENTIALS)
{
// Read server data
- if (0 == ssl->cbIoBuffer || scRet == SEC_E_INCOMPLETE_MESSAGE)
+ if (0 == ssl->cbIoBuffer || scRet == SEC_E_INCOMPLETE_MESSAGE)
{
- if (fDoRead)
+ if (fDoRead)
{
static const TIMEVAL tv = {6, 0};
fd_set fd;
// If buffer not large enough reallocate buffer
- if (ssl->sbIoBuffer <= ssl->cbIoBuffer)
+ if (ssl->sbIoBuffer <= ssl->cbIoBuffer)
{
ssl->sbIoBuffer += 4096;
ssl->pbIoBuffer = (PUCHAR)mir_realloc(ssl->pbIoBuffer, ssl->sbIoBuffer);
@@ -337,13 +337,13 @@ static SECURITY_STATUS ClientHandshakeLoop(SslHandle *ssl, BOOL fDoInitialRead) }
cbData = recv(ssl->s, (char*)ssl->pbIoBuffer + ssl->cbIoBuffer, ssl->sbIoBuffer - ssl->cbIoBuffer, 0);
- if (cbData == SOCKET_ERROR)
+ if (cbData == SOCKET_ERROR)
{
NetlibLogf(NULL, "SSL Negotiation failure recieving data (%d)", WSAGetLastError());
scRet = ERROR_NOT_READY;
break;
}
- if (cbData == 0)
+ if (cbData == 0)
{
NetlibLogf(NULL, "SSL Negotiation connection gracefully closed");
scRet = ERROR_NOT_READY;
@@ -405,11 +405,11 @@ static SECURITY_STATUS ClientHandshakeLoop(SslHandle *ssl, BOOL fDoInitialRead) scRet == SEC_I_CONTINUE_NEEDED ||
(FAILED(scRet) && (dwSSPIOutFlags & ISC_RET_EXTENDED_ERROR)))
{
- if (OutBuffers[0].cbBuffer != 0 && OutBuffers[0].pvBuffer != NULL)
+ if (OutBuffers[0].cbBuffer != 0 && OutBuffers[0].pvBuffer != NULL)
{
NetlibDumpData(NULL, (unsigned char*)(OutBuffers[0].pvBuffer), OutBuffers[0].cbBuffer, 1, MSG_DUMPSSL);
cbData = send(ssl->s, (char*)OutBuffers[0].pvBuffer, OutBuffers[0].cbBuffer, 0);
- if (cbData == SOCKET_ERROR || cbData == 0)
+ if (cbData == SOCKET_ERROR || cbData == 0)
{
NetlibLogf(NULL, "SSL Negotiation failure sending data (%d)", WSAGetLastError());
g_pSSPI->FreeContextBuffer(OutBuffers[0].pvBuffer);
@@ -426,10 +426,10 @@ static SECURITY_STATUS ClientHandshakeLoop(SslHandle *ssl, BOOL fDoInitialRead) if (scRet == SEC_E_INCOMPLETE_MESSAGE) continue;
// handshake completed successfully.
- if (scRet == SEC_E_OK)
+ if (scRet == SEC_E_OK)
{
// Store remaining data for further use
- if (InBuffers[1].BufferType == SECBUFFER_EXTRA)
+ if (InBuffers[1].BufferType == SECBUFFER_EXTRA)
{
memmove(ssl->pbIoBuffer,
ssl->pbIoBuffer + (ssl->cbIoBuffer - InBuffers[1].cbBuffer),
@@ -445,10 +445,10 @@ static SECURITY_STATUS ClientHandshakeLoop(SslHandle *ssl, BOOL fDoInitialRead) if (FAILED(scRet)) break;
// server just requested client authentication.
- if (scRet == SEC_I_INCOMPLETE_CREDENTIALS)
+ if (scRet == SEC_I_INCOMPLETE_CREDENTIALS)
{
// Server has requested client authentication and
- // GetNewClientCredentials(ssl);
+ // GetNewClientCredentials(ssl);
// Go around again.
fDoRead = FALSE;
@@ -456,9 +456,8 @@ static SECURITY_STATUS ClientHandshakeLoop(SslHandle *ssl, BOOL fDoInitialRead) continue;
}
-
// Copy any leftover data from the buffer, and go around again.
- if (InBuffers[1].BufferType == SECBUFFER_EXTRA)
+ if (InBuffers[1].BufferType == SECBUFFER_EXTRA)
{
memmove(ssl->pbIoBuffer,
ssl->pbIoBuffer + (ssl->cbIoBuffer - InBuffers[1].cbBuffer),
@@ -472,7 +471,7 @@ static SECURITY_STATUS ClientHandshakeLoop(SslHandle *ssl, BOOL fDoInitialRead) // Delete the security context in the case of a fatal error.
ReportSslError(scRet, __LINE__);
- if (ssl->cbIoBuffer == 0)
+ if (ssl->cbIoBuffer == 0)
{
mir_free(ssl->pbIoBuffer);
ssl->pbIoBuffer = NULL;
@@ -492,7 +491,7 @@ static bool ClientConnect(SslHandle *ssl, const char *host) SECURITY_STATUS scRet;
DWORD cbData;
- if (SecIsValidHandle(&ssl->hContext))
+ if (SecIsValidHandle(&ssl->hContext))
{
g_pSSPI->DeleteSecurityContext(&ssl->hContext);
SecInvalidateHandle(&ssl->hContext);
@@ -538,7 +537,7 @@ static bool ClientConnect(SslHandle *ssl, const char *host) }
// Send response to server if there is one.
- if (OutBuffers[0].cbBuffer != 0 && OutBuffers[0].pvBuffer != NULL)
+ if (OutBuffers[0].cbBuffer != 0 && OutBuffers[0].pvBuffer != NULL)
{
NetlibDumpData(NULL, (unsigned char*)(OutBuffers[0].pvBuffer), OutBuffers[0].cbBuffer, 1, MSG_DUMPSSL);
cbData = send(ssl->s, (char*)OutBuffers[0].pvBuffer, OutBuffers[0].cbBuffer, 0);
@@ -557,7 +556,6 @@ static bool ClientConnect(SslHandle *ssl, const char *host) return ClientHandshakeLoop(ssl, TRUE) == SEC_E_OK;
}
-
SslHandle *NetlibSslConnect(SOCKET s, const char* host, int verify)
{
SslHandle *ssl = (SslHandle*)mir_calloc(sizeof(SslHandle));
@@ -566,24 +564,23 @@ SslHandle *NetlibSslConnect(SOCKET s, const char* host, int verify) SecInvalidateHandle(&ssl->hContext);
DWORD dwFlags = 0;
-
- if ( !host || inet_addr(host) != INADDR_NONE)
+
+ if ( !host || inet_addr(host) != INADDR_NONE)
dwFlags |= 0x00001000;
bool res = SSL_library_init();
if (res) res = ClientConnect(ssl, host);
- if (res && verify) res = VerifyCertificate(ssl, host, dwFlags);
+ if (res && verify) res = VerifyCertificate(ssl, host, dwFlags);
- if ( !res)
+ if ( !res)
{
- NetlibSslFree(ssl);
+ NetlibSslFree(ssl);
ssl = NULL;
}
return ssl;
}
-
void NetlibSslShutdown(SslHandle *ssl)
{
DWORD dwType;
@@ -647,7 +644,7 @@ void NetlibSslShutdown(SslHandle *ssl) if (FAILED(scRet)) return;
// Send the close notify message to the server.
- if (OutBuffers[0].pvBuffer != NULL && OutBuffers[0].cbBuffer != 0)
+ if (OutBuffers[0].pvBuffer != NULL && OutBuffers[0].cbBuffer != 0)
{
NetlibDumpData(NULL, (unsigned char*)(OutBuffers[0].pvBuffer), OutBuffers[0].cbBuffer, 1, MSG_DUMPSSL);
send(ssl->s, (char*)OutBuffers[0].pvBuffer, OutBuffers[0].cbBuffer, 0);
@@ -655,7 +652,7 @@ void NetlibSslShutdown(SslHandle *ssl) }
}
-static int NetlibSslReadSetResult(SslHandle *ssl, char *buf, int num, int peek)
+static int NetlibSslReadSetResult(SslHandle *ssl, char *buf, int num, int peek)
{
if (ssl->cbRecDataBuf == 0)
{
@@ -666,7 +663,7 @@ static int NetlibSslReadSetResult(SslHandle *ssl, char *buf, int num, int peek) int rbytes = ssl->cbRecDataBuf - bytes;
memcpy(buf, ssl->pbRecDataBuf, bytes);
- if ( !peek)
+ if ( !peek)
{
memmove(ssl->pbRecDataBuf, ssl->pbRecDataBuf + bytes, rbytes);
ssl->cbRecDataBuf = rbytes;
@@ -698,17 +695,17 @@ int NetlibSslRead(SslHandle *ssl, char *buf, int num, int peek) scRet = SEC_E_OK;
- for (;;)
+ for (;;)
{
- if (0 == ssl->cbIoBuffer || scRet == SEC_E_INCOMPLETE_MESSAGE)
+ if (0 == ssl->cbIoBuffer || scRet == SEC_E_INCOMPLETE_MESSAGE)
{
- if (ssl->sbIoBuffer <= ssl->cbIoBuffer)
+ if (ssl->sbIoBuffer <= ssl->cbIoBuffer)
{
ssl->sbIoBuffer += 2048;
ssl->pbIoBuffer = (PUCHAR)mir_realloc(ssl->pbIoBuffer, ssl->sbIoBuffer);
}
- if (peek)
+ if (peek)
{
static const TIMEVAL tv = {0};
fd_set fd;
@@ -716,13 +713,13 @@ int NetlibSslRead(SslHandle *ssl, char *buf, int num, int peek) FD_SET(ssl->s, &fd);
cbData = select(1, &fd, NULL, NULL, &tv);
- if (cbData == SOCKET_ERROR)
+ if (cbData == SOCKET_ERROR)
{
ssl->state = sockError;
return NetlibSslReadSetResult(ssl, buf, num, peek);
}
-
- if (cbData == 0 && ssl->cbRecDataBuf)
+
+ if (cbData == 0 && ssl->cbRecDataBuf)
return NetlibSslReadSetResult(ssl, buf, num, peek);
}
@@ -733,8 +730,8 @@ int NetlibSslRead(SslHandle *ssl, char *buf, int num, int peek) ssl->state = sockError;
return NetlibSslReadSetResult(ssl, buf, num, peek);
}
-
- if (cbData == 0)
+
+ if (cbData == 0)
{
NetlibLogf(NULL, "SSL connection gracefully closed");
if (peek && ssl->cbRecDataBuf)
@@ -744,12 +741,12 @@ int NetlibSslRead(SslHandle *ssl, char *buf, int num, int peek) }
// Server disconnected.
- if (ssl->cbIoBuffer)
+ if (ssl->cbIoBuffer)
{
ssl->state = sockError;
return NetlibSslReadSetResult(ssl, buf, num, peek);
}
-
+
return 0;
}
else
@@ -793,7 +790,7 @@ int NetlibSslRead(SslHandle *ssl, char *buf, int num, int peek) // Locate data and (optional) extra buffers.
pDataBuffer = NULL;
pExtraBuffer = NULL;
- for (i = 1; i < 4; i++)
+ for (i = 1; i < 4; i++)
{
if (pDataBuffer == NULL && Buffers[i].BufferType == SECBUFFER_DATA)
pDataBuffer = &Buffers[i];
@@ -803,7 +800,7 @@ int NetlibSslRead(SslHandle *ssl, char *buf, int num, int peek) }
// Return decrypted data.
- if (pDataBuffer)
+ if (pDataBuffer)
{
DWORD bytes, rbytes;
@@ -811,11 +808,11 @@ int NetlibSslRead(SslHandle *ssl, char *buf, int num, int peek) rbytes = pDataBuffer->cbBuffer - bytes;
NetlibDumpData(NULL, (PBYTE)pDataBuffer->pvBuffer, pDataBuffer->cbBuffer, 0, MSG_DUMPSSL);
-
- if (rbytes > 0)
+
+ if (rbytes > 0)
{
int nbytes = ssl->cbRecDataBuf + rbytes;
- if (ssl->sbRecDataBuf < nbytes)
+ if (ssl->sbRecDataBuf < nbytes)
{
ssl->sbRecDataBuf = nbytes;
ssl->pbRecDataBuf = (PUCHAR)mir_realloc(ssl->pbRecDataBuf, nbytes);
@@ -837,7 +834,7 @@ int NetlibSslRead(SslHandle *ssl, char *buf, int num, int peek) }
// Move any "extra" data to the input buffer.
- if (pExtraBuffer)
+ if (pExtraBuffer)
{
memmove(ssl->pbIoBuffer, pExtraBuffer->pvBuffer, pExtraBuffer->cbBuffer);
ssl->cbIoBuffer = pExtraBuffer->cbBuffer;
@@ -848,7 +845,7 @@ int NetlibSslRead(SslHandle *ssl, char *buf, int num, int peek) return resNum;
// Server signaled end of session
- if (scRet == SEC_I_CONTEXT_EXPIRED)
+ if (scRet == SEC_I_CONTEXT_EXPIRED)
{
NetlibLogf(NULL, "SSL Server signaled SSL Shutdown");
ssl->state = sockClosed;
diff --git a/src/modules/netlib/netlibupnp.cpp b/src/modules/netlib/netlibupnp.cpp index 33f48221c3..50f6e421f9 100644 --- a/src/modules/netlib/netlibupnp.cpp +++ b/src/modules/netlib/netlibupnp.cpp @@ -192,7 +192,6 @@ void parseURL(char* szUrl, char* szHost, unsigned short* sPort, char* szPath) }
}
-
static void LongLog(char* szData)
{
CallService(MS_NETLIB_LOG, 0, (LPARAM)szData);
@@ -212,7 +211,7 @@ static void validateSocket(void) static const TIMEVAL tv = { 0, 0 };
fd_set rfd;
char buf[4];
- bool opened;
+ bool opened;
if (sock == INVALID_SOCKET)
return;
@@ -261,7 +260,7 @@ static int httpTransact(char* szUrl, char* szResult, int resSize, char* szAction for (;;)
{
retryCount = 0;
- switch(reqtype)
+ switch(reqtype)
{
case DeviceGetReq:
sz = mir_snprintf (szData, 4096, xml_get_hdr, szPath, szHost, sPort);
@@ -594,7 +593,6 @@ static bool getUPnPURLs(char* szUrl, size_t sizeUrl) return gatewayFound;
}
-
static void discoverUPnP(void)
{
char* buf;
@@ -700,7 +698,6 @@ static void discoverUPnP(void) closesocket(sock);
}
-
static bool findUPnPGateway(void)
{
if ((time(NULL) - lastDiscTime) >= expireTime)
|