summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Presence/XMPPServer.hs15
-rw-r--r--xmppServer.hs18
2 files changed, 27 insertions, 6 deletions
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs
index dd693b8c..af392f27 100644
--- a/Presence/XMPPServer.hs
+++ b/Presence/XMPPServer.hs
@@ -16,6 +16,7 @@ module XMPPServer
16 , LangSpecificMessage(..) 16 , LangSpecificMessage(..)
17 , peerKeyToText 17 , peerKeyToText
18 , peerKeyToResolvedName 18 , peerKeyToResolvedName
19 , peerKeyToResolvedNames
19 , addrToText 20 , addrToText
20 , sendModifiedStanzaToPeer 21 , sendModifiedStanzaToPeer
21 , sendModifiedStanzaToClient 22 , sendModifiedStanzaToClient
@@ -50,6 +51,7 @@ import qualified Text.XML.Stream.Render as XML
50import qualified Text.XML.Stream.Parse as XML 51import qualified Text.XML.Stream.Parse as XML
51import Data.XML.Types as XML 52import Data.XML.Types as XML
52import Data.Maybe 53import Data.Maybe
54import Data.List (nub)
53import Data.Monoid ( (<>) ) 55import Data.Monoid ( (<>) )
54import Data.Text (Text) 56import Data.Text (Text)
55import qualified Data.Text as Text (pack,unpack) 57import qualified Data.Text as Text (pack,unpack)
@@ -227,12 +229,17 @@ peerKeyToText (ClientKey { localAddress=addr }) = "ErrorClIeNt0"
227 229
228peerKeyToResolvedName :: ConnectionKey -> IO Text 230peerKeyToResolvedName :: ConnectionKey -> IO Text
229peerKeyToResolvedName k@(ClientKey { localAddress=addr }) = return "ErrorClIeNt1" 231peerKeyToResolvedName k@(ClientKey { localAddress=addr }) = return "ErrorClIeNt1"
230peerKeyToResolvedName k@(PeerKey { callBackAddress=addr }) = do 232peerKeyToResolvedName pk = do
231 mname <- handleIO_ (return Nothing) $ do 233 ns <- peerKeyToResolvedNames pk
234 return $ maybe (peerKeyToText pk) id (listToMaybe ns)
235
236peerKeyToResolvedNames :: ConnectionKey -> IO [Text]
237peerKeyToResolvedNames k@(ClientKey { localAddress=addr }) = return []
238peerKeyToResolvedNames k@(PeerKey { callBackAddress=addr }) = do
239 handleIO_ (return []) $ do
232 ent <- getHostByAddr addr -- AF_UNSPEC addr 240 ent <- getHostByAddr addr -- AF_UNSPEC addr
233 let names = BSD.hostName ent : BSD.hostAliases ent 241 let names = BSD.hostName ent : BSD.hostAliases ent
234 return $ listToMaybe names 242 return $ map Text.pack $ nub names
235 return $ maybe (peerKeyToText k) Text.pack mname
236 243
237 244
238wlog :: String -> IO () 245wlog :: String -> IO ()
diff --git a/xmppServer.hs b/xmppServer.hs
index 8fdb4f78..107054bf 100644
--- a/xmppServer.hs
+++ b/xmppServer.hs
@@ -294,6 +294,7 @@ newConn state k addr outchan = do
294 294
295eofConn state k = atomically $ modifyTVar' (keyToChan state) $ Map.delete k 295eofConn state k = atomically $ modifyTVar' (keyToChan state) $ Map.delete k
296 296
297{-
297rewriteJIDForClient1:: Text -> IO (Maybe ((Maybe Text,Text,Maybe Text),SockAddr)) 298rewriteJIDForClient1:: Text -> IO (Maybe ((Maybe Text,Text,Maybe Text),SockAddr))
298rewriteJIDForClient1 jid = do 299rewriteJIDForClient1 jid = do
299 let (n,h,r) = splitJID jid 300 let (n,h,r) = splitJID jid
@@ -301,6 +302,7 @@ rewriteJIDForClient1 jid = do
301 flip (maybe $ return Nothing) maddr $ \addr -> do 302 flip (maybe $ return Nothing) maddr $ \addr -> do
302 h' <- peerKeyToResolvedName (PeerKey addr) 303 h' <- peerKeyToResolvedName (PeerKey addr)
303 return $ Just ((n,h',r), addr) 304 return $ Just ((n,h',r), addr)
305-}
304 306
305parseAddress :: Text -> IO (Maybe SockAddr) 307parseAddress :: Text -> IO (Maybe SockAddr)
306parseAddress addr_str = do 308parseAddress addr_str = do
@@ -336,6 +338,17 @@ rewriteJIDForClient laddr jid = do
336 else peerKeyToResolvedName (PeerKey addr) 338 else peerKeyToResolvedName (PeerKey addr)
337 return (mine,(n,h',r)) 339 return (mine,(n,h',r))
338 340
341multiplyJIDForClient :: SockAddr -> Text -> IO (Bool,[(Maybe Text,Text,Maybe Text)])
342multiplyJIDForClient laddr jid = do
343 let (n,h,r) = splitJID jid
344 maddr <- parseAddress (strip_brackets h)
345 flip (maybe $ return (False,[(n,ip6literal h,r)])) maddr $ \addr -> do
346 let mine = laddr `withPort` 0 == addr `withPort` 0
347 names <- if mine then fmap (:[]) textHostName
348 else peerKeyToResolvedNames (PeerKey addr)
349 return (mine,map (\h' -> (n,h',r)) names)
350
351
339addrTextToKey h = do 352addrTextToKey h = do
340 maddr <- parseAddress (strip_brackets h) 353 maddr <- parseAddress (strip_brackets h)
341 return (fmap PeerKey maddr) 354 return (fmap PeerKey maddr)
@@ -460,9 +473,10 @@ informPeerPresence state k stanza = do
460 forM_ clients $ \(ck,con,client) -> do 473 forM_ clients $ \(ck,con,client) -> do
461 from' <- do 474 from' <- do
462 let ClientKey laddr = ck 475 let ClientKey laddr = ck
463 (_,trip) <- rewriteJIDForClient laddr from 476 (_,trip) <- multiplyJIDForClient laddr from
464 return (unsplitJID trip) 477 return (map unsplitJID trip)
465 putStrLn $ "sending to client: " ++ show (stanzaType stanza) 478 putStrLn $ "sending to client: " ++ show (stanzaType stanza)
479 forM_ from' $ \from' -> do
466 dup <- cloneStanza stanza 480 dup <- cloneStanza stanza
467 sendModifiedStanzaToClient (dup { stanzaFrom=Just from' }) 481 sendModifiedStanzaToClient (dup { stanzaFrom=Just from' })
468 (connChan con) 482 (connChan con)