QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/http2/decoder/payload_decoders/window_update_payload_decoder.h" |
| 6 | |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 7 | #include "net/third_party/quiche/src/http2/decoder/decode_buffer.h" |
| 8 | #include "net/third_party/quiche/src/http2/decoder/decode_http2_structures.h" |
| 9 | #include "net/third_party/quiche/src/http2/decoder/http2_frame_decoder_listener.h" |
| 10 | #include "net/third_party/quiche/src/http2/http2_constants.h" |
| 11 | #include "net/third_party/quiche/src/http2/http2_structures.h" |
QUICHE team | 61940b4 | 2019-03-07 23:32:27 -0500 | [diff] [blame] | 12 | #include "net/third_party/quiche/src/http2/platform/api/http2_logging.h" |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 13 | |
| 14 | namespace http2 { |
| 15 | |
| 16 | DecodeStatus WindowUpdatePayloadDecoder::StartDecodingPayload( |
| 17 | FrameDecoderState* state, |
| 18 | DecodeBuffer* db) { |
| 19 | const Http2FrameHeader& frame_header = state->frame_header(); |
| 20 | const uint32_t total_length = frame_header.payload_length; |
| 21 | |
QUICHE team | 61940b4 | 2019-03-07 23:32:27 -0500 | [diff] [blame] | 22 | HTTP2_DVLOG(2) << "WindowUpdatePayloadDecoder::StartDecodingPayload: " |
| 23 | << frame_header; |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 24 | |
| 25 | DCHECK_EQ(Http2FrameType::WINDOW_UPDATE, frame_header.type); |
| 26 | DCHECK_LE(db->Remaining(), total_length); |
| 27 | |
| 28 | // WINDOW_UPDATE frames have no flags. |
| 29 | DCHECK_EQ(0, frame_header.flags); |
| 30 | |
| 31 | // Special case for when the payload is the correct size and entirely in |
| 32 | // the buffer. |
| 33 | if (db->Remaining() == Http2WindowUpdateFields::EncodedSize() && |
| 34 | total_length == Http2WindowUpdateFields::EncodedSize()) { |
| 35 | DoDecode(&window_update_fields_, db); |
| 36 | state->listener()->OnWindowUpdate( |
| 37 | frame_header, window_update_fields_.window_size_increment); |
| 38 | return DecodeStatus::kDecodeDone; |
| 39 | } |
| 40 | state->InitializeRemainders(); |
| 41 | return HandleStatus(state, state->StartDecodingStructureInPayload( |
| 42 | &window_update_fields_, db)); |
| 43 | } |
| 44 | |
| 45 | DecodeStatus WindowUpdatePayloadDecoder::ResumeDecodingPayload( |
| 46 | FrameDecoderState* state, |
| 47 | DecodeBuffer* db) { |
QUICHE team | 61940b4 | 2019-03-07 23:32:27 -0500 | [diff] [blame] | 48 | HTTP2_DVLOG(2) << "ResumeDecodingPayload: remaining_payload=" |
| 49 | << state->remaining_payload() |
| 50 | << "; db->Remaining=" << db->Remaining(); |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 51 | DCHECK_EQ(Http2FrameType::WINDOW_UPDATE, state->frame_header().type); |
| 52 | DCHECK_LE(db->Remaining(), state->frame_header().payload_length); |
| 53 | return HandleStatus(state, state->ResumeDecodingStructureInPayload( |
| 54 | &window_update_fields_, db)); |
| 55 | } |
| 56 | |
| 57 | DecodeStatus WindowUpdatePayloadDecoder::HandleStatus(FrameDecoderState* state, |
| 58 | DecodeStatus status) { |
QUICHE team | 61940b4 | 2019-03-07 23:32:27 -0500 | [diff] [blame] | 59 | HTTP2_DVLOG(2) << "HandleStatus: status=" << status |
| 60 | << "; remaining_payload=" << state->remaining_payload(); |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 61 | if (status == DecodeStatus::kDecodeDone) { |
| 62 | if (state->remaining_payload() == 0) { |
| 63 | state->listener()->OnWindowUpdate( |
| 64 | state->frame_header(), window_update_fields_.window_size_increment); |
| 65 | return DecodeStatus::kDecodeDone; |
| 66 | } |
| 67 | // Payload is too long. |
| 68 | return state->ReportFrameSizeError(); |
| 69 | } |
| 70 | // Not done decoding the structure. Either we've got more payload to decode, |
| 71 | // or we've run out because the payload is too short, in which case |
| 72 | // OnFrameSizeError will have already been called. |
| 73 | DCHECK( |
| 74 | (status == DecodeStatus::kDecodeInProgress && |
| 75 | state->remaining_payload() > 0) || |
| 76 | (status == DecodeStatus::kDecodeError && state->remaining_payload() == 0)) |
| 77 | << "\n status=" << status |
| 78 | << "; remaining_payload=" << state->remaining_payload(); |
| 79 | return status; |
| 80 | } |
| 81 | |
| 82 | } // namespace http2 |