Refactoring on the transformation classes

This commit is contained in:
Felipe Zimmerle
2016-12-20 14:56:28 -03:00
parent bbb61d560c
commit 15b81d09e7
5 changed files with 406 additions and 144 deletions

View File

@@ -58,10 +58,6 @@
#include "src/actions/transformations/url_encode.h"
#include "src/actions/transformations/utf8_to_unicode.h"
#define IF_MATCH(b) \
if (a.compare(2, std::strlen(#b), #b) == 0)
namespace modsecurity {
namespace actions {
namespace transformations {
@@ -73,50 +69,6 @@ std::string Transformation::evaluate(std::string value,
}
Transformation* Transformation::instantiate(std::string a) {
IF_MATCH(base64DecodeExt) { return new Base64DecodeExt(a); }
IF_MATCH(base64Decode) { return new Base64Decode(a); }
IF_MATCH(base64Encode) { return new Base64Encode(a); }
IF_MATCH(cmd_line) { return new CmdLine(a); }
IF_MATCH(compress_whitespace) { return new CompressWhitespace(a); }
IF_MATCH(cssDecode) { return new CssDecode(a); }
IF_MATCH(escapeSeqDecode) { return new EscapeSeqDecode(a); }
IF_MATCH(hexDecode) { return new HexDecode(a); }
IF_MATCH(hexEncode) { return new HexEncode(a); }
IF_MATCH(htmlEntityDecode) { return new HtmlEntityDecode(a); }
IF_MATCH(jsDecode) { return new JsDecode(a); }
IF_MATCH(length) { return new Length(a); }
IF_MATCH(lowercase) { return new LowerCase(a); }
IF_MATCH(md5) { return new Md5(a); }
IF_MATCH(none) { return new None(a); }
IF_MATCH(normalizePathWin) { return new NormalisePathWin(a); }
IF_MATCH(normalisePathWin) { return new NormalisePathWin(a); }
IF_MATCH(normalizePath) { return new NormalisePath(a); }
IF_MATCH(normalisePath) { return new NormalisePath(a); }
IF_MATCH(parityEven7bit) { return new ParityEven7bit(a); }
IF_MATCH(parityOdd7bit) { return new ParityOdd7bit(a); }
IF_MATCH(parityZero7bit) { return new ParityZero7bit(a); }
IF_MATCH(removeCommentsChar) { return new RemoveCommentsChar(a); }
IF_MATCH(removeComments) { return new RemoveComments(a); }
IF_MATCH(removeNulls) { return new RemoveNulls(a); }
IF_MATCH(removeWhitespace) { return new RemoveWhitespace(a); }
IF_MATCH(compressWhitespace) { return new CompressWhitespace(a); }
IF_MATCH(replaceComments) { return new ReplaceComments(a); }
IF_MATCH(replaceNulls) { return new ReplaceNulls(a); }
IF_MATCH(sha1) { return new Sha1(a); }
IF_MATCH(sqlHexDecode) { return new SqlHexDecode(a); }
IF_MATCH(transformation) { return new Transformation(a); }
IF_MATCH(trimLeft) { return new TrimLeft(a); }
IF_MATCH(trimRight) { return new TrimRight(a); }
IF_MATCH(trim) { return new Trim(a); }
IF_MATCH(urlDecodeUni) { return new UrlDecodeUni(a); }
IF_MATCH(urlDecode) { return new UrlDecode(a); }
IF_MATCH(urlEncode) { return new UrlEncode(a); }
IF_MATCH(utf8ToUnicode) { return new Utf8ToUnicode(a); }
return new Transformation(a);
}
} // namespace transformations
} // namespace actions
} // namespace modsecurity

View File

@@ -20,8 +20,6 @@
#ifndef SRC_ACTIONS_TRANSFORMATIONS_TRANSFORMATION_H_
#define SRC_ACTIONS_TRANSFORMATIONS_TRANSFORMATION_H_
#ifdef __cplusplus
namespace modsecurity {
class Transaction;
@@ -36,8 +34,6 @@ class Transformation : public Action {
explicit Transformation(const std::string& _action, int kind)
: Action(_action, kind) { }
static Transformation* instantiate(std::string);
std::string evaluate(std::string exp,
Transaction *transaction) override;
};
@@ -46,6 +42,5 @@ class Transformation : public Action {
} // namespace actions
} // namespace modsecurity
#endif
#endif // SRC_ACTIONS_TRANSFORMATIONS_TRANSFORMATION_H_