Skip to content

Commit

Permalink
Split builder and fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Anilm3 committed Jan 7, 2025
1 parent 185e42f commit 014f86d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
1 change: 1 addition & 0 deletions cmake/objects.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions src/builder/waf_builder.cpp
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <utility>

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
16 changes: 3 additions & 13 deletions src/builder/waf_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
3 changes: 1 addition & 2 deletions src/configuration/legacy_rule_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions src/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 014f86d

Please sign in to comment.