aboutsummaryrefslogtreecommitdiff
path: root/Utility/SRV.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-10-26 12:55:29 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-10-26 12:55:29 -0400
commit71a94e5cc6b1249998fe305a971604501e027c7b (patch)
tree287df99eb08831c11841dd3f93ecc157bbec66b0 /Utility/SRV.hs
parent89a33e4ce1219dff81f6c5fd296b6e6ba6866ea3 (diff)
hook up SRV lookups for XMPP
Diffstat (limited to 'Utility/SRV.hs')
-rw-r--r--Utility/SRV.hs15
1 files changed, 8 insertions, 7 deletions
diff --git a/Utility/SRV.hs b/Utility/SRV.hs
index 51d4360e2..c30c8bd86 100644
--- a/Utility/SRV.hs
+++ b/Utility/SRV.hs
@@ -35,7 +35,7 @@ type HostPort = (HostName, PortID)
{- Returns an ordered list, with highest priority hosts first.
-
- On error, returns an empty list. -}
-lookupSRV :: String -> IO [HostPort]
+lookupSRV :: HostName -> IO [HostPort]
#ifdef WITH_ADNS
lookupSRV srv = initResolver [] $ \resolver -> do
r <- catchDefaultIO (Right []) $
@@ -45,7 +45,7 @@ lookupSRV srv = initResolver [] $ \resolver -> do
lookupSRV = lookupSRVHost
#endif
-lookupSRVHost :: String -> IO [HostPort]
+lookupSRVHost :: HostName -> IO [HostPort]
lookupSRVHost srv
| Build.SysConfig.host = catchDefaultIO [] $
parseSrvHost <$> readProcessEnv "host" ["-t", "SRV", "--", srv]
@@ -54,16 +54,17 @@ lookupSRVHost srv
| otherwise = return []
parseSrvHost :: String -> [HostPort]
-parseSrvHost = map snd . reverse . sortBy priority . catMaybes . map parse . lines
+parseSrvHost = map snd . reverse . sortBy cost . catMaybes . map parse . lines
where
- priority = compare `on` fst
+ cost = compare `on` fst
parse l = case words l of
- [_, _, _, _, priority, weight, sport, hostname] ->
- case PortNumber . fromIntegral <$> readish sport of
+ [_, _, _, _, priority, weight, sport, hostname] -> do
+ let v = readish sport :: Maybe Int
+ case v of
Nothing -> Nothing
Just port -> Just
( (priority, weight)
- , (hostname, port)
+ , (hostname, PortNumber $ fromIntegral port)
)
_ -> Nothing