Kea 1.5.0
labelsequence.h
Go to the documentation of this file.
1// Copyright (C) 2012-2018 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
13namespace isc {
14namespace dns {
15
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 =
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
126 data_(ls.data_),
127 offsets_(ls.offsets_),
128 first_label_(ls.first_label_),
129 last_label_(ls.last_label_)
130 {}
131
145 const uint8_t* getData(size_t* len) const;
146
161 size_t getDataLength() const;
162
172 size_t getSerializedLength() const;
173
228 void serialize(void* buf, size_t buf_len) const;
229
239 bool equals(const LabelSequence& other, bool case_sensitive = false) const;
240
247 bool operator==(const LabelSequence& other) const {
248 return (equals(other));
249 }
250
261 bool case_sensitive = false) const;
262
272 void stripLeft(size_t i);
273
283 void stripRight(size_t i);
284
288 size_t getLabelCount() const {
289 return (last_label_ - first_label_ + 1);
290 }
291
306 std::string toText() const;
307
316 std::string toRawText(bool omit_final_dot) const;
317
347 void extend(const LabelSequence& labels,
348 uint8_t buf[MAX_SERIALIZED_LENGTH]);
349
350private:
363 std::string toText(bool omit_final_dot) const;
364public:
388 size_t getHash(bool case_sensitive) const;
389
393 bool isAbsolute() const;
394
395private:
396 const uint8_t* data_; // wire-format name data
397 const uint8_t* offsets_; // an array of offsets in data_ for the labels
398 size_t first_label_; // index of offsets_ for the first label
399 size_t last_label_; // index of offsets_ for the last label.
400 // can be equal to first_label_, but must not
401 // be smaller (the class ensures that)
402};
403
404
419std::ostream&
420operator<<(std::ostream& os, const LabelSequence& label_sequence);
421
422inline const LabelSequence&
424 static const uint8_t wildcard_buf[4] = { 0x01, 0x00, 0x01, '*' };
425 static const LabelSequence wild_ls(wildcard_buf);
426 return (wild_ls);
427}
428
429} // end namespace dns
430} // end namespace isc
431
432#endif
433
434// Local Variables:
435// mode: c++
436// End:
Light-weight Accessor to Name data.
Definition: labelsequence.h:35
std::string toRawText(bool omit_final_dot) const
Convert the LabelSequence to a string without escape sequences.
LabelSequence(const LabelSequence &ls)
Copy constructor.
static const size_t MAX_SERIALIZED_LENGTH
Max possible size of serialized image generated by serialize.
Definition: labelsequence.h:45
size_t getHash(bool case_sensitive) const
Calculate a simple hash for the label sequence.
void serialize(void *buf, size_t buf_len) const
Serialize the LabelSequence object in to a buffer.
NameComparisonResult compare(const LabelSequence &other, bool case_sensitive=false) const
Compares two label sequences.
bool isAbsolute() const
Checks whether the label sequence is absolute.
LabelSequence(const Name &name)
Constructs a LabelSequence for the given name.
Definition: labelsequence.h:64
bool operator==(const LabelSequence &other) const
Compares two label sequences for equality (case ignored).
bool equals(const LabelSequence &other, bool case_sensitive=false) const
Compares two label sequences for equality.
size_t getLabelCount() const
Returns the current number of labels for this LabelSequence.
size_t getSerializedLength() const
Return the size of serialized image of the LabelSequence.
static const LabelSequence & WILDCARD()
Wildcard label ("*")
void stripLeft(size_t i)
Remove labels from the front of this LabelSequence.
const uint8_t * getData(size_t *len) const
Return the wire-format data for this LabelSequence.
friend std::string Name::toText(bool) const
void stripRight(size_t i)
Remove labels from the end of this LabelSequence.
size_t getDataLength() const
Return the length of the wire-format data of this LabelSequence.
void extend(const LabelSequence &labels, uint8_t buf[MAX_SERIALIZED_LENGTH])
Extend this LabelSequence with the given labelsequence.
This is a supplemental class used only as a return value of Name::compare() and LabelSequence::compar...
Definition: name.h:117
The Name class encapsulates DNS names.
Definition: name.h:223
static const size_t MAX_WIRE
Max allowable length of domain names.
Definition: name.h:699
std::string toText(bool omit_final_dot=false) const
Convert the Name to a string.
Definition: name.cc:507
static const size_t MAX_LABELS
Max allowable labels of domain names.
Definition: name.h:705
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition: edns.cc:172
Defines the logger used by the top-level component of kea-dhcp-ddns.