@@ -2330,5 +2330,60 @@ extern "C" int msc_set_request_hostname(Transaction *transaction,
23302330}
23312331
23322332
2333+ /* *
2334+ * @name msc_get_rules_messages_size
2335+ * @brief Retrieve the number of RuleMessage records on a transaction.
2336+ *
2337+ * Returns the size of Transaction::m_rulesMessages: the number of
2338+ * RuleMessage records that were selected to be logged on the
2339+ * transaction. This is not necessarily the total number of rules that
2340+ * matched!
2341+ *
2342+ * @param transaction ModSecurity transaction.
2343+ *
2344+ * @returns The number of RuleMessage records on the transaction.
2345+ *
2346+ */
2347+ extern " C" size_t msc_get_rules_messages_size (const Transaction *transaction) {
2348+ return transaction->m_rulesMessages .size ();
2349+ }
2350+
2351+
2352+ /* *
2353+ * @name msc_get_rules_messages_rule_ids
2354+ * @brief Copy the rule ids from Transaction::m_rulesMessages into a buffer.
2355+ *
2356+ * Copies the rule id of each RuleMessage into the caller-provided buffer.
2357+ * Only rule messages that were selected to be logged are included.
2358+ *
2359+ * The caller is expected to size the buffer using
2360+ * msc_get_rules_messages_size. If @p ids_len is smaller than the number
2361+ * of available records, only the first @p ids_len ids are written and
2362+ * the remaining records are skipped.
2363+ *
2364+ * @param transaction ModSecurity transaction.
2365+ * @param ids Caller-provided buffer to receive the rule ids.
2366+ * May be NULL only if @p ids_len is 0.
2367+ * @param ids_len Capacity of @p ids, in number of int64_t slots.
2368+ *
2369+ * @returns The number of rule ids written into @p ids.
2370+ *
2371+ */
2372+ extern " C" size_t msc_get_rules_messages_rule_ids (const Transaction *transaction,
2373+ int64_t *ids, size_t ids_len) {
2374+ if (ids == nullptr || ids_len == 0 ) {
2375+ return 0 ;
2376+ }
2377+ size_t written = 0 ;
2378+ for (const auto &msg : transaction->m_rulesMessages ) {
2379+ if (written >= ids_len) {
2380+ break ;
2381+ }
2382+ ids[written++] = msg.m_rule .m_ruleId ;
2383+ }
2384+ return written;
2385+ }
2386+
2387+
23332388} // namespace modsecurity
23342389
0 commit comments