summaryrefslogtreecommitdiff
path: root/xmppServer.hs
diff options
context:
space:
mode:
Diffstat (limited to 'xmppServer.hs')
-rw-r--r--xmppServer.hs53
1 files changed, 2 insertions, 51 deletions
diff --git a/xmppServer.hs b/xmppServer.hs
index 3752218a..f7f7fb36 100644
--- a/xmppServer.hs
+++ b/xmppServer.hs
@@ -7,14 +7,7 @@ import Control.Concurrent.STM.TMVar
7import Control.Monad.Trans.Resource (runResourceT) 7import Control.Monad.Trans.Resource (runResourceT)
8import Control.Monad.Trans 8import Control.Monad.Trans
9import Control.Monad.IO.Class (MonadIO, liftIO) 9import Control.Monad.IO.Class (MonadIO, liftIO)
10import Network.Socket 10import Network.Socket ( SockAddr(..) )
11 ( addrAddress
12 , getAddrInfo
13 , defaultHints
14 , addrFlags
15 , AddrInfoFlag(AI_CANONNAME,AI_V4MAPPED,AI_NUMERICHOST)
16 , SockAddr(..)
17 )
18import System.Endian (fromBE32) 11import System.Endian (fromBE32)
19import Data.List (nub, (\\), intersect, groupBy, sort ) 12import Data.List (nub, (\\), intersect, groupBy, sort )
20import Data.Monoid ( (<>) ) 13import Data.Monoid ( (<>) )
@@ -40,6 +33,7 @@ import TraversableT
40import UTmp (ProcessID,users) 33import UTmp (ProcessID,users)
41import LocalPeerCred 34import LocalPeerCred
42import XMPPServer 35import XMPPServer
36import PeerResolve
43 37
44type UserName = Text 38type UserName = Text
45type ResourceName = Text 39type ResourceName = Text
@@ -142,42 +136,6 @@ data PresenceState = PresenceState
142 } 136 }
143 137
144 138
145make6mapped4 addr@(SockAddrInet6 {}) = addr
146make6mapped4 addr@(SockAddrInet port a) = SockAddrInet6 port 0 (0,0,0xFFFF,fromBE32 a) 0
147
148resolvePeer :: Text -> IO [SockAddr]
149resolvePeer addrtext = do
150 r <- atomically newEmptyTMVar
151 mvar <- atomically newEmptyTMVar
152 rt <- forkOS $ resolver r mvar
153 tt <- forkIO $ timer r rt
154 atomically $ putTMVar mvar tt
155 atomically $ readTMVar r
156 where
157 resolver r mvar = do
158 xs <- handle (\e -> let _ = isDoesNotExistError e in return [])
159 $ do fmap (map $ make6mapped4 . addrAddress) $
160 getAddrInfo (Just $ defaultHints { addrFlags = [ AI_CANONNAME, AI_V4MAPPED ]})
161 (Just $ Text.unpack $ strip_brackets addrtext)
162 (Just "5269")
163 did <- atomically $ tryPutTMVar r xs
164 when did $ do
165 tt <- atomically $ readTMVar mvar
166 throwTo tt (ErrorCall "Interrupted delay")
167 return ()
168 timer r rt = do
169 handle (\(ErrorCall _)-> return ()) $ do
170 threadDelay 1000000
171 did <- atomically $ tryPutTMVar r []
172 when did $ do
173 putStrLn $ "timeout resolving: "++show addrtext
174 killThread rt
175
176strip_brackets s =
177 case Text.uncons s of
178 Just ('[',t) -> Text.takeWhile (/=']') t
179 _ -> s
180
181 139
182getConsolePids :: PresenceState -> IO [(Text,ProcessID)] 140getConsolePids :: PresenceState -> IO [(Text,ProcessID)]
183getConsolePids state = do 141getConsolePids state = do
@@ -376,13 +334,6 @@ rewriteJIDForClient1 jid = do
376 return $ Just ((n,h',r), addr) 334 return $ Just ((n,h',r), addr)
377-} 335-}
378 336
379parseAddress :: Text -> IO (Maybe SockAddr)
380parseAddress addr_str = do
381 info <- getAddrInfo (Just $ defaultHints { addrFlags = [ AI_NUMERICHOST ] })
382 (Just . Text.unpack $ addr_str)
383 (Just "0")
384 return . listToMaybe $ map addrAddress info
385
386todo = error "Unimplemented" 337todo = error "Unimplemented"
387 338
388 339