summaryrefslogtreecommitdiff
path: root/Presence
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-02-16 22:46:17 -0500
committerjoe <joe@jerkface.net>2014-02-16 22:46:17 -0500
commitdf83e87aa66748d1e38a471ff6c7ef8ddbe5dc83 (patch)
tree690c90fbf0e3062c38e173fc05fa6b32d5ced03e /Presence
parent934f42f8b547ee59da7066168e34258996c48881 (diff)
Updated XMPPServer to use SockAddr user data for Server
Diffstat (limited to 'Presence')
-rw-r--r--Presence/XMPPServer.hs35
1 files changed, 22 insertions, 13 deletions
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs
index 83a9fb39..222d8ac4 100644
--- a/Presence/XMPPServer.hs
+++ b/Presence/XMPPServer.hs
@@ -121,7 +121,7 @@ data Stanza = Stanza
121 121
122data XMPPServerParameters = 122data XMPPServerParameters =
123 XMPPServerParameters 123 XMPPServerParameters
124 { xmppChooseResourceName :: ConnectionKey -> Socket -> Maybe Text -> IO Text 124 { xmppChooseResourceName :: ConnectionKey -> SockAddr -> Maybe Text -> IO Text
125 , xmppNewConnection :: ConnectionKey -> TChan Stanza -> IO () 125 , xmppNewConnection :: ConnectionKey -> TChan Stanza -> IO ()
126 , xmppEOF :: ConnectionKey -> IO () 126 , xmppEOF :: ConnectionKey -> IO ()
127 , xmppRosterBuddies :: ConnectionKey -> IO [Text] 127 , xmppRosterBuddies :: ConnectionKey -> IO [Text]
@@ -396,7 +396,7 @@ grokStanza "jabber:client" stanzaTag =
396 _ | tagName stanzaTag == "{jabber:client}message" -> grokMessage "jabber:client" stanzaTag 396 _ | tagName stanzaTag == "{jabber:client}message" -> grokMessage "jabber:client" stanzaTag
397 _ -> return $ Just Unrecognized 397 _ -> return $ Just Unrecognized
398 398
399xmppInbound :: Server ConnectionKey 399xmppInbound :: Server ConnectionKey SockAddr
400 -> ConnectionKey 400 -> ConnectionKey
401 -> FlagCommand 401 -> FlagCommand
402 -> Source IO XML.Event 402 -> Source IO XML.Event
@@ -617,7 +617,7 @@ goodbye =
617 , EventEndDocument 617 , EventEndDocument
618 ] 618 ]
619 619
620forkConnection :: Server ConnectionKey 620forkConnection :: Server ConnectionKey SockAddr
621 -> ConnectionKey 621 -> ConnectionKey
622 -> FlagCommand 622 -> FlagCommand
623 -> Source IO XML.Event 623 -> Source IO XML.Event
@@ -710,9 +710,12 @@ peerKey (sock,addr) = do
710 sIsConnected sock >>= \c -> 710 sIsConnected sock >>= \c ->
711 if c then getPeerName sock -- addr is normally socketName 711 if c then getPeerName sock -- addr is normally socketName
712 else return addr -- Weird hack: addr is would-be peer name 712 else return addr -- Weird hack: addr is would-be peer name
713 return $ PeerKey (peer `withPort` fromIntegral peerport) 713 laddr <- getSocketName sock
714 return $ (PeerKey (peer `withPort` fromIntegral peerport),laddr)
714 715
715clientKey (sock,addr) = return $ ClientKey addr 716clientKey (sock,addr) = do
717 laddr <- getSocketName sock
718 return $ (ClientKey addr,laddr)
716 719
717stanzaToConduit :: MonadIO m => Stanza -> ConduitM i Event m () 720stanzaToConduit :: MonadIO m => Stanza -> ConduitM i Event m ()
718stanzaToConduit stanza = do 721stanzaToConduit stanza = do
@@ -797,11 +800,17 @@ sendRoster query xmpp replyto = do
797 , stanzaOrigin = LocalPeer 800 , stanzaOrigin = LocalPeer
798 } 801 }
799 802
800socketFromKey :: Server k -> k -> IO Socket 803socketFromKey :: Server ConnectionKey SockAddr -> ConnectionKey -> IO SockAddr
801socketFromKey sv k = do 804socketFromKey sv k = do
802 let v = Map.lookup k $ conmap sv 805 map <- atomically $ readTVar (conmap sv)
803 flip (maybe $ todo) v $ \_ ->do 806 let mcd = Map.lookup k map
804 return todo 807 case mcd of
808 Nothing -> case k of
809 ClientKey addr -> return addr
810 PeerKey addr -> return addr
811 -- XXX: ? wrong address
812 -- Shouldnt happen anyway.
813 Just cd -> return $ cdata cd
805 814
806monitor sv params xmpp = do 815monitor sv params xmpp = do
807 chan <- return $ serverEvent sv 816 chan <- return $ serverEvent sv
@@ -809,7 +818,7 @@ monitor sv params xmpp = do
809 quitVar <- atomically newEmptyTMVar 818 quitVar <- atomically newEmptyTMVar
810 fix $ \loop -> do 819 fix $ \loop -> do
811 action <- atomically $ foldr1 orElse 820 action <- atomically $ foldr1 orElse
812 [ readTChan chan >>= \(k,e) -> return $ do 821 [ readTChan chan >>= \((k,u),e) -> return $ do
813 case e of 822 case e of
814 Connection pingflag conread conwrite -> do 823 Connection pingflag conread conwrite -> do
815 wlog $ tomsg k "Connection" 824 wlog $ tomsg k "Connection"
@@ -832,8 +841,8 @@ monitor sv params xmpp = do
832 NetworkOrigin k@(ClientKey {}) replyto -> 841 NetworkOrigin k@(ClientKey {}) replyto ->
833 case stanzaType stanza of 842 case stanzaType stanza of
834 RequestResource wanted -> do 843 RequestResource wanted -> do
835 sock <- socketFromKey sv k 844 sockaddr <- socketFromKey sv k
836 rsc <- xmppChooseResourceName xmpp k sock wanted 845 rsc <- xmppChooseResourceName xmpp k sockaddr wanted
837 let reply = iq_bind_reply (stanzaId stanza) rsc 846 let reply = iq_bind_reply (stanzaId stanza) rsc
838 sendReply quitVar SetResource reply replyto 847 sendReply quitVar SetResource reply replyto
839 SessionRequest -> do 848 SessionRequest -> do
@@ -870,7 +879,7 @@ monitor sv params xmpp = do
870 879
871xmppServer :: ( MonadResource m 880xmppServer :: ( MonadResource m
872 , MonadIO m 881 , MonadIO m
873 ) => XMPPServerParameters -> m (Server ConnectionKey,ConnectionParameters ConnectionKey) 882 ) => XMPPServerParameters -> m (Server ConnectionKey SockAddr,ConnectionParameters ConnectionKey SockAddr)
874xmppServer xmpp = do 883xmppServer xmpp = do
875 sv <- server 884 sv <- server
876 -- some fuzz helps avoid simultaneity 885 -- some fuzz helps avoid simultaneity