Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions headers/modsecurity/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,12 @@
/** @ingroup ModSecurity_C_API */
int msc_set_request_hostname(Transaction *transaction, const unsigned char *hostname);

/** @ingroup ModSecurity_C_API */
size_t msc_get_matched_rules_count(Transaction *transaction);

/** @ingroup ModSecurity_C_API */
int64_t msc_get_matched_rule_id(Transaction *transaction, size_t index);

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, wo curl)

syntax error: '<parameter-list>' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, wo curl)

syntax error: ';' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, wo curl)

syntax error: identifier 'msc_get_matched_rule_id' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, wo lua)

syntax error: '<parameter-list>' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, wo lua)

syntax error: ';' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, wo lua)

syntax error: identifier 'msc_get_matched_rule_id' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, wo libxml)

syntax error: '<parameter-list>' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, wo libxml)

syntax error: ';' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, wo libxml)

syntax error: identifier 'msc_get_matched_rule_id' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, full)

syntax error: '<parameter-list>' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, full)

syntax error: ';' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, full)

syntax error: identifier 'msc_get_matched_rule_id' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, wo maxmind)

syntax error: '<parameter-list>' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, wo maxmind)

syntax error: ';' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, wo maxmind)

syntax error: identifier 'msc_get_matched_rule_id' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, full)

syntax error: '<parameter-list>' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, full)

syntax error: ';' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, full)

syntax error: identifier 'msc_get_matched_rule_id' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, with lmdb)

syntax error: '<parameter-list>' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, with lmdb)

syntax error: ';' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, with lmdb)

syntax error: identifier 'msc_get_matched_rule_id' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, without maxmind)

syntax error: '<parameter-list>' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, without maxmind)

syntax error: ';' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, without maxmind)

syntax error: identifier 'msc_get_matched_rule_id' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, with lmdb)

syntax error: '<parameter-list>' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, with lmdb)

syntax error: ';' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, with lmdb)

syntax error: identifier 'msc_get_matched_rule_id' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, without libxml)

syntax error: '<parameter-list>' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, without libxml)

syntax error: ';' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, without libxml)

syntax error: identifier 'msc_get_matched_rule_id' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, without lua)

syntax error: '<parameter-list>' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, without lua)

syntax error: ';' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, without lua)

syntax error: identifier 'msc_get_matched_rule_id' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, without curl)

syntax error: '<parameter-list>' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, without curl)

syntax error: ';' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

Check failure on line 746 in headers/modsecurity/transaction.h

View workflow job for this annotation

GitHub Actions / Windows (x64, without curl)

syntax error: identifier 'msc_get_matched_rule_id' [D:\a\ModSecurity\ModSecurity\build\win32\build\simple_example_using_c.vcxproj]

#ifdef __cplusplus
}
} // namespace modsecurity
Expand Down
43 changes: 43 additions & 0 deletions src/transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <set>
#include <unordered_map>
#include <vector>
Expand Down Expand Up @@ -2325,5 +2326,47 @@
}


/**
* @name msc_get_matched_rules_count
* @brief Retrieve the number of matched rules on a transaction.
*
* Returns the number of rule-match records held on the transaction.
* Every rule that matched (disruptive or not) contributes one entry.
*
Comment thread
meirdev marked this conversation as resolved.
Outdated
* @param transaction ModSecurity transaction.
*
* @returns The number of matched rule records on the transaction.
*
*/
extern "C" size_t msc_get_matched_rules_count(Transaction *transaction) {

Check warning on line 2341 in src/transaction.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this parameter a pointer-to-const. The current type of "transaction" is "class modsecurity::Transaction *".

See more on https://sonarcloud.io/project/issues?id=owasp-modsecurity_ModSecurity&issues=AZ20PajO9hZDB1hNVx-n&open=AZ20PajO9hZDB1hNVx-n&pullRequest=3551

Check warning on line 2341 in src/transaction.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Move this 'extern "C"' declaration out of the namespace.

See more on https://sonarcloud.io/project/issues?id=owasp-modsecurity_ModSecurity&issues=AZ20PajO9hZDB1hNVx-m&open=AZ20PajO9hZDB1hNVx-m&pullRequest=3551
return transaction->m_rulesMessages.size();
}


/**
* @name msc_get_matched_rule_id
* @brief Retrieve the rule id of the n-th matched rule.
*
* Returns the rule id of the n-th matched rule (0-based).
*
* @param transaction ModSecurity transaction.
* @param index Zero-based index into the matched rule records.
*
* @returns The rule id at the given index.
* @retval >0 Rule id of the matched rule at the given index.
* @retval 0 Index is out of range.
*
*/
extern "C" int64_t msc_get_matched_rule_id(Transaction *transaction,

Check warning on line 2360 in src/transaction.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Move this 'extern "C"' declaration out of the namespace.

See more on https://sonarcloud.io/project/issues?id=owasp-modsecurity_ModSecurity&issues=AZ20PajO9hZDB1hNVx-o&open=AZ20PajO9hZDB1hNVx-o&pullRequest=3551
Comment thread
meirdev marked this conversation as resolved.
Outdated
size_t index) {
if (index >= transaction->m_rulesMessages.size()) {
return 0;
}
auto it = transaction->m_rulesMessages.begin();
std::advance(it, index);
return it->m_rule.m_ruleId;
Comment thread
meirdev marked this conversation as resolved.
Outdated
}


} // namespace modsecurity

Loading