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>
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];
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_;
void setBuffer(isc::util::OutputBuffer *buffer)
Set or reset a temporary output buffer.
MessageRendererImpl()
Constructor.
The Name class encapsulates DNS names.
boost::array< size_t, Name::MAX_LABELS > seq_hashes_
virtual void setLengthLimit(size_t len)
Set the maximum length of rendered data that can fit in the corresponding DNS message without truncat...
uint16_t findOffset(const OutputBuffer &buffer, InputBuffer &name_buf, size_t hash, bool case_sensitive) const
static const size_t BUCKETS
bool truncated_
A boolean flag that indicates truncation has occurred while rendering the data.
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
size_t getLabelCount() const
Returns the current number of labels for this LabelSequence.
virtual void setTruncated()
Mark the renderer to indicate truncation has occurred while rendering.
AbstractMessageRenderer()
The default constructor.
virtual void clear()
Clear the internal buffer and other internal resources.
The MessageRendererImpl class is the actual implementation of MessageRenderer.
virtual bool isTruncated() const
Return whether truncation has occurred while rendering.
vector< OffsetItem > table_[BUCKETS]
static const uint16_t NO_OFFSET
virtual void clear()
Clear the internal buffer and other internal resources.
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 getHash(bool case_sensitive) const
Calculate a simple hash for the label sequence.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
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...
size_t getDataLength() const
Return the length of the wire-format data of this LabelSequence.
const OutputBuffer * buffer_
CompressMode
Compression mode constants.
void stripRight(size_t i)
Remove labels from the end of this LabelSequence.
uint16_t msglength_limit_
The maximum length of rendered data that can fit without truncation.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the internal buffer of the renderer object. ...
Compress names case-sensitive manner.
void clear()
Clear buffer content.
static const uint16_t MAX_COMPRESS_POINTER
Max possible pointer value for name compression.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
virtual ~MessageRenderer()
uint16_t len_
The length of the corresponding sequence (which is a domain name).
Defines the logger used by the top-level component of kea-dhcp-ddns.
const isc::util::OutputBuffer & getBuffer() const
Return the output buffer we render into.
const uint8_t * getData(size_t *len) const
Return the wire-format data for this LabelSequence.
static const uint16_t COMPRESS_POINTER_MARK16
A 16-bit masked value indicating a start of compression pointer.
virtual CompressMode getCompressMode() const
Return the compression mode of the renderer class object.
virtual size_t getLengthLimit() const
Return the maximum length of rendered data that can fit in the corresponding DNS message without trun...
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)
CompressMode compress_mode_
The name compression mode.
Compress names case-insensitive manner (default)
virtual void setCompressMode(CompressMode mode)
This implementation does not allow this call in the middle of rendering (i.e.
size_t getLength() const
Return the length of data written in the internal buffer.
size_t hash_
The hash value for the stored name calculated by LabelSequence.getHash.
static const size_t RESERVED_ITEMS
uint16_t pos_
The position (offset from the beginning) in the buffer where the name starts.
void stripLeft(size_t i)
Remove labels from the front of this LabelSequence.
size_t getLength() const
Return the length of data written in the buffer.
Light-weight Accessor to Name data.
const uint8_t maptolower[]