50 lines
1.2 KiB
C++
50 lines
1.2 KiB
C++
#ifndef RULE_ENGINE_H
|
|
#define RULE_ENGINE_H
|
|
|
|
#include "common.h"
|
|
#include <unordered_set>
|
|
#include <vector>
|
|
#include <shared_mutex>
|
|
#include <string>
|
|
|
|
class RuleEngine {
|
|
public:
|
|
RuleEngine();
|
|
~RuleEngine();
|
|
|
|
// Load rules from parsed data
|
|
bool LoadRules(const std::vector<DomainRule>& rules);
|
|
|
|
// Check if domain should be blocked (thread-safe)
|
|
FilterAction CheckDomain(const std::string& domain) const;
|
|
|
|
// Get statistics
|
|
size_t GetRuleCount() const;
|
|
|
|
// Clear all rules
|
|
void ClearRules();
|
|
|
|
private:
|
|
// Exact match rules (fastest lookup)
|
|
std::unordered_set<std::string> blocked_domains_;
|
|
std::unordered_set<std::string> allowed_domains_;
|
|
|
|
// Wildcard pattern rules
|
|
struct WildcardRule {
|
|
std::string pattern;
|
|
FilterAction action;
|
|
|
|
WildcardRule(const std::string& p, FilterAction a) : pattern(p), action(a) {}
|
|
};
|
|
std::vector<WildcardRule> wildcard_rules_;
|
|
|
|
// Thread safety
|
|
mutable std::shared_mutex rules_mutex_;
|
|
|
|
// Helper functions
|
|
bool MatchWildcard(const std::string& pattern, const std::string& domain) const;
|
|
std::string NormalizeDomain(const std::string& domain) const;
|
|
};
|
|
|
|
#endif // RULE_ENGINE_H
|