libddwaf-src 2.1.0

Source distribution and build integration for DataDog/libddwaf
Documentation
// 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.

#pragma once

#include "action_mapper.hpp"
#include "attribute_collector.hpp"
#include "clock.hpp"
#include "memory_resource.hpp"
#include "obfuscator.hpp"
#include "object.hpp"
#include "pointer.hpp"
#include "rule.hpp"
#include <utility>
#include <vector>

namespace ddwaf {

// NOLINTBEGIN(cppcoreguidelines-avoid-const-or-ref-data-members)
struct result_components {
    borrowed_object events;
    borrowed_object actions;
    borrowed_object duration;
    borrowed_object timeout;
    borrowed_object attributes;
    borrowed_object keep;
    borrowed_object evaluated;
};
// NOLINTEND(cppcoreguidelines-avoid-const-or-ref-data-members)

class result_serializer {
public:
    explicit result_serializer(const match_obfuscator *obfuscator, const action_mapper &actions,
        nonnull_ptr<memory::memory_resource> alloc = memory::get_default_resource())
        : obfuscator_(obfuscator), actions_(actions), alloc_(alloc)
    {}

    void serialize(std::vector<rule_result> &results, attribute_collector &collector,
        const timer &deadline, result_components output);

    std::pair<owned_object, result_components> initialise_result_object();

protected:
    // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
    const match_obfuscator *obfuscator_;
    // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
    const action_mapper &actions_;

    nonnull_ptr<memory::memory_resource> alloc_;
};

} // namespace ddwaf