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/priority_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 PriorityPayloadDecoder::StartDecodingPayload(
16 FrameDecoderState* state, DecodeBuffer* db) {
17 QUICHE_DVLOG(2) << "PriorityPayloadDecoder::StartDecodingPayload: "
18 << state->frame_header();
19 QUICHE_DCHECK_EQ(Http2FrameType::PRIORITY, state->frame_header().type);
20 QUICHE_DCHECK_LE(db->Remaining(), state->frame_header().payload_length);
21 // PRIORITY frames have no flags.
22 QUICHE_DCHECK_EQ(0, state->frame_header().flags);
23 state->InitializeRemainders();
24 return HandleStatus(
25 state, state->StartDecodingStructureInPayload(&priority_fields_, db));
26 }
27
ResumeDecodingPayload(FrameDecoderState * state,DecodeBuffer * db)28 DecodeStatus PriorityPayloadDecoder::ResumeDecodingPayload(
29 FrameDecoderState* state, DecodeBuffer* db) {
30 QUICHE_DVLOG(2) << "PriorityPayloadDecoder::ResumeDecodingPayload"
31 << " remaining_payload=" << state->remaining_payload()
32 << " db->Remaining=" << db->Remaining();
33 QUICHE_DCHECK_EQ(Http2FrameType::PRIORITY, state->frame_header().type);
34 QUICHE_DCHECK_LE(db->Remaining(), state->frame_header().payload_length);
35 return HandleStatus(
36 state, state->ResumeDecodingStructureInPayload(&priority_fields_, db));
37 }
38
HandleStatus(FrameDecoderState * state,DecodeStatus status)39 DecodeStatus PriorityPayloadDecoder::HandleStatus(FrameDecoderState* state,
40 DecodeStatus status) {
41 if (status == DecodeStatus::kDecodeDone) {
42 if (state->remaining_payload() == 0) {
43 state->listener()->OnPriorityFrame(state->frame_header(),
44 priority_fields_);
45 return DecodeStatus::kDecodeDone;
46 }
47 // Payload is too long.
48 return state->ReportFrameSizeError();
49 }
50 // Not done decoding the structure. Either we've got more payload to decode,
51 // or we've run out because the payload is too short, in which case
52 // OnFrameSizeError will have already been called.
53 QUICHE_DCHECK(
54 (status == DecodeStatus::kDecodeInProgress &&
55 state->remaining_payload() > 0) ||
56 (status == DecodeStatus::kDecodeError && state->remaining_payload() == 0))
57 << "\n status=" << status
58 << "; remaining_payload=" << state->remaining_payload();
59 return status;
60 }
61
62 } // namespace http2
63