Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
biglittlebigben committed Oct 29, 2024
1 parent 1b3d68d commit 0a906a8
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions pkg/sip/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const (
type URI struct {
User string
Host string
Port uint16
Addr netip.AddrPort
Transport Transport
}
Expand All @@ -85,7 +86,7 @@ func CreateURIFromUserAndAddress(user string, address string, transport Transpor
Transport: transport,
}

uri.Normalize()
uri = uri.Normalize()

return uri
}
Expand All @@ -94,7 +95,17 @@ func (u URI) Normalize() URI {
if addr, sport, err := net.SplitHostPort(u.Host); err == nil {
if port, err := strconv.Atoi(sport); err == nil {
u.Host = addr
u.Addr = netip.AddrPortFrom(u.Addr.Addr(), uint16(port))
u.Port = uint16(port) // Store the port separately in case the AddrPort is not valid

if !u.Addr.IsValid() {
// Attempt to parse host as AddrPort
naddr, err := netip.ParseAddr(u.Host)
if err == nil {
u.Addr = netip.AddrPortFrom(naddr, uint16(port))
}
} else {
u.Addr = netip.AddrPortFrom(u.Addr.Addr(), uint16(port))
}
}
}
return u
Expand All @@ -109,7 +120,10 @@ func (u URI) GetHost() string {
}

func (u URI) GetPort() int {
port := int(u.Addr.Port())
port = int(u.Port)

Check failure on line 123 in pkg/sip/types.go

View workflow job for this annotation

GitHub Actions / test

undefined: port

Check failure on line 123 in pkg/sip/types.go

View workflow job for this annotation

GitHub Actions / test

undefined: port
if port == 0 {

Check failure on line 124 in pkg/sip/types.go

View workflow job for this annotation

GitHub Actions / test

undefined: port

Check failure on line 124 in pkg/sip/types.go

View workflow job for this annotation

GitHub Actions / test

undefined: port
port := int(u.Addr.Port())

Check failure on line 125 in pkg/sip/types.go

View workflow job for this annotation

GitHub Actions / test

declared and not used: port

Check failure on line 125 in pkg/sip/types.go

View workflow job for this annotation

GitHub Actions / test

declared and not used: port
}
if port == 0 {

Check failure on line 127 in pkg/sip/types.go

View workflow job for this annotation

GitHub Actions / test

undefined: port

Check failure on line 127 in pkg/sip/types.go

View workflow job for this annotation

GitHub Actions / test

undefined: port
port = 5060

Check failure on line 128 in pkg/sip/types.go

View workflow job for this annotation

GitHub Actions / test

undefined: port
}
Expand Down Expand Up @@ -142,7 +156,7 @@ func (u URI) GetURI() *sip.Uri {
User: u.User,
Host: u.GetHost(),
}
if port := u.Addr.Port(); port != 0 {
if port := u.GetPortOrNone(); port != 0 {
su.Port = int(port)
}
if u.Transport != "" {
Expand Down

0 comments on commit 0a906a8

Please sign in to comment.