public void ContentLengthCompactParseFromSingleRequestTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string notifyRequest =
                @"NOTIFY sip:10.1.1.5:62647;transport=tcp SIP/2.0" + CRLF +
                "Via: SIP/2.0/TCP 10.1.1.5:4506;branch=z9hG4bKa4d17f991015b1d8b788f2ac54d66ec66811226a;rport" + CRLF +
                "Via: SIP/2.0/UDP 127.0.0.1:5060;branch=z9hG4bKc2224b79f5af4c4a9b1cd649890c6497;rport" + CRLF +
                "Via: SIP/2.0/UDP 127.0.0.1:5003;branch=z9hG4bK0495dc29b7eb40008779a75c3734c4c5;rport=5003;received=127.0.0.1" + CRLF +
                "To: <sip:10.1.1.5:62647;transport=tcp>;tag=1892981968" + CRLF +
                "From: <sip:127.0.0.1:5003>;tag=1555449860" + CRLF +
                "Call-ID: 1b569032-d1e4-4869-be9f-67d4ba8a4e3a" + CRLF +
                "CSeq: 4 NOTIFY" + CRLF +
                "l: 2393" + CRLF +
                "Contact: <sip:127.0.0.1:5003>" + CRLF +
                "Max-Forwards: 69" + CRLF +
                "Event: dialog" + CRLF + CRLF;

            byte[] notifyRequestBytes = UTF8Encoding.UTF8.GetBytes(notifyRequest);

            int contentLength = SIPMessage.GetContentLength(notifyRequestBytes, 0, notifyRequestBytes.Length);

            Console.WriteLine("Content-Length " + contentLength + ".");

            Assert.IsTrue(contentLength == 2393, "The content length was parsed incorrectly.");
        }
        public void ParseRequestBytesReadShortTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string testReceive =
                @"SUBSCRIBE sip:[email protected] SIP/2.0
Via: SIP/2.0/TCP 10.1.1.5:62647;branch=z9hG4bKa58b912c426f415daa887289efda50cd;rport
To: <sip:[email protected]>
From: <sip:[email protected]>;tag=1902440575
Call-ID: 1b569032-d1e4-4869-be9f-67d4ba8a4e3a
CSeq: 3 SUBSCRIBE
Contact: <sip:10.1.1.5:62647;transport=tcp>
Max-Forwards: 70
Expires: 600
Content-Length: 15
Content-Type: text/text
Event: dialog

include                                               ";

            byte[] testReceiveBytes = UTF8Encoding.UTF8.GetBytes(testReceive);
            byte[] request1Bytes    = SIPMessage.ParseSIPMessageFromStream(testReceiveBytes, 0, testReceiveBytes.Length - 100, out _);

            Assert.IsNull(request1Bytes, "A request array should not have been returned.");
        }
        public void ParseRequestOneByteExtraTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string testReceive =
                @"SUBSCRIBE sip:[email protected] SIP/2.0" + CRLF +
                "Via: SIP/2.0/TCP 10.1.1.5:62647;branch=z9hG4bKa58b912c426f415daa887289efda50cd;rport" + CRLF +
                "To: <sip:[email protected]>" + CRLF +
                "From: <sip:[email protected]>;tag=1902440575" + CRLF +
                "Call-ID: 1b569032-d1e4-4869-be9f-67d4ba8a4e3a" + CRLF +
                "CSeq: 3 SUBSCRIBE" + CRLF +
                "Contact: <sip:10.1.1.5:62647;transport=tcp>" + CRLF +
                "Max-Forwards: 70" + CRLF +
                "Expires: 600" + CRLF +
                "Content-Length: 15" + CRLF +
                "Content-Type: text/text" + CRLF +
                "Event: dialog" + CRLF +
                CRLF +
                "includesdp=true!";

            byte[] testReceiveBytes = UTF8Encoding.UTF8.GetBytes(testReceive);
            byte[] request1Bytes    = SIPMessage.ParseSIPMessageFromStream(testReceiveBytes, 0, testReceiveBytes.Length, out _);

            Assert.IsTrue(request1Bytes.Length == testReceiveBytes.Length - 1, "The parsed bytes was an incorrect length.");
        }
        public void ParseRequestWithLeadingNATKeepAliveBytesTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string testReceive =
                @"    SUBSCRIBE sip:[email protected] SIP/2.0" + CRLF +
                "Via: SIP/2.0/TCP 10.1.1.5:62647;branch=z9hG4bKa58b912c426f415daa887289efda50cd;rport" + CRLF +
                "To: <sip:[email protected]>" + CRLF +
                "From: <sip:[email protected]>;tag=1902440575" + CRLF +
                "Call-ID: 1b569032-d1e4-4869-be9f-67d4ba8a4e3a" + CRLF +
                "CSeq: 3 SUBSCRIBE" + CRLF +
                "Contact: <sip:10.1.1.5:62647;transport=tcp>" + CRLF +
                "Max-Forwards: 70" + CRLF +
                "Expires: 600" + CRLF +
                "Content-Length: 15" + CRLF +
                "Content-Type: text/text" + CRLF +
                "Event: dialog" + CRLF +
                CRLF +
                "includesdp=true";

            byte[] testReceiveBytes = UTF8Encoding.UTF8.GetBytes(testReceive);

            int skippedBytes = 0;

            byte[] request1Bytes = SIPMessage.ParseSIPMessageFromStream(testReceiveBytes, 0, testReceiveBytes.Length, out skippedBytes);

            Console.WriteLine(Encoding.UTF8.GetString(request1Bytes));

            Assert.IsNotNull(request1Bytes, "The parsed bytes should have been populated.");
            Assert.IsTrue(skippedBytes == 4, "The number of skipped bytes was incorrect.");
        }
        public void ParseMultipleContactsResponse()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg =
                "SIP/2.0 200 OK" + m_CRLF +
                "Via: SIP/2.0/UDP 192.168.1.32:64226;branch=z9hG4bK-d87543-ac7a6a75bc519655-1--d87543-;rport=64226;received=89.100.104.191" + m_CRLF +
                "To: \"253989\"<sip:[email protected]>;tag=cb2000b247d89723001a836145f3b053.5b6c" + m_CRLF +
                "From: \"253989\"<sip:[email protected]>;tag=9812dd2f" + m_CRLF +
                "Call-ID: ODllYWY1NDJiNGMwYmQ1MjVmZmViMmEyMDViMGM0Y2Y." + m_CRLF +
                "CSeq: 2 REGISTER" + m_CRLF +
                "Date: Fri, 17 Nov 2006 17:15:35 GMT" + m_CRLF +
                "Contact: <sip:[email protected]>;q=0.1;expires=3298, \"Joe Bloggs\"<sip:[email protected]:64226;rinstance=5720c5fed8cbcd34>;q=0.1;expires=3600" + m_CRLF +
                "Content-Length: 0" + m_CRLF + m_CRLF;

            SIPMessage  sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
            SIPResponse okResp     = SIPResponse.ParseSIPResponse(sipMessage);

            Console.WriteLine("To: " + okResp.Header.To.ToString());

            Assert.AreEqual(SIPResponseStatusCodesEnum.Ok, okResp.Status, "Response should have been ok.");
            Assert.AreEqual(okResp.Header.Contact.Count, 2, "Response should have had two contacts.");
            Assert.AreEqual(okResp.Header.Contact[0].ContactURI.ToString(), "sip:[email protected]", "The contact URI for the first contact header was incorrect.");
            Assert.AreEqual(okResp.Header.Contact[0].Expires, 3298, "The expires value for the first contact header was incorrect.");
            Assert.AreEqual(okResp.Header.Contact[0].Q, "0.1", "The q value for the first contact header was incorrect.");
            Assert.AreEqual(okResp.Header.Contact[1].ContactName, "Joe Bloggs", "The contact name for the first contact header was incorrect.");
            Assert.AreEqual(okResp.Header.Contact[1].ContactURI.ToString(), "sip:[email protected]:64226;rinstance=5720c5fed8cbcd34", "The contact URI for the first contact header was incorrect.");
            Assert.AreEqual(okResp.Header.Contact[1].Expires, 3600, "The expires value for the second contact header was incorrect.");
            Assert.AreEqual(okResp.Header.Contact[1].Q, "0.1", "The q value for the second contact header was incorrect.");
            Console.WriteLine("-----------------------------------------");
        }
        public void TestProcessRecevieWithBytesToSkipTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string testReceive =
                "            SUBSCRIBE sip:[email protected] SIP/2.0" + CRLF +
                "Via: SIP/2.0/TCP 10.1.1.5:62647;branch=z9hG4bKa58b912c426f415daa887289efda50cd;rport" + CRLF +
                "To: <sip:[email protected]>" + CRLF +
                "From: <sip:[email protected]>;tag=1902440575" + CRLF +
                "Call-ID: 1b569032-d1e4-4869-be9f-67d4ba8a4e3a" + CRLF +
                "CSeq: 3 SUBSCRIBE" + CRLF +
                "Contact: <sip:10.1.1.5:62647;transport=tcp>" + CRLF +
                "Max-Forwards: 70" + CRLF +
                "Expires: 600" + CRLF +
                "Content-Length: 15" + CRLF +
                "Content-Type: text/text" + CRLF +
                "Event: dialog" + CRLF +
                CRLF +
                "includesdp=true";

            byte[] testReceiveBytes = UTF8Encoding.UTF8.GetBytes(testReceive);

            int bytesSkipped = 0;

            byte[] result = SIPMessage.ParseSIPMessageFromStream(testReceiveBytes, 0, testReceiveBytes.Length, out bytesSkipped);

            Assert.IsNotNull(result, "The resultant array should not have been null.");
            Assert.IsTrue(bytesSkipped == 12, "The bytes skipped was incorrect.");
        }
        public void ParseMissingCSeqOptionsResponse()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg =
                "SIP/2.0 200 OK" + m_CRLF +
                "To: <sip:[email protected]:5060>;tag=eba877fbb8dd284bi0" + m_CRLF +
                "From: <sip:213.168.225.133:5060>;tag=5880003940" + m_CRLF +
                "Call-ID: [email protected]" + m_CRLF +
                "Via: SIP/2.0/UDP 213.168.225.133:5060;branch=z9hG4bK1702000048" + m_CRLF +
                "Server: Linksys/RT31P2-2.0.10(LIc)" + m_CRLF +
                "Content-Length: 0" + m_CRLF +
                "Allow: ACK, BYE, CANCEL, INFO, INVITE, NOTIFY, OPTIONS, REFER" + m_CRLF +
                "Supported: x-sipura" + m_CRLF + m_CRLF;

            SIPMessage  sipMessage  = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
            SIPResponse optionsResp = SIPResponse.ParseSIPResponse(sipMessage);

            Console.WriteLine("CSeq=" + optionsResp.Header.CSeq + ".");
            Console.WriteLine("CSeq Method=" + optionsResp.Header.CSeqMethod + ".");

            Assert.IsTrue(optionsResp.Header.CSeq == -1, "Response CSeq was incorrect.");
            Assert.IsTrue(optionsResp.Header.CSeqMethod == SIPMethodsEnum.NONE, "Response CSeq method was incorrect.");

            Console.WriteLine("-----------------------------------------");
        }
Exemple #8
0
        public void VerifyCustomHeadersNotPresentWithEmptyDictionary()
        {
            SIPMessage message = SIPMessage.Faker.Generate(1).First();

            Assert.DoesNotContain("X-Test-Case: 1", message.ToString());
            Assert.DoesNotContain("X-", message.ToString());
        }
        public void ParseOptionsBodyResponse()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg = "SIP/2.0 200 OK" + m_CRLF +
                            "Via: SIP/2.0/UDP 213.168.225.133:5060;branch=z9hG4bK10a1fab0" + m_CRLF +
                            "From: \"Unknown\" <sip:[email protected]>;tag=as18338373" + m_CRLF +
                            "To: <sip:[email protected]>;tag=OLg-20481" + m_CRLF +
                            "Call-ID: [email protected]" + m_CRLF +
                            "CSeq: 102 OPTIONS" + m_CRLF +
                            "content-type: application/sdp" + m_CRLF +
                            "Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, INFO, REFER, NOTIFY" + m_CRLF +
                            "Content-Length: 217" + m_CRLF +
                            m_CRLF +
                            "v=0" + m_CRLF +
                            "o=0 5972727 56415 IN IP4 0.0.0.0" + m_CRLF +
                            "s=SIP Call" + m_CRLF +
                            "c=IN IP4 0.0.0.0" + m_CRLF +
                            "t=0 0" + m_CRLF +
                            "m=audio 0 RTP/AVP 18 0 8 4 2" + m_CRLF +
                            "a=rtpmap:18 G729/8000" + m_CRLF +
                            "a=rtpmap:0 pcmu/8000" + m_CRLF +
                            "a=rtpmap:8 pcma/8000" + m_CRLF +
                            "a=rtpmap:4 g723/8000" + m_CRLF +
                            "a=rtpmap:2 g726/8000" + m_CRLF;

            SIPMessage  sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
            SIPResponse okResp     = SIPResponse.ParseSIPResponse(sipMessage);

            Assert.IsTrue(okResp.Status == SIPResponseStatusCodesEnum.Ok, "The SIP response status was not parsed correctly.");
            Assert.IsTrue(okResp.Body.Length == 217, "The SIP response body length was not correct.");

            Console.WriteLine("-----------------------------------------");
        }
Exemple #10
0
        public void AllowMaxForwardsofZero()
        {
            SIPMessage message = SIPMessage.Faker.Generate(1).First();

            message.Header.MaxForwards = 0;

            Assert.Contains("Max-Forwards", message.ToString());
        }
Exemple #11
0
        public void BranchHasSemicolonIfTagPresent()
        {
            SIPMessage message = SIPMessage.Faker.Generate(1).First();

            message.Header.From.Tag = "iamabanana";

            Assert.Contains(";", message.Header.From.ToString());
        }
Exemple #12
0
        public void BranchDoesNotHaveSemicolonIfTagNull()
        {
            SIPMessage message = SIPMessage.Faker.Generate(1).First();

            message.Header.From.Tag = null;

            Assert.DoesNotContain(";", message.Header.From.ToString());
        }
Exemple #13
0
        public SIPRequest ParseSIPRequest(string sipRequestStr)
        {
            // Strings from Rich text boxes use a \n end of line character.
            sipRequestStr = Regex.Replace(sipRequestStr, "\n", "\r\n");
            sipRequestStr = Regex.Replace(sipRequestStr, "\r\r", "\r");

            SIPMessage sipMessage = SIPMessage.ParseSIPMessage(sipRequestStr, null, null);

            return(SIPRequest.ParseSIPRequest(sipMessage));
        }
Exemple #14
0
        public void EnsureValidPhoneFromFaker()
        {
            SIPMessage message = SIPMessage.Faker.Generate(1).First();

            Assert.NotNull(message.RequestLine.RequestURI.UserPart);
            //https://stackoverflow.com/questions/2113908/what-regular-expression-will-match-valid-international-phone-numbers : Updated to make the international identifiers optional
            Regex PhoneRegex = new Regex(@"^\+?(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)?\d{1,14}$");

            Assert.Matches(PhoneRegex, message.RequestLine.RequestURI.UserPart);
        }
Exemple #15
0
        public void CustomHeadersAreRendered()
        {
            SIPMessage message = SIPMessage.Faker.Generate(1).First();
            Dictionary <string, string> CustomHeaders = new Dictionary <string, string>();

            CustomHeaders.Add("Test-Case", "1");

            message.Header.CustomHeaders = CustomHeaders;

            Assert.Contains("X-Test-Case: 1", message.ToString());
        }
Exemple #16
0
        public void ContentLengthSetTest()
        {
            SIPMessage testmessage = SIPMessage.Faker.Generate(1).First();

            if (testmessage.Body != null)
            {
                Assert.True(testmessage.Header.ContentLength > 0);
                Assert.True(testmessage.Header.ContentLength == Encoding.UTF8.GetByteCount(testmessage.Body.ToString()));
            }
            else
            {
                Assert.True(testmessage.Header.ContentLength == 0);
            }
        }
Exemple #17
0
        public void TestMethod1()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg =
                @"INVITE sip:[email protected];unknownparam SIP/2.0
        TO :
        sip:[email protected] ;   tag    = 1918181833n
        from   : ""J Rosenberg \\\""""       <sip:[email protected]>
        ;
        tag = 98asjd8
        MaX-fOrWaRdS: 0068
        Call-ID: [email protected]
        Content-Length   : 150
        cseq: 0009
        INVITE
        Via  : SIP  /   2.0
        /UDP
        192.0.2.2;branch=390skdjuw
        s :
        NewFangledHeader:   newfangled value
        continued newfangled value
        UnknownHeaderWithUnusualValue: ;;,,;;,;
        Content-Type: application/sdp
        Route:
        <sip:services.example.com;lr;unknownwith=value;unknown-no-value>
        v:  SIP  / 2.0  / TCP     spindle.example.com   ;
        branch  =   z9hG4bK9ikj8  ,
        SIP  /    2.0   / UDP  192.168.255.111   ; branch=
        z9hG4bK30239
        m:""Quoted string \""\"""" <sip:[email protected]> ; newparam =
        newvalue ;
        secondparam ; q = 0.33

        v=0
      o=mhandley 29739 7272939 IN IP4 192.0.2.3
      s=-
      c=IN IP4 192.0.2.4
      t=0 0
      m=audio 49217 RTP/AVP 0 12
      m=video 3227 RTP/AVP 31
      a=rtpmap:31 LPC";

            SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
            SIPRequest inviteReq  = SIPRequest.ParseSIPRequest(sipMessage);

            Console.WriteLine(inviteReq.ToString());

            Console.WriteLine("-----------------------------------------");
        }
Exemple #18
0
        public void VerifyNoContentLengthIfBodyNotPresent()
        {
            Faker <SIPMessage> CustomFaker = new Faker <SIPMessage>()
                                             .StrictMode(false)
                                             .RuleFor(o => o.Body, f => null)
                                             .RuleFor(o => o.RequestLine, f => RequestLine.Faker.Generate(1).First())
                                             .RuleFor(o => o.Header, f => MessageHeader.Faker.Generate(1).First());

            SIPMessage.SetCustomFaker(CustomFaker);

            Assert.Equal(CustomFaker, SIPMessage.Faker);

            SIPMessage TestMessage = SIPMessage.Faker.Generate(1).First();

            Assert.Null(TestMessage.Body);
            Assert.DoesNotContain("Content-Length", TestMessage.ToString());
        }
        public void ParseMultiLineRecordRouteResponse()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg =
                "SIP/2.0 200 OK" + m_CRLF +
                "Via: SIP/2.0/UDP 10.0.0.100:5060;rport=61540;branch=z9hG4bK40661a8b4a2d4973ae75fa52f1940383" + m_CRLF +
                "From: <sip:[email protected]>;tag=1014391101" + m_CRLF +
                "To: <sip:[email protected]>;tag=gj-2k5-490f768a-00005cf1-00002e1aR2f0f2383.b" + m_CRLF +
                "Call-ID: 1960514b216a465fb900e2966d30e9bb" + m_CRLF +
                "CSeq: 2 INVITE" + m_CRLF +
                "Record-Route: <sip:77.75.25.44:5060;lr=on>" + m_CRLF +
                "Record-Route: <sip:77.75.25.45:5060;lr=on;ftag=1014391101>" + m_CRLF +
                "Accept: application/sdp, application/isup, application/dtmf, application/dtmf-relay,  multipart/mixed" + m_CRLF +
                "Contact: <sip:[email protected]:5060>" + m_CRLF +
                "Allow: INVITE,ACK,CANCEL,BYE,REGISTER,REFER,INFO,SUBSCRIBE,NOTIFY,PRACK,UPDATE,OPTIONS" + m_CRLF +
                "Supported: timer" + m_CRLF +
                "Session-Expires: 600;refresher=uas" + m_CRLF +
                "Content-Length:  232" + m_CRLF +
                "Content-Disposition: session; handling=required" + m_CRLF +
                "Content-Type: application/sdp" + m_CRLF +
                m_CRLF +
                "v=0" + m_CRLF +
                "o=Sonus_UAC 4125 3983 IN IP4 64.152.60.78" + m_CRLF +
                "s=SIP Media Capabilities" + m_CRLF +
                "c=IN IP4 64.152.60.164" + m_CRLF +
                "t=0 0" + m_CRLF +
                "m=audio 19144 RTP/AVP 0 101" + m_CRLF +
                "a=rtpmap:0 PCMU/8000" + m_CRLF +
                "a=rtpmap:101 telephone-event/8000" + m_CRLF +
                "a=fmtp:101 0-15" + m_CRLF +
                "a=sendrecv" + m_CRLF +
                "a=ptime:20" + m_CRLF;

            SIPMessage  sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
            SIPResponse okResp     = SIPResponse.ParseSIPResponse(sipMessage);

            Assert.IsTrue(okResp.Header.RecordRoutes.Length == 2, "The wrong number of Record-Route headers were present in the parsed response.");
            Assert.IsTrue(okResp.Header.RecordRoutes.PopRoute().ToString() == "<sip:77.75.25.44:5060;lr=on>", "The top Record-Route header was incorrect.");
            SIPRoute nextRoute = okResp.Header.RecordRoutes.PopRoute();

            Assert.IsTrue(nextRoute.ToString() == "<sip:77.75.25.45:5060;lr=on;ftag=1014391101>", "The second Record-Route header was incorrect, " + nextRoute.ToString() + ".");

            Console.WriteLine("-----------------------------------------");
        }
Exemple #20
0
        [Ignore] // Bit trickier to pass than anticipated.
        public void ShortTorturousInvite()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            Assert.IsTrue(File.Exists("wsinv.dat"), "The wsinv.dat torture test input file was missing.");

            string raw = File.ReadAllText("wsinv.dat");

            logger.LogDebug(raw);

            SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(raw), null, null);
            SIPRequest inviteReq  = SIPRequest.ParseSIPRequest(raw);

            Assert.IsNotNull(sipMessage, "The SIP message could not be parsed.");
            Assert.IsNotNull(inviteReq, "The SIP request could not be parsed.");

            logger.LogDebug("-----------------------------------------");
        }
        public void ParseAsteriskOKUnitTest()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg =
                "SIP/2.0 200 OK" + m_CRLF +
                "Via: SIP/2.0/UDP 213.168.225.135:5060;branch=z9hG4bKT36BdhXPlT5cqPFQQr81yMmZ37U=" + m_CRLF +
                "Via: SIP/2.0/UDP 192.168.1.2:5065;received=220.240.255.198:64216;branch=z9hG4bK7D8B6549580844AEA104BD4A837049DD" + m_CRLF +
                "From: bluesipd <sip:bluesipd@bluesipd:5065>;tag=630217013" + m_CRLF +
                "To: <sip:303@bluesipd>;tag=as46f418e9" + m_CRLF +
                "Call-ID: [email protected]" + m_CRLF +
                "CSeq: 27481 INVITE" + m_CRLF +
                "User-Agent: asterisk" + m_CRLF +
                "Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY" + m_CRLF +
                "Contact: <sip:[email protected]>" + m_CRLF +
                "Content-Type: application/sdp" + m_CRLF +
                "Content-Length: 352" + m_CRLF +
                m_CRLF +
                "v=0" + m_CRLF +
                "o=root 24710 24712 IN IP4 213.168.225.133" + m_CRLF +
                "s=session" + m_CRLF +
                "c=IN IP4 213.168.225.133" + m_CRLF +
                "t=0 0" + m_CRLF +
                "m=audio 18656 RTP/AVP 0 8 18 3 97 111 101" + m_CRLF +
                "a=rtpmap:0 PCMU/8000" + m_CRLF +
                "a=rtpmap:8 PCMA/8000" + m_CRLF +
                "a=rtpmap:18 G729/8000" + m_CRLF +
                "a=rtpmap:3 GSM/8000" + m_CRLF +
                "a=rtpmap:97 iLBC/8000" + m_CRLF +
                "a=rtpmap:111 G726-32/8000" + m_CRLF +
                "a=rtpmap:101 telephone-event/8000" + m_CRLF +
                "a=fmtp:101 0-16" + m_CRLF +
                "a=silenceSupp:off - - - -" + m_CRLF;

            SIPMessage  sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
            SIPResponse okResp     = SIPResponse.ParseSIPResponse(sipMessage);

            Assert.IsTrue(okResp.Status == SIPResponseStatusCodesEnum.Ok, "The SIP response status was not parsed correctly.");
            Assert.IsTrue(okResp.Body.Length == 352, "The SIP response body length was not correct.");

            Console.WriteLine("-----------------------------------------");
        }
        public void ParseMultiLineViaResponse()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg =
                "SIP/2.0 200 OK" + m_CRLF +
                "Via: SIP/2.0/UDP 194.213.29.100:5060;branch=z9hG4bK5feb18267ce40fb05969b4ba843681dbfc9ffcff, SIP/2.0/UDP 194.213.29.54:5061;branch=z9hG4bK52b6a8b7" + m_CRLF +
                "Record-Route: <sip:194.213.29.100:5060;lr>" + m_CRLF +
                "From: Unknown <sip:[email protected]:5061>;tag=as58cbdbd1" + m_CRLF +
                "To: <sip:[email protected]:5060>;tag=1144090013" + m_CRLF +
                "Call-ID: [email protected]" + m_CRLF +
                "CSeq: 102 INVITE" + m_CRLF +
                "Contact: <sip:[email protected]:5060>" + m_CRLF +
                "Server: Patton SN4634 3BIS 00A0BA04469B R5.3 2009-01-15 H323 SIP BRI M5T SIP Stack/4.0.28.28" + m_CRLF +
                "Supported: replaces" + m_CRLF +
                "Content-Type: application/sdp" + m_CRLF +
                "Content-Length: 298" + m_CRLF +
                m_CRLF +
                "v=0" + m_CRLF +
                "o=MxSIP 0 56 IN IP4 10.10.10.155" + m_CRLF +
                "s=SIP Call" + m_CRLF +
                "c=IN IP4 10.10.10.155" + m_CRLF +
                "t=0 0" + m_CRLF +
                "m=audio 4974 RTP/AVP 0 18 8 101" + m_CRLF +
                "a=rtpmap:0 PCMU/8000" + m_CRLF +
                "a=rtpmap:18 G729/8000" + m_CRLF +
                "a=rtpmap:8 PCMA/8000" + m_CRLF +
                "a=rtpmap:101 telephone-event/8000" + m_CRLF +
                "a=fmtp:18 annexb=no" + m_CRLF +
                "a=fmtp:101 0-16" + m_CRLF +
                "a=sendrecv" + m_CRLF +
                "m=video 0 RTP/AVP 31 34 103 99";

            SIPMessage  sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
            SIPResponse okResp     = SIPResponse.ParseSIPResponse(sipMessage);

            Assert.IsTrue(okResp.Header.Vias.Length == 2, "The wrong number of Record-Route headers were present in the parsed response.");
            Assert.IsTrue(okResp.Header.Vias.TopViaHeader.ContactAddress == "194.213.29.100:5060", "The top via contact address was not ocrrectly parsed.");

            Console.WriteLine("-----------------------------------------");
        }
        public void ParseMSCOkResponse()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg =
                "SIP/2.0 200 OK" + m_CRLF +
                "From: Blue Face<sip:[email protected]>;tag=as5fd53de7" + m_CRLF +
                "To: sip:[email protected];tag=MTHf2-ol1Yn0" + m_CRLF +
                "Call-ID: [email protected]:5061" + m_CRLF +
                "CSeq: 102 INVITE" + m_CRLF +
                "Via: SIP/2.0/UDP 213.168.225.133:5060;branch=z9hG4bKG+WGOVwLyT6vOW9s" + m_CRLF +
                "Via: SIP/2.0/UDP 213.168.225.133:5061;branch=z9hG4bK09db9c73" + m_CRLF +
                "Contact: +3535xxx<sip:[email protected]:5061>" + m_CRLF +
                "User-Agent: MSC/VC510  Build-Date Nov  7 2005" + m_CRLF +
                "Allow: INVITE,BYE,CANCEL,OPTIONS,PRACK,NOTIFY,UPDATE,REFER" + m_CRLF +
                "Supported: timer,replaces" + m_CRLF +
                "Record-Route: <sip:213.168.225.133:5060;lr>,<sip:213.168.225.133:5061;lr>" + m_CRLF +
                "Content-Type: application/sdp" + m_CRLF +
                "Content-Length: 182" + m_CRLF +
                m_CRLF +
                "v=0" + m_CRLF +
                "o=xxxxxxxxx 75160 1 IN IP4 127.127.127.30" + m_CRLF +
                "s=-" + m_CRLF +
                "c=IN IP4 127.127.127.30" + m_CRLF +
                "t=0 0" + m_CRLF +
                "m=audio 8002 RTP/AVP 0 101" + m_CRLF +
                "a=rtpmap:0 PCMU/8000" + m_CRLF +
                "a=rtpmap:101 telephone-event/8000" + m_CRLF +
                "a=ptime:20";

            SIPMessage  sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
            SIPResponse okResp     = SIPResponse.ParseSIPResponse(sipMessage);

            Console.WriteLine("To: " + okResp.Header.To.ToString());

            Assert.AreEqual(SIPResponseStatusCodesEnum.Ok, okResp.Status, "Response should have been ok.");
            Assert.AreEqual("127.0.0.1", okResp.Header.To.ToURI.Host, "To URI host was not parsed correctly.");

            Console.WriteLine("-----------------------------------------");
        }
        public void ParseForbiddenResponse()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg = "SIP/2.0 403 Forbidden" + m_CRLF +
                            "Via: SIP/2.0/UDP 192.168.1.1;branch=z9hG4bKbcb78f72d221beec" + m_CRLF +
                            "From: <sip:sip.blueface.ie>;tag=9a4c86234adcc297" + m_CRLF +
                            "To: <sip:sip.blueface.ie>;tag=as6900b876" + m_CRLF +
                            "Call-ID: [email protected]" + m_CRLF +
                            "CSeq: 100 REGISTER" + m_CRLF +
                            "User-Agent: asterisk" + m_CRLF +
                            "Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY" + m_CRLF +
                            "Contact: <sip:[email protected]>" + m_CRLF +
                            "Content-Length: 0" + m_CRLF + m_CRLF;

            SIPMessage  sipMessage    = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
            SIPResponse forbiddenResp = SIPResponse.ParseSIPResponse(sipMessage);

            Assert.IsTrue(forbiddenResp.Status == SIPResponseStatusCodesEnum.Forbidden, "The SIP response status was not parsed correctly.");

            Console.WriteLine("-----------------------------------------");
        }
        public void ParseReceiveNoContentLengthHeaderRequestTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string notifyRequest =
                "NOTIFY sip:10.1.1.5:62647;transport=tcp SIP/2.0" + CRLF +
                "Via: SIP/2.0/TCP 10.1.1.5:4506;branch=z9hG4bKa4d17f991015b1d8b788f2ac54d66ec66811226a;rport" + CRLF +
                "Via: SIP/2.0/UDP 127.0.0.1:5060;branch=z9hG4bKc2224b79f5af4c4a9b1cd649890c6497;rport" + CRLF +
                "Via: SIP/2.0/UDP 127.0.0.1:5003;branch=z9hG4bK0495dc29b7eb40008779a75c3734c4c5;rport=5003;received=127.0.0.1" + CRLF +
                "To: <sip:10.1.1.5:62647;transport=tcp>;tag=1892981968" + CRLF +
                "From: <sip:127.0.0.1:5003>;tag=1555449860" + CRLF +
                "Call-ID: 1b569032-d1e4-4869-be9f-67d4ba8a4e3a" + CRLF +
                "CSeq: 4 NOTIFY" + CRLF +
                "Contact: <sip:127.0.0.1:5003>" + CRLF +
                "Max-Forwards: 69" + CRLF +
                "Event: dialog" + CRLF + CRLF;

            byte[] notifyRequestBytes = UTF8Encoding.UTF8.GetBytes(notifyRequest);
            byte[] parsedNotifyBytes  = SIPMessage.ParseSIPMessageFromStream(notifyRequestBytes, 0, notifyRequestBytes.Length, out _);

            Assert.IsTrue(notifyRequestBytes.Length == parsedNotifyBytes.Length, "The length of the parsed byte array was incorrect.");
        }
        public void ParseResponseNoEndDoubleCRLFUnitTest()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg =
                "SIP/2.0 100 Trying" + CRLF +
                "Via: SIP/2.0/UDP 213.168.225.135:5060;branch=z9hG4bKD+ta2mJ+C+VV/L50aPO1lFJnrag=" + CRLF +
                "Via: SIP/2.0/UDP 192.168.1.2:5065;received=220.240.255.198:64193;branch=z9hG4bKB86FC8D2431F49E9862D1EE439C78AD8" + CRLF +
                "From: bluesipd <sip:bluesipd@bluesipd:5065>;tag=3272744142" + CRLF +
                "To: <sip:303@bluesipd>" + CRLF +
                "Call-ID: [email protected]" + CRLF +
                "CSeq: 45560 INVITE" + CRLF +
                "User-Agent: asterisk" + CRLF +
                "Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY" + CRLF +
                "Contact: <sip:[email protected]>" + CRLF +
                "Content-Length: 0" + CRLF;

            SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);

            Assert.IsTrue(sipMessage != null, "The SIP message not parsed correctly.");

            Console.WriteLine("-----------------------------------------");
        }
        public void ParseCiscoOptionsResponseUnitTest()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg =
                "SIP/2.0 200 OK" + CRLF +
                "Via: SIP/2.0/UDP 213.168.225.133:5060;branch=z9hG4bK7ae332e73550dbdf2f159061651e7ed5bb88ac52, SIP/2.0/UDP 194.213.29.52:5064;branch=z9hG4bK1121681627" + CRLF +
                "From: <sip:[email protected]:5064>;tag=8341482660" + CRLF +
                "To: <sip:[email protected]:5060>;tag=000e38e46c60ef28651381fe-201e6ab1" + CRLF +
                "Call-ID: [email protected]" + CRLF +
                "Date: Wed, 29 Nov 2006 22:31:58 GMT" + CRLF +
                "CSeq: 148 OPTIONS" + CRLF +
                "Server: CSCO/7" + CRLF +
                "Content-Type: application/sdp" + CRLF +
                "Allow: OPTIONS,INVITE,BYE,CANCEL,REGISTER,ACK,NOTIFY,REFER" + CRLF +
                "Content-Length: 193" + CRLF +
                CRLF +
                "v=0" + CRLF +
                "o=Cisco-SIPUA (null) (null) IN IP4 87.198.196.121" + CRLF +
                "s=SIP Call" + CRLF +
                "c=IN IP4 87.198.196.121" + CRLF +
                "t=0 0" + CRLF +
                "m=audio 1 RTP/AVP 18 0 8" + CRLF +
                "a=rtpmap:18 G729/8000" + CRLF +
                "a=rtpmap:0 PCMU/8000" + CRLF +
                "a=rtpmap:8 PCMA/8000" + CRLF +
                CRLF;

            SIPMessage  sipMessage  = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
            SIPResponse sipResponse = SIPResponse.ParseSIPResponse(sipMessage);

            Assert.IsTrue(sipMessage != null, "The SIP message not parsed correctly.");
            Assert.IsTrue(sipResponse.Header.Vias.Length == 2, "The SIP reponse did not end up with the right number of Via headers.");

            Console.WriteLine("-----------------------------------------");
        }
        public void ParseOptionsResponse()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg =
                "SIP/2.0 200 OK" + m_CRLF +
                "Via: SIP/2.0/UDP 194.213.29.11:5060;branch=z9hG4bK330f55c874" + m_CRLF +
                "From: Anonymous <sip:194.213.29.11:5060>;tag=6859154930" + m_CRLF +
                "To: <sip:[email protected]:10062>;tag=0013c339acec0fe007b80bbf-30071da3" + m_CRLF +
                "Call-ID: [email protected]" + m_CRLF +
                "Date: Mon, 01 May 2006 13:47:24 GMT" + m_CRLF +
                "CSeq: 915 OPTIONS" + m_CRLF +
                "Server: CSCO/7" + m_CRLF +
                "Content-Type: application/sdp" + m_CRLF +
                "Content-Length: 247" + m_CRLF +
                "Allow: OPTIONS,INVITE,BYE,CANCEL,REGISTER,ACK,NOTIFY,REFER" + m_CRLF +
                m_CRLF +
                "v=0" + m_CRLF +
                "o=Cisco-SIPUA (null) (null) IN IP4 192.168.1.100" + m_CRLF +
                "s=SIP Call" + m_CRLF +
                "c=IN IP4 192.168.1.100" + m_CRLF +
                "t=0 0" + m_CRLF +
                "m=audio 1 RTP/AVP 0 8 18 101" + m_CRLF +
                "a=rtpmap:0 PCMU/8000" + m_CRLF +
                "a=rtpmap:8 PCMA/8000" + m_CRLF +
                "a=rtpmap:18 G729/8000" + m_CRLF +
                "a=rtpmap:101 telephone-event/8000" + m_CRLF +
                "a=fmtp:101 0-15" + m_CRLF + m_CRLF;

            SIPMessage  sipMessage  = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
            SIPResponse optionsResp = SIPResponse.ParseSIPResponse(sipMessage);

            Assert.IsTrue(optionsResp.Status == SIPResponseStatusCodesEnum.Ok, "The SIP response status was not parsed correctly.");

            Console.WriteLine("-----------------------------------------");
        }
Exemple #29
0
        /// <summary>
        /// 설정된 NIC 디바이스의 패킷 수신 이벤트 처리
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void device_OnPacketArrival(object sender, CaptureEventArgs e)
        {
            //log("Packet 수신!");
            Packet p = Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);
            UdpPacket udpPacket = UdpPacket.GetEncapsulated(p);
            string data = Encoding.ASCII.GetString(udpPacket.PayloadData);
            SIPM = makeSIPConstructor(data);

            //log(data);
            if (!SIPM.from.Equals(SIPM.to) && !SIPM.from.Equals("unknown") && !SIPM.to.Equals("unknown"))
            {

                if (SIPM.method.Equals("INVITE"))
                {
                    if (SIPM.sName.Equals("session")) //Ringing
                    {
                        LogWrite("Ringing : " + SIPM.from + "|" + SIPM.to + "|" + SIPM.callid);

                    }
                    else if (SIPM.sName.Equals("SIP Call")) //Dial
                    {
                        LogWrite("Dialing : " + SIPM.from + "|" + SIPM.to + "|" + SIPM.callid);

                    }
                }
                else if (SIPM.code.Equals("200")) //Answer
                {
                    if (SIPM.sName.Equals("SIP Call"))
                    {
                        LogWrite("Answer : " + SIPM.from + "|" + SIPM.to + "|" + SIPM.callid);

                    }
                    else if (SIPM.sName.Equals("session")) //발신 후 연결 
                    {
                        LogWrite("CallConnect : " + SIPM.from + "|" + SIPM.to + "|" + SIPM.callid);

                    }
                }
                else if (SIPM.method.Equals("CANCEL")) //Abandon
                {
                    LogWrite("Abandon : " + SIPM.from + "|" + SIPM.to + "|" + SIPM.callid);

                }
                else if (SIPM.method.Equals("BYE")) //Abandon
                {
                    LogWrite("HangUp : " + SIPM.from + "|" + SIPM.to + "|" + SIPM.callid);

                }
            }
        }
Exemple #30
0
        private SIPMessage makeSIPConstructor(string data)
        {
            SIPM = new SIPMessage();
            StreamWriter sw = new StreamWriter("PacketDump_" + DateTime.Now.ToShortDateString() + ".txt", true, Encoding.Default);
            try
            {
                string code = "Unknown";
                string method = "Unknown";
                string callid = "Unknown";
                string cseq = "Unknown";
                string from = "Unknown";
                string to = "Unknown";
                string agent = "Unknown";
                string sName = "Unknown";


                StringReader sr = new StringReader(data);
                
                while (sr.Peek() != -1)
                {
                    string line = sr.ReadLine();
                    string Gubun = "";

                    if (line.Length > 2)
                    {
                        Gubun = line.Substring(0, 3);
                    }
                    if (Gubun.Equals("REG"))
                    {
                        break;
                    }
                    else
                    {
                        if (Gubun.Equals(ConstDef.NIC_SIP))  //Status Line
                        {
                            string[] sipArr = line.Split(' ');
                            if (sipArr.Length > 0)
                            {
                                code = sipArr[1].Trim();
                                method = sipArr[2].Trim();
                                sw.WriteLine("code : "+code + " / method : " + method);
                            }
                        }
                        else if (Gubun.Equals("INV"))
                        {
                            method = "INVITE";
                        }
                        else if (Gubun.Equals("CAN"))
                        {
                            method = "CANCEL";
                        }
                        else
                        {
                            string[] sipArr = line.Split(':');
                            if (sipArr.Length < 2)
                            {
                                sipArr = line.Split('=');
                                if (sipArr.Length > 1)
                                {
                                    sw.WriteLine(sipArr[0] + " = " + sipArr[1]);
                                    if (sipArr[0].Equals("s")) sName = sipArr[1];
                                }
                            }
                            else
                            {
                                string key = sipArr[0];

                                switch (key)
                                {
                                    case "From":
                                        from = sipArr[2].Split('@')[0];
                                        sw.WriteLine("From = " + from);
                                        break;

                                    case "To":
                                        to = sipArr[2].Split('@')[0];
                                        sw.WriteLine("To = " + to);
                                        break;

                                    case "Call-ID":
                                        callid = sipArr[1].Split('@')[0];
                                        sw.WriteLine("Call-ID = " + callid);
                                        break;

                                    case "CSeq":
                                        cseq = sipArr[1].Split('@')[0];
                                        sw.WriteLine("CSeq = " + cseq);
                                        break;

                                    case "User-Agent":
                                        agent = sipArr[1].Split('@')[0];
                                        sw.WriteLine("User-Agent = " + cseq);
                                        break;

                                    default:

                                        string value = "";
                                        for (int i = 1; i < sipArr.Length; i++)
                                        {
                                            value += sipArr[i];
                                        }
                                        sw.WriteLine(key + " = " + value);

                                        break;
                                }
                            }
                        }
                    }
                }
                sw.WriteLine("\r\n");
                sw.WriteLine("###########");
                sw.Flush();
                sw.Close();
                if (!from.Equals(to) && !from.Equals("unknown") && !to.Equals("unknown"))
                {
                    LogWrite(data);
                }
                SIPM.setSIPMessage(code, method, callid, cseq, from, to, agent, sName);

            }
            catch (Exception ex)
            {
                LogWrite(ex.ToString());
                sw.Close();
            }

            return SIPM;
        }
        public void ParseMultiRequestAndResponseTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string testReceive =
                @"SUBSCRIBE sip:[email protected] SIP/2.0" + CRLF +
                "Via: SIP/2.0/TCP 10.1.1.5:62647;branch=z9hG4bKa58b912c426f415daa887289efda50cd;rport" + CRLF +
                "To: <sip:[email protected]>" + CRLF +
                "From: <sip:[email protected]>;tag=1902440575" + CRLF +
                "Call-ID: 1b569032-d1e4-4869-be9f-67d4ba8a4e3a" + CRLF +
                "CSeq: 3 SUBSCRIBE" + CRLF +
                "Contact: <sip:10.1.1.5:62647;transport=tcp>" + CRLF +
                "Max-Forwards: 70" + CRLF +
                "Expires: 600" + CRLF +
                "Content-Length: 15" + CRLF +
                "Content-Type: text/text" + CRLF +
                "Event: dialog" + CRLF +
                CRLF +
                "includesdp=trueSUBSCRIBE sip:[email protected] SIP/2.0" + CRLF +
                "Via: SIP/2.0/UDP 127.0.0.1:5060;branch=z9hG4bK82b1f0704fc31f47b4c9e0bc383d3e0e41f2a60f;rport" + CRLF +
                "Via: SIP/2.0/TCP 10.1.1.5:4506;branch=z9hG4bK6d88a47e4b5c4bde9c45270ca64a1c53;rport" + CRLF +
                "Via: SIP/2.0/TCP 10.1.1.5:62647;branch=z9hG4bKa58b912c426f415daa887289efda50cd;rport=62647;received=10.1.1.5" + CRLF +
                "To: <sip:[email protected]>" + CRLF +
                "From: <sip:[email protected]>;tag=1902440575" + CRLF +
                "Call-ID: 1b569032-d1e4-4869-be9f-67d4ba8a4e3a" + CRLF +
                "CSeq: 3 SUBSCRIBE" + CRLF +
                "Contact: <sip:10.1.1.5:62647;transport=tcp>" + CRLF +
                "Max-Forwards: 69" + CRLF +
                "Expires: 600" + CRLF +
                "Content-Length: 15" + CRLF +
                "Content-Type: text/text" + CRLF +
                "Event: dialog" + CRLF +
                "Proxy-ReceivedFrom: tcp:10.1.1.5:62647" + CRLF +
                "Proxy-ReceivedOn: tcp:10.1.1.5:4506" + CRLF +
                CRLF +
                "includesdp=trueSIP/2.0 200 Ok" + CRLF +
                "Via: SIP/2.0/UDP 127.0.0.1:5060;branch=z9hG4bKba4e75d7c55baef96457b36b7b570dae9a253dd8;rport=5060;received=127.0.0.1" + CRLF +
                "Via: SIP/2.0/TCP 10.1.1.5:4506;branch=z9hG4bKc6f4c0fcd4684246abf539848017c0f0;rport" + CRLF +
                "Via: SIP/2.0/TCP 10.1.1.5:62647;branch=z9hG4bK17bbf15513b44e6aa88b605410148d2b;rport=62647;received=10.1.1.5" + CRLF +
                "To: <sip:[email protected]>;tag=2140367015" + CRLF +
                "From: <sip:[email protected]>;tag=1557768010" + CRLF +
                "Call-ID: a65b4461-6929-4604-b498-256f6643e6ac" + CRLF +
                "CSeq: 2 REGISTER" + CRLF +
                "Contact: <sip:10.1.1.5:62647;transport=tcp>;expires=113" + CRLF +
                "Date: Wed, 10 Mar 2010 00:21:14 GMT" + CRLF +
                "Content-Length: 0" + CRLF +
                "Server: www.sipsorcery.com" + CRLF + CRLF;

            byte[] testReceiveBytes = UTF8Encoding.UTF8.GetBytes(testReceive);

            byte[] request1Bytes = SIPMessage.ParseSIPMessageFromStream(testReceiveBytes, 0, testReceiveBytes.Length, out _);
            Console.WriteLine("Request1=" + UTF8Encoding.UTF8.GetString(request1Bytes));

            byte[] request2Bytes = SIPMessage.ParseSIPMessageFromStream(testReceiveBytes, request1Bytes.Length, testReceiveBytes.Length, out _);
            Console.WriteLine("Request2=" + UTF8Encoding.UTF8.GetString(request2Bytes));

            byte[] response1Bytes = SIPMessage.ParseSIPMessageFromStream(testReceiveBytes, request1Bytes.Length + request2Bytes.Length, testReceiveBytes.Length, out _);
            Console.WriteLine("Response1=" + UTF8Encoding.UTF8.GetString(response1Bytes));

            Assert.IsTrue(request1Bytes.Length + request2Bytes.Length + response1Bytes.Length == testReceiveBytes.Length, "The length of the parsed requests and responses was incorrect.");
        }
        public void ParseReceiveSingleRequestTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string notifyRequest =
                @"NOTIFY sip:10.1.1.5:62647;transport=tcp SIP/2.0" + CRLF +
                "Via: SIP/2.0/TCP 10.1.1.5:4506;branch=z9hG4bKa4d17f991015b1d8b788f2ac54d66ec66811226a;rport" + CRLF +
                "Via: SIP/2.0/UDP 127.0.0.1:5060;branch=z9hG4bKc2224b79f5af4c4a9b1cd649890c6497;rport" + CRLF +
                "Via: SIP/2.0/UDP 127.0.0.1:5003;branch=z9hG4bK0495dc29b7eb40008779a75c3734c4c5;rport=5003;received=127.0.0.1" + CRLF +
                "To: <sip:10.1.1.5:62647;transport=tcp>;tag=1892981968" + CRLF +
                "From: <sip:127.0.0.1:5003>;tag=1555449860" + CRLF +
                "Call-ID: 1b569032-d1e4-4869-be9f-67d4ba8a4e3a" + CRLF +
                "CSeq: 4 NOTIFY" + CRLF +
                "Contact: <sip:127.0.0.1:5003>" + CRLF +
                "Max-Forwards: 69" + CRLF +
                "Content-Length: 2393" + CRLF +
                "Event: dialog" + CRLF +
                CRLF +
                "<?xml version='1.0' encoding='utf-16'?>" + CRLF +
                "<dialog-info xmlns:ss='sipsorcery:dialog-info' version='0' state='full' entity='sip:[email protected]' xmlns='urn:ietf:params:xml:ns:dialog-info'>" + CRLF +
                "  <dialog id='6eab270b-b981-4734-bb6f-a4d33f77c331' call-id='c0a6182504cd4501afb8339f4218704e' local-tag='1047197926' remote-tag='56F30C5C-4B96DF700001F3A1-B67FABB0' direction='initiator'>" + CRLF +
                "    <state>confirmed</state>" + CRLF +
                "    <duration>1676</duration>" + CRLF +
                "    <ss:bridgeid>1c47e24b-4c1b-4dae-af93-567f26a7c215</ss:bridgeid>" + CRLF +
                "    <local>" + CRLF +
                "      <identity>sip:[email protected]</identity>" + CRLF +
                "      <cseq>1</cseq>" + CRLF +
                "      <ss:sdp>v=0" + CRLF +
                "o=- 1268178554 1268178554 IN IP4 10.1.1.7" + CRLF +
                "s=Polycom IP Phone" + CRLF +
                "c=IN IP4 10.1.1.7" + CRLF +
                "t=0 0" + CRLF +
                "a=sendrecv" + CRLF +
                "m=audio 2262 RTP/AVP 18 0 8 101" + CRLF +
                "a=rtpmap:18 G729/8000" + CRLF +
                "a=rtpmap:0 PCMU/8000" + CRLF +
                "a=rtpmap:8 PCMA/8000" + CRLF +
                "a=rtpmap:101 telephone-event/8000" + CRLF +
                "</ss:sdp>" + CRLF +
                "    </local>" + CRLF +
                "    <remote>" + CRLF +
                "      <identity>sip:[email protected]</identity>" + CRLF +
                "      <target uri='sip:[email protected]:5080' />" + CRLF +
                "      <cseq>1</cseq>" + CRLF +
                "      <ss:sdp>v=0" + CRLF +
                "o=sems 2134578198 1169488647 IN IP4 213.192.59.78" + CRLF +
                "s=session" + CRLF +
                "c=IN IP4 213.192.59.91" + CRLF +
                "t=0 0" + CRLF +
                "m=audio 27712 RTP/AVP 0 8 101" + CRLF +
                "a=rtpmap:0 PCMU/8000" + CRLF +
                "a=rtpmap:8 PCMA/8000" + CRLF +
                "a=rtpmap:101 telephone-event/8000" + CRLF +
                "a=fmtp:101 0-15" + CRLF +
                "</ss:sdp>" + CRLF +
                "    </remote>" + CRLF +
                "  </dialog>" + CRLF +
                "  <dialog id='b5f20497-c482-4b88-99d1-51b13f9d9167' call-id='4b20b31441064c599e63a3a1320322ae' local-tag='1468371802' remote-tag='1048320465' direction='recipient'>" + CRLF +
                "    <state>confirmed</state>" + CRLF +
                "    <duration>1676</duration>" + CRLF +
                "    <ss:bridgeid>1c47e24b-4c1b-4dae-af93-567f26a7c215</ss:bridgeid>" + CRLF +
                "    <local>" + CRLF +
                "      <identity>sip:[email protected]@10.1.1.5</identity>" + CRLF +
                "      <cseq>2</cseq>" + CRLF +
                "      <ss:sdp>v=0" + CRLF +
                "o=sems 2134578198 1169488647 IN IP4 213.192.59.78" + CRLF +
                "s=session" + CRLF +
                "c=IN IP4 213.192.59.91" + CRLF +
                "t=0 0" + CRLF +
                "m=audio 27712 RTP/AVP 0 8 101" + CRLF +
                "a=rtpmap:0 PCMU/8000" + CRLF +
                "a=rtpmap:8 PCMA/8000" + CRLF +
                "a=rtpmap:101 telephone-event/8000" + CRLF +
                "a=fmtp:101 0-15" + CRLF +
                "</ss:sdp>" + CRLF +
                "    </local>" + CRLF +
                "    <remote>" + CRLF +
                "      <identity>sip:[email protected]</identity>" + CRLF +
                "      <target uri='sip:10.1.1.5:62442;transport=tcp' />" + CRLF +
                "      <cseq>2</cseq>" + CRLF +
                "      <ss:sdp>v=0" + CRLF +
                "o=- 1268178554 1268178554 IN IP4 10.1.1.7" + CRLF +
                "s=Polycom IP Phone" + CRLF +
                "c=IN IP4 10.1.1.7" + CRLF +
                "t=0 0" + CRLF +
                "a=sendrecv" + CRLF +
                "m=audio 2262 RTP/AVP 18 0 8 101" + CRLF +
                "a=rtpmap:18 G729/8000" + CRLF +
                "a=rtpmap:0 PCMU/8000" + CRLF +
                "a=rtpmap:8 PCMA/8000" + CRLF +
                "a=rtpmap:101 telephone-event/8000" + CRLF +
                "</ss:sdp>" + CRLF +
                "    </remote>" + CRLF +
                "  </dialog>" + CRLF +
                "</dialog-info>";

            byte[] notifyRequestBytes = Encoding.ASCII.GetBytes(notifyRequest);
            byte[] parsedNotifyBytes  = SIPMessage.ParseSIPMessageFromStream(notifyRequestBytes, 0, notifyRequestBytes.Length, out _);

            Assert.IsTrue(notifyRequestBytes.Length == parsedNotifyBytes.Length, "The length of the parsed byte array was incorrect.");
        }