| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 14 #include "net/base/net_export.h" | 14 #include "net/base/net_export.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 // A handler class for SPDY headers block key/value pairs. | 18 // A handler class for SPDY headers. |
| 19 // TODO(ygi) Modify this stub handler to pass the key-value pair | 19 class SpdyHeadersHandlerInterface { |
| 20 // through the spdy logic. | |
| 21 class KeyValueHandler { | |
| 22 public: | 20 public: |
| 23 virtual ~KeyValueHandler() {} | 21 virtual ~SpdyHeadersHandlerInterface() {} |
| 22 |
| 23 // A callback method which notifies when the parser starts handling a new |
| 24 // SPDY headers block, this method also notifies on the number of headers in |
| 25 // the block. |
| 26 virtual void OnHeaderBlock(uint32_t num_of_headers) = 0; |
| 27 |
| 28 // A callback method which notifies when the parser finishes handling a SPDY |
| 29 // headers block. |
| 30 virtual void OnHeaderBlockEnd() = 0; |
| 31 |
| 32 // A callback method which notifies on a SPDY header key value pair. |
| 24 virtual void OnKeyValuePair(const base::StringPiece& key, | 33 virtual void OnKeyValuePair(const base::StringPiece& key, |
| 25 const base::StringPiece& value) = 0; | 34 const base::StringPiece& value) = 0; |
| 26 }; | 35 }; |
| 27 | 36 |
| 28 // Helper class which simplifies reading contiguously | 37 // Helper class which simplifies reading contiguously |
| 29 // from a disjoint buffer prefix & suffix. | 38 // from a disjoint buffer prefix & suffix. |
| 30 class NET_EXPORT_PRIVATE SpdyHeadersBlockParserReader { | 39 class NET_EXPORT_PRIVATE SpdyHeadersBlockParserReader { |
| 31 public: | 40 public: |
| 32 // StringPieces are treated as raw buffers. | 41 // StringPieces are treated as raw buffers. |
| 33 SpdyHeadersBlockParserReader(base::StringPiece prefix, | 42 SpdyHeadersBlockParserReader(base::StringPiece prefix, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 50 size_t offset_; | 59 size_t offset_; |
| 51 }; | 60 }; |
| 52 | 61 |
| 53 // This class handles SPDY headers block bytes and parses out key-value pairs | 62 // This class handles SPDY headers block bytes and parses out key-value pairs |
| 54 // as they arrive. This class is not thread-safe, and assumes that all headers | 63 // as they arrive. This class is not thread-safe, and assumes that all headers |
| 55 // block bytes are processed in a single thread. | 64 // block bytes are processed in a single thread. |
| 56 class NET_EXPORT_PRIVATE SpdyHeadersBlockParser { | 65 class NET_EXPORT_PRIVATE SpdyHeadersBlockParser { |
| 57 public: | 66 public: |
| 58 // Costructor. The handler's OnKeyValuePair will be called for every key | 67 // Costructor. The handler's OnKeyValuePair will be called for every key |
| 59 // value pair that we parsed from the headers block. | 68 // value pair that we parsed from the headers block. |
| 60 explicit SpdyHeadersBlockParser(KeyValueHandler* handler); | 69 explicit SpdyHeadersBlockParser(SpdyHeadersHandlerInterface* handler); |
| 61 | 70 |
| 62 virtual ~SpdyHeadersBlockParser(); | 71 virtual ~SpdyHeadersBlockParser(); |
| 63 | 72 |
| 64 // Handles headers block data as it arrives. | 73 // Handles headers block data as it arrives. |
| 65 void HandleControlFrameHeadersData(const char* headers_data, size_t len); | 74 void HandleControlFrameHeadersData(const char* headers_data, size_t len); |
| 66 | 75 |
| 67 private: | 76 private: |
| 68 // The state of the parser. | 77 // The state of the parser. |
| 69 enum ParserState { | 78 enum ParserState { |
| 70 READING_HEADER_BLOCK_LEN, | 79 READING_HEADER_BLOCK_LEN, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 95 // a value). | 104 // a value). |
| 96 uint32_t next_field_len_; | 105 uint32_t next_field_len_; |
| 97 | 106 |
| 98 // The length of the key of the current header. | 107 // The length of the key of the current header. |
| 99 uint32_t key_len_; | 108 uint32_t key_len_; |
| 100 | 109 |
| 101 // Holds unprocessed bytes of the headers block. | 110 // Holds unprocessed bytes of the headers block. |
| 102 std::vector<char> headers_block_prefix_; | 111 std::vector<char> headers_block_prefix_; |
| 103 | 112 |
| 104 // Handles key-value pairs as we parse them. | 113 // Handles key-value pairs as we parse them. |
| 105 KeyValueHandler* handler_; | 114 SpdyHeadersHandlerInterface* handler_; |
| 106 | 115 |
| 107 // Points to the current key. | 116 // Points to the current key. |
| 108 scoped_ptr<char[]> current_key; | 117 scoped_ptr<char[]> current_key; |
| 109 | 118 |
| 110 // Points to the current value. | 119 // Points to the current value. |
| 111 scoped_ptr<char[]> current_value; | 120 scoped_ptr<char[]> current_value; |
| 112 }; | 121 }; |
| 113 | 122 |
| 114 } // namespace net | 123 } // namespace net |
| 115 | 124 |
| 116 #endif // NET_SPDY_SPDY_HEADERS_BLOCK_PARSER_H_ | 125 #endif // NET_SPDY_SPDY_HEADERS_BLOCK_PARSER_H_ |
| OLD | NEW |