Skip to content

Commit

Permalink
update: use route header to set dstination
Browse files Browse the repository at this point in the history
  • Loading branch information
sreeram-narayanan committed Dec 13, 2022
1 parent 138f3a8 commit c389f6d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 37 deletions.
15 changes: 0 additions & 15 deletions sip/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ type Message interface {
SetSource(src string)
Destination() string
SetDestination(dest string)
Proxy() string
SetProxy(proxy string)

IsCancel() bool
IsAck() bool
Expand Down Expand Up @@ -417,7 +415,6 @@ type message struct {
startLine func() string
tp string
src string
proxy string
dest string
fields log.Fields
}
Expand Down Expand Up @@ -526,18 +523,6 @@ func (msg *message) SetDestination(dest string) {
msg.mu.Unlock()
}

func (msg *message) Proxy() string {
msg.mu.RLock()
defer msg.mu.RUnlock()
return msg.proxy
}

func (msg *message) SetProxy(proxy string) {
msg.mu.Lock()
msg.proxy = proxy
msg.mu.Unlock()
}

// Copy all headers of one type from one message to another.
// Appending to any headers that were already there.
func CopyHeaders(name string, from, to Message) {
Expand Down
13 changes: 5 additions & 8 deletions sip/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,23 +224,20 @@ func (req *request) Source() string {
return fmt.Sprintf("%v:%v", host, port)
}

func (req *request) Proxy() string {
return req.message.Proxy()
}

func (req *request) Destination() string {
if dest := req.message.Destination(); dest != "" {
return dest
}

var uri *SipUri
if hdrs := req.GetHeaders("Route"); len(hdrs) > 0 {
routeHeader, ok := hdrs[0].(*RouteHeader)
if ok && len(routeHeader.Addresses) > 0 {
uri = routeHeader.Addresses[0].(*SipUri)
}
}

if uri == nil {
if dest := req.message.Destination(); dest != "" {
return dest
}

if u, ok := req.Recipient().(*SipUri); ok {
uri = u
} else {
Expand Down
16 changes: 2 additions & 14 deletions transport/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,7 @@ func (tpl *layer) Send(msg sip.Message) error {
}
}

var dest string

if msg.Proxy() != "" {
dest = msg.Proxy()
} else {
dest = msg.Destination()
}
dest := msg.Destination()

target, err := NewTargetFromAddr(dest)
if err != nil {
Expand Down Expand Up @@ -323,13 +317,7 @@ func (tpl *layer) Send(msg sip.Message) error {
return UnsupportedProtocolError(fmt.Sprintf("protocol %s is not supported", viaHop.Transport))
}

var dest string

if msg.Proxy() != "" {
dest = msg.Proxy()
} else {
dest = msg.Destination()
}
dest := msg.Destination()

target, err := NewTargetFromAddr(dest)
if err != nil {
Expand Down

0 comments on commit c389f6d

Please sign in to comment.