| 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> |
| 9 #include <stdint.h> |
| 10 |
| 8 #include <map> | 11 #include <map> |
| 9 #include <memory> | 12 #include <memory> |
| 10 #include <string> | 13 #include <string> |
| 11 #include <utility> | 14 #include <utility> |
| 12 | 15 |
| 13 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/strings/string_piece.h" | 17 #include "base/strings/string_piece.h" |
| 15 #include "base/sys_byteorder.h" | 18 #include "base/sys_byteorder.h" |
| 16 #include "net/base/net_export.h" | 19 #include "net/base/net_export.h" |
| 17 #include "net/spdy/hpack/hpack_decoder.h" | 20 #include "net/spdy/hpack/hpack_decoder.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 41 class TestSpdyVisitor; | 44 class TestSpdyVisitor; |
| 42 class SpdyFramerPeer; | 45 class SpdyFramerPeer; |
| 43 | 46 |
| 44 } // namespace test | 47 } // namespace test |
| 45 | 48 |
| 46 // A datastructure for holding the ID and flag fields for SETTINGS. | 49 // A datastructure for holding the ID and flag fields for SETTINGS. |
| 47 // Conveniently handles converstion to/from wire format. | 50 // Conveniently handles converstion to/from wire format. |
| 48 class NET_EXPORT_PRIVATE SettingsFlagsAndId { | 51 class NET_EXPORT_PRIVATE SettingsFlagsAndId { |
| 49 public: | 52 public: |
| 50 static SettingsFlagsAndId FromWireFormat(SpdyMajorVersion version, | 53 static SettingsFlagsAndId FromWireFormat(SpdyMajorVersion version, |
| 51 uint32 wire); | 54 uint32_t wire); |
| 52 | 55 |
| 53 SettingsFlagsAndId() : flags_(0), id_(0) {} | 56 SettingsFlagsAndId() : flags_(0), id_(0) {} |
| 54 | 57 |
| 55 // TODO(hkhalil): restrict to enums instead of free-form ints. | 58 // TODO(hkhalil): restrict to enums instead of free-form ints. |
| 56 SettingsFlagsAndId(uint8 flags, uint32 id); | 59 SettingsFlagsAndId(uint8_t flags, uint32_t id); |
| 57 | 60 |
| 58 uint32 GetWireFormat(SpdyMajorVersion version) const; | 61 uint32_t GetWireFormat(SpdyMajorVersion version) const; |
| 59 | 62 |
| 60 uint32 id() const { return id_; } | 63 uint32_t id() const { return id_; } |
| 61 uint8 flags() const { return flags_; } | 64 uint8_t flags() const { return flags_; } |
| 62 | 65 |
| 63 private: | 66 private: |
| 64 static void ConvertFlagsAndIdForSpdy2(uint32* val); | 67 static void ConvertFlagsAndIdForSpdy2(uint32_t* val); |
| 65 | 68 |
| 66 uint8 flags_; | 69 uint8_t flags_; |
| 67 uint32 id_; | 70 uint32_t id_; |
| 68 }; | 71 }; |
| 69 | 72 |
| 70 // SettingsMap has unique (flags, value) pair for given SpdySettingsIds ID. | 73 // SettingsMap has unique (flags, value) pair for given SpdySettingsIds ID. |
| 71 typedef std::pair<SpdySettingsFlags, uint32> SettingsFlagsAndValue; | 74 typedef std::pair<SpdySettingsFlags, uint32_t> SettingsFlagsAndValue; |
| 72 typedef std::map<SpdySettingsIds, SettingsFlagsAndValue> SettingsMap; | 75 typedef std::map<SpdySettingsIds, SettingsFlagsAndValue> SettingsMap; |
| 73 | 76 |
| 74 // SpdyFramerVisitorInterface is a set of callbacks for the SpdyFramer. | 77 // SpdyFramerVisitorInterface is a set of callbacks for the SpdyFramer. |
| 75 // Implement this interface to receive event callbacks as frames are | 78 // Implement this interface to receive event callbacks as frames are |
| 76 // decoded from the framer. | 79 // decoded from the framer. |
| 77 // | 80 // |
| 78 // Control frames that contain SPDY header blocks (SYN_STREAM, SYN_REPLY, | 81 // Control frames that contain SPDY header blocks (SYN_STREAM, SYN_REPLY, |
| 79 // HEADER, and PUSH_PROMISE) are processed in fashion that allows the | 82 // HEADER, and PUSH_PROMISE) are processed in fashion that allows the |
| 80 // decompressed header block to be delivered in chunks to the visitor. | 83 // decompressed header block to be delivered in chunks to the visitor. |
| 81 // The following steps are followed: | 84 // The following steps are followed: |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 // Called when a RST_STREAM frame has been parsed. | 170 // Called when a RST_STREAM frame has been parsed. |
| 168 virtual void OnRstStream(SpdyStreamId stream_id, | 171 virtual void OnRstStream(SpdyStreamId stream_id, |
| 169 SpdyRstStreamStatus status) = 0; | 172 SpdyRstStreamStatus status) = 0; |
| 170 | 173 |
| 171 // Called when a SETTINGS frame is received. | 174 // Called when a SETTINGS frame is received. |
| 172 // |clear_persisted| True if the respective flag is set on the SETTINGS frame. | 175 // |clear_persisted| True if the respective flag is set on the SETTINGS frame. |
| 173 virtual void OnSettings(bool clear_persisted) {} | 176 virtual void OnSettings(bool clear_persisted) {} |
| 174 | 177 |
| 175 // Called when a complete setting within a SETTINGS frame has been parsed and | 178 // Called when a complete setting within a SETTINGS frame has been parsed and |
| 176 // validated. | 179 // validated. |
| 177 virtual void OnSetting(SpdySettingsIds id, uint8 flags, uint32 value) = 0; | 180 virtual void OnSetting(SpdySettingsIds id, uint8_t flags, uint32_t value) = 0; |
| 178 | 181 |
| 179 // Called when a SETTINGS frame is received with the ACK flag set. | 182 // Called when a SETTINGS frame is received with the ACK flag set. |
| 180 virtual void OnSettingsAck() {} | 183 virtual void OnSettingsAck() {} |
| 181 | 184 |
| 182 // Called before and after parsing SETTINGS id and value tuples. | 185 // Called before and after parsing SETTINGS id and value tuples. |
| 183 virtual void OnSettingsEnd() = 0; | 186 virtual void OnSettingsEnd() = 0; |
| 184 | 187 |
| 185 // Called when a PING frame has been parsed. | 188 // Called when a PING frame has been parsed. |
| 186 virtual void OnPing(SpdyPingId unique_id, bool is_ack) = 0; | 189 virtual void OnPing(SpdyPingId unique_id, bool is_ack) = 0; |
| 187 | 190 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 256 |
| 254 // Called when an ALTSVC frame has been parsed. | 257 // Called when an ALTSVC frame has been parsed. |
| 255 virtual void OnAltSvc( | 258 virtual void OnAltSvc( |
| 256 SpdyStreamId stream_id, | 259 SpdyStreamId stream_id, |
| 257 base::StringPiece origin, | 260 base::StringPiece origin, |
| 258 const SpdyAltSvcWireFormat::AlternativeServiceVector& altsvc_vector) {} | 261 const SpdyAltSvcWireFormat::AlternativeServiceVector& altsvc_vector) {} |
| 259 | 262 |
| 260 // Called when a PRIORITY frame is received. | 263 // Called when a PRIORITY frame is received. |
| 261 virtual void OnPriority(SpdyStreamId stream_id, | 264 virtual void OnPriority(SpdyStreamId stream_id, |
| 262 SpdyStreamId parent_stream_id, | 265 SpdyStreamId parent_stream_id, |
| 263 uint8 weight, | 266 uint8_t weight, |
| 264 bool exclusive) {} | 267 bool exclusive) {} |
| 265 | 268 |
| 266 // Called when a frame type we don't recognize is received. | 269 // Called when a frame type we don't recognize is received. |
| 267 // Return true if this appears to be a valid extension frame, false otherwise. | 270 // Return true if this appears to be a valid extension frame, false otherwise. |
| 268 // We distinguish between extension frames and nonsense by checking | 271 // We distinguish between extension frames and nonsense by checking |
| 269 // whether the stream id is valid. | 272 // whether the stream id is valid. |
| 270 virtual bool OnUnknownFrame(SpdyStreamId stream_id, int frame_type) = 0; | 273 virtual bool OnUnknownFrame(SpdyStreamId stream_id, int frame_type) = 0; |
| 271 }; | 274 }; |
| 272 | 275 |
| 273 // Optionally, and in addition to SpdyFramerVisitorInterface, a class supporting | 276 // Optionally, and in addition to SpdyFramerVisitorInterface, a class supporting |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 bool probable_http_response() const { return probable_http_response_; } | 549 bool probable_http_response() const { return probable_http_response_; } |
| 547 | 550 |
| 548 SpdyPriority GetLowestPriority() const { | 551 SpdyPriority GetLowestPriority() const { |
| 549 return protocol_version_ < SPDY3 ? 3 : 7; | 552 return protocol_version_ < SPDY3 ? 3 : 7; |
| 550 } | 553 } |
| 551 | 554 |
| 552 SpdyPriority GetHighestPriority() const { return 0; } | 555 SpdyPriority GetHighestPriority() const { return 0; } |
| 553 | 556 |
| 554 // Interpolates SpdyPriority values into SPDY4/HTTP2 priority weights, | 557 // Interpolates SpdyPriority values into SPDY4/HTTP2 priority weights, |
| 555 // and vice versa. | 558 // and vice versa. |
| 556 static uint8 MapPriorityToWeight(SpdyPriority priority); | 559 static uint8_t MapPriorityToWeight(SpdyPriority priority); |
| 557 static SpdyPriority MapWeightToPriority(uint8 weight); | 560 static SpdyPriority MapWeightToPriority(uint8_t weight); |
| 558 | 561 |
| 559 // Deliver the given control frame's compressed headers block to the visitor | 562 // Deliver the given control frame's compressed headers block to the visitor |
| 560 // in decompressed form, in chunks. Returns true if the visitor has | 563 // in decompressed form, in chunks. Returns true if the visitor has |
| 561 // accepted all of the chunks. | 564 // accepted all of the chunks. |
| 562 bool IncrementallyDecompressControlFrameHeaderData( | 565 bool IncrementallyDecompressControlFrameHeaderData( |
| 563 SpdyStreamId stream_id, | 566 SpdyStreamId stream_id, |
| 564 const char* data, | 567 const char* data, |
| 565 size_t len); | 568 size_t len); |
| 566 | 569 |
| 567 // Updates the maximum size of the header encoder compression table. | 570 // Updates the maximum size of the header encoder compression table. |
| 568 void UpdateHeaderEncoderTableSize(uint32 value); | 571 void UpdateHeaderEncoderTableSize(uint32_t value); |
| 569 | 572 |
| 570 // Returns the maximum size of the header encoder compression table. | 573 // Returns the maximum size of the header encoder compression table. |
| 571 size_t header_encoder_table_size() const; | 574 size_t header_encoder_table_size() const; |
| 572 | 575 |
| 573 protected: | 576 protected: |
| 574 friend class HttpNetworkLayer; // This is temporary for the server. | 577 friend class HttpNetworkLayer; // This is temporary for the server. |
| 575 friend class HttpNetworkTransactionTest; | 578 friend class HttpNetworkTransactionTest; |
| 576 friend class HttpProxyClientSocketPoolTest; | 579 friend class HttpProxyClientSocketPoolTest; |
| 577 friend class SpdyHttpStreamTest; | 580 friend class SpdyHttpStreamTest; |
| 578 friend class SpdyNetworkTransactionTest; | 581 friend class SpdyNetworkTransactionTest; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 // headers. Note that header data blocks (for control types that have them) | 728 // headers. Note that header data blocks (for control types that have them) |
| 726 // are part of the frame's payload, and not the frame's headers. | 729 // are part of the frame's payload, and not the frame's headers. |
| 727 size_t remaining_control_header_; | 730 size_t remaining_control_header_; |
| 728 | 731 |
| 729 CharBuffer current_frame_buffer_; | 732 CharBuffer current_frame_buffer_; |
| 730 | 733 |
| 731 // The type of the frame currently being read. | 734 // The type of the frame currently being read. |
| 732 SpdyFrameType current_frame_type_; | 735 SpdyFrameType current_frame_type_; |
| 733 | 736 |
| 734 // The total length of the frame currently being read, including frame header. | 737 // The total length of the frame currently being read, including frame header. |
| 735 uint32 current_frame_length_; | 738 uint32_t current_frame_length_; |
| 736 | 739 |
| 737 // The stream ID field of the frame currently being read, if applicable. | 740 // The stream ID field of the frame currently being read, if applicable. |
| 738 SpdyStreamId current_frame_stream_id_; | 741 SpdyStreamId current_frame_stream_id_; |
| 739 | 742 |
| 740 // Set this to the current stream when we receive a HEADERS, PUSH_PROMISE, or | 743 // Set this to the current stream when we receive a HEADERS, PUSH_PROMISE, or |
| 741 // CONTINUATION frame without the END_HEADERS(0x4) bit set. These frames must | 744 // CONTINUATION frame without the END_HEADERS(0x4) bit set. These frames must |
| 742 // be followed by a CONTINUATION frame, or else we throw a PROTOCOL_ERROR. | 745 // be followed by a CONTINUATION frame, or else we throw a PROTOCOL_ERROR. |
| 743 // A value of 0 indicates that we are not expecting a CONTINUATION frame. | 746 // A value of 0 indicates that we are not expecting a CONTINUATION frame. |
| 744 SpdyStreamId expect_continuation_; | 747 SpdyStreamId expect_continuation_; |
| 745 | 748 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 759 | 762 |
| 760 SpdyFramerVisitorInterface* visitor_; | 763 SpdyFramerVisitorInterface* visitor_; |
| 761 SpdyFramerDebugVisitorInterface* debug_visitor_; | 764 SpdyFramerDebugVisitorInterface* debug_visitor_; |
| 762 | 765 |
| 763 std::string display_protocol_; | 766 std::string display_protocol_; |
| 764 | 767 |
| 765 // The protocol version to be spoken/understood by this framer. | 768 // The protocol version to be spoken/understood by this framer. |
| 766 const SpdyMajorVersion protocol_version_; | 769 const SpdyMajorVersion protocol_version_; |
| 767 | 770 |
| 768 // The flags field of the frame currently being read. | 771 // The flags field of the frame currently being read. |
| 769 uint8 current_frame_flags_; | 772 uint8_t current_frame_flags_; |
| 770 | 773 |
| 771 // Determines whether HPACK or gzip compression is used. | 774 // Determines whether HPACK or gzip compression is used. |
| 772 bool enable_compression_; | 775 bool enable_compression_; |
| 773 | 776 |
| 774 // Tracks if we've ever gotten far enough in framing to see a control frame of | 777 // Tracks if we've ever gotten far enough in framing to see a control frame of |
| 775 // type SYN_STREAM or SYN_REPLY. | 778 // type SYN_STREAM or SYN_REPLY. |
| 776 // | 779 // |
| 777 // If we ever get something which looks like a data frame before we've had a | 780 // If we ever get something which looks like a data frame before we've had a |
| 778 // SYN, we explicitly check to see if it looks like we got an HTTP response | 781 // SYN, we explicitly check to see if it looks like we got an HTTP response |
| 779 // to a SPDY request. This boolean lets us do that. | 782 // to a SPDY request. This boolean lets us do that. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 793 bool end_stream_when_done_; | 796 bool end_stream_when_done_; |
| 794 | 797 |
| 795 // If true, then ProcessInput returns after processing a full frame, | 798 // If true, then ProcessInput returns after processing a full frame, |
| 796 // rather than reading all available input. | 799 // rather than reading all available input. |
| 797 bool process_single_input_frame_ = false; | 800 bool process_single_input_frame_ = false; |
| 798 }; | 801 }; |
| 799 | 802 |
| 800 } // namespace net | 803 } // namespace net |
| 801 | 804 |
| 802 #endif // NET_SPDY_SPDY_FRAMER_H_ | 805 #endif // NET_SPDY_SPDY_FRAMER_H_ |
| OLD | NEW |