Moves static methods from class String to the namespace string

This commit is contained in:
Felipe Zimmerle 2016-11-04 15:58:05 -03:00
parent 62a0cb468b
commit 2244e874e2
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
31 changed files with 151 additions and 182 deletions

View File

@ -24,14 +24,11 @@
#include "modsecurity/modsecurity.h" #include "modsecurity/modsecurity.h"
using modsecurity::utils::String;
namespace modsecurity { namespace modsecurity {
namespace actions { namespace actions {
bool Allow::init(std::string *error) { bool Allow::init(std::string *error) {
std::string a = String::tolower(m_parser_payload); std::string a = utils::string::tolower(m_parser_payload);
if (a == "phase") { if (a == "phase") {
m_allowType = PhaseAllowType; m_allowType = PhaseAllowType;

View File

@ -22,8 +22,6 @@
#include "modsecurity/transaction.h" #include "modsecurity/transaction.h"
#include "src/utils/string.h" #include "src/utils/string.h"
using modsecurity::utils::String;
namespace modsecurity { namespace modsecurity {
namespace actions { namespace actions {
@ -32,7 +30,7 @@ namespace ctl {
bool RuleRemoveTargetById::init(std::string *error) { bool RuleRemoveTargetById::init(std::string *error) {
std::string what(m_parser_payload, 21, m_parser_payload.size() - 21); std::string what(m_parser_payload, 21, m_parser_payload.size() - 21);
std::vector<std::string> param = String::split(what, ';'); std::vector<std::string> param = utils::string::split(what, ';');
if (param.size() < 2) { if (param.size() < 2) {
error->assign(what + " is not a valid `ID;VARIABLE'"); error->assign(what + " is not a valid `ID;VARIABLE'");

View File

@ -22,7 +22,6 @@
#include "modsecurity/transaction.h" #include "modsecurity/transaction.h"
#include "src/utils/string.h" #include "src/utils/string.h"
using modsecurity::utils::String;
namespace modsecurity { namespace modsecurity {
namespace actions { namespace actions {
@ -31,7 +30,7 @@ namespace ctl {
bool RuleRemoveTargetByTag::init(std::string *error) { bool RuleRemoveTargetByTag::init(std::string *error) {
std::string what(m_parser_payload, 22, m_parser_payload.size() - 22); std::string what(m_parser_payload, 22, m_parser_payload.size() - 22);
std::vector<std::string> param = String::split(what, ';'); std::vector<std::string> param = utils::string::split(what, ';');
if (param.size() < 2) { if (param.size() < 2) {
error->assign(what + " is not a valid `TAG;VARIABLE'"); error->assign(what + " is not a valid `TAG;VARIABLE'");

View File

@ -24,14 +24,11 @@
#include "src/utils/string.h" #include "src/utils/string.h"
using modsecurity::utils::String;
namespace modsecurity { namespace modsecurity {
namespace actions { namespace actions {
bool Phase::init(std::string *error) { bool Phase::init(std::string *error) {
std::string a = String::tolower(m_parser_payload); std::string a = utils::string::tolower(m_parser_payload);
m_phase = -1; m_phase = -1;
try { try {

View File

@ -23,8 +23,6 @@
#include "src/macro_expansion.h" #include "src/macro_expansion.h"
#include "src/utils/string.h" #include "src/utils/string.h"
using modsecurity::utils::String;
namespace modsecurity { namespace modsecurity {
namespace actions { namespace actions {
@ -52,7 +50,7 @@ bool SetVar::init(std::string *error) {
pos = m_parser_payload.find("."); pos = m_parser_payload.find(".");
if (pos != std::string::npos) { if (pos != std::string::npos) {
m_collectionName = std::string(m_parser_payload, 0, pos); m_collectionName = std::string(m_parser_payload, 0, pos);
m_collectionName = String::toupper(m_collectionName); m_collectionName = utils::string::toupper(m_collectionName);
} else { } else {
error->assign("Missing the collection and/or variable name"); error->assign("Missing the collection and/or variable name");
return false; return false;

View File

@ -25,15 +25,12 @@
#include "modsecurity/rule_message.h" #include "modsecurity/rule_message.h"
using modsecurity::utils::String;
namespace modsecurity { namespace modsecurity {
namespace actions { namespace actions {
bool Severity::init(std::string *error) { bool Severity::init(std::string *error) {
std::string a = String::tolower(m_parser_payload); std::string a = utils::string::tolower(m_parser_payload);
if (a == "emergency") { if (a == "emergency") {
m_severity = 0; m_severity = 0;
return true; return true;

View File

@ -90,20 +90,20 @@ int CssDecode::css_decode_inplace(unsigned char *input, int64_t input_len) {
switch (j) { switch (j) {
/* Number of hex characters */ /* Number of hex characters */
case 1: case 1:
*d++ = modsecurity::utils::xsingle2c(&input[i]); *d++ = utils::string::xsingle2c(&input[i]);
break; break;
case 2: case 2:
case 3: case 3:
/* Use the last two from the end. */ /* Use the last two from the end. */
*d++ = modsecurity::utils::x2c(&input[i + j - 2]); *d++ = utils::string::x2c(&input[i + j - 2]);
break; break;
case 4: case 4:
/* Use the last two from the end, but request /* Use the last two from the end, but request
* a full width check. * a full width check.
*/ */
*d = modsecurity::utils::x2c(&input[i + j - 2]); *d = utils::string::x2c(&input[i + j - 2]);
fullcheck = 1; fullcheck = 1;
break; break;
@ -112,7 +112,7 @@ int CssDecode::css_decode_inplace(unsigned char *input, int64_t input_len) {
* a full width check if the number is greater * a full width check if the number is greater
* or equal to 0xFFFF. * or equal to 0xFFFF.
*/ */
*d = modsecurity::utils::x2c(&input[i + j - 2]); *d = utils::string::x2c(&input[i + j - 2]);
/* Do full check if first byte is 0 */ /* Do full check if first byte is 0 */
if (input[i] == '0') { if (input[i] == '0') {
fullcheck = 1; fullcheck = 1;
@ -126,7 +126,7 @@ int CssDecode::css_decode_inplace(unsigned char *input, int64_t input_len) {
* a full width check if the number is greater * a full width check if the number is greater
* or equal to 0xFFFF. * or equal to 0xFFFF.
*/ */
*d = modsecurity::utils::x2c(&input[i + j - 2]); *d = utils::string::x2c(&input[i + j - 2]);
/* Do full check if first/second bytes are 0 */ /* Do full check if first/second bytes are 0 */
if ((input[i] == '0') if ((input[i] == '0')

View File

@ -92,7 +92,7 @@ int EscapeSeqDecode::ansi_c_sequences_decode_inplace(unsigned char *input,
if ((i + 3 < input_len) && (isxdigit(input[i + 2])) if ((i + 3 < input_len) && (isxdigit(input[i + 2]))
&& (isxdigit(input[i + 3]))) { && (isxdigit(input[i + 3]))) {
/* Two digits. */ /* Two digits. */
c = modsecurity::utils::x2c(&input[i + 2]); c = utils::string::x2c(&input[i + 2]);
i += 4; i += 4;
} else { } else {
/* Invalid encoding, do nothing. */ /* Invalid encoding, do nothing. */

View File

@ -65,7 +65,7 @@ int HexDecode::inplace(unsigned char *data, int len) {
} }
for (i = 0; i <= len - 2; i += 2) { for (i = 0; i <= len - 2; i += 2) {
*d++ = modsecurity::utils::x2c(&data[i]); *d++ = utils::string::x2c(&data[i]);
count++; count++;
} }
*d = '\0'; *d = '\0';

View File

@ -72,7 +72,7 @@ int JsDecode::inplace(unsigned char *input, u_int64_t input_len) {
/* \uHHHH */ /* \uHHHH */
/* Use only the lower byte. */ /* Use only the lower byte. */
*d = modsecurity::utils::x2c(&input[i + 4]); *d = utils::string::x2c(&input[i + 4]);
/* Full width ASCII (ff01 - ff5e) needs 0x20 added */ /* Full width ASCII (ff01 - ff5e) needs 0x20 added */
if ((*d > 0x00) && (*d < 0x5f) if ((*d > 0x00) && (*d < 0x5f)
@ -87,7 +87,7 @@ int JsDecode::inplace(unsigned char *input, u_int64_t input_len) {
} else if ((i + 3 < input_len) && (input[i + 1] == 'x') } else if ((i + 3 < input_len) && (input[i + 1] == 'x')
&& VALID_HEX(input[i + 2]) && VALID_HEX(input[i + 3])) { && VALID_HEX(input[i + 2]) && VALID_HEX(input[i + 3])) {
/* \xHH */ /* \xHH */
*d++ = modsecurity::utils::x2c(&input[i + 2]); *d++ = utils::string::x2c(&input[i + 2]);
count++; count++;
i += 4; i += 4;
} else if ((i + 1 < input_len) && ISODIGIT(input[i + 1])) { } else if ((i + 1 < input_len) && ISODIGIT(input[i + 1])) {

View File

@ -96,7 +96,7 @@ int SqlHexDecode::inplace(unsigned char *data, int len) {
} }
while (VALID_HEX(data[0]) && VALID_HEX(data[1])) { while (VALID_HEX(data[0]) && VALID_HEX(data[1])) {
*d++ = modsecurity::utils::x2c(data); *d++ = utils::string::x2c(data);
data += 2; data += 2;
count += 2; count += 2;
} }

View File

@ -114,7 +114,7 @@ int UrlDecodeUni::inplace(unsigned char *input, u_int64_t input_len,
} else { } else {
/* We first make use of the lower byte here, /* We first make use of the lower byte here,
* ignoring the higher byte. */ * ignoring the higher byte. */
*d = modsecurity::utils::x2c(&input[i + 4]); *d = utils::string::x2c(&input[i + 4]);
/* Full width ASCII (ff01 - ff5e) /* Full width ASCII (ff01 - ff5e)
* needs 0x20 added */ * needs 0x20 added */
@ -153,7 +153,7 @@ int UrlDecodeUni::inplace(unsigned char *input, u_int64_t input_len,
char c2 = input[i + 2]; char c2 = input[i + 2];
if (VALID_HEX(c1) && VALID_HEX(c2)) { if (VALID_HEX(c1) && VALID_HEX(c2)) {
*d++ = modsecurity::utils::x2c(&input[i + 1]); *d++ = utils::string::x2c(&input[i + 1]);
count++; count++;
i += 3; i += 3;
} else { } else {

View File

@ -69,7 +69,7 @@ std::string UrlEncode::url_enc(const char *input,
} else { } else {
*d++ = '%'; *d++ = '%';
count++; count++;
modsecurity::utils::c2x(c, (unsigned char *)d); utils::string::c2x(c, (unsigned char *)d);
d += 2; d += 2;
count++; count++;
count++; count++;

View File

@ -93,7 +93,7 @@ char *Utf8ToUnicode::inplace(unsigned char *input,
count++; count++;
if (count <= len) { if (count <= len) {
if (c == 0) if (c == 0)
*data = modsecurity::utils::x2c(&c); *data = utils::string::x2c(&c);
else else
*data++ = c; *data++ = c;
} }

View File

@ -28,9 +28,6 @@
#include "src/utils/string.h" #include "src/utils/string.h"
using modsecurity::utils::String;
namespace modsecurity { namespace modsecurity {
namespace collection { namespace collection {
namespace backend { namespace backend {
@ -103,8 +100,8 @@ void InMemoryPerProcess::resolveMultiMatches(const std::string& var,
if (x.first.at(keySize) != ':') { if (x.first.at(keySize) != ':') {
continue; continue;
} }
std::string fu = String::toupper(x.first); std::string fu = utils::string::toupper(x.first);
std::string fvar = String::toupper(var); std::string fvar = utils::string::toupper(var);
if (fu.compare(0, keySize, fvar) != 0) { if (fu.compare(0, keySize, fvar) != 0) {
continue; continue;
} }

View File

@ -30,9 +30,6 @@
#include "src/utils/string.h" #include "src/utils/string.h"
using modsecurity::utils::String;
namespace modsecurity { namespace modsecurity {
namespace collection { namespace collection {
@ -64,28 +61,28 @@ Collections::~Collections() {
void Collections::storeOrUpdateFirst(const std::string& collectionName, void Collections::storeOrUpdateFirst(const std::string& collectionName,
const std::string& variableName, const std::string& variableName,
const std::string& targetValue) { const std::string& targetValue) {
if (String::tolower(collectionName) == "ip" if (utils::string::tolower(collectionName) == "ip"
&& !m_ip_collection_key.empty()) { && !m_ip_collection_key.empty()) {
m_ip_collection->storeOrUpdateFirst(collectionName + ":" m_ip_collection->storeOrUpdateFirst(collectionName + ":"
+ variableName, m_ip_collection_key, targetValue); + variableName, m_ip_collection_key, targetValue);
return; return;
} }
if (String::tolower(collectionName) == "global" if (utils::string::tolower(collectionName) == "global"
&& !m_global_collection_key.empty()) { && !m_global_collection_key.empty()) {
m_global_collection->storeOrUpdateFirst(collectionName + ":" m_global_collection->storeOrUpdateFirst(collectionName + ":"
+ variableName, m_global_collection_key, targetValue); + variableName, m_global_collection_key, targetValue);
return; return;
} }
if (String::tolower(collectionName) == "resource" if (utils::string::tolower(collectionName) == "resource"
&& !m_resource_collection_key.empty()) { && !m_resource_collection_key.empty()) {
m_resource_collection->storeOrUpdateFirst(collectionName + ":" m_resource_collection->storeOrUpdateFirst(collectionName + ":"
+ variableName, m_resource_collection_key, targetValue); + variableName, m_resource_collection_key, targetValue);
return; return;
} }
if (String::tolower(collectionName) == "session" if (utils::string::tolower(collectionName) == "session"
&& !m_session_collection_key.empty()) { && !m_session_collection_key.empty()) {
m_session_collection->storeOrUpdateFirst(collectionName + ":" m_session_collection->storeOrUpdateFirst(collectionName + ":"
+ variableName, m_session_collection_key, targetValue); + variableName, m_session_collection_key, targetValue);
@ -137,7 +134,7 @@ std::string* Collections::resolveFirst(const std::string& var) {
for (auto &a : *this) { for (auto &a : *this) {
std::string *res = a.second->resolveFirst( std::string *res = a.second->resolveFirst(
String::toupper(a.first) + ":" + var); utils::string::toupper(a.first) + ":" + var);
if (res != NULL) { if (res != NULL) {
return res; return res;
} }
@ -149,38 +146,39 @@ std::string* Collections::resolveFirst(const std::string& var) {
std::string* Collections::resolveFirst(const std::string& collectionName, std::string* Collections::resolveFirst(const std::string& collectionName,
const std::string& var) { const std::string& var) {
if (String::tolower(collectionName) == "ip" if (utils::string::tolower(collectionName) == "ip"
&& !m_ip_collection_key.empty()) { && !m_ip_collection_key.empty()) {
return m_ip_collection->resolveFirst( return m_ip_collection->resolveFirst(
String::toupper(collectionName) utils::string::toupper(collectionName)
+ ":" + var, m_ip_collection_key); + ":" + var, m_ip_collection_key);
} }
if (String::tolower(collectionName) == "global" if (utils::string::tolower(collectionName) == "global"
&& !m_global_collection_key.empty()) { && !m_global_collection_key.empty()) {
return m_global_collection->resolveFirst( return m_global_collection->resolveFirst(
String::toupper(collectionName) utils::string::toupper(collectionName)
+ ":" + var, m_global_collection_key); + ":" + var, m_global_collection_key);
} }
if (String::tolower(collectionName) == "resource" if (utils::string::tolower(collectionName) == "resource"
&& !m_resource_collection_key.empty()) { && !m_resource_collection_key.empty()) {
return m_resource_collection->resolveFirst( return m_resource_collection->resolveFirst(
String::toupper(collectionName) utils::string::toupper(collectionName)
+ ":" + var, m_resource_collection_key); + ":" + var, m_resource_collection_key);
} }
if (String::tolower(collectionName) == "session" if (utils::string::tolower(collectionName) == "session"
&& !m_session_collection_key.empty()) { && !m_session_collection_key.empty()) {
return m_session_collection->resolveFirst( return m_session_collection->resolveFirst(
String::toupper(collectionName) utils::string::toupper(collectionName)
+ ":" + var, m_session_collection_key); + ":" + var, m_session_collection_key);
} }
for (auto &a : *this) { for (auto &a : *this) {
if (String::tolower(a.first) == String::tolower(collectionName)) { if (utils::string::tolower(a.first)
== utils::string::tolower(collectionName)) {
std::string *res = a.second->resolveFirst( std::string *res = a.second->resolveFirst(
String::toupper(a.first) utils::string::toupper(a.first)
+ ":" + var); + ":" + var);
if (res != NULL) { if (res != NULL) {
return res; return res;
@ -200,7 +198,8 @@ std::string Collections::resolveFirstCopy(const std::string& var) {
} }
for (auto &a : *this) { for (auto &a : *this) {
std::string res = a.second->resolveFirstCopy(String::toupper(a.first) + std::string res = a.second->resolveFirstCopy(
utils::string::toupper(a.first) +
":" + var); ":" + var);
if (res.empty() == false) { if (res.empty() == false) {
return res; return res;
@ -213,38 +212,39 @@ std::string Collections::resolveFirstCopy(const std::string& var) {
std::string Collections::resolveFirstCopy(const std::string& collectionName, std::string Collections::resolveFirstCopy(const std::string& collectionName,
const std::string& var) { const std::string& var) {
if (String::tolower(collectionName) == "ip" if (utils::string::tolower(collectionName) == "ip"
&& !m_ip_collection_key.empty()) { && !m_ip_collection_key.empty()) {
return m_ip_collection->resolveFirstCopy( return m_ip_collection->resolveFirstCopy(
String::toupper(collectionName) utils::string::toupper(collectionName)
+ ":" + var, m_ip_collection_key); + ":" + var, m_ip_collection_key);
} }
if (String::tolower(collectionName) == "global" if (utils::string::tolower(collectionName) == "global"
&& !m_global_collection_key.empty()) { && !m_global_collection_key.empty()) {
return m_global_collection->resolveFirstCopy( return m_global_collection->resolveFirstCopy(
String::toupper(collectionName) + ":" + var, utils::string::toupper(collectionName) + ":" + var,
m_global_collection_key); m_global_collection_key);
} }
if (String::tolower(collectionName) == "resource" if (utils::string::tolower(collectionName) == "resource"
&& !m_resource_collection_key.empty()) { && !m_resource_collection_key.empty()) {
return m_resource_collection->resolveFirstCopy( return m_resource_collection->resolveFirstCopy(
String::toupper(collectionName) + ":" + var, utils::string::toupper(collectionName) + ":" + var,
m_resource_collection_key); m_resource_collection_key);
} }
if (String::tolower(collectionName) == "session" if (utils::string::tolower(collectionName) == "session"
&& !m_session_collection_key.empty()) { && !m_session_collection_key.empty()) {
return m_session_collection->resolveFirstCopy( return m_session_collection->resolveFirstCopy(
String::toupper(collectionName) + ":" + var, utils::string::toupper(collectionName) + ":" + var,
m_session_collection_key); m_session_collection_key);
} }
for (auto &a : *this) { for (auto &a : *this) {
if (String::tolower(a.first) == String::tolower(collectionName)) { if (utils::string::tolower(a.first)
== utils::string::tolower(collectionName)) {
std::string res = a.second->resolveFirstCopy( std::string res = a.second->resolveFirstCopy(
String::toupper(a.first) + ":" + var); utils::string::toupper(a.first) + ":" + var);
if (res.empty() == false) { if (res.empty() == false) {
return res; return res;
} }
@ -266,27 +266,27 @@ void Collections::resolveSingleMatch(const std::string& var,
const std::string& collection, const std::string& collection,
std::vector<const Variable *> *l) { std::vector<const Variable *> *l) {
if (String::tolower(collection) == "ip" if (utils::string::tolower(collection) == "ip"
&& !m_ip_collection_key.empty()) { && !m_ip_collection_key.empty()) {
m_ip_collection->resolveSingleMatch(var, m_ip_collection_key, l); m_ip_collection->resolveSingleMatch(var, m_ip_collection_key, l);
return; return;
} }
if (String::tolower(collection) == "global" if (utils::string::tolower(collection) == "global"
&& !m_global_collection_key.empty()) { && !m_global_collection_key.empty()) {
m_global_collection->resolveSingleMatch(var, m_global_collection->resolveSingleMatch(var,
m_global_collection_key, l); m_global_collection_key, l);
return; return;
} }
if (String::tolower(collection) == "resource" if (utils::string::tolower(collection) == "resource"
&& !m_resource_collection_key.empty()) { && !m_resource_collection_key.empty()) {
m_resource_collection->resolveSingleMatch(var, m_resource_collection->resolveSingleMatch(var,
m_resource_collection_key, l); m_resource_collection_key, l);
return; return;
} }
if (String::tolower(collection) == "session" if (utils::string::tolower(collection) == "session"
&& !m_session_collection_key.empty()) { && !m_session_collection_key.empty()) {
m_session_collection->resolveSingleMatch(var, m_session_collection->resolveSingleMatch(var,
m_session_collection_key, l); m_session_collection_key, l);
@ -308,27 +308,27 @@ void Collections::resolveMultiMatches(const std::string& var,
void Collections::resolveMultiMatches(const std::string& var, void Collections::resolveMultiMatches(const std::string& var,
const std::string& collection, const std::string& collection,
std::vector<const Variable *> *l) { std::vector<const Variable *> *l) {
if (String::tolower(collection) == "ip" if (utils::string::tolower(collection) == "ip"
&& !m_ip_collection_key.empty()) { && !m_ip_collection_key.empty()) {
m_ip_collection->resolveMultiMatches(var, m_ip_collection_key, l); m_ip_collection->resolveMultiMatches(var, m_ip_collection_key, l);
return; return;
} }
if (String::tolower(collection) == "global" if (utils::string::tolower(collection) == "global"
&& !m_global_collection_key.empty()) { && !m_global_collection_key.empty()) {
m_global_collection->resolveMultiMatches(var, m_global_collection->resolveMultiMatches(var,
m_global_collection_key, l); m_global_collection_key, l);
return; return;
} }
if (String::tolower(collection) == "resource" if (utils::string::tolower(collection) == "resource"
&& !m_resource_collection_key.empty()) { && !m_resource_collection_key.empty()) {
m_resource_collection->resolveMultiMatches(var, m_resource_collection->resolveMultiMatches(var,
m_resource_collection_key, l); m_resource_collection_key, l);
return; return;
} }
if (String::tolower(collection) == "session" if (utils::string::tolower(collection) == "session"
&& !m_session_collection_key.empty()) { && !m_session_collection_key.empty()) {
m_session_collection->resolveMultiMatches(var, m_session_collection->resolveMultiMatches(var,
m_session_collection_key, l); m_session_collection_key, l);
@ -349,34 +349,34 @@ void Collections::resolveRegularExpression(const std::string& var,
void Collections::resolveRegularExpression(const std::string& var, void Collections::resolveRegularExpression(const std::string& var,
const std::string& collection, const std::string& collection,
std::vector<const Variable *> *l) { std::vector<const Variable *> *l) {
if (String::tolower(collection) == "ip" if (utils::string::tolower(collection) == "ip"
&& !m_ip_collection_key.empty()) { && !m_ip_collection_key.empty()) {
m_ip_collection->resolveRegularExpression( m_ip_collection->resolveRegularExpression(
String::toupper(collection) utils::string::toupper(collection)
+ ":" + var, m_ip_collection_key, l); + ":" + var, m_ip_collection_key, l);
return; return;
} }
if (String::tolower(collection) == "global" if (utils::string::tolower(collection) == "global"
&& !m_global_collection_key.empty()) { && !m_global_collection_key.empty()) {
m_global_collection->resolveRegularExpression( m_global_collection->resolveRegularExpression(
String::toupper(collection) utils::string::toupper(collection)
+ ":" + var, m_global_collection_key, l); + ":" + var, m_global_collection_key, l);
return; return;
} }
if (String::tolower(collection) == "resource" if (utils::string::tolower(collection) == "resource"
&& !m_resource_collection_key.empty()) { && !m_resource_collection_key.empty()) {
m_resource_collection->resolveRegularExpression( m_resource_collection->resolveRegularExpression(
String::toupper(collection) utils::string::toupper(collection)
+ ":" + var, m_resource_collection_key, l); + ":" + var, m_resource_collection_key, l);
return; return;
} }
if (String::tolower(collection) == "session" if (utils::string::tolower(collection) == "session"
&& !m_session_collection_key.empty()) { && !m_session_collection_key.empty()) {
m_session_collection->resolveRegularExpression( m_session_collection->resolveRegularExpression(
String::toupper(collection) utils::string::toupper(collection)
+ ":" + var, m_session_collection_key, l); + ":" + var, m_session_collection_key, l);
return; return;
} }

View File

@ -22,8 +22,6 @@
#include "src/utils/string.h" #include "src/utils/string.h"
using modsecurity::utils::String;
namespace modsecurity { namespace modsecurity {
MacroExpansion::MacroExpansion() { } MacroExpansion::MacroExpansion() { }
@ -75,7 +73,7 @@ std::string MacroExpansion::expand(const std::string& input,
std::string var = std::string(variable, collection + 1, std::string var = std::string(variable, collection + 1,
variable.length() - (collection + 1)); variable.length() - (collection + 1));
if (String::toupper(col) == "RULE") { if (utils::string::toupper(col) == "RULE") {
if (rule == NULL) { if (rule == NULL) {
transaction->debug(9, "macro expansion: cannot resolve " \ transaction->debug(9, "macro expansion: cannot resolve " \
"RULE variable without the Rule object"); "RULE variable without the Rule object");

View File

@ -122,7 +122,6 @@ using modsecurity::actions::Ver;
using modsecurity::actions::transformations::None; using modsecurity::actions::transformations::None;
using modsecurity::actions::transformations::Transformation; using modsecurity::actions::transformations::Transformation;
using modsecurity::operators::Operator; using modsecurity::operators::Operator;
using modsecurity::utils::String;
@ -578,7 +577,7 @@ expression:
} }
| CONFIG_DIR_SEC_MARKER | CONFIG_DIR_SEC_MARKER
{ {
driver.addSecMarker(String::removeBracketsIfNeeded($1)); driver.addSecMarker(modsecurity::utils::string::removeBracketsIfNeeded($1));
} }
| CONFIG_DIR_RULE_ENG CONFIG_VALUE_OFF | CONFIG_DIR_RULE_ENG CONFIG_VALUE_OFF
{ {

View File

@ -11,7 +11,6 @@
using modsecurity::Parser::Driver; using modsecurity::Parser::Driver;
using modsecurity::Utils::HttpsClient; using modsecurity::Utils::HttpsClient;
using modsecurity::utils::String;
typedef yy::seclang_parser p; typedef yy::seclang_parser p;
@ -436,7 +435,7 @@ VAR_FREE_TEXT_SPACE_COMMA [^, \t\"]+
std::string key; std::string key;
std::string url; std::string url;
std::vector<std::string> conf = String::split(yytext, ' '); std::vector<std::string> conf = modsecurity::utils::string::split(yytext, ' ');
key = conf[1]; key = conf[1];
url = conf[2]; url = conf[2];
c.setKey(key); c.setKey(key);

View File

@ -31,9 +31,6 @@
#include "src/utils/string.h" #include "src/utils/string.h"
using modsecurity::utils::String;
namespace modsecurity { namespace modsecurity {
namespace RequestBodyProcessor { namespace RequestBodyProcessor {
@ -720,7 +717,7 @@ int Multipart::process_part_header(std::string *error) {
} }
new_value = std::string(data); new_value = std::string(data);
String::chomp(&new_value); utils::string::chomp(&new_value);
/* update the header value in the table */ /* update the header value in the table */
header_value = m_mpp->m_headers.at(m_mpp->m_last_header_name); header_value = m_mpp->m_headers.at(m_mpp->m_last_header_name);
@ -770,7 +767,7 @@ int Multipart::process_part_header(std::string *error) {
data++; data++;
} }
header_value = std::string(data); header_value = std::string(data);
String::chomp(&header_value); utils::string::chomp(&header_value);
/* error if the name already exists */ /* error if the name already exists */
if (m_mpp->m_headers.count(header_name) > 0) { if (m_mpp->m_headers.count(header_name) > 0) {
@ -1040,7 +1037,7 @@ int Multipart::multipart_complete(std::string *error) {
int Multipart::count_boundary_params(const std::string& str_header_value) { int Multipart::count_boundary_params(const std::string& str_header_value) {
std::string lower = String::tolower(str_header_value); std::string lower = utils::string::tolower(str_header_value);
const char *header_value = lower.c_str(); const char *header_value = lower.c_str();
char *duplicate = NULL; char *duplicate = NULL;
char *s = NULL; char *s = NULL;

View File

@ -37,7 +37,6 @@
using modsecurity::Variables::Variations::Exclusion; using modsecurity::Variables::Variations::Exclusion;
using modsecurity::utils::String;
namespace modsecurity { namespace modsecurity {
@ -428,8 +427,8 @@ bool Rule::evaluate(Transaction *trasn) {
} }
#ifndef NO_LOGS #ifndef NO_LOGS
trasn->debug(9, "Target value: \"" + String::limitTo(80, trasn->debug(9, "Target value: \"" + utils::string::limitTo(80,
String::toHexIfNeeded(value)) \ utils::string::toHexIfNeeded(value)) \
+ "\" (Variable: " + v->m_key + ")"); + "\" (Variable: " + v->m_key + ")");
#endif #endif
@ -453,9 +452,10 @@ bool Rule::evaluate(Transaction *trasn) {
if (this->op->m_match_message.empty() == true) { if (this->op->m_match_message.empty() == true) {
ruleMessage->m_match = "Matched \"Operator `" + ruleMessage->m_match = "Matched \"Operator `" +
this->op->m_op + "' with parameter `" + this->op->m_op + "' with parameter `" +
String::limitTo(200, this->op->m_param) + utils::string::limitTo(200, this->op->m_param) +
"' against variable `" + v->m_key + "' (Value: `" + "' against variable `" + v->m_key + "' (Value: `" +
String::limitTo(100, String::toHexIfNeeded(value)) + utils::string::limitTo(100,
utils::string::toHexIfNeeded(value)) +
"' ) \" at " + v->m_key; "' ) \" at " + v->m_key;
} else { } else {
ruleMessage->m_match = this->op->m_match_message; ruleMessage->m_match = this->op->m_match_message;

View File

@ -48,7 +48,7 @@ std::string RuleMessage::errorLog(Transaction *trans) {
msg.append(" [uri \"" + std::string(trans->m_uri) + "\"]"); msg.append(" [uri \"" + std::string(trans->m_uri) + "\"]");
msg.append(" [unique_id \"" + trans->m_id + "\"]"); msg.append(" [unique_id \"" + trans->m_id + "\"]");
return modsecurity::utils::String::toHexIfNeeded(msg); return modsecurity::utils::string::toHexIfNeeded(msg);
} }
} // namespace modsecurity } // namespace modsecurity

View File

@ -20,16 +20,13 @@
#include "src/utils/string.h" #include "src/utils/string.h"
using modsecurity::utils::String;
namespace modsecurity { namespace modsecurity {
bool RulesExceptions::load(const std::string &a, std::string *error) { bool RulesExceptions::load(const std::string &a, std::string *error) {
std::vector<std::string> toRemove = String::split(a, ' '); std::vector<std::string> toRemove = utils::string::split(a, ' ');
for (std::string &a : toRemove) { for (std::string &a : toRemove) {
std::string b = String::removeBracketsIfNeeded(a); std::string b = utils::string::removeBracketsIfNeeded(a);
size_t dash = b.find('-'); size_t dash = b.find('-');
if (dash != std::string::npos) { if (dash != std::string::npos) {

View File

@ -55,7 +55,6 @@
using modsecurity::actions::Action; using modsecurity::actions::Action;
using modsecurity::RequestBodyProcessor::Multipart; using modsecurity::RequestBodyProcessor::Multipart;
using modsecurity::RequestBodyProcessor::XML; using modsecurity::RequestBodyProcessor::XML;
using modsecurity::utils::String;
namespace modsecurity { namespace modsecurity {
@ -251,7 +250,7 @@ int Transaction::processConnection(const char *client, int cPort,
bool Transaction::extractArguments(const std::string &orig, bool Transaction::extractArguments(const std::string &orig,
const std::string& buf) { const std::string& buf) {
char sep1 = '&'; char sep1 = '&';
std::vector<std::string> key_value_sets = String::split(buf, sep1); std::vector<std::string> key_value_sets = utils::string::split(buf, sep1);
for (std::string t : key_value_sets) { for (std::string t : key_value_sets) {
char sep2 = '='; char sep2 = '=';
@ -263,7 +262,7 @@ bool Transaction::extractArguments(const std::string &orig,
std::string key; std::string key;
std::string value; std::string value;
std::vector<std::string> key_value = String::split(t, sep2); std::vector<std::string> key_value = utils::string::split(t, sep2);
for (auto& a : key_value) { for (auto& a : key_value) {
if (i == 0) { if (i == 0) {
key = a; key = a;
@ -499,16 +498,17 @@ int Transaction::addRequestHeader(const std::string& key,
this->m_collections.store("REQUEST_HEADERS:" + key, value); this->m_collections.store("REQUEST_HEADERS:" + key, value);
std::string keyl = String::tolower(key); std::string keyl = utils::string::tolower(key);
if (keyl == "authorization") { if (keyl == "authorization") {
std::vector<std::string> type = String::split(value, ' '); std::vector<std::string> type = utils::string::split(value, ' ');
this->m_collections.store("AUTH_TYPE", type[0]); this->m_collections.store("AUTH_TYPE", type[0]);
} }
if (keyl == "cookie") { if (keyl == "cookie") {
std::vector<std::string> cookies = String::split(value, ';'); std::vector<std::string> cookies = utils::string::split(value, ';');
while (cookies.empty() == false) { while (cookies.empty() == false) {
std::vector<std::string> s = String::split(cookies.back(), '='); std::vector<std::string> s = utils::string::split(cookies.back(),
'=');
if (s.size() > 1) { if (s.size() > 1) {
if (s[0].at(0) == ' ') { if (s[0].at(0) == ' ') {
s[0].erase(0, 1); s[0].erase(0, 1);
@ -530,7 +530,7 @@ int Transaction::addRequestHeader(const std::string& key,
if (keyl == "content-type") { if (keyl == "content-type") {
std::string multipart("multipart/form-data"); std::string multipart("multipart/form-data");
std::string l = String::tolower(value); std::string l = utils::string::tolower(value);
if (l.compare(0, multipart.length(), multipart) == 0) { if (l.compare(0, multipart.length(), multipart) == 0) {
this->m_requestBodyType = MultiPartRequestBody; this->m_requestBodyType = MultiPartRequestBody;
m_collections.store("REQBODY_PROCESSOR", "MULTIPART"); m_collections.store("REQBODY_PROCESSOR", "MULTIPART");
@ -543,7 +543,7 @@ int Transaction::addRequestHeader(const std::string& key,
} }
if (keyl == "host") { if (keyl == "host") {
std::vector<std::string> host = String::split(value, ':'); std::vector<std::string> host = utils::string::split(value, ':');
m_collections.store("SERVER_NAME", host[0]); m_collections.store("SERVER_NAME", host[0]);
} }
return 1; return 1;
@ -948,7 +948,7 @@ int Transaction::addResponseHeader(const std::string& key,
this->m_collections.store("RESPONSE_HEADERS:" + key, value); this->m_collections.store("RESPONSE_HEADERS:" + key, value);
if (String::tolower(key) == "content-type") { if (utils::string::tolower(key) == "content-type") {
this->m_responseContentType->assign(value); this->m_responseContentType->assign(value);
} }
return 1; return 1;
@ -1307,15 +1307,15 @@ std::string Transaction::toOldAuditLogFormatIndex(const std::string &filename,
strftime(tstr, 299, "[%d/%b/%Y:%H:%M:%S %z]", &timeinfo); strftime(tstr, 299, "[%d/%b/%Y:%H:%M:%S %z]", &timeinfo);
ss << String::dash_if_empty( ss << utils::string::dash_if_empty(
this->m_collections.resolveFirst("REQUEST_HEADERS:Host")) << " "; this->m_collections.resolveFirst("REQUEST_HEADERS:Host")) << " ";
ss << String::dash_if_empty(this->m_clientIpAddress) << " "; ss << utils::string::dash_if_empty(this->m_clientIpAddress) << " ";
/** TODO: Check variable */ /** TODO: Check variable */
ss << String::dash_if_empty( ss << utils::string::dash_if_empty(
this->m_collections.resolveFirst("REMOTE_USER")); this->m_collections.resolveFirst("REMOTE_USER"));
ss << " "; ss << " ";
/** TODO: Check variable */ /** TODO: Check variable */
ss << String::dash_if_empty( ss << utils::string::dash_if_empty(
this->m_collections.resolveFirst("LOCAL_USER")); this->m_collections.resolveFirst("LOCAL_USER"));
ss << " "; ss << " ";
ss << tstr << " "; ss << tstr << " ";
@ -1329,15 +1329,15 @@ std::string Transaction::toOldAuditLogFormatIndex(const std::string &filename,
ss << this->m_httpCodeReturned << " "; ss << this->m_httpCodeReturned << " ";
ss << this->m_responseBody.tellp(); ss << this->m_responseBody.tellp();
/** TODO: Check variable */ /** TODO: Check variable */
ss << String::dash_if_empty( ss << utils::string::dash_if_empty(
this->m_collections.resolveFirst("REFERER")) << " "; this->m_collections.resolveFirst("REFERER")) << " ";
ss << "\""; ss << "\"";
ss << String::dash_if_empty( ss << utils::string::dash_if_empty(
this->m_collections.resolveFirst("REQUEST_HEADERS:User-Agent")); this->m_collections.resolveFirst("REQUEST_HEADERS:User-Agent"));
ss << "\" "; ss << "\" ";
ss << this->m_id << " "; ss << this->m_id << " ";
/** TODO: Check variable */ /** TODO: Check variable */
ss << String::dash_if_empty( ss << utils::string::dash_if_empty(
this->m_collections.resolveFirst("REFERER")) << " "; this->m_collections.resolveFirst("REFERER")) << " ";
ss << filename << " "; ss << filename << " ";
@ -1435,7 +1435,7 @@ std::string Transaction::toJSON(int parts) {
const unsigned char *buf; const unsigned char *buf;
size_t len; size_t len;
yajl_gen g = NULL; yajl_gen g = NULL;
std::string ts = String::ascTime(&m_timeStamp).c_str(); std::string ts = utils::string::ascTime(&m_timeStamp).c_str();
std::string uniqueId = UniqueId::uniqueId(); std::string uniqueId = UniqueId::uniqueId();
g = yajl_gen_alloc(NULL); g = yajl_gen_alloc(NULL);

View File

@ -43,7 +43,7 @@ int urldecode_nonstrict_inplace(unsigned char *input,
char c1 = input[i + 1]; char c1 = input[i + 1];
char c2 = input[i + 2]; char c2 = input[i + 2];
if (VALID_HEX(c1) && VALID_HEX(c2)) { if (VALID_HEX(c1) && VALID_HEX(c2)) {
uint64_t uni = x2c(&input[i + 1]); uint64_t uni = string::x2c(&input[i + 1]);
*d++ = (wchar_t)uni; *d++ = (wchar_t)uni;
count++; count++;
@ -99,8 +99,8 @@ std::string uri_decode(const std::string & sSrc) {
while (pSrc < SRC_LAST_DEC) { while (pSrc < SRC_LAST_DEC) {
if (*pSrc == '%') { if (*pSrc == '%') {
char dec1, dec2; char dec1, dec2;
if (-1 != (dec1 = HEX2DEC[*(pSrc + 1)]) if (-1 != (dec1 = string::HEX2DEC[*(pSrc + 1)])
&& -1 != (dec2 = HEX2DEC[*(pSrc + 2)])) { && -1 != (dec2 = string::HEX2DEC[*(pSrc + 2)])) {
*pEnd++ = (dec1 << 4) + dec2; *pEnd++ = (dec1 << 4) + dec2;
pSrc += 3; pSrc += 3;
continue; continue;

View File

@ -44,16 +44,17 @@
namespace modsecurity { namespace modsecurity {
namespace utils { namespace utils {
namespace string {
std::string String::ascTime(time_t *t) { std::string ascTime(time_t *t) {
std::string ts = std::ctime(t); std::string ts = std::ctime(t);
ts.pop_back(); ts.pop_back();
return ts; return ts;
} }
std::string String::dash_if_empty(const std::string *str) { std::string dash_if_empty(const std::string *str) {
if (str == NULL || str->empty()) { if (str == NULL || str->empty()) {
return "-"; return "-";
} }
@ -62,7 +63,7 @@ std::string String::dash_if_empty(const std::string *str) {
} }
std::string String::dash_if_empty(const char *str) { std::string dash_if_empty(const char *str) {
if (str == NULL || strlen(str) == 0) { if (str == NULL || strlen(str) == 0) {
return "-"; return "-";
} }
@ -71,7 +72,7 @@ std::string String::dash_if_empty(const char *str) {
} }
std::string String::limitTo(int amount, const std::string &str) { std::string limitTo(int amount, const std::string &str) {
std::string ret; std::string ret;
if (str.length() > amount) { if (str.length() > amount) {
@ -85,7 +86,7 @@ std::string String::limitTo(int amount, const std::string &str) {
} }
std::string String::removeBracketsIfNeeded(std::string a) { std::string removeBracketsIfNeeded(std::string a) {
if ((a.at(0) == '"') && (a.at(a.length()-1) == '"')) { if ((a.at(0) == '"') && (a.at(a.length()-1) == '"')) {
a.pop_back(); a.pop_back();
a.erase(0, 1); a.erase(0, 1);
@ -94,7 +95,7 @@ std::string String::removeBracketsIfNeeded(std::string a) {
} }
std::string String::string_to_hex(const std::string& input) { std::string string_to_hex(const std::string& input) {
static const char* const lut = "0123456789ABCDEF"; static const char* const lut = "0123456789ABCDEF";
size_t len = input.length(); size_t len = input.length();
@ -109,7 +110,7 @@ std::string String::string_to_hex(const std::string& input) {
} }
std::string String::toHexIfNeeded(const std::string &str) { std::string toHexIfNeeded(const std::string &str) {
std::stringstream res; std::stringstream res;
for (int i = 0; i < str.size(); i++) { for (int i = 0; i < str.size(); i++) {
@ -125,7 +126,7 @@ std::string String::toHexIfNeeded(const std::string &str) {
} }
std::string String::tolower(std::string str) { std::string tolower(std::string str) {
std::string value; std::string value;
value.resize(str.length()); value.resize(str.length());
@ -138,7 +139,7 @@ std::string String::tolower(std::string str) {
} }
std::string String::toupper(std::string str) { std::string toupper(std::string str) {
std::locale loc; std::locale loc;
std::string value; std::string value;
@ -150,7 +151,7 @@ std::string String::toupper(std::string str) {
} }
std::vector<std::string> String::split(std::string str, char delimiter) { std::vector<std::string> split(std::string str, char delimiter) {
std::vector<std::string> internal; std::vector<std::string> internal;
std::stringstream ss(str); // Turn the string into a stream. std::stringstream ss(str); // Turn the string into a stream.
std::string tok; std::string tok;
@ -163,7 +164,7 @@ std::vector<std::string> String::split(std::string str, char delimiter) {
} }
void String::chomp(std::string *str) { void chomp(std::string *str) {
std::string::size_type pos = str->find_last_not_of("\n\r"); std::string::size_type pos = str->find_last_not_of("\n\r");
if (pos != std::string::npos) { if (pos != std::string::npos) {
str->erase(pos+1, str->length()-pos-1); str->erase(pos+1, str->length()-pos-1);
@ -205,5 +206,6 @@ unsigned char *c2x(unsigned what, unsigned char *where) {
} }
} // namespace string
} // namespace utils } // namespace utils
} // namespace modsecurity } // namespace modsecurity

View File

@ -18,8 +18,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#ifndef SRC_UTILS_MSC_STRING_H_ #ifndef SRC_UTILS_STRING_H_
#define SRC_UTILS_MSC_STRING_H_ #define SRC_UTILS_STRING_H_
#define VALID_HEX(X) (((X >= '0') && (X <= '9')) || \ #define VALID_HEX(X) (((X >= '0') && (X <= '9')) || \
((X >= 'a') && (X <= 'f')) || ((X >= 'A') && (X <= 'F'))) ((X >= 'a') && (X <= 'f')) || ((X >= 'A') && (X <= 'F')))
@ -29,6 +29,7 @@
namespace modsecurity { namespace modsecurity {
namespace utils { namespace utils {
namespace string {
const char HEX2DEC[256] = { const char HEX2DEC[256] = {
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
@ -54,26 +55,24 @@ const char HEX2DEC[256] = {
}; };
class String { std::string ascTime(time_t *t);
public: std::string dash_if_empty(const char *str);
static std::string ascTime(time_t *t); std::string dash_if_empty(const std::string *str);
static std::string dash_if_empty(const char *str); std::string limitTo(int amount, const std::string &str);
static std::string dash_if_empty(const std::string *str); std::string removeBracketsIfNeeded(std::string a);
static std::string limitTo(int amount, const std::string &str); std::string string_to_hex(const std::string& input);
static std::string removeBracketsIfNeeded(std::string a); std::string toHexIfNeeded(const std::string &str);
static std::string string_to_hex(const std::string& input); std::string tolower(std::string str);
static std::string toHexIfNeeded(const std::string &str); std::string toupper(std::string str);
static std::string tolower(std::string str); std::vector<std::string> split(std::string str, char delimiter);
static std::string toupper(std::string str); void chomp(std::string *str);
static std::vector<std::string> split(std::string str, char delimiter);
static void chomp(std::string *str);
};
unsigned char x2c(unsigned char *what); unsigned char x2c(unsigned char *what);
unsigned char xsingle2c(unsigned char *what); unsigned char xsingle2c(unsigned char *what);
unsigned char *c2x(unsigned what, unsigned char *where); unsigned char *c2x(unsigned what, unsigned char *where);
} // namespace string
} // namespace utils } // namespace utils
} // namespace modsecurity } // namespace modsecurity
#endif // SRC_UTILS_MSC_STRING_H_ #endif // SRC_UTILS_STRING_H_

View File

@ -47,9 +47,6 @@
#include "src/utils/string.h" #include "src/utils/string.h"
using modsecurity::utils::String;
namespace modsecurity { namespace modsecurity {
namespace Variables { namespace Variables {
@ -57,7 +54,7 @@ void Rule::evaluateInternal(Transaction *t,
modsecurity::Rule *rule, modsecurity::Rule *rule,
std::vector<const collection::Variable *> *l) { std::vector<const collection::Variable *> *l) {
std::map<std::string, std::string> envs; std::map<std::string, std::string> envs;
std::string m_name_upper = String::toupper(m_name); std::string m_name_upper = utils::string::toupper(m_name);
// id // id
envs.insert(std::pair<std::string, std::string>("RULE:id", envs.insert(std::pair<std::string, std::string>("RULE:id",
@ -99,7 +96,7 @@ void Rule::evaluateInternal(Transaction *t,
} }
for (auto& x : envs) { for (auto& x : envs) {
std::string xup = String::toupper(x.first); std::string xup = utils::string::toupper(x.first);
if ((xup.substr(0, m_name_upper.size() + 1) if ((xup.substr(0, m_name_upper.size() + 1)
.compare(m_name_upper + ":") != 0) .compare(m_name_upper + ":") != 0)
&& (xup != m_name_upper)) { && (xup != m_name_upper)) {

View File

@ -25,7 +25,6 @@
#include "src/utils/string.h" #include "src/utils/string.h"
using modsecurity::utils::String;
using modsecurity::Variables::Variations::Exclusion; using modsecurity::Variables::Variations::Exclusion;
@ -39,7 +38,7 @@ Variable::Variable(std::string name)
m_isExclusion(false), m_isExclusion(false),
m_isCount(false) { m_isCount(false) {
if (m_name.find(":") != std::string::npos) { if (m_name.find(":") != std::string::npos) {
std::string col = String::toupper( std::string col = utils::string::toupper(
std::string(m_name, 0, m_name.find(":"))); std::string(m_name, 0, m_name.find(":")));
std::string name = std::string(m_name, m_name.find(":") + 1, std::string name = std::string(m_name, m_name.find(":") + 1,
m_name.size()); m_name.size());
@ -56,19 +55,19 @@ Variable::Variable(std::string name)
m_type = MultipleMatches; m_type = MultipleMatches;
} }
if (String::tolower(m_name) == "tx") { if (utils::string::tolower(m_name) == "tx") {
m_collectionName = "TX"; m_collectionName = "TX";
m_type = MultipleMatches; m_type = MultipleMatches;
} else if (String::tolower(m_name) == "ip") { } else if (utils::string::tolower(m_name) == "ip") {
m_collectionName = "IP"; m_collectionName = "IP";
m_type = MultipleMatches; m_type = MultipleMatches;
} else if (String::tolower(m_name) == "global") { } else if (utils::string::tolower(m_name) == "global") {
m_collectionName = "GLOBAL"; m_collectionName = "GLOBAL";
m_type = MultipleMatches; m_type = MultipleMatches;
} else if (String::tolower(m_name) == "resource") { } else if (utils::string::tolower(m_name) == "resource") {
m_collectionName = "RESOURCE"; m_collectionName = "RESOURCE";
m_type = MultipleMatches; m_type = MultipleMatches;
} else if (String::tolower(m_name) == "session") { } else if (utils::string::tolower(m_name) == "session") {
m_collectionName = "SESSION"; m_collectionName = "SESSION";
m_type = MultipleMatches; m_type = MultipleMatches;
} else if (m_name.find(".") != std::string::npos) { } else if (m_name.find(".") != std::string::npos) {
@ -87,7 +86,7 @@ Variable::Variable(std::string name, VariableKind kind)
m_isExclusion(false), m_isExclusion(false),
m_isCount(false) { m_isCount(false) {
if (m_name.find(":") != std::string::npos) { if (m_name.find(":") != std::string::npos) {
std::string col = String::toupper( std::string col = utils::string::toupper(
std::string(m_name, 0, m_name.find(":"))); std::string(m_name, 0, m_name.find(":")));
std::string name = std::string(m_name, m_name.find(":") + 1, std::string name = std::string(m_name, m_name.find(":") + 1,
m_name.size()); m_name.size());
@ -104,19 +103,19 @@ Variable::Variable(std::string name, VariableKind kind)
m_type = MultipleMatches; m_type = MultipleMatches;
} }
if (String::tolower(m_name) == "tx") { if (utils::string::tolower(m_name) == "tx") {
m_collectionName = "TX"; m_collectionName = "TX";
m_type = MultipleMatches; m_type = MultipleMatches;
} else if (String::tolower(m_name) == "ip") { } else if (utils::string::tolower(m_name) == "ip") {
m_collectionName = "IP"; m_collectionName = "IP";
m_type = MultipleMatches; m_type = MultipleMatches;
} else if (String::tolower(m_name) == "global") { } else if (utils::string::tolower(m_name) == "global") {
m_collectionName = "GLOBAL"; m_collectionName = "GLOBAL";
m_type = MultipleMatches; m_type = MultipleMatches;
} else if (String::tolower(m_name) == "resource") { } else if (utils::string::tolower(m_name) == "resource") {
m_collectionName = "RESOURCE"; m_collectionName = "RESOURCE";
m_type = MultipleMatches; m_type = MultipleMatches;
} else if (String::tolower(m_name) == "session") { } else if (utils::string::tolower(m_name) == "session") {
m_collectionName = "SESSION"; m_collectionName = "SESSION";
m_type = MultipleMatches; m_type = MultipleMatches;
} else if (m_name.find(".") != std::string::npos) { } else if (m_name.find(".") != std::string::npos) {

View File

@ -31,7 +31,6 @@
#include "src/utils/string.h" #include "src/utils/string.h"
using modsecurity::utils::String;
using modsecurity_test::UnitTest; using modsecurity_test::UnitTest;
using modsecurity_test::ModSecurityTest; using modsecurity_test::ModSecurityTest;
using modsecurity_test::ModSecurityTestResults; using modsecurity_test::ModSecurityTestResults;
@ -91,7 +90,8 @@ void perform_unit_test(ModSecurityTest<UnitTest> *test, UnitTest *t,
if (test->m_automake_output) { if (test->m_automake_output) {
std::cout << t->name << " " std::cout << t->name << " "
<< String::toHexIfNeeded(t->input) << std::endl; << modsecurity::utils::string::toHexIfNeeded(t->input)
<< std::endl;
} }
} }

View File

@ -27,9 +27,6 @@
#include "src/utils/string.h" #include "src/utils/string.h"
using modsecurity::utils::String;
namespace modsecurity_test { namespace modsecurity_test {
@ -112,9 +109,11 @@ std::string UnitTest::print() {
i << this->obtained << "\"" << std::endl; i << this->obtained << "\"" << std::endl;
} }
if (this->output != this->obtainedOutput) { if (this->output != this->obtainedOutput) {
i << "Expecting: \"" << String::toHexIfNeeded(this->output); i << "Expecting: \"";
i << modsecurity::utils::string::toHexIfNeeded(this->output);
i << "\" - returned: \""; i << "\" - returned: \"";
i << String::toHexIfNeeded(this->obtainedOutput) << "\""; i << modsecurity::utils::string::toHexIfNeeded(this->obtainedOutput);
i << "\"";
i << std::endl; i << std::endl;
} }