| 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 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't | 5 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't |
| 6 // constantly adding and subtracting header sizes; this is ugly and error- | 6 // constantly adding and subtracting header sizes; this is ugly and error- |
| 7 // prone. | 7 // prone. |
| 8 | 8 |
| 9 #include "net/spdy/spdy_framer.h" | 9 #include "net/spdy/spdy_framer.h" |
| 10 | 10 |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 break; | 557 break; |
| 558 } | 558 } |
| 559 | 559 |
| 560 case SPDY_CONSUME_PADDING: { | 560 case SPDY_CONSUME_PADDING: { |
| 561 size_t bytes_read = ProcessFramePadding(data, len); | 561 size_t bytes_read = ProcessFramePadding(data, len); |
| 562 len -= bytes_read; | 562 len -= bytes_read; |
| 563 data += bytes_read; | 563 data += bytes_read; |
| 564 break; | 564 break; |
| 565 } | 565 } |
| 566 | 566 |
| 567 case SPDY_IGNORE_REMAINING_PAYLOAD: | 567 case SPDY_IGNORE_REMAINING_PAYLOAD: { |
| 568 // control frame has too-large payload | 568 size_t bytes_read = ProcessIgnoredControlFramePayload(/*data,*/ len); |
| 569 // intentional fallthrough | 569 len -= bytes_read; |
| 570 data += bytes_read; |
| 571 break; |
| 572 } |
| 573 |
| 570 case SPDY_FORWARD_STREAM_FRAME: { | 574 case SPDY_FORWARD_STREAM_FRAME: { |
| 571 size_t bytes_read = ProcessDataFramePayload(data, len); | 575 size_t bytes_read = ProcessDataFramePayload(data, len); |
| 572 len -= bytes_read; | 576 len -= bytes_read; |
| 573 data += bytes_read; | 577 data += bytes_read; |
| 574 break; | 578 break; |
| 575 } | 579 } |
| 580 |
| 576 default: | 581 default: |
| 577 LOG(DFATAL) << "Invalid value for " << display_protocol_ | 582 LOG(DFATAL) << "Invalid value for " << display_protocol_ |
| 578 << " framer state: " << state_; | 583 << " framer state: " << state_; |
| 579 // This ensures that we don't infinite-loop if state_ gets an | 584 // This ensures that we don't infinite-loop if state_ gets an |
| 580 // invalid value somehow, such as due to a SpdyFramer getting deleted | 585 // invalid value somehow, such as due to a SpdyFramer getting deleted |
| 581 // from a callback it calls. | 586 // from a callback it calls. |
| 582 goto bottom; | 587 goto bottom; |
| 583 } | 588 } |
| 584 } while (state_ != previous_state_); | 589 } while (state_ != previous_state_); |
| 585 bottom: | 590 bottom: |
| (...skipping 1315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1901 // Communicate the padding to the visitor through a NULL data pointer, with | 1906 // Communicate the padding to the visitor through a NULL data pointer, with |
| 1902 // a nonzero size. | 1907 // a nonzero size. |
| 1903 if (amount_to_discard) { | 1908 if (amount_to_discard) { |
| 1904 visitor_->OnStreamFrameData( | 1909 visitor_->OnStreamFrameData( |
| 1905 current_frame_stream_id_, NULL, amount_to_discard, false); | 1910 current_frame_stream_id_, NULL, amount_to_discard, false); |
| 1906 } | 1911 } |
| 1907 data += amount_to_discard; | 1912 data += amount_to_discard; |
| 1908 len -= amount_to_discard; | 1913 len -= amount_to_discard; |
| 1909 remaining_padding_payload_length_ -= amount_to_discard; | 1914 remaining_padding_payload_length_ -= amount_to_discard; |
| 1910 remaining_data_length_ -= amount_to_discard; | 1915 remaining_data_length_ -= amount_to_discard; |
| 1911 | |
| 1912 // If the FIN flag is set, and there is no more data in this data | |
| 1913 // frame, inform the visitor of EOF via a 0-length data frame. | |
| 1914 if (!remaining_data_length_ && current_frame_flags_ & DATA_FLAG_FIN) { | |
| 1915 visitor_->OnStreamFrameData(current_frame_stream_id_, NULL, 0, true); | |
| 1916 } | |
| 1917 } | 1916 } |
| 1918 | 1917 |
| 1919 if (remaining_data_length_ == 0) { | 1918 if (remaining_data_length_ == 0) { |
| 1919 // If the FIN flag is set, and there is no more data in this data frame, |
| 1920 // inform the visitor of EOF via a 0-length data frame. |
| 1921 if (current_frame_flags_ & DATA_FLAG_FIN) { |
| 1922 visitor_->OnStreamFrameData(current_frame_stream_id_, NULL, 0, true); |
| 1923 } |
| 1924 |
| 1920 CHANGE_STATE(SPDY_AUTO_RESET); | 1925 CHANGE_STATE(SPDY_AUTO_RESET); |
| 1921 } | 1926 } |
| 1922 return original_len - len; | 1927 return original_len - len; |
| 1923 } | 1928 } |
| 1924 | 1929 |
| 1925 size_t SpdyFramer::ProcessDataFramePayload(const char* data, size_t len) { | 1930 size_t SpdyFramer::ProcessDataFramePayload(const char* data, size_t len) { |
| 1926 size_t original_len = len; | 1931 size_t original_len = len; |
| 1927 if (remaining_data_length_ - remaining_padding_payload_length_ > 0) { | 1932 if (remaining_data_length_ - remaining_padding_payload_length_ > 0) { |
| 1928 size_t amount_to_forward = std::min( | 1933 size_t amount_to_forward = std::min( |
| 1929 remaining_data_length_ - remaining_padding_payload_length_, len); | 1934 remaining_data_length_ - remaining_padding_payload_length_, len); |
| 1930 if (amount_to_forward && state_ != SPDY_IGNORE_REMAINING_PAYLOAD) { | 1935 if (amount_to_forward && state_ != SPDY_IGNORE_REMAINING_PAYLOAD) { |
| 1931 // Only inform the visitor if there is data. | 1936 // Only inform the visitor if there is data. |
| 1932 if (amount_to_forward) { | 1937 if (amount_to_forward) { |
| 1933 visitor_->OnStreamFrameData( | 1938 visitor_->OnStreamFrameData( |
| 1934 current_frame_stream_id_, data, amount_to_forward, false); | 1939 current_frame_stream_id_, data, amount_to_forward, false); |
| 1935 } | 1940 } |
| 1936 } | 1941 } |
| 1937 data += amount_to_forward; | 1942 data += amount_to_forward; |
| 1938 len -= amount_to_forward; | 1943 len -= amount_to_forward; |
| 1939 remaining_data_length_ -= amount_to_forward; | 1944 remaining_data_length_ -= amount_to_forward; |
| 1940 | |
| 1941 // If the FIN flag is set, and there is no more data in this data | |
| 1942 // frame, inform the visitor of EOF via a 0-length data frame. | |
| 1943 if (!remaining_data_length_ && current_frame_flags_ & DATA_FLAG_FIN) { | |
| 1944 visitor_->OnStreamFrameData(current_frame_stream_id_, NULL, 0, true); | |
| 1945 } | |
| 1946 } | 1945 } |
| 1947 | 1946 |
| 1948 if (remaining_data_length_ == remaining_padding_payload_length_) { | 1947 if (remaining_data_length_ == remaining_padding_payload_length_) { |
| 1949 CHANGE_STATE(SPDY_CONSUME_PADDING); | 1948 CHANGE_STATE(SPDY_CONSUME_PADDING); |
| 1950 } | 1949 } |
| 1951 return original_len - len; | 1950 return original_len - len; |
| 1952 } | 1951 } |
| 1953 | 1952 |
| 1953 size_t SpdyFramer::ProcessIgnoredControlFramePayload(/*const char* data,*/ |
| 1954 size_t len) { |
| 1955 size_t original_len = len; |
| 1956 if (remaining_data_length_ > 0) { |
| 1957 size_t amount_to_ignore = std::min(remaining_data_length_, len); |
| 1958 len -= amount_to_ignore; |
| 1959 remaining_data_length_ -= amount_to_ignore; |
| 1960 } |
| 1961 |
| 1962 if (remaining_data_length_ == 0) { |
| 1963 CHANGE_STATE(SPDY_AUTO_RESET); |
| 1964 } |
| 1965 return original_len - len; |
| 1966 } |
| 1967 |
| 1954 size_t SpdyFramer::ParseHeaderBlockInBuffer(const char* header_data, | 1968 size_t SpdyFramer::ParseHeaderBlockInBuffer(const char* header_data, |
| 1955 size_t header_length, | 1969 size_t header_length, |
| 1956 SpdyHeaderBlock* block) const { | 1970 SpdyHeaderBlock* block) const { |
| 1957 SpdyFrameReader reader(header_data, header_length); | 1971 SpdyFrameReader reader(header_data, header_length); |
| 1958 | 1972 |
| 1959 // Read number of headers. | 1973 // Read number of headers. |
| 1960 uint32 num_headers; | 1974 uint32 num_headers; |
| 1961 if (protocol_version() <= SPDY2) { | 1975 if (protocol_version() <= SPDY2) { |
| 1962 uint16 temp; | 1976 uint16 temp; |
| 1963 if (!reader.ReadUInt16(&temp)) { | 1977 if (!reader.ReadUInt16(&temp)) { |
| (...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2943 builder->Seek(compressed_size); | 2957 builder->Seek(compressed_size); |
| 2944 builder->RewriteLength(*this); | 2958 builder->RewriteLength(*this); |
| 2945 | 2959 |
| 2946 pre_compress_bytes.Add(uncompressed_len); | 2960 pre_compress_bytes.Add(uncompressed_len); |
| 2947 post_compress_bytes.Add(compressed_size); | 2961 post_compress_bytes.Add(compressed_size); |
| 2948 | 2962 |
| 2949 compressed_frames.Increment(); | 2963 compressed_frames.Increment(); |
| 2950 } | 2964 } |
| 2951 | 2965 |
| 2952 } // namespace net | 2966 } // namespace net |
| OLD | NEW |