Exemplo n.º 1
0
        public override bool Equals([NotNullWhen(true)] object?comparand)
        {
            Cookie?other = comparand as Cookie;

            return(other != null &&
                   string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase) &&
                   string.Equals(Value, other.Value, StringComparison.Ordinal) &&
                   string.Equals(Path, other.Path, StringComparison.Ordinal) &&
                   CookieComparer.EqualDomains(Domain, other.Domain) &&
                   (Version == other.Version));
        }
Exemplo n.º 2
0
        internal int IndexOf(Cookie cookie)
        {
            int idx = 0;

            foreach (Cookie c in _list)
            {
                if (CookieComparer.Compare(cookie, c) == 0)
                {
                    return(idx);
                }
                ++idx;
            }
            return(-1);
        }
Exemplo n.º 3
0
        // If isStrict == false, assumes that incoming cookie is unique.
        // If isStrict == true, replace the cookie if found same with newest Variant.
        // Returns 1 if added, 0 if replaced or rejected.

        internal int InternalAdd(Cookie cookie, bool isStrict)
        {
            int ret = 1;

            if (isStrict)
            {
                int idx       = 0;
                int listCount = m_list.Count;
                for (int i = 0; i < listCount; i++)
                {
                    Cookie c = (Cookie)m_list[i] !;
                    if (CookieComparer.Equals(cookie, c))
                    {
                        ret = 0; // Will replace or reject

                        // Cookie2 spec requires that new Variant cookie overwrite the old one.
                        if (c !.Variant <= cookie.Variant)
                        {
                            m_list[idx] = cookie;
                        }
                        break;
                    }
                    ++idx;
                }
                if (idx == m_list.Count)
                {
                    m_list.Add(cookie);
                }
            }
            else
            {
                m_list.Add(cookie);
            }
            if (cookie.Version != Cookie.MaxSupportedVersion)
            {
                m_has_other_versions = true;
            }
            return(ret);
        }
Exemplo n.º 4
0
        // If isStrict == false, assumes that incoming cookie is unique.
        // If isStrict == true, replace the cookie if found same with newest Variant.
        // Returns 1 if added, 0 if replaced or rejected.
        internal int InternalAdd(Cookie cookie, bool isStrict)
        {
            int ret = 1;

            if (isStrict)
            {
                CookieComparer comp = CookieComparer.Instance;

                int idx = 0;
                foreach (Cookie c in _list)
                {
                    if (comp.Compare(cookie, c) == 0)
                    {
                        ret = 0; // Will replace or reject

                        // Cookie2 spec requires that new Variant cookie overwrite the old one.
                        if (c.Variant <= cookie.Variant)
                        {
                            _list[idx] = cookie;
                        }
                        break;
                    }
                    ++idx;
                }
                if (idx == _list.Count)
                {
                    _list.Add(cookie);
                }
            }
            else
            {
                _list.Add(cookie);
            }
            if (cookie.Version != Cookie.MaxSupportedVersion)
            {
                _hasOtherVersions = true;
            }
            return(ret);
        }