-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.cpp
More file actions
50 lines (38 loc) · 1.31 KB
/
event.cpp
File metadata and controls
50 lines (38 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// Created by amoncusir on 05/10/23.
//
#include "event.h"
#include "ubus.h"
#include <string>
#include <regex>
namespace Logtrigger
{
EventMatcher* generate_from(const Args::TriggerArgs* exec)
{
if (strcmp(exec->type, "all") == 0)
{
return new AcceptAllMatcher(exec);
}
else if (strcmp(exec->type, "regex") == 0)
{
return new RegexDataMatcher(exec);
}
throw std::runtime_error("Invalid type for matcher: " + std::string(exec->type));
}
// AcceptAllMatcher ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
AcceptAllMatcher::AcceptAllMatcher(const Args::TriggerArgs*)
{}
bool Logtrigger::AcceptAllMatcher::accept(const ubus_log_event& event) const
{
return true;
}
// RegexDataMatcher ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
RegexDataMatcher::RegexDataMatcher(const char* regex) : m_regex {regex, std::regex::ECMAScript}
{}
RegexDataMatcher::RegexDataMatcher(const Args::TriggerArgs* exec) : RegexDataMatcher(exec->matcher)
{}
bool RegexDataMatcher::accept(const ubus_log_event& event) const
{
return std::regex_match(event.data, m_regex);
}
} // Logtrigger