summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Presence/Server.hs7
-rw-r--r--Presence/SockAddr.hs13
-rw-r--r--Presence/XMPPServer.hs22
-rw-r--r--xmppServer.hs53
4 files changed, 18 insertions, 77 deletions
diff --git a/Presence/Server.hs b/Presence/Server.hs
index abf9f5e3..fd5f1e43 100644
--- a/Presence/Server.hs
+++ b/Presence/Server.hs
@@ -63,16 +63,11 @@ import Network.BSD
63import Debug.Trace 63import Debug.Trace
64import Data.Time.Clock (UTCTime,getCurrentTime,diffUTCTime) 64import Data.Time.Clock (UTCTime,getCurrentTime,diffUTCTime)
65import Data.Time.Format (formatTime) 65import Data.Time.Format (formatTime)
66import SockAddr ()
66-- import System.Locale (defaultTimeLocale) 67-- import System.Locale (defaultTimeLocale)
67 68
68todo = error "unimplemented" 69todo = error "unimplemented"
69 70
70#if MIN_VERSION_network(2,4,0)
71#else
72deriving instance Ord SockAddr
73#endif
74
75
76type Microseconds = Int 71type Microseconds = Int
77type Miliseconds = Int 72type Miliseconds = Int
78type TimeOut = Miliseconds 73type TimeOut = Miliseconds
diff --git a/Presence/SockAddr.hs b/Presence/SockAddr.hs
new file mode 100644
index 00000000..91a03870
--- /dev/null
+++ b/Presence/SockAddr.hs
@@ -0,0 +1,13 @@
1{-# LANGUAGE CPP #-}
2{-# LANGUAGE StandaloneDeriving #-}
3module SockAddr () where
4
5import Network.Socket ( SockAddr(..) )
6
7#if MIN_VERSION_network(2,4,0)
8#else
9deriving instance Ord SockAddr
10#endif
11
12
13
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs
index f029810d..9059a4c0 100644
--- a/Presence/XMPPServer.hs
+++ b/Presence/XMPPServer.hs
@@ -66,17 +66,17 @@ import qualified Data.Map as Map
66import Data.Set (Set, (\\) ) 66import Data.Set (Set, (\\) )
67import qualified Data.Set as Set 67import qualified Data.Set as Set
68import qualified System.Random 68import qualified System.Random
69import qualified Network.BSD as BSD
70import Data.Void (Void) 69import Data.Void (Void)
71import System.Endian (toBE32) 70import System.Endian (toBE32)
72 71
73import GetHostByAddr (getHostByAddr) 72import ConnectionKey
74import qualified Control.Concurrent.STM.UpdateStream as Slotted 73import qualified Control.Concurrent.STM.UpdateStream as Slotted
75import Nesting 74import Nesting
76import Server 75import Server
77import EventUtil 76import EventUtil
78import ControlMaybe 77import ControlMaybe
79import LockedChan 78import LockedChan
79import PeerResolve
80 80
81withPort :: SockAddr -> Int -> SockAddr 81withPort :: SockAddr -> Int -> SockAddr
82withPort (SockAddrInet _ a) port = SockAddrInet (toEnum port) a 82withPort (SockAddrInet _ a) port = SockAddrInet (toEnum port) a
@@ -91,11 +91,6 @@ clientport = 5222
91my_uuid :: Text 91my_uuid :: Text
92my_uuid = "154ae29f-98f2-4af4-826d-a40c8a188574" 92my_uuid = "154ae29f-98f2-4af4-826d-a40c8a188574"
93 93
94data ConnectionKey
95 = PeerKey { callBackAddress :: SockAddr }
96 | ClientKey { localAddress :: SockAddr }
97 deriving (Show, Ord, Eq)
98
99data JabberShow = Offline 94data JabberShow = Offline
100 | ExtendedAway 95 | ExtendedAway
101 | Away 96 | Away
@@ -251,19 +246,6 @@ peerKeyToResolvedName pk = do
251 ns <- peerKeyToResolvedNames pk 246 ns <- peerKeyToResolvedNames pk
252 return $ maybe (peerKeyToText pk) id (listToMaybe ns) 247 return $ maybe (peerKeyToText pk) id (listToMaybe ns)
253 248
254peerKeyToResolvedNames :: ConnectionKey -> IO [Text]
255peerKeyToResolvedNames k@(ClientKey { localAddress=addr }) = return []
256peerKeyToResolvedNames k@(PeerKey { callBackAddress=addr }) = do
257 handleIO_ (return []) $ do
258 ent <- getHostByAddr (unmap6mapped4 addr) -- AF_UNSPEC addr
259 let names = BSD.hostName ent : BSD.hostAliases ent
260 return $ map Text.pack $ nub names
261
262unmap6mapped4 addr@(SockAddrInet6 port _ (0,0,0xFFFF,a) _) =
263 SockAddrInet port (toBE32 a)
264unmap6mapped4 addr = addr
265
266
267 249
268wlog :: String -> IO () 250wlog :: String -> IO ()
269wlog s = putStrLn s >> hFlush stdout 251wlog s = putStrLn s >> hFlush stdout
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