14#include <boost/functional/hash.hpp>
29 "Null pointer passed to LabelSequence constructor");
33 const uint8_t* bp =
reinterpret_cast<const uint8_t*
>(buf);
35 const uint8_t offsets_len = *bp++;
40 "Bad offsets len in serialized LabelSequence data: "
41 <<
static_cast<unsigned int>(offsets_len));
45 last_label_ = offsets_len - 1;
47 data_ = bp + offsets_len;
51 const uint8_t* dp = data_;
52 for (
size_t cur_offset = 0; cur_offset < offsets_len; ++cur_offset) {
55 "Broken offset or name data in serialized "
56 "LabelSequence data");
64 uint8_t buf[MAX_SERIALIZED_LENGTH]) {
66 const uint8_t *data = src.getData(&data_len);
67 std::memcpy(buf, data, data_len);
69 for (
size_t i = 0; i < src.getLabelCount(); ++i) {
71 src.offsets_[src.first_label_];
75 last_label_ = src.last_label_ - src.first_label_;
84 return (&data_[offsets_[first_label_]]);
89 const size_t last_label_len = data_[offsets_[last_label_]] + 1;
90 return (offsets_[last_label_] - offsets_[first_label_] + last_label_len);
103isOutOfRange(
const uint8_t* bp,
const uint8_t* ep,
104 const uint8_t* buf,
size_t buf_len) {
105 return (bp >= buf + buf_len ||
113 if (expected_size > buf_len) {
122 uint8_t* bp =
reinterpret_cast<uint8_t*
>(buf);
124 if (!isOutOfRange(offsets_, offsets_ + offsets_len, bp, buf_len) ||
125 !isOutOfRange(data_, data_ + ndata_len, bp, buf_len)) {
130 for (
size_t i = 0; i < offsets_len; ++i) {
131 *bp++ = offsets_[first_label_ + i] - offsets_[first_label_];
133 std::memcpy(bp, &data_[offsets_[first_label_]], ndata_len);
136 isc_throw_assert(bp -
reinterpret_cast<const uint8_t*
>(buf) == expected_size);
141 size_t len, other_len;
142 const uint8_t* data =
getData(&len);
143 const uint8_t* other_data = other.getData(&other_len);
145 if (len != other_len) {
148 if (case_sensitive) {
149 return (std::memcmp(data, other_data, len) == 0);
155 for (
size_t i = 0; i < len; ++i) {
156 const uint8_t ch = data[i];
157 const uint8_t other_ch = other_data[i];
168 bool case_sensitive)
const {
173 unsigned int nlabels = 0;
175 int l2 = other.getLabelCount();
176 const int ldiff =
static_cast<int>(l1) -
static_cast<int>(l2);
177 unsigned int l = (ldiff < 0) ? l1 : l2;
183 size_t pos1 = offsets_[l1 + first_label_];
184 size_t pos2 = other.offsets_[l2 + other.first_label_];
185 unsigned int count1 = data_[pos1++];
186 unsigned int count2 = other.data_[pos2++];
192 const int cdiff =
static_cast<int>(count1) -
static_cast<int>(count2);
193 unsigned int count = (cdiff < 0) ? count1 : count2;
196 const uint8_t label1 = data_[pos1];
197 const uint8_t label2 = other.data_[pos2];
200 if (case_sensitive) {
201 chdiff =
static_cast<int>(label1) -
static_cast<int>(label2);
203 chdiff =
static_cast<int>(
231 }
else if (ldiff > 0) {
259 return (data_[offsets_[last_label_]] == 0);
265 const uint8_t* s =
getData(&length);
272 const uint8_t c = *s++;
273 boost::hash_combine(hash_val, case_sensitive ? c :
282 const uint8_t* np = &data_[offsets_[first_label_]];
295 while (np != np_end) {
303 if (!omit_final_dot || result.empty()) {
304 result.push_back(
'.');
312 if (!result.empty()) {
314 result.push_back(
'.');
317 while (count-- > 0) {
318 const uint8_t c = *np++;
336 const uint8_t* np = &data_[offsets_[first_label_]];
349 while (np != np_end) {
357 if (!omit_final_dot || result.empty()) {
358 result.push_back(
'.');
366 if (!result.empty()) {
368 result.push_back(
'.');
371 while (count-- > 0) {
372 const uint8_t c = *np++;
383 result.push_back(
'\\');
387 if (c > 0x20 && c < 0x7f) {
392 result.push_back(0x5c);
393 result.push_back(0x30 + ((c / 100) % 10));
394 result.push_back(0x30 + ((c / 10) % 10));
395 result.push_back(0x30 + (c % 10));
400 isc_throw(BadLabelType,
"unknown label type in name data");
418 uint8_t buf[MAX_SERIALIZED_LENGTH]) {
420 size_t label_count = last_label_ + 1;
423 size_t data_pos = offsets_[last_label_] + data_[offsets_[last_label_]] + 1;
430 const size_t append_label_count = labels.getLabelCount();
432 const uint8_t *data = labels.getData(&data_len);
437 "extend() called with unrelated buffer");
442 "extend() would exceed maximum number of labels");
446 "extend() would exceed maximum wire length");
450 std::memmove(&buf[data_pos], data, data_len);
452 for (
size_t i = 0; i < append_label_count; ++i) {
455 labels.offsets_[i + labels.first_label_] -
456 labels.offsets_[labels.first_label_];
458 last_label_ = label_count + append_label_count - 1;
463 os << label_sequence.toText();
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
A standard DNS module exception that is thrown if the name parser encounters an obsolete or incomplet...
Light-weight Accessor to Name data.
std::string toRawText(bool omit_final_dot) const
Convert the LabelSequence to a string without escape sequences.
size_t getHash(bool case_sensitive) const
Calculate a simple hash for the label sequence.
void serialize(void *buf, size_t buf_len) const
Serialize the LabelSequence object in to a buffer.
NameComparisonResult compare(const LabelSequence &other, bool case_sensitive=false) const
Compares two label sequences.
bool isAbsolute() const
Checks whether the label sequence is absolute.
LabelSequence(const Name &name)
Constructs a LabelSequence for the given name.
bool equals(const LabelSequence &other, bool case_sensitive=false) const
Compares two label sequences for equality.
size_t getLabelCount() const
Returns the current number of labels for this LabelSequence.
size_t getSerializedLength() const
Return the size of serialized image of the 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.
friend std::string Name::toText(bool) const
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.
void extend(const LabelSequence &labels, uint8_t buf[MAX_SERIALIZED_LENGTH])
Extend this LabelSequence with the given labelsequence.
This is a supplemental class used only as a return value of Name::compare() and LabelSequence::compar...
static const size_t MAX_LABELLEN
Max allowable length of labels of a domain name.
static const size_t MAX_WIRE
Max allowable length of domain names.
static const size_t MAX_LABELS
Max allowable labels of domain names.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define isc_throw_assert(expr)
Replacement for assert() that throws if the expression is false.
const uint8_t maptolower[]
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Defines the logger used by the top-level component of kea-lfc.