anchor.diff:  -include("erldns.hrl").
   
   -export([resolve/3]).
  -
  -%% Internal API
  --export([resolve/6]).
  --export([requires_additional_processing/2, additional_processing/3, additional_processing/4]).
  -
   
   %% Resolve the questions in the message.
   resolve(Message, AuthorityRecords, Host) ->
  
positive.code: restart_query(Message, Name, Qtype, Host, CnameChain, _Zone, false) ->
    resolve(Message, Name, Qtype, erldns_zone_cache:find_zone(Name), Host, CnameChain).
  
  restart_delegated_query(Message, Name, Qtype, Host, CnameChain, Zone, true) ->
    resolve(Message, Name, Qtype, Zone, Host, CnameChain);
  restart_delegated_query(Message, Name, Qtype, Host, CnameChain, Zone, false) ->
    resolve(Message, Name, Qtype, erldns_zone_cache:find_zone(Name, Zone#zone.authority), Host, CnameChain). % Zone lookup
  
  
negative.code:       end
    end.
  
  %% We are authoritative and there were no NS records here.
  resolve_exact_type_match(Message, _Qname, _Qtype, _Host, _CnameChain, MatchedRecords, _Zone, _AuthorityRecords, []) ->
    Message#dns_message{aa = true, rc = ?DNS_RCODE_NOERROR, answers = Message#dns_message.answers ++ MatchedRecords};
  
  %% We are authoritative and there are NS records here.
  resolve_exact_type_match(Message, _Qname, Qtype, Host, CnameChain, MatchedRecords, Zone, _AuthorityRecords, NSRecords) ->
    Answer = lists:last(MatchedRecords),
    NSRecord = lists:last(NSRecords),
    Name = NSRecord#dns_rr.name,
    case Name =:= Answer#dns_rr.name of
      true ->
        Message#dns_message{aa = false, rc = ?DNS_RCODE_NOERROR, authority = Message#dns_message.authority ++ NSRecords};
      false ->
        restart_delegated_query(Message, Name, Qtype, Host, CnameChain, Zone, erldns_zone_cache:in_zone(Name))
    end.
  
  