Kea: labelsequence.h Source File

| Kea 1.5.0

labelsequence.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7 #ifndef LABELSEQUENCE_H
8 #define LABELSEQUENCE_H 1
9
10 #include <dns/name.h>
11 #include <util/buffer.h>
12
13 namespace isc {
14 namespace dns {
15
35 class LabelSequence {
36 // Name calls the private toText(bool) method of LabelSequence.
37 friend std::string Name::toText(bool) const;
38
39 public:
45 static const size_t MAX_SERIALIZED_LENGTH =
46 Name::MAX_WIRE + Name::MAX_LABELS + 1;
47
51
52 static const LabelSequence& WILDCARD();
55
64 explicit LabelSequence(const Name& name):
65 data_(&name.ndata_[0]),
66 offsets_(&name.offsets_[0]),
67 first_label_(0),
68 last_label_(name.getLabelCount() - 1)
69 {}
70
87 explicit LabelSequence(const void* buf);
88
114 LabelSequence(const LabelSequence& src, uint8_t buf[MAX_SERIALIZED_LENGTH]);
115
125 LabelSequence(const LabelSequence& ls):
126 data_(ls.data_),
127 offsets_(ls.offsets_),
128 first_label_(ls.first_label_),
129 last_label_(ls.last_label_)
130 {}
131
145 const uint8_t* getData(size_t* len) const;
146
161 size_t getDataLength() const;
162
172 size_t getSerializedLength() const;
173
228 void serialize(void* buf, size_t buf_len) const;
229
239 bool equals(const LabelSequence& other, bool case_sensitive = false) const;
240
247 bool operator==(const LabelSequence& other) const {
248 return (equals(other));
249 }
250
260 NameComparisonResult compare(const LabelSequence& other,
261 bool case_sensitive = false) const;
262
272 void stripLeft(size_t i);
273
283 void stripRight(size_t i);
284
288 size_t getLabelCount() const {
289 return (last_label_ - first_label_ + 1);
290 }
291
306 std::string toText() const;
307
316 std::string toRawText(bool omit_final_dot) const;
317
347 void extend(const LabelSequence& labels,
348 uint8_t buf[MAX_SERIALIZED_LENGTH]);
349
350 private:
363 std::string toText(bool omit_final_dot) const;
364 public:
388 size_t getHash(bool case_sensitive) const;
389
393 bool isAbsolute() const;
394
395 private:
396 const uint8_t* data_; // wire-format name data
397 const uint8_t* offsets_; // an array of offsets in data_ for the labels
398 size_t first_label_; // index of offsets_ for the first label
399 size_t last_label_; // index of offsets_ for the last label.
400 // can be equal to first_label_, but must not
401 // be smaller (the class ensures that)
402 };
403
404
419 std::ostream&
420 operator<<(std::ostream& os, const LabelSequence& label_sequence);
421
422 inline const LabelSequence&
423 LabelSequence::WILDCARD() {
424 static const uint8_t wildcard_buf[4] = { 0x01, 0x00, 0x01, '*' };
425 static const LabelSequence wild_ls(wildcard_buf);
426 return (wild_ls);
427 }
428
429 } // end namespace dns
430 } // end namespace isc
431
432 #endif
433
434 // Local Variables:
435 // mode: c++
436 // End:
isc::dns::LabelSequence::toRawText
std::string toRawText(bool omit_final_dot) const
Convert the LabelSequence to a string without escape sequences.
Definition: labelsequence.cc:283
isc::dns::LabelSequence::serialize
void serialize(void *buf, size_t buf_len) const
Serialize the LabelSequence object in to a buffer.
Definition: labelsequence.cc:112
isc::dns::LabelSequence::isAbsolute
bool isAbsolute() const
Checks whether the label sequence is absolute.
Definition: labelsequence.cc:260
isc::dns::LabelSequence::toText
std::string toText() const
Convert the LabelSequence to a string.
Definition: labelsequence.cc:414
name.h
isc::dns::Name::toText
std::string toText(bool omit_final_dot=false) const
Convert the Name to a string.
Definition: name.cc:507
isc::dns::LabelSequence::extend
void extend(const LabelSequence &labels, uint8_t buf[MAX_SERIALIZED_LENGTH])
Extend this LabelSequence with the given labelsequence.
Definition: labelsequence.cc:419
isc::dns::LabelSequence::LabelSequence
LabelSequence(const LabelSequence &ls)
Copy constructor.
Definition: labelsequence.h:125
isc::dns::LabelSequence::getDataLength
size_t getDataLength() const
Return the length of the wire-format data of this LabelSequence.
Definition: labelsequence.cc:88
isc::dns::LabelSequence::WILDCARD
static const LabelSequence & WILDCARD()
Wildcard label ("*")
Definition: labelsequence.h:423
isc::dns::NameComparisonResult
This is a supplemental class used only as a return value of Name::compare() and LabelSequence::compar...
Definition: name.h:117
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::dns::operator<<
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition: edns.cc:172
isc::dns::Name
The Name class encapsulates DNS names.
Definition: name.h:223
isc::dns::LabelSequence::equals
bool equals(const LabelSequence &other, bool case_sensitive=false) const
Compares two label sequences for equality.
Definition: labelsequence.cc:141
isc::dns::LabelSequence::getLabelCount
size_t getLabelCount() const
Returns the current number of labels for this LabelSequence.
Definition: labelsequence.h:288
isc::dns::LabelSequence::getHash
size_t getHash(bool case_sensitive) const
Calculate a simple hash for the label sequence.
Definition: labelsequence.cc:265
isc::dns::Name::MAX_WIRE
static const size_t MAX_WIRE
Max allowable length of domain names.
Definition: name.h:699
buffer.h
isc::dns::LabelSequence::stripLeft
void stripLeft(size_t i)
Remove labels from the front of this LabelSequence.
Definition: labelsequence.cc:242
isc::dns::LabelSequence::operator==
bool operator==(const LabelSequence &other) const
Compares two label sequences for equality (case ignored).
Definition: labelsequence.h:247
isc::dns::LabelSequence::getData
const uint8_t * getData(size_t *len) const
Return the wire-format data for this LabelSequence.
Definition: labelsequence.cc:82
isc::dns::Name::MAX_LABELS
static const size_t MAX_LABELS
Max allowable labels of domain names.
Definition: name.h:705
isc::dns::LabelSequence::getSerializedLength
size_t getSerializedLength() const
Return the size of serialized image of the LabelSequence.
Definition: labelsequence.cc:94
isc::dns::LabelSequence::LabelSequence
LabelSequence(const Name &name)
Constructs a LabelSequence for the given name.
Definition: labelsequence.h:64
isc::dns::LabelSequence::stripRight
void stripRight(size_t i)
Remove labels from the end of this LabelSequence.
Definition: labelsequence.cc:251
isc::dns::LabelSequence::MAX_SERIALIZED_LENGTH
static const size_t MAX_SERIALIZED_LENGTH
Max possible size of serialized image generated by serialize.
Definition: labelsequence.h:45
isc::dns::LabelSequence::compare
NameComparisonResult compare(const LabelSequence &other, bool case_sensitive=false) const
Compares two label sequences.
Definition: labelsequence.cc:168
isc::dns::LabelSequence
Light-weight Accessor to Name data.
Definition: labelsequence.h:35