-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathsipCseq.go
56 lines (43 loc) · 1009 Bytes
/
sipCseq.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
package siprocket
/*
RFC 3261 - https://www.ietf.org/rfc/rfc3261.txt - 8.1.1.5 CSeq
The CSeq header field serves as a way to identify and order
transactions. It consists of a sequence number and a method. The
method MUST match that of the request.
Example:
CSeq: 4711 INVITE
*/
type sipCseq struct {
Id []byte // Cseq ID
Method []byte // Cseq Method
Src []byte // Full source if needed
}
func parseSipCseq(v []byte, out *sipCseq) {
pos := 0
state := FIELD_ID
// Init the output area
out.Id = nil
out.Method = nil
out.Src = nil
// Keep the source line if needed
if keep_src {
out.Src = v
}
// Loop through the bytes making up the line
for pos < len(v) {
// FSM
//fmt.Println("POS:", pos, "CHR:", string(v[pos]), "STATE:", state)
switch state {
case FIELD_ID:
if v[pos] == ' ' {
state = FIELD_METHOD
pos++
continue
}
out.Id = append(out.Id, v[pos])
case FIELD_METHOD:
out.Method = append(out.Method, v[pos])
}
pos++
}
}