read & print test SIP messages

This commit is contained in:
Andre Heber
2024-08-02 18:08:47 +02:00
parent a884e8d523
commit 868be1adef
24 changed files with 417 additions and 1 deletions

61
main.go
View File

@ -2,8 +2,67 @@ package main
import (
"fmt"
"os"
"strings"
)
func main() {
fmt.Println("Hello, I'm the SIP Parser!")
content, errChan := readTestFiles("./sip_messages")
printMessages(content, errChan)
}
// readTestFiles reads all files in the given directory that start with "test" and sends their content to the output channel.
// If an error occurs, it sends the error to the error channel.
func readTestFiles(directory string) (<-chan string, <-chan error) {
output := make(chan string)
errChan := make(chan error)
go func(output chan<- string, errChan chan<- error) {
defer close(output)
defer close(errChan)
files, err := os.ReadDir(directory)
if err != nil {
errChan <- err
return
}
for _, file := range files {
if !file.IsDir() && strings.HasPrefix(file.Name(), "test") {
content, err := os.ReadFile(directory + "/" + file.Name())
if err != nil {
errChan <- err
return
}
output <- fmt.Sprintf("Content of %s:\n%s\n", file.Name(), content)
}
}
}(output, errChan)
return output, errChan
}
// printMessages reads from the content and error channels and prints the messages to the console.
// It stops when both channels are closed.
func printMessages(content <-chan string, errChan <-chan error) {
for {
select {
case c, ok := <-content:
if !ok {
content = nil
} else {
fmt.Println(c)
}
case err, ok := <-errChan:
if !ok {
errChan = nil
} else {
fmt.Println(err)
}
}
if content == nil && errChan == nil {
break
}
}
}

19
sip_messages/test21.txt Normal file
View File

@ -0,0 +1,19 @@
INVITE <sip:user@company.com> SIP/2.0
To: sip:user@company.com
From: sip:caller@university.edu
Call-ID: 1@10.0.0.1
CSeq: 1 INVITE
Via: SIP/2.0/UDP 135.180.130.133
Content-Type: application/sdp
Content-Length: 174
v=0
o=mhandley 29739 7272939 IN IP4 126.5.4.3
s=SIP Call
t=3149328700 0
c=IN IP4 135.180.130.88
m=audio 49210 RTP/AVP 0 12
m=video 3227 RTP/AVP 31
a=rtpmap:31 LPC/8000

20
sip_messages/test22.txt Normal file
View File

@ -0,0 +1,20 @@
INVITE sip:user@company.com; transport=udp SIP/2.0
To: sip:user@company.com
From: sip:caller@university.edu
Call-ID: 2@10.0.0.1
CSeq: 1 INVITE
Via: SIP/2.0/UDP 135.180.130.133
Content-Type: application/sdp
Content-Length: 174
v=0
o=mhandley 29739 7272939 IN IP4 126.5.4.3
s=SIP Call
t=3149328700 0
c=IN IP4 135.180.130.88
m=audio 49210 RTP/AVP 0 12
m=video 3227 RTP/AVP 31
a=rtpmap:31 LPC/8000

19
sip_messages/test23.txt Normal file
View File

@ -0,0 +1,19 @@
INVITE sip:user@company.com SIP/2.0
To: sip:user@company.com
From: sip:caller@university.edu
Call-ID: 3@10.0.0.1
CSeq: 1 INVITE
Via: SIP/2.0/UDP 135.180.130.133
Content-Type: application/sdp
Content-Length: 174
v=0
o=mhandley 29739 7272939 IN IP4 126.5.4.3
s=SIP Call
c=IN IP4 135.180.130.88
t=3149328700 0
m=audio 49210 RTP/AVP 0 12
m=video 3227 RTP/AVP 31
a=rtpmap:31 LPC/8000

19
sip_messages/test24.txt Normal file
View File

@ -0,0 +1,19 @@
INVITE sip:sip%3Auser%40example.com@company.com;other-param=summit SIP/2.0
To: sip:user@company.com
From: sip:caller@university.edu
Call-ID: 4@10.0.0.1
CSeq: 1 INVITE
Via: SIP/2.0/UDP 135.180.130.133
Content-Type: application/sdp
Content-Length: 174
v=0
o=mhandley 29739 7272939 IN IP4 126.5.4.3
s=SIP Call
c=IN IP4 135.180.130.88
t=3149328700 0
m=audio 49210 RTP/AVP 0 12
m=video 3227 RTP/AVP 31
a=rtpmap:31 LPC/8000

19
sip_messages/test25.txt Normal file
View File

@ -0,0 +1,19 @@
INVITE sip:user@company.com?Route=%3Csip:sip.example.com%3E SIP/2.0
To: sip:user@company.com
From: sip:caller@university.edu
Call-ID: 5@10.0.0.1
CSeq: 1 INVITE
Via: SIP/2.0/UDP 135.180.130.133
Content-Type: application/sdp
Content-Length: 174
v=0
o=mhandley 29739 7272939 IN IP4 126.5.4.3
s=SIP Call
c=IN IP4 135.180.130.88
t=3149328700 0
m=audio 49210 RTP/AVP 0 12
m=video 3227 RTP/AVP 31
a=rtpmap:31 LPC/8000

19
sip_messages/test26.txt Normal file
View File

@ -0,0 +1,19 @@
INVITE name:user SIP/2.0
To: sip:user@company.com
From: sip:caller@university.edu
Call-ID: 6@10.0.0.1
CSeq: 1 INVITE
Via: SIP/2.0/UDP 135.180.130.133
Content-Type: application/sdp
Content-Length: 174
v=0
o=mhandley 29739 7272939 IN IP4 126.5.4.3
s=SIP Call
c=IN IP4 135.180.130.88
t=3149328700 0
m=audio 49210 RTP/AVP 0 12
m=video 3227 RTP/AVP 31
a=rtpmap:31 LPC/8000

8
sip_messages/test27.txt Normal file
View File

@ -0,0 +1,8 @@
OPTIONS sip:user@company.com SIP/2.0
To: sip:user@company.com
From: "caller"<sip:caller@example.com>
Call-ID: 1234abcd@10.0.0.1
CSeq: 1 OPTIONS
Via: SIP/2.0/UDP 135.180.130.133

8
sip_messages/test28.txt Normal file
View File

@ -0,0 +1,8 @@
OPTIONS sip:user@company.com SIP/2.0
To: sip:user@company.com
From: "caller" <sip:caller@example.com>
Call-ID: 1234abcd@10.0.0.1
CSeq: 2 OPTIONS
Via: SIP/2.0/UDP 135.180.130.133

20
sip_messages/test29.txt Normal file
View File

@ -0,0 +1,20 @@
INVITE sip:user@company.com SIP/2.0
To: sip:user@company.com
From: sip:caller@university.edu
Call-ID: 7@10.0.0.1
CSeq: 1 INVITE
Via: SIP/2.0/UDP 135.180.130.133
Expires: Fri, 01 Jan 2010 16:00:00 EST
Content-Type: application/sdp
Content-Length: 174
v=0
o=mhandley 29739 7272939 IN IP4 126.5.4.3
s=SIP Call
t=3149328700 0
c=IN IP4 135.180.130.88
m=audio 49210 RTP/AVP 0 12
m=video 3227 RTP/AVP 31
a=rtpmap:31 LPC/8000

20
sip_messages/test30.txt Normal file
View File

@ -0,0 +1,20 @@
INVITE sip:user@company.com SIP/2.0
To: sip:user@company.com
From: sip:caller@university.edu
Call-ID: 8@10.0.0.1
CSeq: 1 INVITE
Via: SIP/2.0/UDP 135.180.130.133
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Content-Type: application/sdp
Content-Length: 174
v=0
o=mhandley 29739 7272939 IN IP4 126.5.4.3
s=SIP Call
c=IN IP4 135.180.130.88
t=3149328700 0
m=audio 49210 RTP/AVP 0 12
m=video 3227 RTP/AVP 31
a=rtpmap:31 LPC/8000

20
sip_messages/test31.txt Normal file
View File

@ -0,0 +1,20 @@
INVITE sip:user@company.com SIP/2.0
To: sip:user@company.com
From: sip:caller@university.edu
Call-ID: 9@10.0.0.1
CSeq: 1 INVITE
Via: SIP/2.0/UDP 135.180.130.133
Max-Forwards: 0
Content-Type: application/sdp
Content-Length: 174
v=0
o=mhandley 29739 7272939 IN IP4 126.5.4.3
s=SIP Call
c=IN IP4 135.180.130.88
t=3149328700 0
m=audio 49210 RTP/AVP 0 12
m=video 3227 RTP/AVP 31
a=rtpmap:31 LPC/8000

10
sip_messages/test32.txt Normal file
View File

@ -0,0 +1,10 @@
REGISTER sip:company.com SIP/2.0
To: sip:user@company.com
From: sip:user@company.com
Contact: sip:user@host.company.com
Call-ID: k345asrl3fdbv@10.0.0.1
CSeq: 1 REGISTER
Via: SIP/2.0/UDP 135.180.130.133
Contact: <sip:user@example.com?Route=%3Csip:sip.example.com%3E>

10
sip_messages/test33.txt Normal file
View File

@ -0,0 +1,10 @@
REGISTER sip:company.com SIP/2.0
To: sip:user@company.com
From: sip:user@company.com
Contact: sip:user@host.company.com
Call-ID: k345asrl3fdbv@10.0.0.1
CSeq: 1 REGISTER
Via: SIP/2.0/UDP 135.180.130.133
Contact: sip:user@example.com?Route=%3Csip:sip.example.com%3E

52
sip_messages/test34.txt Normal file
View File

@ -0,0 +1,52 @@
INVITE sip:user@company.com SIP/2.0
To: "I have a user name of extreme proportion" <sip:user@company.com:6000;other-param=1234567890somethingelselong1234567890>
From: sip:caller@university.edu
Call-ID: kl24ahsd546folnyt2vbak9sad98u23naodiunzds09a3bqw0sdfbsk34poouymnae0043nsed09mfkvc74bd0cuwnms05dknw87hjpobd76f
CSeq: 1 INVITE
My-State: sldkjflzdsfaret0803adgaasd0afds0asdaasd
Via: SIP/2.0/UDP sip33.example.com
Via: SIP/2.0/UDP sip32.example.com
Via: SIP/2.0/UDP sip31.example.com
Via: SIP/2.0/UDP sip30.example.com
Via: SIP/2.0/UDP sip29.example.com
Via: SIP/2.0/UDP sip28.example.com
Via: SIP/2.0/UDP sip27.example.com
Via: SIP/2.0/UDP sip26.example.com
Via: SIP/2.0/UDP sip25.example.com
Via: SIP/2.0/UDP sip24.example.com
Via: SIP/2.0/UDP sip23.example.com
Via: SIP/2.0/UDP sip22.example.com
Via: SIP/2.0/UDP sip21.example.com
Via: SIP/2.0/UDP sip20.example.com
Via: SIP/2.0/UDP sip19.example.com
Via: SIP/2.0/UDP sip18.example.com
Via: SIP/2.0/UDP sip17.example.com
Via: SIP/2.0/UDP sip16.example.com
Via: SIP/2.0/UDP sip15.example.com
Via: SIP/2.0/UDP sip14.example.com
Via: SIP/2.0/UDP sip13.example.com
Via: SIP/2.0/UDP sip12.example.com
Via: SIP/2.0/UDP sip11.example.com
Via: SIP/2.0/UDP sip10.example.com
Via: SIP/2.0/UDP sip9.example.com
Via: SIP/2.0/UDP sip8.example.com
Via: SIP/2.0/UDP sip7.example.com
Via: SIP/2.0/UDP sip6.example.com
Via: SIP/2.0/UDP sip5.example.com
Via: SIP/2.0/UDP sip4.example.com
Via: SIP/2.0/UDP sip3.example.com
Via: SIP/2.0/UDP sip2.example.com
Via: SIP/2.0/UDP sip1.example.com
Via: SIP/2.0/UDP host.example.com;received=135.180.130.133;branch=C1C3344E2710000000E299E568E7potato10potato0potato0
Content-Type: application/sdp
v=0
o=mhandley 29739 7272939 IN IP4 126.5.4.3
s=SIP Call
c=IN IP4 135.180.130.88
t=3149328700 0
m=audio 49210 RTP/AVP 0 12
m=video 3227 RTP/AVP 31
a=rtpmap:31 LPC/8000

16
sip_messages/test35.txt Normal file
View File

@ -0,0 +1,16 @@
OPTIONS sip:135.180.130.133 SIP/2.0
Via: SIP/2.0/UDP company.com:5604
From: sip:iuser@company.com
To: sip:user@135.180.130.133
Call-ID: 1804928587@company.com
CSeq: 1 OPTIONS
Expires: 0 0l@company.com
To: sip:user@135.180.130.133
Call-ID: 1804928587@company.com
CSeq: 1 OPTIONS
Contact: sip:host.company.com
Expires: 0xpires: 0sip:host.company.com
Expires: 0
Contact: sip:host.company.com

25
sip_messages/test36.txt Normal file
View File

@ -0,0 +1,25 @@
INVITE sip:+1-972-555-2222;phone-context=name%40domain;new=user?%22Route%3a%20X%40Y%3bZ=W%22@gw1.wcom.com;user=phone SIP/2.0
Via: SIP/2.0/UDP iftgw.there.com:5060
From: sip:+1-303-555-1111@ift.here.com;user=phone
To: sip:+1-650-555-2222@ss1.wcom.com;user=phone
Call-ID: 1717@ift.here.com
CSeq: 56 INVITE
Content-Type: application/sdp
Content-Length: 320
v=0
o=faxgw1 2890844527 2890844527 IN IP4 iftgw.there.com
s=Session SDP
c=IN IP4 iftmg.there.com
t=0 0
m=image 49172 udptl t38
a=T38FaxVersion:0
a=T38maxBitRate:14400
a=T38FaxFillBitRemoval:0
a=T38FaxTranscodingMMR:0
a=T38FaxTranscodingJBIG:0
a=T38FaxRateManagement:transferredTCF
a=T38FaxMaxBuffer:260
a=T38FaxUdpEC:t38UDPRedundancy

9
sip_messages/test37.txt Normal file
View File

@ -0,0 +1,9 @@
REGISTER sip:bell-tel.com SIP/2.0
Via: SIP/2.0/UDP saturn.bell-tel.com
From: sip:watson@bell-tel.com
To: sip:watson@bell-tel.com
Call-ID: 70710@saturn.bell-tel.com
CSeq: 2 REGISTER
Contact: sip:+1-972-555-2222@gw1.wcom.com;user=phone

9
sip_messages/test38.txt Normal file
View File

@ -0,0 +1,9 @@
REGISTER sip:bell-tel.com SIP/2.0
Via: SIP/2.0/UDP saturn.bell-tel.com
From: sip:watson@bell-tel.com
To: sip:watson@bell-tel.com
Call-ID: 70710@saturn.bell-tel.com
CSeq: 3 REGISTER
Contact: <sip:+1-972-555-2222@gw1.wcom.com;user=phone>

8
sip_messages/test39.txt Normal file
View File

@ -0,0 +1,8 @@
INVITE sip:t.watson@ieee.org SIP/2.0
Via: SIP/2.0/UDP c.bell-tel.com
From: A. Bell <sip:a.g.bell@bell-tel.com>
To: T. Watson <sip:t.watson@ieee.org>
Call-ID: 31414@c.bell-tel.com
CSeq: 1 INVITE

8
sip_messages/test40.txt Normal file
View File

@ -0,0 +1,8 @@
INVITE sip:t.watson@ieee.org SIP/2.0
Via: SIP/2.0/UDP c.bell-tel.com
From: Bell, Alexander <sip:a.g.bell@bell-tel.com>
To: Watson, Thomas <sip:t.watson@ieee.org>
Call-ID: 31415@c.bell-tel.com
CSeq: 1 INVITE

8
sip_messages/test41.txt Normal file
View File

@ -0,0 +1,8 @@
INVITE sip:t.watson@ieee.org SIP/02.00
Via: SIP/2.0/UDP c.bell-tel.com
From: A. Bell <sip:a.g.bell@bell-tel.com>
To: T. Watson <sip:t.watson@ieee.org>
Call-ID: 31416@c.bell-tel.com
CSeq: 1 INVITE

11
sip_messages/test42.txt Normal file
View File

@ -0,0 +1,11 @@
INVITE sip:t.watson@ieee.org SIP/7.0
Via: SIP/2.0/UDP c.bell-tel.com
From: A. Bell <sip:a.g.bell@bell-tel.com>
To: T. Watson <sip:t.watson@ieee.org>
Call-ID: 31417@c.bell-tel.com
CSeq: 1 INVITE

Binary file not shown.