Browse Source

[1747] pull out target and additional vectors

Jelte Jansen 13 years ago
parent
commit
70c188de44
3 changed files with 30 additions and 9 deletions
  1. 6 8
      src/bin/auth/query.cc
  2. 7 1
      src/bin/auth/query.h
  3. 17 0
      src/bin/auth/tests/query_unittest.cc

+ 6 - 8
src/bin/auth/query.cc

@@ -411,13 +411,11 @@ Query::process() {
     // indirectly via delegation).  Look into the zone.
     response_->setHeaderFlag(Message::HEADERFLAG_AA);
     response_->setRcode(Rcode::NOERROR());
-    vector<ConstRRsetPtr> target;
-    vector<ConstRRsetPtr> additionals;
     boost::function0<ZoneFinderContextPtr> find;
     const bool qtype_is_any = (qtype_ == RRType::ANY());
     if (qtype_is_any) {
         find = boost::bind(&ZoneFinder::findAll, &zfinder, qname_,
-                           boost::ref(target), dnssec_opt_);
+                           boost::ref(target_), dnssec_opt_);
     } else {
         find = boost::bind(&ZoneFinder::find, &zfinder, qname_, qtype_,
                            dnssec_opt_);
@@ -491,7 +489,7 @@ Query::process() {
             if (qtype_is_any) {
                 // If quety type is ANY, insert all RRs under the domain
                 // into answer section.
-                BOOST_FOREACH(ConstRRsetPtr rrset, target) {
+                BOOST_FOREACH(ConstRRsetPtr rrset, target_) {
                     response_->addRRset(Message::SECTION_ANSWER,
                         boost::const_pointer_cast<AbstractRRset>(rrset), dnssec_);
                 }
@@ -502,7 +500,7 @@ Query::process() {
             }
 
             // Retrieve additional records for the answer
-            getAdditional(qname_, qtype_, *db_context, additionals);
+            getAdditional(qname_, qtype_, *db_context, additionals_);
 
             // If apex NS records haven't been provided in the answer
             // section, insert apex NS records into the authority section
@@ -514,7 +512,7 @@ Query::process() {
                 db_context->code != ZoneFinder::SUCCESS ||
                 (qtype_ != RRType::NS() && !qtype_is_any))
             {
-                addAuthAdditional(*result.zone_finder, additionals);
+                addAuthAdditional(*result.zone_finder, additionals_);
             }
 
             // If the answer is a result of wildcard substitution,
@@ -537,7 +535,7 @@ Query::process() {
                 boost::const_pointer_cast<AbstractRRset>(db_context->rrset),
                 dnssec_);
             // Retrieve additional records for the name servers
-            db_context->getAdditional(A_AND_AAAA(), additionals);
+            db_context->getAdditional(A_AND_AAAA(), additionals_);
 
             // If DNSSEC is requested, see whether there is a DS
             // record for this delegation.
@@ -570,7 +568,7 @@ Query::process() {
             break;
     }
 
-    for_each(additionals.begin(), additionals.end(),
+    for_each(additionals_.begin(), additionals_.end(),
              RRsetInserter(*response_, Message::SECTION_ADDITIONAL,
                            dnssec_));
 }

+ 7 - 1
src/bin/auth/query.h

@@ -351,7 +351,7 @@ public:
     void
     reset(datasrc::DataSourceClient* datasrc_client,
           const isc::dns::Name qname, const isc::dns::RRType qtype,
-          isc::dns::Message* response, bool dnssec) {
+          isc::dns::Message* response, bool dnssec = false) {
         datasrc_client_ = datasrc_client;
         qname_ = qname;
         qtype_ = qtype;
@@ -359,6 +359,9 @@ public:
         dnssec_ = dnssec;
         dnssec_opt_ = (dnssec ?  isc::datasrc::ZoneFinder::FIND_DNSSEC :
                        isc::datasrc::ZoneFinder::FIND_DEFAULT);
+
+        target_.clear();
+        additionals_.clear();
     }
 
 private:
@@ -368,6 +371,9 @@ private:
     isc::dns::Message* response_;
     bool dnssec_;
     isc::datasrc::ZoneFinder::FindOptions dnssec_opt_;
+
+    std::vector<isc::dns::ConstRRsetPtr> target_;
+    std::vector<isc::dns::ConstRRsetPtr> additionals_;
 };
 
 }

+ 17 - 0
src/bin/auth/tests/query_unittest.cc

@@ -959,6 +959,23 @@ TEST_F(QueryTest, exactMatch) {
                   www_a_txt, zone_ns_txt, ns_addrs_txt);
 }
 
+TEST_F(QueryTest, exactMatchMultipleQueries) {
+    Query query(&memory_client, qname, qtype, &response);
+    EXPECT_NO_THROW(query.process());
+    // find match rrset
+    responseCheck(response, Rcode::NOERROR(), AA_FLAG, 1, 3, 3,
+                  www_a_txt, zone_ns_txt, ns_addrs_txt);
+    response.clear(isc::dns::Message::RENDER);
+    response.setRcode(Rcode::NOERROR());
+    response.setOpcode(Opcode::QUERY());
+    query.reset(&memory_client, qname, qtype, &response);
+    EXPECT_NO_THROW(query.process());
+    // find match rrset
+    SCOPED_TRACE("Second query");
+    responseCheck(response, Rcode::NOERROR(), AA_FLAG, 1, 3, 3,
+                  www_a_txt, zone_ns_txt, ns_addrs_txt);
+}
+
 TEST_F(QueryTest, exactMatchIgnoreSIG) {
     // Check that we do not include the RRSIG when not requested even when
     // we receive it from the data source.