+import Network.DNS.DomainMap (DomainMap)
import Network.DNS.Message
import Network.DNS.Named
import Network.DNS.Named.Config
import Network.Socket.IsString ()
main :: IO ()
-main = runNamed cnf (return . findZone)
+main = runNamed cnf zones
where
cnf :: Config
cnf = Config {
, cnfAllowTransfer = True
}
- findZone :: DomainName -> Maybe Zone
- findZone name
- | name `isInZone` zone = Just zone
- | otherwise = Nothing
-
- zone :: Zone
- zone = Zone {
- zoneName = "cielonegro.org."
- , zoneSOA = Just SOAFields {
- soaMasterNameServer = "ns.cielonegro.org."
- , soaResponsibleMailbox = "root.ns.cielonegro.org."
- , soaSerialNumber = 2008022148
- , soaRefreshInterval = 3600
- , soaRetryInterval = 900
- , soaExpirationLimit = 3600000
- , soaMinimumTTL = 3600
- }
- , zoneRecordNames = return [ "ns.cielonegro.org."
- , "www.cielonegro.org."
- , "git.cielonegro.org."
- ]
- , zoneResponder = return . responder
- }
+ zones :: DomainMap Zone
+ zones = fromZones
+ [ Zone {
+ zoneName = "cielonegro.org."
+ , zoneSOA = Just SOAFields {
+ soaMasterNameServer = "ns.cielonegro.org."
+ , soaResponsibleMailbox = "root.ns.cielonegro.org."
+ , soaSerialNumber = 2008022148
+ , soaRefreshInterval = 3600
+ , soaRetryInterval = 900
+ , soaExpirationLimit = 3600000
+ , soaMinimumTTL = 3600
+ }
+ , zoneRecordNames = return [ "ns.cielonegro.org."
+ , "www.cielonegro.org."
+ , "git.cielonegro.org."
+ ]
+ , zoneResponder = return . responder
+ }
+ ]
responder :: DomainName -> [SomeRR]
responder name
module Network.DNS.Named.Zone
- ( Zone(..)
+ ( ZoneFinder(..)
+ , fromZones
+
+ , Zone(..)
, isInZone
, zoneSOARecord
import Data.Maybe
import Network.DNS.Message
+import Network.DNS.DomainMap
+
+
+class ZoneFinder a where
+ findZone :: a -> DomainName -> IO (Maybe Zone)
+
+instance ZoneFinder (DomainMap Zone) where
+ findZone = (return .) . flip nearest
+
+instance ZoneFinder (IO (DomainMap Zone)) where
+ findZone = flip (fmap . nearest)
+
+instance ZoneFinder (DomainName -> Maybe Zone) where
+ findZone = (return .)
+
+instance ZoneFinder (DomainName -> IO (Maybe Zone)) where
+ findZone = id
+
+
+fromZones :: [Zone] -> DomainMap Zone
+fromZones = fromList . map toPair
+ where
+ toPair z = (zoneName z, z)
data Zone