Branch data Line data Source code
1 : : // Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
2 : : //
3 : : // Permission to use, copy, modify, and/or distribute this software for any
4 : : // purpose with or without fee is hereby granted, provided that the above
5 : : // copyright notice and this permission notice appear in all copies.
6 : : //
7 : : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
8 : : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9 : : // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
10 : : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11 : : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
12 : : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13 : : // PERFORMANCE OF THIS SOFTWARE.
14 : :
15 : : #include <iostream>
16 : : #include <string>
17 : :
18 : : #include <util/buffer.h>
19 : : #include <dns/messagerenderer.h>
20 : : #include <dns/name.h>
21 : : #include <dns/question.h>
22 : : #include <dns/rrclass.h>
23 : : #include <dns/rrtype.h>
24 : :
25 : : using namespace std;
26 : : using namespace isc::util;
27 : :
28 : : namespace isc {
29 : : namespace dns {
30 : 8 : Question::Question(InputBuffer& buffer) :
31 : 8 : name_(buffer), rrtype_(0), rrclass_(0)
32 : : {
33 : : // In theory, we could perform this in the member initialization list,
34 : : // and it would be a little bit more efficient. We don't do this, however,
35 : : // because the initialization ordering is crucial (type must be first)
36 : : // and the ordering in the initialization list depends on the appearance
37 : : // order of member variables. It's fragile to rely on such an implicit
38 : : // dependency, so we make the initialization order explicit.
39 [ + - ]: 6 : rrtype_ = RRType(buffer);
40 [ + + ]: 6 : rrclass_ = RRClass(buffer);
41 : 4 : }
42 : :
43 : : string
44 : 559 : Question::toText() const {
45 : 559 : return (name_.toText() + " " + rrclass_.toText() + " " +
46 [ + - ][ + - ]: 1118 : rrtype_.toText() + "\n");
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
47 : : }
48 : :
49 : : unsigned int
50 : 4 : Question::toWire(OutputBuffer& buffer) const {
51 : 4 : name_.toWire(buffer);
52 : 4 : rrtype_.toWire(buffer);
53 : 4 : rrclass_.toWire(buffer); // number of "entries", which is always 1
54 : :
55 : 4 : return (1);
56 : : }
57 : :
58 : : unsigned int
59 : 913 : Question::toWire(AbstractMessageRenderer& renderer) const {
60 : 913 : const size_t pos0 = renderer.getLength();
61 : :
62 : 913 : renderer.writeName(name_);
63 : 913 : rrtype_.toWire(renderer);
64 : 913 : rrclass_.toWire(renderer);
65 : :
66 : : // Make sure the renderer has a room for the question
67 [ + + ]: 913 : if (renderer.getLength() > renderer.getLengthLimit()) {
68 : 6 : renderer.trim(renderer.getLength() - pos0);
69 : 6 : renderer.setTruncated();
70 : 913 : return (0);
71 : : }
72 : :
73 : : return (1); // number of "entries"
74 : : }
75 : :
76 : : ostream&
77 : 1 : operator<<(std::ostream& os, const Question& question) {
78 [ + - ]: 1 : os << question.toText();
79 : 1 : return (os);
80 : : }
81 : : }
82 : 137 : }
|