diff options
-rw-r--r-- | xmppServer.hs | 74 |
1 files changed, 53 insertions, 21 deletions
diff --git a/xmppServer.hs b/xmppServer.hs index 99d5a197..13883c75 100644 --- a/xmppServer.hs +++ b/xmppServer.hs | |||
@@ -247,12 +247,15 @@ rosterGetStuff what state k = forClient state k (return []) | |||
247 | return jids | 247 | return jids |
248 | 248 | ||
249 | rosterGetBuddies :: PresenceState -> ConnectionKey -> IO [Text] | 249 | rosterGetBuddies :: PresenceState -> ConnectionKey -> IO [Text] |
250 | rosterGetBuddies state k = do | 250 | rosterGetBuddies state k = rosterGetStuff ConfigFiles.getBuddies state k |
251 | buds <- rosterGetStuff ConfigFiles.getBuddies state k | ||
252 | return buds | ||
253 | 251 | ||
252 | rosterGetSolicited :: PresenceState -> ConnectionKey -> IO [Text] | ||
254 | rosterGetSolicited = rosterGetStuff ConfigFiles.getSolicited | 253 | rosterGetSolicited = rosterGetStuff ConfigFiles.getSolicited |
254 | |||
255 | rosterGetOthers :: PresenceState -> ConnectionKey -> IO [Text] | ||
255 | rosterGetOthers = rosterGetStuff ConfigFiles.getOthers | 256 | rosterGetOthers = rosterGetStuff ConfigFiles.getOthers |
257 | |||
258 | rosterGetSubscribers :: PresenceState -> ConnectionKey -> IO [Text] | ||
256 | rosterGetSubscribers = rosterGetStuff ConfigFiles.getSubscribers | 259 | rosterGetSubscribers = rosterGetStuff ConfigFiles.getSubscribers |
257 | 260 | ||
258 | data Conn = Conn { connChan :: TChan Stanza | 261 | data Conn = Conn { connChan :: TChan Stanza |
@@ -616,7 +619,13 @@ sendCachedPresence state k = do | |||
616 | -- send local buddies. | 619 | -- send local buddies. |
617 | return () | 620 | return () |
618 | 621 | ||
619 | addToRosterFile doit whose to addrs = do | 622 | addToRosterFile doit whose to addrs = |
623 | modifyRosterFile doit whose to addrs True | ||
624 | |||
625 | removeFromRosterFile doit whose to addrs = | ||
626 | modifyRosterFile doit whose to addrs False | ||
627 | |||
628 | modifyRosterFile doit whose to addrs bAdd = do | ||
620 | let (mu,_,_) = splitJID to | 629 | let (mu,_,_) = splitJID to |
621 | cmp jid = runTraversableT $ do | 630 | cmp jid = runTraversableT $ do |
622 | let (mu,stored_h,mr) = splitJID (lazyByteStringToText jid) | 631 | let (mu,stored_h,mr) = splitJID (lazyByteStringToText jid) |
@@ -629,7 +638,7 @@ addToRosterFile doit whose to addrs = do | |||
629 | mzero | 638 | mzero |
630 | doit (textToLazyByteString whose) | 639 | doit (textToLazyByteString whose) |
631 | cmp | 640 | cmp |
632 | (Just $ textToLazyByteString to) | 641 | (guard bAdd >> Just (textToLazyByteString to)) |
633 | 642 | ||
634 | clientSubscriptionRequest :: PresenceState -> IO () -> ConnectionKey -> Stanza -> TChan Stanza -> IO () | 643 | clientSubscriptionRequest :: PresenceState -> IO () -> ConnectionKey -> Stanza -> TChan Stanza -> IO () |
635 | clientSubscriptionRequest state fail k stanza chan = do | 644 | clientSubscriptionRequest state fail k stanza chan = do |
@@ -660,6 +669,17 @@ clientSubscriptionRequest state fail k stanza chan = do | |||
660 | sv <- atomically $ takeTMVar $ server state | 669 | sv <- atomically $ takeTMVar $ server state |
661 | addPeer sv (head addrs) | 670 | addPeer sv (head addrs) |
662 | 671 | ||
672 | |||
673 | resolvedFromRoster | ||
674 | :: (L.ByteString -> IO [L.ByteString]) | ||
675 | -> UserName -> IO [(Maybe UserName, ConnectionKey)] | ||
676 | resolvedFromRoster doit u = do | ||
677 | subs <- configText doit u | ||
678 | runTraversableT $ do | ||
679 | (mu,h,_) <- liftT $ splitJID `fmap` subs | ||
680 | addr <- liftMT $ resolvePeer h | ||
681 | return (mu,PeerKey addr) | ||
682 | |||
663 | peerSubscriptionRequest :: PresenceState -> IO () -> ConnectionKey -> Stanza -> TChan Stanza -> IO () | 683 | peerSubscriptionRequest :: PresenceState -> IO () -> ConnectionKey -> Stanza -> TChan Stanza -> IO () |
664 | peerSubscriptionRequest state fail k stanza chan = do | 684 | peerSubscriptionRequest state fail k stanza chan = do |
665 | putStrLn $ "Handling pending subscription from remote" | 685 | putStrLn $ "Handling pending subscription from remote" |
@@ -677,12 +697,8 @@ peerSubscriptionRequest state fail k stanza chan = do | |||
677 | (_,fromtup) <- rewriteJIDForClient laddr from | 697 | (_,fromtup) <- rewriteJIDForClient laddr from |
678 | flip (maybe fail) mto_u $ \u -> do | 698 | flip (maybe fail) mto_u $ \u -> do |
679 | flip (maybe fail) mfrom_u $ \from_u -> do | 699 | flip (maybe fail) mfrom_u $ \from_u -> do |
680 | subs <- configText ConfigFiles.getSubscribers u | 700 | resolved_subs <- resolvedFromRoster ConfigFiles.getSubscribers u |
681 | let resolved_subs = runTraversableT $ do | 701 | let already_subscribed = elem (mfrom_u,k) resolved_subs |
682 | (mu,h,_) <- liftT $ splitJID `fmap` subs | ||
683 | addr <- liftMT $ resolvePeer h | ||
684 | return (mu,PeerKey addr) | ||
685 | already_subscribed <- fmap (elem (mfrom_u,k)) resolved_subs | ||
686 | -- Section 8 says (for presence of type "subscribe", the server MUST | 702 | -- Section 8 says (for presence of type "subscribe", the server MUST |
687 | -- adhere to the rules defined under Section 3 and summarized under | 703 | -- adhere to the rules defined under Section 3 and summarized under |
688 | -- see Appendix A. (pariticularly Appendex A.3.1) | 704 | -- see Appendix A. (pariticularly Appendex A.3.1) |
@@ -722,17 +738,33 @@ peerSubscriptionRequest state fail k stanza chan = do | |||
722 | 738 | ||
723 | 739 | ||
724 | clientInformSubscription state fail k stanza = do | 740 | clientInformSubscription state fail k stanza = do |
725 | putStrLn $ "TODO: clientInformSubscription" | 741 | forClient state k fail $ \client -> do |
726 | -- approval: | 742 | flip (maybe fail) (stanzaTo stanza) $ \to -> do |
727 | -- add to subscribers | 743 | putStrLn $ "clientInformSubscription" |
728 | -- remove from pending | 744 | let (mu,h,mr) = splitJID to |
729 | -- remove from others | 745 | addrs <- resolvePeer h |
730 | -- rejection: | 746 | -- remove from pending |
731 | -- add to others | 747 | buds <- resolvedFromRoster ConfigFiles.getBuddies (clientUser client) |
732 | -- remove from pending | 748 | let is_buddy = not . null $ map ((mu,) . PeerKey) addrs \\ buds |
733 | -- remove from subscribers | 749 | removeFromRosterFile ConfigFiles.modifyPending (clientUser client) to addrs |
734 | -- | 750 | let (relationship,addf,remf) = |
751 | case stanzaType stanza of | ||
752 | PresenceInformSubscription True -> | ||
753 | ( if is_buddy then "both" | ||
754 | else "from" | ||
755 | , ConfigFiles.modifySubscribers | ||
756 | , ConfigFiles.modifyOthers ) | ||
757 | _ -> ( if is_buddy then "to" | ||
758 | else "none" | ||
759 | , ConfigFiles.modifyOthers | ||
760 | , ConfigFiles.modifySubscribers ) | ||
761 | addToRosterFile addf (clientUser client) to addrs | ||
762 | removeFromRosterFile remf (clientUser client) to addrs | ||
763 | -- TODO | ||
735 | -- send roster update to clients | 764 | -- send roster update to clients |
765 | -- approve: both ( ∈ buddies) else from | ||
766 | -- reject: to ( ∈ buddies ) else none | ||
767 | |||
736 | -- notify peer | 768 | -- notify peer |
737 | return () | 769 | return () |
738 | 770 | ||