forked from sippy/go-b2bua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sip_from.go
60 lines (51 loc) · 1.28 KB
/
sip_from.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
package sippy_header
import (
"github.com/egovorukhin/go-b2bua/sippy/conf"
"github.com/egovorukhin/go-b2bua/sippy/net"
)
type SipFrom struct {
compactName
*sipAddressHF
}
var sipFromName compactName = newCompactName("From", "f")
func CreateSipFrom(body string) []SipHeader {
addresses := CreateSipAddressHFs(body)
rval := make([]SipHeader, len(addresses))
for i, address := range addresses {
rval[i] = &SipFrom{
compactName: sipFromName,
sipAddressHF: address,
}
}
return rval
}
func NewSipFrom(address *SipAddress, config sippy_conf.Config) *SipFrom {
if address == nil {
address = NewSipAddress("Anonymous", NewSipURL("", /* username */
config.GetMyAddress(),
config.GetMyPort(),
false))
}
return &SipFrom{
compactName: sipFromName,
sipAddressHF: newSipAddressHF(address),
}
}
func (s *SipFrom) String() string {
return s.LocalStr(nil, false)
}
func (s *SipFrom) LocalStr(hostPort *sippy_net.HostPort, compact bool) string {
if compact {
return s.CompactName() + ": " + s.LocalStringBody(hostPort)
}
return s.Name() + ": " + s.LocalStringBody(hostPort)
}
func (s *SipFrom) GetCopy() *SipFrom {
return &SipFrom{
compactName: sipFromName,
sipAddressHF: s.sipAddressHF.getCopy(),
}
}
func (s *SipFrom) GetCopyAsIface() SipHeader {
return s.GetCopy()
}