Browse Source

Move dialog handling into own package

Fix some linter warnings
gofuzz^2
negbie 6 years ago
parent
commit
80e84b2900
51 changed files with 531 additions and 467 deletions
  1. +73
    -64
      dialog/dialog.go
  2. +28
    -26
      dialog/messages.go
  3. +24
    -10
      dialog/receiver.go
  4. +19
    -10
      dialog/route.go
  5. +5
    -5
      dialog/trace.go
  6. +21
    -14
      dialog/transport.go
  7. +30
    -0
      dialog/util.go
  8. +3
    -3
      dsp/awgn.go
  9. +5
    -4
      dsp/awgn_test.go
  10. +3
    -3
      dsp/dsp.go
  11. +5
    -4
      dsp/dsp_test.go
  12. +8
    -7
      example/echo/echo_test.go
  13. +15
    -13
      example/echo2/echo2_test.go
  14. +11
    -9
      example/echo3/echo3_test.go
  15. +6
    -5
      example/options/options_test.go
  16. +5
    -4
      example/rawsip/rawsip_test.go
  17. +13
    -11
      fone/main.go
  18. +3
    -3
      rtp/dtmf.go
  19. +3
    -3
      rtp/rtp.go
  20. +6
    -5
      rtp/session.go
  21. +3
    -3
      rtp/session_test.go
  22. +3
    -3
      sdp/codec.go
  23. +27
    -27
      sdp/codecs.go
  24. +3
    -3
      sdp/media.go
  25. +4
    -3
      sdp/origin.go
  26. +38
    -37
      sdp/sdp_test.go
  27. +4
    -3
      sip/addr.go
  28. +16
    -15
      sip/addr_test.go
  29. +3
    -3
      sip/charsets.go
  30. +3
    -3
      sip/charsets_test.go
  31. +3
    -3
      sip/errors.go
  32. +3
    -3
      sip/escape.go
  33. +7
    -11
      sip/escape_test.go
  34. +3
    -3
      sip/method.go
  35. +3
    -3
      sip/msg.go
  36. +40
    -39
      sip/msg_test.go
  37. +3
    -3
      sip/msgerror.go
  38. +3
    -3
      sip/param.go
  39. +3
    -3
      sip/payload.go
  40. +3
    -3
      sip/prefs.go
  41. +3
    -3
      sip/quote.go
  42. +10
    -17
      sip/quote_test.go
  43. +3
    -3
      sip/status.go
  44. +5
    -4
      sip/uri.go
  45. +25
    -24
      sip/uri_test.go
  46. +3
    -3
      sip/uriheader.go
  47. +3
    -3
      sip/uriparam.go
  48. +3
    -23
      sip/util.go
  49. +5
    -4
      sip/via.go
  50. +3
    -3
      sip/xheader.go
  51. +7
    -3
      util/util.go

sip/dialog.go → dialog/dialog.go View File


sip/messages.go → dialog/messages.go View File


sip/receiver.go → dialog/receiver.go View File


sip/route.go → dialog/route.go View File


sip/trace.go → dialog/trace.go View File


sip/transport.go → dialog/transport.go View File


+ 30
- 0
dialog/util.go View File

@ -0,0 +1,30 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package dialog
import (
"time"
)
func duration(ms *int) time.Duration {
return time.Duration(*ms) * time.Millisecond
}
func or5060(port uint16) uint16 {
if port == 0 {
return 5060
}
return port
}

+ 3
- 3
dsp/awgn.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 5
- 4
dsp/awgn_test.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -15,8 +15,9 @@
package dsp_test
import (
"github.com/jart/gosip/dsp"
"testing"
"github.com/jart/gosip/dsp"
)
func TestAWGN(t *testing.T) {


+ 3
- 3
dsp/dsp.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 5
- 4
dsp/dsp_test.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -15,8 +15,9 @@
package dsp_test
import (
"github.com/jart/gosip/dsp"
"testing"
"github.com/jart/gosip/dsp"
)
func TestL16MixSat160(t *testing.T) {


+ 8
- 7
example/echo/echo_test.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -147,15 +147,16 @@ package echo_test
import (
"bytes"
"github.com/jart/gosip/rtp"
"github.com/jart/gosip/sdp"
"github.com/jart/gosip/sip"
"github.com/jart/gosip/util"
"log"
"math/rand"
"net"
"testing"
"time"
"github.com/jart/gosip/rtp"
"github.com/jart/gosip/sdp"
"github.com/jart/gosip/sip"
"github.com/jart/gosip/util"
)
func TestCallToEchoApp(t *testing.T) {


+ 15
- 13
example/echo2/echo2_test.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -17,14 +17,16 @@
package echo2_test
import (
"github.com/jart/gosip/dsp"
"github.com/jart/gosip/rtp"
"github.com/jart/gosip/sdp"
"github.com/jart/gosip/sip"
"log"
"net"
"testing"
"time"
"github.com/jart/gosip/dialog"
"github.com/jart/gosip/dsp"
"github.com/jart/gosip/rtp"
"github.com/jart/gosip/sdp"
"github.com/jart/gosip/sip"
)
func TestCallToEchoApp(t *testing.T) {
@ -40,14 +42,14 @@ func TestCallToEchoApp(t *testing.T) {
rtpaddr := rs.Sock.LocalAddr().(*net.UDPAddr)
// Create the SIP UDP transport layer.
tp, err := sip.NewTransport(from)
tp, err := dialog.NewTransport(from)
if err != nil {
t.Fatal(err)
}
defer tp.Sock.Close()
// Send an INVITE message with an SDP media session description.
invite := sip.NewRequest(tp, sip.MethodInvite, to, from)
invite := dialog.NewRequest(tp, sip.MethodInvite, to, from)
invite.Payload = sdp.New(rtpaddr, sdp.ULAWCodec, sdp.DTMFCodec)
err = tp.Send(invite)
if err != nil {
@ -91,7 +93,7 @@ loop:
case msg = <-tp.C:
if msg.IsResponse() {
if msg.Status >= sip.StatusOK && msg.CSeq == invite.CSeq {
err = tp.Send(sip.NewAck(msg, invite))
err = tp.Send(dialog.NewAck(msg, invite))
if err != nil {
t.Fatal("SIP send failed:", err)
}
@ -129,7 +131,7 @@ loop:
} else {
if msg.Method == "BYE" {
log.Printf("Remote Hangup!")
err = tp.Send(sip.NewResponse(invite, sip.StatusOK))
err = tp.Send(dialog.NewResponse(invite, sip.StatusOK))
if err != nil {
t.Fatal("SIP send failed:", err)
}
@ -148,9 +150,9 @@ loop:
resendTimer = time.After(resendInterval)
case <-deathTimer:
if answered {
resend = sip.NewBye(invite, msg, nil)
resend = dialog.NewBye(invite, msg, nil)
} else {
resend = sip.NewCancel(invite)
resend = dialog.NewCancel(invite)
}
err = tp.Send(resend)
if err != nil {


+ 11
- 9
example/echo3/echo3_test.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -17,14 +17,16 @@
package echo3_test
import (
"net"
"testing"
"time"
"github.com/jart/gosip/dialog"
"github.com/jart/gosip/dsp"
"github.com/jart/gosip/rtp"
"github.com/jart/gosip/sdp"
"github.com/jart/gosip/sip"
"github.com/jart/gosip/util"
"net"
"testing"
"time"
)
func TestCallToEchoApp(t *testing.T) {
@ -49,7 +51,7 @@ func TestCallToEchoApp(t *testing.T) {
}
// Create a SIP phone call.
dl, err := sip.NewDialog(invite)
dl, err := dialog.NewDialog(invite)
if err != nil {
t.Fatal(err)
}
@ -79,9 +81,9 @@ func TestCallToEchoApp(t *testing.T) {
return
case state := <-dl.OnState:
switch state {
case sip.DialogAnswered:
case dialog.Answered:
answered = true
case sip.DialogHangup:
case dialog.Hangup:
if !answered {
t.Error("Call didn't get answered!")
}


+ 6
- 5
example/options/options_test.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -18,11 +18,12 @@ package options_test
import (
"bytes"
"github.com/jart/gosip/sip"
"github.com/jart/gosip/util"
"net"
"testing"
"time"
"github.com/jart/gosip/sip"
"github.com/jart/gosip/util"
)
func TestOptions(t *testing.T) {


+ 5
- 4
example/rawsip/rawsip_test.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -18,12 +18,13 @@
package rawsip_test
import (
"github.com/jart/gosip/util"
"net"
"strconv"
"strings"
"testing"
"time"
"github.com/jart/gosip/util"
)
// An 'OPTIONS' message is used to:


+ 13
- 11
fone/main.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -25,11 +25,6 @@ import (
"errors"
"flag"
"fmt"
"github.com/jart/gosip/dsp"
"github.com/jart/gosip/rtp"
"github.com/jart/gosip/sdp"
"github.com/jart/gosip/sip"
"github.com/jart/gosip/util"
"io/ioutil"
"log"
"net"
@ -38,6 +33,13 @@ import (
"os/signal"
"time"
"unsafe"
"github.com/jart/gosip/dialog"
"github.com/jart/gosip/dsp"
"github.com/jart/gosip/rtp"
"github.com/jart/gosip/sdp"
"github.com/jart/gosip/sip"
"github.com/jart/gosip/util"
)
const (
@ -132,7 +134,7 @@ func main() {
}
// Create SIP Dialog State Machine
dl, err := sip.NewDialog(invite)
dl, err := dialog.NewDialog(invite)
if err != nil {
panic(err)
}
@ -213,10 +215,10 @@ func main() {
case rs.Peer = <-dl.OnPeer:
case state := <-dl.OnState:
switch state {
case sip.DialogAnswered:
case dialog.Answered:
answered = true
keyboardStart()
case sip.DialogHangup:
case dialog.Hangup:
if answered {
return
} else {


+ 3
- 3
rtp/dtmf.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 3
- 3
rtp/rtp.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 6
- 5
rtp/session.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -18,13 +18,14 @@ package rtp
import (
"errors"
"github.com/jart/gosip/dsp"
"github.com/jart/gosip/sdp"
"log"
"math/rand"
"net"
"strconv"
"strings"
"github.com/jart/gosip/dsp"
"github.com/jart/gosip/sdp"
)
const (


+ 3
- 3
rtp/session_test.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 3
- 3
sdp/codec.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 27
- 27
sdp/codecs.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -38,29 +38,29 @@ var (
Opus = Codec{PT: 111, Name: "opus", Rate: 48000, Param: "2"}
StandardCodecs = map[uint8]Codec{
0: ULAWCodec, // G.711 μ-Law is the de-facto codec (SpanDSP g711.h)
3: Codec{PT: 3, Name: "GSM", Rate: 8000}, // Uncool codec asterisk ppl like (SpanDSP gsm0610.h)
4: Codec{PT: 4, Name: "G723", Rate: 8000}, // Worthless.
5: Codec{PT: 5, Name: "DVI4", Rate: 8000}, // Adaptive pulse code modulation (SpanDSP ima_adpcm.h)
6: Codec{PT: 6, Name: "DVI4", Rate: 16000}, // Adaptive pulse code modulation 16khz (SpanDSP ima_adpcm.h)
7: Codec{PT: 7, Name: "LPC", Rate: 8000}, // Chat with your friends ww2 field marshall style (SpanDSP lpc10.h)
8: Codec{PT: 8, Name: "PCMA", Rate: 8000}, // G.711 variant of μ-Law used in yurop (SpanDSP g711.h)
9: Codec{PT: 9, Name: "G722", Rate: 8000}, // Used for Polycom HD Voice; Rate actually 16khz LOL (SpanDSP g722.h)
10: Codec{PT: 10, Name: "L16", Rate: 44100, Param: "2"}, // 16-bit signed PCM stereo/mono (mind your MTU; adjust ptime)
11: Codec{PT: 11, Name: "L16", Rate: 44100},
12: Codec{PT: 12, Name: "QCELP", Rate: 8000},
13: Codec{PT: 13, Name: "CN", Rate: 8000}, // RFC3389 comfort noise
14: Codec{PT: 14, Name: "MPA", Rate: 90000},
15: Codec{PT: 15, Name: "G728", Rate: 8000},
16: Codec{PT: 16, Name: "DVI4", Rate: 11025},
17: Codec{PT: 17, Name: "DVI4", Rate: 22050},
18: Codec{PT: 18, Name: "G729", Rate: 8000}, // Best telephone voice codec (if you got $10 bucks)
25: Codec{PT: 25, Name: "CelB", Rate: 90000},
26: Codec{PT: 26, Name: "JPEG", Rate: 90000},
28: Codec{PT: 28, Name: "nv", Rate: 90000},
31: Codec{PT: 31, Name: "H261", Rate: 90000}, // RFC4587 Video
32: Codec{PT: 32, Name: "MPV", Rate: 90000},
33: Codec{PT: 33, Name: "MP2T", Rate: 90000},
34: Codec{PT: 34, Name: "H263", Rate: 90000}, // $$$ video
0: ULAWCodec, // G.711 μ-Law is the de-facto codec (SpanDSP g711.h)
3: {PT: 3, Name: "GSM", Rate: 8000}, // Uncool codec asterisk ppl like (SpanDSP gsm0610.h)
4: {PT: 4, Name: "G723", Rate: 8000}, // Worthless.
5: {PT: 5, Name: "DVI4", Rate: 8000}, // Adaptive pulse code modulation (SpanDSP ima_adpcm.h)
6: {PT: 6, Name: "DVI4", Rate: 16000}, // Adaptive pulse code modulation 16khz (SpanDSP ima_adpcm.h)
7: {PT: 7, Name: "LPC", Rate: 8000}, // Chat with your friends ww2 field marshall style (SpanDSP lpc10.h)
8: {PT: 8, Name: "PCMA", Rate: 8000}, // G.711 variant of μ-Law used in yurop (SpanDSP g711.h)
9: {PT: 9, Name: "G722", Rate: 8000}, // Used for Polycom HD Voice; Rate actually 16khz LOL (SpanDSP g722.h)
10: {PT: 10, Name: "L16", Rate: 44100, Param: "2"}, // 16-bit signed PCM stereo/mono (mind your MTU; adjust ptime)
11: {PT: 11, Name: "L16", Rate: 44100},
12: {PT: 12, Name: "QCELP", Rate: 8000},
13: {PT: 13, Name: "CN", Rate: 8000}, // RFC3389 comfort noise
14: {PT: 14, Name: "MPA", Rate: 90000},
15: {PT: 15, Name: "G728", Rate: 8000},
16: {PT: 16, Name: "DVI4", Rate: 11025},
17: {PT: 17, Name: "DVI4", Rate: 22050},
18: {PT: 18, Name: "G729", Rate: 8000}, // Best telephone voice codec (if you got $10 bucks)
25: {PT: 25, Name: "CelB", Rate: 90000},
26: {PT: 26, Name: "JPEG", Rate: 90000},
28: {PT: 28, Name: "nv", Rate: 90000},
31: {PT: 31, Name: "H261", Rate: 90000}, // RFC4587 Video
32: {PT: 32, Name: "MPV", Rate: 90000},
33: {PT: 33, Name: "MP2T", Rate: 90000},
34: {PT: 34, Name: "H263", Rate: 90000}, // $$$ video
}
)

+ 3
- 3
sdp/media.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 4
- 3
sdp/origin.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -16,6 +16,7 @@ package sdp
import (
"bytes"
"github.com/jart/gosip/util"
)


+ 38
- 37
sdp/sdp_test.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -16,8 +16,9 @@ package sdp_test
import (
"fmt"
"github.com/jart/gosip/sdp"
"testing"
"github.com/jart/gosip/sdp"
)
type sdpTest struct {
@ -30,7 +31,7 @@ type sdpTest struct {
var sdpTests = []sdpTest{
sdpTest{
{
name: "Asterisk PCMU+DTMF",
s: ("v=0\r\n" +
"o=root 31589 31589 IN IP4 10.0.0.38\r\n" +
@ -58,18 +59,18 @@ var sdpTests = []sdpTest{
Proto: "RTP/AVP",
Port: 30126,
Codecs: []sdp.Codec{
sdp.Codec{PT: 0, Name: "PCMU", Rate: 8000},
sdp.Codec{PT: 101, Name: "telephone-event", Rate: 8000, Fmtp: "0-16"},
{PT: 0, Name: "PCMU", Rate: 8000},
{PT: 101, Name: "telephone-event", Rate: 8000, Fmtp: "0-16"},
},
},
Attrs: [][2]string{
[2]string{"silenceSupp", "off - - - -"},
{"silenceSupp", "off - - - -"},
},
Ptime: 20,
},
},
sdpTest{
{
name: "Audio+Video+Implicit+Fmtp",
s: "v=0\r\n" +
"o=- 3366701332 3366701332 IN IP4 1.2.3.4\r\n" +
@ -102,21 +103,21 @@ var sdpTests = []sdpTest{
Proto: "RTP/AVP",
Port: 32898,
Codecs: []sdp.Codec{
sdp.Codec{PT: 18, Name: "G729", Rate: 8000, Fmtp: "annexb=yes"},
{PT: 18, Name: "G729", Rate: 8000, Fmtp: "annexb=yes"},
},
},
Video: &sdp.Media{
Proto: "RTP/AVP",
Port: 32900,
Codecs: []sdp.Codec{
sdp.Codec{PT: 34, Name: "H263", Rate: 90000},
{PT: 34, Name: "H263", Rate: 90000},
},
},
Attrs: [][2]string{},
},
},
sdpTest{
{
name: "Implicit Codecs",
s: "v=0\r\n" +
"o=- 3366701332 3366701332 IN IP4 1.2.3.4\r\n" +
@ -152,10 +153,10 @@ var sdpTests = []sdpTest{
Proto: "RTP/AVP",
Port: 32898,
Codecs: []sdp.Codec{
sdp.Codec{PT: 9, Name: "G722", Rate: 8000},
sdp.Codec{PT: 18, Name: "G729", Rate: 8000},
sdp.Codec{PT: 0, Name: "PCMU", Rate: 8000},
sdp.Codec{PT: 101, Name: "telephone-event", Rate: 8000},
{PT: 9, Name: "G722", Rate: 8000},
{PT: 18, Name: "G729", Rate: 8000},
{PT: 0, Name: "PCMU", Rate: 8000},
{PT: 101, Name: "telephone-event", Rate: 8000},
},
},
Ptime: 20,
@ -163,7 +164,7 @@ var sdpTests = []sdpTest{
},
},
sdpTest{
{
name: "IPv6",
s: "v=0\r\n" +
"o=- 3366701332 3366701332 IN IP6 dead:beef::666\r\n" +
@ -199,10 +200,10 @@ var sdpTests = []sdpTest{
Proto: "RTP/AVP",
Port: 32898,
Codecs: []sdp.Codec{
sdp.Codec{PT: 9, Name: "G722", Rate: 8000},
sdp.Codec{PT: 18, Name: "G729", Rate: 8000},
sdp.Codec{PT: 0, Name: "PCMU", Rate: 8000},
sdp.Codec{PT: 101, Name: "telephone-event", Rate: 8000},
{PT: 9, Name: "G722", Rate: 8000},
{PT: 18, Name: "G729", Rate: 8000},
{PT: 0, Name: "PCMU", Rate: 8000},
{PT: 101, Name: "telephone-event", Rate: 8000},
},
},
Ptime: 20,
@ -210,7 +211,7 @@ var sdpTests = []sdpTest{
},
},
sdpTest{
{
name: "pjmedia long sdp is long",
s: ("v=0\r\n" +
"o=- 3457169218 3457169218 IN IP4 10.11.34.37\r\n" +
@ -247,26 +248,26 @@ var sdpTests = []sdpTest{
Proto: "RTP/AVP",
Port: 4000,
Codecs: []sdp.Codec{
sdp.Codec{PT: 103, Name: "speex", Rate: 16000},
sdp.Codec{PT: 102, Name: "speex", Rate: 8000},
sdp.Codec{PT: 104, Name: "speex", Rate: 32000},
sdp.Codec{PT: 113, Name: "iLBC", Rate: 8000, Fmtp: "mode=30"},
sdp.Codec{PT: 3, Name: "GSM", Rate: 8000},
sdp.Codec{PT: 0, Name: "PCMU", Rate: 8000},
sdp.Codec{PT: 8, Name: "PCMA", Rate: 8000},
sdp.Codec{PT: 9, Name: "G722", Rate: 8000},
sdp.Codec{PT: 101, Name: "telephone-event", Rate: 8000, Fmtp: "0-15"},
{PT: 103, Name: "speex", Rate: 16000},
{PT: 102, Name: "speex", Rate: 8000},
{PT: 104, Name: "speex", Rate: 32000},
{PT: 113, Name: "iLBC", Rate: 8000, Fmtp: "mode=30"},
{PT: 3, Name: "GSM", Rate: 8000},
{PT: 0, Name: "PCMU", Rate: 8000},
{PT: 8, Name: "PCMA", Rate: 8000},
{PT: 9, Name: "G722", Rate: 8000},
{PT: 101, Name: "telephone-event", Rate: 8000, Fmtp: "0-15"},
},
},
Ptime: 20,
Attrs: [][2]string{
[2]string{"rtcp", "4001 IN IP4 10.11.34.37"},
[2]string{"X-nat", "0"},
{"rtcp", "4001 IN IP4 10.11.34.37"},
{"X-nat", "0"},
},
},
},
sdpTest{
{
name: "mp3 tcp",
s: ("v=0\r\n" +
"o=- 3366701332 3366701334 IN IP4 10.11.34.37\r\n" +
@ -291,7 +292,7 @@ var sdpTests = []sdpTest{
Proto: "TCP/IP",
Port: 80,
Codecs: []sdp.Codec{
sdp.Codec{PT: 111, Name: "MP3", Rate: 44100, Param: "2"},
{PT: 111, Name: "MP3", Rate: 44100, Param: "2"},
},
},
Attrs: [][2]string{},
@ -341,7 +342,7 @@ func sdpCompareCodecs(t *testing.T, name string, corrects, codecs []sdp.Codec) {
if len(corrects) != len(codecs) {
t.Error(name, "len(Codecs)", len(corrects), "!=", len(codecs))
} else {
for i, _ := range corrects {
for i := range corrects {
c1, c2 := &corrects[i], &codecs[i]
if c1 == nil || c2 == nil {
t.Error(name, "where my codecs at?")
@ -426,7 +427,7 @@ func TestParse(t *testing.T) {
} else if len(sdp.Attrs) != len(test.sdp.Attrs) {
t.Error(test.name, "Attrs length not same")
} else {
for i, _ := range sdp.Attrs {
for i := range sdp.Attrs {
p1, p2 := test.sdp.Attrs[i], sdp.Attrs[i]
if p1[0] != p2[0] || p1[1] != p2[1] {
t.Error(test.name, "attr", p1, "!=", p2)


+ 4
- 3
sip/addr.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -34,6 +34,7 @@ package sip
import (
"bytes"
"github.com/jart/gosip/util"
)


+ 16
- 15
sip/addr_test.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -16,9 +16,10 @@ package sip_test
import (
"bytes"
"github.com/jart/gosip/sip"
"reflect"
"testing"
"github.com/jart/gosip/sip"
)
type addrTest struct {
@ -31,7 +32,7 @@ type addrTest struct {
var addrTests = []addrTest{
addrTest{
{
name: "Basic address",
s: "<sip:pokemon.net>",
addr: sip.Addr{
@ -42,7 +43,7 @@ var addrTests = []addrTest{
},
},
addrTest{
{
name: "Address parameter",
s: "<sip:pokemon.net>;tag=deadbeef",
addr: sip.Addr{
@ -54,7 +55,7 @@ var addrTests = []addrTest{
},
},
addrTest{
{
name: "Address parameter spacing",
s: "<sip:pokemon.net>\t ;\t tag\t = \tdeadbeef",
s_canonical: "<sip:pokemon.net>;tag=deadbeef",
@ -67,7 +68,7 @@ var addrTests = []addrTest{
},
},
addrTest{
{
name: "Address parameter quoted",
s: "<sip:pokemon.net>;tag=\"deadbeef\"",
s_canonical: "<sip:pokemon.net>;tag=deadbeef",
@ -80,7 +81,7 @@ var addrTests = []addrTest{
},
},
addrTest{
{
name: "Address parameter quoted spacing",
s: "<sip:pokemon.net>\t ;\t tag\t = \t\"deadbeef\"",
s_canonical: "<sip:pokemon.net>;tag=deadbeef",
@ -93,7 +94,7 @@ var addrTests = []addrTest{
},
},
addrTest{
{
name: "Address parameter quoted escaped",
s: "<sip:pokemon.net>;tag=\"\\\"deadbeef\\\"\"",
addr: sip.Addr{
@ -105,7 +106,7 @@ var addrTests = []addrTest{
},
},
addrTest{
{
name: "URI parameter",
s: "<sip:brave@toaster.net;isup-oli=29>",
addr: sip.Addr{
@ -118,7 +119,7 @@ var addrTests = []addrTest{
},
},
addrTest{
{
name: "Address + URI parameter",
s: "<sip:brave@toaster.net;isup-oli=29>;tag=deadbeef",
addr: sip.Addr{
@ -132,7 +133,7 @@ var addrTests = []addrTest{
},
},
addrTest{
{
s: `<sip:pokemon.com>, Ditto <sip:ditto@pokemon.com>`,
addr: sip.Addr{
Uri: &sip.URI{
@ -150,7 +151,7 @@ var addrTests = []addrTest{
},
},
addrTest{
{
s: `<sip:1.2.3.4>, <sip:1.2.3.5>, <sip:[666::dead:beef]>`,
addr: sip.Addr{
Uri: &sip.URI{
@ -172,7 +173,7 @@ var addrTests = []addrTest{
},
},
addrTest{
{
s: "\"\\\"\\\"Justine \\\\Tunney \" " +
"<sip:jart@google.com;isup-oli=29>;tag=deadbeef",
addr: sip.Addr{


+ 3
- 3
sip/charsets.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 3
- 3
sip/charsets_test.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 3
- 3
sip/errors.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 3
- 3
sip/escape.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 7
- 11
sip/escape_test.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -27,29 +27,25 @@ type escapeTest struct {
}
var escapeTests = []escapeTest{
escapeTest{
{
name: "Param Normal",
in: "hello",
out: "hello",
p: paramc,
},
escapeTest{
{
name: "User Normal",
in: "hello",
out: "hello",
p: userc,
},
escapeTest{
{
name: "Param Spacing",
in: "hello there",
out: "hello%20there",
p: paramc,
},
escapeTest{
{
name: "User Spacing",
in: "hello there",
out: "hello%20there",


+ 3
- 3
sip/method.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 3
- 3
sip/msg.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 40
- 39
sip/msg_test.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -15,9 +15,10 @@
package sip_test
import (
"github.com/jart/gosip/sip"
"reflect"
"testing"
"github.com/jart/gosip/sip"
)
const (
@ -63,12 +64,12 @@ type msgTest struct {
var msgTests = []msgTest{
msgTest{
{
s: "",
e: sip.MsgIncompleteError{Msg: []uint8{}},
},
msgTest{
{
name: "UTF8 Phrase",
s: "SIP/2.0 200 ◕◡◕\r\n" +
"\r\n",
@ -79,7 +80,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Left Padding",
s: "SIP/2.0 200 OK\r\n" +
"Expires: 666\r\n" +
@ -92,7 +93,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Extension Headers",
s: "SIP/2.0 200 OK\r\n" +
"X-LOL: omfg\r\n" +
@ -105,7 +106,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Multiple Addresses",
s: "SIP/2.0 200 OK\r\n" +
"From: <sip:lol.com> , <sip:bog.com> \r\n" +
@ -129,7 +130,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Line Continuation Warning",
s: "SIP/2.0 200 OK\r\n" +
"Warning: Morning and evening\r\n" +
@ -152,7 +153,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Line Continuation Warning Followed By Extended Header",
s: "SIP/2.0 200 OK\r\n" +
"Warning: Morning and evening\r\n" +
@ -177,7 +178,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Line Continuation Extended Followed By Extended",
s: "SIP/2.0 200 OK\r\n" +
"X-Warning: Come buy our orchard fruits,\r\n" +
@ -200,7 +201,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Line Continuation Extended Followed By Extended 2",
s: "SIP/2.0 200 OK\r\n" +
"NewFangledHeader: newfangled value\r\n" +
@ -223,7 +224,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Line Continuations Addr",
s: "SIP/2.0 200 OK\r\n" +
"From:\r\n" +
@ -249,7 +250,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Extended header looks like standard headers",
s: "SIP/2.0 200 OK\r\n" +
"viaz: floor\r\n" +
@ -285,7 +286,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Address Unquoted Display",
s: "SIP/2.0 200 OK\r\n" +
"From: Kitty <sip:lol.com>\r\n" +
@ -304,7 +305,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Address Quoted Display",
s: "SIP/2.0 200 OK\r\n" +
"From: \"Hello \\\"Kitty\\\" ◕◡◕\" <sip:lol.com>\r\n" +
@ -323,7 +324,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Address Quoted Display Multiline",
s: "SIP/2.0 200 OK\r\n" +
"From: \"oh\r\n" +
@ -346,7 +347,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Address Unquoted Display Multiline",
s: "SIP/2.0 200 OK\r\n" +
"From: oh\r\n" +
@ -369,7 +370,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Addr Tag",
s: "SIP/2.0 200 OK\r\n" +
"From: <sip:lol.com>;tag=omfg\r\n" +
@ -388,7 +389,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Addr Tag Quoted",
// TODO(jart): Crash when extra spacing in here.
s: "SIP/2.0 200 OK\r\n" +
@ -408,7 +409,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Addr Tag Bare",
s: "SIP/2.0 200 OK\r\n" +
"From: <sip:lol.com>;tag\r\n" +
@ -427,7 +428,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Missing Angle Brackets With Tag Belongs to Addr Not URI",
s: "SIP/2.0 200 OK\r\n" +
"From: sip:lol.com;tag=omfg\r\n" +
@ -447,7 +448,7 @@ var msgTests = []msgTest{
},
// // TODO(jart): Implement me.
// msgTest{
// {
// name: "Content Type Params",
// s: "SIP/2.0 200 OK\r\n" +
// "Content-Type: multipart/signed;\r\n" +
@ -462,7 +463,7 @@ var msgTests = []msgTest{
// },
// },
msgTest{
{
name: "Via Host Only",
s: "SIP/2.0 200 OK\r\n" +
"Via: SIP/2.0/UDP 8.8.4.4\r\n" +
@ -480,7 +481,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Via Port",
s: "SIP/2.0 200 OK\r\n" +
"Via: SIP/2.0/UDP 8.8.4.4:666\r\n" +
@ -499,7 +500,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Via Port Spacing",
s: "SIP/2.0 200 OK\r\n" +
"Via: SIP/2.0/UDP 8.8.4.4 \t : \t 666\r\n" +
@ -518,7 +519,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Via Line Continuation",
s: "SIP/2.0 200 OK\r\n" +
"Via: SIP/2.0/UDP 10.11.34.37 ,\r\n" +
@ -545,7 +546,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Via Multiple Lines",
s: "SIP/2.0 200 OK\r\n" +
"Via: SIP/2.0/UDP 10.11.34.37\r\n" +
@ -570,7 +571,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Via Multiple Lines Continuation",
s: "SIP/2.0 200 OK\r\n" +
"Via: SIP/2.0/UDP 10.11.34.37\r\n" +
@ -608,7 +609,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Via Param",
s: "SIP/2.0 200 OK\r\n" +
"Via: SIP/ 2.0/TCP spindle.example.com ;branch=z9hG4bK9ikj8\r\n" +
@ -627,7 +628,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Via Param Torture",
s: "SIP/2.0 200 OK\r\n" +
"v: SIP / 2.0 / TCP spindle.example.com ;\r\n" +
@ -647,7 +648,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Via Torture",
s: "SIP/2.0 200 OK\r\n" +
"Via : SIP / 2.0\r\n" +
@ -686,7 +687,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "OPTIONS",
s: "OPTIONS sip:10.11.34.37:42367 SIP/2.0\r\n" +
"Via: SIP/2.0/UDP 10.11.34.37:42367;rport;branch=9dc39c3c3e84\r\n" +
@ -752,7 +753,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
s: "SIP/2.0 200 OK\r\n" +
"Via: SIP/2.0/UDP 127.0.0.1:52711;branch=z9hG4bK-03d1d81e94a0;received=127.0.0.1;rport=52711\r\n" +
"From: <sip:127.0.0.1:52711;transport=udp>;tag=4568e274dbd8\r\n" +
@ -851,7 +852,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "Flowroute Fun",
s: flowroute,
msg: sip.Msg{
@ -924,7 +925,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "INVITE",
s: "INVITE sip:10.11.34.37 SIP/2.0\r\n" +
"via: SIP/2.0/UDP 10.11.34.37:59516;rport;branch=z9hG4bKS308QB9UUpNyD\r\n" +
@ -1026,7 +1027,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "RFC4475 Torture Message #1",
s: "INVITE sip:vivekg@chair-dnrc.example.com;unknownparam SIP/2.0\r\n" +
"TO :\r\n" +
@ -1172,7 +1173,7 @@ var msgTests = []msgTest{
},
},
msgTest{
{
name: "RFC4475 Torture Message #2",
s: torture2,
msg: sip.Msg{


+ 3
- 3
sip/msgerror.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 3
- 3
sip/param.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 3
- 3
sip/payload.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 3
- 3
sip/prefs.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 3
- 3
sip/quote.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 10
- 17
sip/quote_test.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -26,44 +26,37 @@ type quoteTest struct {
}
var quoteTests = []quoteTest{
quoteTest{
{
name: "Normal value",
in: "hello",
out: "hello",
},
quoteTest{
{
name: "Space doesn't quotes",
in: "hello there",
out: "hello there",
},
quoteTest{
{
name: "Less than adds quotes",
in: "hello there<",
out: "\"hello there<\"",
},
quoteTest{
{
name: "CRLF with space after works",
in: "hello\r\n there!",
out: "\"hello\r\n there!\"",
},
quoteTest{
{
name: "CRLF without space truncates",
in: "hello\r\nthere!",
out: "\"hello\"",
},
quoteTest{
{
name: "Escapable character escapes",
in: "hello\"there",
out: "\"hello\\\"there\"",
},
quoteTest{
{
name: "Unescapable character truncates",
in: "hello\xFFthere",
out: "\"hello\"",


+ 3
- 3
sip/status.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 5
- 4
sip/uri.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -36,6 +36,7 @@ package sip
import (
"bytes"
"github.com/jart/gosip/util"
)
@ -104,7 +105,7 @@ func (uri *URI) Append(b *bytes.Buffer) {
}
if uri.Port > 0 {
b.WriteByte(':')
b.WriteString(portstr(uri.Port))
b.WriteString(util.Portstr(uri.Port))
}
uri.Param.Append(b)
uri.Header.Append(b)


+ 25
- 24
sip/uri_test.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -16,9 +16,10 @@ package sip_test
import (
"errors"
"github.com/jart/gosip/sip"
"reflect"
"testing"
"github.com/jart/gosip/sip"
)
type uriTest struct {
@ -30,22 +31,22 @@ type uriTest struct {
var uriTests = []uriTest{
uriTest{
{
s: "",
e: errors.New("Incomplete URI: "),
},
uriTest{
{
s: "sip:",
e: errors.New("Incomplete URI: sip:"),
},
uriTest{
{
s: "sip:example.com:LOL",
e: errors.New("Error in URI at pos 16: sip:example.com:LOL"),
},
uriTest{
{
s: "sip:example.com",
uri: &sip.URI{
Scheme: "sip",
@ -53,7 +54,7 @@ var uriTests = []uriTest{
},
},
uriTest{
{
s: "sip:example.com:5060",
uri: &sip.URI{
Scheme: "sip",
@ -62,7 +63,7 @@ var uriTests = []uriTest{
},
},
uriTest{
{
s: "sips:jart@google.com",
uri: &sip.URI{
Scheme: "sips",
@ -71,7 +72,7 @@ var uriTests = []uriTest{
},
},
uriTest{
{
s: "sips:jart@google.com:5060",
uri: &sip.URI{
Scheme: "sips",
@ -81,7 +82,7 @@ var uriTests = []uriTest{
},
},
uriTest{
{
s: "sips:jart:letmein@google.com",
uri: &sip.URI{
Scheme: "sips",
@ -91,7 +92,7 @@ var uriTests = []uriTest{
},
},
uriTest{
{
s: "sips:jart:LetMeIn@google.com:5060",
uri: &sip.URI{
Scheme: "sips",
@ -102,7 +103,7 @@ var uriTests = []uriTest{
},
},
uriTest{
{
s: "sips:GOOGLE.com",
uri: &sip.URI{
Scheme: "sips",
@ -111,7 +112,7 @@ var uriTests = []uriTest{
skipFormat: true,
},
uriTest{
{
s: "sip:[dead:beef::666]:5060",
uri: &sip.URI{
Scheme: "sip",
@ -120,12 +121,12 @@ var uriTests = []uriTest{
},
},
uriTest{
{
s: "sip:dead:beef::666:5060",
e: errors.New("Error in URI at pos 9: sip:dead:beef::666:5060"),
},
uriTest{
{
s: "tel:+12126660420",
uri: &sip.URI{
Scheme: "tel",
@ -133,7 +134,7 @@ var uriTests = []uriTest{
},
},
uriTest{
{
s: "sip:bob%20barker:priceisright@[dead:beef::666]:5060;isup-oli=00",
uri: &sip.URI{
Scheme: "sip",
@ -145,12 +146,12 @@ var uriTests = []uriTest{
},
},
uriTest{
{
s: "sips:google.com ;lol ;h=omg",
e: errors.New("Error in URI at pos 15: sips:google.com ;lol ;h=omg"),
},
uriTest{
{
s: "SIP:example.com",
uri: &sip.URI{
Scheme: "sip",
@ -159,7 +160,7 @@ var uriTests = []uriTest{
skipFormat: true,
},
uriTest{
{
s: "sips:alice@atlanta.com?priority=urgent&subject=project%20x",
uri: &sip.URI{
Scheme: "sips",
@ -176,7 +177,7 @@ var uriTests = []uriTest{
},
},
uriTest{
{
s: "sip:+1-212-555-1212:1234@gateway.com;user=phone",
uri: &sip.URI{
Scheme: "sip",
@ -187,7 +188,7 @@ var uriTests = []uriTest{
},
},
uriTest{
{
s: "sip:atlanta.com;method=register?to=alice%40atlanta.com",
uri: &sip.URI{
Scheme: "sip",
@ -197,7 +198,7 @@ var uriTests = []uriTest{
},
},
uriTest{
{
s: "sip:alice;day=tuesday@atlanta.com",
uri: &sip.URI{
Scheme: "sip",


+ 3
- 3
sip/uriheader.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 3
- 3
sip/uriparam.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 3
- 23
sip/util.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -14,26 +14,6 @@
package sip
import (
"strconv"
"time"
)
func duration(ms *int) time.Duration {
return time.Duration(*ms) * time.Millisecond
}
func or5060(port uint16) uint16 {
if port == 0 {
return 5060
}
return port
}
func portstr(port uint16) string {
return strconv.FormatInt(int64(port), 10)
}
func unhex(b byte) byte {
switch {
case '0' <= b && b <= '9':


+ 5
- 4
sip/via.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -18,8 +18,9 @@ package sip
import (
"bytes"
"github.com/jart/gosip/util"
"strconv"
"github.com/jart/gosip/util"
)
// Example: SIP/2.0/UDP 1.2.3.4:5060;branch=z9hG4bK556f77e6.


+ 3
- 3
sip/xheader.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


+ 7
- 3
util/util.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -92,3 +92,7 @@ func append(buf []byte, s string) []byte {
}
return buf
}
func Portstr(port uint16) string {
return strconv.FormatInt(int64(port), 10)
}

Loading…
Cancel
Save