Skip to main content

relay_core_lib/rule/engine/
compiled.rs

1use crate::rule::Rule;
2use glob::Pattern;
3use ipnetwork::IpNetwork;
4use regex::Regex;
5
6#[derive(Debug)]
7pub struct CompiledRule {
8    pub original: Rule,
9    pub filter: CompiledFilter,
10}
11
12#[derive(Debug, Clone)]
13pub enum CompiledFilter {
14    All,
15    SrcIp(IpNetwork),
16    DstPort(u16),
17    Protocol(String),
18    TransparentMode(bool),
19    Url(CompiledStringMatcher),
20    Host(CompiledStringMatcher),
21    Path(CompiledStringMatcher),
22    Method(CompiledStringMatcher),
23    RequestHeader {
24        name: String,
25        value: Option<CompiledStringMatcher>,
26    },
27    ResponseHeader {
28        name: String,
29        value: Option<CompiledStringMatcher>,
30    },
31    StatusCode(u16),
32    ResponseBody(CompiledStringMatcher),
33    WebSocketMessage(CompiledStringMatcher),
34    And(Vec<CompiledFilter>),
35    Or(Vec<CompiledFilter>),
36    Not(Box<CompiledFilter>),
37    Invalid, // Fallback for compilation errors
38}
39
40#[derive(Debug, Clone)]
41pub enum CompiledStringMatcher {
42    Exact(String),
43    Contains(String),
44    Prefix(String),
45    Suffix(String),
46    Regex(Regex),
47    Glob(Pattern),
48    Invalid,
49}