示例#1
0
        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.");
        }
        /// <summary>
        /// Gets the destination of the remote SIP end point for this call.
        /// </summary>
        /// <param name="sipCallDescriptor">The call descriptor containing the settings to use to place the call.</param>
        /// <returns>The server end point for the call.</returns>
        public async Task <SIPEndPoint> GetCallDestination(SIPCallDescriptor sipCallDescriptor)
        {
            SIPURI      callURI        = SIPURI.ParseSIPURI(sipCallDescriptor.Uri);
            SIPEndPoint serverEndPoint = null;

            // If the outbound proxy is a loopback address, as it will normally be for local deployments, then it cannot be overriden.
            if (m_outboundProxy != null && IPAddress.IsLoopback(m_outboundProxy.Address))
            {
                serverEndPoint = m_outboundProxy;
            }
            else if (!sipCallDescriptor.ProxySendFrom.IsNullOrBlank())
            {
                // If the binding has a specific proxy end point sent then the request needs to be forwarded to the proxy's default end point for it to take care of.
                //SIPEndPoint outboundProxyEndPoint = SIPEndPoint.ParseSIPEndPoint(sipCallDescriptor.ProxySendFrom);
                //m_outboundProxy = new SIPEndPoint(SIPProtocolsEnum.udp, outboundProxyEndPoint.Address, SIPConstants.DEFAULT_SIP_PORT);
                //m_serverEndPoint = m_outboundProxy;
                m_outboundProxy = SIPEndPoint.ParseSIPEndPoint(sipCallDescriptor.ProxySendFrom);
                serverEndPoint  = m_outboundProxy;
                logger.LogDebug($"SIPClientUserAgent Call using alternate outbound proxy of {serverEndPoint}.");
            }
            else if (m_outboundProxy != null)
            {
                // Using the system outbound proxy only, no additional user routing requirements.
                serverEndPoint = m_outboundProxy;
            }

            // No outbound proxy, determine the forward destination based on the SIP request.
            if (serverEndPoint == null)
            {
                //SIPDNSLookupResult lookupResult = null;
                SIPEndPoint lookupResult = null;
                double      lookupDurationMilliseconds = 0;

                if (sipCallDescriptor.RouteSet != null && sipCallDescriptor.RouteSet.IndexOf(OUTBOUNDPROXY_AS_ROUTESET_CHAR) != -1)
                {
                    var routeSet = new SIPRouteSet();
                    routeSet.PushRoute(new SIPRoute(sipCallDescriptor.RouteSet, true));
                    logger.LogDebug("Route set for call " + routeSet.ToString() + ".");
                    //lookupResult = m_sipTransport.GetURIEndPoint(routeSet.TopRoute.URI, false);
                    lookupResult = await m_sipTransport.ResolveSIPUriAsync(routeSet.TopRoute.URI).ConfigureAwait(false);
                }
                else
                {
                    logger.LogDebug("SIPClientUserAgent attempting to resolve " + callURI.Host + ".");
                    //lookupResult = m_sipTransport.GetURIEndPoint(callURI, false);
                    DateTime lookupStartedAt = DateTime.Now;
                    lookupResult = await m_sipTransport.ResolveSIPUriAsync(callURI).ConfigureAwait(false);

                    lookupDurationMilliseconds = DateTime.Now.Subtract(lookupStartedAt).TotalMilliseconds;
                }

                if (lookupResult == null)
                {
                    logger.LogDebug($"SIPClientUserAgent DNS failure resolving {callURI.Host} in {lookupDurationMilliseconds:0.##}ms. Call cannot proceed.");
                }
                else
                {
                    logger.LogDebug($"SIPClientUserAgent resolved {callURI.Host} to {lookupResult} in {lookupDurationMilliseconds:0.##}ms.");
                    serverEndPoint = lookupResult;
                }
            }

            return(serverEndPoint);
        }