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 #ifndef QUICHE_HTTP2_DECODER_PAYLOAD_DECODERS_ALTSVC_PAYLOAD_DECODER_H_ 6 #define QUICHE_HTTP2_DECODER_PAYLOAD_DECODERS_ALTSVC_PAYLOAD_DECODER_H_ 7 8 // Decodes the payload of a ALTSVC frame. 9 10 #include "quiche/http2/decoder/decode_buffer.h" 11 #include "quiche/http2/decoder/decode_status.h" 12 #include "quiche/http2/decoder/frame_decoder_state.h" 13 #include "quiche/http2/http2_structures.h" 14 #include "quiche/common/platform/api/quiche_export.h" 15 16 namespace http2 { 17 namespace test { 18 class AltSvcPayloadDecoderPeer; 19 } // namespace test 20 21 class QUICHE_EXPORT AltSvcPayloadDecoder { 22 public: 23 // States during decoding of a ALTSVC frame. 24 enum class PayloadState { 25 // Start decoding the fixed size structure at the start of an ALTSVC 26 // frame (Http2AltSvcFields). 27 kStartDecodingStruct, 28 29 // Handle the DecodeStatus returned from starting or resuming the 30 // decoding of Http2AltSvcFields. If complete, calls OnAltSvcStart. 31 kMaybeDecodedStruct, 32 33 // Reports the value of the strings (origin and value) of an ALTSVC frame 34 // to the listener. 35 kDecodingStrings, 36 37 // The initial decode buffer wasn't large enough for the Http2AltSvcFields, 38 // so this state resumes the decoding when ResumeDecodingPayload is called 39 // later with a new DecodeBuffer. 40 kResumeDecodingStruct, 41 }; 42 43 // Starts the decoding of a ALTSVC frame's payload, and completes it if the 44 // entire payload is in the provided decode buffer. 45 DecodeStatus StartDecodingPayload(FrameDecoderState* state, DecodeBuffer* db); 46 47 // Resumes decoding a ALTSVC frame's payload that has been split across 48 // decode buffers. 49 DecodeStatus ResumeDecodingPayload(FrameDecoderState* state, 50 DecodeBuffer* db); 51 52 private: 53 friend class test::AltSvcPayloadDecoderPeer; 54 55 // Implements state kDecodingStrings. 56 DecodeStatus DecodeStrings(FrameDecoderState* state, DecodeBuffer* db); 57 58 Http2AltSvcFields altsvc_fields_; 59 PayloadState payload_state_; 60 }; 61 62 } // namespace http2 63 64 #endif // QUICHE_HTTP2_DECODER_PAYLOAD_DECODERS_ALTSVC_PAYLOAD_DECODER_H_ 65