diff options
author | joe <joe@jerkface.net> | 2014-03-06 00:53:30 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2014-03-06 00:53:30 -0500 |
commit | a41ffe16f5f3237a0b16c49f743ba423b19e46d6 (patch) | |
tree | bfe331ade9d93a611d9d292c2ff660c83cc0b65e | |
parent | 364db76d6c2ca9bc2504b0ba0752b8f6e31481be (diff) |
multiply presence for client (for hostname aliases)
-rw-r--r-- | Presence/XMPPServer.hs | 15 | ||||
-rw-r--r-- | xmppServer.hs | 18 |
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 | |||
50 | import qualified Text.XML.Stream.Parse as XML | 51 | import qualified Text.XML.Stream.Parse as XML |
51 | import Data.XML.Types as XML | 52 | import Data.XML.Types as XML |
52 | import Data.Maybe | 53 | import Data.Maybe |
54 | import Data.List (nub) | ||
53 | import Data.Monoid ( (<>) ) | 55 | import Data.Monoid ( (<>) ) |
54 | import Data.Text (Text) | 56 | import Data.Text (Text) |
55 | import qualified Data.Text as Text (pack,unpack) | 57 | import qualified Data.Text as Text (pack,unpack) |
@@ -227,12 +229,17 @@ peerKeyToText (ClientKey { localAddress=addr }) = "ErrorClIeNt0" | |||
227 | 229 | ||
228 | peerKeyToResolvedName :: ConnectionKey -> IO Text | 230 | peerKeyToResolvedName :: ConnectionKey -> IO Text |
229 | peerKeyToResolvedName k@(ClientKey { localAddress=addr }) = return "ErrorClIeNt1" | 231 | peerKeyToResolvedName k@(ClientKey { localAddress=addr }) = return "ErrorClIeNt1" |
230 | peerKeyToResolvedName k@(PeerKey { callBackAddress=addr }) = do | 232 | peerKeyToResolvedName pk = do |
231 | mname <- handleIO_ (return Nothing) $ do | 233 | ns <- peerKeyToResolvedNames pk |
234 | return $ maybe (peerKeyToText pk) id (listToMaybe ns) | ||
235 | |||
236 | peerKeyToResolvedNames :: ConnectionKey -> IO [Text] | ||
237 | peerKeyToResolvedNames k@(ClientKey { localAddress=addr }) = return [] | ||
238 | peerKeyToResolvedNames 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 | ||
238 | wlog :: String -> IO () | 245 | wlog :: 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 | ||
295 | eofConn state k = atomically $ modifyTVar' (keyToChan state) $ Map.delete k | 295 | eofConn state k = atomically $ modifyTVar' (keyToChan state) $ Map.delete k |
296 | 296 | ||
297 | {- | ||
297 | rewriteJIDForClient1:: Text -> IO (Maybe ((Maybe Text,Text,Maybe Text),SockAddr)) | 298 | rewriteJIDForClient1:: Text -> IO (Maybe ((Maybe Text,Text,Maybe Text),SockAddr)) |
298 | rewriteJIDForClient1 jid = do | 299 | rewriteJIDForClient1 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 | ||
305 | parseAddress :: Text -> IO (Maybe SockAddr) | 307 | parseAddress :: Text -> IO (Maybe SockAddr) |
306 | parseAddress addr_str = do | 308 | parseAddress 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 | ||
341 | multiplyJIDForClient :: SockAddr -> Text -> IO (Bool,[(Maybe Text,Text,Maybe Text)]) | ||
342 | multiplyJIDForClient 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 | |||
339 | addrTextToKey h = do | 352 | addrTextToKey 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) |