Ejemplo n.º 1
0
        /// <summary>
        /// Attempts to parse a SIP URI from a string.
        /// </summary>
        /// <param name="text">The input text.</param>
        /// <param name="uri">The output <see cref="SipUri" />.</param>
        /// <returns><c>true</c> if the URI was parsed successfully.</returns>
        public static bool TryParse(string text, out SipUri uri)
        {
            uri = new SipUri();

            if (uri.Parse(text))
            {
                return(true);
            }
            else
            {
                uri = null;
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="speechServerUri">The Microsoft Speech Server <see cref="SipUri" />.</param>
        /// <param name="trunkUri">The SIP trunking service URI <see cref="SipUri" />.</param>
        public SipMssGatewaySettings(SipUri speechServerUri, SipUri trunkUri)
        {
            if (speechServerUri == null)
            {
                throw new ArgumentNullException("speechServerUri");
            }

            if (trunkUri == null)
            {
                throw new ArgumentNullException("trunkUri");
            }

            this.SpeechServerUri = speechServerUri;
            this.TrunkUri        = trunkUri;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns a deep clone of the URI.
        /// </summary>
        /// <returns>The cloned copy.</returns>
        public SipUri Clone()
        {
            var clone = new SipUri();

            clone.isSecure = this.isSecure;
            clone.user     = this.user;
            clone.host     = this.host;
            clone.port     = this.port;

            foreach (string key in this.parameters.Keys)
            {
                clone.parameters.Add(key, parameters[key]);
            }

            foreach (SipHeader header in this.headers)
            {
                clone.headers.Add(header.Clone());
            }

            return(clone);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Converts a contact style header value into the <see cref="NetworkBinding" />
        /// and optional <see cref="SipTransportType" /> to be used when figuring out
        /// how to deliver an outbound SIP message.
        /// </summary>
        /// <param name="contactText">The <b>Contact</b> header text.</param>
        /// <param name="binding">Returns as the <see cref="NetworkBinding" /> to use.</param>
        /// <param name="transportType">Returns the <see cref="SipTransportType" /> to use</param>
        /// <returns></returns>
        /// <remarks>
        /// <para>
        /// The <paramref name="contactText" /> parameter should be passed as the SIP request URI,
        /// or the value of a <b>To</b>, <b>From</b>, or a <b>Contact</b> header value.  The method
        /// parses this value, looking for the IP address, port, and transport information to be used
        /// when selecting a transport to communicate with this entity.  The method will perform an
        /// necessary DNS lookups to resolve host names into IP addresses.
        /// </para>
        /// <para>
        /// If the operation was successful, the method returns <c>true</c> and sets the <paramref name="binding" />
        /// and <paramref name="transportType" /> values.
        /// </para>
        /// <note>
        /// <paramref name="transportType" /> will return as <see cref="SipTransportType.Unspecified" /> if the
        /// contact information didn't explicitly specify a transport.
        /// </note>
        /// </remarks>
        public static bool TryGetRemoteBinding(string contactText, out NetworkBinding binding, out SipTransportType transportType)
        {
            SipContactValue v = new SipContactValue(contactText);
            IPAddress       address;
            int             port;
            SipUri          uri;
            string          transport;
            string          sHost, sPort;
            int             p;

            binding       = null;
            transportType = SipTransportType.Unspecified;

            // First try to parse the text as a SIP URI.

            if (SipUri.TryParse(v.Uri, out uri))
            {
                if (!IPAddress.TryParse(uri.Host, out address))
                {
                    try
                    {
                        address = Dns.GetHostEntry(uri.Host).AddressList[0];
                    }
                    catch
                    {
                        return(false);
                    }
                }

                binding = new NetworkBinding(address, uri.Port);

                if (uri.Parameters.TryGetValue("transport", out transport))
                {
                    switch (transport.ToUpper())
                    {
                    case "UDP":

                        transportType = SipTransportType.UDP;
                        break;

                    case "TCP":

                        transportType = SipTransportType.TCP;
                        break;

                    case "TLS":

                        transportType = SipTransportType.TLS;
                        break;
                    }
                }

                return(true);
            }

            // Now look for <ip-address> [":" <port>]

            p = v.Uri.IndexOf(':');
            if (p == -1)
            {
                if (!IPAddress.TryParse(v.Uri, out address))
                {
                    try
                    {
                        address = Dns.GetHostEntry(v.Uri).AddressList.IPv4Only()[0];
                    }
                    catch
                    {
                        return(false);
                    }
                }

                binding = new NetworkBinding(address, NetworkPort.SIP);
                return(true);
            }

            sHost = v.Uri.Substring(0, p).Trim();
            sPort = v.Uri.Substring(p + 1).Trim();

            if (sHost.Length == 0 || sPort.Length == 0)
            {
                return(false);
            }

            if (!int.TryParse(sPort, out port) || port <= 0 || port > ushort.MaxValue)
            {
                return(false);
            }

            if (IPAddress.TryParse(sHost, out address))
            {
                binding = new NetworkBinding(address, port);
                return(true);
            }

            // The host portion is not an IP address so perform a host lookup

            if (!IPAddress.TryParse(sHost, out address))
            {
                try
                {
                    address = Dns.GetHostEntry(sHost).AddressList.IPv4Only()[0];
                }
                catch
                {
                    return(false);
                }
            }

            binding = new NetworkBinding(address, port);
            return(true);
        }