Kea 2.7.6
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 {
27public:
28 EmptyLabel(const char* file, size_t line, const char* what) :
29 NameParserException(file, line, what) {}
30};
31
37public:
38 TooLongName(const char* file, size_t line, const char* what) :
39 NameParserException(file, line, what) {}
40};
41
47public:
48 TooLongLabel(const char* file, size_t line, const char* what) :
49 NameParserException(file, line, what) {}
50};
51
59public:
60 BadLabelType(const char* file, size_t line, const char* what) :
61 NameParserException(file, line, what) {}
62};
63
69public:
70 BadEscape(const char* file, size_t line, const char* what) :
71 NameParserException(file, line, what) {}
72};
73
82public:
83 IncompleteName(const char* file, size_t line, const char* what) :
84 NameParserException(file, line, what) {}
85};
86
93public:
94 MissingNameOrigin(const char* file, size_t line, const char* what) :
95 NameParserException(file, line, what) {}
96};
97
114public:
145
149
150
154 NameComparisonResult(int order, unsigned int nlabels,
155 NameRelation relation) :
156 order_(order), nlabels_(nlabels), relation_(relation) {}
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
219class 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&
735 static Name root_name(".");
736 return (root_name);
737}
738
753std::ostream&
754operator<<(std::ostream& os, const Name& name);
755
756}
757}
758#endif // NAME_H
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
A standard DNS module exception that is thrown if the name parser fails to decode a back-slash escape...
Definition name.h:68
BadEscape(const char *file, size_t line, const char *what)
Definition name.h:70
A standard DNS module exception that is thrown if the name parser encounters an obsolete or incomplet...
Definition name.h:58
BadLabelType(const char *file, size_t line, const char *what)
Definition name.h:60
A standard DNS module exception that is thrown if the name parser encounters an empty label in the mi...
Definition name.h:26
EmptyLabel(const char *file, size_t line, const char *what)
Definition name.h:28
A standard DNS module exception that is thrown if the name parser finds the input (string or wire-for...
Definition name.h:81
IncompleteName(const char *file, size_t line, const char *what)
Definition name.h:83
Light-weight Accessor to Name data.
Thrown when origin is null and is needed.
Definition name.h:92
MissingNameOrigin(const char *file, size_t line, const char *what)
Definition name.h:94
This is a supplemental class used only as a return value of Name::compare() and LabelSequence::compar...
Definition name.h:113
unsigned int getCommonLabels() const
Returns the number of common labels of the comparison result.
Definition name.h:166
int getOrder() const
Returns the ordering of the comparison result.
Definition name.h:164
NameComparisonResult(int order, unsigned int nlabels, NameRelation relation)
Constructor from a comparison tuple.
Definition name.h:154
NameRelation getRelation() const
Returns the NameRelation of the comparison result.
Definition name.h:168
NameRelation
The relation of two names under comparison.
Definition name.h:138
Base class for name parser exceptions.
The Name class encapsulates DNS names.
Definition name.h:219
static const size_t MAX_LABELLEN
Max allowable length of labels of a domain name.
Definition name.h:704
bool operator>=(const Name &other) const
Same as geq()
Definition name.h:502
static const uint16_t MAX_COMPRESS_POINTER
Max possible pointer value for name compression.
Definition name.h:711
Name reverse() const
Reverse the labels of a name.
Definition name.cc:610
bool lthan(const Name &other) const
Less-than comparison for Name against other
Definition name.cc:559
NameComparisonResult compare(const Name &other) const
Compare two Names.
Definition name.cc:515
bool equals(const Name &other) const
Return true iff two names are equal.
Definition name.cc:522
static const uint16_t COMPRESS_POINTER_MARK16
A 16-bit masked value indicating a start of compression pointer.
Definition name.h:715
bool geq(const Name &other) const
Greater-than or equal comparison for Name against other
Definition name.cc:554
static const size_t MAX_WIRE
Max allowable length of domain names.
Definition name.h:695
Name split(unsigned int first, unsigned int n) const
Extract a specified subpart of Name.
Definition name.cc:639
bool nequals(const Name &other) const
Return true iff two names are not equal.
Definition name.h:470
bool operator<(const Name &other) const
Same as lthan()
Definition name.h:516
uint8_t at(size_t pos) const
Provides one-byte name data in wire format at the specified position.
Definition name.h:342
bool operator!=(const Name &other) const
Same as nequals()
Definition name.h:473
std::string toText(bool omit_final_dot=false) const
Convert the Name to a string.
Definition name.cc:503
void toWire(AbstractMessageRenderer &renderer) const
Render the Name in the wire format with compression.
Definition name.cc:498
bool operator>(const Name &other) const
Same as gthan()
Definition name.h:530
unsigned int getLabelCount() const
Returns the number of labels contained in the Name.
Definition name.h:366
bool operator<=(const Name &other) const
Same as leq()
Definition name.h:487
static const size_t MAX_LABELS
Max allowable labels of domain names.
Definition name.h:701
bool gthan(const Name &other) const
Greater-than comparison for Name against other
Definition name.cc:564
bool operator==(const Name &other) const
Same as equals()
Definition name.h:463
static const Name & ROOT_NAME()
Root name (i.e. ".").
Definition name.h:734
Name concatenate(const Name &suffix) const
Concatenate two names.
Definition name.cc:574
std::string toRawText(bool omit_final_dot=false) const
Convert the LabelSequence to a string without escape sequences.
Definition name.cc:509
size_t getLength() const
Gets the length of the Name in its wire format.
Definition name.h:356
static const uint16_t COMPRESS_POINTER_MARK8
A 8-bit masked value indicating a start of compression pointer.
Definition name.h:713
bool leq(const Name &other) const
Less-than or equal comparison for Name against other
Definition name.cc:549
Name & downcase()
Downcase all upper case alphabet characters in the name.
Definition name.cc:687
bool isWildcard() const
Test if this is a wildcard name.
Definition name.cc:569
A standard DNS module exception that is thrown if the name parser encounters too long a label.
Definition name.h:46
TooLongLabel(const char *file, size_t line, const char *what)
Definition name.h:48
A standard DNS module exception that is thrown if the name parser encounters too long a name.
Definition name.h:36
TooLongName(const char *file, size_t line, const char *what)
Definition name.h:38
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition buffer.h:81
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:343
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition edns.cc:163
Defines the logger used by the top-level component of kea-lfc.