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 "quiche/http2/decoder/payload_decoders/window_update_payload_decoder.h"
6
7 #include "quiche/http2/decoder/decode_buffer.h"
8 #include "quiche/http2/decoder/decode_http2_structures.h"
9 #include "quiche/http2/decoder/http2_frame_decoder_listener.h"
10 #include "quiche/http2/http2_constants.h"
11 #include "quiche/http2/http2_structures.h"
12 #include "quiche/common/platform/api/quiche_logging.h"
13
14 namespace http2 {
15
StartDecodingPayload(FrameDecoderState * state,DecodeBuffer * db)16 DecodeStatus WindowUpdatePayloadDecoder::StartDecodingPayload(
17 FrameDecoderState* state, DecodeBuffer* db) {
18 const Http2FrameHeader& frame_header = state->frame_header();
19 const uint32_t total_length = frame_header.payload_length;
20
21 QUICHE_DVLOG(2) << "WindowUpdatePayloadDecoder::StartDecodingPayload: "
22 << frame_header;
23
24 QUICHE_DCHECK_EQ(Http2FrameType::WINDOW_UPDATE, frame_header.type);
25 QUICHE_DCHECK_LE(db->Remaining(), total_length);
26
27 // WINDOW_UPDATE frames have no flags.
28 QUICHE_DCHECK_EQ(0, frame_header.flags);
29
30 // Special case for when the payload is the correct size and entirely in
31 // the buffer.
32 if (db->Remaining() == Http2WindowUpdateFields::EncodedSize() &&
33 total_length == Http2WindowUpdateFields::EncodedSize()) {
34 DoDecode(&window_update_fields_, db);
35 state->listener()->OnWindowUpdate(
36 frame_header, window_update_fields_.window_size_increment);
37 return DecodeStatus::kDecodeDone;
38 }
39 state->InitializeRemainders();
40 return HandleStatus(state, state->StartDecodingStructureInPayload(
41 &window_update_fields_, db));
42 }
43
ResumeDecodingPayload(FrameDecoderState * state,DecodeBuffer * db)44 DecodeStatus WindowUpdatePayloadDecoder::ResumeDecodingPayload(
45 FrameDecoderState* state, DecodeBuffer* db) {
46 QUICHE_DVLOG(2) << "ResumeDecodingPayload: remaining_payload="
47 << state->remaining_payload()
48 << "; db->Remaining=" << db->Remaining();
49 QUICHE_DCHECK_EQ(Http2FrameType::WINDOW_UPDATE, state->frame_header().type);
50 QUICHE_DCHECK_LE(db->Remaining(), state->frame_header().payload_length);
51 return HandleStatus(state, state->ResumeDecodingStructureInPayload(
52 &window_update_fields_, db));
53 }
54
HandleStatus(FrameDecoderState * state,DecodeStatus status)55 DecodeStatus WindowUpdatePayloadDecoder::HandleStatus(FrameDecoderState* state,
56 DecodeStatus status) {
57 QUICHE_DVLOG(2) << "HandleStatus: status=" << status
58 << "; remaining_payload=" << state->remaining_payload();
59 if (status == DecodeStatus::kDecodeDone) {
60 if (state->remaining_payload() == 0) {
61 state->listener()->OnWindowUpdate(
62 state->frame_header(), window_update_fields_.window_size_increment);
63 return DecodeStatus::kDecodeDone;
64 }
65 // Payload is too long.
66 return state->ReportFrameSizeError();
67 }
68 // Not done decoding the structure. Either we've got more payload to decode,
69 // or we've run out because the payload is too short, in which case
70 // OnFrameSizeError will have already been called.
71 QUICHE_DCHECK(
72 (status == DecodeStatus::kDecodeInProgress &&
73 state->remaining_payload() > 0) ||
74 (status == DecodeStatus::kDecodeError && state->remaining_payload() == 0))
75 << "\n status=" << status
76 << "; remaining_payload=" << state->remaining_payload();
77 return status;
78 }
79
80 } // namespace http2
81