Пример #1
0
        private void AddSessionId(StringBuilder sb)
        {
            X2chAuthenticator authenticator = X2chAuthenticator.GetInstance();

            if (authenticator.HasSession)
            {
                sb.AppendFormat("&sid={0}", UrlEncode(authenticator.SessionId));
            }
        }
Пример #2
0
        public static bool IsValidUsernamePassword(string username, string password)
        {
            if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
            {
                return(false);
            }

            X2chAuthenticator test = new X2chAuthenticator();

            test.Connect(username, password);
            return(test.IsValidSessionId(test.SessionId));
        }
Пример #3
0
        private string AddSessionId(string url)
        {
            StringBuilder urlOutput = new StringBuilder();

            urlOutput.Append(url);

            X2chAuthenticator authenticator = X2chAuthenticator.GetInstance();

            if (authenticator.HasSession)
            {
                urlOutput.AppendFormat("?raw=0.0&sid={0}", HttpUtility.UrlEncode(authenticator.SessionId, Encoding.GetEncoding("shift_jis")));
            }
            return(urlOutput.ToString());
        }
        /// <summary>
        /// スレッドを開く
        /// </summary>
        /// <param name="th"></param>
        public override bool Open(ThreadHeader header)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }
            if (IsOpen)
            {
                throw new InvalidOperationException("既にストリームが開かれています");
            }

            headerInfo = header;
            //firstRead = true;
            RokkaResponseState = X2chRokkaResponseState.None;

            if (header.Pastlog)
            {
                return(false);
            }

            X2chAuthenticator authenticator = X2chAuthenticator.GetInstance();

            if (authenticator.HasSession)
            {
                X2chThreadHeader x2chHeader = header as X2chThreadHeader;
                if (x2chHeader != null)
                {
                    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(x2chHeader.AuthenticateUrl);
                    req.Timeout           = 15000;
                    req.UserAgent         = UserAgent;
                    req.AllowAutoRedirect = false;

                    // ** 9/26 削除 **
                    // req.Headers.Add("Accept-Encoding", "gzip");

                    // ** 9/26 追加 **
                    req.AutomaticDecompression = DecompressionMethods.GZip;

                    req.Headers.Add("Pragma", "no-cache");
                    req.Headers.Add("Cache-Control", "no-cache");

                    if (x2chHeader.ETag != String.Empty)
                    {
                        req.Headers.Add("If-None-Match", x2chHeader.ETag);
                    }

                    _res = (HttpWebResponse)req.GetResponse();

                    //baseStream = _res.GetResponseStream();
                    baseStream          = FileUtility.CreateMemoryStream(_res.GetResponseStream());
                    baseStream.Position = 0;
                    length = (int)baseStream.Length;

                    RokkaResponseState = ParseRokkaFirstline(baseStream);

                    if (_res.StatusCode == HttpStatusCode.OK)
                    {
                        /* 9 26削除
                         * using (GZipStream gzipInp = new GZipStream(_res.GetResponseStream(), CompressionMode.Decompress))
                         * baseStream = FileUtility.CreateMemoryStream(gzipInp);
                         */

                        x2chHeader.ETag         = _res.Headers["ETag"];
                        x2chHeader.LastModified = _res.LastModified;

                        index    = header.GotResCount + 1;
                        position = 0;
                        isOpen   = true;
                    }
                    else
                    {
                        OnPastlog(new PastlogEventArgs(header));
                    }
                }
            }
            else
            {
                OnPastlog(new PastlogEventArgs(header));
            }

            // 過去ログなのでdat落ちに設定
            headerInfo.Pastlog = true;

            return(isOpen);
        }