コード例 #1
0
ファイル: XmlTextReaderImpl.cs プロジェクト: chcosta/corefx
        private void PushParsingState()
        {
            if (_parsingStatesStack == null)
            {
                _parsingStatesStack = new ParsingState[InitialParsingStatesDepth];
                Debug.Assert(_parsingStatesStackTop == -1);
            }
            else if (_parsingStatesStackTop + 1 == _parsingStatesStack.Length)
            {
                ParsingState[] newParsingStateStack = new ParsingState[_parsingStatesStack.Length * 2];
                Array.Copy(_parsingStatesStack, 0, newParsingStateStack, 0, _parsingStatesStack.Length);
                _parsingStatesStack = newParsingStateStack;
            }
            _parsingStatesStackTop++;
            _parsingStatesStack[_parsingStatesStackTop] = _ps;

            _ps.Clear();
        }
コード例 #2
0
ファイル: XmlTextReaderImpl.cs プロジェクト: chcosta/corefx
 private void PopParsingState()
 {
     Debug.Assert(_parsingStatesStackTop >= 0);
     _ps.Close(true);
     _ps = _parsingStatesStack[_parsingStatesStackTop--];
 }
コード例 #3
0
        public ParseResult ParseRequest(ref ReadableBuffer buffer)
        {
            if (_state == ParsingState.StartLine)
            {
                // Find \n
                ReadCursor delim;
                ReadableBuffer startLine;
                if (!buffer.TrySliceTo((byte)'\r', (byte)'\n', out startLine, out delim))
                {
                    return ParseResult.Incomplete;
                }

                // Move the buffer to the rest
                buffer = buffer.Slice(delim).Slice(2);

                ReadableBuffer method;
                if (!startLine.TrySliceTo((byte)' ', out method, out delim))
                {
                    return ParseResult.BadRequest;
                }

                _method = method.Preserve();

                // Skip ' '
                startLine = startLine.Slice(delim).Slice(1);

                ReadableBuffer path;
                if (!startLine.TrySliceTo((byte)' ', out path, out delim))
                {
                    return ParseResult.BadRequest;
                }

                _path = path.Preserve();

                // Skip ' '
                startLine = startLine.Slice(delim).Slice(1);

                var httpVersion = startLine;
                if (httpVersion.IsEmpty)
                {
                    return ParseResult.BadRequest;
                }

                _httpVersion = httpVersion.Preserve();

                _state = ParsingState.Headers;
            }

            // Parse headers
            // key: value\r\n

            while (!buffer.IsEmpty)
            {
                var headerName = default(ReadableBuffer);
                var headerValue = default(ReadableBuffer);

                // End of the header
                // \n
                ReadCursor delim;
                ReadableBuffer headerPair;
                if (!buffer.TrySliceTo((byte)'\r', (byte)'\n', out headerPair, out delim))
                {
                    return ParseResult.Incomplete;
                }

                buffer = buffer.Slice(delim).Slice(2);

                // End of headers
                if (headerPair.IsEmpty)
                {
                    return ParseResult.Complete;
                }

                // :
                if (!headerPair.TrySliceTo((byte)':', out headerName, out delim))
                {
                    return ParseResult.BadRequest;
                }

                headerName = headerName.TrimStart();
                headerPair = headerPair.Slice(delim).Slice(1);

                headerValue = headerPair.TrimStart();
                RequestHeaders.SetHeader(ref headerName, ref headerValue);
            }

            return ParseResult.Incomplete;
        }
コード例 #4
0
ファイル: XmlTextReaderImpl.cs プロジェクト: JianwenSun/cc
 private void PushParsingState() {
     if ( parsingStatesStack == null ) {
         parsingStatesStack = new ParsingState[ InitialParsingStatesDepth ];
         Debug.Assert( parsingStatesStackTop == -1 );
     }
     else if ( parsingStatesStackTop + 1 == parsingStatesStack.Length ) {
         ParsingState[] newParsingStateStack = new ParsingState[ parsingStatesStack.Length * 2 ];
         Array.Copy( parsingStatesStack, 0, newParsingStateStack, 0, parsingStatesStack.Length );
         parsingStatesStack = newParsingStateStack;
     }
     parsingStatesStackTop++;
     parsingStatesStack[ parsingStatesStackTop ] = ps;
     
     ps.Clear();
 }
コード例 #5
0
 private void InitParsingStateParse()
 {
     if (SqlExceptionToParse.ErrorCode == 547)
     {
         parsingState = ParsingState.CheckParsingSuperstate;
     }
     else
         parsingState = ParsingState.UnParsedParsingState;
 }
コード例 #6
0
        public void Reset()
        {
            _state = ParsingState.StartLine;

            _method.Dispose();
            _path.Dispose();
            _httpVersion.Dispose();

            RequestHeaders.Reset();
        }
コード例 #7
0
        /// <summary>
        /// ���������� ������ ���������� ��� ��������� ������ � ����������� �����������
        /// </summary>
        /// <returns>������, ���� ������ ��������� �������</returns>
        public bool Parse()
        {
            isParsed = false;
            parsingState = ParsingState.InitParsingState;

            if (SqlExceptionToParse == null)
                throw new ArgumentException("SqlExceptionToParse �� �����.");

            while ((parsingState != ParsingState.ParsedParsingState) || (parsingState != ParsingState.UnParsedParsingState))
            {
                switch (parsingState)
                {
                    case ParsingState.InitParsingState:
                        InitParsingStateParse();
                        break;
                    case ParsingState.CheckParsingSuperstate:
                        CheckParsingSupersateParse();
                        break;

                }
            }
            return isParsed;
        }
コード例 #8
0
        private void CheckParsingSupersateParse()
        {
            string[] actions = new string[3]{ "INSERT", "DELETE", "UPDATE" };
            string actionTemplate = "The {0} statement conflicted with the";
            string action;
            parsingState = ParsingState.UnParsedParsingState;

            for (int i = 0; i < actions.Length; i++)
            {
                action = string.Format(actionTemplate, actions[i]);
                if (messageToParse.IndexOf(action, 0) != -1)
                {
                    parsingState = ParsingState.ActionParsedState;
                    commandType = (SqlCommandType)i;
                    break;
                }
            }
        }
コード例 #9
0
 void AppendKeyValue(object keyValue)
 {
     _currentElement.AppendAttribute(_keyName, keyValue);
     _state = ParsingState.ExpectKeyName;
 }
コード例 #10
0
            public override int Read(Span <byte> buffer)
            {
                if (_connection == null || buffer.Length == 0)
                {
                    // Response body fully consumed or the caller didn't ask for any data.
                    return(0);
                }

                // Try to consume from data we already have in the buffer.
                int bytesRead = ReadChunksFromConnectionBuffer(buffer, cancellationRegistration: default);

                if (bytesRead > 0)
                {
                    return(bytesRead);
                }

                // Nothing available to consume.  Fall back to I/O.
                while (true)
                {
                    if (_connection == null)
                    {
                        // Fully consumed the response in ReadChunksFromConnectionBuffer.
                        if (HttpTelemetry.IsEnabled)
                        {
                            LogRequestStop();
                        }
                        return(0);
                    }

                    if (_state == ParsingState.ExpectChunkData &&
                        buffer.Length >= _connection.ReadBufferSize &&
                        _chunkBytesRemaining >= (ulong)_connection.ReadBufferSize)
                    {
                        // As an optimization, we skip going through the connection's read buffer if both
                        // the remaining chunk data and the buffer are both at least as large
                        // as the connection buffer.  That avoids an unnecessary copy while still reading
                        // the maximum amount we'd otherwise read at a time.
                        Debug.Assert(_connection.RemainingBuffer.Length == 0);
                        bytesRead = _connection.Read(buffer.Slice(0, (int)Math.Min((ulong)buffer.Length, _chunkBytesRemaining)));
                        if (bytesRead == 0)
                        {
                            throw new IOException(SR.Format(SR.net_http_invalid_response_premature_eof_bytecount, _chunkBytesRemaining));
                        }
                        _chunkBytesRemaining -= (ulong)bytesRead;
                        if (_chunkBytesRemaining == 0)
                        {
                            _state = ParsingState.ExpectChunkTerminator;
                        }
                        return(bytesRead);
                    }

                    // We're only here if we need more data to make forward progress.
                    _connection.Fill();

                    // Now that we have more, see if we can get any response data, and if
                    // we can we're done.
                    int bytesCopied = ReadChunksFromConnectionBuffer(buffer, cancellationRegistration: default);
                    if (bytesCopied > 0)
                    {
                        return(bytesCopied);
                    }
                }
            }
コード例 #11
0
            private async ValueTask <int> ReadAsyncCore(Memory <byte> buffer, CancellationToken cancellationToken)
            {
                // Should only be called if ReadChunksFromConnectionBuffer returned 0.

                Debug.Assert(_connection != null);
                Debug.Assert(buffer.Length > 0);

                CancellationTokenRegistration ctr = _connection.RegisterCancellation(cancellationToken);

                try
                {
                    while (true)
                    {
                        if (_connection == null)
                        {
                            // Fully consumed the response in ReadChunksFromConnectionBuffer.
                            return(0);
                        }

                        if (_state == ParsingState.ExpectChunkData &&
                            buffer.Length >= _connection.ReadBufferSize &&
                            _chunkBytesRemaining >= (ulong)_connection.ReadBufferSize)
                        {
                            // As an optimization, we skip going through the connection's read buffer if both
                            // the remaining chunk data and the buffer are both at least as large
                            // as the connection buffer.  That avoids an unnecessary copy while still reading
                            // the maximum amount we'd otherwise read at a time.
                            Debug.Assert(_connection.RemainingBuffer.Length == 0);
                            int bytesRead = await _connection.ReadAsync(buffer.Slice(0, (int)Math.Min((ulong)buffer.Length, _chunkBytesRemaining))).ConfigureAwait(false);

                            if (bytesRead == 0)
                            {
                                throw new IOException(SR.Format(SR.net_http_invalid_response_premature_eof_bytecount, _chunkBytesRemaining));
                            }
                            _chunkBytesRemaining -= (ulong)bytesRead;
                            if (_chunkBytesRemaining == 0)
                            {
                                _state = ParsingState.ExpectChunkTerminator;
                            }
                            return(bytesRead);
                        }

                        // We're only here if we need more data to make forward progress.
                        await _connection.FillAsync(async : true).ConfigureAwait(false);

                        // Now that we have more, see if we can get any response data, and if
                        // we can we're done.
                        int bytesCopied = ReadChunksFromConnectionBuffer(buffer.Span, ctr);
                        if (bytesCopied > 0)
                        {
                            return(bytesCopied);
                        }
                    }
                }
                catch (Exception exc) when(CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken))
                {
                    throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken);
                }
                finally
                {
                    ctr.Dispose();
                }
            }
コード例 #12
0
 public static bool IsSuccessful(this ParsingState state)
 => state == ParsingState.Success;
コード例 #13
0
 public static bool NotSuccessful(this ParsingState state)
 => state != ParsingState.Success;