diff --git a/main.go b/main.go index 3372989..b6f6dde 100644 --- a/main.go +++ b/main.go @@ -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 + } + } } \ No newline at end of file diff --git a/sip_messages/test21.txt b/sip_messages/test21.txt new file mode 100644 index 0000000..c4e4857 --- /dev/null +++ b/sip_messages/test21.txt @@ -0,0 +1,19 @@ +INVITE 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 + + diff --git a/sip_messages/test22.txt b/sip_messages/test22.txt new file mode 100644 index 0000000..088fc28 --- /dev/null +++ b/sip_messages/test22.txt @@ -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 + + + diff --git a/sip_messages/test23.txt b/sip_messages/test23.txt new file mode 100644 index 0000000..162c8fd --- /dev/null +++ b/sip_messages/test23.txt @@ -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 + + diff --git a/sip_messages/test24.txt b/sip_messages/test24.txt new file mode 100644 index 0000000..4f4ef6e --- /dev/null +++ b/sip_messages/test24.txt @@ -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 + + diff --git a/sip_messages/test25.txt b/sip_messages/test25.txt new file mode 100644 index 0000000..75ab015 --- /dev/null +++ b/sip_messages/test25.txt @@ -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 + + diff --git a/sip_messages/test26.txt b/sip_messages/test26.txt new file mode 100644 index 0000000..2ca0b02 --- /dev/null +++ b/sip_messages/test26.txt @@ -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 + + diff --git a/sip_messages/test27.txt b/sip_messages/test27.txt new file mode 100644 index 0000000..f4624a8 --- /dev/null +++ b/sip_messages/test27.txt @@ -0,0 +1,8 @@ +OPTIONS sip:user@company.com SIP/2.0 +To: sip:user@company.com +From: "caller" +Call-ID: 1234abcd@10.0.0.1 +CSeq: 1 OPTIONS +Via: SIP/2.0/UDP 135.180.130.133 + + diff --git a/sip_messages/test28.txt b/sip_messages/test28.txt new file mode 100644 index 0000000..24b4cb4 --- /dev/null +++ b/sip_messages/test28.txt @@ -0,0 +1,8 @@ +OPTIONS sip:user@company.com SIP/2.0 +To: sip:user@company.com +From: "caller" +Call-ID: 1234abcd@10.0.0.1 +CSeq: 2 OPTIONS +Via: SIP/2.0/UDP 135.180.130.133 + + diff --git a/sip_messages/test29.txt b/sip_messages/test29.txt new file mode 100644 index 0000000..b41e1e2 --- /dev/null +++ b/sip_messages/test29.txt @@ -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 + + diff --git a/sip_messages/test30.txt b/sip_messages/test30.txt new file mode 100644 index 0000000..d43f98d --- /dev/null +++ b/sip_messages/test30.txt @@ -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 + + diff --git a/sip_messages/test31.txt b/sip_messages/test31.txt new file mode 100644 index 0000000..6f3c92a --- /dev/null +++ b/sip_messages/test31.txt @@ -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 + + diff --git a/sip_messages/test32.txt b/sip_messages/test32.txt new file mode 100644 index 0000000..c06b71b --- /dev/null +++ b/sip_messages/test32.txt @@ -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: + + diff --git a/sip_messages/test33.txt b/sip_messages/test33.txt new file mode 100644 index 0000000..6168d76 --- /dev/null +++ b/sip_messages/test33.txt @@ -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 + + diff --git a/sip_messages/test34.txt b/sip_messages/test34.txt new file mode 100644 index 0000000..40bdbca --- /dev/null +++ b/sip_messages/test34.txt @@ -0,0 +1,52 @@ +INVITE sip:user@company.com SIP/2.0 +To: "I have a user name of extreme proportion" +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 + + diff --git a/sip_messages/test35.txt b/sip_messages/test35.txt new file mode 100644 index 0000000..bbc6b3a --- /dev/null +++ b/sip_messages/test35.txt @@ -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 + + diff --git a/sip_messages/test36.txt b/sip_messages/test36.txt new file mode 100644 index 0000000..0262d44 --- /dev/null +++ b/sip_messages/test36.txt @@ -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 + + diff --git a/sip_messages/test37.txt b/sip_messages/test37.txt new file mode 100644 index 0000000..70f69fc --- /dev/null +++ b/sip_messages/test37.txt @@ -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 + + diff --git a/sip_messages/test38.txt b/sip_messages/test38.txt new file mode 100644 index 0000000..a15705b --- /dev/null +++ b/sip_messages/test38.txt @@ -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: + + diff --git a/sip_messages/test39.txt b/sip_messages/test39.txt new file mode 100644 index 0000000..882c669 --- /dev/null +++ b/sip_messages/test39.txt @@ -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 +To: T. Watson +Call-ID: 31414@c.bell-tel.com +CSeq: 1 INVITE + + diff --git a/sip_messages/test40.txt b/sip_messages/test40.txt new file mode 100644 index 0000000..08ddecc --- /dev/null +++ b/sip_messages/test40.txt @@ -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 +To: Watson, Thomas +Call-ID: 31415@c.bell-tel.com +CSeq: 1 INVITE + + diff --git a/sip_messages/test41.txt b/sip_messages/test41.txt new file mode 100644 index 0000000..170805e --- /dev/null +++ b/sip_messages/test41.txt @@ -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 +To: T. Watson +Call-ID: 31416@c.bell-tel.com +CSeq: 1 INVITE + + diff --git a/sip_messages/test42.txt b/sip_messages/test42.txt new file mode 100644 index 0000000..d6bd86c --- /dev/null +++ b/sip_messages/test42.txt @@ -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 +To: T. Watson +Call-ID: 31417@c.bell-tel.com +CSeq: 1 INVITE + + + + + diff --git a/sip_parser b/sip_parser index 9395825..223f6df 100755 Binary files a/sip_parser and b/sip_parser differ