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])
67 const uint8_t *data = src.
getData(&data_len);
68 std::memcpy(buf, data, data_len);
72 src.offsets_[src.first_label_];
76 last_label_ = src.last_label_ - src.first_label_;
85 return (&data_[offsets_[first_label_]]);
90 const size_t last_label_len = data_[offsets_[last_label_]] + 1;
91 return (offsets_[last_label_] - offsets_[first_label_] + last_label_len);
104 isOutOfRange(
const uint8_t* bp,
const uint8_t* ep,
105 const uint8_t* buf,
size_t buf_len)
107 return (bp >= buf + buf_len ||
115 if (expected_size > buf_len) {
124 uint8_t* bp =
reinterpret_cast<uint8_t*
>(buf);
126 if (!isOutOfRange(offsets_, offsets_ + offsets_len, bp, buf_len) ||
127 !isOutOfRange(data_, data_ + ndata_len, bp, buf_len)) {
132 for (
size_t i = 0; i < offsets_len; ++i) {
133 *bp++ = offsets_[first_label_ + i] - offsets_[first_label_];
135 std::memcpy(bp, &data_[offsets_[first_label_]], ndata_len);
138 isc_throw_assert(bp - reinterpret_cast<const uint8_t*>(buf) == expected_size);
143 size_t len, other_len;
144 const uint8_t* data =
getData(&len);
145 const uint8_t* other_data = other.
getData(&other_len);
147 if (len != other_len) {
150 if (case_sensitive) {
151 return (std::memcmp(data, other_data, len) == 0);
157 for (
size_t i = 0; i < len; ++i) {
158 const uint8_t ch = data[i];
159 const uint8_t other_ch = other_data[i];
170 bool case_sensitive)
const
176 unsigned int nlabels = 0;
179 const int ldiff =
static_cast<int>(l1) - static_cast<int>(l2);
180 unsigned int l = (ldiff < 0) ? l1 : l2;
186 size_t pos1 = offsets_[l1 + first_label_];
187 size_t pos2 = other.offsets_[l2 + other.first_label_];
188 unsigned int count1 = data_[pos1++];
189 unsigned int count2 = other.data_[pos2++];
195 const int cdiff =
static_cast<int>(count1) - static_cast<int>(count2);
196 unsigned int count = (cdiff < 0) ? count1 : count2;
199 const uint8_t label1 = data_[pos1];
200 const uint8_t label2 = other.data_[pos2];
203 if (case_sensitive) {
204 chdiff =
static_cast<int>(label1) - static_cast<int>(label2);
206 chdiff =
static_cast<int>(
234 }
else if (ldiff > 0) {
262 return (data_[offsets_[last_label_]] == 0);
268 const uint8_t* s =
getData(&length);
275 const uint8_t c = *s++;
276 boost::hash_combine(hash_val, case_sensitive ? c :
285 const uint8_t* np = &data_[offsets_[first_label_]];
298 while (np != np_end) {
306 if (!omit_final_dot || result.empty()) {
307 result.push_back(
'.');
315 if (!result.empty()) {
317 result.push_back(
'.');
320 while (count-- > 0) {
321 const uint8_t c = *np++;
339 const uint8_t* np = &data_[offsets_[first_label_]];
352 while (np != np_end) {
360 if (!omit_final_dot || result.empty()) {
361 result.push_back(
'.');
369 if (!result.empty()) {
371 result.push_back(
'.');
374 while (count-- > 0) {
375 const uint8_t c = *np++;
386 result.push_back(
'\\');
390 if (c > 0x20 && c < 0x7f) {
395 result.push_back(0x5c);
396 result.push_back(0x30 + ((c / 100) % 10));
397 result.push_back(0x30 + ((c / 10) % 10));
398 result.push_back(0x30 + (c % 10));
403 isc_throw(BadLabelType,
"unknown label type in name data");
421 uint8_t buf[MAX_SERIALIZED_LENGTH])
424 size_t label_count = last_label_ + 1;
427 size_t data_pos = offsets_[last_label_] + data_[offsets_[last_label_]] + 1;
436 const uint8_t *data = labels.
getData(&data_len);
441 "extend() called with unrelated buffer");
446 "extend() would exceed maximum number of labels");
448 if (data_pos + data_len > Name::MAX_WIRE) {
450 "extend() would exceed maximum wire length");
454 std::memmove(&buf[data_pos], data, data_len);
456 for (
size_t i = 0; i < append_label_count; ++i) {
457 buf[Name::MAX_WIRE + label_count + i] =
459 labels.offsets_[i + labels.first_label_] -
460 labels.offsets_[labels.first_label_];
462 last_label_ = label_count + append_label_count - 1;
467 os << label_sequence.
toText();
#define isc_throw_assert(expr)
Replacement for assert() that throws if the expression is false.
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.
std::string toText() const
Convert the LabelSequence to a string.
std::string toRawText(bool omit_final_dot) const
Convert the LabelSequence to a string without escape sequences.
size_t getLabelCount() const
Returns the current number of labels for 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.
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.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
size_t getDataLength() const
Return the length of the wire-format data of this LabelSequence.
void stripRight(size_t i)
Remove labels from the end of this LabelSequence.
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.
const uint8_t * getData(size_t *len) const
Return the wire-format data for this LabelSequence.
void serialize(void *buf, size_t buf_len) const
Serialize the LabelSequence object in to a buffer.
bool isAbsolute() const
Checks whether the label sequence is absolute.
static const size_t MAX_LABELLEN
Max allowable length of labels of a domain name.
size_t getSerializedLength() const
Return the size of serialized image of the LabelSequence.
static const size_t MAX_LABELS
Max allowable labels of domain names.
bool equals(const LabelSequence &other, bool case_sensitive=false) const
Compares two label sequences for equality.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
void stripLeft(size_t i)
Remove labels from the front of this LabelSequence.
NameComparisonResult compare(const LabelSequence &other, bool case_sensitive=false) const
Compares two label sequences.
Light-weight Accessor to Name data.
const uint8_t maptolower[]