From 014f86d70c37d1709dd5410dd60d4ec814be2fc8 Mon Sep 17 00:00:00 2001 From: Anil Mahtani <929854+Anilm3@users.noreply.github.com> Date: Tue, 7 Jan 2025 20:04:05 +0000 Subject: [PATCH] Split builder and fix lint --- cmake/objects.cmake | 1 + src/builder/waf_builder.cpp | 32 ++++++++++++++++++++++++ src/builder/waf_builder.hpp | 16 +++--------- src/configuration/legacy_rule_parser.cpp | 3 +-- src/interface.cpp | 1 + 5 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 src/builder/waf_builder.cpp diff --git a/cmake/objects.cmake b/cmake/objects.cmake index 1a9e66f8..6d3dc1bb 100644 --- a/cmake/objects.cmake +++ b/cmake/objects.cmake @@ -24,6 +24,7 @@ set(LIBDDWAF_SOURCE ${libddwaf_SOURCE_DIR}/src/builder/module_builder.cpp ${libddwaf_SOURCE_DIR}/src/builder/processor_builder.cpp ${libddwaf_SOURCE_DIR}/src/builder/ruleset_builder.cpp + ${libddwaf_SOURCE_DIR}/src/builder/waf_builder.cpp ${libddwaf_SOURCE_DIR}/src/tokenizer/sql_base.cpp ${libddwaf_SOURCE_DIR}/src/tokenizer/pgsql.cpp ${libddwaf_SOURCE_DIR}/src/tokenizer/mysql.cpp diff --git a/src/builder/waf_builder.cpp b/src/builder/waf_builder.cpp new file mode 100644 index 00000000..7addda0c --- /dev/null +++ b/src/builder/waf_builder.cpp @@ -0,0 +1,32 @@ +// Unless explicitly stated otherwise all files in this repository are +// dual-licensed under the Apache-2.0 License or BSD-3-Clause License. +// +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2021 Datadog, Inc. + +#include "builder/waf_builder.hpp" +#include "configuration/manager.hpp" +#include "parameter.hpp" +#include "ruleset_info.hpp" +#include "waf.hpp" +#include +#include + +namespace ddwaf { + +bool waf_builder::add_or_update( + const std::string &path, parameter::map &root, base_ruleset_info &info) +{ + return cfg_mgr_.add_or_update(path, root, info); +} + +bool waf_builder::remove(const std::string &path) { return cfg_mgr_.remove(path); } + +ddwaf::waf waf_builder::build() +{ + auto config = cfg_mgr_.consolidate(); + auto ruleset = rbuilder_.build(config); + return waf{std::move(ruleset)}; +} + +} // namespace ddwaf diff --git a/src/builder/waf_builder.hpp b/src/builder/waf_builder.hpp index 954375ba..481d8407 100644 --- a/src/builder/waf_builder.hpp +++ b/src/builder/waf_builder.hpp @@ -28,19 +28,9 @@ class waf_builder { waf_builder &operator=(waf_builder &&) = delete; waf_builder &operator=(const waf_builder &) = delete; - bool add_or_update(const std::string &path, parameter::map &root, base_ruleset_info &info) - { - return cfg_mgr_.add_or_update(path, root, info); - } - - bool remove(const std::string &path) { return cfg_mgr_.remove(path); } - - ddwaf::waf build() - { - auto config = cfg_mgr_.consolidate(); - auto ruleset = rbuilder_.build(config); - return waf{std::move(ruleset)}; - } + bool add_or_update(const std::string &path, parameter::map &root, base_ruleset_info &info); + bool remove(const std::string &path); + ddwaf::waf build(); protected: configuration_manager cfg_mgr_; diff --git a/src/configuration/legacy_rule_parser.cpp b/src/configuration/legacy_rule_parser.cpp index fe8919c7..acef532d 100644 --- a/src/configuration/legacy_rule_parser.cpp +++ b/src/configuration/legacy_rule_parser.cpp @@ -31,8 +31,7 @@ #include "matcher/regex_match.hpp" #include "parameter.hpp" #include "rule.hpp" -#include "ruleset.hpp" -#include "ruleset_info.hpp" +#include "target_address.hpp" #include "transformer/base.hpp" #include "utils.hpp" diff --git a/src/interface.cpp b/src/interface.cpp index 0bf7d639..9e30db5c 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -281,6 +281,7 @@ ddwaf_builder ddwaf_builder_init(const ddwaf_config *config) } bool ddwaf_builder_add_or_update_config(ddwaf::waf_builder *builder, const char *path, + // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) uint32_t path_len, ddwaf_object *config, ddwaf_object *diagnostics) { if (builder == nullptr) {