Kea  2.1.7-git
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 
13 #include <exceptions/exceptions.h>
14 
15 #include <util/buffer.h>
16 #include <dns/messagerenderer.h>
17 #include <dns/rrparamregistry.h>
18 #include <dns/rrclass.h>
19 
20 using namespace std;
21 using namespace isc::dns;
22 using namespace isc::util;
23 
24 namespace isc {
25 namespace dns {
26 
27 RRClass::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 
36 RRClass::RRClass(InputBuffer& buffer) {
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 
43 const string
44 RRClass::toText() const {
45  return (RRParamRegistry::getRegistry().codeToClassText(classcode_));
46 }
47 
48 void
49 RRClass::toWire(OutputBuffer& buffer) const {
50  buffer.writeUint16(classcode_);
51 }
52 
53 void
54 RRClass::toWire(AbstractMessageRenderer& renderer) const {
55  renderer.writeUint16(classcode_);
56 }
57 
58 RRClass*
59 RRClass::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 
68 ostream&
69 operator<<(ostream& os, const RRClass& rrclass) {
70  os << rrclass.toText();
71  return (os);
72 }
73 }
74 }
A standard DNS module exception that is thrown if an RRClass object is being constructed from a incom...
Definition: rrclass.h:58
size_t getPosition() const
Return the current read position.
Definition: buffer.h:102
STL namespace.
size_t getLength() const
Return the length of the data stored in the buffer.
Definition: buffer.h:100
The RRClass class encapsulates DNS resource record classes.
Definition: rrclass.h:98
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the internal buffer in network byte order...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A standard DNS module exception that is thrown if an RRClass object is being constructed from an unre...
Definition: rrclass.h:48
Definition: edns.h:19
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
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
Defines the logger used by the top-level component of kea-lfc.
ostream & operator<<(ostream &os, const RRClass &rrclass)
Insert the RRClass as a string into stream.
Definition: rrclass.cc:69
const std::string toText() const
Convert the RRClass to a string.
Definition: rrclass.cc:44
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
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition: buffer.h:81