| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't | 5 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't |
| 6 // constantly adding and subtracting header sizes; this is ugly and error- | 6 // constantly adding and subtracting header sizes; this is ugly and error- |
| 7 // prone. | 7 // prone. |
| 8 | 8 |
| 9 #include "net/spdy/spdy_framer.h" | 9 #include "net/spdy/spdy_framer.h" |
| 10 | 10 |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 /* static */ | 843 /* static */ |
| 844 bool SpdyFramer::ParseCredentialData(const char* data, size_t len, | 844 bool SpdyFramer::ParseCredentialData(const char* data, size_t len, |
| 845 SpdyCredential* credential) { | 845 SpdyCredential* credential) { |
| 846 DCHECK(credential); | 846 DCHECK(credential); |
| 847 | 847 |
| 848 void* iter = NULL; | 848 void* iter = NULL; |
| 849 SpdyFrameBuilder parser(data, len); | 849 SpdyFrameBuilder parser(data, len); |
| 850 if (!parser.ReadUInt16(&iter, &credential->slot)) | 850 if (!parser.ReadUInt16(&iter, &credential->slot)) |
| 851 return false; | 851 return false; |
| 852 | 852 |
| 853 uint16 origin_len; | |
| 854 const char* origin_data; | |
| 855 if (!parser.ReadData(&iter, &origin_data, &origin_len)) | |
| 856 return false; | |
| 857 credential->origin.assign(origin_data, origin_len); | |
| 858 | |
| 859 uint32 proof_len; | 853 uint32 proof_len; |
| 860 const char* proof_data; | 854 const char* proof_data; |
| 861 if (!parser.ReadReadLen32PrefixedData(&iter, &proof_data, &proof_len)) | 855 if (!parser.ReadReadLen32PrefixedData(&iter, &proof_data, &proof_len)) |
| 862 return false; | 856 return false; |
| 863 credential->proof.assign(proof_data, proof_len); | 857 credential->proof.assign(proof_data, proof_len); |
| 864 | 858 |
| 865 while (parser.IteratorHasRoomFor(iter, 1)) { | 859 while (parser.IteratorHasRoomFor(iter, 1)) { |
| 866 uint32 cert_len; | 860 uint32 cert_len; |
| 867 const char* cert_data; | 861 const char* cert_data; |
| 868 if (!parser.ReadReadLen32PrefixedData(&iter, &cert_data, &cert_len)) | 862 if (!parser.ReadReadLen32PrefixedData(&iter, &cert_data, &cert_len)) |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 frame.WriteUInt32(delta_window_size); | 1055 frame.WriteUInt32(delta_window_size); |
| 1062 return reinterpret_cast<SpdyWindowUpdateControlFrame*>(frame.take()); | 1056 return reinterpret_cast<SpdyWindowUpdateControlFrame*>(frame.take()); |
| 1063 } | 1057 } |
| 1064 | 1058 |
| 1065 /* static */ | 1059 /* static */ |
| 1066 SpdyCredentialControlFrame* SpdyFramer::CreateCredentialFrame( | 1060 SpdyCredentialControlFrame* SpdyFramer::CreateCredentialFrame( |
| 1067 const SpdyCredential& credential) { | 1061 const SpdyCredential& credential) { |
| 1068 // Calculate the size of the frame by adding the size of the | 1062 // Calculate the size of the frame by adding the size of the |
| 1069 // variable length data to the size of the fixed length data. | 1063 // variable length data to the size of the fixed length data. |
| 1070 size_t frame_size = SpdyCredentialControlFrame::size() + | 1064 size_t frame_size = SpdyCredentialControlFrame::size() + |
| 1071 credential.origin.length() + credential.proof.length(); | 1065 credential.proof.length(); |
| 1072 DCHECK_EQ(SpdyCredentialControlFrame::size(), 16u); | 1066 DCHECK_EQ(SpdyCredentialControlFrame::size(), 14u); |
| 1073 for (vector<std::string>::const_iterator cert = credential.certs.begin(); | 1067 for (vector<std::string>::const_iterator cert = credential.certs.begin(); |
| 1074 cert != credential.certs.end(); | 1068 cert != credential.certs.end(); |
| 1075 cert++) { | 1069 cert++) { |
| 1076 frame_size += sizeof(uint32); // size of the cert_length field | 1070 frame_size += sizeof(uint32); // size of the cert_length field |
| 1077 frame_size += cert->length(); // size of the cert_data field | 1071 frame_size += cert->length(); // size of the cert_data field |
| 1078 } | 1072 } |
| 1079 size_t payload_size = frame_size - SpdyFrame::kHeaderSize; | 1073 size_t payload_size = frame_size - SpdyFrame::kHeaderSize; |
| 1080 | 1074 |
| 1081 SpdyFrameBuilder frame(frame_size); | 1075 SpdyFrameBuilder frame(frame_size); |
| 1082 // Create our FlagsAndLength. | 1076 // Create our FlagsAndLength. |
| 1083 SpdyControlFlags flags = spdy::CONTROL_FLAG_NONE; | 1077 SpdyControlFlags flags = spdy::CONTROL_FLAG_NONE; |
| 1084 FlagsAndLength flags_length = CreateFlagsAndLength(flags, payload_size); | 1078 FlagsAndLength flags_length = CreateFlagsAndLength(flags, payload_size); |
| 1085 | 1079 |
| 1086 frame.WriteUInt16(kControlFlagMask | spdy_version_); | 1080 frame.WriteUInt16(kControlFlagMask | spdy_version_); |
| 1087 frame.WriteUInt16(CREDENTIAL); | 1081 frame.WriteUInt16(CREDENTIAL); |
| 1088 frame.WriteBytes(&flags_length, sizeof(flags_length)); | 1082 frame.WriteBytes(&flags_length, sizeof(flags_length)); |
| 1089 frame.WriteUInt16(credential.slot); | 1083 frame.WriteUInt16(credential.slot); |
| 1090 frame.WriteUInt16(credential.origin.size()); | |
| 1091 frame.WriteBytes(credential.origin.c_str(), credential.origin.size()); | |
| 1092 frame.WriteUInt32(credential.proof.size()); | 1084 frame.WriteUInt32(credential.proof.size()); |
| 1093 frame.WriteBytes(credential.proof.c_str(), credential.proof.size()); | 1085 frame.WriteBytes(credential.proof.c_str(), credential.proof.size()); |
| 1094 for (vector<std::string>::const_iterator cert = credential.certs.begin(); | 1086 for (vector<std::string>::const_iterator cert = credential.certs.begin(); |
| 1095 cert != credential.certs.end(); | 1087 cert != credential.certs.end(); |
| 1096 cert++) { | 1088 cert++) { |
| 1097 frame.WriteUInt32(cert->length()); | 1089 frame.WriteUInt32(cert->length()); |
| 1098 frame.WriteBytes(cert->c_str(), cert->length()); | 1090 frame.WriteBytes(cert->c_str(), cert->length()); |
| 1099 } | 1091 } |
| 1100 return reinterpret_cast<SpdyCredentialControlFrame*>(frame.take()); | 1092 return reinterpret_cast<SpdyCredentialControlFrame*>(frame.take()); |
| 1101 } | 1093 } |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1722 | 1714 |
| 1723 void SpdyFramer::set_enable_compression_default(bool value) { | 1715 void SpdyFramer::set_enable_compression_default(bool value) { |
| 1724 compression_default_ = value; | 1716 compression_default_ = value; |
| 1725 } | 1717 } |
| 1726 | 1718 |
| 1727 void SpdyFramer::set_validate_control_frame_sizes(bool value) { | 1719 void SpdyFramer::set_validate_control_frame_sizes(bool value) { |
| 1728 validate_control_frame_sizes_ = value; | 1720 validate_control_frame_sizes_ = value; |
| 1729 } | 1721 } |
| 1730 | 1722 |
| 1731 } // namespace spdy | 1723 } // namespace spdy |
| OLD | NEW |