| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_FRAMER_H_ | 5 #ifndef NET_SPDY_SPDY_FRAMER_H_ |
| 6 #define NET_SPDY_SPDY_FRAMER_H_ | 6 #define NET_SPDY_SPDY_FRAMER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 class TestSpdyVisitor; | 46 class TestSpdyVisitor; |
| 47 class SpdyFramerPeer; | 47 class SpdyFramerPeer; |
| 48 | 48 |
| 49 } // namespace test | 49 } // namespace test |
| 50 | 50 |
| 51 // A datastructure for holding the ID and flag fields for SETTINGS. | 51 // A datastructure for holding the ID and flag fields for SETTINGS. |
| 52 // Conveniently handles converstion to/from wire format. | 52 // Conveniently handles converstion to/from wire format. |
| 53 class NET_EXPORT_PRIVATE SettingsFlagsAndId { | 53 class NET_EXPORT_PRIVATE SettingsFlagsAndId { |
| 54 public: | 54 public: |
| 55 static SettingsFlagsAndId FromWireFormat(SpdyMajorVersion version, | 55 static SettingsFlagsAndId FromWireFormat(uint32_t wire); |
| 56 uint32_t wire); | |
| 57 | 56 |
| 58 SettingsFlagsAndId() : flags_(0), id_(0) {} | 57 SettingsFlagsAndId() : flags_(0), id_(0) {} |
| 59 | 58 |
| 60 // TODO(hkhalil): restrict to enums instead of free-form ints. | 59 // TODO(hkhalil): restrict to enums instead of free-form ints. |
| 61 SettingsFlagsAndId(uint8_t flags, uint32_t id); | 60 SettingsFlagsAndId(uint8_t flags, uint32_t id); |
| 62 | 61 |
| 63 uint32_t GetWireFormat(SpdyMajorVersion version) const; | 62 uint32_t GetWireFormat() const; |
| 64 | 63 |
| 65 uint32_t id() const { return id_; } | 64 uint32_t id() const { return id_; } |
| 66 uint8_t flags() const { return flags_; } | 65 uint8_t flags() const { return flags_; } |
| 67 | 66 |
| 68 private: | 67 private: |
| 69 uint8_t flags_; | 68 uint8_t flags_; |
| 70 uint32_t id_; | 69 uint32_t id_; |
| 71 }; | 70 }; |
| 72 | 71 |
| 73 // SettingsMap has unique (flags, value) pair for given SpdySettingsIds ID. | 72 // SettingsMap has unique (flags, value) pair for given SpdySettingsIds ID. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 virtual void OnPing(SpdyPingId unique_id, bool is_ack) = 0; | 163 virtual void OnPing(SpdyPingId unique_id, bool is_ack) = 0; |
| 165 | 164 |
| 166 // Called when a GOAWAY frame has been parsed. | 165 // Called when a GOAWAY frame has been parsed. |
| 167 virtual void OnGoAway(SpdyStreamId last_accepted_stream_id, | 166 virtual void OnGoAway(SpdyStreamId last_accepted_stream_id, |
| 168 SpdyGoAwayStatus status) = 0; | 167 SpdyGoAwayStatus status) = 0; |
| 169 | 168 |
| 170 // Called when a HEADERS frame is received. | 169 // Called when a HEADERS frame is received. |
| 171 // Note that header block data is not included. See OnHeaderFrameStart(). | 170 // Note that header block data is not included. See OnHeaderFrameStart(). |
| 172 // |stream_id| The stream receiving the header. | 171 // |stream_id| The stream receiving the header. |
| 173 // |has_priority| Whether or not the headers frame included a priority value, | 172 // |has_priority| Whether or not the headers frame included a priority value, |
| 174 // and, if protocol version == HTTP2, stream dependency info. | 173 // and stream dependency info. |
| 175 // |weight| If |has_priority| is true, then weight (in the range [1, 256]) | 174 // |weight| If |has_priority| is true, then weight (in the range [1, 256]) |
| 176 // for the receiving stream, otherwise 0. | 175 // for the receiving stream, otherwise 0. |
| 177 // |parent_stream_id| If |has_priority| is true and protocol | 176 // |parent_stream_id| If |has_priority| is true the parent stream of the |
| 178 // version == HTTP2, the parent stream of the receiving stream, else 0. | 177 // receiving stream, else 0. |
| 179 // |exclusive| If |has_priority| is true and protocol | 178 // |exclusive| If |has_priority| is true the exclusivity of dependence on the |
| 180 // version == HTTP2, the exclusivity of dependence on the parent stream, | 179 // parent stream, else false. |
| 181 // else false. | |
| 182 // |fin| Whether FIN flag is set in frame headers. | 180 // |fin| Whether FIN flag is set in frame headers. |
| 183 // |end| False if HEADERs frame is to be followed by a CONTINUATION frame, | 181 // |end| False if HEADERs frame is to be followed by a CONTINUATION frame, |
| 184 // or true if not. | 182 // or true if not. |
| 185 virtual void OnHeaders(SpdyStreamId stream_id, | 183 virtual void OnHeaders(SpdyStreamId stream_id, |
| 186 bool has_priority, | 184 bool has_priority, |
| 187 int weight, | 185 int weight, |
| 188 SpdyStreamId parent_stream_id, | 186 SpdyStreamId parent_stream_id, |
| 189 bool exclusive, | 187 bool exclusive, |
| 190 bool fin, | 188 bool fin, |
| 191 bool end) = 0; | 189 bool end) = 0; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 | 330 |
| 333 // The maximum size of header data decompressed/delivered at once to the | 331 // The maximum size of header data decompressed/delivered at once to the |
| 334 // header block parser. (Exposed here for unit test purposes.) | 332 // header block parser. (Exposed here for unit test purposes.) |
| 335 static const size_t kHeaderDataChunkMaxSize; | 333 static const size_t kHeaderDataChunkMaxSize; |
| 336 | 334 |
| 337 void SerializeHeaderBlockWithoutCompression( | 335 void SerializeHeaderBlockWithoutCompression( |
| 338 SpdyFrameBuilder* builder, | 336 SpdyFrameBuilder* builder, |
| 339 const SpdyHeaderBlock& header_block) const; | 337 const SpdyHeaderBlock& header_block) const; |
| 340 | 338 |
| 341 // Retrieve serialized length of SpdyHeaderBlock. | 339 // Retrieve serialized length of SpdyHeaderBlock. |
| 342 static size_t GetSerializedLength( | 340 static size_t GetSerializedLength(const SpdyHeaderBlock* headers); |
| 343 const SpdyMajorVersion spdy_version, | |
| 344 const SpdyHeaderBlock* headers); | |
| 345 | 341 |
| 346 // Create a new Framer, provided a SPDY version. | 342 SpdyFramer(); |
| 347 explicit SpdyFramer(SpdyMajorVersion version); | |
| 348 | 343 |
| 349 // Used recursively from the above constructor in order to support | 344 // Used recursively from the above constructor in order to support |
| 350 // instantiating a SpdyFramerDecoderAdapter selected via flags or some other | 345 // instantiating a SpdyFramerDecoderAdapter selected via flags or some other |
| 351 // means. | 346 // means. |
| 352 SpdyFramer(SpdyMajorVersion version, DecoderAdapterFactoryFn adapter_factory); | 347 explicit SpdyFramer(DecoderAdapterFactoryFn adapter_factory); |
| 353 | 348 |
| 354 virtual ~SpdyFramer(); | 349 virtual ~SpdyFramer(); |
| 355 | 350 |
| 356 // Set callbacks to be called from the framer. A visitor must be set, or | 351 // Set callbacks to be called from the framer. A visitor must be set, or |
| 357 // else the framer will likely crash. It is acceptable for the visitor | 352 // else the framer will likely crash. It is acceptable for the visitor |
| 358 // to do nothing. If this is called multiple times, only the last visitor | 353 // to do nothing. If this is called multiple times, only the last visitor |
| 359 // will be used. | 354 // will be used. |
| 360 void set_visitor(SpdyFramerVisitorInterface* visitor); | 355 void set_visitor(SpdyFramerVisitorInterface* visitor); |
| 361 | 356 |
| 362 // Set debug callbacks to be called from the framer. The debug visitor is | 357 // Set debug callbacks to be called from the framer. The debug visitor is |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 | 509 |
| 515 // Returns the maximum payload size of a DATA frame. | 510 // Returns the maximum payload size of a DATA frame. |
| 516 size_t GetDataFrameMaximumPayload() const; | 511 size_t GetDataFrameMaximumPayload() const; |
| 517 | 512 |
| 518 // For debugging. | 513 // For debugging. |
| 519 static const char* StateToString(int state); | 514 static const char* StateToString(int state); |
| 520 static const char* ErrorCodeToString(int error_code); | 515 static const char* ErrorCodeToString(int error_code); |
| 521 static const char* StatusCodeToString(int status_code); | 516 static const char* StatusCodeToString(int status_code); |
| 522 static const char* FrameTypeToString(SpdyFrameType type); | 517 static const char* FrameTypeToString(SpdyFrameType type); |
| 523 | 518 |
| 524 SpdyMajorVersion protocol_version() const { return protocol_version_; } | |
| 525 | |
| 526 // Did the most recent frame header appear to be an HTTP/1.x (or earlier) | 519 // Did the most recent frame header appear to be an HTTP/1.x (or earlier) |
| 527 // response (i.e. start with "HTTP/")? | 520 // response (i.e. start with "HTTP/")? |
| 528 bool probable_http_response() const; | 521 bool probable_http_response() const; |
| 529 | 522 |
| 530 SpdyPriority GetLowestPriority() const { return kV3LowestPriority; } | 523 SpdyPriority GetLowestPriority() const { return kV3LowestPriority; } |
| 531 | 524 |
| 532 SpdyPriority GetHighestPriority() const { return kV3HighestPriority; } | 525 SpdyPriority GetHighestPriority() const { return kV3HighestPriority; } |
| 533 | 526 |
| 534 // Updates the maximum size of the header encoder compression table. | 527 // Updates the maximum size of the header encoder compression table. |
| 535 void UpdateHeaderEncoderTableSize(uint32_t value); | 528 void UpdateHeaderEncoderTableSize(uint32_t value); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 }; | 600 }; |
| 608 | 601 |
| 609 // Internal breakouts from ProcessInput. Each returns the number of bytes | 602 // Internal breakouts from ProcessInput. Each returns the number of bytes |
| 610 // consumed from the data. | 603 // consumed from the data. |
| 611 size_t ProcessCommonHeader(const char* data, size_t len); | 604 size_t ProcessCommonHeader(const char* data, size_t len); |
| 612 size_t ProcessControlFramePayload(const char* data, size_t len); | 605 size_t ProcessControlFramePayload(const char* data, size_t len); |
| 613 size_t ProcessControlFrameBeforeHeaderBlock(const char* data, size_t len); | 606 size_t ProcessControlFrameBeforeHeaderBlock(const char* data, size_t len); |
| 614 // HPACK data is re-encoded as SPDY3 and re-entrantly delivered through | 607 // HPACK data is re-encoded as SPDY3 and re-entrantly delivered through |
| 615 // |ProcessControlFrameHeaderBlock()|. |is_hpack_header_block| controls | 608 // |ProcessControlFrameHeaderBlock()|. |is_hpack_header_block| controls |
| 616 // whether data is treated as HPACK- vs SPDY3-encoded. | 609 // whether data is treated as HPACK- vs SPDY3-encoded. |
| 617 size_t ProcessControlFrameHeaderBlock(const char* data, | 610 size_t ProcessControlFrameHeaderBlock(const char* data, size_t len); |
| 618 size_t len, | |
| 619 bool is_hpack_header_block); | |
| 620 size_t ProcessDataFramePaddingLength(const char* data, size_t len); | 611 size_t ProcessDataFramePaddingLength(const char* data, size_t len); |
| 621 size_t ProcessFramePadding(const char* data, size_t len); | 612 size_t ProcessFramePadding(const char* data, size_t len); |
| 622 size_t ProcessDataFramePayload(const char* data, size_t len); | 613 size_t ProcessDataFramePayload(const char* data, size_t len); |
| 623 size_t ProcessGoAwayFramePayload(const char* data, size_t len); | 614 size_t ProcessGoAwayFramePayload(const char* data, size_t len); |
| 624 size_t ProcessRstStreamFramePayload(const char* data, size_t len); | 615 size_t ProcessRstStreamFramePayload(const char* data, size_t len); |
| 625 size_t ProcessSettingsFrameHeader(const char* data, size_t len); | 616 size_t ProcessSettingsFrameHeader(const char* data, size_t len); |
| 626 size_t ProcessSettingsFramePayload(const char* data, size_t len); | 617 size_t ProcessSettingsFramePayload(const char* data, size_t len); |
| 627 size_t ProcessAltSvcFramePayload(const char* data, size_t len); | 618 size_t ProcessAltSvcFramePayload(const char* data, size_t len); |
| 628 size_t ProcessIgnoredControlFramePayload(/*const char* data,*/ size_t len); | 619 size_t ProcessIgnoredControlFramePayload(/*const char* data,*/ size_t len); |
| 629 | 620 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 | 750 |
| 760 SpdyFramerVisitorInterface* visitor_; | 751 SpdyFramerVisitorInterface* visitor_; |
| 761 SpdyFramerDebugVisitorInterface* debug_visitor_; | 752 SpdyFramerDebugVisitorInterface* debug_visitor_; |
| 762 | 753 |
| 763 std::unique_ptr<SpdyHeadersBlockParser> header_parser_; | 754 std::unique_ptr<SpdyHeadersBlockParser> header_parser_; |
| 764 SpdyHeadersHandlerInterface* header_handler_; | 755 SpdyHeadersHandlerInterface* header_handler_; |
| 765 | 756 |
| 766 // Optional decoder to use instead of this instance. | 757 // Optional decoder to use instead of this instance. |
| 767 std::unique_ptr<SpdyFramerDecoderAdapter> decoder_adapter_; | 758 std::unique_ptr<SpdyFramerDecoderAdapter> decoder_adapter_; |
| 768 | 759 |
| 769 // The protocol version to be spoken/understood by this framer. | |
| 770 const SpdyMajorVersion protocol_version_; | |
| 771 | |
| 772 // The flags field of the frame currently being read. | 760 // The flags field of the frame currently being read. |
| 773 uint8_t current_frame_flags_; | 761 uint8_t current_frame_flags_; |
| 774 | 762 |
| 775 // Determines whether HPACK compression is used. | 763 // Determines whether HPACK compression is used. |
| 776 bool enable_compression_; | 764 bool enable_compression_; |
| 777 | 765 |
| 778 // On the first read, we check to see if the data starts with HTTP. | 766 // On the first read, we check to see if the data starts with HTTP. |
| 779 // If it does, we likely have an HTTP response. This isn't guaranteed | 767 // If it does, we likely have an HTTP response. This isn't guaranteed |
| 780 // though: we could have gotten a settings frame and then corrupt data that | 768 // though: we could have gotten a settings frame and then corrupt data that |
| 781 // just looks like HTTP, but deterministic checking requires a lot more state. | 769 // just looks like HTTP, but deterministic checking requires a lot more state. |
| 782 bool probable_http_response_; | 770 bool probable_http_response_; |
| 783 | 771 |
| 784 // If a HEADERS frame is followed by a CONTINUATION frame, the FIN/END_STREAM | 772 // If a HEADERS frame is followed by a CONTINUATION frame, the FIN/END_STREAM |
| 785 // flag is still carried in the HEADERS frame. If it's set, flip this so that | 773 // flag is still carried in the HEADERS frame. If it's set, flip this so that |
| 786 // we know to terminate the stream when the entire header block has been | 774 // we know to terminate the stream when the entire header block has been |
| 787 // processed. | 775 // processed. |
| 788 bool end_stream_when_done_; | 776 bool end_stream_when_done_; |
| 789 | 777 |
| 790 // If true, then ProcessInput returns after processing a full frame, | 778 // If true, then ProcessInput returns after processing a full frame, |
| 791 // rather than reading all available input. | 779 // rather than reading all available input. |
| 792 bool process_single_input_frame_ = false; | 780 bool process_single_input_frame_ = false; |
| 793 }; | 781 }; |
| 794 | 782 |
| 795 } // namespace net | 783 } // namespace net |
| 796 | 784 |
| 797 #endif // NET_SPDY_SPDY_FRAMER_H_ | 785 #endif // NET_SPDY_SPDY_FRAMER_H_ |
| OLD | NEW |