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/rst_stream_payload_decoder.h"
6
7 #include "quiche/http2/decoder/decode_buffer.h"
8 #include "quiche/http2/decoder/http2_frame_decoder_listener.h"
9 #include "quiche/http2/http2_constants.h"
10 #include "quiche/http2/http2_structures.h"
11 #include "quiche/common/platform/api/quiche_logging.h"
12
13 namespace http2 {
14
StartDecodingPayload(FrameDecoderState * state,DecodeBuffer * db)15 DecodeStatus RstStreamPayloadDecoder::StartDecodingPayload(
16 FrameDecoderState* state, DecodeBuffer* db) {
17 QUICHE_DVLOG(2) << "RstStreamPayloadDecoder::StartDecodingPayload: "
18 << state->frame_header();
19 QUICHE_DCHECK_EQ(Http2FrameType::RST_STREAM, state->frame_header().type);
20 QUICHE_DCHECK_LE(db->Remaining(), state->frame_header().payload_length);
21 // RST_STREAM has no flags.
22 QUICHE_DCHECK_EQ(0, state->frame_header().flags);
23 state->InitializeRemainders();
24 return HandleStatus(
25 state, state->StartDecodingStructureInPayload(&rst_stream_fields_, db));
26 }
27
ResumeDecodingPayload(FrameDecoderState * state,DecodeBuffer * db)28 DecodeStatus RstStreamPayloadDecoder::ResumeDecodingPayload(
29 FrameDecoderState* state, DecodeBuffer* db) {
30 QUICHE_DVLOG(2) << "RstStreamPayloadDecoder::ResumeDecodingPayload"
31 << " remaining_payload=" << state->remaining_payload()
32 << " db->Remaining=" << db->Remaining();
33 QUICHE_DCHECK_EQ(Http2FrameType::RST_STREAM, state->frame_header().type);
34 QUICHE_DCHECK_LE(db->Remaining(), state->frame_header().payload_length);
35 return HandleStatus(
36 state, state->ResumeDecodingStructureInPayload(&rst_stream_fields_, db));
37 }
38
HandleStatus(FrameDecoderState * state,DecodeStatus status)39 DecodeStatus RstStreamPayloadDecoder::HandleStatus(FrameDecoderState* state,
40 DecodeStatus status) {
41 QUICHE_DVLOG(2) << "HandleStatus: status=" << status
42 << "; remaining_payload=" << state->remaining_payload();
43 if (status == DecodeStatus::kDecodeDone) {
44 if (state->remaining_payload() == 0) {
45 state->listener()->OnRstStream(state->frame_header(),
46 rst_stream_fields_.error_code);
47 return DecodeStatus::kDecodeDone;
48 }
49 // Payload is too long.
50 return state->ReportFrameSizeError();
51 }
52 // Not done decoding the structure. Either we've got more payload to decode,
53 // or we've run out because the payload is too short, in which case
54 // OnFrameSizeError will have already been called by the FrameDecoderState.
55 QUICHE_DCHECK(
56 (status == DecodeStatus::kDecodeInProgress &&
57 state->remaining_payload() > 0) ||
58 (status == DecodeStatus::kDecodeError && state->remaining_payload() == 0))
59 << "\n status=" << status
60 << "; remaining_payload=" << state->remaining_payload();
61 return status;
62 }
63
64 } // namespace http2
65