-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsipUrl.go
101 lines (91 loc) · 1.88 KB
/
sipUrl.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
93
94
95
96
97
98
99
100
101
package sipanonymizer
import (
"bytes"
)
/*
RFC 3261 - https://www.ietf.org/rfc/rfc3261.txt
"John Doe" <sip:[email protected]>;tag=bvbvfhehj
John <sip:[email protected]>;tag=bvbvfhehj
sip:[email protected];tag=bvbvfhehj
sip:[email protected];tag=bvbvfhehj
*/
// processSipURL hides user's personal data in SIP URL
func processSipURL(v []byte) {
pos := 0
state := FieldBase
atPos := getIndexSep(v, '@')
pinholePos := bytes.Index(v, pinholeBytes)
schemePos := bytes.Index(v, sipBytes)
schemeLen := 4
if schemePos < 0 {
schemePos = bytes.Index(v, sipsBytes)
schemeLen = 5
if schemePos < 0 {
schemePos = bytes.Index(v, telBytes)
schemeLen = 4
}
}
// Loop through the bytes making up the line
vLen := len(v)
for pos < vLen {
// FSM
switch state {
case FieldBase:
if v[pos] == '"' && pos == 0 {
state = FieldNameQ
pos++
continue
}
// Not a space so check for uri types
if pos == schemePos {
pos = pos + schemeLen
if atPos < 0 {
// there is no user part
pos = pos + processHost(v[pos+1:])
if pinholePos > 0 {
// pinhole=UDP:
// len("pinhole=") = 8
pos = pinholePos + 8 + 4
processHost(v[pos:])
}
return
}
state = FieldUser
continue
}
// Check for other chrs
if v[pos] != '<' && v[pos] != '>' && v[pos] != ';' {
state = FieldName
continue
}
case FieldNameQ:
if v[pos] == '"' {
state = FieldName
pos++
continue
}
// hide displayName
pos = pos + processUser(v[pos:])
continue
case FieldName:
if v[pos] == '<' || v[pos] == ' ' {
state = FieldBase
pos++
continue
}
// hide displayName
pos = pos + processUser(v[pos:])
continue
case FieldUser:
if pos == atPos {
pos++
processHost(v[pos:])
return
}
// hide displayName
pos = pos + processUser(v[pos:])
continue
}
pos++
}
}