Kea 2.5.5
rrclass.cc
Go to the documentation of this file.
1// Copyright (C) 2010-2015 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
9#include <stdint.h>
10
11#include <string>
12
14
15#include <util/buffer.h>
16#include <dns/messagerenderer.h>
17#include <dns/rrparamregistry.h>
18#include <dns/rrclass.h>
19
20using namespace std;
21using namespace isc::dns;
22using namespace isc::util;
23
24namespace isc {
25namespace dns {
26
27RRClass::RRClass(const std::string& class_str) {
28 uint16_t classcode;
29 if (!RRParamRegistry::getRegistry().textToClassCode(class_str, classcode)) {
31 "Unrecognized RR class string: " + class_str);
32 }
33 classcode_ = classcode;
34}
35
37 if (buffer.getLength() - buffer.getPosition() < sizeof(uint16_t)) {
38 isc_throw(IncompleteRRClass, "incomplete wire-format RR class");
39 }
40 classcode_ = buffer.readUint16();
41}
42
43const string
45 return (RRParamRegistry::getRegistry().codeToClassText(classcode_));
46}
47
48void
50 buffer.writeUint16(classcode_);
51}
52
53void
55 renderer.writeUint16(classcode_);
56}
57
59RRClass::createFromText(const string& class_str) {
60 uint16_t class_code;
61 if (RRParamRegistry::getRegistry().textToClassCode(class_str,
62 class_code)) {
63 return (new RRClass(class_code));
64 }
65 return (NULL);
66}
67
68ostream&
69operator<<(ostream& os, const RRClass& rrclass) {
70 os << rrclass.toText();
71 return (os);
72}
73}
74}
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:58
A standard DNS module exception that is thrown if an RRClass object is being constructed from an unre...
Definition: rrclass.h:48
The RRClass class encapsulates DNS resource record classes.
Definition: rrclass.h:98
void toWire(AbstractMessageRenderer &renderer) const
Render the RRClass in the wire format.
Definition: rrclass.cc:54
static RRClass * createFromText(const std::string &class_str)
A separate factory of RRClass from text.
Definition: rrclass.cc:59
const std::string toText() const
Convert the RRClass to a string.
Definition: rrclass.cc:44
RRClass(uint16_t classcode)
Constructor from an integer class code.
Definition: rrclass.h:109
static RRParamRegistry & getRegistry()
Return the singleton instance of RRParamRegistry.
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition: buffer.h:81
size_t getPosition() const
Return the current read position.
Definition: buffer.h:102
size_t getLength() const
Return the length of the data stored in the buffer.
Definition: buffer.h:100
uint16_t readUint16()
Read an unsigned 16-bit integer in network byte order from the buffer, convert it to host byte order,...
Definition: buffer.h:142
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
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:490
#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:172
Definition: edns.h:19
Defines the logger used by the top-level component of kea-lfc.