diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-11-20 15:06:40 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-11-22 11:48:58 +0000 |
commit | daa093eea7c773db06799a13bd7e4e2e2a9f8f14 (patch) | |
tree | 96cc5e7b9194c1b29eab927730bfa419e7111c25 /chromium/net/dns/record_rdata.cc | |
parent | be59a35641616a4cf23c4a13fa0632624b021c1b (diff) | |
download | qtwebengine-chromium-daa093eea7c773db06799a13bd7e4e2e2a9f8f14.tar.gz |
BASELINE: Update Chromium to 63.0.3239.58
Change-Id: Ia93b322a00ba4dd4004f3bcf1254063ba90e1605
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/net/dns/record_rdata.cc')
-rw-r--r-- | chromium/net/dns/record_rdata.cc | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/chromium/net/dns/record_rdata.cc b/chromium/net/dns/record_rdata.cc index ff9434b489e..9282b0ed2f7 100644 --- a/chromium/net/dns/record_rdata.cc +++ b/chromium/net/dns/record_rdata.cc @@ -4,6 +4,8 @@ #include "net/dns/record_rdata.h" +#include <numeric> + #include "base/big_endian.h" #include "net/dns/dns_protocol.h" #include "net/dns/dns_response.h" @@ -276,4 +278,66 @@ bool NsecRecordRdata::GetBit(unsigned i) const { return (bitmap_[byte_num] & (1 << bit_num)) != 0; } +OptRecordRdata::OptRecordRdata() {} + +OptRecordRdata::~OptRecordRdata() {} + +// static +std::unique_ptr<OptRecordRdata> OptRecordRdata::Create( + const base::StringPiece& data, + const DnsRecordParser& parser) { + std::unique_ptr<OptRecordRdata> rdata(new OptRecordRdata); + rdata->buf_.assign(data.begin(), data.end()); + + base::BigEndianReader reader(data.data(), data.size()); + while (reader.remaining() > 0) { + uint16_t opt_code, opt_data_size; + base::StringPiece opt_data; + + if (!(reader.ReadU16(&opt_code) && reader.ReadU16(&opt_data_size) && + reader.ReadPiece(&opt_data, opt_data_size))) { + return std::unique_ptr<OptRecordRdata>(); + } + rdata->opts_.push_back(Opt(opt_code, opt_data)); + } + + return rdata; +} + +uint16_t OptRecordRdata::Type() const { + return OptRecordRdata::kType; +} + +bool OptRecordRdata::IsEqual(const RecordRdata* other) const { + if (other->Type() != Type()) + return false; + const OptRecordRdata* opt_other = static_cast<const OptRecordRdata*>(other); + return opt_other->opts_ == opts_; +} + +void OptRecordRdata::AddOpt(const Opt& opt) { + base::StringPiece opt_data = opt.data(); + + // Resize buffer to accommodate new OPT. + const size_t orig_rdata_size = buf_.size(); + buf_.resize(orig_rdata_size + Opt::kHeaderSize + opt_data.size()); + + // Start writing from the end of the existing rdata. + base::BigEndianWriter writer(buf_.data() + orig_rdata_size, buf_.size()); + bool success = writer.WriteU16(opt.code()) && + writer.WriteU16(opt_data.size()) && + writer.WriteBytes(opt_data.data(), opt_data.size()); + DCHECK(success); + + opts_.push_back(opt); +} + +OptRecordRdata::Opt::Opt(uint16_t code, base::StringPiece data) : code_(code) { + data.CopyToString(&data_); +} + +bool OptRecordRdata::Opt::operator==(const OptRecordRdata::Opt& other) const { + return code_ == other.code_ && data_ == other.data_; +} + } // namespace net |