-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrules.go
92 lines (83 loc) · 2.05 KB
/
rules.go
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// RoutingA:
// https://github.com/v2rayA/RoutingA
// Use of this source code is governed by MIT license that can be found in the LICENSE file.
package RoutingA
import "strings"
/*
inbound: httpauthin = http(address: 0.0.0.0, port: 1080, user: 'my-username', pass: 'my-password', user: 'my-username2', pass: 'my-password2')
outbound: httpout = http(address: 127.0.0.1, port: 8080, user: 'my-username', pass: 'my-password')
default: proxy
*/
type Define struct {
Name string
Value interface{}
}
func newDefine(s symbol) (d *Define) {
if s.sym != 'B' || !symMatch(s.children, []rune("D:E")) {
return nil
}
E := s.children[2]
d = new(Define)
d.Name = s.children[0].val
switch {
case symMatch(E.children, []rune("D=F")):
d.Value = *newBound(E)
case symMatch(E.children, []rune("D")):
d.Value = E.children[0].val
default:
return nil
}
return
}
/*
httpauthin = http(address: 0.0.0.0, port: 1080, user: 'my-username', pass: 'my-password')
httpout = http(address: 127.0.0.1, port: 8080, user: 'my-username', pass: 'my-password')
*/
type Bound struct {
Name string
Value Function
}
func newBound(s symbol) (o *Bound) {
if s.sym != 'E' || !symMatch(s.children, []rune("D=F")) {
return nil
}
o = new(Bound)
o.Name = strings.TrimSpace(s.children[0].val)
o.Value = *newFunction(s.children[2])
return
}
/*
http(address: 127.0.0.1, port: 8080, user: 'my-username', pass: 'my-password')
*/
type Function struct {
Name string
Params []string
NamedParams map[string][]string
}
func newFunction(s symbol) (f *Function) {
if s.sym != 'F' {
return nil
}
f = new(Function)
f.Name = s.children[0].val
G := s.children[2]
f.Params, f.NamedParams = parseG(G)
return
}
/*
domain(domain: v2raya.mzz.pub) -> socksout
*/
type Routing struct {
And []Function
Out string
}
func newRouting(s symbol) (r *Routing) {
if s.sym != 'C' || !symMatch(s.children, []rune("FQ->D")) {
return nil
}
r = new(Routing)
r.Out = strings.TrimSpace(s.children[4].val)
r.And = append(r.And, *newFunction(s.children[0]))
r.And = append(r.And, parseQ(s.children[1])...)
return
}