LCOV - code coverage report
Current view: top level - datasrc - zone_finder_context.cc (source / functions) Hit Total Coverage
Test: report.info Lines: 34 34 100.0 %
Date: 2012-05-15 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 46 64 71.9 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2012  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 <dns/rdata.h>
      16                 :            : #include <dns/rrset.h>
      17                 :            : #include <dns/rrtype.h>
      18                 :            : #include <dns/rdataclass.h>
      19                 :            : 
      20                 :            : #include <datasrc/zone.h>
      21                 :            : 
      22                 :            : #include <boost/foreach.hpp>
      23                 :            : 
      24                 :            : #include <vector>
      25                 :            : 
      26                 :            : using namespace std;
      27                 :            : using namespace isc::dns;
      28                 :            : using namespace isc::dns::rdata;
      29                 :            : 
      30                 :            : namespace isc {
      31                 :            : namespace datasrc {
      32                 :            : 
      33                 :            : namespace {
      34                 :            : void
      35                 :        151 : getAdditionalAddrs(ZoneFinder& finder, const Name& name,
      36                 :            :                    const vector<RRType>& requested_types,
      37                 :            :                    vector<ConstRRsetPtr>& result_rrsets,
      38                 :            :                    ZoneFinder::FindOptions options)
      39                 :            : {
      40                 :            :     // Ignore out-of-zone names
      41         [ +  - ]:        151 :     const NameComparisonResult cmp = finder.getOrigin().compare(name);
      42 [ +  + ][ -  + ]:        151 :     if ((cmp.getRelation() != NameComparisonResult::SUPERDOMAIN) &&
                 [ +  + ]
      43                 :         41 :         (cmp.getRelation() != NameComparisonResult::EQUAL)) {
      44                 :        151 :         return;
      45                 :            :     }
      46                 :            : 
      47 [ +  + ][ +  - ]:        506 :     BOOST_FOREACH(RRType rrtype, requested_types) {
         [ +  - ][ +  + ]
                 [ +  + ]
      48                 :        198 :         ConstZoneFinderContextPtr ctx = finder.find(name, rrtype, options);
      49         [ +  + ]:        198 :         if (ctx->code == ZoneFinder::SUCCESS) {
      50                 :        246 :             result_rrsets.push_back(ctx->rrset);
      51                 :            :         }
      52                 :            :     }
      53                 :            : }
      54                 :            : 
      55                 :            : void
      56                 :         88 : getAdditionalForRRset(ZoneFinder& finder, const AbstractRRset& rrset,
      57                 :            :                       const vector<RRType>& requested_types,
      58                 :            :                       vector<ConstRRsetPtr>& result,
      59                 :            :                       ZoneFinder::FindOptions orig_options)
      60                 :            : {
      61                 :         88 :     RdataIteratorPtr rdata_iterator(rrset.getRdataIterator());
      62                 :         88 :     ZoneFinder::FindOptions options = ZoneFinder::FIND_DEFAULT;
      63         [ +  + ]:         88 :     if ((orig_options & ZoneFinder::FIND_DNSSEC) != 0) {
      64                 :         88 :         options = options | ZoneFinder::FIND_DNSSEC;
      65                 :            :     }
      66                 :            : 
      67 [ +  - ][ +  - ]:        266 :     for (; !rdata_iterator->isLast(); rdata_iterator->next()) {
                 [ +  + ]
      68         [ +  - ]:        178 :         const Rdata& rdata(rdata_iterator->getCurrent());
      69                 :            : 
      70 [ +  - ][ +  + ]:        178 :         if (rrset.getType() == RRType::NS()) {
      71                 :            :             // Need to perform the search in the "GLUE OK" mode.
      72         [ +  - ]:        131 :             const generic::NS& ns = dynamic_cast<const generic::NS&>(rdata);
      73         [ +  - ]:        131 :             getAdditionalAddrs(finder, ns.getNSName(), requested_types,
      74         [ +  - ]:        131 :                                result, options | ZoneFinder::FIND_GLUE_OK);
      75 [ +  - ][ +  + ]:         47 :         } else if (rrset.getType() == RRType::MX()) {
      76         [ +  - ]:         20 :             const generic::MX& mx = dynamic_cast<const generic::MX&>(rdata);
      77         [ +  - ]:         20 :             getAdditionalAddrs(finder, mx.getMXName(), requested_types,
      78         [ +  - ]:         20 :                                result, options);
      79                 :            :         }
      80                 :            :     }
      81                 :         88 : }
      82                 :            : }
      83                 :            : 
      84                 :            : void
      85                 :         82 : ZoneFinder::Context::getAdditionalImpl(const vector<RRType>& requested_types,
      86                 :            :                                        vector<ConstRRsetPtr>& result)
      87                 :            : {
      88                 :            :     // If rrset is non NULL, it should have been SUCCESS/DELEGATION; otherwise
      89                 :            :     // we should have responded to type ANY query.
      90         [ +  + ]:         82 :     if (rrset) {
      91                 :         78 :         getAdditionalForRRset(finder_, *rrset, requested_types, result,
      92                 :         78 :                               options_);
      93                 :         82 :         return;
      94                 :            :     }
      95   [ +  +  +  - ]:         44 :     BOOST_FOREACH(ConstRRsetPtr rrset_in_set, all_set_) {
         [ +  - ][ +  + ]
                 [ +  + ]
      96                 :         10 :         getAdditionalForRRset(finder_, *rrset_in_set, requested_types, result,
      97         [ +  - ]:         10 :                               options_);
      98                 :            :     }
      99                 :            : }
     100                 :            : 
     101                 :            : } // namespace datasrc
     102                 :        107 : } // datasrc isc

Generated by: LCOV version 1.9