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/unknown_payload_decoder.h" 6 7 #include <stddef.h> 8 9 #include "quiche/http2/decoder/decode_buffer.h" 10 #include "quiche/http2/decoder/http2_frame_decoder_listener.h" 11 #include "quiche/http2/http2_constants.h" 12 #include "quiche/http2/http2_structures.h" 13 #include "quiche/common/platform/api/quiche_logging.h" 14 15 namespace http2 { 16 StartDecodingPayload(FrameDecoderState * state,DecodeBuffer * db)17DecodeStatus UnknownPayloadDecoder::StartDecodingPayload( 18 FrameDecoderState* state, DecodeBuffer* db) { 19 const Http2FrameHeader& frame_header = state->frame_header(); 20 21 QUICHE_DVLOG(2) << "UnknownPayloadDecoder::StartDecodingPayload: " 22 << frame_header; 23 QUICHE_DCHECK(!IsSupportedHttp2FrameType(frame_header.type)) << frame_header; 24 QUICHE_DCHECK_LE(db->Remaining(), frame_header.payload_length); 25 26 state->InitializeRemainders(); 27 state->listener()->OnUnknownStart(frame_header); 28 return ResumeDecodingPayload(state, db); 29 } 30 ResumeDecodingPayload(FrameDecoderState * state,DecodeBuffer * db)31DecodeStatus UnknownPayloadDecoder::ResumeDecodingPayload( 32 FrameDecoderState* state, DecodeBuffer* db) { 33 QUICHE_DVLOG(2) << "UnknownPayloadDecoder::ResumeDecodingPayload " 34 << "remaining_payload=" << state->remaining_payload() 35 << "; db->Remaining=" << db->Remaining(); 36 QUICHE_DCHECK(!IsSupportedHttp2FrameType(state->frame_header().type)) 37 << state->frame_header(); 38 QUICHE_DCHECK_LE(state->remaining_payload(), 39 state->frame_header().payload_length); 40 QUICHE_DCHECK_LE(db->Remaining(), state->remaining_payload()); 41 42 size_t avail = db->Remaining(); 43 if (avail > 0) { 44 state->listener()->OnUnknownPayload(db->cursor(), avail); 45 db->AdvanceCursor(avail); 46 state->ConsumePayload(avail); 47 } 48 if (state->remaining_payload() == 0) { 49 state->listener()->OnUnknownEnd(); 50 return DecodeStatus::kDecodeDone; 51 } 52 return DecodeStatus::kDecodeInProgress; 53 } 54 55 } // namespace http2 56