Kea: name.h Source File

| Kea 3.0.3-git

name.h
Go to the documentation of this file.
1// Copyright (C) 2009-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 NAME_H
8#define NAME_H
9
10#include <util/buffer.h>
11#include <dns/messagerenderer.h>
12
13#include <stdint.h>
14
15#include <string>
16#include <vector>
17
18#include <dns/exceptions.h>
19
20namespace isc {
21namespace dns {
26 class EmptyLabel : public NameParserException {
27public:
28 EmptyLabel(const char* file, size_t line, const char* what) :
29 NameParserException(file, line, what) {}
30};
31
36 class TooLongName : public NameParserException {
37public:
38 TooLongName(const char* file, size_t line, const char* what) :
39 NameParserException(file, line, what) {}
40};
41
46 class TooLongLabel : public NameParserException {
47public:
48 TooLongLabel(const char* file, size_t line, const char* what) :
49 NameParserException(file, line, what) {}
50};
51
58 class BadLabelType : public NameParserException {
59public:
60 BadLabelType(const char* file, size_t line, const char* what) :
61 NameParserException(file, line, what) {}
62};
63
68 class BadEscape : public NameParserException {
69public:
70 BadEscape(const char* file, size_t line, const char* what) :
71 NameParserException(file, line, what) {}
72};
73
81 class IncompleteName : public NameParserException {
82public:
83 IncompleteName(const char* file, size_t line, const char* what) :
84 NameParserException(file, line, what) {}
85};
86
92 class MissingNameOrigin : public NameParserException {
93public:
94 MissingNameOrigin(const char* file, size_t line, const char* what) :
95 NameParserException(file, line, what) {}
96};
97
113 class NameComparisonResult {
114public:
138 enum NameRelation {
139 SUPERDOMAIN = 0,
140 SUBDOMAIN = 1,
141 EQUAL = 2,
142 COMMONANCESTOR = 3,
143 NONE = 4
144 };
145
149
150
154 NameComparisonResult(int order, unsigned int nlabels,
155 NameRelation relation) :
156 order_(order), nlabels_(nlabels), relation_(relation) {}
157
158
162
163
164 int getOrder() const { return (order_); }
166 unsigned int getCommonLabels() const { return (nlabels_); }
168 NameRelation getRelation() const { return (relation_); }
170private:
171 int order_;
172 unsigned int nlabels_;
173 NameRelation relation_;
174};
175
219 class Name {
220 // LabelSequences use knowledge about the internal data structure
221 // of this class for efficiency (they use the offsets_ vector and
222 // the ndata_ string)
223 friend class LabelSequence;
224
228
229private:
231 typedef std::vector<uint8_t> NameString;
233 typedef std::vector<uint8_t> NameOffsets;
234
241 Name() : length_(0), labelcount_(0) {}
242public:
253 explicit Name(const std::string& namestr, bool downcase = false);
254
282 Name(const char* name_data, size_t data_len, const Name* origin,
283 bool downcase = false);
284
301 explicit Name(isc::util::InputBuffer& buff, bool downcase = false);
304
305
307
311
312
342 uint8_t at(size_t pos) const
343 {
344 if (pos >= length_) {
345 isc_throw(OutOfRange, "Out of range access in Name::at()");
346 }
347 return (ndata_[pos]);
348 }
349
356 size_t getLength() const { return (length_); }
357
366 unsigned int getLabelCount() const { return (labelcount_); }
368
372
373
386 //
389 std::string toText(bool omit_final_dot = false) const;
390
399 std::string toRawText(bool omit_final_dot = false) const;
400
412 void toWire(AbstractMessageRenderer& renderer) const;
413
424 void toWire(isc::util::OutputBuffer& buff) const;
426
430
431
444 NameComparisonResult compare(const Name& other) const;
445
446public:
460 bool equals(const Name& other) const;
461
463 bool operator==(const Name& other) const { return (equals(other)); }
464
470 bool nequals(const Name& other) const { return (!(equals(other))); }
471
473 bool operator!=(const Name& other) const { return (nequals(other)); }
474
484 bool leq(const Name& other) const;
485
487 bool operator<=(const Name& other) const { return (leq(other)); }
488
499 bool geq(const Name& other) const;
500
502 bool operator>=(const Name& other) const { return (geq(other)); }
503
513 bool lthan(const Name& other) const;
514
516 bool operator<(const Name& other) const { return (lthan(other)); }
517
527 bool gthan(const Name& other) const;
528
530 bool operator>(const Name& other) const { return (gthan(other)); }
532
536
537
564 Name split(unsigned int first, unsigned int n) const;
565
630 Name split(unsigned int level) const;
631
638 Name reverse() const;
639
653 Name concatenate(const Name& suffix) const;
654
676 Name& downcase();
678
682
683
687 bool isWildcard() const;
689
693
694
695 static const size_t MAX_WIRE = 255;
696
701 static const size_t MAX_LABELS = 128;
702
704 static const size_t MAX_LABELLEN = 63;
705
711 static const uint16_t MAX_COMPRESS_POINTER = 0x3fff;
713 static const uint16_t COMPRESS_POINTER_MARK8 = 0xc0;
715 static const uint16_t COMPRESS_POINTER_MARK16 = 0xc000;
717
721
722
723 static const Name& ROOT_NAME();
725
726private:
727 NameString ndata_;
728 NameOffsets offsets_;
729 unsigned int length_;
730 unsigned int labelcount_;
731};
732
733inline const Name&
734Name::ROOT_NAME() {
735 static Name root_name(".");
736 return (root_name);
737}
738
753std::ostream&
754 operator<<(std::ostream& os, const Name& name);
755
756}
757}
758#endif // NAME_H
buffer.h
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition exceptions/exceptions.cc:32
isc::OutOfRange
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
Definition exceptions/exceptions.h:115
isc::dns::AbstractMessageRenderer
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
Definition messagerenderer.h:69
isc::dns::BadEscape::BadEscape
BadEscape(const char *file, size_t line, const char *what)
Definition name.h:70
isc::dns::BadLabelType::BadLabelType
BadLabelType(const char *file, size_t line, const char *what)
Definition name.h:60
isc::dns::EmptyLabel::EmptyLabel
EmptyLabel(const char *file, size_t line, const char *what)
Definition name.h:28
isc::dns::IncompleteName::IncompleteName
IncompleteName(const char *file, size_t line, const char *what)
Definition name.h:83
isc::dns::MissingNameOrigin::MissingNameOrigin
MissingNameOrigin(const char *file, size_t line, const char *what)
Definition name.h:94
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::NameComparisonResult::getCommonLabels
unsigned int getCommonLabels() const
Returns the number of common labels of the comparison result.
Definition name.h:166
isc::dns::NameComparisonResult::getOrder
int getOrder() const
Returns the ordering of the comparison result.
Definition name.h:164
isc::dns::NameComparisonResult::NameComparisonResult
NameComparisonResult(int order, unsigned int nlabels, NameRelation relation)
Constructor from a comparison tuple.
Definition name.h:154
isc::dns::NameComparisonResult::getRelation
NameRelation getRelation() const
Returns the NameRelation of the comparison result.
Definition name.h:168
isc::dns::NameComparisonResult::NameRelation
NameRelation
The relation of two names under comparison.
Definition name.h:138
isc::dns::NameComparisonResult::SUBDOMAIN
@ SUBDOMAIN
Definition name.h:140
isc::dns::NameComparisonResult::COMMONANCESTOR
@ COMMONANCESTOR
Definition name.h:142
isc::dns::NameComparisonResult::SUPERDOMAIN
@ SUPERDOMAIN
Definition name.h:139
isc::dns::NameComparisonResult::EQUAL
@ EQUAL
Definition name.h:141
isc::dns::NameComparisonResult::NONE
@ NONE
Definition name.h:143
isc::dns::NameParserException::NameParserException
NameParserException(const char *file, size_t line, const char *what)
Definition dns/exceptions.h:45
isc::dns::Name
The Name class encapsulates DNS names.
Definition name.h:219
isc::dns::Name::MAX_LABELLEN
static const size_t MAX_LABELLEN
Max allowable length of labels of a domain name.
Definition name.h:704
isc::dns::Name::operator>=
bool operator>=(const Name &other) const
Same as geq().
Definition name.h:502
isc::dns::Name::MAX_COMPRESS_POINTER
static const uint16_t MAX_COMPRESS_POINTER
Max possible pointer value for name compression.
Definition name.h:711
isc::dns::Name::reverse
Name reverse() const
Reverse the labels of a name.
Definition name.cc:610
isc::dns::Name::lthan
bool lthan(const Name &other) const
Less-than comparison for Name against other.
Definition name.cc:559
isc::dns::Name::compare
NameComparisonResult compare(const Name &other) const
Compare two Names.
Definition name.cc:515
isc::dns::Name::equals
bool equals(const Name &other) const
Return true iff two names are equal.
Definition name.cc:522
isc::dns::Name::COMPRESS_POINTER_MARK16
static const uint16_t COMPRESS_POINTER_MARK16
A 16-bit masked value indicating a start of compression pointer.
Definition name.h:715
isc::dns::Name::geq
bool geq(const Name &other) const
Greater-than or equal comparison for Name against other.
Definition name.cc:554
isc::dns::Name::MAX_WIRE
static const size_t MAX_WIRE
Max allowable length of domain names.
Definition name.h:695
isc::dns::Name::split
Name split(unsigned int first, unsigned int n) const
Extract a specified subpart of Name.
Definition name.cc:639
isc::dns::Name::LabelSequence
friend class LabelSequence
Definition name.h:223
isc::dns::Name::nequals
bool nequals(const Name &other) const
Return true iff two names are not equal.
Definition name.h:470
isc::dns::Name::operator<
bool operator<(const Name &other) const
Same as lthan().
Definition name.h:516
isc::dns::Name::at
uint8_t at(size_t pos) const
Provides one-byte name data in wire format at the specified position.
Definition name.h:342
isc::dns::Name::operator!=
bool operator!=(const Name &other) const
Same as nequals().
Definition name.h:473
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::toWire
void toWire(AbstractMessageRenderer &renderer) const
Render the Name in the wire format with compression.
Definition name.cc:498
isc::dns::Name::operator>
bool operator>(const Name &other) const
Same as gthan().
Definition name.h:530
isc::dns::Name::getLabelCount
unsigned int getLabelCount() const
Returns the number of labels contained in the Name.
Definition name.h:366
isc::dns::Name::operator<=
bool operator<=(const Name &other) const
Same as leq().
Definition name.h:487
isc::dns::Name::MAX_LABELS
static const size_t MAX_LABELS
Max allowable labels of domain names.
Definition name.h:701
isc::dns::Name::gthan
bool gthan(const Name &other) const
Greater-than comparison for Name against other.
Definition name.cc:564
isc::dns::Name::operator==
bool operator==(const Name &other) const
Same as equals().
Definition name.h:463
isc::dns::Name::ROOT_NAME
static const Name & ROOT_NAME()
Root name (i.e. ".").
Definition name.h:734
isc::dns::Name::concatenate
Name concatenate(const Name &suffix) const
Concatenate two names.
Definition name.cc:574
isc::dns::Name::toRawText
std::string toRawText(bool omit_final_dot=false) const
Convert the LabelSequence to a string without escape sequences.
Definition name.cc:509
isc::dns::Name::getLength
size_t getLength() const
Gets the length of the Name in its wire format.
Definition name.h:356
isc::dns::Name::COMPRESS_POINTER_MARK8
static const uint16_t COMPRESS_POINTER_MARK8
A 8-bit masked value indicating a start of compression pointer.
Definition name.h:713
isc::dns::Name::leq
bool leq(const Name &other) const
Less-than or equal comparison for Name against other.
Definition name.cc:549
isc::dns::Name::downcase
Name & downcase()
Downcase all upper case alphabet characters in the name.
Definition name.cc:687
isc::dns::Name::isWildcard
bool isWildcard() const
Test if this is a wildcard name.
Definition name.cc:569
isc::dns::TooLongLabel::TooLongLabel
TooLongLabel(const char *file, size_t line, const char *what)
Definition name.h:48
isc::dns::TooLongName::TooLongName
TooLongName(const char *file, size_t line, const char *what)
Definition name.h:38
isc::util::InputBuffer
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition buffer.h:81
isc::util::OutputBuffer
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:346
exceptions.h
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
messagerenderer.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 agent_parser.cc:148