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 <util/buffer.h>
16 : : #include <dns/name.h>
17 : : #include <dns/rrset.h>
18 : : #include <dns/message.h>
19 : :
20 : : #include <cc/data.h>
21 : :
22 : : #include <datasrc/query.h>
23 : :
24 : : using namespace isc::dns;
25 : :
26 : : namespace isc {
27 : : namespace datasrc {
28 : :
29 : 66 : QueryTask::QueryTask(const Query& qry, const isc::dns::Name& n,
30 : : const isc::dns::RRType& t,
31 : : const isc::dns::Message::Section sect) :
32 : : q(qry), qname(n), qclass(qry.qclass()), qtype(t), section(sect),
33 : 66 : op(AUTH_QUERY), state(GETANSWER), flags(0)
34 : 66 : {}
35 : :
36 : 14 : QueryTask::QueryTask(const Query& qry, const isc::dns::Name& n,
37 : : const isc::dns::RRType& t,
38 : : const isc::dns::Message::Section sect,
39 : : const Op o) :
40 : : q(qry), qname(n), qclass(qry.qclass()), qtype(t), section(sect), op(o),
41 : 14 : state(GETANSWER), flags(0)
42 : 14 : {}
43 : :
44 : 26 : QueryTask::QueryTask(const Query& qry, const isc::dns::Name& n,
45 : : const isc::dns::RRType& t,
46 : : const isc::dns::Message::Section sect,
47 : : const State st) :
48 : : q(qry), qname(n), qclass(qry.qclass()), qtype(t), section(sect),
49 : 26 : op(AUTH_QUERY), state(st), flags(0)
50 : 26 : {}
51 : :
52 : 0 : QueryTask::QueryTask(const Query& qry, const isc::dns::Name& n,
53 : : const isc::dns::RRType& t,
54 : : const isc::dns::Message::Section sect,
55 : : const Op o, const State st) :
56 : : q(qry), qname(n), qclass(qry.qclass()), qtype(t), section(sect), op(o),
57 : 0 : state(st), flags(0)
58 : 0 : {}
59 : :
60 : 50 : QueryTask::QueryTask(const Query& qry, const isc::dns::Name& n,
61 : : const isc::dns::RRType& t, const Op o) :
62 : : q(qry), qname(n), qclass(qry.qclass()), qtype(t),
63 : 50 : section(Message::SECTION_ANSWER), op(o), state(GETANSWER), flags(0)
64 : : {
65 [ - + ]: 50 : if (op != SIMPLE_QUERY) {
66 [ # # ][ # # ]: 0 : isc_throw(Unexpected, "invalid constructor for this task operation");
67 : : }
68 : 50 : }
69 : :
70 : : // A referral query doesn't need to specify section, state, or type.
71 : 48 : QueryTask::QueryTask(const Query& qry, const isc::dns::Name& n, const Op o) :
72 : 48 : q(qry), qname(n), qclass(qry.qclass()), qtype(RRType::ANY()),
73 : 48 : section(Message::SECTION_ANSWER), op(o), state(GETANSWER), flags(0)
74 : : {
75 [ - + ]: 48 : if (op != REF_QUERY) {
76 [ # # ][ # # ]: 0 : isc_throw(Unexpected, "invalid constructor for this task operation");
77 : : }
78 : 48 : }
79 : :
80 : 83 : QueryTask::QueryTask(const Query& qry, const isc::dns::Name& n,
81 : : const isc::dns::Message::Section sect, const Op o,
82 : : const State st) :
83 : 83 : q(qry), qname(n), qclass(qry.qclass()), qtype(RRType::ANY()),
84 : 83 : section(sect), op(o), state(st), flags(0)
85 : : {
86 [ - + ]: 83 : if (op != GLUE_QUERY && op != NOGLUE_QUERY) {
87 [ # # ][ # # ]: 0 : isc_throw(Unexpected, "invalid constructor for this task operation");
88 : : }
89 : 83 : }
90 : :
91 : 287 : QueryTask::~QueryTask() {}
92 : :
93 : 66 : Query::Query(Message& m, HotCache& c, bool dnssec) :
94 : : status_(PENDING), qname_(NULL), qclass_(NULL), qtype_(NULL),
95 : 66 : cache_(&c), message_(&m), want_additional_(true), want_dnssec_(dnssec)
96 : : {
97 : : // Check message formatting
98 [ + - ][ - + ]: 66 : if (message_->getRRCount(Message::SECTION_QUESTION) != 1) {
99 [ # # ][ # # ]: 0 : isc_throw(Unexpected, "malformed message: too many questions");
100 : : }
101 : :
102 : : // Populate the query task queue with the initial question
103 [ + - ][ + - ]: 132 : QuestionPtr question = *message_->beginQuestion();
[ + - ]
104 : 66 : qname_ = &question->getName();
105 : 66 : qclass_ = &question->getClass();
106 : 66 : qtype_ = &question->getType();
107 : 66 : restarts_ = 0;
108 : :
109 : : querytasks_.push(QueryTaskPtr(new QueryTask(*this, *qname_, *qtype_,
110 [ + - ][ + - ]: 66 : Message::SECTION_ANSWER)));
111 : 66 : }
112 : :
113 : 66 : Query::~Query() {}
114 : :
115 : : }
116 : 107 : }
|