parent
642f49a2c3
commit
8a0cc23737
@ -1,9 +1,21 @@
|
||||
package io.zhile.research.ja.netfilter.enums;
|
||||
|
||||
import io.zhile.research.ja.netfilter.rulers.*;
|
||||
|
||||
public enum RuleType {
|
||||
PREFIX,
|
||||
SUFFIX,
|
||||
KEYWORD,
|
||||
REGEXP,
|
||||
EQUAL
|
||||
PREFIX(new PrefixRuler()),
|
||||
SUFFIX(new SuffixRuler()),
|
||||
KEYWORD(new KeywordRuler()),
|
||||
REGEXP(new RegExpRuler()),
|
||||
EQUAL(new EqualRuler());
|
||||
|
||||
private final Ruler ruler;
|
||||
|
||||
RuleType(Ruler ruler) { // Lazy here. No lazy loading
|
||||
this.ruler = ruler;
|
||||
}
|
||||
|
||||
public Ruler getRuler() {
|
||||
return ruler;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
package io.zhile.research.ja.netfilter.rulers;
|
||||
|
||||
public class EqualRuler implements Ruler {
|
||||
@Override
|
||||
public boolean test(String rule, String content) {
|
||||
return content.equals(rule);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package io.zhile.research.ja.netfilter.rulers;
|
||||
|
||||
public class KeywordRuler implements Ruler {
|
||||
@Override
|
||||
public boolean test(String rule, String content) {
|
||||
return content.contains(rule);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package io.zhile.research.ja.netfilter.rulers;
|
||||
|
||||
public class PrefixRuler implements Ruler {
|
||||
@Override
|
||||
public boolean test(String rule, String content) {
|
||||
return content.startsWith(rule);
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package io.zhile.research.ja.netfilter.rulers;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class RegExpRuler implements Ruler {
|
||||
@Override
|
||||
public boolean test(String rule, String content) {
|
||||
return Pattern.matches(rule, content);
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package io.zhile.research.ja.netfilter.rulers;
|
||||
|
||||
public interface Ruler {
|
||||
default boolean test(String rule, String content) {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package io.zhile.research.ja.netfilter.rulers;
|
||||
|
||||
public class SuffixRuler implements Ruler {
|
||||
@Override
|
||||
public boolean test(String rule, String content) {
|
||||
return content.endsWith(rule);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue