forked from sippy/go-b2bua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sip_rack.go
109 lines (93 loc) · 1.86 KB
/
sip_rack.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
102
103
104
105
106
107
108
109
package sippy_header
import (
"errors"
"strconv"
"github.com/egovorukhin/go-b2bua/sippy/net"
"github.com/egovorukhin/go-b2bua/sippy/utils"
)
type SipRAckBody struct {
CSeq int
RSeq int
Method string
}
type SipRAck struct {
normalName
stringBody string
body *SipRAckBody
}
func NewSipRAck(rseq, cseq int, method string) *SipRAck {
return &SipRAck{
normalName: sipRackName,
body: newSipRAckBody(rseq, cseq, method),
}
}
func newSipRAckBody(rseq, cseq int, method string) *SipRAckBody {
return &SipRAckBody{
RSeq: rseq,
CSeq: cseq,
Method: method,
}
}
var sipRackName = newNormalName("RAck")
func CreateSipRAck(body string) []SipHeader {
return []SipHeader{
&SipRAck{
normalName: sipRackName,
stringBody: body,
},
}
}
func (s *SipRAck) parse() error {
arr := sippy_utils.FieldsN(s.stringBody, 3)
if len(arr) != 3 {
return errors.New("Malformed RAck field")
}
rseq, err := strconv.Atoi(arr[0])
if err != nil {
return err
}
cseq, err := strconv.Atoi(arr[1])
if err != nil {
return err
}
s.body = &SipRAckBody{
CSeq: cseq,
RSeq: rseq,
Method: arr[2],
}
return nil
}
func (s *SipRAck) GetCopyAsIface() SipHeader {
return s.GetCopy()
}
func (s *SipRAck) GetBody() (*SipRAckBody, error) {
if s.body == nil {
if err := s.parse(); err != nil {
return nil, err
}
}
return s.body, nil
}
func (s *SipRAck) GetCopy() *SipRAck {
tmp := *s
if s.body != nil {
body := *s.body
tmp.body = &body
}
return &tmp
}
func (s *SipRAck) LocalStr(*sippy_net.HostPort, bool) string {
return s.String()
}
func (s *SipRAck) String() string {
return s.Name() + ": " + s.StringBody()
}
func (s *SipRAck) StringBody() string {
if s.body != nil {
return s.body.String()
}
return s.stringBody
}
func (s *SipRAckBody) String() string {
return strconv.Itoa(s.RSeq) + " " + strconv.Itoa(s.CSeq) + " " + s.Method
}