diff --git a/src/request_body_processor/multipart.cc b/src/request_body_processor/multipart.cc index 93df5e7f..c578638b 100644 --- a/src/request_body_processor/multipart.cc +++ b/src/request_body_processor/multipart.cc @@ -855,7 +855,7 @@ int Multipart::process_part_header(std::string *error, int offset) { } new_value = std::string(data); - utils::string::chomp(&new_value); + utils::string::chomp(new_value); /* update the header value in the table */ header_value = m_mpp->m_headers.at( @@ -924,7 +924,7 @@ int Multipart::process_part_header(std::string *error, int offset) { i++; } header_value = std::string(data); - utils::string::chomp(&header_value); + utils::string::chomp(header_value); /* error if the name already exists */ if (m_mpp->m_headers.count(header_name) > 0) { diff --git a/src/utils/string.h b/src/utils/string.h index eaacffe5..700f33b9 100644 --- a/src/utils/string.h +++ b/src/utils/string.h @@ -59,7 +59,7 @@ const char HEX2DEC[256] = { }; -inline std::string ascTime(time_t *t) { +inline std::string ascTime(const time_t *t) { std::string ts = std::ctime(t); ts.pop_back(); return ts; @@ -67,7 +67,7 @@ inline std::string ascTime(time_t *t) { inline std::string dash_if_empty(const std::string *str) { - if (str == NULL || str->empty()) { + if (str == nullptr || str->empty()) { return "-"; } @@ -107,7 +107,7 @@ inline std::string toHexIfNeeded(const std::string &str, bool escape_spec = fals } -inline std::vector ssplit(std::string str, char delimiter) { +inline std::vector ssplit(const std::string &str, char delimiter) { std::vector internal; std::stringstream ss(str); // Turn the string into a stream. std::string tok; @@ -134,10 +134,10 @@ inline std::pair ssplit_pair(const std::string& str, c } -inline std::vector split(std::string str, char delimiter) { +inline std::vector split(const std::string &str, char delimiter) { std::vector internal = ssplit(str, delimiter); - if (internal.size() == 0) { + if (internal.empty()) { internal.push_back(str); } @@ -145,10 +145,10 @@ inline std::vector split(std::string str, char delimiter) { } -inline void chomp(std::string *str) { - std::string::size_type pos = str->find_last_not_of("\n\r"); +inline void chomp(std::string &str) { + std::string::size_type pos = str.find_last_not_of("\n\r"); if (pos != std::string::npos) { - str->erase(pos+1, str->length()-pos-1); + str.erase(pos+1, str.length()-pos-1); } } @@ -194,17 +194,6 @@ inline std::string parserSanitizer(std::string a) { } -inline unsigned char x2c(const unsigned char *what) { - unsigned char digit; - - digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A') + 10 : (what[0] - '0')); - digit *= 16; - digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A') + 10 : (what[1] - '0')); - - return digit; -} - - /** * Converts a single hexadecimal digit into a decimal value. */ @@ -217,6 +206,17 @@ inline unsigned char xsingle2c(const unsigned char *what) { } +inline unsigned char x2c(const unsigned char *what) { + unsigned char digit; + + digit = xsingle2c(what); + digit *= 16; + digit += xsingle2c(what+1); + + return digit; +} + + inline unsigned char *c2x(unsigned what, unsigned char *where) { static const char c2x_table[] = "0123456789abcdef";