public void ParseAsteriskRecordRouteHeadersTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string xtenInviteHeaders = "Via: SIP/2.0/UDP 213.168.225.135:5060;branch=z9hG4bK8Z4EIWBeY45fRGwC0qIeu/xpw3A=" + m_CRLF + "Via: SIP/2.0/UDP 192.168.1.2:5065;received=220.240.255.198:64091;branch=z9hG4bK4E0728C26A0640E7830D7C9179D08D67" + m_CRLF + "Record-Route: <sip:213.168.225.133:5060;lr>,<sip:220.240.255.198:64091;lr>" + m_CRLF + "From: bluesipd <sip:bluesipd@bluesipd:5065>;tag=457825353" + m_CRLF + "To: <sip:303@bluesipd>;tag=as02a64a42" + m_CRLF + "Call-ID: [email protected]" + m_CRLF + "CSeq: 38002 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: 350" + m_CRLF; logger.LogDebug("Original SIP Headers:\n" + xtenInviteHeaders); string[] headersCollection = Regex.Split(xtenInviteHeaders, "\r\n"); SIPHeader sipHeader = SIPHeader.ParseSIPHeaders(headersCollection); logger.LogDebug("Parsed SIP Headers:\n" + sipHeader.ToString()); SIPRoute topRoute = sipHeader.RecordRoutes.PopRoute(); Assert.True(topRoute.Host == "213.168.225.133:5060", "The top record route was not parsed correctly."); logger.LogDebug("---------------------------------------------------"); }
public void MissingBracketsRouteTest() { Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); SIPRoute newRoute = new SIPRoute("sip:127.0.0.1:5060"); Console.WriteLine(newRoute.ToString()); Assert.IsTrue(newRoute.URI.ToString() == "sip:127.0.0.1:5060", "The Route header URI was not correctly parsed."); }
public void MissingBracketsRouteTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPRoute newRoute = new SIPRoute("sip:127.0.0.1:5060"); logger.LogDebug(newRoute.ToString()); Assert.True(newRoute.URI.ToString() == "sip:127.0.0.1:5060", "The Route header URI was not correctly parsed."); }
public void ParseRouteWithDoubleQuotedDisplayNameTest() { Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); SIPRoute route = SIPRoute.ParseSIPRoute("\"Joe Bloggs\" <sip:127.0.0.1:5060;lr>"); Console.WriteLine("SIP Route=" + route.ToString() + "."); Assert.AreEqual(route.Host, "127.0.0.1:5060", "The SIP route host was not parsed correctly."); Assert.AreEqual(route.ToString(), "\"Joe Bloggs\" <sip:127.0.0.1:5060;lr>", "The SIP route string was not correct."); Assert.IsFalse(route.IsStrictRouter, "Route was not correctly passed as a loose router."); }
public void ParseRouteTest() { Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); SIPRoute route = SIPRoute.ParseSIPRoute("<sip:127.0.0.1:5060;lr>"); Console.WriteLine("SIP Route=" + route.ToString() + "."); Assert.True(route.Host == "127.0.0.1:5060", "The SIP route host was not parsed correctly."); Assert.True(route.ToString() == "<sip:127.0.0.1:5060;lr>", "The SIP route string was not correct."); Assert.False(route.IsStrictRouter, "Route was not correctly passed as a loose router."); }
public void ParseRouteWithDoubleQuotedDisplayNameTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPRoute route = SIPRoute.ParseSIPRoute("\"Joe Bloggs\" <sip:127.0.0.1:5060;lr>"); logger.LogDebug("SIP Route=" + route.ToString() + "."); Assert.True(route.Host == "127.0.0.1:5060", "The SIP route host was not parsed correctly."); Assert.True(route.ToString() == "\"Joe Bloggs\" <sip:127.0.0.1:5060;lr>", "The SIP route string was not correct."); Assert.False(route.IsStrictRouter, "Route was not correctly passed as a loose router."); }
public void ParseRouteWithDisplayNameTest() { Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); SIPRoute route = SIPRoute.ParseSIPRoute("12345656 <sip:127.0.0.1:5060;lr>"); Console.WriteLine("SIP Route=" + route.ToString() + "."); Console.WriteLine("Route to SIPEndPoint=" + route.ToSIPEndPoint().ToString() + "."); Assert.AreEqual(route.Host, "127.0.0.1:5060", "The SIP route host was not parsed correctly."); Assert.AreEqual(route.ToString(), "\"12345656\" <sip:127.0.0.1:5060;lr>", "The SIP route string was not correct."); Assert.IsFalse(route.IsStrictRouter, "Route was not correctly passed as a loose router."); Assert.AreEqual(route.ToSIPEndPoint().ToString(), "udp:127.0.0.1:5060", "The SIP route did not produce the correct SIP End Point."); }
public void RemoveLooseRouterTest() { Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); SIPRoute route = SIPRoute.ParseSIPRoute("<sip:127.0.0.1:5060;lr>"); route.IsStrictRouter = true; Console.WriteLine("SIP Route=" + route.ToString() + "."); Assert.AreEqual(route.Host, "127.0.0.1:5060", "The SIP route host was not parsed correctly."); Assert.AreEqual(route.ToString(), "<sip:127.0.0.1:5060>", "The SIP route string was not correct."); Assert.IsTrue(route.IsStrictRouter, "Route was not correctly settable as a strict router."); }
public void RemoveLooseRouterTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPRoute route = SIPRoute.ParseSIPRoute("<sip:127.0.0.1:5060;lr>"); route.IsStrictRouter = true; logger.LogDebug("SIP Route=" + route.ToString() + "."); Assert.True(route.Host == "127.0.0.1:5060", "The SIP route host was not parsed correctly."); Assert.True(route.ToString() == "<sip:127.0.0.1:5060>", "The SIP route string was not correct."); Assert.True(route.IsStrictRouter, "Route was not correctly settable as a strict router."); }
public void ParseRouteWithUserPortionTest() { Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); string routeStr = "<sip:[email protected]:5060;lr;transport=udp>"; SIPRoute route = SIPRoute.ParseSIPRoute(routeStr); Console.WriteLine("SIP Route=" + route.ToString() + "."); Console.WriteLine("Route to SIPEndPoint=" + route.ToSIPEndPoint().ToString() + "."); Assert.AreEqual(route.Host, "127.0.0.1:5060", "The SIP route host was not parsed correctly."); Assert.AreEqual(route.ToString(), routeStr, "The SIP route string was not correct."); Assert.IsFalse(route.IsStrictRouter, "Route was not correctly passed as a loose router."); Assert.AreEqual(route.ToSIPEndPoint().ToString(), "udp:127.0.0.1:5060", "The SIP route did not produce the correct SIP End Point."); }
public void ParseRouteWithUserPortionTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string routeStr = "<sip:[email protected]:5060;lr;transport=udp>"; SIPRoute route = SIPRoute.ParseSIPRoute(routeStr); logger.LogDebug("SIP Route=" + route.ToString() + "."); logger.LogDebug("Route to SIPEndPoint=" + route.ToSIPEndPoint().ToString() + "."); Assert.True(route.Host == "127.0.0.1:5060", "The SIP route host was not parsed correctly."); Assert.True(route.ToString() == routeStr, "The SIP route string was not correct."); Assert.False(route.IsStrictRouter, "Route was not correctly passed as a loose router."); Assert.True(route.ToSIPEndPoint().ToString() == "udp:127.0.0.1:5060", "The SIP route did not produce the correct SIP End Point."); }
public void ParseMultiLineRecordRouteResponse() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(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; SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); SIPResponse okResp = SIPResponse.ParseSIPResponse(sipMessageBuffer); Assert.True(okResp.Header.RecordRoutes.Length == 2, "The wrong number of Record-Route headers were present in the parsed response."); Assert.True(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.True(nextRoute.ToString() == "<sip:77.75.25.45:5060;lr=on;ftag=1014391101>", "The second Record-Route header was incorrect, " + nextRoute.ToString() + "."); logger.LogDebug("-----------------------------------------"); }
public void ParseAMulitLineHeaderTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string mulitLineHeader = "Via: SIP/2.0/UDP 213.168.225.135:5060;branch=z9hG4bK8Z4EIWBeY45fRGwC0qIeu/xpw3A=" + m_CRLF + "Via: SIP/2.0/UDP 192.168.1.2:5065;received=220.240.255.198:64091;branch=z9hG4bK4E0728C26A0640E7830D7C9179D08D67" + m_CRLF + "Record-Route: <sip:213.168.225.133:5060;lr>," + m_CRLF + " <sip:220.240.255.198:64091;lr>" + m_CRLF + "From: bluesipd <sip:bluesipd@bluesipd:5065>;tag=457825353" + m_CRLF + "To: <sip:303@bluesipd>;tag=as02a64a42" + m_CRLF + "Call-ID: [email protected]" + m_CRLF + "CSeq: 38002 INVITE" + 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: 350" + m_CRLF; logger.LogDebug("Original SIP Headers:\n" + mulitLineHeader); string[] headersCollection = SIPHeader.SplitHeaders(mulitLineHeader); foreach (string headerStr in headersCollection) { logger.LogDebug("Header => " + headerStr + "."); } Assert.True(headersCollection.Length == 12, "The headers were not split properly."); logger.LogDebug(""); SIPHeader sipHeader = SIPHeader.ParseSIPHeaders(headersCollection); logger.LogDebug("Parsed SIP Headers:\n" + sipHeader.ToString()); Assert.True(sipHeader.RecordRoutes.Length == 2, "An incorrect number of record route entries was extracted, number was " + sipHeader.RecordRoutes.Length + "."); SIPRoute topRoute = sipHeader.RecordRoutes.PopRoute(); Assert.True(topRoute.Host == "213.168.225.133:5060", "The top record route was not parsed correctly."); logger.LogDebug("---------------------------------------------------"); }
public void ParseSIPRouteSetTest() { Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); string routeSetString = "<sip:127.0.0.1:5434;lr>,<sip:10.0.0.1>,<sip:192.168.0.1;ftag=12345;lr=on>"; SIPRouteSet routeSet = SIPRouteSet.ParseSIPRouteSet(routeSetString); Console.WriteLine(routeSet.ToString()); Assert.IsTrue(routeSet.Length == 3, "The parsed route set had an incorrect length."); Assert.IsTrue(routeSet.ToString() == routeSetString, "The parsed route set did not produce the same string as the original parsed value."); SIPRoute topRoute = routeSet.PopRoute(); Assert.IsTrue(topRoute.Host == "127.0.0.1:5434", "The first route host was not parsed correctly."); Assert.IsFalse(topRoute.IsStrictRouter, "The first route host was not correctly recognised as a loose router."); topRoute = routeSet.PopRoute(); Assert.IsTrue(topRoute.Host == "10.0.0.1", "The second route host was not parsed correctly."); Assert.IsTrue(topRoute.IsStrictRouter, "The second route host was not correctly recognised as a strict router."); topRoute = routeSet.PopRoute(); Assert.IsTrue(topRoute.Host == "192.168.0.1", "The third route host was not parsed correctly."); Assert.IsFalse(topRoute.IsStrictRouter, "The third route host was not correctly recognised as a loose router."); Assert.IsTrue(topRoute.URI.Parameters.Get("ftag") == "12345", "The ftag parameter on the third route was not correctly parsed."); }