/// <summary>
        /// Parse URI from string value.
        /// </summary>
        /// <param name="value">String URI value.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>value</b> is null reference.</exception>
        /// <exception cref="ArgumentException">Is raised when <b>value</b> has invalid URI value.</exception>
        public static AbsoluteUri Parse(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            if (value == "")
            {
                throw new ArgumentException("Argument 'value' value must be specified.");
            }

            string[] scheme_value = value.Split(new[] {':'}, 2);
            if (scheme_value[0].ToLower() == UriSchemes.sip || scheme_value[0].ToLower() == UriSchemes.sips)
            {
                SIP_Uri uri = new SIP_Uri();
                uri.ParseInternal(value);

                return uri;
            }
            else
            {
                AbsoluteUri uri = new AbsoluteUri();
                uri.ParseInternal(value);

                return uri;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>Returns true if two objects are equal.</returns>
        public override bool Equals(object obj)
        {
            /* RFC 3261 19.1.4 URI Comparison.
             *  SIP and SIPS URIs are compared for equality according to the following rules:
             *      o  A SIP and SIPS URI are never equivalent.
             *
             *      o  Comparison of the userinfo of SIP and SIPS URIs is case-
             *         sensitive.  This includes userinfo containing passwords or
             *         formatted as telephone-subscribers.  Comparison of all other
             *         components of the URI is case-insensitive unless explicitly
             *         defined otherwise.
             *
             *      o  The ordering of parameters and header fields is not significant
             *         in comparing SIP and SIPS URIs.
             *
             *      o  Characters other than those in the "reserved" set (see RFC 2396
             *         [5]) are equivalent to their ""%" HEX HEX" encoding.
             *
             *      o  An IP address that is the result of a DNS lookup of a host name
             *         does not match that host name.
             *
             *      o  For two URIs to be equal, the user, password, host, and port
             *         components must match.
             *
             *         A URI omitting the user component will not match a URI that
             *         includes one.  A URI omitting the password component will not
             *         match a URI that includes one.
             *
             *         A URI omitting any component with a default value will not
             *         match a URI explicitly containing that component with its
             *         default value.  For instance, a URI omitting the optional port
             *         component will not match a URI explicitly declaring port 5060.
             *         The same is true for the transport-parameter, ttl-parameter,
             *         user-parameter, and method components.
             *
             *      o  URI uri-parameter components are compared as follows:
             *          -  Any uri-parameter appearing in both URIs must match.
             *
             *          -  A user, ttl, or method uri-parameter appearing in only one
             *             URI never matches, even if it contains the default value.
             *
             *          -  A URI that includes an maddr parameter will not match a URI
             *             that contains no maddr parameter.
             *
             *          -  All other uri-parameters appearing in only one URI are
             *             ignored when comparing the URIs.
             *
             *      o  URI header components are never ignored.  Any present header
             *         component MUST be present in both URIs and match for the URIs
             *         to match.
             *
             */

            if (obj == null)
            {
                return(false);
            }
            if (!(obj is SIP_Uri))
            {
                return(false);
            }

            SIP_Uri sipUri = (SIP_Uri)obj;

            if (IsSecure && !sipUri.IsSecure)
            {
                return(false);
            }

            if (User != sipUri.User)
            {
                return(false);
            }

            /*
             * if(this.Password != sipUri.Password){
             *  return false;
             * }*/

            if (Host.ToLower() != sipUri.Host.ToLower())
            {
                return(false);
            }

            if (Port != sipUri.Port)
            {
                return(false);
            }

            // TODO: prameters compare
            // TODO: header fields compare

            return(true);
        }