Skip to content

Commit

Permalink
exporting fromDNSFormat.
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Feb 19, 2014
1 parent 8d9ff9c commit fcbf800
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions Network/DNS/Resolver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ module Network.DNS.Resolver (
-- ** Type and function for resolver
, Resolver(..), withResolver, withResolvers
-- ** Looking up functions
, lookup, lookupAuth, lookupRaw
, lookup
, lookupAuth
-- ** Raw looking up function
, lookupRaw
, fromDNSFormat
) where

import Control.Applicative
Expand Down Expand Up @@ -199,20 +203,25 @@ lookupSection section rlv dom typ = do
eans <- lookupRaw rlv dom typ
case eans of
Left err -> return $ Left err
Right ans -> return $ case errcode ans of
NoErr -> Right $ toRDATA ans
FormatErr -> Left FormatError
ServFail -> Left ServerFailure
NameErr -> Left NameError
NotImpl -> Left NotImplemented
Refused -> Left OperationRefused
Right ans -> return $ fromDNSFormat ans toRDATA
where
{- CNAME hack
dom' = if "." `isSuffixOf` dom then dom else dom ++ "."
correct r = rrname r == dom' && rrtype r == typ
-}
correct r = rrtype r == typ
toRDATA = map rdata . filter correct . section

-- | Extract necessary information from 'DNSFormat'
fromDNSFormat :: DNSFormat -> (DNSFormat -> a) -> Either DNSError a
fromDNSFormat ans conv = case errcode ans of
NoErr -> Right $ conv ans
FormatErr -> Left FormatError
ServFail -> Left ServerFailure
NameErr -> Left NameError
NotImpl -> Left NotImplemented
Refused -> Left OperationRefused
where
errcode = rcode . flags . header

-- | Look up resource records for a domain, collecting the results
Expand Down

0 comments on commit fcbf800

Please sign in to comment.