Kea  1.9.9-git
labelsequence.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2020 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 
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 =
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 
126  data_(ls.data_),
127  offsets_(ls.offsets_),
128  first_label_(ls.first_label_),
129  last_label_(ls.last_label_)
130  {}
131 
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 
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 
370 private:
383  std::string toText(bool omit_final_dot) const;
384 public:
408  size_t getHash(bool case_sensitive) const;
409 
413  bool isAbsolute() const;
414 
415 private:
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 
439 std::ostream&
440 operator<<(std::ostream& os, const LabelSequence& label_sequence);
441 
442 inline const LabelSequence&
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
453 
454 // Local Variables:
455 // mode: c++
456 // End:
The Name class encapsulates DNS names.
Definition: name.h:223
LabelSequence(const Name &name)
Constructs a LabelSequence for the given name.
Definition: labelsequence.h:64
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition: edns.cc:172
std::string toText() const
Convert the LabelSequence to a string.
static const size_t MAX_SERIALIZED_LENGTH
Max possible size of serialized image generated by serialize.
Definition: labelsequence.h:45
std::string toRawText(bool omit_final_dot) const
Convert the LabelSequence to a string without escape sequences.
std::string toText(bool omit_final_dot=false) const
Convert the Name to a string.
Definition: name.cc:507
size_t getLabelCount() const
Returns the current number of labels for this LabelSequence.
LabelSequence & operator=(const LabelSequence &other)
Assignment operator.
This is a supplemental class used only as a return value of Name::compare() and LabelSequence::compar...
Definition: name.h:117
void extend(const LabelSequence &labels, uint8_t buf[MAX_SERIALIZED_LENGTH])
Extend this LabelSequence with the given labelsequence.
static const size_t MAX_WIRE
Max allowable length of domain names.
Definition: name.h:699
bool operator==(const LabelSequence &other) const
Compares two label sequences for equality (case ignored).
size_t getHash(bool case_sensitive) const
Calculate a simple hash for the label sequence.
size_t getDataLength() const
Return the length of the wire-format data of this LabelSequence.
void stripRight(size_t i)
Remove labels from the end of this LabelSequence.
Defines the logger used by the top-level component of kea-dhcp-ddns.
const uint8_t * getData(size_t *len) const
Return the wire-format data for this LabelSequence.
static const LabelSequence & WILDCARD()
Wildcard label ("*")
void serialize(void *buf, size_t buf_len) const
Serialize the LabelSequence object in to a buffer.
bool isAbsolute() const
Checks whether the label sequence is absolute.
size_t getSerializedLength() const
Return the size of serialized image of the LabelSequence.
static const size_t MAX_LABELS
Max allowable labels of domain names.
Definition: name.h:705
bool equals(const LabelSequence &other, bool case_sensitive=false) const
Compares two label sequences for equality.
LabelSequence(const LabelSequence &ls)
Copy constructor.
void stripLeft(size_t i)
Remove labels from the front of this LabelSequence.
NameComparisonResult compare(const LabelSequence &other, bool case_sensitive=false) const
Compares two label sequences.
Light-weight Accessor to Name data.
Definition: labelsequence.h:35