Skip to content

Commit

Permalink
add sort filters option to maintain binary search property
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperlarson committed Sep 2, 2024
1 parent 342a505 commit 2053247
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion include/forti_api/dns_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ struct Filter {
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Filter, id, q_origin_key, category, action, log)
};

struct CompareFilters { bool operator()(const Filter& a, const Filter& b) { return a.category < b.category; } };

struct DNSFilterOptions {
std::string options;
std::vector<Filter> filters;
Expand Down Expand Up @@ -65,6 +67,8 @@ struct DNSFilterOptions {
if (match_found) filters[index].action = "monitor";
else filters.emplace_back(category, "monitor");
}

void sort_filters() { std::sort(filters.begin(), filters.end(), CompareFilters()); }
};

struct DomainFilter {
Expand Down Expand Up @@ -125,8 +129,9 @@ class DNSFilter {
inline static std::string api_endpoint = "/cmdb/dnsfilter/profile";

public:
static void update(const DNSProfile& profile) {
static void update(DNSProfile& profile) {
if (!contains(profile.name)) throw std::runtime_error("Can't update non-existent DNS Profile");
profile.ftgd_dns.sort_filters();
FortiAPI::put(std::format("{}/{}", api_endpoint, profile.name), profile);
}

Expand Down

0 comments on commit 2053247

Please sign in to comment.