, SomeRR(..)
, A(..)
+ , AAAA(..)
, NS(..)
, MD(..)
, MF(..)
, HS(..)
, mkDomainName
- , mkDN
+ , rootName
+ , isRootName
+ , consLabel
+ , unconsLabel
+ , nameToLabels
, isZoneOf
, wrapQuestion
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as C8 hiding (ByteString)
import qualified Data.ByteString.Lazy as LBS
+import Data.String
import Data.Typeable
import qualified Data.IntMap as IM
import Data.IntMap (IntMap)
newtype DomainName = DN [DomainLabel] deriving (Eq, Show, Ord, Typeable)
type DomainLabel = BS.ByteString
+instance IsString DomainName where
+ fromString = mkDomainName
+
rootName :: DomainName
rootName = DN [BS.empty]
unconsLabel (DN (x:xs)) = (x, DN xs)
unconsLabel x = error ("Illegal use of unconsLabel: " ++ show x)
+nameToLabels :: DomainName -> [DomainLabel]
+nameToLabels (DN xs) = xs
+
isZoneOf :: DomainName -> DomainName -> Bool
isZoneOf (DN a) (DN b) = a `isSuffixOf` b
-> mkLabels (C8.pack l : soFar) rest
_ -> error ("Illegal domain name: " ++ xs)
-mkDN :: String -> DomainName
-mkDN = mkDomainName
-
class (Show rc, Eq rc, Typeable rc) => RecordClass rc where
rcToInt :: rc -> Int
putRecordData _ = P.putWord32be
getRecordData _ = U.getWord32be
+data AAAA = AAAA deriving (Show, Eq, Typeable)
+instance RecordType AAAA HostAddress6 where
+ rtToInt _ = 28
+ putRecordData _ = \ (a, b, c, d) ->
+ do P.putWord32be a
+ P.putWord32be b
+ P.putWord32be c
+ P.putWord32be d
+ getRecordData _ = do a <- U.getWord32be
+ b <- U.getWord32be
+ c <- U.getWord32be
+ d <- U.getWord32be
+ return (a, b, c, d)
+
data NS = NS deriving (Show, Eq, Typeable)
instance RecordType NS DomainName where
rtToInt _ = 2
defaultRTTable :: IntMap SomeRT
defaultRTTable = IM.fromList $ map toPair $
[ SomeRT A
+ , SomeRT AAAA
, SomeRT NS
, SomeRT MD
, SomeRT MF