Kea 2.7.5
question.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/name.h>
11#include <dns/question.h>
12#include <dns/rrclass.h>
13#include <dns/rrtype.h>
14#include <util/buffer.h>
15
16#include <iostream>
17#include <string>
18
19using namespace isc::util;
20
21using namespace std;
22
23namespace isc {
24namespace dns {
26 name_(buffer), rrtype_(0), rrclass_(0) {
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
37std::string
38Question::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
48uint32_t
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
57uint32_t
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
75ostream&
76operator<<(std::ostream& os, const Question& question) {
77 os << question.toText();
78 return (os);
79}
80}
81}
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
std::string toText(bool omit_final_dot=false) const
Convert the Name to a string.
Definition name.cc:503
void toWire(AbstractMessageRenderer &renderer) const
Render the Name in the wire format with compression.
Definition name.cc:498
The Question class encapsulates the common search key of DNS lookup, consisting of owner name,...
Definition question.h:88
std::string toText(bool newline=false) const
Convert the Question to a string.
Definition question.cc:38
uint32_t toWire(AbstractMessageRenderer &renderer) const
Render the Question in the wire format with name compression.
Definition question.cc:58
Question(isc::util::InputBuffer &buff)
Constructor from wire-format data.
Definition question.cc:25
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
const std::string toText() const
Convert the RRClass to a string.
Definition rrclass.cc:43
The RRType class encapsulates DNS resource record types.
Definition rrtype.h:96
void toWire(AbstractMessageRenderer &renderer) const
Render the RRType in the wire format.
Definition rrtype.cc:54
const std::string toText() const
Convert the RRType to a string.
Definition rrtype.cc:44
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition buffer.h:81
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:343
const RRClass & rrclass_
const Name & name_
const RRType & rrtype_
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.