summaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-10-26 13:03:08 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-10-26 13:03:08 -0400
commit0c01a949a686aadb2596434cf92990c715ad84a7 (patch)
tree6e8f42ccee6fea0a27b0dd9597ec88a049025a14 /Utility
parent71a94e5cc6b1249998fe305a971604501e027c7b (diff)
SRV record construction
Diffstat (limited to 'Utility')
-rw-r--r--Utility/SRV.hs17
1 files changed, 14 insertions, 3 deletions
diff --git a/Utility/SRV.hs b/Utility/SRV.hs
index c30c8bd86..38ac28787 100644
--- a/Utility/SRV.hs
+++ b/Utility/SRV.hs
@@ -11,6 +11,8 @@
{-# LANGUAGE CPP #-}
module Utility.SRV (
+ mkSRVTcp,
+ mkSRV,
lookupSRV,
) where
@@ -30,12 +32,21 @@ import ADNS.Resolver
import Data.Either
#endif
+newtype SRV = SRV String
+
type HostPort = (HostName, PortID)
+mkSRV :: String -> String -> HostName -> SRV
+mkSRV transport protocol host = SRV $ concat
+ ["_", protocol, ".", transport, ".", host]
+
+mkSRVTcp :: String -> HostName -> SRV
+mkSRVTcp = mkSRV "tcp"
+
{- Returns an ordered list, with highest priority hosts first.
-
- On error, returns an empty list. -}
-lookupSRV :: HostName -> IO [HostPort]
+lookupSRV :: SRV -> IO [HostPort]
#ifdef WITH_ADNS
lookupSRV srv = initResolver [] $ \resolver -> do
r <- catchDefaultIO (Right []) $
@@ -45,8 +56,8 @@ lookupSRV srv = initResolver [] $ \resolver -> do
lookupSRV = lookupSRVHost
#endif
-lookupSRVHost :: HostName -> IO [HostPort]
-lookupSRVHost srv
+lookupSRVHost :: SRV -> IO [HostPort]
+lookupSRVHost (SRV srv)
| Build.SysConfig.host = catchDefaultIO [] $
parseSrvHost <$> readProcessEnv "host" ["-t", "SRV", "--", srv]
-- clear environment, to avoid LANG affecting output