Kea  1.9.9-git
question.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 <iostream>
10 #include <string>
11 
12 #include <util/buffer.h>
13 #include <dns/messagerenderer.h>
14 #include <dns/name.h>
15 #include <dns/question.h>
16 #include <dns/rrclass.h>
17 #include <dns/rrtype.h>
18 
19 using namespace std;
20 using namespace isc::util;
21 
22 namespace isc {
23 namespace dns {
24 Question::Question(InputBuffer& buffer) :
25  name_(buffer), rrtype_(0), rrclass_(0)
26 {
27  // In theory, we could perform this in the member initialization list,
28  // and it would be a little bit more efficient. We don't do this, however,
29  // because the initialization ordering is crucial (type must be first)
30  // and the ordering in the initialization list depends on the appearance
31  // order of member variables. It's fragile to rely on such an implicit
32  // dependency, so we make the initialization order explicit.
33  rrtype_ = RRType(buffer);
34  rrclass_ = RRClass(buffer);
35 }
36 
37 std::string
38 Question::toText(bool newline) const {
39  std::string r(name_.toText() + " " + rrclass_.toText() + " " +
40  rrtype_.toText());
41  if (newline) {
42  r.append("\n");
43  }
44 
45  return (r);
46 }
47 
48 unsigned int
50  name_.toWire(buffer);
51  rrtype_.toWire(buffer);
52  rrclass_.toWire(buffer); // number of "entries", which is always 1
53 
54  return (1);
55 }
56 
57 unsigned int
59  const size_t pos0 = renderer.getLength();
60 
61  renderer.writeName(name_);
62  rrtype_.toWire(renderer);
63  rrclass_.toWire(renderer);
64 
65  // Make sure the renderer has a room for the question
66  if (renderer.getLength() > renderer.getLengthLimit()) {
67  renderer.trim(renderer.getLength() - pos0);
68  renderer.setTruncated();
69  return (0);
70  }
71 
72  return (1); // number of "entries"
73 }
74 
75 ostream&
76 operator<<(std::ostream& os, const Question& question) {
77  os << question.toText();
78  return (os);
79 }
80 }
81 }
const RRClass & rrclass_
Definition: dns/message.cc:695
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition: edns.cc:172
virtual void writeName(const Name &name, bool compress=true)=0
Write a Name object into the internal buffer in wire format, with or without name compression...
The Question class encapsulates the common search key of DNS lookup, consisting of owner name...
Definition: question.h:95
std::string toText(bool omit_final_dot=false) const
Convert the Name to a string.
Definition: name.cc:507
STL namespace.
void trim(size_t len)
Trim the specified length of data from the end of the internal buffer.
const RRType & rrtype_
Definition: dns/message.cc:694
The RRClass class encapsulates DNS resource record classes.
Definition: rrclass.h:98
const std::string toText() const
Convert the RRType to a string.
Definition: rrtype.cc:45
Definition: edns.h:19
unsigned int toWire(AbstractMessageRenderer &renderer) const
Render the Question in the wire format with name compression.
Definition: question.cc:58
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
virtual void setTruncated()=0
Mark the renderer to indicate truncation has occurred while rendering.
const std::string toText() const
Convert the RRClass to a string.
Definition: rrclass.cc:44
void toWire(AbstractMessageRenderer &renderer) const
Render the RRType in the wire format.
Definition: rrtype.cc:55
void toWire(AbstractMessageRenderer &renderer) const
Render the RRClass in the wire format.
Definition: rrclass.cc:54
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
Defines the logger used by the top-level component of kea-dhcp-ddns.
std::string toText(bool newline=false) const
Convert the Question to a string.
Definition: question.cc:38
const Name & name_
Definition: dns/message.cc:693
The RRType class encapsulates DNS resource record types.
Definition: rrtype.h:106
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition: buffer.h:81
size_t getLength() const
Return the length of data written in the internal buffer.
virtual size_t getLengthLimit() const =0
Return the maximum length of rendered data that can fit in the corresponding DNS message without trun...
void toWire(AbstractMessageRenderer &renderer) const
Render the Name in the wire format with compression.
Definition: name.cc:502