Kea: labelsequence.h Source File

| Kea 3.2.0-git

labelsequence.h
Go to the documentation of this file.
1// Copyright (C) 2012-2024 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
9
10#include <dns/name.h>
11#include <util/buffer.h>
12
13namespace isc {
14namespace dns {
15
35 class LabelSequence {
36 // Name calls the private toText(bool) method of LabelSequence.
37 friend std::string Name::toText(bool) const;
38
39public:
45 static const size_t MAX_SERIALIZED_LENGTH =
46 Name::MAX_WIRE + Name::MAX_LABELS + 1;
47
51
52
53 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
141 LabelSequence& operator=(const LabelSequence& other) {
142 if (this != &other) {
143 // Not self-assignment.
144 data_ = other.data_;
145 offsets_ = other.offsets_;
146 first_label_ = other.first_label_;
147 last_label_ = other.last_label_;
148 }
149 return (*this);
150 }
151
165 const uint8_t* getData(size_t* len) const;
166
181 size_t getDataLength() const;
182
192 size_t getSerializedLength() const;
193
248 void serialize(void* buf, size_t buf_len) const;
249
259 bool equals(const LabelSequence& other, bool case_sensitive = false) const;
260
267 bool operator==(const LabelSequence& other) const {
268 return (equals(other));
269 }
270
280 NameComparisonResult compare(const LabelSequence& other,
281 bool case_sensitive = false) const;
282
292 void stripLeft(size_t i);
293
303 void stripRight(size_t i);
304
308 size_t getLabelCount() const {
309 return (last_label_ - first_label_ + 1);
310 }
311
326 std::string toText() const;
327
336 std::string toRawText(bool omit_final_dot) const;
337
367 void extend(const LabelSequence& labels,
368 uint8_t buf[MAX_SERIALIZED_LENGTH]);
369
370private:
383 std::string toText(bool omit_final_dot) const;
384public:
408 size_t getHash(bool case_sensitive) const;
409
413 bool isAbsolute() const;
414
415private:
416 const uint8_t* data_; // wire-format name data
417 const uint8_t* offsets_; // an array of offsets in data_ for the labels
418 size_t first_label_; // index of offsets_ for the first label
419 size_t last_label_; // index of offsets_ for the last label.
420 // can be equal to first_label_, but must not
421 // be smaller (the class ensures that)
422};
423
424
439std::ostream&
440 operator<<(std::ostream& os, const LabelSequence& label_sequence);
441
442inline const LabelSequence&
443LabelSequence::WILDCARD() {
444 static const uint8_t wildcard_buf[4] = { 0x01, 0x00, 0x01, '*' };
445 static const LabelSequence wild_ls(wildcard_buf);
446 return (wild_ls);
447}
448
449} // end namespace dns
450} // end namespace isc
451
452#endif
buffer.h
isc::dns::LabelSequence
Light-weight Accessor to Name data.
Definition labelsequence.h:35
isc::dns::LabelSequence::toRawText
std::string toRawText(bool omit_final_dot) const
Convert the LabelSequence to a string without escape sequences.
Definition labelsequence.cc:282
isc::dns::LabelSequence::LabelSequence
LabelSequence(const LabelSequence &ls)
Copy constructor.
Definition labelsequence.h:125
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::getHash
size_t getHash(bool case_sensitive) const
Calculate a simple hash for the label sequence.
Definition labelsequence.cc:264
isc::dns::LabelSequence::serialize
void serialize(void *buf, size_t buf_len) const
Serialize the LabelSequence object in to a buffer.
Definition labelsequence.cc:111
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::isAbsolute
bool isAbsolute() const
Checks whether the label sequence is absolute.
Definition labelsequence.cc:259
isc::dns::LabelSequence::toText
std::string toText() const
Convert the LabelSequence to a string.
Definition labelsequence.cc:415
isc::dns::LabelSequence::LabelSequence
LabelSequence(const Name &name)
Constructs a LabelSequence for the given name.
Definition labelsequence.h:64
isc::dns::LabelSequence::operator==
bool operator==(const LabelSequence &other) const
Compares two label sequences for equality (case ignored).
Definition labelsequence.h:267
isc::dns::LabelSequence::operator=
LabelSequence & operator=(const LabelSequence &other)
Assignment operator.
Definition labelsequence.h:141
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:308
isc::dns::LabelSequence::getSerializedLength
size_t getSerializedLength() const
Return the size of serialized image of the LabelSequence.
Definition labelsequence.cc:94
isc::dns::LabelSequence::WILDCARD
static const LabelSequence & WILDCARD()
Wildcard label ("*").
Definition labelsequence.h:443
isc::dns::LabelSequence::stripLeft
void stripLeft(size_t i)
Remove labels from the front of this LabelSequence.
Definition labelsequence.cc:241
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::LabelSequence::stripRight
void stripRight(size_t i)
Remove labels from the end of this LabelSequence.
Definition labelsequence.cc:250
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::extend
void extend(const LabelSequence &labels, uint8_t buf[MAX_SERIALIZED_LENGTH])
Extend this LabelSequence with the given labelsequence.
Definition labelsequence.cc:420
isc::dns::NameComparisonResult
This is a supplemental class used only as a return value of Name::compare() and LabelSequence::compar...
Definition name.h:113
isc::dns::Name
The Name class encapsulates DNS names.
Definition name.h:219
isc::dns::Name::MAX_WIRE
static const size_t MAX_WIRE
Max allowable length of domain names.
Definition name.h:695
isc::dns::Name::toText
std::string toText(bool omit_final_dot=false) const
Convert the Name to a string.
Definition name.cc:503
isc::dns::Name::MAX_LABELS
static const size_t MAX_LABELS
Max allowable labels of domain names.
Definition name.h:701
name.h
isc::dns::name
Definition name.cc:69
isc::dns
Definition char_string.cc:26
isc::dns::operator<<
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition edns.cc:163
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18