SRV record construction
This commit is contained in:
parent
5544ca2fb8
commit
a11fb94c65
2 changed files with 15 additions and 4 deletions
|
@ -83,7 +83,7 @@ connectXMPP c a = case parseJID (xmppJID c) of
|
||||||
connectXMPP' :: JID -> XMPPCreds -> (JID -> XMPP a) -> IO (Either SomeException ())
|
connectXMPP' :: JID -> XMPPCreds -> (JID -> XMPP a) -> IO (Either SomeException ())
|
||||||
connectXMPP' jid c a = go =<< lookupSRV srvrecord
|
connectXMPP' jid c a = go =<< lookupSRV srvrecord
|
||||||
where
|
where
|
||||||
srvrecord = "_xmpp-client._tcp." ++ (T.unpack $ strDomain $ jidDomain jid)
|
srvrecord = mkSRVTcp "xmpp-client" (T.unpack $ strDomain $ jidDomain jid)
|
||||||
serverjid = JID Nothing (jidDomain jid) Nothing
|
serverjid = JID Nothing (jidDomain jid) Nothing
|
||||||
|
|
||||||
go [] = run (xmppHostname c)
|
go [] = run (xmppHostname c)
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
{-# LANGUAGE CPP #-}
|
{-# LANGUAGE CPP #-}
|
||||||
|
|
||||||
module Utility.SRV (
|
module Utility.SRV (
|
||||||
|
mkSRVTcp,
|
||||||
|
mkSRV,
|
||||||
lookupSRV,
|
lookupSRV,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
@ -30,12 +32,21 @@ import ADNS.Resolver
|
||||||
import Data.Either
|
import Data.Either
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
newtype SRV = SRV String
|
||||||
|
|
||||||
type HostPort = (HostName, PortID)
|
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.
|
{- Returns an ordered list, with highest priority hosts first.
|
||||||
-
|
-
|
||||||
- On error, returns an empty list. -}
|
- On error, returns an empty list. -}
|
||||||
lookupSRV :: HostName -> IO [HostPort]
|
lookupSRV :: SRV -> IO [HostPort]
|
||||||
#ifdef WITH_ADNS
|
#ifdef WITH_ADNS
|
||||||
lookupSRV srv = initResolver [] $ \resolver -> do
|
lookupSRV srv = initResolver [] $ \resolver -> do
|
||||||
r <- catchDefaultIO (Right []) $
|
r <- catchDefaultIO (Right []) $
|
||||||
|
@ -45,8 +56,8 @@ lookupSRV srv = initResolver [] $ \resolver -> do
|
||||||
lookupSRV = lookupSRVHost
|
lookupSRV = lookupSRVHost
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
lookupSRVHost :: HostName -> IO [HostPort]
|
lookupSRVHost :: SRV -> IO [HostPort]
|
||||||
lookupSRVHost srv
|
lookupSRVHost (SRV srv)
|
||||||
| Build.SysConfig.host = catchDefaultIO [] $
|
| Build.SysConfig.host = catchDefaultIO [] $
|
||||||
parseSrvHost <$> readProcessEnv "host" ["-t", "SRV", "--", srv]
|
parseSrvHost <$> readProcessEnv "host" ["-t", "SRV", "--", srv]
|
||||||
-- clear environment, to avoid LANG affecting output
|
-- clear environment, to avoid LANG affecting output
|
||||||
|
|
Loading…
Add table
Reference in a new issue