SIPSorcery.SIP.SIPURI.ParseSIPURIRelaxed C# (CSharp) Method

ParseSIPURIRelaxed() public static method

public static ParseSIPURIRelaxed ( string partialURI ) : SIPURI
partialURI string
return SIPURI
        public static SIPURI ParseSIPURIRelaxed(string partialURI)
        {
            if (partialURI == null || partialURI.Trim().Length == 0)
            {
                return null;
            }
            else
            {
                string regexSchemePattern = "^(" + SIPSchemesEnum.sip + "|" + SIPSchemesEnum.sips + "):";

                if (Regex.Match(partialURI, regexSchemePattern + @"\S+").Success)
                {
                    // The partial uri is already valid.
                    return SIPURI.ParseSIPURI(partialURI);
                }
                else
                {
                    // The partial URI is missing the scheme.
                    return SIPURI.ParseSIPURI(m_defaultSIPScheme.ToString() + SCHEME_ADDR_SEPARATOR.ToString() + partialURI);
                }
            }
        }

Usage Example

Example #1
0
        /// <summary>
        /// Parses a SIP end point from either a serialised SIP end point string, format of:
        /// (udp|tcp|tls|ws|wss):(IPEndpoint)
        /// or from a string that represents a SIP URI.
        /// </summary>
        /// <param name="sipEndPointStr">The string to parse to extract the SIP end point.</param>
        /// <returns>If successful a SIPEndPoint object or null otherwise.</returns>
        public static SIPEndPoint ParseSIPEndPoint(string sipEndPointStr)
        {
            if (sipEndPointStr.IsNullOrBlank())
            {
                return(null);
            }

            if (sipEndPointStr.ToLower().StartsWith("udp:") ||
                sipEndPointStr.ToLower().StartsWith("tcp:") ||
                sipEndPointStr.ToLower().StartsWith("tls:") ||
                sipEndPointStr.ToLower().StartsWith("ws:") ||
                sipEndPointStr.ToLower().StartsWith("wss:"))
            {
                return(ParseSerialisedSIPEndPoint(sipEndPointStr));
            }
            else
            {
                var sipUri      = SIPURI.ParseSIPURIRelaxed(sipEndPointStr);
                var sipEndPoint = sipUri.ToSIPEndPoint();
                if (sipEndPoint != null)
                {
                    sipEndPoint.Scheme = sipUri.Scheme;
                    return(sipEndPoint);
                }
                else
                {
                    return(null);
                }
            }
        }
All Usage Examples Of SIPSorcery.SIP.SIPURI::ParseSIPURIRelaxed