Kea 2.5.8
rrclass.cc
Go to the documentation of this file.
1// Copyright (C) 2010-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#include <config.h>
8
10#include <dns/messagerenderer.h>
11#include <dns/rrparamregistry.h>
12#include <dns/rrclass.h>
13#include <util/buffer.h>
14
15#include <stdint.h>
16#include <string>
17
18using namespace isc::dns;
19using namespace isc::util;
20
21using namespace std;
22
23namespace isc {
24namespace dns {
25
26RRClass::RRClass(const std::string& class_str) {
27 uint16_t classcode;
28 if (!RRParamRegistry::getRegistry().textToClassCode(class_str, classcode)) {
30 "Unrecognized RR class string: " + class_str);
31 }
32 classcode_ = classcode;
33}
34
36 if (buffer.getLength() - buffer.getPosition() < sizeof(uint16_t)) {
37 isc_throw(IncompleteRRClass, "incomplete wire-format RR class");
38 }
39 classcode_ = buffer.readUint16();
40}
41
42const string
44 return (RRParamRegistry::getRegistry().codeToClassText(classcode_));
45}
46
47void
49 buffer.writeUint16(classcode_);
50}
51
52void
54 renderer.writeUint16(classcode_);
55}
56
58RRClass::createFromText(const string& class_str) {
59 uint16_t class_code;
60 if (RRParamRegistry::getRegistry().textToClassCode(class_str,
61 class_code)) {
62 return (new RRClass(class_code));
63 }
64 return (0);
65}
66
67ostream&
68operator<<(ostream& os, const RRClass& rrclass) {
69 os << rrclass.toText();
70 return (os);
71}
72}
73}
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the internal buffer in network byte order.
A standard DNS module exception that is thrown if an RRClass object is being constructed from a incom...
Definition: rrclass.h:49
A standard DNS module exception that is thrown if an RRClass object is being constructed from an unre...
Definition: rrclass.h:39
The RRClass class encapsulates DNS resource record classes.
Definition: rrclass.h:89
void toWire(AbstractMessageRenderer &renderer) const
Render the RRClass in the wire format.
Definition: rrclass.cc:53
static RRClass * createFromText(const std::string &class_str)
A separate factory of RRClass from text.
Definition: rrclass.cc:58
const std::string toText() const
Convert the RRClass to a string.
Definition: rrclass.cc:43
RRClass(uint16_t classcode)
Constructor from an integer class code.
Definition: rrclass.h:100
static RRParamRegistry & getRegistry()
Return the singleton instance of RRParamRegistry.
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition: buffer.h:82
size_t getPosition() const
Return the current read position.
Definition: buffer.h:101
size_t getLength() const
Return the length of the data stored in the buffer.
Definition: buffer.h:96
uint16_t readUint16()
Read an unsigned 16-bit integer in network byte order from the buffer, and return it.
Definition: buffer.h:167
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:347
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the buffer in network byte order.
Definition: buffer.h:498
#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.