Kea: name.h Source File

| Kea 2.2.0

name.h
Go to the documentation of this file.
1// Copyright (C) 2009-2019 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 1
9
10#include <stdint.h>
11
12#include <string>
13#include <vector>
14
15#include <dns/exceptions.h>
16
17namespace isc {
18namespace util {
19class InputBuffer;
20class OutputBuffer;
21}
22
23namespace dns {
24class AbstractMessageRenderer;
25
30 class EmptyLabel : public NameParserException {
31public:
32 EmptyLabel(const char* file, size_t line, const char* what) :
33 NameParserException(file, line, what) {}
34};
35
40 class TooLongName : public NameParserException {
41public:
42 TooLongName(const char* file, size_t line, const char* what) :
43 NameParserException(file, line, what) {}
44};
45
50 class TooLongLabel : public NameParserException {
51public:
52 TooLongLabel(const char* file, size_t line, const char* what) :
53 NameParserException(file, line, what) {}
54};
55
62 class BadLabelType : public NameParserException {
63public:
64 BadLabelType(const char* file, size_t line, const char* what) :
65 NameParserException(file, line, what) {}
66};
67
72 class BadEscape : public NameParserException {
73public:
74 BadEscape(const char* file, size_t line, const char* what) :
75 NameParserException(file, line, what) {}
76};
77
85 class IncompleteName : public NameParserException {
86public:
87 IncompleteName(const char* file, size_t line, const char* what) :
88 NameParserException(file, line, what) {}
89};
90
96 class MissingNameOrigin : public NameParserException {
97public:
98 MissingNameOrigin(const char* file, size_t line, const char* what) :
99 NameParserException(file, line, what) {}
100};
101
117 class NameComparisonResult {
118public:
142 enum NameRelation {
143 SUPERDOMAIN = 0,
144 SUBDOMAIN = 1,
145 EQUAL = 2,
146 COMMONANCESTOR = 3,
147 NONE = 4
148 };
149
153
154
158 NameComparisonResult(int order, unsigned int nlabels,
159 NameRelation relation) :
160 order_(order), nlabels_(nlabels), relation_(relation) {}
162
166
167
168 int getOrder() const { return (order_); }
170 unsigned int getCommonLabels() const { return (nlabels_); }
172 NameRelation getRelation() const { return (relation_); }
174private:
175 int order_;
176 unsigned int nlabels_;
177 NameRelation relation_;
178};
179
223 class Name {
224 // LabelSequences use knowledge about the internal data structure
225 // of this class for efficiency (they use the offsets_ vector and
226 // the ndata_ string)
227 friend class LabelSequence;
228
232
233private:
235 typedef std::basic_string<uint8_t> NameString;
237 typedef std::vector<uint8_t> NameOffsets;
238
245 Name() : length_(0), labelcount_(0) {}
246public:
257 explicit Name(const std::string& namestr, bool downcase = false);
258
286 Name(const char* name_data, size_t data_len, const Name* origin,
287 bool downcase = false);
288
305 explicit Name(isc::util::InputBuffer& buffer, bool downcase = false);
308
309
311
315
316
346 uint8_t at(size_t pos) const
347 {
348 if (pos >= length_) {
349 isc_throw(OutOfRange, "Out of range access in Name::at()");
350 }
351 return (ndata_[pos]);
352 }
353
360 size_t getLength() const { return (length_); }
361
370 unsigned int getLabelCount() const { return (labelcount_); }
372
376
377
390 //
393 std::string toText(bool omit_final_dot = false) const;
394
403 std::string toRawText(bool omit_final_dot = false) const;
404
416 void toWire(AbstractMessageRenderer& renderer) const;
417
428 void toWire(isc::util::OutputBuffer& buffer) const;
430
434
435
448 NameComparisonResult compare(const Name& other) const;
449
450public:
464 bool equals(const Name& other) const;
465
467 bool operator==(const Name& other) const { return (equals(other)); }
468
474 bool nequals(const Name& other) const { return (!(equals(other))); }
475
477 bool operator!=(const Name& other) const { return (nequals(other)); }
478
488 bool leq(const Name& other) const;
489
491 bool operator<=(const Name& other) const { return (leq(other)); }
492
503 bool geq(const Name& other) const;
504
506 bool operator>=(const Name& other) const { return (geq(other)); }
507
517 bool lthan(const Name& other) const;
518
520 bool operator<(const Name& other) const { return (lthan(other)); }
521
531 bool gthan(const Name& other) const;
532
534 bool operator>(const Name& other) const { return (gthan(other)); }
536
540
541
568 Name split(unsigned int first, unsigned int n) const;
569
634 Name split(unsigned int level) const;
635
642 Name reverse() const;
643
657 Name concatenate(const Name& suffix) const;
658
680 Name& downcase();
682
686
687
691 bool isWildcard() const;
693
697
698
699 static const size_t MAX_WIRE = 255;
700
705 static const size_t MAX_LABELS = 128;
706
708 static const size_t MAX_LABELLEN = 63;
709
715 static const uint16_t MAX_COMPRESS_POINTER = 0x3fff;
717 static const uint16_t COMPRESS_POINTER_MARK8 = 0xc0;
719 static const uint16_t COMPRESS_POINTER_MARK16 = 0xc000;
721
725
726
727 static const Name& ROOT_NAME();
729
730private:
731 NameString ndata_;
732 NameOffsets offsets_;
733 unsigned int length_;
734 unsigned int labelcount_;
735};
736
737inline const Name&
738Name::ROOT_NAME() {
739 static Name root_name(".");
740 return (root_name);
741}
742
757std::ostream&
758 operator<<(std::ostream& os, const Name& name);
759
760}
761}
762#endif // NAME_H
763
764// Local Variables:
765// mode: c++
766// End:
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:68
isc::dns::BadEscape
A standard DNS module exception that is thrown if the name parser fails to decode a back-slash escape...
Definition: name.h:72
isc::dns::BadEscape::BadEscape
BadEscape(const char *file, size_t line, const char *what)
Definition: name.h:74
isc::dns::BadLabelType
A standard DNS module exception that is thrown if the name parser encounters an obsolete or incomplet...
Definition: name.h:62
isc::dns::BadLabelType::BadLabelType
BadLabelType(const char *file, size_t line, const char *what)
Definition: name.h:64
isc::dns::EmptyLabel
A standard DNS module exception that is thrown if the name parser encounters an empty label in the mi...
Definition: name.h:30
isc::dns::EmptyLabel::EmptyLabel
EmptyLabel(const char *file, size_t line, const char *what)
Definition: name.h:32
isc::dns::IncompleteName
A standard DNS module exception that is thrown if the name parser finds the input (string or wire-for...
Definition: name.h:85
isc::dns::IncompleteName::IncompleteName
IncompleteName(const char *file, size_t line, const char *what)
Definition: name.h:87
isc::dns::LabelSequence
Light-weight Accessor to Name data.
Definition: labelsequence.h:35
isc::dns::MissingNameOrigin
Thrown when origin is NULL and is needed.
Definition: name.h:96
isc::dns::MissingNameOrigin::MissingNameOrigin
MissingNameOrigin(const char *file, size_t line, const char *what)
Definition: name.h:98
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::dns::NameComparisonResult::getCommonLabels
unsigned int getCommonLabels() const
Returns the number of common labels of the comparison result.
Definition: name.h:170
isc::dns::NameComparisonResult::getOrder
int getOrder() const
Returns the ordering of the comparison result.
Definition: name.h:168
isc::dns::NameComparisonResult::NameComparisonResult
NameComparisonResult(int order, unsigned int nlabels, NameRelation relation)
Constructor from a comparison tuple.
Definition: name.h:158
isc::dns::NameComparisonResult::getRelation
NameRelation getRelation() const
Returns the NameRelation of the comparison result.
Definition: name.h:172
isc::dns::NameComparisonResult::NameRelation
NameRelation
The relation of two names under comparison.
Definition: name.h:142
isc::dns::NameComparisonResult::SUBDOMAIN
@ SUBDOMAIN
Definition: name.h:144
isc::dns::NameComparisonResult::COMMONANCESTOR
@ COMMONANCESTOR
Definition: name.h:146
isc::dns::NameComparisonResult::SUPERDOMAIN
@ SUPERDOMAIN
Definition: name.h:143
isc::dns::NameComparisonResult::EQUAL
@ EQUAL
Definition: name.h:145
isc::dns::NameComparisonResult::NONE
@ NONE
Definition: name.h:147
isc::dns::NameParserException
Base class for name parser exceptions.
Definition: dns/exceptions.h:43
isc::dns::Name
The Name class encapsulates DNS names.
Definition: name.h:223
isc::dns::Name::MAX_LABELLEN
static const size_t MAX_LABELLEN
Max allowable length of labels of a domain name.
Definition: name.h:708
isc::dns::Name::operator>=
bool operator>=(const Name &other) const
Same as geq()
Definition: name.h:506
isc::dns::Name::MAX_COMPRESS_POINTER
static const uint16_t MAX_COMPRESS_POINTER
Max possible pointer value for name compression.
Definition: name.h:715
isc::dns::Name::reverse
Name reverse() const
Reverse the labels of a name.
Definition: name.cc:614
isc::dns::Name::lthan
bool lthan(const Name &other) const
Less-than comparison for Name against other
Definition: name.cc:563
isc::dns::Name::compare
NameComparisonResult compare(const Name &other) const
Compare two Names.
Definition: name.cc:519
isc::dns::Name::equals
bool equals(const Name &other) const
Return true iff two names are equal.
Definition: name.cc:526
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:719
isc::dns::Name::geq
bool geq(const Name &other) const
Greater-than or equal comparison for Name against other
Definition: name.cc:558
isc::dns::Name::MAX_WIRE
static const size_t MAX_WIRE
Max allowable length of domain names.
Definition: name.h:699
isc::dns::Name::split
Name split(unsigned int first, unsigned int n) const
Extract a specified subpart of Name.
Definition: name.cc:643
isc::dns::Name::nequals
bool nequals(const Name &other) const
Return true iff two names are not equal.
Definition: name.h:474
isc::dns::Name::operator<
bool operator<(const Name &other) const
Same as lthan()
Definition: name.h:520
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:346
isc::dns::Name::operator!=
bool operator!=(const Name &other) const
Same as nequals()
Definition: name.h:477
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::Name::toWire
void toWire(AbstractMessageRenderer &renderer) const
Render the Name in the wire format with compression.
Definition: name.cc:502
isc::dns::Name::operator>
bool operator>(const Name &other) const
Same as gthan()
Definition: name.h:534
isc::dns::Name::getLabelCount
unsigned int getLabelCount() const
Returns the number of labels contained in the Name.
Definition: name.h:370
isc::dns::Name::operator<=
bool operator<=(const Name &other) const
Same as leq()
Definition: name.h:491
isc::dns::Name::MAX_LABELS
static const size_t MAX_LABELS
Max allowable labels of domain names.
Definition: name.h:705
isc::dns::Name::gthan
bool gthan(const Name &other) const
Greater-than comparison for Name against other
Definition: name.cc:568
isc::dns::Name::operator==
bool operator==(const Name &other) const
Same as equals()
Definition: name.h:467
isc::dns::Name::ROOT_NAME
static const Name & ROOT_NAME()
Root name (i.e. ".").
Definition: name.h:738
isc::dns::Name::concatenate
Name concatenate(const Name &suffix) const
Concatenate two names.
Definition: name.cc:578
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:513
isc::dns::Name::getLength
size_t getLength() const
Gets the length of the Name in its wire format.
Definition: name.h:360
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:717
isc::dns::Name::leq
bool leq(const Name &other) const
Less-than or equal comparison for Name against other
Definition: name.cc:553
isc::dns::Name::downcase
Name & downcase()
Downcase all upper case alphabet characters in the name.
Definition: name.cc:690
isc::dns::Name::isWildcard
bool isWildcard() const
Test if this is a wildcard name.
Definition: name.cc:573
isc::dns::TooLongLabel
A standard DNS module exception that is thrown if the name parser encounters too long a label.
Definition: name.h:50
isc::dns::TooLongLabel::TooLongLabel
TooLongLabel(const char *file, size_t line, const char *what)
Definition: name.h:52
isc::dns::TooLongName
A standard DNS module exception that is thrown if the name parser encounters too long a name.
Definition: name.h:40
isc::dns::TooLongName::TooLongName
TooLongName(const char *file, size_t line, const char *what)
Definition: name.h:42
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:294
exceptions.h
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition: exceptions/exceptions.h:210
isc::dns::operator<<
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition: edns.cc:172
isc
Defines the logger used by the top-level component of kea-lfc.
Definition: agent_parser.cc:143