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