Skip to content

Commit a76d2b3

Browse files
committed
- Added some const
1 parent fd2149a commit a76d2b3

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

H2Proto.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ class Http2Protocol : public HPack
154154
{
155155
size_t nReturn = 0;
156156

157-
function<void()> fnResetStream0Flag = [&]()
157+
const function<void()> fnResetStream0Flag = [&]()
158158
{
159159
// We reset in Stream 0 that we are in the middle of receiving a Header
160160
auto itStream0 = umStreamCache.find(0);
161161
if (itStream0 != end(umStreamCache))
162162
STREAMSTATE(itStream0) &= ~HEADER_RECEIVED;
163163
};
164164

165-
function<void(STREAMLIST::iterator&, const H2FRAME&)> fnHasExpectHeader = [&](STREAMLIST::iterator& streamData, const H2FRAME& h2f)
165+
const function<void(STREAMLIST::iterator&, const H2FRAME&)> fnHasExpectHeader = [&](STREAMLIST::iterator& streamData, const H2FRAME& h2f)
166166
{
167167
auto itExpect = GETHEADERLIST(streamData).find("expect");
168168
if (itExpect != end(GETHEADERLIST(streamData)))

HttpFetch.cpp

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
#if defined(_WIN32) || defined(_WIN64)
3+
#define _HAS_STD_BYTE 0
4+
#endif
5+
26
#include <regex>
37
#include <unordered_map>
48

@@ -14,7 +18,7 @@ extern void OutputDebugStringA(const char* pOut);
1418

1519
using namespace std::placeholders;
1620

17-
vector<string> vecProtokolls = { {"h2"}, {"http/1.1"} };
21+
static const vector<string> vecProtokolls = { {"h2"}, {"http/1.1"} };
1822

1923
HttpFetch::HttpFetch(function<void(HttpFetch*, void*, uint32_t)> fnNotify, void* /*vpUserData*/) : m_pcClientCon(nullptr), m_sPort(80), m_UseSSL(false), m_uiStatus(0), m_bIsHttp2(false), m_bOutpHeader(false), m_bEndOfHeader(false), m_nContentLength(SIZE_MAX), m_nContentReceived(0), m_nChuncked(-1), m_nNextChunk(0), m_nChunkFooter(0), m_fnNotify(fnNotify)
2024
{
@@ -123,7 +127,7 @@ void HttpFetch::Connected(TcpSocket* const pTcpSocket)
123127
string Protocoll;
124128
if (m_UseSSL == true)
125129
{
126-
long nResult = reinterpret_cast<SslTcpSocket*>(m_pcClientCon)->CheckServerCertificate(m_strServer.c_str());
130+
const long nResult = reinterpret_cast<SslTcpSocket*>(m_pcClientCon)->CheckServerCertificate(m_strServer.c_str());
127131
if (nResult != 0)
128132
OutputDebugString(L"Http2Fetch::Connected Zertifikat not verifyd\r\n");
129133

@@ -157,6 +161,7 @@ void HttpFetch::Connected(TcpSocket* const pTcpSocket)
157161

158162
for (auto& itPair : m_umAddHeader)
159163
{
164+
if (itPair.first == "Content-Length") continue;
160165
transform(begin(itPair.first), end(itPair.first), begin(itPair.first), ::tolower);
161166
nReturn = HPackEncode(caBuffer + 9 + nHeaderLen, 2048 - 9 - nHeaderLen, itPair.first.c_str(), itPair.second.c_str());
162167
if (nReturn == SIZE_MAX)
@@ -184,7 +189,7 @@ uint32_t nSend = 0;
184189

185190
while (data != nullptr) // loop until we have nullptr packet
186191
{
187-
uint32_t nDataLen = *(reinterpret_cast<uint32_t*>(data.get()));
192+
const uint32_t nDataLen = *(reinterpret_cast<uint32_t*>(data.get()));
188193

189194
auto apBuf = make_unique<uint8_t[]>(nDataLen + 9);
190195
copy(reinterpret_cast<unsigned char*>(data.get() + 4), reinterpret_cast<unsigned char*>(data.get() + 4 + nDataLen), apBuf.get() + 9);
@@ -255,7 +260,7 @@ uint32_t nSend = 0;
255260
m_mxVecData.unlock();
256261
while (data != nullptr) // loop until we have nullptr packet
257262
{
258-
uint32_t nDataLen = *(reinterpret_cast<uint32_t*>(data.get()));
263+
const uint32_t nDataLen = *(reinterpret_cast<uint32_t*>(data.get()));
259264
pTcpSocket->Write(reinterpret_cast<unsigned char*>(data.get() + 4), nDataLen);
260265
nSend += nDataLen;
261266
m_mxVecData.lock();
@@ -296,15 +301,15 @@ void HttpFetch::DatenEmpfangen(TcpSocket* const pTcpSocket)
296301
static atomic_bool atTmp;
297302
static deque<AUTHITEM> dqAuth;
298303

299-
size_t nAvailable = pTcpSocket->GetBytesAvailable();
304+
const size_t nAvailable = pTcpSocket->GetBytesAvailable();
300305

301306
if (nAvailable == 0)
302307
{
303308
pTcpSocket->Close();
304309
return;
305310
}
306311

307-
shared_ptr<char[]> spBuffer(new char[m_strBuffer.size() + nAvailable + 1]);
312+
const shared_ptr<char[]> spBuffer(new char[m_strBuffer.size() + nAvailable + 1]);
308313
copy(begin(m_strBuffer), begin(m_strBuffer) + m_strBuffer.size(), spBuffer.get());
309314

310315
size_t nRead = pTcpSocket->Read(spBuffer.get() + m_strBuffer.size(), nAvailable);
@@ -320,8 +325,8 @@ void HttpFetch::DatenEmpfangen(TcpSocket* const pTcpSocket)
320325

321326
if (m_bIsHttp2 == true)
322327
{
323-
size_t nRet, nReadSave = nRead;
324-
if (nRet = Http2StreamProto(m_soMetaDa, spBuffer.get(), nRead, m_qDynTable, m_tuStreamSettings, m_umStreamCache, m_mtxStreams, m_mResWndSizes, atTmp, dqAuth), nRet != SIZE_MAX)
328+
const size_t nReadSave = nRead;
329+
if (Http2StreamProto(m_soMetaDa, spBuffer.get(), nRead, m_qDynTable, m_tuStreamSettings, m_umStreamCache, m_mtxStreams, m_mResWndSizes, atTmp, dqAuth) != SIZE_MAX)
325330
{
326331
// no GOAWAY frame
327332
if (nRead > 0)
@@ -389,8 +394,8 @@ void HttpFetch::DatenEmpfangen(TcpSocket* const pTcpSocket)
389394
pSecondSpace = strchr(pFirstSpace + 1, ' ');
390395
if (pSecondSpace != nullptr && pSecondSpace < pEndOfLine)
391396
{
392-
string strStatus(pFirstSpace + 1, pSecondSpace - pFirstSpace - 1);
393-
int iStatus = stoi(strStatus);
397+
const string strStatus(pFirstSpace + 1, pSecondSpace - pFirstSpace - 1);
398+
const int iStatus = stoi(strStatus);
394399
if (iStatus >= 200)
395400
m_umRespHeader.emplace_back(make_pair(":status", strStatus));
396401
else // 1xx Statuscode
@@ -449,11 +454,11 @@ void HttpFetch::DatenEmpfangen(TcpSocket* const pTcpSocket)
449454
bool bLastChunk = false;
450455
if (m_nChuncked == 0 && m_nNextChunk == 0 && m_nChunkFooter == 0)
451456
{
452-
static regex rx("^([0-9a-fA-F]+)[\\r]?\\n"); //rx("^[\\r]?\\n([0-9a-fA-F]+)[\\r]?\\n");
457+
static const regex rx("^([0-9a-fA-F]+)[\\r]?\\n"); //rx("^[\\r]?\\n([0-9a-fA-F]+)[\\r]?\\n");
453458
match_results<const char*> mr;
454459
if (regex_search(spBuffer.get() + nWriteOffset, mr, rx, regex_constants::format_first_only) == true && mr[0].matched == true && mr[1].matched == true)
455460
{
456-
m_nNextChunk = strtol(mr[1].str().c_str(), 0, 16);
461+
m_nNextChunk = strtol(mr[1].str().c_str(), nullptr, 16);
457462
nWriteOffset += mr.length();
458463
nRead -= mr.length();
459464
m_nChunkFooter = 2;
@@ -464,7 +469,7 @@ void HttpFetch::DatenEmpfangen(TcpSocket* const pTcpSocket)
464469
OutputDebugString(L"Buffer Fehler\r\n");
465470
}
466471

467-
size_t nAnzahlDatenBytes = m_nNextChunk != 0 || m_nChunkFooter != 0 ? min(nRead, m_nNextChunk) : nRead;
472+
const size_t nAnzahlDatenBytes = m_nNextChunk != 0 || m_nChunkFooter != 0 ? min(nRead, m_nNextChunk) : nRead;
468473
//m_pTmpFileRec.get()->Write(spBuffer.get() + nWriteOffset, nAnzahlDatenBytes);
469474
if (nAnzahlDatenBytes > 0)
470475
{
@@ -556,7 +561,7 @@ void HttpFetch::EndOfStreamAction(const MetaSocketData& soMetaDa, const uint32_t
556561
GZipUnpack gzipDecoder;
557562
if (gzipDecoder.Init() == Z_OK)
558563
{
559-
unique_ptr<unsigned char[]> dstBuf(new unsigned char[4096]);
564+
const unique_ptr<unsigned char[]> dstBuf(new unsigned char[4096]);
560565

561566
//shared_ptr<TempFile> pDestFile = make_shared<TempFile>();
562567
//pDestFile->Open();
@@ -578,7 +583,7 @@ void HttpFetch::EndOfStreamAction(const MetaSocketData& soMetaDa, const uint32_t
578583
pmtxReqdata.unlock();
579584
if (data == nullptr)
580585
break;
581-
uint32_t nDataLen = *(reinterpret_cast<uint32_t*>(data.get()));
586+
const uint32_t nDataLen = *(reinterpret_cast<uint32_t*>(data.get()));
582587
gzipDecoder.InitBuffer(reinterpret_cast<unsigned char*>(data.get() + 4), nDataLen);
583588

584589
uint32_t nBytesConverted;
@@ -597,16 +602,16 @@ void HttpFetch::EndOfStreamAction(const MetaSocketData& soMetaDa, const uint32_t
597602
}
598603
else if (encoding->second.find("br") != string::npos)
599604
{
600-
BrotliDecoderState* s = BrotliDecoderCreateInstance(NULL, NULL, NULL);
605+
BrotliDecoderState* s = BrotliDecoderCreateInstance(nullptr, nullptr, nullptr);
601606

602607
//if (dictionary_path != NULL) {
603608
// size_t dictionary_size = 0;
604609
// dictionary = ReadDictionary(dictionary_path, &dictionary_size);
605610
// BrotliDecoderSetCustomDictionary(s, dictionary_size, dictionary);
606611
//}
607612

608-
unique_ptr<unsigned char[]> srcBuf(new unsigned char[4096]);
609-
unique_ptr<unsigned char[]> dstBuf(new unsigned char[4096]);
613+
const unique_ptr<unsigned char[]> srcBuf(new unsigned char[4096]);
614+
const unique_ptr<unsigned char[]> dstBuf(new unsigned char[4096]);
610615

611616
//shared_ptr<TempFile> pDestFile = make_shared<TempFile>();
612617
//pDestFile->Open();
@@ -635,7 +640,7 @@ void HttpFetch::EndOfStreamAction(const MetaSocketData& soMetaDa, const uint32_t
635640
pmtxReqdata.unlock();
636641
if (data == nullptr)
637642
break;
638-
uint32_t nDataLen = *(reinterpret_cast<uint32_t*>(data.get()));
643+
const uint32_t nDataLen = *(reinterpret_cast<uint32_t*>(data.get()));
639644
nBytesRead = min(nDataLen, static_cast<uint32_t>(4096));
640645
copy(data.get() + 4, data.get() + 4 + nBytesRead, srcBuf.get());
641646
if (nBytesRead < nDataLen)
@@ -654,7 +659,7 @@ void HttpFetch::EndOfStreamAction(const MetaSocketData& soMetaDa, const uint32_t
654659
else
655660
break; /* Error or success. */
656661

657-
result = BrotliDecoderDecompressStream(s, &nBytesRead, &input, &nBytesOut, &next_out, 0);
662+
result = BrotliDecoderDecompressStream(s, &nBytesRead, &input, &nBytesOut, &next_out, nullptr);
658663
}
659664
if (next_out != dstBuf.get())
660665
m_fnNotify(this, reinterpret_cast<unsigned char*>(dstBuf.get()), static_cast<uint32_t>(next_out - dstBuf.get())); //pDestFile->Write(reinterpret_cast<char*>(dstBuf.get()), (next_out - dstBuf.get()));
@@ -689,7 +694,7 @@ void HttpFetch::EndOfStreamAction(const MetaSocketData& soMetaDa, const uint32_t
689694
pmtxReqdata.unlock();
690695
if (data == nullptr)
691696
break;
692-
uint32_t nDataLen = *(reinterpret_cast<uint32_t*>(data.get()));
697+
const uint32_t nDataLen = *(reinterpret_cast<uint32_t*>(data.get()));
693698
m_fnNotify(this, reinterpret_cast<unsigned char*>(data.get() + 4), nDataLen);
694699
}
695700
}
@@ -721,4 +726,4 @@ void HttpFetch::ExchangeTmpFile(shared_ptr<TempFile>& rhs)
721726
{
722727
rhs.swap(m_pTmpFileRec);
723728
}
724-
*/
729+
*/

0 commit comments

Comments
 (0)