13 #include <boost/functional/hash.hpp> 28 "Null pointer passed to LabelSequence constructor");
32 const uint8_t* bp = reinterpret_cast<const uint8_t*>(buf);
34 const uint8_t offsets_len = *bp++;
39 "Bad offsets len in serialized LabelSequence data: " 40 << static_cast<unsigned int>(offsets_len));
44 last_label_ = offsets_len - 1;
46 data_ = bp + offsets_len;
50 const uint8_t* dp = data_;
51 for (
size_t cur_offset = 0; cur_offset < offsets_len; ++cur_offset) {
54 "Broken offset or name data in serialized " 55 "LabelSequence data");
63 uint8_t buf[MAX_SERIALIZED_LENGTH])
66 const uint8_t *data = src.
getData(&data_len);
67 std::memcpy(buf, data, data_len);
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);
103 isOutOfRange(
const uint8_t* bp,
const uint8_t* ep,
104 const uint8_t* buf,
size_t buf_len)
106 return (bp >= buf + buf_len ||
114 if (expected_size > buf_len) {
119 assert(offsets_len < 256);
123 uint8_t* bp = reinterpret_cast<uint8_t*>(buf);
125 if (!isOutOfRange(offsets_, offsets_ + offsets_len, bp, buf_len) ||
126 !isOutOfRange(data_, data_ + ndata_len, bp, buf_len)) {
131 for (
size_t i = 0; i < offsets_len; ++i) {
132 *bp++ = offsets_[first_label_ + i] - offsets_[first_label_];
134 std::memcpy(bp, &data_[offsets_[first_label_]], ndata_len);
137 assert(bp - reinterpret_cast<const uint8_t*>(buf) == expected_size);
142 size_t len, other_len;
143 const uint8_t* data =
getData(&len);
144 const uint8_t* other_data = other.
getData(&other_len);
146 if (len != other_len) {
149 if (case_sensitive) {
150 return (std::memcmp(data, other_data, len) == 0);
156 for (
size_t i = 0; i < len; ++i) {
157 const uint8_t ch = data[i];
158 const uint8_t other_ch = other_data[i];
169 bool case_sensitive)
const 175 unsigned int nlabels = 0;
178 const int ldiff = static_cast<int>(l1) - static_cast<int>(l2);
179 unsigned int l = (ldiff < 0) ? l1 : l2;
185 size_t pos1 = offsets_[l1 + first_label_];
186 size_t pos2 = other.offsets_[l2 + other.first_label_];
187 unsigned int count1 = data_[pos1++];
188 unsigned int count2 = other.data_[pos2++];
194 const int cdiff = static_cast<int>(count1) - static_cast<int>(count2);
195 unsigned int count = (cdiff < 0) ? count1 : count2;
198 const uint8_t label1 = data_[pos1];
199 const uint8_t label2 = other.data_[pos2];
202 if (case_sensitive) {
203 chdiff = static_cast<int>(label1) - static_cast<int>(label2);
205 chdiff = static_cast<int>(
233 }
else if (ldiff > 0) {
261 return (data_[offsets_[last_label_]] == 0);
267 const uint8_t* s =
getData(&length);
274 const uint8_t c = *s++;
275 boost::hash_combine(hash_val, case_sensitive ? c :
284 const uint8_t* np = &data_[offsets_[first_label_]];
297 while (np != np_end) {
305 if (!omit_final_dot || result.empty()) {
306 result.push_back(
'.');
312 assert(np_end - np >= count);
314 if (!result.empty()) {
316 result.push_back(
'.');
319 while (count-- > 0) {
320 const uint8_t c = *np++;
329 assert(np == np_end);
338 const uint8_t* np = &data_[offsets_[first_label_]];
351 while (np != np_end) {
359 if (!omit_final_dot || result.empty()) {
360 result.push_back(
'.');
366 assert(np_end - np >= count);
368 if (!result.empty()) {
370 result.push_back(
'.');
373 while (count-- > 0) {
374 const uint8_t c = *np++;
385 result.push_back(
'\\');
389 if (c > 0x20 && c < 0x7f) {
394 result.push_back(0x5c);
395 result.push_back(0x30 + ((c / 100) % 10));
396 result.push_back(0x30 + ((c / 10) % 10));
397 result.push_back(0x30 + (c % 10));
402 isc_throw(BadLabelType,
"unknown label type in name data");
407 assert(np == np_end);
420 uint8_t buf[MAX_SERIALIZED_LENGTH])
423 size_t label_count = last_label_ + 1;
426 size_t data_pos = offsets_[last_label_] + data_[offsets_[last_label_]] + 1;
435 const uint8_t *data = labels.
getData(&data_len);
440 "extend() called with unrelated buffer");
445 "extend() would exceed maximum number of labels");
449 "extend() would exceed maximum wire length");
453 std::memmove(&buf[data_pos], data, data_len);
455 for (
size_t i = 0; i < append_label_count; ++i) {
458 labels.offsets_[i + labels.first_label_] -
459 labels.offsets_[labels.first_label_];
461 last_label_ = label_count + append_label_count - 1;
466 os << label_sequence.
toText();
LabelSequence(const Name &name)
Constructs a LabelSequence for the given name.
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
size_t getLabelCount() const
Returns the current number of labels for this LabelSequence.
void serialize(void *buf, size_t buf_len) const
Serialize the LabelSequence object in to a buffer.
size_t getHash(bool case_sensitive) const
Calculate a simple hash for the label sequence.
size_t getDataLength() const
Return the length of the wire-format data of this LabelSequence.
This is a supplemental class used only as a return value of Name::compare() and LabelSequence::compar...
void extend(const LabelSequence &labels, uint8_t buf[MAX_SERIALIZED_LENGTH])
Extend this LabelSequence with the given labelsequence.
static const size_t MAX_WIRE
Max allowable length of domain names.
#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 is considered invalid in that con...
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.
std::string toText() const
Convert the LabelSequence to a string.
NameComparisonResult compare(const LabelSequence &other, bool case_sensitive=false) const
Compares two label sequences.
A standard DNS module exception that is thrown if the name parser encounters an obsolete or incomplet...
Defines the logger used by the top-level component of kea-dhcp-ddns.
bool equals(const LabelSequence &other, bool case_sensitive=false) const
Compares two label sequences for equality.
size_t getSerializedLength() const
Return the size of serialized image of the LabelSequence.
std::string toRawText(bool omit_final_dot) const
Convert the LabelSequence to a string without escape sequences.
static const size_t MAX_LABELLEN
Max allowable length of labels of a domain name.
static const size_t MAX_LABELS
Max allowable labels of domain names.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
bool isAbsolute() const
Checks whether the label sequence is absolute.
void stripLeft(size_t i)
Remove labels from the front of this LabelSequence.
Light-weight Accessor to Name data.
const uint8_t maptolower[]