ToString() public method

public ToString ( ) : string
return string
Ejemplo n.º 1
0
        /// <summary>Gets the HTTP cookie header that contains the HTTP cookies that represent the <see cref="T:System.Net.Cookie" /> instances that are associated with a specific URI.</summary>
        /// <returns>An HTTP cookie header, with strings representing <see cref="T:System.Net.Cookie" /> instances delimited by semicolons.</returns>
        /// <param name="uri">The URI of the <see cref="T:System.Net.Cookie" /> instances desired. </param>
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="uri" /> is null. </exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        /// </PermissionSet>
        public string GetCookieHeader(System.Uri uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            CookieCollection cookieCollection = this.GetCookies(uri);

            if (cookieCollection.Count == 0)
            {
                return(string.Empty);
            }
            StringBuilder stringBuilder = new StringBuilder();

            foreach (object obj in cookieCollection)
            {
                Cookie cookie = (Cookie)obj;
                stringBuilder.Append(cookie.ToString(uri));
                stringBuilder.Append("; ");
            }
            if (stringBuilder.Length > 0)
            {
                stringBuilder.Length -= 2;
            }
            return(stringBuilder.ToString());
        }
Ejemplo n.º 2
0
        private CookieCollection ParseCookies(Uri uri, string setCookieHeader)
        {
            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Info(this, "uri:" + uri + " setCookieHeader:" + setCookieHeader);
            }
            CookieCollection cookies = new CookieCollection();
            CookieParser     parser  = new CookieParser(setCookieHeader);

            while (true)
            {
                Cookie cookie = parser.GetServer();
                if (cookie == null)
                {
                    // EOF, done.
                    break;
                }
                if (NetEventSource.IsEnabled)
                {
                    NetEventSource.Info(this, "CookieParser returned cookie: " + cookie.ToString());
                }
                if (cookie.Name.Length == 0)
                {
                    continue;
                }

                InternalAddMethod(cookies, cookie, true);
            }
            return(cookies);
        }
Ejemplo n.º 3
0
        private async Task OnAddCookieRequested(System.Net.Cookie cookie)
        {
            if (Control == null || cookie == null || String.IsNullOrEmpty(cookie.Domain) || String.IsNullOrEmpty(cookie.Name))
            {
                return;
            }

            var nsCookie = new NSHttpCookie(cookie);

            if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                var store = _configuration.WebsiteDataStore.HttpCookieStore;
                await store.SetCookieAsync(nsCookie);
            }
            NSHttpCookieStorage.SharedStorage.SetCookie(nsCookie);
            foreach (var cookies in NSHttpCookieStorage.SharedStorage.Cookies)
            {
                System.Diagnostics.Debug.WriteLine(cookie.ToString());
            }

            if (!_cookieDomains.ContainsKey(cookie.Domain))
            {
                _cookieDomains[cookie.Domain] = 0;
            }
            _cookieDomains[cookie.Domain] = _cookieDomains[cookie.Domain] + 1;
#if DEBUG
            await OnPrintCookiesRequested();
#endif
        }
Ejemplo n.º 4
0
		public void PublicFields ()
		{
			Cookie c = new Cookie ();
			Assert.AreEqual (string.Empty, c.Name, "#A1");
			Assert.AreEqual (string.Empty, c.Value, "#A2");
			Assert.AreEqual (string.Empty, c.Domain, "#A3");
			Assert.AreEqual (string.Empty, c.Port, "#A4");
			Assert.AreEqual (string.Empty, c.Comment, "#A5");
			Assert.AreEqual (null, c.CommentUri, "#A6");
			Assert.IsFalse (c.Discard, "#A7");
			Assert.IsFalse (c.Expired, "#A8");
			Assert.AreEqual (DateTime.MinValue, c.Expires, "#A9");
			Assert.IsFalse (c.HttpOnly, "#A10");
			Assert.AreEqual (string.Empty, c.Path, "#A11");
			Assert.IsFalse (c.Secure, "#A12");
			Assert.AreEqual (0, c.Version, "#A13");
			Assert.AreEqual (string.Empty, c.ToString (), "#A14");

			c.Expires = DateTime.Now;
			Assert.IsTrue (c.Expired, "#A15");

			c.Port = null;
			Assert.AreEqual (string.Empty, c.Port, "#A16");

			c.Value = null;
			Assert.AreEqual (string.Empty, c.Value, "#A17");
		}
Ejemplo n.º 5
0
        private ExHentaiConnection()
        {
            wc = new WebClient();

            HatHConfig.Load(System.IO.Directory.GetCurrentDirectory() + "/settings.ini");

            string uid = HatHConfig.UserID;
            string passhash = HatHConfig.PassHash;

            Cookie id = new Cookie("ipb_member_id", uid, "/", ".exhentai.org");
            Cookie pass = new Cookie("ipb_pass_hash", passhash, "/", ".exhentai.org");
            wc.Headers.Add(HttpRequestHeader.Cookie, id.ToString() + ";" + pass.ToString());
        }
Ejemplo n.º 6
0
 private void ExeTest()
 {
     if (QueProxy.Count == 0)
     {
         btnStartTest.Enabled = true;
         return;
     }
     string proxy = QueProxy.Dequeue();
     Cookie coki = new Cookie(CookieId.ToString(), Cookie_P1 + CookieId + "; " + Cookie_P2 + CookieId, Application.StartupPath + "\\Cookie", "/");
     Core.Core.InternetSetCookie(TestUrl, null, coki.ToString() + "; expires = Sun, 01-Jan-2017 00:00:00 GMT");
     Core.Core.RefreshIESettings(proxy);
     wb.Tag = proxy;
     wb.Navigate(TestUrl);
     tmr.Start();
 }
        private void SetCookie(System.Net.Cookie cookie)
        {
            var cookieDomain = cookie.Domain;
            var url          = $"{cookieDomain}";
            var cookieString = $"{cookie.ToString()}; Domain={cookieDomain}; Path={cookie.Path}";

            //CookieSyncManager cookieSyncManager = CookieSyncManager.CreateInstance(_webView.Context);
            CookieManager cookieManager = CookieManager.Instance;

            CookieManager.Instance.SetAcceptCookie(true);
            CookieManager.Instance.RemoveAllCookie();
            System.Threading.Thread.Sleep(500);
            CookieManager.Instance.SetCookie(url, cookieString);
            //cookieSyncManager.Sync();

            if (!_cookieDomains.ContainsKey(cookie.Domain))
            {
                _cookieDomains[cookie.Domain] = 0;
            }
            _cookieDomains[cookie.Domain] = _cookieDomains[cookie.Domain] + 1;
        }
Ejemplo n.º 8
0
    public static Dictionary <int, Tuple <string, Uri, string> > Getniconico(string url, out Dictionary <string, string> videoinfo)
    {
        Uri u = new Uri(url);

        System.Net.Cookie nchs         = null;
        string            player_raw   = "";
        string            watchId      = u.AbsolutePath.Replace("/watch/", "");
        string            getflv_param = n_getflv.getflv(watchId, ref nchs, ref player_raw);

        videoinfo = n_getflv.getflvParse(getflv_param);
        string downloadUri = videoinfo["url"];
        Regex  r           = new Regex("(?<=movieType\\: )\\'.+?\\'", System.Text.RegularExpressions.RegexOptions.ECMAScript | System.Text.RegularExpressions.RegexOptions.Compiled);
        string ext         = r.Matches(player_raw)[0].Value.Replace("'", "");
        Dictionary <int, Tuple <string, Uri, string> > returnvalue = new Dictionary <int, Tuple <string, Uri, string> > {
            {
                0,
                new Tuple <string, Uri, string>("*." + ext, new Uri(downloadUri), nchs.ToString())
            }
        };

        getflv_param = null;
        return(returnvalue);
    }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets a <see cref="DirectConnection"/> by its Rendezvous cookie
        /// </summary>
        /// <returns>The <see cref="DirectConnection"/> that corresponds to the cookie, or null if no corresponding DC is found</returns>
        public DirectConnection GetDirectConnectionByCookie(Cookie key, bool removefromcache)
        {
            DirectConnection retval = null;
            foreach (DirectConnection dc in _directconnections)
            {
                if(dc.Cookie.ToString() == key.ToString())
                {
                    retval = dc;
                    break;
                }
            }

            if (retval != null && removefromcache)
            {
                _directconnections.Remove(retval);
            }

            return retval;
        }
Ejemplo n.º 10
0
        private static string GetHttpHeader(Cookie cookie, string domainOverride = null)
        {
            var cookieHeader = new StringBuilder(1024);

            cookieHeader.AppendFormat("{0}={1}", cookie.Name, cookie.Value);

            // Workaround for bug in Cookie.ToString() which fails to includes the path
            // and domain attributes unless you temporarily set the cookie version to 1.
            if (cookie.Version == 0)
            {
                cookie.Version = 1;
                cookie.Version = 0;
            }

            var cookieString = cookie.ToString();

            if (cookieString.Contains("$Domain=") && !string.IsNullOrWhiteSpace(cookie.Domain))
            {
                cookieHeader.AppendFormat("; Domain={0}", domainOverride ?? cookie.Domain);
            }

            if (!string.IsNullOrWhiteSpace(cookie.Path))
            {
                cookieHeader.AppendFormat("; Path={0}", cookie.Path);
            }

            if (cookie.Expires != DateTime.MinValue)
            {
                var utcExpires = cookie.Expires.Kind == DateTimeKind.Local ? cookie.Expires.ToUniversalTime() : cookie.Expires;
                cookieHeader.AppendFormat("; Expires={0:R}", utcExpires);
            }

            if (!string.IsNullOrWhiteSpace(cookie.Comment))
            {
                cookieHeader.AppendFormat("; Comment={0}", cookie.Comment);
            }

            if (cookie.CommentUri != null)
            {
                cookieHeader.AppendFormat("; CommentURL={0}", cookie.CommentUri);
            }

            if (cookie.HttpOnly)
            {
                cookieHeader.AppendFormat("; HttpOnly");
            }

            if (cookie.Secure && domainOverride == null)
            {
                cookieHeader.AppendFormat("; Secure");
            }

            if (cookie.Discard)
            {
                cookieHeader.AppendFormat("; Discard");
            }

            if (!string.IsNullOrWhiteSpace(cookie.Port))
            {
                cookieHeader.AppendFormat("; Port={0}", cookie.Port);
            }

            if (cookie.Version != 0)
            {
                cookieHeader.AppendFormat("; Version={0}", cookie.Version);
            }

            return cookieHeader.ToString();
        }
Ejemplo n.º 11
0
		public void ToStringTest ()
		{
			Cookie c1 = new Cookie ("NAME", "VALUE", "/", "example.com");
			Assert.AreEqual ("NAME=VALUE", c1.ToString (), "#A1");

			Cookie c2 = new Cookie ();
			Assert.AreEqual (string.Empty, c2.ToString (), "#A2");

			Cookie c3 = new Cookie("NAME", "VALUE");
			Assert.AreEqual ("NAME=VALUE", c3.ToString (), "#A3");

			Cookie c4 = new Cookie ("NAME", "VALUE", "/", "example.com");
			c4.Version = 1;
			Assert.AreEqual ("$Version=1; NAME=VALUE; $Path=/; $Domain=example.com", c4.ToString (), "#A4");

			Cookie c5 = new Cookie ("NAME", "VALUE", "/", "example.com");
			c5.Port = "\"8080\"";
			Assert.AreEqual ("$Version=1; NAME=VALUE; $Path=/; $Domain=example.com; $Port=\"8080\"", c5.ToString (), "#A5");

			Cookie c6 = new Cookie ("NAME", "VALUE");
			c6.Version = 1;
			Assert.AreEqual ("$Version=1; NAME=VALUE", c6.ToString (), "#A6");
		}
Ejemplo n.º 12
0
        // This method is called *only* when cookie verification is done,
        // so unlike with public Add(Cookie cookie) the cookie is in sane condition
        internal void Add(Cookie cookie, bool throwOnError)
        {
            PathList pathList;

            if (cookie.Value.Length > m_maxCookieSize)
            {
                if (throwOnError)
                {
                    throw new CookieException(SR.GetString(SR.net_cookie_size, cookie.ToString(), m_maxCookieSize));
                }
                return;
            }

            try {
                pathList = (PathList)m_domainTable[cookie.DomainKey];
                if (pathList == null)
                {
                    pathList = new PathList();
                    AddRemoveDomain(cookie.DomainKey, pathList);
                }
                int domain_count = pathList.GetCookiesCount();

                CookieCollection cookies = (CookieCollection)pathList[cookie.Path];

                if (cookies == null)
                {
                    cookies = new CookieCollection();
                    pathList[cookie.Path] = cookies;
                }

                if (cookie.Expired)
                {
                    //Explicit removal command (Max-Age == 0)
                    lock (cookies) {
                        int idx = cookies.IndexOf(cookie);
                        if (idx != -1)
                        {
                            cookies.RemoveAt(idx);
                            --m_count;
                        }
                    }
                }
                else
                {
                    //This is about real cookie adding, check Capacity first
                    if (domain_count >= m_maxCookiesPerDomain && !AgeCookies(cookie.DomainKey))
                    {
                        return;     //cannot age -> reject new cookie
                    }
                    else if (this.m_count >= m_maxCookies && !AgeCookies(null))
                    {
                        return;     //cannot age -> reject new cookie
                    }

                    //about to change the collection
                    lock (cookies) {
                        m_count += cookies.InternalAdd(cookie, true);
                    }
                }
            }
            catch (Exception e) {
                if (throwOnError)
                {
                    throw new CookieException(SR.GetString(SR.net_container_add_cookie), e);
                }
            }
        }
Ejemplo n.º 13
0
 internal void Add(Cookie cookie, bool throwOnError)
 {
     if (cookie.Value.Length > this.m_maxCookieSize)
     {
         if (!throwOnError)
         {
             return;
         }
         throw new CookieException(SR.GetString("net_cookie_size", (object)cookie.ToString(), (object)this.m_maxCookieSize));
     }
     else
     {
         try
         {
             PathList pathList = (PathList)this.m_domainTable[(object)cookie.DomainKey];
             if (pathList == null)
             {
                 pathList = new PathList();
                 this.AddRemoveDomain(cookie.DomainKey, pathList);
             }
             int cookiesCount = pathList.GetCookiesCount();
             CookieCollection cookieCollection = (CookieCollection)pathList[cookie.Path];
             if (cookieCollection == null)
             {
                 cookieCollection      = new CookieCollection();
                 pathList[cookie.Path] = (object)cookieCollection;
             }
             if (cookie.Expired)
             {
                 lock (cookieCollection)
                 {
                     int local_3 = cookieCollection.IndexOf(cookie);
                     if (local_3 == -1)
                     {
                         return;
                     }
                     cookieCollection.RemoveAt(local_3);
                     --this.m_count;
                 }
             }
             else
             {
                 if (cookiesCount >= this.m_maxCookiesPerDomain && !this.AgeCookies(cookie.DomainKey) || this.m_count >= this.m_maxCookies && !this.AgeCookies((string)null))
                 {
                     return;
                 }
                 lock (cookieCollection)
                     this.m_count += cookieCollection.InternalAdd(cookie, true);
             }
         }
         catch (Exception ex)
         {
             if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException)
             {
                 throw;
             }
             else if (throwOnError)
             {
                 throw new CookieException(SR.GetString("net_container_add_cookie"), ex);
             }
         }
     }
 }
 internal void Add(Cookie cookie, bool throwOnError)
 {
     if (cookie.Value.Length > this.m_maxCookieSize)
     {
         if (throwOnError)
         {
             throw new CookieException(SR.GetString("net_cookie_size", new object[] { cookie.ToString(), this.m_maxCookieSize }));
         }
     }
     else
     {
         try
         {
             PathList list = (PathList)this.m_domainTable[cookie.DomainKey];
             if (list == null)
             {
                 list = new PathList();
                 this.AddRemoveDomain(cookie.DomainKey, list);
             }
             int cookiesCount         = list.GetCookiesCount();
             CookieCollection cookies = (CookieCollection)list[cookie.Path];
             if (cookies == null)
             {
                 cookies           = new CookieCollection();
                 list[cookie.Path] = cookies;
             }
             if (cookie.Expired)
             {
                 lock (cookies)
                 {
                     int index = cookies.IndexOf(cookie);
                     if (index != -1)
                     {
                         cookies.RemoveAt(index);
                         this.m_count--;
                     }
                     return;
                 }
             }
             if (((cookiesCount < this.m_maxCookiesPerDomain) || this.AgeCookies(cookie.DomainKey)) && ((this.m_count < this.m_maxCookies) || this.AgeCookies(null)))
             {
                 lock (cookies)
                 {
                     this.m_count += cookies.InternalAdd(cookie, true);
                 }
             }
         }
         catch (Exception exception)
         {
             if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
             {
                 throw;
             }
             if (throwOnError)
             {
                 throw new CookieException(SR.GetString("net_container_add_cookie"), exception);
             }
         }
     }
 }
        // This method is called *only* when cookie verification is done,
        // so unlike with public Add(Cookie cookie) the cookie is in sane condition
        internal void Add(Cookie cookie, bool throwOnError) {

            PathList pathList;

            if (cookie.Value.Length > m_maxCookieSize) {
                if (throwOnError) {
                    throw new CookieException(SR.GetString(SR.net_cookie_size, cookie.ToString(), m_maxCookieSize));
                }
                return;
            }

            try {

                pathList = (PathList)m_domainTable[cookie.DomainKey];
                if (pathList == null) {
                    pathList = new PathList();
                    AddRemoveDomain(cookie.DomainKey, pathList);
                }
                int domain_count = pathList.GetCookiesCount();

                CookieCollection cookies = (CookieCollection)pathList[cookie.Path];

                if (cookies == null) {
                    cookies = new CookieCollection();
                    pathList[cookie.Path] = cookies;
                }

                if(cookie.Expired) {
                    //Explicit removal command (Max-Age == 0)
                    lock (cookies) {
                        int idx = cookies.IndexOf(cookie);
                        if (idx != -1) {
                            cookies.RemoveAt(idx);
                            --m_count;
                        }
                    }
                }
                else {
                    //This is about real cookie adding, check Capacity first
                    if (domain_count >= m_maxCookiesPerDomain && !AgeCookies(cookie.DomainKey)) {
                            return; //cannot age -> reject new cookie
                    }
                    else if (this.m_count >= m_maxCookies && !AgeCookies(null)) {
                            return; //cannot age -> reject new cookie
                    }

                    //about to change the collection
                    lock (cookies) {
                        m_count += cookies.InternalAdd(cookie, true);
                    }
                }
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
                    throw;
                }

                if (throwOnError) {
                    throw new CookieException(SR.GetString(SR.net_container_add_cookie), e);
                }
            }
            catch {
                if (throwOnError) {
                    throw new CookieException(SR.GetString(SR.net_container_add_cookie), new Exception(SR.GetString(SR.net_nonClsCompliantException)));
                }
            }
        }
Ejemplo n.º 16
0
		public void GetCookieHeader5b ()
		{
			CookieContainer cc = new CookieContainer ();
			Cookie cookie = new Cookie ("name1", "value1");
			cookie.Domain = "localhost";
			cookie.Comment = "Short name";
			cookie.Expires = DateTime.Now.Add (new TimeSpan (3, 2, 5));
			cookie.Version = 1;
			cc.Add (cookie);
			Assert.AreEqual ("$Version=1; name1=value1; $Domain=localhost", cookie.ToString (), "#E0");
			Assert.AreEqual ("$Version=1; name1=value1; $Path=/",
				cc.GetCookieHeader (new Uri ("http://localhost/path/sub")), "#E1");
		}
        /// <summary>
        /// Authenticate to the dataImportAPI and get the <see cref="_jsessionID"/>
        /// </summary>
        private void Authenticate()
        {
            if (clusterHost == null) {
                ClusterLookup ();
            }

            string password = HttpUtility.UrlEncode(this.password);
            string url = String.Format ("{0}{1}/SpatialKeyFramework/dataImportAPI?action=login&orgName={2}&user={3}&password={4}",
                                       _protocol, clusterHost, organizationName, HttpUtility.UrlEncode (userName), password);
            Log(String.Format("Authenticate: {0}", url.Replace(password, "XXX")));

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create (url);
            request.Method = "GET";
            CookieContainer cookieJar = new CookieContainer ();
            request.CookieContainer = cookieJar;

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse ())
            using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
            {
                if (response.StatusCode != HttpStatusCode.OK) {
                    throw new SystemException ("Authentication Failed");
                }

                _jsessionID = cookieJar.GetCookies (request.RequestUri) ["JSESSIONID"];
                Log(streamReader.ReadToEnd());
            }

            Log(_jsessionID.ToString());
        }
Ejemplo n.º 18
0
        // This method is called *only* when cookie verification is done, so unlike with public
        // Add(Cookie cookie) the cookie is in a reasonable condition.
        internal void Add(Cookie cookie, bool throwOnError)
        {
            PathList pathList;

            if (cookie.Value.Length > _maxCookieSize)
            {
                if (throwOnError)
                {
                    throw new CookieException(SR.Format(SR.net_cookie_size, cookie.ToString(), _maxCookieSize));
                }
                return;
            }

            try
            {
                lock (_domainTable)
                {
                    _domainTable.TryGetValue(cookie.DomainKey, out pathList);
                    if (pathList == null)
                    {
                        pathList = new PathList();
                        AddRemoveDomain(cookie.DomainKey, pathList);
                    }
                }
                int domain_count = pathList.GetCookiesCount();

                CookieCollection cookies;
                lock (pathList.SyncRoot)
                {
                    cookies = (CookieCollection)pathList[cookie.Path];

                    if (cookies == null)
                    {
                        cookies = new CookieCollection();
                        pathList[cookie.Path] = cookies;
                    }
                }

                if (cookie.Expired)
                {
                    // Explicit removal command (Max-Age == 0)
                    lock (cookies)
                    {
                        int idx = cookies.IndexOf(cookie);
                        if (idx != -1)
                        {
                            cookies.RemoveAt(idx);
                            --_count;
                        }
                    }
                }
                else
                {
                    // This is about real cookie adding, check Capacity first
                    if (domain_count >= _maxCookiesPerDomain && !AgeCookies(cookie.DomainKey))
                    {
                        return; // Cannot age: reject new cookie
                    }
                    else if (_count >= _maxCookies && !AgeCookies(null))
                    {
                        return; // Cannot age: reject new cookie
                    }

                    // About to change the collection
                    lock (cookies)
                    {
                        _count += cookies.InternalAdd(cookie, true);
                    }
                }
            }
            catch (OutOfMemoryException)
            {
                throw;
            }
            catch (Exception e)
            {
                if (throwOnError)
                {
                    throw new CookieException(SR.net_container_add_cookie, e);
                }
            }
        }
Ejemplo n.º 19
0
 internal void Add(Cookie cookie, bool throwOnError)
 {
     if (cookie.Value.Length > this.m_maxCookieSize)
       {
     if (!throwOnError)
       return;
     throw new CookieException(SR.GetString("net_cookie_size", (object) cookie.ToString(), (object) this.m_maxCookieSize));
       }
       else
       {
     try
     {
       PathList pathList = (PathList) this.m_domainTable[(object) cookie.DomainKey];
       if (pathList == null)
       {
     pathList = new PathList();
     this.AddRemoveDomain(cookie.DomainKey, pathList);
       }
       int cookiesCount = pathList.GetCookiesCount();
       CookieCollection cookieCollection = (CookieCollection) pathList[cookie.Path];
       if (cookieCollection == null)
       {
     cookieCollection = new CookieCollection();
     pathList[cookie.Path] = (object) cookieCollection;
       }
       if (cookie.Expired)
       {
     lock (cookieCollection)
     {
       int local_3 = cookieCollection.IndexOf(cookie);
       if (local_3 == -1)
         return;
       cookieCollection.RemoveAt(local_3);
       --this.m_count;
     }
       }
       else
       {
     if (cookiesCount >= this.m_maxCookiesPerDomain && !this.AgeCookies(cookie.DomainKey) || this.m_count >= this.m_maxCookies && !this.AgeCookies((string) null))
       return;
     lock (cookieCollection)
       this.m_count += cookieCollection.InternalAdd(cookie, true);
       }
     }
     catch (Exception ex)
     {
       if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException)
     throw;
       else if (throwOnError)
     throw new CookieException(SR.GetString("net_container_add_cookie"), ex);
     }
       }
 }
 internal void Add(Cookie cookie, bool throwOnError)
 {
     if (cookie.Value.Length > this.m_maxCookieSize)
     {
         if (throwOnError)
         {
             throw new CookieException(SR.GetString("net_cookie_size", new object[] { cookie.ToString(), this.m_maxCookieSize }));
         }
     }
     else
     {
         try
         {
             PathList list = (PathList) this.m_domainTable[cookie.DomainKey];
             if (list == null)
             {
                 list = new PathList();
                 this.AddRemoveDomain(cookie.DomainKey, list);
             }
             int cookiesCount = list.GetCookiesCount();
             CookieCollection cookies = (CookieCollection) list[cookie.Path];
             if (cookies == null)
             {
                 cookies = new CookieCollection();
                 list[cookie.Path] = cookies;
             }
             if (cookie.Expired)
             {
                 lock (cookies)
                 {
                     int index = cookies.IndexOf(cookie);
                     if (index != -1)
                     {
                         cookies.RemoveAt(index);
                         this.m_count--;
                     }
                     return;
                 }
             }
             if (((cookiesCount < this.m_maxCookiesPerDomain) || this.AgeCookies(cookie.DomainKey)) && ((this.m_count < this.m_maxCookies) || this.AgeCookies(null)))
             {
                 lock (cookies)
                 {
                     this.m_count += cookies.InternalAdd(cookie, true);
                 }
             }
         }
         catch (Exception exception)
         {
             if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
             {
                 throw;
             }
             if (throwOnError)
             {
                 throw new CookieException(SR.GetString("net_container_add_cookie"), exception);
             }
         }
     }
 }
Ejemplo n.º 21
0
        // This method is called *only* when cookie verification is done, so unlike with public
        // Add(Cookie cookie) the cookie is in a reasonable condition.
        internal void Add(Cookie cookie, bool throwOnError)
        {
            PathList pathList;

            if (cookie.Value.Length > m_maxCookieSize)
            {
                if (throwOnError)
                {
                    throw new CookieException(SR.Format(SR.net_cookie_size, cookie.ToString(), m_maxCookieSize));
                }
                return;
            }

            try
            {
                lock (m_domainTable)
                {
                    if (!m_domainTable.TryGetValue(cookie.DomainKey, out pathList))
                    {
                        m_domainTable[cookie.DomainKey] = (pathList = PathList.Create());
                    }
                }
                int domain_count = pathList.GetCookiesCount();

                CookieCollection cookies;
                lock (pathList.SyncRoot)
                {
                    cookies = pathList[cookie.Path];

                    if (cookies == null)
                    {
                        cookies = new CookieCollection();
                        pathList[cookie.Path] = cookies;
                    }
                }

                if (cookie.Expired)
                {
                    // Explicit removal command (Max-Age == 0)
                    lock (cookies)
                    {
                        int idx = cookies.IndexOf(cookie);
                        if (idx != -1)
                        {
                            cookies.RemoveAt(idx);
                            --m_count;
                        }
                    }
                }
                else
                {
                    // This is about real cookie adding, check Capacity first
                    if (domain_count >= m_maxCookiesPerDomain && !AgeCookies(cookie.DomainKey))
                    {
                        return; // Cannot age: reject new cookie
                    }
                    else if (m_count >= m_maxCookies && !AgeCookies(null))
                    {
                        return; // Cannot age: reject new cookie
                    }

                    // About to change the collection
                    lock (cookies)
                    {
                        m_count += cookies.InternalAdd(cookie, true);
                    }
                }
            }
            catch (OutOfMemoryException)
            {
                throw;
            }
            catch (Exception e)
            {
                if (throwOnError)
                {
                    throw new CookieException(SR.net_container_add_cookie, e);
                }
            }
        }
Ejemplo n.º 22
0
 internal void ComputeCookies()
 {
     GlobalLog.Print("HttpListenerResponse#" + ValidationHelper.HashString(this) + "::ComputeCookies() entering Set-Cookie: " + ValidationHelper.ToString(Headers[HttpResponseHeader.SetCookie]) + " Set-Cookie2: " + ValidationHelper.ToString(Headers[HttpKnownHeaderNames.SetCookie2]));
     if (m_Cookies != null)
     {
         // now go through the collection, and concatenate all the cookies in per-variant strings
         string setCookie2 = null;
         string setCookie  = null;
         for (int index = 0; index < m_Cookies.Count; index++)
         {
             Cookie cookie       = m_Cookies[index];
             string cookieString = cookie.ToServerString();
             if (cookieString == null || cookieString.Length == 0)
             {
                 continue;
             }
             GlobalLog.Print("HttpListenerResponse#" + ValidationHelper.HashString(this) + "::ComputeCookies() now looking at index:" + index + " cookie.Variant:" + cookie.Variant + " cookie:" + cookie.ToString());
             if (cookie.Variant == CookieVariant.Rfc2965 || (HttpListenerContext.PromoteCookiesToRfc2965 && cookie.Variant == CookieVariant.Rfc2109))
             {
                 setCookie2 = setCookie2 == null ? cookieString : setCookie2 + ", " + cookieString;
             }
             else
             {
                 setCookie = setCookie == null ? cookieString : setCookie + ", " + cookieString;
             }
         }
         if (!string.IsNullOrEmpty(setCookie))
         {
             Headers.Set(HttpResponseHeader.SetCookie, setCookie);
             if (string.IsNullOrEmpty(setCookie2))
             {
                 Headers.Remove(HttpKnownHeaderNames.SetCookie2);
             }
         }
         if (!string.IsNullOrEmpty(setCookie2))
         {
             Headers.Set(HttpKnownHeaderNames.SetCookie2, setCookie2);
             if (string.IsNullOrEmpty(setCookie))
             {
                 Headers.Remove(HttpKnownHeaderNames.SetCookie);
             }
         }
     }
     GlobalLog.Print("HttpListenerResponse#" + ValidationHelper.HashString(this) + "::ComputeCookies() exiting Set-Cookie: " + ValidationHelper.ToString(Headers[HttpResponseHeader.SetCookie]) + " Set-Cookie2: " + ValidationHelper.ToString(Headers[HttpKnownHeaderNames.SetCookie2]));
 }
Ejemplo n.º 23
0
        private void ExeFlag()
        {
            //var t = new System.Threading.Thread(() =>
            //{

            //});
            //t.SetApartmentState(System.Threading.ApartmentState.STA);
            //t.Start();

            if (_flagQue.Count == 0) return;
            Datasource.FlagUnit flag = _flagQue.Dequeue();
            while (!flag.Exe)
                flag = _flagQue.Dequeue();
            WebBrowser _flagBrowser = new WebBrowser();
            _flagBrowser.DocumentCompleted += _flagBrowser_DocumentCompleted;
            Cookie coki = new Cookie("Cookie" + flag.PID, flag.Proxy + flag.AgentId + flag.PID, Application.StartupPath + "/Cookie", "/");
            Core.Core.InternetSetCookie(flag.Url, null, coki.ToString() + "; expires = Sun, 01-Jan-2017 00:00:00 GMT");

            ChangeUserAgent(flag.Agent);
            Core.Core.RefreshIESettings(flag.Proxy);
            _flagBrowser.Tag = flag;
            _tmr_flag.Tag = _flagBrowser;
            System.Threading.Thread.Sleep(1000 * 3);
            _tmr_flag.Start();
            _flagBrowser.Navigate(flag.Url);
        }
Ejemplo n.º 24
0
        private void ExeFlag()
        {
            //var t = new System.Threading.Thread(() => {   });
            //t.SetApartmentState(System.Threading.ApartmentState.STA);
            //t.Start();
            if (_maxIpUsage == _changeIPoffset)
            {
                Core.HMA.ChangeIP();
                System.Threading.Thread.Sleep(2000);
                while (Core.HMA.Status() == Core.HMA.HMA_State.Not_Connected)
                {
                    System.Threading.Thread.Sleep(1000);
                    Application.DoEvents();
                }
                _changeIPoffset = 0;
            }

            if (_flagoffset == _flagQue.Count)
            {
                _flagoffset = 0;
                _flagLoop++;
            }
            if (_flagLoop == _maxFlagLoop)
            {
                btnSearch.Enabled = btnStartFlag.Enabled = btnAddPID.Enabled = true; Application.DoEvents();
                MessageBox.Show("Flagging Completed ...", "Done ...", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            Datasource.FlagUnit flag = _flagQue[_flagoffset];
            _flagoffset++;
            while (!flag.Exe)
            {
                _flagoffset++;
                flag = _flagQue[_flagoffset];
            }
            WebBrowser _flagBrowser = new WebBrowser();
            _flagBrowser.DocumentCompleted += _flagBrowser_DocumentCompleted;
            Cookie coki = new Cookie("Cookie" + flag.PID, flag.Proxy + flag.AgentId + flag.PID, Application.StartupPath + "/Cookie", "/");
            Core.Core.InternetSetCookie(flag.Url, null, coki.ToString() + "; expires = Sun, 01-Jan-2017 00:00:00 GMT");

            ChangeUserAgent(flag.Agent);
            _flagBrowser.Tag = flag;
            _tmr_flag.Tag = _flagBrowser;
            //System.Threading.Thread.Sleep(1000 * 3);
            _tmr_flag.Start();
            _flagBrowser.Navigate(flag.Url);
            //_changeIPoffset++;
        }