RemoveAt() private method

private RemoveAt ( int idx ) : void
idx int
return void
示例#1
0
        private void MergeUpdateCollections(CookieCollection destination, CookieCollection source, int port, bool isSecure, bool isPlainOnly)
        {
            lock (source)
            {
                // Cannot use foreach as we going update 'source'
                for (int idx = 0; idx < source.Count; ++idx)
                {
                    bool to_add = false;

                    Cookie cookie = source[idx];

                    if (cookie.Expired)
                    {
                        // If expired, remove from container and don't add to the destination
                        source.RemoveAt(idx);
                        --_count;
                        --idx;
                    }
                    else
                    {
                        // Add only if port does match to this request URI
                        // or was not present in the original response.
                        if (isPlainOnly && cookie.Variant != CookieVariant.Plain)
                        {
                            ; // Don't add
                        }
                        else if (cookie.PortList != null)
                        {
                            foreach (int p in cookie.PortList)
                            {
                                if (p == port)
                                {
                                    to_add = true;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            // It was implicit Port, always OK to add.
                            to_add = true;
                        }

                        // Refuse to add a secure cookie into an 'unsecure' destination
                        if (cookie.Secure && !isSecure)
                        {
                            to_add = false;
                        }

                        if (to_add)
                        {
                            // In 'source' are already orederd.
                            // If two same cookies come from different 'source' then they
                            // will follow (not replace) each other.
                            destination.InternalAdd(cookie, false);
                        }
                    }
                }
            }
        }
示例#2
0
 private void MergeUpdateCollections(CookieCollection destination, CookieCollection source, int port, bool isSecure, bool isPlainOnly)
 {
     lock (source)
     {
         for (int local_0 = 0; local_0 < source.Count; ++local_0)
         {
             bool   local_1 = false;
             Cookie local_2 = source[local_0];
             if (local_2.Expired)
             {
                 source.RemoveAt(local_0);
                 --this.m_count;
                 --local_0;
             }
             else
             {
                 if (!isPlainOnly || local_2.Variant == CookieVariant.Plain)
                 {
                     if (local_2.PortList != null)
                     {
                         foreach (int item_0 in local_2.PortList)
                         {
                             if (item_0 == port)
                             {
                                 local_1 = true;
                                 break;
                             }
                         }
                     }
                     else
                     {
                         local_1 = true;
                     }
                 }
                 if (local_2.Secure && !isSecure)
                 {
                     local_1 = false;
                 }
                 if (local_1)
                 {
                     destination.InternalAdd(local_2, false);
                 }
             }
         }
     }
 }
示例#3
0
        private int ExpireCollection(CookieCollection cc)
        {
            int count = cc.Count;
            int idx   = count - 1;

            lock (cc)
            {
                for (; idx >= 0; --idx)
                {
                    if (cc[idx].Expired)
                    {
                        cc.RemoveAt(idx);
                    }
                }
            }
            return(count - cc.Count);
        }
示例#4
0
 //return number of cookies removed from the collection
 private int ExpireCollection(CookieCollection cc)
 {
     lock (cc) {
         int oldCount = cc.Count;
         int idx      = oldCount - 1;
         //Cannot use enumerator as we are going to alter collection
         while (idx >= 0)
         {
             Cookie cookie = cc[idx];
             if (cookie.Expired)
             {
                 cc.RemoveAt(idx);
             }
             --idx;
         }
         return(oldCount - cc.Count);
     }
 }
 private void MergeUpdateCollections(CookieCollection destination, CookieCollection source, int port, bool isSecure, bool isPlainOnly)
 {
     lock (source)
     {
         for (int i = 0; i < source.Count; i++)
         {
             bool   flag   = false;
             Cookie cookie = source[i];
             if (cookie.Expired)
             {
                 source.RemoveAt(i);
                 this.m_count--;
                 i--;
                 continue;
             }
             if (!isPlainOnly || (cookie.Variant == CookieVariant.Plain))
             {
                 if (cookie.PortList != null)
                 {
                     foreach (int num2 in cookie.PortList)
                     {
                         if (num2 == port)
                         {
                             flag = true;
                             break;
                         }
                     }
                 }
                 else
                 {
                     flag = true;
                 }
             }
             if (cookie.Secure && !isSecure)
             {
                 flag = false;
             }
             if (flag)
             {
                 destination.InternalAdd(cookie, false);
             }
         }
     }
 }
        private int ExpireCollection(CookieCollection cc)
        {
            int count = cc.Count;
            int idx   = count - 1;

            lock (cc)
            {
                while (idx >= 0)
                {
                    Cookie cookie = cc[idx];
                    if (cookie.Expired)
                    {
                        cc.RemoveAt(idx);
                    }
                    idx--;
                }
            }
            return(count - cc.Count);
        }
示例#7
0
        //return number of cookies removed from the collection
        private int ExpireCollection(CookieCollection cc)
        {
            int oldCount = cc.Count;
            int idx      = oldCount - 1;

            // minor optimization by caching Now
            DateTime now = DateTime.Now;

            lock (cc) {
                //Cannot use enumerator as we are going to alter collection
                while (idx >= 0)
                {
                    Cookie cookie = cc[idx];
                    if (cookie.Expires <= now && cookie.Expires != DateTime.MinValue)
                    {
                        cc.RemoveAt(idx);
                    }
                    --idx;
                }
            }
            return(oldCount - cc.Count);
        }
示例#8
0
        // This function, when called, must delete at least one cookie.
        // If there are expired cookies in given scope they are cleaned up.
        // If nothing is found the least used Collection will be found and removed
        // from the container.
        //
        // Also note that expired cookies are also removed during request preparation
        // (this.GetCookies method).
        //
        // Param. 'domain' == null means to age in the whole container.
        private bool AgeCookies(string domain)
        {
            Debug.Assert(m_maxCookies != 0);
            Debug.Assert(m_maxCookiesPerDomain != 0);

            int      removed = 0;
            DateTime oldUsed = DateTime.MaxValue;
            DateTime tempUsed;

            CookieCollection lruCc      = null;
            string           lruDomain  = null;
            string           tempDomain = null;

            PathList pathList;
            int      domain_count      = 0;
            int      itemp             = 0;
            float    remainingFraction = 1.0F;

            // The container was shrunk, might need additional cleanup for each domain
            if (m_count > m_maxCookies)
            {
                // Means the fraction of the container to be left.
                // Each domain will be cut accordingly.
                remainingFraction = (float)m_maxCookies / (float)m_count;
            }
            lock (m_domainTable)
            {
                foreach (KeyValuePair <string, PathList> entry in m_domainTable)
                {
                    if (domain == null)
                    {
                        tempDomain = entry.Key;
                        pathList   = entry.Value; // Aliasing to trick foreach
                    }
                    else
                    {
                        tempDomain = domain;
                        m_domainTable.TryGetValue(domain, out pathList);
                    }

                    domain_count = 0; // Cookies in the domain
                    lock (pathList.SyncRoot)
                    {
                        foreach (KeyValuePair <string, CookieCollection> pair in pathList)
                        {
                            CookieCollection cc = pair.Value;
                            itemp         = ExpireCollection(cc);
                            removed      += itemp;
                            m_count      -= itemp; // Update this container's count
                            domain_count += cc.Count;

                            // We also find the least used cookie collection in ENTIRE container.
                            // We count the collection as LRU only if it holds 1+ elements.
                            if (cc.Count > 0 && (tempUsed = cc.TimeStamp(CookieCollection.Stamp.Check)) < oldUsed)
                            {
                                lruDomain = tempDomain;
                                lruCc     = cc;
                                oldUsed   = tempUsed;
                            }
                        }
                    }

                    // Check if we have reduced to the limit of the domain by expiration only.
                    int min_count = Math.Min((int)(domain_count * remainingFraction), Math.Min(m_maxCookiesPerDomain, m_maxCookies) - 1);
                    if (domain_count > min_count)
                    {
                        // This case requires sorting all domain collections by timestamp.
                        KeyValuePair <DateTime, CookieCollection>[] cookies;
                        lock (pathList.SyncRoot)
                        {
                            cookies = new KeyValuePair <DateTime, CookieCollection> [pathList.Count];
                            foreach (KeyValuePair <string, CookieCollection> pair in pathList)
                            {
                                CookieCollection cc = pair.Value;
                                cookies[itemp] = new KeyValuePair <DateTime, CookieCollection>(cc.TimeStamp(CookieCollection.Stamp.Check), cc);
                                ++itemp;
                            }
                        }
                        Array.Sort(cookies, (a, b) => a.Key.CompareTo(b.Key));

                        itemp = 0;
                        for (int i = 0; i < cookies.Length; ++i)
                        {
                            CookieCollection cc = cookies[i].Value;

                            lock (cc)
                            {
                                while (domain_count > min_count && cc.Count > 0)
                                {
                                    cc.RemoveAt(0);
                                    --domain_count;
                                    --m_count;
                                    ++removed;
                                }
                            }
                            if (domain_count <= min_count)
                            {
                                break;
                            }
                        }

                        if (domain_count > min_count && domain != null)
                        {
                            // Cannot complete aging of explicit domain (no cookie adding allowed).
                            return(false);
                        }
                    }
                }
            }

            // We have completed aging of the specified domain.
            if (domain != null)
            {
                return(true);
            }

            // The rest is for entire container aging.
            // We must get at least one free slot.

            // Don't need to apply LRU if we already cleaned something.
            if (removed != 0)
            {
                return(true);
            }

            if (oldUsed == DateTime.MaxValue)
            {
                // Something strange. Either capacity is 0 or all collections are locked with cc.Used.
                return(false);
            }

            // Remove oldest cookies from the least used collection.
            lock (lruCc)
            {
                while (m_count >= m_maxCookies && lruCc.Count > 0)
                {
                    lruCc.RemoveAt(0);
                    --m_count;
                }
            }
            return(true);
        }
示例#9
0
 private int ExpireCollection(CookieCollection cc)
 {
     int count = cc.Count;
       int idx = count - 1;
       lock (cc)
       {
     for (; idx >= 0; --idx)
     {
       if (cc[idx].Expired)
     cc.RemoveAt(idx);
     }
       }
       return count - cc.Count;
 }
        //return number of cookies removed from the collection
        private int ExpireCollection(CookieCollection cc) {
            int oldCount = cc.Count;
            int idx = oldCount-1;

            // minor optimization by caching Now
            DateTime now = DateTime.Now;

            lock (cc) {
                //Cannot use enumerator as we are going to alter collection
                while (idx >= 0) {
                    Cookie cookie = cc[idx];
                    if (cookie.Expires <= now && cookie.Expires != DateTime.MinValue) {

                        cc.RemoveAt(idx);
                    }
                    --idx;
                }
            }
            return oldCount - cc.Count;
        }
示例#11
0
        private bool AgeCookies(string?domain)
        {
            Debug.Assert(m_maxCookies != 0);
            Debug.Assert(m_maxCookiesPerDomain != 0);

            int      removed = 0;
            DateTime oldUsed = DateTime.MaxValue;
            DateTime tempUsed;

            CookieCollection?lruCc     = null;
            string?          lruDomain = null;
            string           tempDomain;

            PathList pathList;
            int      domain_count      = 0;
            int      itemp             = 0;
            float    remainingFraction = 1.0F;

            // The container was shrunk, might need additional cleanup for each domain
            if (m_count > m_maxCookies)
            {
                // Means the fraction of the container to be left.
                // Each domain will be cut accordingly.
                remainingFraction = (float)m_maxCookies / (float)m_count;
            }
            lock (m_domainTable.SyncRoot)
            {
                foreach (object item in m_domainTable)
                {
                    DictionaryEntry entry = (DictionaryEntry)item;
                    if (domain == null)
                    {
                        tempDomain = (string)entry.Key;
                        pathList   = (PathList)entry.Value !; // Aliasing to trick foreach
                    }
                    else
                    {
                        tempDomain = domain;
                        pathList   = (PathList)m_domainTable[domain] !;
                    }

                    domain_count = 0; // Cookies in the domain
                    lock (pathList.SyncRoot)
                    {
                        foreach (CookieCollection?cc in pathList.Values)
                        {
                            Debug.Assert(cc != null);
                            itemp         = ExpireCollection(cc);
                            removed      += itemp;
                            m_count      -= itemp; // Update this container's count
                            domain_count += cc.Count;

                            // We also find the least used cookie collection in ENTIRE container.
                            // We count the collection as LRU only if it holds 1+ elements.
                            if (cc.Count > 0 && (tempUsed = cc.TimeStamp(CookieCollection.Stamp.Check)) < oldUsed)
                            {
                                lruDomain = tempDomain;
                                lruCc     = cc;
                                oldUsed   = tempUsed;
                            }
                        }
                    }

                    // Check if we have reduced to the limit of the domain by expiration only.
                    int min_count = Math.Min((int)(domain_count * remainingFraction), Math.Min(m_maxCookiesPerDomain, m_maxCookies) - 1);
                    if (domain_count > min_count)
                    {
                        // This case requires sorting all domain collections by timestamp.
                        Array cookies;
                        Array stamps;
                        lock (pathList.SyncRoot)
                        {
                            cookies = Array.CreateInstance(typeof(CookieCollection), pathList.Count);
                            stamps  = Array.CreateInstance(typeof(DateTime), pathList.Count);
                            foreach (CookieCollection?cc in pathList.Values)
                            {
                                stamps.SetValue(cc !.TimeStamp(CookieCollection.Stamp.Check), itemp);
                                cookies.SetValue(cc, itemp);
                                ++itemp;
                            }
                        }
                        Array.Sort(stamps, cookies);

                        itemp = 0;
                        for (int i = 0; i < cookies.Length; ++i)
                        {
                            CookieCollection cc = (CookieCollection)cookies.GetValue(i) !;

                            lock (cc)
                            {
                                while (domain_count > min_count && cc.Count > 0)
                                {
                                    cc.RemoveAt(0);
                                    --domain_count;
                                    --m_count;
                                    ++removed;
                                }
                            }
                            if (domain_count <= min_count)
                            {
                                break;
                            }
                        }

                        if (domain_count > min_count && domain != null)
                        {
                            // Cannot complete aging of explicit domain (no cookie adding allowed).
                            return(false);
                        }
                    }
                }
            }

            // We have completed aging of the specified domain.
            if (domain != null)
            {
                return(true);
            }

            // The rest is for entire container aging.
            // We must get at least one free slot.

            // Don't need to apply LRU if we already cleaned something.
            if (removed != 0)
            {
                return(true);
            }

            if (oldUsed == DateTime.MaxValue)
            {
                // Something strange. Either capacity is 0 or all collections are locked with cc.Used.
                return(false);
            }

            // Remove oldest cookies from the least used collection.
            lock (lruCc !)
            {
                while (m_count >= m_maxCookies && lruCc.Count > 0)
                {
                    lruCc.RemoveAt(0);
                    --m_count;
                }
            }
            return(true);
        }
        private bool AgeCookies(string domain)
        {
            if ((this.m_maxCookies == 0) || (this.m_maxCookiesPerDomain == 0))
            {
                this.m_domainTable = new Hashtable();
                this.m_count       = 0;
                return(false);
            }
            int              num      = 0;
            DateTime         maxValue = DateTime.MaxValue;
            CookieCollection cookies  = null;
            string           key      = null;
            int              num2     = 0;
            int              index    = 0;
            float            num4     = 1f;

            if (this.m_count > this.m_maxCookies)
            {
                num4 = ((float)this.m_maxCookies) / ((float)this.m_count);
            }
            foreach (DictionaryEntry entry in this.m_domainTable)
            {
                PathList list;
                if (domain == null)
                {
                    key  = (string)entry.Key;
                    list = (PathList)entry.Value;
                }
                else
                {
                    key  = domain;
                    list = (PathList)this.m_domainTable[domain];
                }
                num2 = 0;
                foreach (CookieCollection cookies2 in list.Values)
                {
                    DateTime time2;
                    index         = this.ExpireCollection(cookies2);
                    num          += index;
                    this.m_count -= index;
                    num2         += cookies2.Count;
                    if ((cookies2.Count > 0) && ((time2 = cookies2.TimeStamp(CookieCollection.Stamp.Check)) < maxValue))
                    {
                        cookies  = cookies2;
                        maxValue = time2;
                    }
                }
                int num5 = Math.Min((int)(num2 * num4), Math.Min(this.m_maxCookiesPerDomain, this.m_maxCookies) - 1);
                if (num2 > num5)
                {
                    Array items = Array.CreateInstance(typeof(CookieCollection), list.Count);
                    Array keys  = Array.CreateInstance(typeof(DateTime), list.Count);
                    foreach (CookieCollection cookies3 in list.Values)
                    {
                        keys.SetValue(cookies3.TimeStamp(CookieCollection.Stamp.Check), index);
                        items.SetValue(cookies3, index);
                        index++;
                    }
                    Array.Sort(keys, items);
                    index = 0;
                    for (int i = 0; i < list.Count; i++)
                    {
                        CookieCollection cookies4 = (CookieCollection)items.GetValue(i);
                        lock (cookies4)
                        {
                            while ((num2 > num5) && (cookies4.Count > 0))
                            {
                                cookies4.RemoveAt(0);
                                num2--;
                                this.m_count--;
                                num++;
                            }
                        }
                        if (num2 <= num5)
                        {
                            break;
                        }
                    }
                    if ((num2 > num5) && (domain != null))
                    {
                        return(false);
                    }
                }
                if (domain != null)
                {
                    return(true);
                }
            }
            if (num == 0)
            {
                if (maxValue == DateTime.MaxValue)
                {
                    return(false);
                }
                lock (cookies)
                {
                    while ((this.m_count >= this.m_maxCookies) && (cookies.Count > 0))
                    {
                        cookies.RemoveAt(0);
                        this.m_count--;
                    }
                }
            }
            return(true);
        }
示例#13
0
        private void MergeUpdateCollections(CookieCollection destination, CookieCollection source, int port, bool isSecure, bool isPlainOnly)
        {
            lock (source)
            {
                // Cannot use foreach as we going update 'source'
                for (int idx = 0; idx < source.Count; ++idx)
                {
                    bool to_add = false;

                    Cookie cookie = source[idx];

                    if (cookie.Expired)
                    {
                        // If expired, remove from container and don't add to the destination
                        source.RemoveAt(idx);
                        --_count;
                        --idx;
                    }
                    else
                    {
                        // Add only if port does match to this request URI
                        // or was not present in the original response.
                        if (isPlainOnly && cookie.Variant != CookieVariant.Plain)
                        {
                            ; // Don't add
                        }
                        else if (cookie.PortList != null)
                        {
                            foreach (int p in cookie.PortList)
                            {
                                if (p == port)
                                {
                                    to_add = true;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            // It was implicit Port, always OK to add.
                            to_add = true;
                        }

                        // Refuse to add a secure cookie into an 'unsecure' destination
                        if (cookie.Secure && !isSecure)
                        {
                            to_add = false;
                        }

                        if (to_add)
                        {
                            // In 'source' are already orederd.
                            // If two same cookies come from different 'source' then they
                            // will follow (not replace) each other.
                            destination.InternalAdd(cookie, false);
                        }
                    }
                }
            }
        }
示例#14
0
        // Return number of cookies removed from the collection.
        private int ExpireCollection(CookieCollection cc)
        {
            lock (cc)
            {
                int oldCount = cc.Count;
                int idx = oldCount - 1;

                // Cannot use enumerator as we are going to alter collection.
                while (idx >= 0)
                {
                    Cookie cookie = cc[idx];
                    if (cookie.Expired)
                    {
                        cc.RemoveAt(idx);
                    }
                    --idx;
                }
                return oldCount - cc.Count;
            }
        }
示例#15
0
 private void MergeUpdateCollections(CookieCollection destination, CookieCollection source, int port, bool isSecure, bool isPlainOnly)
 {
     lock (source)
       {
     for (int local_0 = 0; local_0 < source.Count; ++local_0)
     {
       bool local_1 = false;
       Cookie local_2 = source[local_0];
       if (local_2.Expired)
       {
     source.RemoveAt(local_0);
     --this.m_count;
     --local_0;
       }
       else
       {
     if (!isPlainOnly || local_2.Variant == CookieVariant.Plain)
     {
       if (local_2.PortList != null)
       {
         foreach (int item_0 in local_2.PortList)
         {
           if (item_0 == port)
           {
             local_1 = true;
             break;
           }
         }
       }
       else
         local_1 = true;
     }
     if (local_2.Secure && !isSecure)
       local_1 = false;
     if (local_1)
       destination.InternalAdd(local_2, false);
       }
     }
       }
 }
 private int ExpireCollection(CookieCollection cc)
 {
     int count = cc.Count;
     int idx = count - 1;
     lock (cc)
     {
         while (idx >= 0)
         {
             Cookie cookie = cc[idx];
             if (cookie.Expired)
             {
                 cc.RemoveAt(idx);
             }
             idx--;
         }
     }
     return (count - cc.Count);
 }
示例#17
0
        //
        // This function, once called, must delete at least one cookie
        // If there are expired cookies in given scope they are cleaned up
        // If nothing found the least used Collection will be found and removed
        // from the container.
        //
        // Also note that expired cookies are also removed during request preparation
        // (this.GetCookies method)
        //
        // Param. 'domain' == null means to age in the whole container
        //
        private bool AgeCookies(string domain)
        {
            // border case => shrinked to zero
            if (m_maxCookies == 0 || m_maxCookiesPerDomain == 0)
            {
                m_domainTable = new Hashtable();
                m_count       = 0;
                return(false);
            }

            int      removed = 0;
            DateTime oldUsed = DateTime.MaxValue;
            DateTime tempUsed;

            CookieCollection lruCc      = null;
            string           lruDomain  = null;
            string           tempDomain = null;

            PathList pathList;
            int      domain_count      = 0;
            int      itemp             = 0;
            float    remainingFraction = 1.0F;

            // the container was shrinked, might need additional cleanup for each domain
            if (m_count > m_maxCookies)
            {
                // Means the fraction of the container to be left
                // Each domain will be cut accordingly
                remainingFraction = (float)m_maxCookies / (float)m_count;
            }

            foreach (DictionaryEntry entry in m_domainTable)
            {
                if (domain == null)
                {
                    tempDomain = (string)entry.Key;
                    pathList   = (PathList)entry.Value;         //aliasing to trick foreach
                }
                else
                {
                    tempDomain = domain;
                    pathList   = (PathList)m_domainTable[domain];
                }

                domain_count = 0;                             // cookies in the domain
                foreach (CookieCollection cc in pathList.Values)
                {
                    itemp         = ExpireCollection(cc);
                    removed      += itemp;
                    m_count      -= itemp;                 //update this container count;
                    domain_count += cc.Count;
                    // we also find the least used cookie collection in ENTIRE container
                    // we count the collection as LRU only if it holds 1+ elements
                    if (cc.Count > 0 && (tempUsed = cc.TimeStamp(CookieCollection.Stamp.Check)) < oldUsed)
                    {
                        lruDomain = tempDomain;
                        lruCc     = cc;
                        oldUsed   = tempUsed;
                    }
                }

                // Check if we have reduced to the limit of the domain by expiration only
                int min_count = Math.Min((int)(domain_count * remainingFraction), Math.Min(m_maxCookiesPerDomain, m_maxCookies) - 1);
                if (domain_count > min_count)
                {
                    //That case require sorting all domain collections by timestamp
                    Array cookies = Array.CreateInstance(typeof(CookieCollection), pathList.Count);
                    Array stamps  = Array.CreateInstance(typeof(DateTime), pathList.Count);
                    foreach (CookieCollection cc in pathList.Values)
                    {
                        stamps.SetValue(cc.TimeStamp(CookieCollection.Stamp.Check), itemp);
                        cookies.SetValue(cc, itemp);
                        ++itemp;
                    }
                    Array.Sort(stamps, cookies);

                    itemp = 0;
                    for (int i = 0; i < pathList.Count; ++i)
                    {
                        CookieCollection cc = (CookieCollection)cookies.GetValue(i);

                        lock (cc) {
                            while (domain_count > min_count && cc.Count > 0)
                            {
                                cc.RemoveAt(0);
                                --domain_count;
                                --m_count;
                                ++removed;
                            }
                        }
                        if (domain_count <= min_count)
                        {
                            break;
                        }
                    }

                    if (domain_count > min_count && domain != null)
                    {
                        //cannot complete aging of explicit domain (no cookie adding allowed)
                        return(false);
                    }
                }

                // we have completed aging of specific domain
                if (domain != null)
                {
                    return(true);
                }
            }

            //  The rest is  for entire container aging
            //  We must get at least one free slot.

            //Don't need to appy LRU if we already cleaned something
            if (removed != 0)
            {
                return(true);
            }

            if (oldUsed == DateTime.MaxValue)
            {
                //Something strange. Either capacity is 0 or all collections are locked with cc.Used
                return(false);
            }

            // Remove oldest cookies from the least used collection
            lock (lruCc) {
                while (m_count >= m_maxCookies && lruCc.Count > 0)
                {
                    lruCc.RemoveAt(0);
                    --m_count;
                }
            }
            return(true);
        }
 private void MergeUpdateCollections(CookieCollection destination, CookieCollection source, int port, bool isSecure, bool isPlainOnly)
 {
     lock (source)
     {
         for (int i = 0; i < source.Count; i++)
         {
             bool flag = false;
             Cookie cookie = source[i];
             if (cookie.Expired)
             {
                 source.RemoveAt(i);
                 this.m_count--;
                 i--;
                 continue;
             }
             if (!isPlainOnly || (cookie.Variant == CookieVariant.Plain))
             {
                 if (cookie.PortList != null)
                 {
                     foreach (int num2 in cookie.PortList)
                     {
                         if (num2 == port)
                         {
                             flag = true;
                             break;
                         }
                     }
                 }
                 else
                 {
                     flag = true;
                 }
             }
             if (cookie.Secure && !isSecure)
             {
                 flag = false;
             }
             if (flag)
             {
                 destination.InternalAdd(cookie, false);
             }
         }
     }
 }
示例#19
0
 private bool AgeCookies(string domain)
 {
     if (this.m_maxCookies == 0 || this.m_maxCookiesPerDomain == 0)
     {
         this.m_domainTable = new Hashtable();
         this.m_count       = 0;
         return(false);
     }
     else
     {
         int              num1              = 0;
         DateTime         dateTime1         = DateTime.MaxValue;
         CookieCollection cookieCollection1 = (CookieCollection)null;
         string           str    = (string)null;
         int              index1 = 0;
         float            num2   = 1f;
         if (this.m_count > this.m_maxCookies)
         {
             num2 = (float)this.m_maxCookies / (float)this.m_count;
         }
         foreach (DictionaryEntry dictionaryEntry in this.m_domainTable)
         {
             PathList pathList;
             if (domain == null)
             {
                 str      = (string)dictionaryEntry.Key;
                 pathList = (PathList)dictionaryEntry.Value;
             }
             else
             {
                 str      = domain;
                 pathList = (PathList)this.m_domainTable[(object)domain];
             }
             int num3 = 0;
             foreach (CookieCollection cc in (IEnumerable)pathList.Values)
             {
                 index1        = this.ExpireCollection(cc);
                 num1         += index1;
                 this.m_count -= index1;
                 num3         += cc.Count;
                 DateTime dateTime2;
                 if (cc.Count > 0 && (dateTime2 = cc.TimeStamp(CookieCollection.Stamp.Check)) < dateTime1)
                 {
                     cookieCollection1 = cc;
                     dateTime1         = dateTime2;
                 }
             }
             int num4 = Math.Min((int)((double)num3 * (double)num2), Math.Min(this.m_maxCookiesPerDomain, this.m_maxCookies) - 1);
             if (num3 > num4)
             {
                 Array instance1 = Array.CreateInstance(typeof(CookieCollection), pathList.Count);
                 Array instance2 = Array.CreateInstance(typeof(DateTime), pathList.Count);
                 foreach (CookieCollection cookieCollection2 in (IEnumerable)pathList.Values)
                 {
                     instance2.SetValue((object)cookieCollection2.TimeStamp(CookieCollection.Stamp.Check), index1);
                     instance1.SetValue((object)cookieCollection2, index1);
                     ++index1;
                 }
                 Array.Sort(instance2, instance1);
                 index1 = 0;
                 for (int index2 = 0; index2 < pathList.Count; ++index2)
                 {
                     CookieCollection cookieCollection2 = (CookieCollection)instance1.GetValue(index2);
                     lock (cookieCollection2)
                     {
                         while (num3 > num4)
                         {
                             if (cookieCollection2.Count > 0)
                             {
                                 cookieCollection2.RemoveAt(0);
                                 --num3;
                                 --this.m_count;
                                 ++num1;
                             }
                             else
                             {
                                 break;
                             }
                         }
                     }
                     if (num3 <= num4)
                     {
                         break;
                     }
                 }
                 if (num3 > num4 && domain != null)
                 {
                     return(false);
                 }
             }
             if (domain != null)
             {
                 return(true);
             }
         }
         if (num1 != 0)
         {
             return(true);
         }
         if (dateTime1 == DateTime.MaxValue)
         {
             return(false);
         }
         lock (cookieCollection1)
         {
             for (; this.m_count >= this.m_maxCookies; --this.m_count)
             {
                 if (cookieCollection1.Count > 0)
                 {
                     cookieCollection1.RemoveAt(0);
                 }
                 else
                 {
                     break;
                 }
             }
         }
         return(true);
     }
 }