summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-03-08 23:59:08 -0500
committerjoe <joe@jerkface.net>2014-03-08 23:59:08 -0500
commit787fba50106105ed6fb77205ffcc6fe2a0102bed (patch)
tree23d0c39fefa7cef00e4c4493956ed56471a1357c
parent0d9594428d6e197ea4dde15e3e1f53fc48c0bcf9 (diff)
ask=suscribe roster update on buddy request
-rw-r--r--Presence/XMPPServer.hs4
-rw-r--r--xmppServer.hs42
2 files changed, 31 insertions, 15 deletions
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs
index d9cacb4c..a181b3e5 100644
--- a/Presence/XMPPServer.hs
+++ b/Presence/XMPPServer.hs
@@ -795,8 +795,8 @@ makePresenceStanza namespace mjid pstat = do
795 , EventContent (ContentText stat) 795 , EventContent (ContentText stat)
796 , EventEndElement "{jabber:client}show" ] 796 , EventEndElement "{jabber:client}show" ]
797 797
798makeRosterUpdate tojid contact relationship = do 798makeRosterUpdate tojid contact (suborask,relationship) = do
799 let attrs = [attr "subscription" relationship] 799 let attrs = [attr suborask relationship]
800 stanzaFromList Unrecognized 800 stanzaFromList Unrecognized
801 [ EventBeginElement "{jabber:client}iq" 801 [ EventBeginElement "{jabber:client}iq"
802 [ attr "to" tojid 802 [ attr "to" tojid
diff --git a/xmppServer.hs b/xmppServer.hs
index 7b220c95..d38c78cf 100644
--- a/xmppServer.hs
+++ b/xmppServer.hs
@@ -652,14 +652,25 @@ clientSubscriptionRequest state fail k stanza chan = do
652 if null addrs then fail else do 652 if null addrs then fail else do
653 -- add to-address to from's solicited 653 -- add to-address to from's solicited
654 addToRosterFile ConfigFiles.modifySolicited (clientUser client) to addrs 654 addToRosterFile ConfigFiles.modifySolicited (clientUser client) to addrs
655
655 (ktc,ap) <- atomically $ 656 (ktc,ap) <- atomically $
656 liftM2 (,) (readTVar $ keyToChan state) 657 liftM2 (,) (readTVar $ keyToChan state)
657 (readTVar $ associatedPeers state) 658 (readTVar $ associatedPeers state)
659
660 hostname <- textHostName
661 let cjid = unsplitJID (Just $ clientUser client, hostname,Nothing)
662 chans <- clientCons state ktc (clientUser client)
663 forM_ chans $ \( Conn { connChan=chan }, client ) -> do
664 -- roster update ask="subscribe"
665 update <- makeRosterUpdate cjid to ("ask","subscribe")
666 sendModifiedStanzaToClient update chan
667
658 let dsts = Map.fromList $ map ((,()) . PeerKey) addrs 668 let dsts = Map.fromList $ map ((,()) . PeerKey) addrs
659 cdsts = ktc Map.\\ dsts 669 cdsts = ktc Map.\\ dsts
660 forM_ (Map.toList cdsts) $ \(pk,con) -> do 670 forM_ (Map.toList cdsts) $ \(pk,con) -> do
661 -- if already connected, send solicitation ... 671 -- if already connected, send solicitation ...
662 let from = clientJID con client 672 let from = clientJID con client
673
663 sendModifiedStanzaToPeer (stanza { stanzaTo = Just to 674 sendModifiedStanzaToPeer (stanza { stanzaTo = Just to
664 , stanzaFrom = Just from }) 675 , stanzaFrom = Just from })
665 (connChan con) 676 (connChan con)
@@ -685,8 +696,11 @@ clientCons state ktc u = do
685 cmap <- readTVar $ clientsByUser state 696 cmap <- readTVar $ clientsByUser state
686 return $ Map.lookup u cmap 697 return $ Map.lookup u cmap
687 let ks = do lp <- maybeToList mlp 698 let ks = do lp <- maybeToList mlp
688 Map.keys (networkClients lp) 699 Map.toList (networkClients lp)
689 return $ mapMaybe (flip Map.lookup ktc) ks 700 doit (k,client) = do
701 con <- Map.lookup k ktc
702 return (con,client)
703 return $ mapMaybe doit ks
690 704
691peerSubscriptionRequest :: PresenceState -> IO () -> ConnectionKey -> Stanza -> TChan Stanza -> IO () 705peerSubscriptionRequest :: PresenceState -> IO () -> ConnectionKey -> Stanza -> TChan Stanza -> IO ()
692peerSubscriptionRequest state fail k stanza chan = do 706peerSubscriptionRequest state fail k stanza chan = do
@@ -732,7 +746,7 @@ peerSubscriptionRequest state fail k stanza chan = do
732 -- contact ∉ subscribers & contact ∉ pending --> MUST 746 -- contact ∉ subscribers & contact ∉ pending --> MUST
733 747
734 chans <- clientCons state ktc u 748 chans <- clientCons state ktc u
735 forM_ chans $ \Conn { connChan=chan } -> do 749 forM_ chans $ \( Conn { connChan=chan }, client ) -> do
736 -- send to clients 750 -- send to clients
737 -- TODO: interested/available clients only? 751 -- TODO: interested/available clients only?
738 dup <- cloneStanza stanza 752 dup <- cloneStanza stanza
@@ -754,12 +768,12 @@ clientInformSubscription state fail k stanza = do
754 let (relationship,addf,remf) = 768 let (relationship,addf,remf) =
755 case stanzaType stanza of 769 case stanzaType stanza of
756 PresenceInformSubscription True -> 770 PresenceInformSubscription True ->
757 ( if is_buddy then "both" 771 ( ("subscription", if is_buddy then "both"
758 else "from" 772 else "from" )
759 , ConfigFiles.modifySubscribers 773 , ConfigFiles.modifySubscribers
760 , ConfigFiles.modifyOthers ) 774 , ConfigFiles.modifyOthers )
761 _ -> ( if is_buddy then "to" 775 _ -> ( ("subscription", if is_buddy then "to"
762 else "none" 776 else "none" )
763 , ConfigFiles.modifyOthers 777 , ConfigFiles.modifyOthers
764 , ConfigFiles.modifySubscribers ) 778 , ConfigFiles.modifySubscribers )
765 addToRosterFile addf (clientUser client) to addrs 779 addToRosterFile addf (clientUser client) to addrs
@@ -814,12 +828,12 @@ peerInformSubscription state fail k stanza = do
814 let (relationship,addf,remf) = 828 let (relationship,addf,remf) =
815 case stanzaType stanza of 829 case stanzaType stanza of
816 PresenceInformSubscription True -> 830 PresenceInformSubscription True ->
817 ( if is_sub then "both" 831 ( ("subscription", if is_sub then "both"
818 else "to" 832 else "to" )
819 , ConfigFiles.modifyBuddies 833 , ConfigFiles.modifyBuddies
820 , ConfigFiles.modifyOthers ) 834 , ConfigFiles.modifyOthers )
821 _ -> ( if is_sub then "from" 835 _ -> ( ("subscription", if is_sub then "from"
822 else "none" 836 else "none")
823 , ConfigFiles.modifyOthers 837 , ConfigFiles.modifyOthers
824 , ConfigFiles.modifyBuddies ) 838 , ConfigFiles.modifyBuddies )
825 addToRosterFile addf user from'' addrs 839 addToRosterFile addf user from'' addrs
@@ -832,9 +846,11 @@ peerInformSubscription state fail k stanza = do
832 let to' = unsplitJID (Just user, hostname, Nothing) 846 let to' = unsplitJID (Just user, hostname, Nothing)
833 (_,fromtup) <- rewriteJIDForClient laddr from 847 (_,fromtup) <- rewriteJIDForClient laddr from
834 chans <- clientCons state ktc user 848 chans <- clientCons state ktc user
835 forM_ chans $ \Conn { connChan=chan } -> do 849 forM_ chans $ \(Conn { connChan=chan }, client) -> do
836 update <- makeRosterUpdate to' from relationship 850 update <- makeRosterUpdate to' from relationship
837 sendModifiedStanzaToClient update chan 851 when (clientIsInterested client) $ do
852 sendModifiedStanzaToClient update chan
853 -- TODO: interested/availabe clients only?
838 dup <- cloneStanza stanza 854 dup <- cloneStanza stanza
839 sendModifiedStanzaToClient dup { stanzaFrom = Just $ unsplitJID fromtup 855 sendModifiedStanzaToClient dup { stanzaFrom = Just $ unsplitJID fromtup
840 , stanzaTo = Just to' } 856 , stanzaTo = Just to' }