OLD | NEW |
(Empty) | |
| 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 "net/http2/decoder/payload_decoders/goaway_payload_decoder.h" |
| 6 |
| 7 #include <stddef.h> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "base/macros.h" |
| 11 #include "net/http2/decoder/decode_buffer.h" |
| 12 #include "net/http2/decoder/http2_frame_decoder_listener.h" |
| 13 #include "net/http2/http2_constants.h" |
| 14 #include "net/http2/http2_structures.h" |
| 15 #include "net/http2/tools/http2_bug_tracker.h" |
| 16 |
| 17 namespace net { |
| 18 |
| 19 std::ostream& operator<<(std::ostream& out, |
| 20 GoAwayPayloadDecoder::PayloadState v) { |
| 21 switch (v) { |
| 22 case GoAwayPayloadDecoder::PayloadState::kStartDecodingFixedFields: |
| 23 return out << "kStartDecodingFixedFields"; |
| 24 case GoAwayPayloadDecoder::PayloadState::kHandleFixedFieldsStatus: |
| 25 return out << "kHandleFixedFieldsStatus"; |
| 26 case GoAwayPayloadDecoder::PayloadState::kReadOpaqueData: |
| 27 return out << "kReadOpaqueData"; |
| 28 case GoAwayPayloadDecoder::PayloadState::kResumeDecodingFixedFields: |
| 29 return out << "kResumeDecodingFixedFields"; |
| 30 } |
| 31 |
| 32 NOTREACHED(); |
| 33 return out; |
| 34 } |
| 35 |
| 36 DecodeStatus GoAwayPayloadDecoder::StartDecodingPayload( |
| 37 FrameDecoderState* state, |
| 38 DecodeBuffer* db) { |
| 39 DVLOG(2) << "GoAwayPayloadDecoder::StartDecodingPayload: " |
| 40 << state->frame_header(); |
| 41 DCHECK_EQ(Http2FrameType::GOAWAY, state->frame_header().type); |
| 42 DCHECK_LE(db->Remaining(), state->frame_header().payload_length); |
| 43 DCHECK_EQ(0, state->frame_header().flags); |
| 44 |
| 45 state->InitializeRemainders(); |
| 46 payload_state_ = PayloadState::kStartDecodingFixedFields; |
| 47 return ResumeDecodingPayload(state, db); |
| 48 } |
| 49 |
| 50 DecodeStatus GoAwayPayloadDecoder::ResumeDecodingPayload( |
| 51 FrameDecoderState* state, |
| 52 DecodeBuffer* db) { |
| 53 DVLOG(2) << "GoAwayPayloadDecoder::ResumeDecodingPayload: remaining_payload=" |
| 54 << state->remaining_payload() |
| 55 << ", db->Remaining=" << db->Remaining(); |
| 56 |
| 57 const Http2FrameHeader& frame_header = state->frame_header(); |
| 58 DCHECK_EQ(Http2FrameType::GOAWAY, frame_header.type); |
| 59 DCHECK_LE(db->Remaining(), frame_header.payload_length); |
| 60 DCHECK_NE(PayloadState::kHandleFixedFieldsStatus, payload_state_); |
| 61 |
| 62 // |status| has to be initialized to some value to avoid compiler error in |
| 63 // case PayloadState::kHandleFixedFieldsStatus below, but value does not |
| 64 // matter, see DCHECK_NE above. |
| 65 DecodeStatus status = DecodeStatus::kDecodeError; |
| 66 size_t avail; |
| 67 while (true) { |
| 68 DVLOG(2) << "GoAwayPayloadDecoder::ResumeDecodingPayload payload_state_=" |
| 69 << payload_state_; |
| 70 switch (payload_state_) { |
| 71 case PayloadState::kStartDecodingFixedFields: |
| 72 status = state->StartDecodingStructureInPayload(&goaway_fields_, db); |
| 73 // FALLTHROUGH_INTENDED |
| 74 |
| 75 case PayloadState::kHandleFixedFieldsStatus: |
| 76 if (status == DecodeStatus::kDecodeDone) { |
| 77 state->listener()->OnGoAwayStart(frame_header, goaway_fields_); |
| 78 } else { |
| 79 // Not done decoding the structure. Either we've got more payload |
| 80 // to decode, or we've run out because the payload is too short, |
| 81 // in which case OnFrameSizeError will have already been called. |
| 82 DCHECK((status == DecodeStatus::kDecodeInProgress && |
| 83 state->remaining_payload() > 0) || |
| 84 (status == DecodeStatus::kDecodeError && |
| 85 state->remaining_payload() == 0)) |
| 86 << "\n status=" << status |
| 87 << "; remaining_payload=" << state->remaining_payload(); |
| 88 payload_state_ = PayloadState::kResumeDecodingFixedFields; |
| 89 return status; |
| 90 } |
| 91 // FALLTHROUGH_INTENDED |
| 92 |
| 93 case PayloadState::kReadOpaqueData: |
| 94 // The opaque data is all the remains to be decoded, so anything left |
| 95 // in the decode buffer is opaque data. |
| 96 avail = db->Remaining(); |
| 97 if (avail > 0) { |
| 98 state->listener()->OnGoAwayOpaqueData(db->cursor(), avail); |
| 99 db->AdvanceCursor(avail); |
| 100 state->ConsumePayload(avail); |
| 101 } |
| 102 if (state->remaining_payload() > 0) { |
| 103 payload_state_ = PayloadState::kReadOpaqueData; |
| 104 return DecodeStatus::kDecodeInProgress; |
| 105 } |
| 106 state->listener()->OnGoAwayEnd(); |
| 107 return DecodeStatus::kDecodeDone; |
| 108 |
| 109 case PayloadState::kResumeDecodingFixedFields: |
| 110 status = state->ResumeDecodingStructureInPayload(&goaway_fields_, db); |
| 111 payload_state_ = PayloadState::kHandleFixedFieldsStatus; |
| 112 continue; |
| 113 } |
| 114 HTTP2_BUG << "PayloadState: " << payload_state_; |
| 115 } |
| 116 } |
| 117 |
| 118 } // namespace net |
OLD | NEW |