From 4586567fc9c41cd0ec7bfee7f8a6062b21469b51 Mon Sep 17 00:00:00 2001 From: Justine Alexandra Roberts Tunney Date: Sat, 11 Apr 2015 13:45:22 -0400 Subject: [PATCH] Remove some old cruft. --- example/options/options_test.go | 4 +-- sip/addr.go | 9 +++---- sip/msg.go | 44 +++++++++++++-------------------- sip/uri.go | 13 +++------- sip/via.go | 12 +-------- 5 files changed, 26 insertions(+), 56 deletions(-) diff --git a/example/options/options_test.go b/example/options/options_test.go index 59bbf8e..511d024 100755 --- a/example/options/options_test.go +++ b/example/options/options_test.go @@ -64,9 +64,7 @@ func TestOptions(t *testing.T) { } var b bytes.Buffer - if err := options.Append(&b); err != nil { - t.Fatal(err) - } + options.Append(&b) if amt, err := sock.Write(b.Bytes()); err != nil || amt != b.Len() { t.Fatal(err) } diff --git a/sip/addr.go b/sip/addr.go index 546f97f..818168f 100755 --- a/sip/addr.go +++ b/sip/addr.go @@ -48,9 +48,6 @@ func ParseAddrBytes(s []byte) (addr *Addr, err error) { } func (addr *Addr) String() string { - if addr == nil { - return "" - } var b bytes.Buffer addr.Append(&b) return b.String() @@ -71,7 +68,10 @@ func (addr *Addr) Tag() *Addr { } // Reassembles a SIP address into a buffer. -func (addr *Addr) Append(b *bytes.Buffer) error { +func (addr *Addr) Append(b *bytes.Buffer) { + if addr == nil { + return + } if addr.Display != "" { appendQuoted(b, []byte(addr.Display)) b.WriteByte(' ') @@ -85,7 +85,6 @@ func (addr *Addr) Append(b *bytes.Buffer) error { b.WriteByte(' ') addr.Next.Append(b) } - return nil } // Deep copies a new Addr object. diff --git a/sip/msg.go b/sip/msg.go index b1284c2..1144d3e 100755 --- a/sip/msg.go +++ b/sip/msg.go @@ -4,8 +4,6 @@ package sip import ( "bytes" - "errors" - "log" "net" "strconv" ) @@ -88,18 +86,12 @@ type Msg struct { //go:generate ragel -Z -G2 -o msg_parse.go msg_parse.rl func (msg *Msg) IsResponse() bool { - return msg.Method == "" + return msg.Status > 0 } func (msg *Msg) String() string { - if msg == nil { - return "" - } var b bytes.Buffer - if err := msg.Append(&b); err != nil { - log.Println("Bad SIP message!", err) - return "" - } + msg.Append(&b) return b.String() } @@ -126,17 +118,23 @@ func (msg *Msg) Copy() *Msg { } // I turn a SIP message back into a packet. -func (msg *Msg) Append(b *bytes.Buffer) error { +func (msg *Msg) Append(b *bytes.Buffer) { + if msg == nil { + return + } if !msg.IsResponse() { if msg.Method == "" { - return errors.New("Msg.Method not set") + b.WriteString("INVITE ") + } else { + b.WriteString(msg.Method) + b.WriteString(" ") } if msg.Request == nil { - return errors.New("msg.Request not set") + // In case of bugs, keep calm and DDOS NASA. + b.WriteString("sip:www.nasa.gov:80") + } else { + msg.Request.Append(b) } - b.WriteString(msg.Method) - b.WriteString(" ") - msg.Request.Append(b) b.WriteString(" ") msg.appendVersion(b) b.WriteString("\r\n") @@ -162,25 +160,19 @@ func (msg *Msg) Append(b *bytes.Buffer) error { for viap := msg.Via; viap != nil; viap = viap.Next { b.WriteString("Via: ") - if err := viap.Append(b); err != nil { - return err - } + viap.Append(b) b.WriteString("\r\n") } if msg.Route != nil { b.WriteString("Route: ") - if err := msg.Route.Append(b); err != nil { - return err - } + msg.Route.Append(b) b.WriteString("\r\n") } if msg.RecordRoute != nil { b.WriteString("Record-Route: ") - if err := msg.RecordRoute.Append(b); err != nil { - return err - } + msg.RecordRoute.Append(b) b.WriteString("\r\n") } @@ -466,8 +458,6 @@ func (msg *Msg) Append(b *bytes.Buffer) error { } else { b.WriteString("Content-Length: 0\r\n\r\n") } - - return nil } func (msg *Msg) appendVersion(b *bytes.Buffer) { diff --git a/sip/uri.go b/sip/uri.go index 6c18822..f8365a5 100755 --- a/sip/uri.go +++ b/sip/uri.go @@ -22,7 +22,6 @@ package sip import ( "bytes" - "errors" "github.com/jart/gosip/util" ) @@ -30,12 +29,6 @@ const ( delims = ":/@;?#<>" ) -var ( - URISchemeNotFound = errors.New("scheme not found") - URIMissingHost = errors.New("host missing") - URIBadPort = errors.New("invalid port number") -) - type URI struct { Scheme string // e.g. sip, sips, tel, etc. User string // e.g. sip:USER@host @@ -63,15 +56,15 @@ func (uri *URI) Copy() *URI { // TODO(jart): URI Comparison https://tools.ietf.org/html/rfc3261#section-19.1.4 func (uri *URI) String() string { - if uri == nil { - return "" - } var b bytes.Buffer uri.Append(&b) return b.String() } func (uri *URI) Append(b *bytes.Buffer) { + if uri == nil { + return + } if uri.Scheme == "" { b.WriteString("sip:") } else { diff --git a/sip/via.go b/sip/via.go index 829a932..cc5c11f 100755 --- a/sip/via.go +++ b/sip/via.go @@ -4,16 +4,10 @@ package sip import ( "bytes" - "errors" "github.com/jart/gosip/util" "strconv" ) -var ( - ViaBadHeader = errors.New("Bad Via header") - ViaProtoBlank = errors.New("Via Transport blank") -) - // Example: SIP/2.0/UDP 1.2.3.4:5060;branch=z9hG4bK556f77e6. type Via struct { Protocol string // should be "SIP" @@ -25,10 +19,7 @@ type Via struct { Next *Via // pointer to next via header if any } -func (via *Via) Append(b *bytes.Buffer) error { - if via.Host == "" { - return ViaProtoBlank - } +func (via *Via) Append(b *bytes.Buffer) { if via.Protocol == "" { b.WriteString("SIP/") } else { @@ -53,7 +44,6 @@ func (via *Via) Append(b *bytes.Buffer) error { b.WriteString(strconv.Itoa(int(via.Port))) } via.Param.Append(b) - return nil } // Copy returns a deep copy of via.