Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update spdlog so it works with recent musls #2921

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions appsec/src/helper/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
#include <spdlog/spdlog.h>
#include <stdexcept>
#include <string>
#include <thread>

#include "action.hpp"
#include "base64.h"
#include "client.hpp"
#include "compression.hpp"
#include "exception.hpp"
#include "network/broker.hpp"
#include "network/proto.hpp"
Expand Down
28 changes: 16 additions & 12 deletions appsec/src/helper/engine_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "utils.hpp"
#include <cstdint>
#include <msgpack.hpp>
#include <ostream>
#include <spdlog/spdlog.h>
#include <string>

namespace dds {
Expand Down Expand Up @@ -71,21 +71,25 @@ struct engine_settings {
schema_extraction.sample_rate ==
oth.schema_extraction.sample_rate;
}
};

} // namespace dds

friend auto &operator<<(std::ostream &os, const engine_settings &c)
template <> struct fmt::formatter<dds::engine_settings> {
constexpr auto parse(format_parse_context &ctx) { return ctx.begin(); }

template <typename FormatContext>
auto format(const dds::engine_settings &c, FormatContext &ctx) const
{
return os << "{rules_file=" << c.rules_file
<< ", waf_timeout_us=" << c.waf_timeout_us
<< ", trace_rate_limit=" << c.trace_rate_limit
<< ", obfuscator_key_regex=" << c.obfuscator_key_regex
<< ", obfuscator_value_regex=" << c.obfuscator_value_regex
<< ", schema_extraction.enabled="
<< c.schema_extraction.enabled
<< ", schema_extraction.sample_rate=" << std::fixed
<< c.schema_extraction.sample_rate << "}";
return format_to(ctx.out(),
"{{rules_file={}, waf_timeout_us={}, trace_rate_limit={}, "
"obfuscator_key_regex={}, obfuscator_value_regex={}, "
"schema_extraction.enabled={}, schema_extraction.sample_rate={}}}",
c.rules_file, c.waf_timeout_us, c.trace_rate_limit,
c.obfuscator_key_regex, c.obfuscator_value_regex,
c.schema_extraction.enabled, c.schema_extraction.sample_rate);
}
};
} // namespace dds

namespace std {
template <> struct hash<dds::engine_settings> {
Expand Down
6 changes: 4 additions & 2 deletions appsec/src/helper/json_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <rapidjson/error/en.h>
#include <rapidjson/prettywriter.h>
#include <string_view>
#include <type_traits>

using namespace std::literals;

Expand Down Expand Up @@ -176,8 +177,9 @@ json_helper::get_field_of_type(const rapidjson::Value &parent_field,
}

if (type != output_itr->value.GetType()) {
SPDLOG_DEBUG("Field {} is not of type {}. Instead {}", key, type,
output_itr->value.GetType());
SPDLOG_DEBUG("Field {} is not of type {}. Instead {}", key,
fmt::underlying(type),
fmt::underlying(output_itr->value.GetType()));
return std::nullopt;
}

Expand Down
14 changes: 9 additions & 5 deletions appsec/src/helper/remote_config/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#include "../utils.hpp"
#include "product.hpp"
#include <spdlog/spdlog.h>
#include <string>
#include <string_view>
#include <vector>

extern "C" {
#include <sys/mman.h>
Expand Down Expand Up @@ -70,15 +70,19 @@ struct config {
{
return shm_path == b.shm_path && rc_path == b.rc_path;
}
};

} // namespace dds::remote_config

friend std::ostream &operator<<(std::ostream &os, const config &c)
template <> struct fmt::formatter<dds::remote_config::config> {
constexpr auto parse(format_parse_context &ctx) { return ctx.begin(); }

auto format(const dds::remote_config::config &c, format_context &ctx) const
{
return os << c.shm_path << ":" << c.rc_path;
return fmt::format_to(ctx.out(), "{}:{}", c.shm_path, c.rc_path);
}
};

} // namespace dds::remote_config

namespace std {
template <> struct hash<dds::remote_config::config> {
std::size_t operator()(const dds::remote_config::config &key) const
Expand Down
18 changes: 12 additions & 6 deletions appsec/src/helper/remote_config/product.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
#pragma once

#include "../config.hpp"
#include "../utils.hpp"
#include <spdlog/spdlog.h>
#include <string_view>

namespace dds::remote_config {
Expand All @@ -19,11 +19,6 @@ class product {

bool operator==(const product &other) const { return name_ == other.name_; }

friend std::ostream &operator<<(std::ostream &os, const product &p)
{
return os << p.name_;
}

private:
std::string_view name_;
};
Expand Down Expand Up @@ -56,6 +51,17 @@ struct known_products {
};
} // namespace dds::remote_config

template <>
struct fmt::formatter<dds::remote_config::product>
: fmt::formatter<std::string_view> {

auto format(const dds::remote_config::product &p, format_context &ctx) const
{
auto name = p.name();
return formatter<std::string_view>::format(name, ctx);
}
};

namespace std {
template <> struct hash<dds::remote_config::product> {
std::size_t operator()(const dds::remote_config::product &product) const
Expand Down
15 changes: 13 additions & 2 deletions appsec/src/helper/remote_config/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
#pragma once

#include "../utils.hpp"
#include <algorithm>
#include <cstdint>
#include <msgpack.hpp>
#include <ostream>
#include <spdlog/fmt/bundled/base.h>
#include <string>

namespace dds::remote_config {
Expand All @@ -32,8 +31,20 @@ struct settings {

MSGPACK_DEFINE_MAP(enabled, shmem_path);
};

} // namespace dds::remote_config

template <> struct fmt::formatter<dds::remote_config::settings> {
constexpr auto parse(fmt::format_parse_context &ctx) { return ctx.begin(); }

template <typename FormatContext>
auto format(const dds::remote_config::settings &s, FormatContext &ctx) const
{
return fmt::format_to(ctx.out(), "{{enabled={}, shmem_path={}}}",
s.enabled, s.shmem_path);
}
};

namespace std {
template <> struct hash<dds::remote_config::settings> {
std::size_t operator()(const dds::remote_config::settings &s) const noexcept
Expand Down
31 changes: 27 additions & 4 deletions appsec/src/helper/service_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,37 @@
#pragma once

#include <atomic>
#include <map>
#include <optional>
#include <spdlog/spdlog.h>
#include <unordered_map>

namespace dds {

enum class enable_asm_status : unsigned { NOT_SET = 0, ENABLED, DISABLED };
} // namespace dds

template <>
struct fmt::formatter<std::atomic<dds::enable_asm_status>>
: fmt::formatter<std::string_view> {
auto format(const std::atomic<dds::enable_asm_status> &status,
format_context &ctx) const
{
auto val = status.load();
std::string_view name{"UNKNOWN"};
switch (val) {
case dds::enable_asm_status::NOT_SET:
name = "NOT_SET";
break;
case dds::enable_asm_status::ENABLED:
name = "ENABLED";
break;
case dds::enable_asm_status::DISABLED:
name = "DISABLED";
break;
}

return fmt::formatter<std::string_view>::format(name, ctx);
}
};

namespace dds {

inline std::string_view to_string_view(enable_asm_status status)
{
Expand Down
3 changes: 2 additions & 1 deletion appsec/src/helper/subscriber/waf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ void instance::listener::call(dds::parameter_view &data, event &event)
parameter_to_json(parameter_view{res.events}),
res.total_runtime / millis);
SPDLOG_DEBUG("Waf response: code {} - actions {} - derivatives {}",
code, parameter_to_json(parameter_view{res.actions}),
fmt::underlying(code),
parameter_to_json(parameter_view{res.actions}),
parameter_to_json(parameter_view{res.derivatives}));

} else {
Expand Down
2 changes: 1 addition & 1 deletion appsec/third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ endif()
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG eb3220622e73a4889eee355ffa37972b3cac3df5)
GIT_TAG 5fd32e1a70871e2f6a52734e36bc33cb7ac022a5)
FetchContent_MakeAvailable(spdlog)
set_target_properties(spdlog PROPERTIES POSITION_INDEPENDENT_CODE 1)

Expand Down
Loading