Moves string related functions from utils' to utils/string'

This commit is contained in:
Felipe Zimmerle
2016-11-01 14:59:06 -03:00
parent 9733cacd4d
commit 73c4d69174
25 changed files with 403 additions and 236 deletions

View File

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

View File

@@ -28,6 +28,10 @@
#include "modsecurity/collection/collection.h"
#include "src/collection/backend/in_memory-per_process.h"
#include "src/utils.h"
#include "utils/msc_string.h"
using modsecurity::utils::String;
namespace modsecurity {
namespace collection {
@@ -60,28 +64,28 @@ Collections::~Collections() {
void Collections::storeOrUpdateFirst(const std::string& collectionName,
const std::string& variableName,
const std::string& targetValue) {
if (tolower(collectionName) == "ip"
if (String::tolower(collectionName) == "ip"
&& !m_ip_collection_key.empty()) {
m_ip_collection->storeOrUpdateFirst(collectionName + ":"
+ variableName, m_ip_collection_key, targetValue);
return;
}
if (tolower(collectionName) == "global"
if (String::tolower(collectionName) == "global"
&& !m_global_collection_key.empty()) {
m_global_collection->storeOrUpdateFirst(collectionName + ":"
+ variableName, m_global_collection_key, targetValue);
return;
}
if (tolower(collectionName) == "resource"
if (String::tolower(collectionName) == "resource"
&& !m_resource_collection_key.empty()) {
m_resource_collection->storeOrUpdateFirst(collectionName + ":"
+ variableName, m_resource_collection_key, targetValue);
return;
}
if (tolower(collectionName) == "session"
if (String::tolower(collectionName) == "session"
&& !m_session_collection_key.empty()) {
m_session_collection->storeOrUpdateFirst(collectionName + ":"
+ variableName, m_session_collection_key, targetValue);
@@ -132,7 +136,8 @@ std::string* Collections::resolveFirst(const std::string& var) {
}
for (auto &a : *this) {
std::string *res = a.second->resolveFirst(toupper(a.first) + ":" + var);
std::string *res = a.second->resolveFirst(
String::toupper(a.first) + ":" + var);
if (res != NULL) {
return res;
}
@@ -144,33 +149,38 @@ std::string* Collections::resolveFirst(const std::string& var) {
std::string* Collections::resolveFirst(const std::string& collectionName,
const std::string& var) {
if (tolower(collectionName) == "ip"
if (String::tolower(collectionName) == "ip"
&& !m_ip_collection_key.empty()) {
return m_ip_collection->resolveFirst(toupper(collectionName)
+ ":" + var, m_ip_collection_key);
return m_ip_collection->resolveFirst(
String::toupper(collectionName)
+ ":" + var, m_ip_collection_key);
}
if (tolower(collectionName) == "global"
if (String::tolower(collectionName) == "global"
&& !m_global_collection_key.empty()) {
return m_global_collection->resolveFirst(toupper(collectionName)
+ ":" + var, m_global_collection_key);
return m_global_collection->resolveFirst(
String::toupper(collectionName)
+ ":" + var, m_global_collection_key);
}
if (tolower(collectionName) == "resource"
if (String::tolower(collectionName) == "resource"
&& !m_resource_collection_key.empty()) {
return m_resource_collection->resolveFirst(toupper(collectionName)
+ ":" + var, m_resource_collection_key);
return m_resource_collection->resolveFirst(
String::toupper(collectionName)
+ ":" + var, m_resource_collection_key);
}
if (tolower(collectionName) == "session"
if (String::tolower(collectionName) == "session"
&& !m_session_collection_key.empty()) {
return m_session_collection->resolveFirst(toupper(collectionName)
+ ":" + var, m_session_collection_key);
return m_session_collection->resolveFirst(
String::toupper(collectionName)
+ ":" + var, m_session_collection_key);
}
for (auto &a : *this) {
if (tolower(a.first) == tolower(collectionName)) {
std::string *res = a.second->resolveFirst(toupper(a.first)
if (String::tolower(a.first) == String::tolower(collectionName)) {
std::string *res = a.second->resolveFirst(
String::toupper(a.first)
+ ":" + var);
if (res != NULL) {
return res;
@@ -190,7 +200,7 @@ std::string Collections::resolveFirstCopy(const std::string& var) {
}
for (auto &a : *this) {
std::string res = a.second->resolveFirstCopy(toupper(a.first) +
std::string res = a.second->resolveFirstCopy(String::toupper(a.first) +
":" + var);
if (res.empty() == false) {
return res;
@@ -203,37 +213,38 @@ std::string Collections::resolveFirstCopy(const std::string& var) {
std::string Collections::resolveFirstCopy(const std::string& collectionName,
const std::string& var) {
if (tolower(collectionName) == "ip"
if (String::tolower(collectionName) == "ip"
&& !m_ip_collection_key.empty()) {
return m_ip_collection->resolveFirstCopy(toupper(collectionName)
+ ":" + var, m_ip_collection_key);
return m_ip_collection->resolveFirstCopy(
String::toupper(collectionName)
+ ":" + var, m_ip_collection_key);
}
if (tolower(collectionName) == "global"
if (String::tolower(collectionName) == "global"
&& !m_global_collection_key.empty()) {
return m_global_collection->resolveFirstCopy(
toupper(collectionName) + ":" + var,
String::toupper(collectionName) + ":" + var,
m_global_collection_key);
}
if (tolower(collectionName) == "resource"
if (String::tolower(collectionName) == "resource"
&& !m_resource_collection_key.empty()) {
return m_resource_collection->resolveFirstCopy(
toupper(collectionName) + ":" + var,
String::toupper(collectionName) + ":" + var,
m_resource_collection_key);
}
if (tolower(collectionName) == "session"
if (String::tolower(collectionName) == "session"
&& !m_session_collection_key.empty()) {
return m_session_collection->resolveFirstCopy(
toupper(collectionName) + ":" + var,
String::toupper(collectionName) + ":" + var,
m_session_collection_key);
}
for (auto &a : *this) {
if (tolower(a.first) == tolower(collectionName)) {
std::string res = a.second->resolveFirstCopy(toupper(a.first)
+ ":" + var);
if (String::tolower(a.first) == String::tolower(collectionName)) {
std::string res = a.second->resolveFirstCopy(
String::toupper(a.first) + ":" + var);
if (res.empty() == false) {
return res;
}
@@ -255,27 +266,27 @@ void Collections::resolveSingleMatch(const std::string& var,
const std::string& collection,
std::vector<const Variable *> *l) {
if (tolower(collection) == "ip"
if (String::tolower(collection) == "ip"
&& !m_ip_collection_key.empty()) {
m_ip_collection->resolveSingleMatch(var, m_ip_collection_key, l);
return;
}
if (tolower(collection) == "global"
if (String::tolower(collection) == "global"
&& !m_global_collection_key.empty()) {
m_global_collection->resolveSingleMatch(var,
m_global_collection_key, l);
return;
}
if (tolower(collection) == "resource"
if (String::tolower(collection) == "resource"
&& !m_resource_collection_key.empty()) {
m_resource_collection->resolveSingleMatch(var,
m_resource_collection_key, l);
return;
}
if (tolower(collection) == "session"
if (String::tolower(collection) == "session"
&& !m_session_collection_key.empty()) {
m_session_collection->resolveSingleMatch(var,
m_session_collection_key, l);
@@ -297,27 +308,27 @@ void Collections::resolveMultiMatches(const std::string& var,
void Collections::resolveMultiMatches(const std::string& var,
const std::string& collection,
std::vector<const Variable *> *l) {
if (tolower(collection) == "ip"
if (String::tolower(collection) == "ip"
&& !m_ip_collection_key.empty()) {
m_ip_collection->resolveMultiMatches(var, m_ip_collection_key, l);
return;
}
if (tolower(collection) == "global"
if (String::tolower(collection) == "global"
&& !m_global_collection_key.empty()) {
m_global_collection->resolveMultiMatches(var,
m_global_collection_key, l);
return;
}
if (tolower(collection) == "resource"
if (String::tolower(collection) == "resource"
&& !m_resource_collection_key.empty()) {
m_resource_collection->resolveMultiMatches(var,
m_resource_collection_key, l);
return;
}
if (tolower(collection) == "session"
if (String::tolower(collection) == "session"
&& !m_session_collection_key.empty()) {
m_session_collection->resolveMultiMatches(var,
m_session_collection_key, l);
@@ -338,30 +349,34 @@ void Collections::resolveRegularExpression(const std::string& var,
void Collections::resolveRegularExpression(const std::string& var,
const std::string& collection,
std::vector<const Variable *> *l) {
if (tolower(collection) == "ip"
if (String::tolower(collection) == "ip"
&& !m_ip_collection_key.empty()) {
m_ip_collection->resolveRegularExpression(toupper(collection)
m_ip_collection->resolveRegularExpression(
String::toupper(collection)
+ ":" + var, m_ip_collection_key, l);
return;
}
if (tolower(collection) == "global"
if (String::tolower(collection) == "global"
&& !m_global_collection_key.empty()) {
m_global_collection->resolveRegularExpression(toupper(collection)
m_global_collection->resolveRegularExpression(
String::toupper(collection)
+ ":" + var, m_global_collection_key, l);
return;
}
if (tolower(collection) == "resource"
if (String::tolower(collection) == "resource"
&& !m_resource_collection_key.empty()) {
m_resource_collection->resolveRegularExpression(toupper(collection)
m_resource_collection->resolveRegularExpression(
String::toupper(collection)
+ ":" + var, m_resource_collection_key, l);
return;
}
if (tolower(collection) == "session"
if (String::tolower(collection) == "session"
&& !m_session_collection_key.empty()) {
m_session_collection->resolveRegularExpression(toupper(collection)
m_session_collection->resolveRegularExpression(
String::toupper(collection)
+ ":" + var, m_session_collection_key, l);
return;
}