summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mir_app/src/netlib.h5
-rw-r--r--src/mir_app/src/netlib_http.cpp23
-rw-r--r--src/mir_app/src/netlib_openconn.cpp4
3 files changed, 14 insertions, 18 deletions
diff --git a/src/mir_app/src/netlib.h b/src/mir_app/src/netlib.h
index 2cfff43aa1..8a1223628d 100644
--- a/src/mir_app/src/netlib.h
+++ b/src/mir_app/src/netlib.h
@@ -129,7 +129,6 @@ struct NetlibConnection : public MZeroedObject
NetlibUrl url;
int timeout;
- MChunkHandler *pChunkHandler;
char *szNewUrl;
mir_cs csHttpSequenceNums;
@@ -208,9 +207,9 @@ bool BindSocketToPort(const char *szPorts, SOCKET s, SOCKET s6, int* portn);
// netlibhttp.cpp
void NetlibHttpSetLastErrorUsingHttpResult(int result);
-int Netlib_SendHttpRequest(HNETLIBCONN hConnection, MHttpRequest *pRec, MChunkHandler *pHandler);
+int Netlib_SendHttpRequest(HNETLIBCONN hConnection, MHttpRequest *pRec, MChunkHandler &pHandler);
-MHttpResponse* NetlibHttpRecv(NetlibConnection *nlc, uint32_t hflags, uint32_t dflags, bool isConnect = false);
+MHttpResponse* NetlibHttpRecv(NetlibConnection *nlc, uint32_t hflags, uint32_t dflags, MChunkHandler &pHandler, bool isConnect = false);
// netliblog.cpp
void NetlibLogShowOptions(void);
diff --git a/src/mir_app/src/netlib_http.cpp b/src/mir_app/src/netlib_http.cpp
index fa74322489..dcf3fb075e 100644
--- a/src/mir_app/src/netlib_http.cpp
+++ b/src/mir_app/src/netlib_http.cpp
@@ -484,7 +484,7 @@ static MHttpResponse* Netlib_RecvHttpHeaders(NetlibConnection *nlc, int flags)
// nlhr.resultCode and nlhr.szResultDescr are ignored by this function.
// Errors: ERROR_INVALID_PARAMETER, anything returned by MS_NETLIB_SEND
-int Netlib_SendHttpRequest(HNETLIBCONN nlc, MHttpRequest *nlhr, MChunkHandler *pHandler)
+int Netlib_SendHttpRequest(HNETLIBCONN nlc, MHttpRequest *nlhr, MChunkHandler &pHandler)
{
MHttpResponse *nlhrReply = nullptr;
HttpSecurityContext httpSecurity;
@@ -527,8 +527,6 @@ int Netlib_SendHttpRequest(HNETLIBCONN nlc, MHttpRequest *nlhr, MChunkHandler *p
const char *pszFullUrl = nlhr->m_szUrl;
const char *pszUrl = nullptr;
- nlc->pChunkHandler = pHandler;
-
unsigned complete = false;
int count = 11;
while (--count) {
@@ -669,7 +667,7 @@ int Netlib_SendHttpRequest(HNETLIBCONN nlc, MHttpRequest *nlhr, MChunkHandler *p
if (nlhr->requestType == REQUEST_HEAD)
nlhrReply = Netlib_RecvHttpHeaders(nlc, hflags);
else
- nlhrReply = NetlibHttpRecv(nlc, hflags, dflags);
+ nlhrReply = NetlibHttpRecv(nlc, hflags, dflags, pHandler);
if (nlhrReply) {
auto *tmpUrl = nlhrReply->FindHeader("Location");
@@ -711,7 +709,7 @@ int Netlib_SendHttpRequest(HNETLIBCONN nlc, MHttpRequest *nlhr, MChunkHandler *p
if (nlhr->requestType == REQUEST_HEAD)
nlhrReply = Netlib_RecvHttpHeaders(nlc, hflags);
else
- nlhrReply = NetlibHttpRecv(nlc, hflags, dflags);
+ nlhrReply = NetlibHttpRecv(nlc, hflags, dflags, pHandler);
replaceStr(pszAuthHdr, nullptr);
if (nlhrReply) {
@@ -745,7 +743,7 @@ int Netlib_SendHttpRequest(HNETLIBCONN nlc, MHttpRequest *nlhr, MChunkHandler *p
if (nlhr->requestType == REQUEST_HEAD)
nlhrReply = Netlib_RecvHttpHeaders(nlc, hflags);
else
- nlhrReply = NetlibHttpRecv(nlc, hflags, dflags);
+ nlhrReply = NetlibHttpRecv(nlc, hflags, dflags, pHandler);
mir_free(pszProxyAuthHdr); pszProxyAuthHdr = nullptr;
if (nlhrReply) {
@@ -904,7 +902,7 @@ static int NetlibHttpRecvChunkHeader(NetlibConnection *nlc, bool first, uint32_t
}
}
-MHttpResponse* NetlibHttpRecv(NetlibConnection *nlc, uint32_t hflags, uint32_t dflags, bool isConnect)
+MHttpResponse* NetlibHttpRecv(NetlibConnection *nlc, uint32_t hflags, uint32_t dflags, MChunkHandler &pHandler, bool isConnect)
{
int dataLen = -1;
bool chunked = false;
@@ -962,13 +960,13 @@ next:
if (recvResult <= dataLen) {
- nlc->pChunkHandler->updateChunk(tmpBuf, recvResult);
+ pHandler.updateChunk(tmpBuf, recvResult);
dataLen -= recvResult;
if (!dataLen)
break;
}
else {
- nlc->pChunkHandler->updateChunk(tmpBuf, dataLen);
+ pHandler.updateChunk(tmpBuf, dataLen);
nlc->foreBuf.appendBefore(tmpBuf.get() + dataLen, recvResult - dataLen);
break;
}
@@ -985,7 +983,7 @@ next:
}
}
- nlc->pChunkHandler->apply(nlhrReply.get());
+ pHandler.apply(nlhrReply.get());
if (chunked)
nlhrReply->AddHeader("Content-Length", CMStringA(FORMAT, "%u", dataLen));
@@ -1074,7 +1072,7 @@ MIR_APP_DLL(MHttpResponse *) Netlib_HttpTransaction(HNETLIBUSER nlu, MHttpReques
nlhr->AddHeader("Accept-Encoding", "deflate, gzip");
MMemoryChunkStorage storage;
- if (Netlib_SendHttpRequest(nlc, nlhr, &storage) == SOCKET_ERROR) {
+ if (Netlib_SendHttpRequest(nlc, nlhr, storage) == SOCKET_ERROR) {
Netlib_CloseHandle(nlc);
return nullptr;
}
@@ -1091,13 +1089,12 @@ MIR_APP_DLL(MHttpResponse *) Netlib_HttpTransaction(HNETLIBUSER nlu, MHttpReques
if (nlhr->requestType == REQUEST_HEAD)
nlhrReply = Netlib_RecvHttpHeaders(nlc, 0);
else
- nlhrReply = NetlibHttpRecv(nlc, hflags, dflags);
+ nlhrReply = NetlibHttpRecv(nlc, hflags, dflags, storage);
if (nlhrReply) {
nlhrReply->szUrl = nlc->szNewUrl;
nlc->szNewUrl = nullptr;
}
- nlc->pChunkHandler = nullptr;
if ((nlhr->flags & NLHRF_PERSISTENT) == 0 || nlhrReply == nullptr) {
Netlib_CloseHandle(nlc);
diff --git a/src/mir_app/src/netlib_openconn.cpp b/src/mir_app/src/netlib_openconn.cpp
index 210c94cb71..6178e29d38 100644
--- a/src/mir_app/src/netlib_openconn.cpp
+++ b/src/mir_app/src/netlib_openconn.cpp
@@ -314,10 +314,10 @@ static bool NetlibInitHttpsConnection(NetlibConnection *nlc)
nlhrSend.flags = NLHRF_DUMPPROXY | NLHRF_HTTP11 | NLHRF_NOPROXY | NLHRF_REDIRECT;
nlhrSend.m_szUrl = szUrl;
- if (Netlib_SendHttpRequest(nlc, &nlhrSend, &storage) == SOCKET_ERROR)
+ if (Netlib_SendHttpRequest(nlc, &nlhrSend, storage) == SOCKET_ERROR)
return false;
- auto *nlhrReply = NetlibHttpRecv(nlc, MSG_DUMPPROXY | MSG_RAW, MSG_DUMPPROXY | MSG_RAW, true);
+ auto *nlhrReply = NetlibHttpRecv(nlc, MSG_DUMPPROXY | MSG_RAW, MSG_DUMPPROXY | MSG_RAW, storage, true);
if (nlhrReply == nullptr)
return false;