SIPSorcery.SIP.SIPProtocolsType.GetProtocolType C# (CSharp) Method

GetProtocolType() public static method

public static GetProtocolType ( string protocolType ) : SIPProtocolsEnum
protocolType string
return SIPProtocolsEnum
        public static SIPProtocolsEnum GetProtocolType(string protocolType)
        {
            return (SIPProtocolsEnum)Enum.Parse(typeof(SIPProtocolsEnum), protocolType, true);
        }

Usage Example

Example #1
0
        public static SIPEndPoint ParseSIPEndPoint(string sipEndPointStr)
        {
            try
            {
                if (sipEndPointStr.IsNullOrBlank())
                {
                    return(null);
                }

                if (sipEndPointStr.StartsWith("udp") || sipEndPointStr.StartsWith("tcp") || sipEndPointStr.StartsWith("tls"))
                {
                    return(ParseSerialisedSIPEndPoint(sipEndPointStr));
                }

                string           ipAddress = null;
                int              port      = 0;
                SIPProtocolsEnum protocol  = SIPProtocolsEnum.udp;

                if (sipEndPointStr.StartsWith("sip:"))
                {
                    sipEndPointStr = sipEndPointStr.Substring(4);
                }
                else if (sipEndPointStr.StartsWith("sips:"))
                {
                    sipEndPointStr = sipEndPointStr.Substring(5);
                    protocol       = SIPProtocolsEnum.tls;
                }

                int colonIndex     = sipEndPointStr.IndexOf(':');
                int semiColonIndex = sipEndPointStr.IndexOf(';');
                if (colonIndex == -1 && semiColonIndex == -1)
                {
                    ipAddress = sipEndPointStr;
                }
                else if (colonIndex != -1 && semiColonIndex == -1)
                {
                    ipAddress = sipEndPointStr.Substring(0, colonIndex);
                    port      = Convert.ToInt32(sipEndPointStr.Substring(colonIndex + 1));
                }
                else
                {
                    if (colonIndex != -1 && colonIndex < semiColonIndex)
                    {
                        ipAddress = sipEndPointStr.Substring(0, colonIndex);
                        port      = Convert.ToInt32(sipEndPointStr.Substring(colonIndex + 1, semiColonIndex - colonIndex - 1));
                    }
                    else
                    {
                        ipAddress = sipEndPointStr.Substring(0, semiColonIndex);
                    }

                    if (protocol != SIPProtocolsEnum.tls)
                    {
                        sipEndPointStr = sipEndPointStr.Substring(semiColonIndex + 1);
                        int transportIndex = sipEndPointStr.ToLower().IndexOf(m_transportParameterKey + "=");
                        if (transportIndex != -1)
                        {
                            sipEndPointStr = sipEndPointStr.Substring(transportIndex + 10);
                            semiColonIndex = sipEndPointStr.IndexOf(';');
                            if (semiColonIndex != -1)
                            {
                                protocol = SIPProtocolsType.GetProtocolType(sipEndPointStr.Substring(0, semiColonIndex));
                            }
                            else
                            {
                                protocol = SIPProtocolsType.GetProtocolType(sipEndPointStr);
                            }
                        }
                    }
                }

                if (port == 0)
                {
                    port = (protocol == SIPProtocolsEnum.tls) ? m_defaultSIPTLSPort : m_defaultSIPPort;
                }

                return(new SIPEndPoint(protocol, IPAddress.Parse(ipAddress), port));
            }
            catch //(Exception excp)
            {
                //logger.LogError("Exception ParseSIPEndPoint (sipEndPointStr=" + sipEndPointStr + "). " + excp.Message);
                throw;
            }
        }
All Usage Examples Of SIPSorcery.SIP.SIPProtocolsType::GetProtocolType