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/settings_payload_decoder.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "net/http2/decoder/decode_buffer.h" | |
9 #include "net/http2/decoder/http2_frame_decoder_listener.h" | |
10 #include "net/http2/http2_constants.h" | |
11 #include "net/http2/http2_structures.h" | |
12 | |
13 namespace net { | |
14 | |
15 DecodeStatus SettingsPayloadDecoder::StartDecodingPayload( | |
16 FrameDecoderState* state, | |
17 DecodeBuffer* db) { | |
18 const Http2FrameHeader& frame_header = state->frame_header(); | |
19 const uint32_t total_length = frame_header.payload_length; | |
20 | |
21 DVLOG(2) << "SettingsPayloadDecoder::StartDecodingPayload: " << frame_header; | |
22 DCHECK_EQ(Http2FrameType::SETTINGS, frame_header.type); | |
23 DCHECK_LE(db->Remaining(), total_length); | |
24 DCHECK_EQ(0, frame_header.flags & ~(Http2FrameFlag::FLAG_ACK)); | |
25 | |
26 if (frame_header.IsAck()) { | |
27 if (total_length == 0) { | |
28 state->listener()->OnSettingsAck(frame_header); | |
29 return DecodeStatus::kDecodeDone; | |
30 } else { | |
31 state->InitializeRemainders(); | |
32 return state->ReportFrameSizeError(); | |
33 } | |
34 } else { | |
35 state->InitializeRemainders(); | |
36 state->listener()->OnSettingsStart(frame_header); | |
37 return StartDecodingSettings(state, db); | |
38 } | |
39 } | |
40 | |
41 DecodeStatus SettingsPayloadDecoder::ResumeDecodingPayload( | |
42 FrameDecoderState* state, | |
43 DecodeBuffer* db) { | |
44 DVLOG(2) << "SettingsPayloadDecoder::ResumeDecodingPayload" | |
45 << " remaining_payload=" << state->remaining_payload() | |
46 << " db->Remaining=" << db->Remaining(); | |
47 DCHECK_EQ(Http2FrameType::SETTINGS, state->frame_header().type); | |
48 DCHECK_LE(db->Remaining(), state->frame_header().payload_length); | |
49 | |
50 DecodeStatus status = | |
51 state->ResumeDecodingStructureInPayload(&setting_fields_, db); | |
52 if (status == DecodeStatus::kDecodeDone) { | |
53 state->listener()->OnSetting(setting_fields_); | |
54 return StartDecodingSettings(state, db); | |
55 } | |
56 return HandleNotDone(state, db, status); | |
57 } | |
58 | |
59 DecodeStatus SettingsPayloadDecoder::StartDecodingSettings( | |
60 FrameDecoderState* state, | |
61 DecodeBuffer* db) { | |
62 DVLOG(2) << "SettingsPayloadDecoder::StartDecodingSettings" | |
63 << " remaining_payload=" << state->remaining_payload() | |
64 << " db->Remaining=" << db->Remaining(); | |
65 while (state->remaining_payload() > 0) { | |
66 DecodeStatus status = | |
67 state->StartDecodingStructureInPayload(&setting_fields_, db); | |
68 if (status == DecodeStatus::kDecodeDone) { | |
69 state->listener()->OnSetting(setting_fields_); | |
70 continue; | |
71 } | |
72 return HandleNotDone(state, db, status); | |
73 } | |
74 DVLOG(2) << "LEAVING SettingsPayloadDecoder::StartDecodingSettings" | |
75 << "\n\tdb->Remaining=" << db->Remaining() | |
76 << "\n\t remaining_payload=" << state->remaining_payload(); | |
77 state->listener()->OnSettingsEnd(); | |
78 return DecodeStatus::kDecodeDone; | |
79 } | |
80 | |
81 DecodeStatus SettingsPayloadDecoder::HandleNotDone(FrameDecoderState* state, | |
82 DecodeBuffer* db, | |
83 DecodeStatus status) { | |
84 // Not done decoding the structure. Either we've got more payload to decode, | |
85 // or we've run out because the payload is too short, in which case | |
86 // OnFrameSizeError will have already been called. | |
87 DCHECK( | |
88 (status == DecodeStatus::kDecodeInProgress && | |
89 state->remaining_payload() > 0) || | |
90 (status == DecodeStatus::kDecodeError && state->remaining_payload() == 0)) | |
91 << "\n status=" << status | |
92 << "; remaining_payload=" << state->remaining_payload() | |
93 << "; db->Remaining=" << db->Remaining(); | |
94 return status; | |
95 } | |
96 | |
97 } // namespace net | |
OLD | NEW |