From cdd6bf525f77553ed7b30794f24b37dc42f0e434 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 28 Apr 2016 16:30:29 +0000 Subject: minor code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@16789 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/mir_app/src/netlibhttp.cpp | 39 ++++++++++++++++---------------------- src/mir_app/src/netlibopenconn.cpp | 25 ++++++++++++------------ 2 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/mir_app/src/netlibhttp.cpp b/src/mir_app/src/netlibhttp.cpp index 8adb6c1580..257aacf9b5 100644 --- a/src/mir_app/src/netlibhttp.cpp +++ b/src/mir_app/src/netlibhttp.cpp @@ -240,15 +240,15 @@ struct HttpSecurityContext } if (m_hNtlmSecurity == NULL) { - char szSpnStr[256] = ""; + CMStringA szSpnStr; if (szHost && _stricmp(szProvider, "Basic")) { unsigned long ip = inet_addr(szHost); PHOSTENT host = (ip == INADDR_NONE) ? gethostbyname(szHost) : gethostbyaddr((char*)&ip, 4, AF_INET); - mir_snprintf(szSpnStr, "HTTP/%s", host && host->h_name ? host->h_name : szHost); - _strlwr(szSpnStr + 5); + szSpnStr.Format("HTTP/%s", host && host->h_name ? host->h_name : szHost); + _strlwr(szSpnStr.GetBuffer() + 5); NetlibLogf(nlu, "Host SPN: %s", szSpnStr); } - m_hNtlmSecurity = NetlibInitSecurityProvider(szProvider, szSpnStr[0] ? szSpnStr : NULL); + m_hNtlmSecurity = NetlibInitSecurityProvider(szProvider, szSpnStr.IsEmpty() ? NULL : szSpnStr.c_str()); if (m_hNtlmSecurity) { m_szProvider = mir_strdup(szProvider); m_szHost = mir_strdup(szHost); @@ -257,7 +257,7 @@ struct HttpSecurityContext } if (m_hNtlmSecurity) { - TCHAR *szLogin = NULL, *szPassw = NULL; + ptrT szLogin, szPassw; if (nlu->settings.useProxyAuth) { mir_cslock lck(csNetlibUser); @@ -265,18 +265,11 @@ struct HttpSecurityContext szPassw = mir_a2t(nlu->settings.szProxyAuthPassword); } - szAuthHdr = NtlmCreateResponseFromChallenge(m_hNtlmSecurity, - szChallenge, szLogin, szPassw, true, complete); - - if (!szAuthHdr) { - NetlibLogf(NULL, "Security login %s failed, user: %S pssw: %S", - szProvider, szLogin ? szLogin : _T("(no user)"), szPassw ? _T("(exist)") : _T("(no psw)")); - } + szAuthHdr = NtlmCreateResponseFromChallenge(m_hNtlmSecurity, szChallenge, szLogin, szPassw, true, complete); + if (!szAuthHdr) + NetlibLogf(NULL, "Security login %s failed, user: %S pssw: %S", szProvider, szLogin ? szLogin : _T("(no user)"), szPassw ? _T("(exist)") : _T("(no psw)")); else if (justCreated) proxyAuthList.add(m_szHost, m_szProvider); - - mir_free(szLogin); - mir_free(szPassw); } else complete = 1; @@ -287,8 +280,7 @@ struct HttpSecurityContext static int HttpPeekFirstResponseLine(NetlibConnection *nlc, DWORD dwTimeoutTime, DWORD recvFlags, int *resultCode, char **ppszResultDescr, int *length) { int bytesPeeked; - char buffer[2048]; - char *peol; + char buffer[2048], *peol; while (true) { bytesPeeked = RecvWithTimeoutTime(nlc, dwTimeoutTime, buffer, _countof(buffer) - 1, MSG_PEEK | recvFlags); @@ -312,7 +304,8 @@ static int HttpPeekFirstResponseLine(NetlibConnection *nlc, DWORD dwTimeoutTime, SetLastError(ERROR_BUFFER_OVERFLOW); return 0; } - if (Miranda_Terminated()) return 0; + if (Miranda_Terminated()) + return 0; Sleep(10); } @@ -332,16 +325,17 @@ static int HttpPeekFirstResponseLine(NetlibConnection *nlc, DWORD dwTimeoutTime, if (off >= (unsigned)bytesPeeked) return 0; - char* pResultCode = buffer + off; + char *pResultCode = buffer + off; *(pResultCode++) = 0; - char* pResultDescr; + char *pResultDescr; *resultCode = strtol(pResultCode, &pResultDescr, 10); if (ppszResultDescr) *ppszResultDescr = mir_strdup(lrtrimp(pResultDescr)); - if (length) *length = peol - buffer + 1; + if (length) + *length = peol - buffer + 1; return 1; } @@ -488,8 +482,7 @@ INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam) } nlc->proxyAuthNeeded = false; - CMStringA httpRequest; - httpRequest.AppendFormat("%s %s HTTP/1.%d\r\n", pszRequest, pszUrl, (nlhr->flags & NLHRF_HTTP11) != 0); + CMStringA httpRequest(FORMAT, "%s %s HTTP/1.%d\r\n", pszRequest, pszUrl, (nlhr->flags & NLHRF_HTTP11) != 0); // HTTP headers doneHostHeader = doneContentLengthHeader = doneProxyAuthHeader = doneAuthHeader = 0; diff --git a/src/mir_app/src/netlibopenconn.cpp b/src/mir_app/src/netlibopenconn.cpp index f6586e6494..103f7eda20 100644 --- a/src/mir_app/src/netlibopenconn.cpp +++ b/src/mir_app/src/netlibopenconn.cpp @@ -294,27 +294,27 @@ static int NetlibInitSocks5Connection(NetlibConnection *nlc, NetlibUser *nlu, NE static bool NetlibInitHttpsConnection(NetlibConnection *nlc, NetlibUser *nlu, NETLIBOPENCONNECTION *nloc) { - //rfc2817 - NETLIBHTTPREQUEST nlhrSend = { 0 }; - char szUrl[512]; - - nlhrSend.cbSize = sizeof(nlhrSend); - nlhrSend.requestType = REQUEST_CONNECT; - nlhrSend.flags = NLHRF_DUMPPROXY | NLHRF_HTTP11 | NLHRF_NOPROXY | NLHRF_REDIRECT; + // rfc2817 + CMStringA szUrl; if (nlc->dnsThroughProxy) - mir_snprintf(szUrl, "%s:%u", nloc->szHost, nloc->wPort); + szUrl.Format("%s:%u", nloc->szHost, nloc->wPort); else { DWORD ip = DnsLookup(nlu, nloc->szHost); if (ip == 0) return false; - mir_snprintf(szUrl, "%s:%u", inet_ntoa(*(PIN_ADDR)&ip), nloc->wPort); + szUrl.Format("%s:%u", inet_ntoa(*(PIN_ADDR)&ip), nloc->wPort); } - nlhrSend.szUrl = szUrl; + + NETLIBHTTPREQUEST nlhrSend = { 0 }; + nlhrSend.cbSize = sizeof(nlhrSend); + nlhrSend.requestType = REQUEST_CONNECT; + nlhrSend.flags = NLHRF_DUMPPROXY | NLHRF_HTTP11 | NLHRF_NOPROXY | NLHRF_REDIRECT; + nlhrSend.szUrl = szUrl.GetBuffer(); nlc->usingHttpGateway = true; if (NetlibHttpSendRequest((WPARAM)nlc, (LPARAM)&nlhrSend) == SOCKET_ERROR) { nlc->usingHttpGateway = false; - return 0; + return false; } NETLIBHTTPREQUEST *nlhrReply = NetlibHttpRecv(nlc, MSG_DUMPPROXY | MSG_RAW, MSG_DUMPPROXY | MSG_RAW, true); @@ -335,8 +335,7 @@ static bool NetlibInitHttpsConnection(NetlibConnection *nlc, NetlibUser *nlu, NE return 0; } NetlibHttpFreeRequestStruct(0, (LPARAM)nlhrReply); - //connected - return true; + return true; // connected } static void FreePartiallyInitedConnection(NetlibConnection *nlc) -- cgit v1.2.3