Loading examples/httpclient.cpp +3 −27 Original line number Diff line number Diff line Loading @@ -40,40 +40,17 @@ #include <cstring> template<typename T = size_t> T Hex2Int(const char* const hexstr, bool* overflow=nullptr) { if (!hexstr) return false; if (overflow) *overflow = false; auto between = [](char val, char c1, char c2) { return val >= c1 && val <= c2; }; size_t len = strlen(hexstr); T result = 0; for (size_t i = 0, offset = sizeof(T) << 3; i < len && (int)offset > 0; i++) { if (between(hexstr[i], '0', '9')) result = result << 4 ^ (hexstr[i] - '0'); else if (between(tolower(hexstr[i]), 'a', 'f')) result = result << 4 ^ (tolower(hexstr[i]) - ('a' - 10)); // Remove the decimal part; offset -= 4; } if (((len + ((len % 2) != 0)) << 2) > (sizeof(T) << 3) && overflow) *overflow = true; return result; } int readchunk(const char* data, size_t datasize, size_t& pos) { int start = pos; char value[512]; while ((pos < datasize) && data[pos] != '\r') { ++pos; }; while ((++pos < datasize) && data[pos] != '\r') {}; int len = pos - start; pos+=2; if (len > 511) { libhttppp::HTTPException ee; ee[libhttppp::HTTPException::Error] << "nginxfiler: chunck size: " << len << " to big aborting !"; Loading Loading @@ -161,7 +138,6 @@ int main(int argc, char** argv){ if ((chunklen = readchunk(data.get(), recv, cpos)) == 0) { break; } std::cout << chunklen << std::endl; readed = 0; } Loading Loading
examples/httpclient.cpp +3 −27 Original line number Diff line number Diff line Loading @@ -40,40 +40,17 @@ #include <cstring> template<typename T = size_t> T Hex2Int(const char* const hexstr, bool* overflow=nullptr) { if (!hexstr) return false; if (overflow) *overflow = false; auto between = [](char val, char c1, char c2) { return val >= c1 && val <= c2; }; size_t len = strlen(hexstr); T result = 0; for (size_t i = 0, offset = sizeof(T) << 3; i < len && (int)offset > 0; i++) { if (between(hexstr[i], '0', '9')) result = result << 4 ^ (hexstr[i] - '0'); else if (between(tolower(hexstr[i]), 'a', 'f')) result = result << 4 ^ (tolower(hexstr[i]) - ('a' - 10)); // Remove the decimal part; offset -= 4; } if (((len + ((len % 2) != 0)) << 2) > (sizeof(T) << 3) && overflow) *overflow = true; return result; } int readchunk(const char* data, size_t datasize, size_t& pos) { int start = pos; char value[512]; while ((pos < datasize) && data[pos] != '\r') { ++pos; }; while ((++pos < datasize) && data[pos] != '\r') {}; int len = pos - start; pos+=2; if (len > 511) { libhttppp::HTTPException ee; ee[libhttppp::HTTPException::Error] << "nginxfiler: chunck size: " << len << " to big aborting !"; Loading Loading @@ -161,7 +138,6 @@ int main(int argc, char** argv){ if ((chunklen = readchunk(data.get(), recv, cpos)) == 0) { break; } std::cout << chunklen << std::endl; readed = 0; } Loading