Example #1
0
        public ICookieGetter CreateDefaultCookieGetter()
        {
            string path = CookieUtil.ReplacePathSymbols(COOKIEPATH);

            if (!File.Exists(path))
            {
                path = null;
            }

            CookieStatus status = new CookieStatus(
                BrowserType.ToString(), path, BrowserType, PathType.File);

            return(new GoogleChromeCookieGetter(status));
        }
        public override CookieContainer GetAllCookies()
        {
            if (base.CookiePath == null || !File.Exists(base.CookiePath))
            {
                throw new CookieGetterException(
                          "Operaのクッキーパスが正しく設定されていません。");
            }

            CookieContainer container = new CookieContainer();

            try
            {
                using (FileStream reader = new FileStream(
                           base.CookiePath, FileMode.Open, FileAccess.Read))
                {
                    Header headerData = getHeader(reader);

                    //version check
                    if ((headerData.file_version_number & 0xfffff000) == 0x00001000)
                    {
                        foreach (Cookie cookie in getCookies(headerData, reader))
                        {
                            try
                            {
                                CookieUtil.AddCookieToContainer(container, cookie);
                            }
                            catch (Exception ex)
                            {
                                CookieGetter.Exceptions.Enqueue(ex);

                                Console.WriteLine(string.Format(
                                                      "Invalid Format! domain:{0},key:{1},value:{2}",
                                                      cookie.Domain, cookie.Name, cookie.Value));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new CookieGetterException(
                          "Operaのクッキー取得でエラーが発生しました。", ex);
            }

            return(container);
        }
Example #3
0
        public ICookieGetter[] CreateCookieGetters()
        {
            FirefoxProfile[] profs = FirefoxProfile.GetProfiles(
                CookieUtil.ReplacePathSymbols(DATAFOLDER),
                INIFILE_NAME);

            if (profs.Length == 0)
            {
                return(new ICookieGetter[] { CreateCookieGetter(null) });
            }

            ICookieGetter[] cgs = new ICookieGetter[profs.Length];
            for (int i = 0; i < profs.Length; i++)
            {
                cgs[i] = CreateCookieGetter(profs[i]);
            }

            return(cgs);
        }
        private Cookie getCookieRecord(Stream stream, Header headerData)
        {
            Record recordData;
            Cookie cookie = new Cookie();

            while (stream.Position < stream.Length)
            {
                recordData = getRecord(stream, headerData);

                switch (recordData.tag_id)
                {
                case 0x10:      // Cookie Name
                    cookie.Name = Encoding.ASCII.GetString(recordData.bytepayload);
                    break;

                case 0x11:      // Cookie Value
                    cookie.Value = Encoding.ASCII.GetString(recordData.bytepayload);
                    if (cookie.Value != null)
                    {
                        cookie.Value = Uri.EscapeDataString(cookie.Value);
                    }
                    break;

                case 0x12:
                    long time;
                    using (MemoryStream ms = new MemoryStream(recordData.bytepayload))
                    {
                        time = getNumber(ms, 8);
                    }
                    cookie.Expires = CookieUtil.UnixTimeToDateTime((int)time);
                    break;
                }
            }

            return(cookie);
        }
        /// <summary>
        /// クエリで指定されたクッキーをすべて取得します。
        /// </summary>
        private CookieContainer GetCookies(string query)
        {
            CookieContainer container = new CookieContainer();

            List <List <object> > itemsList = SQLite.GetCookies(CookiePath, query);

            foreach (List <object> items in itemsList)
            {
                Cookie cookie = null;

                try
                {
                    cookie = MakeCookie(items);

                    CookieUtil.AddCookieToContainer(container, cookie);
                }
                catch (Exception ex)
                {
                    Util.ThrowIfFatal(ex);

                    if (cookie == null)
                    {
                        Log.ErrorException(ex,
                                           "Invalid Format cookie!");
                    }
                    else
                    {
                        Log.ErrorException(ex,
                                           "Invalid Format cookie! domain:{0},key:{1},value:{2}",
                                           cookie.Domain, cookie.Name, cookie.Value);
                    }
                }
            }

            return(container);
        }
        public override CookieContainer GetAllCookies()
        {
            if (base.CookiePath == null || !File.Exists(base.CookiePath))
            {
                throw new CookieGetterException(
                          "Safariのクッキーパスが正しく設定されていません。");
            }

            CookieContainer container = new CookieContainer();

            // Safari5.1対応 07/30
            if (CheckSafariCookieBinary())
            {
                // 相変わらず仕様がわからないので暫定的にへぼい正規表現でさくっと
                return(GetContainer());  // 08/08
            }

            // Safari5.0.5以下
            try
            {
                XmlReaderSettings settings = new XmlReaderSettings();

                // DTDを取得するためにウェブアクセスするのを抑制する
                // (通信遅延や、アクセスエラーを排除するため)
                settings.XmlResolver = null;
#if CLR_GE_4_0
                settings.DtdProcessing = DtdProcessing.Ignore;
#else
                settings.ProhibitDtd = false;
#endif
                settings.CheckCharacters = false;

                using (XmlReader xtr = XmlTextReader.Create(base.CookiePath, settings))
                {
                    while (xtr.Read())
                    {
                        switch (xtr.NodeType)
                        {
                        case XmlNodeType.Element:
                            if (xtr.Name.ToLower().Equals("dict"))
                            {
                                Cookie cookie = getCookie(xtr);
                                try
                                {
                                    CookieUtil.AddCookieToContainer(container, cookie);
                                }
                                catch (Exception ex)
                                {
                                    CookieGetter.Exceptions.Enqueue(ex);
                                    Console.WriteLine(string.Format(
                                                          "Invalid Format! domain:{0},key:{1},value:{2}",
                                                          cookie.Domain, cookie.Name, cookie.Value));
                                }
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new CookieGetterException(
                          "Safariのクッキー取得中にエラーが発生しました。", ex);
            }

            return(container);
        }
        public override CookieCollection GetCookieCollection(Uri url)
        {
            CookieContainer container = GetCookies(MakeQuery(url));

            return(container.GetCookies(CookieUtil.AddSrashLast(url)));
        }
 private string MakeQuery(Uri url)
 {
     return(string.Format(
                "{0} {1} ORDER BY expiry",
                SELECT_QUERY, CookieUtil.MakeWhere(url, "host")));
 }
 private string MakeQuery(Uri url, string key)
 {
     return(string.Format(
                "{0} {1} AND name = \"{2}\" ORDER BY expiry",
                SELECT_QUERY, CookieUtil.MakeWhere(url, "host"), key));
 }
Example #10
0
 private string MakeQuery(Uri url)
 {
     return(string.Format(
                "{0} {1} ORDER BY creation_utc DESC",
                SELECT_QUERY, CookieUtil.MakeWhere(url, "host_key")));
 }
Example #11
0
 private string MakeQuery(Uri url, string key)
 {
     return(string.Format(
                "{0} {1} AND name = \"{2}\" ORDER BY creation_utc DESC",
                SELECT_QUERY, CookieUtil.MakeWhere(url, "host_key"), key));
 }