-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsipUser.go
68 lines (61 loc) · 908 Bytes
/
sipUser.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
package sipanonymizer
import (
"bytes"
)
/*
192.168.192.10
8.8.8.8
domain.com
sip.domain.com
*/
// processUser hides most part in the username like:
// Joh* **e or 123***
// 123*5
// 123**6
// 123***7
// ...
func processUser(v []byte) int {
if len(v) == 0 {
return 0
}
pos := 0
if v[pos] == '"' {
pos = 1
}
userLen := bytes.IndexAny(v[pos:], userEnd) + pos
if userLen < 0 {
userLen = len(v)
}
preserveFirst := 0
preserveLastPos := -1
if userLen > 1 && userLen < 5 {
// 1*
// 1**
// 1***
preserveFirst = 1
preserveLastPos = -1
} else if userLen >= 5 {
// 123*5
// 123**6
// 123***7
// ...
preserveFirst = 3
preserveLastPos = userLen - 1
}
for pos < userLen {
if v[pos] == ' ' {
pos++
continue
}
if preserveFirst != 0 {
preserveFirst--
pos++
continue
}
if pos != preserveLastPos {
v[pos] = maskChar
}
pos++
}
return userLen
}