Code critique please

Jarrod Roberson jarrod@REDACTED
Tue Dec 1 05:35:23 CET 2009


is there anything that I can do to improve this code? Are the nested case of
the best way to do that? It was the only thing I could get to work.

% test to see if a dns_rr.domain is subscribed to
is_subscribed(_,[]) -> false;
is_subscribed(Dom,[S|Rest]) ->
    case lists:suffix(S,Dom) of
        true ->
            {ok,S};
        false ->
            is_subscribed(Dom,Rest)
    end.

% process the list of resource records one at a time
process_dnsrec1(Sub,[]) -> Sub;
process_dnsrec1(Sub,[Response|Rest]) ->
  Dom = Response#dns_rr.domain,
  Key = {Response#dns_rr.domain,Response#dns_rr.type,Response#dns_rr.class},
  case is_subscribed(Dom,dict:fetch_keys(Sub)) of
	  {ok,SD} ->
		  {ok,Value} = dict:find(SD,Sub),
          % if the ttl == Zero then we forget about the details for that server
          case Response#dns_rr.ttl == 0 of
              true ->
                  NewSub = dict:store(SD,dict:new(),Sub),
                  process_dnsrec1(NewSub,[]);
              false ->
                  % update the dns_rr to the current timestamp
                  NewRR = Response#dns_rr{tm=get_timestamp()},
                  NewValue = dict:store(Key,NewRR,Value),
                  NewSub = dict:store(SD,NewValue,Sub),
                  process_dnsrec1(NewSub,Rest)
          end;
     false ->
          process_dnsrec1(Sub,Rest)
  end.

the entire source can be seen here ->
http://github.com/fuzzylollipop/inet_mdns/blob/master/src/inet_mdns.erl


More information about the erlang-questions mailing list