Esempio n. 1
0
        public void ResolveSIPServiceTest()
        {
            try
            {
                logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
                logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

                //SIPDNSManager.UseNAPTRLookups = true;

                CancellationTokenSource cts = new CancellationTokenSource();

                //var result = SIPDNSManager.ResolveSIPService(SIPURI.ParseSIPURIRelaxed("sip:reg.sip-trunk.telekom.de;transport=tcp"), false);
                var result = SIPDns.ResolveAsync(SIPURI.ParseSIPURIRelaxed("sip:reg.sip-trunk.telekom.de;transport=tcp"), false, cts.Token).Result;

                Assert.NotNull(result);
                logger.LogDebug($"resolved to SIP end point {result}.");
                //Assert.NotEmpty(result.SIPNAPTRResults);
                //Assert.NotEmpty(result.SIPSRVResults);
                //Assert.NotEmpty(result.EndPointResults);

                //result = SIPDNSManager.ResolveSIPService(SIPURI.ParseSIPURIRelaxed("sip:tel.t-online.de"), false);
                //Assert.NotNull(resultEP);
                //result = SIPDNSManager.ResolveSIPService(SIPURI.ParseSIPURIRelaxed("sips:hpbxsec.deutschland-lan.de:5061;transport=tls"), false);
                //Assert.NotNull(resultEP);
            }
            finally
            {
                //SIPDNSManager.UseNAPTRLookups = false;
            }
        }
Esempio n. 2
0
        public void NonRespondingDNSServerTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var originalClient = SIPDns.LookupClient;

            try
            {
                LookupClientOptions clientOptions = new LookupClientOptions(IPAddress.Loopback)
                {
                    Retries        = 3,
                    Timeout        = TimeSpan.FromSeconds(1),
                    UseCache       = true,
                    UseTcpFallback = false
                };

                SIPDns.PreferIPv6NameResolution = true;
                SIPDns.LookupClient             = new LookupClient(clientOptions);

                var result = SIPDns.Resolve(SIPURI.ParseSIPURIRelaxed("sipsorcery.com"), false).Result;

                Assert.Null(result);
            }
            finally
            {
                SIPDns.LookupClient             = originalClient;
                SIPDns.PreferIPv6NameResolution = false;
            }
        }
Esempio n. 3
0
        public void NonRespondingDNSServerTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var originalClient = SIPDns.LookupClient;

            try
            {
                LookupClientOptions clientOptions = new LookupClientOptions(IPAddress.Loopback)
                {
                    Retries        = 3,
                    Timeout        = TimeSpan.FromSeconds(1),
                    UseCache       = true,
                    UseTcpFallback = false
                };

                SIPDns.LookupClient = new LookupClient(clientOptions);

                CancellationTokenSource cts = new CancellationTokenSource();
                var result = SIPDns.ResolveAsync(SIPURI.ParseSIPURIRelaxed("sipsorcery.com"), false, cts.Token).Result;

                Assert.Equal(SIPEndPoint.Empty, result);
            }
            finally
            {
                SIPDns.LookupClient = originalClient;
            }
        }
Esempio n. 4
0
        public void ResolveSIPServiceFromCacheTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            CancellationTokenSource cts = new CancellationTokenSource();

            SIPURI lookupURI = SIPURI.ParseSIPURIRelaxed("sip:tel.t-online.de");
            //var result = SIPDNSManager.ResolveSIPService(lookupURI, false);
            var result = SIPDns.ResolveAsync(lookupURI, false, cts.Token).Result;

            Assert.NotNull(result);

            //SIPEndPoint resultEP = result.GetSIPEndPoint();
            Assert.NotNull(result);
            Assert.NotEqual(SIPEndPoint.Empty, result);
            logger.LogDebug($"resolved to SIP end point {result}.");
            //Assert.NotEmpty(result.SIPSRVResults);
            //Assert.NotEmpty(result.EndPointResults);

            // Do the same look up again immediately to check the result when it comes from the in-memory cache.
            var resultCache = SIPDns.ResolveFromCache(lookupURI, false);

            Assert.NotNull(resultCache);
            Assert.NotEqual(SIPEndPoint.Empty, resultCache);
            logger.LogDebug($"cache resolved to SIP end point {resultCache}.");
        }
Esempio n. 5
0
        /// <summary>
        /// Parses the destination command line option into:
        ///  - A SIPEndPoint, which is an IP end point and transport (udp, tcp or tls),
        ///  - A SIP URI.
        ///  The SIPEndPoint determines the remote network destination to send the request to.
        ///  The SIP URI is the URI that will be set on the request.
        /// </summary>
        /// <param name="dstn">The destination string to parse.</param>
        /// <returns>The SIPEndPoint and SIPURI parsed from the destination string.</returns>
        private async static Task <(SIPEndPoint, SIPURI)> ParseDestination(string dst)
        {
            SIPEndPoint dstEp = null;

            SIPURI dstUri = null;

            // Don't attempt a SIP URI parse for serialised SIPEndPoints.
            if (Regex.IsMatch(dst, "^(udp|tcp|tls|ws|wss)") == false && SIPURI.TryParse(dst, out var argUri))
            {
                dstUri = argUri;
                dstEp  = dstUri.ToSIPEndPoint();
            }
            else
            {
                dstEp  = SIPEndPoint.ParseSIPEndPoint(dst);
                dstUri = new SIPURI(SIPSchemesEnum.sip, dstEp);
            }

            if (dstEp == null)
            {
                logger.LogDebug($"Attempting DNS resolve for {dstUri.Host}.");
                DateTime startedAt = DateTime.Now;
                var      result    = await SIPDns.Resolve(dstUri, false);

                if (result != null)
                {
                    int duration = (int)DateTime.Now.Subtract(startedAt).TotalMilliseconds;
                    logger.LogDebug($"Resolved SIP URI {dstUri} to {result} in {duration:0}ms.");
                    dstEp = result;
                }
            }

            return(dstEp, dstUri);
        }
Esempio n. 6
0
        /// <summary>
        /// Places an outgoing SIP call.
        /// </summary>
        /// <param name="destination">The SIP URI to place a call to. The destination can be a full SIP URI in which case the all will
        /// be placed anonymously directly to that URI. Alternatively it can be just the user portion of a URI in which case it will
        /// be sent to the configured SIP server.</param>
        public async Task Call(string destination)
        {
            // Determine if this is a direct anonymous call or whether it should be placed using the pre-configured SIP server account.
            SIPURI callURI     = null;
            string sipUsername = null;
            string sipPassword = null;
            string fromHeader  = null;

            if (destination.Contains("@") || m_sipServer == null)
            {
                // Anonymous call direct to SIP server specified in the URI.
                callURI    = SIPURI.ParseSIPURIRelaxed(destination);
                fromHeader = (new SIPFromHeader(m_sipFromName, SIPURI.ParseSIPURI(SIPFromHeader.DEFAULT_FROM_URI), null)).ToString();
            }
            else
            {
                // This call will use the pre-configured SIP account.
                callURI     = SIPURI.ParseSIPURIRelaxed(destination + "@" + m_sipServer);
                sipUsername = m_sipUsername;
                sipPassword = m_sipPassword;
                fromHeader  = (new SIPFromHeader(m_sipFromName, new SIPURI(m_sipUsername, m_sipServer, null), null)).ToString();
            }

            StatusMessage(this, $"Starting call to {callURI}.");

            var dstEndpoint = await Task.Run(() =>
            {
                return(SIPDns.Resolve(callURI, false));
            });

            if (dstEndpoint == null)
            {
                StatusMessage(this, $"Call failed, could not resolve {callURI}.");
            }
            else
            {
                StatusMessage(this, $"Call progressing, resolved {callURI} to {dstEndpoint}.");
                System.Diagnostics.Debug.WriteLine($"DNS lookup result for {callURI}: {dstEndpoint}.");
                SIPCallDescriptor callDescriptor = new SIPCallDescriptor(sipUsername, sipPassword, callURI.ToString(), fromHeader, null, null, null, null, SIPCallDirection.Out, _sdpMimeContentType, null, null);

                var audioSrcOpts = new AudioOptions
                {
                    AudioSource       = AudioSourcesEnum.CaptureDevice,
                    OutputDeviceIndex = m_audioOutDeviceIndex
                };
                var videoSrcOpts = new VideoOptions
                {
                    VideoSource           = VideoSourcesEnum.TestPattern,
                    SourceFile            = RtpAVSession.VIDEO_TESTPATTERN,
                    SourceFramesPerSecond = VIDEO_LIVE_FRAMES_PER_SECOND
                };
                MediaSession = new RtpAVSession(audioSrcOpts, videoSrcOpts);

                m_userAgent.RemotePutOnHold   += OnRemotePutOnHold;
                m_userAgent.RemoteTookOffHold += OnRemoteTookOffHold;

                await m_userAgent.InitiateCallAsync(callDescriptor, MediaSession);
            }
        }
Esempio n. 7
0
        public void ResolveNonExistentServiceTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var result = SIPDns.Resolve(SIPURI.ParseSIPURIRelaxed("sipsorceryx.com"), false).Result;

            Assert.Null(result);
        }
Esempio n. 8
0
        public void ResolveNonExistentServiceTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            CancellationTokenSource cts = new CancellationTokenSource();
            var result = SIPDns.ResolveAsync(SIPURI.ParseSIPURIRelaxed("sipsorceryx.com"), false, cts.Token).Result;

            Assert.Equal(SIPEndPoint.Empty, result);
        }
Esempio n. 9
0
        public void ResolveHostFromServiceTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var result = SIPDns.Resolve(SIPURI.ParseSIPURIRelaxed("sipsorcery.com"), false).Result;

            Assert.NotNull(result);

            logger.LogDebug($"resolved to SIP end point {result}.");
        }
Esempio n. 10
0
        public void ResolveHostFromSecureSIPURITest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var result = SIPDns.Resolve(new SIPURI(null, "sipsorcery.com", null, SIPSchemesEnum.sips, SIPProtocolsEnum.tls), false).Result;

            Assert.NotNull(result);
            Assert.Equal("67.222.131.147", result.Address.ToString());
            Assert.Equal(5061, result.Port);
            Assert.Equal(SIPProtocolsEnum.tls, result.Protocol);

            logger.LogDebug($"resolved to SIP end point {result}.");
        }
Esempio n. 11
0
        public async Task ResolveSIPServiceAsyncTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            //var result = await SIPDNSManager.ResolveAsync(SIPURI.ParseSIPURIRelaxed("sip:reg.sip-trunk.telekom.de;transport=tcp"));
            var result = await SIPDns.Resolve(SIPURI.ParseSIPURIRelaxed("sip:reg.sip-trunk.telekom.de;transport=tcp"));

            //SIPEndPoint resultEP = result.GetSIPEndPoint();

            Assert.NotNull(result);

            logger.LogDebug($"resolved to SIP end point {result}.");
        }
Esempio n. 12
0
        public void LookupCNAMETest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            CancellationTokenSource cts = new CancellationTokenSource();

            string hostname = "utest.sipsorcery.com";

            var result = SIPDns.ResolveAsync(SIPURI.ParseSIPURIRelaxed(hostname), false, cts.Token).Result;

            Assert.NotNull(result);

            logger.LogDebug($"resolved to SIP end point {result}.");
        }
Esempio n. 13
0
        /// <summary>
        /// Places an outgoing SIP call.
        /// </summary>
        /// <param name="destination">The SIP URI to place a call to. The destination can be a full SIP URI in which case the all will
        /// be placed anonymously directly to that URI. Alternatively it can be just the user portion of a URI in which case it will
        /// be sent to the configured SIP server.</param>
        public async Task Call(string destination)
        {
            // Determine if this is a direct anonymous call or whether it should be placed using the pre-configured SIP server account.
            SIPURI callURI     = null;
            string sipUsername = null;
            string sipPassword = null;
            string fromHeader  = null;

            if (destination.Contains("@") || m_sipServer == null)
            {
                // Anonymous call direct to SIP server specified in the URI.
                callURI    = SIPURI.ParseSIPURIRelaxed(destination);
                fromHeader = (new SIPFromHeader(m_sipFromName, SIPURI.ParseSIPURI(SIPFromHeader.DEFAULT_FROM_URI), null)).ToString();
            }
            else
            {
                // This call will use the pre-configured SIP account.
                callURI     = SIPURI.ParseSIPURIRelaxed(destination + "@" + m_sipServer);
                sipUsername = m_sipUsername;
                sipPassword = m_sipPassword;
                fromHeader  = (new SIPFromHeader(m_sipFromName, new SIPURI(m_sipFromName, m_sipServer, null), null)).ToString();
            }

            StatusMessage(this, $"Starting call to {callURI}.");

            var dstEndpoint = await SIPDns.ResolveAsync(callURI, false, _cts.Token);

            if (dstEndpoint == null)
            {
                StatusMessage(this, $"Call failed, could not resolve {callURI}.");
            }
            else
            {
                StatusMessage(this, $"Call progressing, resolved {callURI} to {dstEndpoint}.");
                System.Diagnostics.Debug.WriteLine($"DNS lookup result for {callURI}: {dstEndpoint}.");
                SIPCallDescriptor callDescriptor = new SIPCallDescriptor(sipUsername, sipPassword, callURI.ToString(), fromHeader, null, null, null, null, SIPCallDirection.Out, _sdpMimeContentType, null, null);
                callDescriptor.CallId = m_sipFromName;
                MediaSession          = CreateMediaSession();

                m_userAgent.RemotePutOnHold   += OnRemotePutOnHold;
                m_userAgent.RemoteTookOffHold += OnRemoteTookOffHold;
                Directory.CreateDirectory(SIPSoftPhoneState.OutputRecordingFolder);
                string guid = Guid.NewGuid().ToString();
                _waveFile = new WaveFileWriter(Path.Combine(SIPSoftPhoneState.OutputRecordingFolder, $"{guid}.mp3"), _waveFormat);
                await m_userAgent.InitiateCallAsync(callDescriptor, MediaSession);
            }
        }
Esempio n. 14
0
        public void LookupLocalHostnameTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string hostname = System.Net.Dns.GetHostName();

            if (hostname.EndsWith(SIPDns.MDNS_TLD))
            {
                logger.LogWarning("Skipping unit test LookupLocalHostnameTest due to RFC6762 domain.");
            }
            else
            {
                //var result = SIPDNSManager.ResolveSIPService(SIPURI.ParseSIPURIRelaxed(hostname), false);
                var result = SIPDns.Resolve(SIPURI.ParseSIPURIRelaxed(hostname)).Result;

                Assert.NotNull(result);

                logger.LogDebug($"resolved to SIP end point {result}.");
            }
        }