Пример #1
0
        public HttpParser ReasonPhrase(out Datagram reasonPhrase)
        {
            if (!this.Success)
            {
                reasonPhrase = (Datagram)null;
                return(this);
            }
            int num1 = 0;

            foreach (byte num2 in this.Range)
            {
                if (ByteExtensions.IsControl(num2))
                {
                    if ((int)num2 != 9)
                    {
                        break;
                    }
                }
                ++num1;
            }
            int length = Enumerable.Count <byte>(Enumerable.TakeWhile <byte>(this.Range, (Func <byte, bool>)(value =>
            {
                if (ByteExtensions.IsControl(value))
                {
                    return((int)value == 9);
                }
                return(true);
            })));

            reasonPhrase  = new Datagram(this._buffer, this._offset, length);
            this._offset += length;
            return(this);
        }
Пример #2
0
 public HttpParser SkipLws()
 {
     while (true)
     {
         IEnumerable <byte> range = this.Range;
         byte num = Enumerable.FirstOrDefault <byte>(range);
         if (ByteExtensions.IsSpaceOrHorizontalTab(num))
         {
             ++this._offset;
         }
         else if ((int)num == 13)
         {
             IEnumerable <byte> source = Enumerable.Skip <byte>(range, 1);
             if ((int)Enumerable.FirstOrDefault <byte>(source) == 10 && ByteExtensions.IsSpaceOrHorizontalTab(Enumerable.FirstOrDefault <byte>(Enumerable.Skip <byte>(source, 1))))
             {
                 this._offset += 3;
             }
             else
             {
                 break;
             }
         }
         else
         {
             break;
         }
     }
     return(this);
 }
Пример #3
0
 public static bool IsHexadecimalDigit(this byte value)
 {
     if (((int)value < 65 || (int)value > 70) && ((int)value < 97 || (int)value > 102))
     {
         return(ByteExtensions.IsDigit(value));
     }
     return(true);
 }
Пример #4
0
 public static bool IsToken(this byte value)
 {
     if (ByteExtensions.IsChar(value) && !ByteExtensions.IsControl(value))
     {
         return(!ByteExtensions.IsSeparator(value));
     }
     return(false);
 }
Пример #5
0
        public HttpParser QuotedString(out Datagram quotedString)
        {
            quotedString = (Datagram)null;
            int offset = this._offset;

            if (!this.Bytes((byte)34).Success)
            {
                return(this);
            }
            while (this.IsNext())
            {
                byte num1 = this.Next();
                switch (num1)
                {
                case (byte)34:
                    ++this._offset;
                    quotedString = new Datagram(this._buffer, offset, this._offset - offset);
                    return(this);

                case (byte)92:
                    if (this.IsNextNext() && ByteExtensions.IsChar(this.NextNext()))
                    {
                        this._offset += 2;
                        continue;
                    }
                    break;
                }
                int num2 = this._offset;
                this.SkipLws();
                if (num2 == this._offset)
                {
                    if (ByteExtensions.IsControl(num1))
                    {
                        return(this.Fail());
                    }
                    ++this._offset;
                }
            }
            return(this.Fail());
        }
Пример #6
0
        public HttpParser Token(out Datagram token)
        {
            if (!this.Success)
            {
                token = (Datagram)null;
                return(this);
            }
            int length = Enumerable.Count <byte>(Enumerable.TakeWhile <byte>(this.Range, (Func <byte, bool>)(value => ByteExtensions.IsToken(value))));

            if (length == 0)
            {
                token = (Datagram)null;
                return(this.Fail());
            }
            token         = new Datagram(this._buffer, this._offset, length);
            this._offset += token.Length;
            return(this);
        }
Пример #7
0
        public HttpParser HexadecimalNumber(out uint?number)
        {
            if (!this.Success)
            {
                number = new uint?();
                return(this);
            }
            IEnumerable <byte> source = Enumerable.TakeWhile <byte>(this.Range, (Func <byte, bool>)(value => ByteExtensions.IsHexadecimalDigit(value)));

            if (!Enumerable.Any <byte>(source))
            {
                number = new uint?();
                return(this.Fail());
            }
            int num1 = Enumerable.Count <byte>(source);
            int num2 = Enumerable.Count <byte>(Enumerable.TakeWhile <byte>(source, (Func <byte, bool>)(value => (int)value == 48)));

            if (num1 - num2 > 8)
            {
                number = new uint?();
                return(this.Fail());
            }
            uint num3 = Enumerable.Aggregate <uint, uint>(Enumerable.Select <byte, uint>(source, (Func <byte, uint>)(value => (uint)ByteExtensions.ToHexadecimalValue(value))), 0U, (Func <uint, uint, uint>)((accumulated, value) => 16U * accumulated + value));

            number        = new uint?(num3);
            this._offset += num1;
            return(this);
        }
Пример #8
0
        public HttpParser DecimalNumber(int numDigits, out uint?number)
        {
            if (numDigits > 8 || numDigits < 0)
            {
                throw new ArgumentOutOfRangeException("numDigits", (object)numDigits, "Only between 0 and 8 digits are supported");
            }
            if (!this.Success)
            {
                number = new uint?();
                return(this);
            }
            IEnumerable <byte> source = Enumerable.TakeWhile <byte>(Enumerable.Take <byte>(this.Range, numDigits), (Func <byte, bool>)(value => ByteExtensions.IsDigit(value)));

            if (Enumerable.Count <byte>(source) != numDigits)
            {
                number = new uint?();
                return(this.Fail());
            }
            number        = new uint?(Enumerable.Aggregate <uint, uint>(Enumerable.Select <byte, uint>(source, (Func <byte, uint>)(value => (uint)value - 48U)), 0U, (Func <uint, uint, uint>)((accumulated, value) => 10U * accumulated + value)));
            this._offset += numDigits;
            return(this);
        }