 |
Kea
1.5.0
|
Go to the documentation of this file.
16 #include <boost/array.hpp>
17 #include <boost/static_assert.hpp>
40 OffsetItem(
size_t hash,
size_t pos,
size_t len) :
64 template <
bool CASE_SENSITIVE>
74 buffer_(&buffer), name_buf_(&name_buf),
hash_(hash)
77 bool operator()(
const OffsetItem& item)
const {
93 uint16_t item_pos = item.pos_;
94 uint16_t item_label_len = 0;
95 for (
size_t i = 0; i < item.len_; ++i, ++item_pos) {
96 item_pos = nextPosition(*buffer_, item_pos, item_label_len);
97 const uint8_t ch1 = (*buffer_)[item_pos];
98 const uint8_t ch2 = name_buf_->
readUint8();
114 static uint16_t nextPosition(
const OutputBuffer& buffer,
115 uint16_t pos, uint16_t& llen)
120 while ((buffer[pos] & Name::COMPRESS_POINTER_MARK8) ==
121 Name::COMPRESS_POINTER_MARK8) {
122 pos = (buffer[pos] & ~Name::COMPRESS_POINTER_MARK8) *
123 256 + buffer[pos + 1];
130 assert(i < Name::MAX_WIRE);
160 static const size_t BUCKETS = 64;
161 static const size_t RESERVED_ITEMS = 16;
162 static const uint16_t NO_OFFSET = 65535;
170 for (
size_t i = 0; i < BUCKETS; ++i) {
171 table_[i].reserve(RESERVED_ITEMS);
176 size_t hash,
bool case_sensitive)
const
183 const size_t bucket_id = hash % BUCKETS;
184 vector<OffsetItem>::const_reverse_iterator found;
185 if (case_sensitive) {
186 found = find_if(table_[bucket_id].rbegin(),
187 table_[bucket_id].rend(),
188 NameCompare<true>(buffer, name_buf, hash));
190 found = find_if(table_[bucket_id].rbegin(),
191 table_[bucket_id].rend(),
192 NameCompare<false>(buffer, name_buf, hash));
194 if (found != table_[bucket_id].rend()) {
195 return (found->pos_);
200 void addOffset(
size_t hash,
size_t offset,
size_t len) {
201 table_[hash % BUCKETS].push_back(OffsetItem(hash, offset, len));
205 vector<OffsetItem> table_[BUCKETS];
221 MessageRenderer::MessageRenderer() :
243 vector<OffsetItem> new_table;
245 new_table.swap(impl_->
table_[i]);
280 "compress mode cannot be changed during rendering");
294 size_t nlabels_uncomp;
298 for (nlabels_uncomp = 0; nlabels_uncomp < nlabels; ++nlabels_uncomp) {
299 if (nlabels_uncomp > 0) {
303 data = sequence.
getData(&data_len);
323 if (nlabels_uncomp > 0 || !compress) {
325 if (compress && nlabels > nlabels_uncomp) {
327 uncomp_sequence.
stripRight(nlabels - nlabels_uncomp);
329 data = uncomp_sequence.
getData(&data_len);
343 for (
size_t i = 0; i < nlabels_uncomp; ++i) {
344 const uint8_t label_len =
getBuffer()[offset];
345 if (label_len == 0) {
354 offset += (label_len + 1);
355 seqlen -= (label_len + 1);
366 local_buffer_(0), buffer_(&local_buffer_)
372 if (buffer != NULL && buffer_->
getLength() != 0) {
374 "MessageRenderer buffer cannot be set when in use");
376 if (buffer == NULL && buffer_ == &local_buffer_) {
378 "Default MessageRenderer buffer cannot be reset");
381 if (buffer == NULL) {
384 buffer_ = &local_buffer_;
uint16_t len_
The length of the corresponding sequence (which is a domain name).
size_t getLength() const
Return the length of data written in the internal buffer.
static const size_t BUCKETS
size_t hash_
The hash value for the stored name calculated by LabelSequence.getHash.
CompressMode
Compression mode constants.
bool truncated_
A boolean flag that indicates truncation has occurred while rendering the data.
AbstractMessageRenderer()
The default constructor.
virtual ~MessageRenderer()
const isc::util::OutputBuffer & getBuffer() const
Return the output buffer we render into.
virtual void setCompressMode(CompressMode mode)
This implementation does not allow this call in the middle of rendering (i.e.
virtual void setTruncated()
Mark the renderer to indicate truncation has occurred while rendering.
size_t getDataLength() const
Return the length of the wire-format data of this LabelSequence.
virtual bool isTruncated() const
Return whether truncation has occurred while rendering.
const uint8_t maptolower[]
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
Defines the logger used by the top-level component of kea-dhcp-ddns.
virtual void writeName(const Name &name, bool compress=true)
Write a Name object into the internal buffer in wire format, with or without name compression.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
uint16_t pos_
The position (offset from the beginning) in the buffer where the name starts.
vector< OffsetItem > table_[BUCKETS]
The Name class encapsulates DNS names.
void clear()
Clear buffer content.
static const uint16_t NO_OFFSET
@ CASE_INSENSITIVE
Compress names case-insensitive manner (default)
size_t getLength() const
Return the length of data written in the buffer.
void setBuffer(isc::util::OutputBuffer *buffer)
Set or reset a temporary output buffer.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the internal buffer in network byte order.
size_t getLabelCount() const
Returns the current number of labels for this LabelSequence.
uint16_t msglength_limit_
The maximum length of rendered data that can fit without truncation.
size_t getHash(bool case_sensitive) const
Calculate a simple hash for the label sequence.
CompressMode compress_mode_
The name compression mode.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the internal buffer of the renderer object.
void stripLeft(size_t i)
Remove labels from the front of this LabelSequence.
static const uint16_t COMPRESS_POINTER_MARK16
A 16-bit masked value indicating a start of compression pointer.
const uint8_t * getData(size_t *len) const
Return the wire-format data for this LabelSequence.
virtual CompressMode getCompressMode() const
Return the compression mode of the renderer class object.
virtual void setLengthLimit(size_t len)
Set the maximum length of rendered data that can fit in the corresponding DNS message without truncat...
The MessageRendererImpl class is the actual implementation of MessageRenderer.
The MessageRenderer is a concrete derived class of AbstractMessageRenderer as a general purpose imple...
void addOffset(size_t hash, size_t offset, size_t len)
@ CASE_SENSITIVE
Compress names case-sensitive manner.
virtual void clear()
Clear the internal buffer and other internal resources.
virtual size_t getLengthLimit() const
Return the maximum length of rendered data that can fit in the corresponding DNS message without trun...
void stripRight(size_t i)
Remove labels from the end of this LabelSequence.
boost::array< size_t, Name::MAX_LABELS > seq_hashes_
static const uint16_t MAX_COMPRESS_POINTER
Max possible pointer value for name compression.
virtual void clear()
Clear the internal buffer and other internal resources.
MessageRendererImpl()
Constructor.
static const size_t RESERVED_ITEMS
uint16_t findOffset(const OutputBuffer &buffer, InputBuffer &name_buf, size_t hash, bool case_sensitive) const
Light-weight Accessor to Name data.