mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Adds method setConnectorInformation to ModSecurity class
For the purpose of log it is necessary for modsecurity to understand which 'connector' is consuming the API.
This commit is contained in:
parent
e42e7545d7
commit
2138dd1369
@ -30,6 +30,9 @@ int main (int argc, char **argv)
|
||||
|
||||
modsec = msc_init();
|
||||
|
||||
msc_set_connector_info(modsec, "ModSecurity-test v0.0.1-alpha (Simple " \
|
||||
"example on how to use ModSecurity API");
|
||||
|
||||
rules = msc_create_rules_set();
|
||||
msc_rules_add_file(rules, main_rule_uri);
|
||||
|
||||
|
@ -124,6 +124,8 @@ class ModSecurity {
|
||||
~ModSecurity() { }
|
||||
|
||||
static std::string whoAmI();
|
||||
void setConnectorInformation(std::string connector);
|
||||
const std::string& getConnectorInformation();
|
||||
|
||||
/**
|
||||
*
|
||||
@ -200,6 +202,9 @@ class ModSecurity {
|
||||
*/
|
||||
NUMBER_OF_PHASES,
|
||||
};
|
||||
|
||||
private:
|
||||
std::string m_connector;
|
||||
};
|
||||
|
||||
|
||||
@ -213,6 +218,8 @@ extern "C" {
|
||||
ModSecurity *msc_init();
|
||||
/** @ingroup ModSecurity_C_API */
|
||||
const char *msc_who_am_i(ModSecurity *msc);
|
||||
/** @ingroup ModSecurity_C_API */
|
||||
void msc_set_connector_info(ModSecurity *msc, const char *connector);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -38,7 +38,8 @@ namespace ModSecurity {
|
||||
*
|
||||
* @endcode
|
||||
*/
|
||||
ModSecurity::ModSecurity() {
|
||||
ModSecurity::ModSecurity()
|
||||
: m_connector("") {
|
||||
UniqueId::uniqueId();
|
||||
srand(time(NULL));
|
||||
}
|
||||
@ -84,6 +85,66 @@ std::string ModSecurity::whoAmI() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @name setConnectorInformation
|
||||
* @brief Set information about the connector that is using the library.
|
||||
*
|
||||
* For the purpose of log it is necessary for modsecurity to understand which
|
||||
* 'connector' is consuming the API.
|
||||
*
|
||||
* @note It is strongly recommended to set a information in the following
|
||||
* pattern:
|
||||
*
|
||||
* ConnectorName vX.Y.Z-tag (something else)
|
||||
*
|
||||
* For instance: ModSecurity-nginx v0.0.1-alpha (Whee)
|
||||
*
|
||||
* @param connector Information about the connector.
|
||||
*
|
||||
*/
|
||||
void ModSecurity::setConnectorInformation(std::string connector) {
|
||||
m_connector = connector;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @name getConnectorInformation
|
||||
* @brief Returns the connector information.
|
||||
*
|
||||
* Returns whatever was set by 'setConnectorInformation'. Check
|
||||
* setConnectorInformation documentation to understand the expected format.
|
||||
*
|
||||
* @retval "" Nothing was informed about the connector.
|
||||
* @retval !="" Connector information.
|
||||
*/
|
||||
const std::string& ModSecurity::getConnectorInformation() {
|
||||
return m_connector;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @name msc_set_connector_info
|
||||
* @brief Set information about the connector that is using the library.
|
||||
*
|
||||
* For the purpose of log it is necessary for modsecurity to understand which
|
||||
* 'connector' is consuming the API.
|
||||
*
|
||||
* @note It is strongly recommended to set a information in the following
|
||||
* pattern:
|
||||
*
|
||||
* ConnectorName vX.Y.Z-tag (something else)
|
||||
*
|
||||
* For instance: ModSecurity-nginx v0.0.1-alpha (Whee)
|
||||
*
|
||||
* @param connector Information about the connector.
|
||||
*
|
||||
*/
|
||||
extern "C" void msc_set_connector_info(ModSecurity *msc,
|
||||
const char *connector) {
|
||||
msc->setConnectorInformation(std::string(connector));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @name msc_who_am_i
|
||||
* @brief Return information about this ModSecurity version and platform.
|
||||
|
@ -74,6 +74,9 @@ int main(int argc, char *argv[]) {
|
||||
ModSecurity::Rules *rules;
|
||||
|
||||
modsec = new ModSecurity::ModSecurity();
|
||||
modsec->setConnectorInformation("ModSecurity-benchmark v0.0.1-alpha" \
|
||||
" (ModSecurity benchmark utility)");
|
||||
|
||||
rules = new ModSecurity::Rules();
|
||||
rules->loadFromUri(rules_file);
|
||||
|
||||
|
@ -70,6 +70,8 @@ void perform_unit_test(std::vector<RegressionTest *> *tests,
|
||||
r.status = 200;
|
||||
|
||||
modsec = new ModSecurity::ModSecurity();
|
||||
modsec->setConnectorInformation("ModSecurity-regression v0.0.1-alpha" \
|
||||
" (ModSecurity regression test utility)");
|
||||
modsec_rules = new ModSecurity::Rules(debug_log);
|
||||
|
||||
if (modsec_rules->load(t->rules.c_str()) == false) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user