mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-19 18:54:23 +03:00
Very first commit: libmodsecurity
Check the README.md file for further information about the libmodsecurity.
This commit is contained in:
47
src/actions/transformations/lowercase.cc
Normal file
47
src/actions/transformations/lowercase.cc
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "actions/transformations/lowercase.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#include "modsecurity/assay.h"
|
||||
#include "actions/transformations/transformation.h"
|
||||
#include "actions/action.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace actions {
|
||||
namespace transformations {
|
||||
|
||||
|
||||
LowerCase::LowerCase(std::string a)
|
||||
: Transformation(a) {
|
||||
}
|
||||
|
||||
std::string & LowerCase::evaluate(std::string value,
|
||||
Assay *assay) {
|
||||
std::locale loc;
|
||||
|
||||
for (std::string::size_type i=0; i < value.length(); ++i) {
|
||||
value[i] = std::tolower(value[i], loc);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
} // namespace transformations
|
||||
} // namespace actions
|
||||
} // namespace ModSecurity
|
||||
45
src/actions/transformations/lowercase.h
Normal file
45
src/actions/transformations/lowercase.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "actions/action.h"
|
||||
#include "actions/transformations/transformation.h"
|
||||
|
||||
#ifndef SRC_ACTIONS_TRANSFORMATIONS_LOWERCASE_H_
|
||||
#define SRC_ACTIONS_TRANSFORMATIONS_LOWERCASE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace ModSecurity {
|
||||
class Assay;
|
||||
namespace actions {
|
||||
namespace transformations {
|
||||
|
||||
|
||||
class LowerCase : public Transformation {
|
||||
public:
|
||||
explicit LowerCase(std::string action);
|
||||
std::string& evaluate(std::string exp,
|
||||
Assay *assay) override;
|
||||
};
|
||||
|
||||
} // namespace transformations
|
||||
} // namespace actions
|
||||
} // namespace ModSecurity
|
||||
|
||||
#endif
|
||||
|
||||
#endif // SRC_ACTIONS_TRANSFORMATIONS_LOWERCASE_H_
|
||||
55
src/actions/transformations/transformation.cc
Normal file
55
src/actions/transformations/transformation.cc
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "actions/transformations/transformation.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "modsecurity/assay.h"
|
||||
#include "actions/transformations/trim.h"
|
||||
#include "actions/transformations/lowercase.h"
|
||||
#include "actions/action.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace actions {
|
||||
namespace transformations {
|
||||
|
||||
Transformation::Transformation(std::string action)
|
||||
: Action(action) {
|
||||
this->name = this->action;
|
||||
this->name.erase(0, 2);
|
||||
this->action_kind = 1;
|
||||
}
|
||||
|
||||
std::string &Transformation::evaluate(std::string value,
|
||||
Assay *assay) {
|
||||
return value;
|
||||
}
|
||||
|
||||
Transformation* Transformation::instantiate(std::string a) {
|
||||
if (a == "t:trim") {
|
||||
return new transformations::Trim(a);
|
||||
}
|
||||
if (a == "t:lowercase") {
|
||||
return new LowerCase(a);
|
||||
}
|
||||
|
||||
return new Transformation(a);
|
||||
}
|
||||
|
||||
} // namespace transformations
|
||||
} // namespace actions
|
||||
} // namespace ModSecurity
|
||||
46
src/actions/transformations/transformation.h
Normal file
46
src/actions/transformations/transformation.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "actions/action.h"
|
||||
|
||||
#ifndef SRC_ACTIONS_TRANSFORMATIONS_TRANSFORMATION_H_
|
||||
#define SRC_ACTIONS_TRANSFORMATIONS_TRANSFORMATION_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace ModSecurity {
|
||||
class Assay;
|
||||
|
||||
namespace actions {
|
||||
namespace transformations {
|
||||
|
||||
class Transformation : public Action {
|
||||
public:
|
||||
explicit Transformation(std::string action);
|
||||
static Transformation* instantiate(std::string);
|
||||
|
||||
std::string& evaluate(std::string exp,
|
||||
Assay *assay) override;
|
||||
};
|
||||
|
||||
} // namespace transformations
|
||||
} // namespace actions
|
||||
} // namespace ModSecurity
|
||||
|
||||
#endif
|
||||
|
||||
#endif // SRC_ACTIONS_TRANSFORMATIONS_TRANSFORMATION_H_
|
||||
61
src/actions/transformations/trim.cc
Normal file
61
src/actions/transformations/trim.cc
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "actions/transformations/trim.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <cctype>
|
||||
#include <locale>
|
||||
|
||||
#include "modsecurity/assay.h"
|
||||
#include "actions/transformations/transformation.h"
|
||||
#include "actions/action.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace actions {
|
||||
namespace transformations {
|
||||
|
||||
static inline std::string *ltrim(std::string *s) {
|
||||
s->erase(s->begin(), std::find_if(s->begin(), s->end(),
|
||||
std::not1(std::ptr_fun<int, int>(std::isspace))));
|
||||
return s;
|
||||
}
|
||||
|
||||
static inline std::string *rtrim(std::string *s) {
|
||||
s->erase(std::find_if(s->rbegin(), s->rend(),
|
||||
std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s->end());
|
||||
return s;
|
||||
}
|
||||
|
||||
static inline std::string *trim(std::string *s) {
|
||||
return ltrim(rtrim(s));
|
||||
}
|
||||
|
||||
Trim::Trim(std::string action)
|
||||
: Transformation(action) {
|
||||
this->action_kind = 1;
|
||||
}
|
||||
|
||||
std::string & Trim::evaluate(std::string value,
|
||||
Assay *assay) {
|
||||
return *trim(&value);
|
||||
}
|
||||
|
||||
} // namespace transformations
|
||||
} // namespace actions
|
||||
} // namespace ModSecurity
|
||||
44
src/actions/transformations/trim.h
Normal file
44
src/actions/transformations/trim.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "actions/action.h"
|
||||
#include "actions/transformations/transformation.h"
|
||||
|
||||
#ifndef SRC_ACTIONS_TRANSFORMATIONS_TRIM_H_
|
||||
#define SRC_ACTIONS_TRANSFORMATIONS_TRIM_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace ModSecurity {
|
||||
class Assay;
|
||||
|
||||
namespace actions {
|
||||
namespace transformations {
|
||||
|
||||
class Trim : public Transformation {
|
||||
public:
|
||||
explicit Trim(std::string action);
|
||||
std::string& evaluate(std::string exp,
|
||||
Assay *assay) override;
|
||||
};
|
||||
|
||||
} // namespace transformations
|
||||
} // namespace actions
|
||||
} // namespace ModSecurity
|
||||
|
||||
#endif
|
||||
|
||||
#endif // SRC_ACTIONS_TRANSFORMATIONS_TRIM_H_
|
||||
Reference in New Issue
Block a user