diff options
Diffstat (limited to 'xmppServer.hs')
-rw-r--r-- | xmppServer.hs | 53 |
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 | |||
7 | import Control.Monad.Trans.Resource (runResourceT) | 7 | import Control.Monad.Trans.Resource (runResourceT) |
8 | import Control.Monad.Trans | 8 | import Control.Monad.Trans |
9 | import Control.Monad.IO.Class (MonadIO, liftIO) | 9 | import Control.Monad.IO.Class (MonadIO, liftIO) |
10 | import Network.Socket | 10 | import Network.Socket ( SockAddr(..) ) |
11 | ( addrAddress | ||
12 | , getAddrInfo | ||
13 | , defaultHints | ||
14 | , addrFlags | ||
15 | , AddrInfoFlag(AI_CANONNAME,AI_V4MAPPED,AI_NUMERICHOST) | ||
16 | , SockAddr(..) | ||
17 | ) | ||
18 | import System.Endian (fromBE32) | 11 | import System.Endian (fromBE32) |
19 | import Data.List (nub, (\\), intersect, groupBy, sort ) | 12 | import Data.List (nub, (\\), intersect, groupBy, sort ) |
20 | import Data.Monoid ( (<>) ) | 13 | import Data.Monoid ( (<>) ) |
@@ -40,6 +33,7 @@ import TraversableT | |||
40 | import UTmp (ProcessID,users) | 33 | import UTmp (ProcessID,users) |
41 | import LocalPeerCred | 34 | import LocalPeerCred |
42 | import XMPPServer | 35 | import XMPPServer |
36 | import PeerResolve | ||
43 | 37 | ||
44 | type UserName = Text | 38 | type UserName = Text |
45 | type ResourceName = Text | 39 | type ResourceName = Text |
@@ -142,42 +136,6 @@ data PresenceState = PresenceState | |||
142 | } | 136 | } |
143 | 137 | ||
144 | 138 | ||
145 | make6mapped4 addr@(SockAddrInet6 {}) = addr | ||
146 | make6mapped4 addr@(SockAddrInet port a) = SockAddrInet6 port 0 (0,0,0xFFFF,fromBE32 a) 0 | ||
147 | |||
148 | resolvePeer :: Text -> IO [SockAddr] | ||
149 | resolvePeer 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 | |||
176 | strip_brackets s = | ||
177 | case Text.uncons s of | ||
178 | Just ('[',t) -> Text.takeWhile (/=']') t | ||
179 | _ -> s | ||
180 | |||
181 | 139 | ||
182 | getConsolePids :: PresenceState -> IO [(Text,ProcessID)] | 140 | getConsolePids :: PresenceState -> IO [(Text,ProcessID)] |
183 | getConsolePids state = do | 141 | getConsolePids 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 | ||
379 | parseAddress :: Text -> IO (Maybe SockAddr) | ||
380 | parseAddress 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 | |||
386 | todo = error "Unimplemented" | 337 | todo = error "Unimplemented" |
387 | 338 | ||
388 | 339 | ||