MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Init

Method Init

internal/waf/rule.go:69–229  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

67}
68
69func (this *Rule) Init() error {
70 // operator
71 switch this.Operator {
72 case RuleOperatorGt:
73 this.floatValue = types.Float64(this.Value)
74 case RuleOperatorGte:
75 this.floatValue = types.Float64(this.Value)
76 case RuleOperatorLt:
77 this.floatValue = types.Float64(this.Value)
78 case RuleOperatorLte:
79 this.floatValue = types.Float64(this.Value)
80 case RuleOperatorEq:
81 this.floatValue = types.Float64(this.Value)
82 case RuleOperatorNeq:
83 this.floatValue = types.Float64(this.Value)
84 case RuleOperatorContainsAny, RuleOperatorContainsAll, RuleOperatorContainsAnyWord, RuleOperatorContainsAllWords, RuleOperatorNotContainsAnyWord:
85 this.stringValues = []string{}
86 if len(this.Value) > 0 {
87 var lines = strings.Split(this.Value, "\n")
88 for _, line := range lines {
89 line = strings.TrimSpace(line)
90 if len(line) > 0 {
91 if this.IsCaseInsensitive {
92 this.stringValues = append(this.stringValues, strings.ToLower(line))
93 } else {
94 this.stringValues = append(this.stringValues, line)
95 }
96 }
97 }
98 if this.Operator == RuleOperatorContainsAnyWord || this.Operator == RuleOperatorContainsAllWords || this.Operator == RuleOperatorNotContainsAnyWord {
99 sort.Strings(this.stringValues)
100 }
101
102 this.stringValueRunes = [][]rune{}
103 for _, line := range this.stringValues {
104 this.stringValueRunes = append(this.stringValueRunes, []rune(line))
105 }
106 }
107 case RuleOperatorMatch:
108 var v = this.Value
109 if this.IsCaseInsensitive && !strings.HasPrefix(v, "(?i)") {
110 v = "(?i)" + v
111 }
112
113 v = this.unescape(v)
114
115 reg, err := re.Compile(v)
116 if err != nil {
117 return err
118 }
119 this.reg = reg
120 case RuleOperatorNotMatch:
121 var v = this.Value
122 if this.IsCaseInsensitive && !strings.HasPrefix(v, "(?i)") {
123 v = "(?i)" + v
124 }
125
126 v = this.unescape(v)

Callers 6

TestRule_Init_SingleFunction · 0.95
TestRule_Init_CompositeFunction · 0.95
TestRule_MatchStarFunction · 0.95
TestRule_VersionFunction · 0.95
TestRule_IPFunction · 0.95

Calls 10

unescapeMethod · 0.95
CompileFunction · 0.92
ParseStringListFunction · 0.92
ParseIPRangeListFunction · 0.92
FindCheckpointFunction · 0.92
ParseIPMethod · 0.80
MatchStringMethod · 0.80
PriorityMethod · 0.65
CacheLifeMethod · 0.65
InitMethod · 0.65

Tested by 6

TestRule_Init_SingleFunction · 0.76
TestRule_Init_CompositeFunction · 0.76
TestRule_MatchStarFunction · 0.76
TestRule_VersionFunction · 0.76
TestRule_IPFunction · 0.76