| 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 <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 // SettingsMap has unique (flags, value) pair for given SpdySettingsIds ID. | 78 // SettingsMap has unique (flags, value) pair for given SpdySettingsIds ID. |
| 79 typedef std::pair<SpdySettingsFlags, uint32> SettingsFlagsAndValue; | 79 typedef std::pair<SpdySettingsFlags, uint32> SettingsFlagsAndValue; |
| 80 typedef std::map<SpdySettingsIds, SettingsFlagsAndValue> SettingsMap; | 80 typedef std::map<SpdySettingsIds, SettingsFlagsAndValue> SettingsMap; |
| 81 | 81 |
| 82 // Scratch space necessary for processing SETTINGS frames. | 82 // Scratch space necessary for processing SETTINGS frames. |
| 83 struct NET_EXPORT_PRIVATE SpdySettingsScratch { | 83 struct NET_EXPORT_PRIVATE SpdySettingsScratch { |
| 84 SpdySettingsScratch() { Reset(); } | 84 SpdySettingsScratch() { Reset(); } |
| 85 | 85 |
| 86 void Reset() { | 86 void Reset() { |
| 87 setting_buf_len = 0; | 87 setting_buf_len = 0; |
| 88 last_setting_id = 0; | 88 last_setting_id = -1; |
| 89 } | 89 } |
| 90 | 90 |
| 91 // Buffer contains up to one complete key/value pair. | 91 // Buffer contains up to one complete key/value pair. |
| 92 char setting_buf[8]; | 92 char setting_buf[8]; |
| 93 | 93 |
| 94 // The amount of the buffer that is filled with valid data. | 94 // The amount of the buffer that is filled with valid data. |
| 95 size_t setting_buf_len; | 95 size_t setting_buf_len; |
| 96 | 96 |
| 97 // The ID of the last setting that was processed in the current SETTINGS | 97 // The ID of the last setting that was processed in the current SETTINGS |
| 98 // frame. Used for detecting out-of-order or duplicate keys within a settings | 98 // frame. Used for detecting out-of-order or duplicate keys within a settings |
| 99 // frame. Set to 0 before first key/value pair is processed. | 99 // frame. Set to -1 before first key/value pair is processed. |
| 100 uint32 last_setting_id; | 100 int last_setting_id; |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 // SpdyFramerVisitorInterface is a set of callbacks for the SpdyFramer. | 103 // SpdyFramerVisitorInterface is a set of callbacks for the SpdyFramer. |
| 104 // Implement this interface to receive event callbacks as frames are | 104 // Implement this interface to receive event callbacks as frames are |
| 105 // decoded from the framer. | 105 // decoded from the framer. |
| 106 // | 106 // |
| 107 // Control frames that contain SPDY header blocks (SYN_STREAM, SYN_REPLY, | 107 // Control frames that contain SPDY header blocks (SYN_STREAM, SYN_REPLY, |
| 108 // HEADER, and PUSH_PROMISE) are processed in fashion that allows the | 108 // HEADER, and PUSH_PROMISE) are processed in fashion that allows the |
| 109 // decompressed header block to be delivered in chunks to the visitor. | 109 // decompressed header block to be delivered in chunks to the visitor. |
| 110 // The following steps are followed: | 110 // The following steps are followed: |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 public: | 274 public: |
| 275 // SPDY states. | 275 // SPDY states. |
| 276 // TODO(mbelshe): Can we move these into the implementation | 276 // TODO(mbelshe): Can we move these into the implementation |
| 277 // and avoid exposing through the header. (Needed for test) | 277 // and avoid exposing through the header. (Needed for test) |
| 278 enum SpdyState { | 278 enum SpdyState { |
| 279 SPDY_ERROR, | 279 SPDY_ERROR, |
| 280 SPDY_RESET, | 280 SPDY_RESET, |
| 281 SPDY_AUTO_RESET, | 281 SPDY_AUTO_RESET, |
| 282 SPDY_READING_COMMON_HEADER, | 282 SPDY_READING_COMMON_HEADER, |
| 283 SPDY_CONTROL_FRAME_PAYLOAD, | 283 SPDY_CONTROL_FRAME_PAYLOAD, |
| 284 SPDY_READ_PADDING_LENGTH, |
| 285 SPDY_CONSUME_PADDING, |
| 284 SPDY_IGNORE_REMAINING_PAYLOAD, | 286 SPDY_IGNORE_REMAINING_PAYLOAD, |
| 285 SPDY_FORWARD_STREAM_FRAME, | 287 SPDY_FORWARD_STREAM_FRAME, |
| 286 SPDY_CONTROL_FRAME_BEFORE_HEADER_BLOCK, | 288 SPDY_CONTROL_FRAME_BEFORE_HEADER_BLOCK, |
| 287 SPDY_CONTROL_FRAME_HEADER_BLOCK, | 289 SPDY_CONTROL_FRAME_HEADER_BLOCK, |
| 288 SPDY_GOAWAY_FRAME_PAYLOAD, | 290 SPDY_GOAWAY_FRAME_PAYLOAD, |
| 289 SPDY_RST_STREAM_FRAME_PAYLOAD, | 291 SPDY_RST_STREAM_FRAME_PAYLOAD, |
| 290 SPDY_SETTINGS_FRAME_PAYLOAD, | 292 SPDY_SETTINGS_FRAME_PAYLOAD, |
| 291 }; | 293 }; |
| 292 | 294 |
| 293 // SPDY error codes. | 295 // SPDY error codes. |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 size_t GetBlockedSize() const; | 472 size_t GetBlockedSize() const; |
| 471 size_t GetPushPromiseMinimumSize() const; | 473 size_t GetPushPromiseMinimumSize() const; |
| 472 size_t GetContinuationMinimumSize() const; | 474 size_t GetContinuationMinimumSize() const; |
| 473 | 475 |
| 474 // Returns the minimum size a frame can be (data or control). | 476 // Returns the minimum size a frame can be (data or control). |
| 475 size_t GetFrameMinimumSize() const; | 477 size_t GetFrameMinimumSize() const; |
| 476 | 478 |
| 477 // Returns the maximum size a frame can be (data or control). | 479 // Returns the maximum size a frame can be (data or control). |
| 478 size_t GetFrameMaximumSize() const; | 480 size_t GetFrameMaximumSize() const; |
| 479 | 481 |
| 482 // Returns the maximum size that a control frame can be. |
| 483 size_t GetControlFrameMaximumSize() const; |
| 484 |
| 480 // Returns the maximum payload size of a DATA frame. | 485 // Returns the maximum payload size of a DATA frame. |
| 481 size_t GetDataFrameMaximumPayload() const; | 486 size_t GetDataFrameMaximumPayload() const; |
| 482 | 487 |
| 483 // For debugging. | 488 // For debugging. |
| 484 static const char* StateToString(int state); | 489 static const char* StateToString(int state); |
| 485 static const char* ErrorCodeToString(int error_code); | 490 static const char* ErrorCodeToString(int error_code); |
| 486 static const char* StatusCodeToString(int status_code); | 491 static const char* StatusCodeToString(int status_code); |
| 487 static const char* FrameTypeToString(SpdyFrameType type); | 492 static const char* FrameTypeToString(SpdyFrameType type); |
| 488 | 493 |
| 489 SpdyMajorVersion protocol_version() const { return spdy_version_; } | 494 SpdyMajorVersion protocol_version() const { return spdy_version_; } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 // consumed from the data. | 542 // consumed from the data. |
| 538 size_t ProcessCommonHeader(const char* data, size_t len); | 543 size_t ProcessCommonHeader(const char* data, size_t len); |
| 539 size_t ProcessControlFramePayload(const char* data, size_t len); | 544 size_t ProcessControlFramePayload(const char* data, size_t len); |
| 540 size_t ProcessControlFrameBeforeHeaderBlock(const char* data, size_t len); | 545 size_t ProcessControlFrameBeforeHeaderBlock(const char* data, size_t len); |
| 541 // HPACK data is re-encoded as SPDY3 and re-entrantly delivered through | 546 // HPACK data is re-encoded as SPDY3 and re-entrantly delivered through |
| 542 // |ProcessControlFrameHeaderBlock()|. |is_hpack_header_block| controls | 547 // |ProcessControlFrameHeaderBlock()|. |is_hpack_header_block| controls |
| 543 // whether data is treated as HPACK- vs SPDY3-encoded. | 548 // whether data is treated as HPACK- vs SPDY3-encoded. |
| 544 size_t ProcessControlFrameHeaderBlock(const char* data, | 549 size_t ProcessControlFrameHeaderBlock(const char* data, |
| 545 size_t len, | 550 size_t len, |
| 546 bool is_hpack_header_block); | 551 bool is_hpack_header_block); |
| 552 size_t ProcessFramePaddingLength(const char* data, size_t len); |
| 553 size_t ProcessFramePadding(const char* data, size_t len); |
| 547 size_t ProcessDataFramePayload(const char* data, size_t len); | 554 size_t ProcessDataFramePayload(const char* data, size_t len); |
| 548 size_t ProcessGoAwayFramePayload(const char* data, size_t len); | 555 size_t ProcessGoAwayFramePayload(const char* data, size_t len); |
| 549 size_t ProcessRstStreamFramePayload(const char* data, size_t len); | 556 size_t ProcessRstStreamFramePayload(const char* data, size_t len); |
| 550 size_t ProcessSettingsFramePayload(const char* data, size_t len); | 557 size_t ProcessSettingsFramePayload(const char* data, size_t len); |
| 551 | 558 |
| 552 // TODO(jgraettinger): To be removed with migration to | 559 // TODO(jgraettinger): To be removed with migration to |
| 553 // SpdyHeadersHandlerInterface. | 560 // SpdyHeadersHandlerInterface. |
| 554 // Serializes the last-processed header block of |hpack_decoder_| as | 561 // Serializes the last-processed header block of |hpack_decoder_| as |
| 555 // a SPDY3 format block, and delivers it to the visitor via reentrant | 562 // a SPDY3 format block, and delivers it to the visitor via reentrant |
| 556 // call to ProcessControlFrameHeaderBlock(). | 563 // call to ProcessControlFrameHeaderBlock(). |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 | 628 |
| 622 // The size of the control frame buffer. | 629 // The size of the control frame buffer. |
| 623 // Since this is only used for control frame headers, the maximum control | 630 // Since this is only used for control frame headers, the maximum control |
| 624 // frame header size (SYN_STREAM) is sufficient; all remaining control | 631 // frame header size (SYN_STREAM) is sufficient; all remaining control |
| 625 // frame data is streamed to the visitor. | 632 // frame data is streamed to the visitor. |
| 626 static const size_t kControlFrameBufferSize; | 633 static const size_t kControlFrameBufferSize; |
| 627 | 634 |
| 628 SpdyState state_; | 635 SpdyState state_; |
| 629 SpdyState previous_state_; | 636 SpdyState previous_state_; |
| 630 SpdyError error_code_; | 637 SpdyError error_code_; |
| 638 |
| 639 // Note that for DATA frame, remaining_data_length_ is sum of lengths of |
| 640 // frame header, padding length field (optional), data payload (optional) and |
| 641 // padding payload (optional). |
| 631 size_t remaining_data_length_; | 642 size_t remaining_data_length_; |
| 632 | 643 |
| 644 // The length (in bytes) of the padding payload to be processed. |
| 645 size_t remaining_padding_payload_length_; |
| 646 |
| 647 // The length (in bytes) of the padding length field to be processed. |
| 648 size_t remaining_padding_length_fields_; |
| 649 |
| 633 // The number of bytes remaining to read from the current control frame's | 650 // The number of bytes remaining to read from the current control frame's |
| 634 // headers. Note that header data blocks (for control types that have them) | 651 // headers. Note that header data blocks (for control types that have them) |
| 635 // are part of the frame's payload, and not the frame's headers. | 652 // are part of the frame's payload, and not the frame's headers. |
| 636 size_t remaining_control_header_; | 653 size_t remaining_control_header_; |
| 637 | 654 |
| 638 scoped_ptr<char[]> current_frame_buffer_; | 655 scoped_ptr<char[]> current_frame_buffer_; |
| 639 // Number of bytes read into the current_frame_buffer_. | 656 // Number of bytes read into the current_frame_buffer_. |
| 640 size_t current_frame_buffer_length_; | 657 size_t current_frame_buffer_length_; |
| 641 | 658 |
| 642 // The type of the frame currently being read. | 659 // The type of the frame currently being read. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 // If a HEADERS frame is followed by a CONTINUATION frame, the FIN/END_STREAM | 713 // If a HEADERS frame is followed by a CONTINUATION frame, the FIN/END_STREAM |
| 697 // flag is still carried in the HEADERS frame. If it's set, flip this so that | 714 // flag is still carried in the HEADERS frame. If it's set, flip this so that |
| 698 // we know to terminate the stream when the entire header block has been | 715 // we know to terminate the stream when the entire header block has been |
| 699 // processed. | 716 // processed. |
| 700 bool end_stream_when_done_; | 717 bool end_stream_when_done_; |
| 701 }; | 718 }; |
| 702 | 719 |
| 703 } // namespace net | 720 } // namespace net |
| 704 | 721 |
| 705 #endif // NET_SPDY_SPDY_FRAMER_H_ | 722 #endif // NET_SPDY_SPDY_FRAMER_H_ |
| OLD | NEW |