OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_SPDY_SPDY_HEADERS_BLOCK_PARSER_H_ | 5 #ifndef NET_SPDY_SPDY_HEADERS_BLOCK_PARSER_H_ |
6 #define NET_SPDY_SPDY_HEADERS_BLOCK_PARSER_H_ | 6 #define NET_SPDY_SPDY_HEADERS_BLOCK_PARSER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 HEADER_BLOCK_TOO_LARGE, | 57 HEADER_BLOCK_TOO_LARGE, |
58 // Set when a header key or value exceeds |kMaximumFieldLength|. | 58 // Set when a header key or value exceeds |kMaximumFieldLength|. |
59 HEADER_FIELD_TOO_LARGE, | 59 HEADER_FIELD_TOO_LARGE, |
60 // Set when the parser is given an unexpected stream ID. | 60 // Set when the parser is given an unexpected stream ID. |
61 UNEXPECTED_STREAM_ID, | 61 UNEXPECTED_STREAM_ID, |
62 }; | 62 }; |
63 ParserError get_error() const { return error_; } | 63 ParserError get_error() const { return error_; } |
64 | 64 |
65 SpdyMajorVersion spdy_version() const { return spdy_version_; } | 65 SpdyMajorVersion spdy_version() const { return spdy_version_; } |
66 | 66 |
67 // Returns the size in bytes of a length field in a SPDY header. | |
68 static size_t LengthFieldSizeForVersion(SpdyMajorVersion spdy_version); | |
69 | |
70 // Returns the maximal number of headers in a SPDY headers block. | 67 // Returns the maximal number of headers in a SPDY headers block. |
71 static size_t MaxNumberOfHeadersForVersion(SpdyMajorVersion spdy_version); | 68 static size_t MaxNumberOfHeaders(); |
72 | 69 |
73 private: | 70 private: |
74 typedef SpdyPrefixedBufferReader Reader; | 71 typedef SpdyPrefixedBufferReader Reader; |
75 | 72 |
76 // Parses and sanity-checks header block length. | 73 // Parses and sanity-checks header block length. |
77 void ParseBlockLength(Reader* reader); | 74 void ParseBlockLength(Reader* reader); |
78 | 75 |
79 // Parses and sanity-checks header field length. | 76 // Parses and sanity-checks header field length. |
80 void ParseFieldLength(Reader* reader); | 77 void ParseFieldLength(Reader* reader); |
81 | 78 |
82 // Parses and decodes network-order lengths into |parsed_length|. | 79 // Parses and decodes network-order lengths into |parsed_length|. |
83 void ParseLength(Reader* reader, uint32_t* parsed_length); | 80 void ParseLength(Reader* reader, uint32_t* parsed_length); |
84 | 81 |
85 // The state of the parser. | 82 // The state of the parser. |
86 enum ParserState { | 83 enum ParserState { |
87 READING_HEADER_BLOCK_LEN, | 84 READING_HEADER_BLOCK_LEN, |
88 READING_KEY_LEN, | 85 READING_KEY_LEN, |
89 READING_KEY, | 86 READING_KEY, |
90 READING_VALUE_LEN, | 87 READING_VALUE_LEN, |
91 READING_VALUE, | 88 READING_VALUE, |
92 FINISHED_HEADER | 89 FINISHED_HEADER |
93 }; | 90 }; |
94 ParserState state_; | 91 ParserState state_; |
95 | 92 |
96 // Size in bytes of a length field in the spdy header. | |
97 const size_t length_field_size_; | |
98 | |
99 // The maximal number of headers in a SPDY headers block. | 93 // The maximal number of headers in a SPDY headers block. |
100 const size_t max_headers_in_block_; | 94 const size_t max_headers_in_block_; |
101 | 95 |
102 // A running total of the bytes parsed since the last call to Reset(). | 96 // A running total of the bytes parsed since the last call to Reset(). |
103 size_t total_bytes_received_; | 97 size_t total_bytes_received_; |
104 | 98 |
105 // Number of key-value pairs until we complete handling the current | 99 // Number of key-value pairs until we complete handling the current |
106 // headers block. | 100 // headers block. |
107 uint32_t remaining_key_value_pairs_for_frame_; | 101 uint32_t remaining_key_value_pairs_for_frame_; |
108 | 102 |
(...skipping 15 matching lines...) Expand all Loading... |
124 SpdyStreamId stream_id_; | 118 SpdyStreamId stream_id_; |
125 | 119 |
126 ParserError error_; | 120 ParserError error_; |
127 | 121 |
128 const SpdyMajorVersion spdy_version_; | 122 const SpdyMajorVersion spdy_version_; |
129 }; | 123 }; |
130 | 124 |
131 } // namespace net | 125 } // namespace net |
132 | 126 |
133 #endif // NET_SPDY_SPDY_HEADERS_BLOCK_PARSER_H_ | 127 #endif // NET_SPDY_SPDY_HEADERS_BLOCK_PARSER_H_ |
OLD | NEW |