diff options
author | joe <joe@jerkface.net> | 2018-06-24 19:17:44 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-06-24 19:18:01 -0400 |
commit | 0cd6528e5d87172429d3ea9969ebe2593dc47a5e (patch) | |
tree | 31fdc716546352e7b6946fca69d5d5c6395e0efe /Presence/Presence.hs | |
parent | f78efaaf6fd64c77c0fd778a7666c40782ce9ec4 (diff) |
xmpp: allow server to change it's name (important for tox peers).
Diffstat (limited to 'Presence/Presence.hs')
-rw-r--r-- | Presence/Presence.hs | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/Presence/Presence.hs b/Presence/Presence.hs index 5fe4e8cf..e8a69066 100644 --- a/Presence/Presence.hs +++ b/Presence/Presence.hs | |||
@@ -437,7 +437,7 @@ sendProbesAndSolicitations state k (Local laddr) chan = do | |||
437 | unsplitJID (Just user,me,Nothing) | 437 | unsplitJID (Just user,me,Nothing) |
438 | stanza <- make from jid | 438 | stanza <- make from jid |
439 | -- send probes for buddies, solicitations for solicited. | 439 | -- send probes for buddies, solicitations for solicited. |
440 | putStrLn $ "probing "++show k++" for: " ++ show (isbud,jid) | 440 | dput XJabber $ "probing "++show k++" for: " ++ show (isbud,jid) |
441 | atomically $ writeTChan chan stanza | 441 | atomically $ writeTChan chan stanza |
442 | -- reverse xs `seq` return () | 442 | -- reverse xs `seq` return () |
443 | 443 | ||
@@ -622,7 +622,7 @@ deliverMessage state fail msg = | |||
622 | XMPP -> return $ stanzaTo msg | 622 | XMPP -> return $ stanzaTo msg |
623 | Tox -> return $ Just $ unsplitJID (Just user, profile, Nothing) | 623 | Tox -> return $ Just $ unsplitJID (Just user, profile, Nothing) |
624 | return (from',chan) | 624 | return (from',chan) |
625 | putStrLn $ "chan count: " ++ show (length chans) | 625 | dput XJabber $ "chan count: " ++ show (length chans) |
626 | if null chans then when (ctyp == XMPP) $ do | 626 | if null chans then when (ctyp == XMPP) $ do |
627 | forM_ (stanzaFrom msg) $ \from -> do | 627 | forM_ (stanzaFrom msg) $ \from -> do |
628 | from' <- do | 628 | from' <- do |
@@ -722,10 +722,10 @@ informPeerPresence :: PresenceState | |||
722 | -> IO () | 722 | -> IO () |
723 | informPeerPresence state k stanza = do | 723 | informPeerPresence state k stanza = do |
724 | -- Presence must indicate full JID with resource... | 724 | -- Presence must indicate full JID with resource... |
725 | putStrLn $ "xmppInformPeerPresence checking from address..." | 725 | dput XJabber $ "xmppInformPeerPresence checking from address..." |
726 | forM_ (stanzaFrom stanza) $ \from -> do | 726 | forM_ (stanzaFrom stanza) $ \from -> do |
727 | let (muser,h,mresource) = splitJID from | 727 | let (muser,h,mresource) = splitJID from |
728 | putStrLn $ "xmppInformPeerPresence from = " ++ show from | 728 | dput XJabber $ "xmppInformPeerPresence from = " ++ show from |
729 | -- forM_ mresource $ \resource -> do | 729 | -- forM_ mresource $ \resource -> do |
730 | forM_ muser $ \user -> do | 730 | forM_ muser $ \user -> do |
731 | 731 | ||
@@ -765,18 +765,18 @@ informPeerPresence state k stanza = do | |||
765 | (ck,client) <- liftMT $ fmap Map.toList $ readTVar (clients state) | 765 | (ck,client) <- liftMT $ fmap Map.toList $ readTVar (clients state) |
766 | con <- liftMaybe $ Map.lookup ck ktc | 766 | con <- liftMaybe $ Map.lookup ck ktc |
767 | return (ck,con,client) | 767 | return (ck,con,client) |
768 | putStrLn $ "xmppInformPeerPresence (length clients="++show (length clients)++")" | 768 | dput XJabber $ "xmppInformPeerPresence (length clients="++show (length clients)++")" |
769 | forM_ clients $ \(ck,con,client) -> do | 769 | forM_ clients $ \(ck,con,client) -> do |
770 | -- (TODO: appropriately authorized clients only.) | 770 | -- (TODO: appropriately authorized clients only.) |
771 | -- For now, all "available" clients (available = sent initial presence) | 771 | -- For now, all "available" clients (available = sent initial presence) |
772 | is_avail <- atomically $ clientIsAvailable client | 772 | is_avail <- atomically $ clientIsAvailable client |
773 | when is_avail $ do | 773 | when is_avail $ do |
774 | putStrLn $ "reversing for client: " ++ show from | 774 | dput XJabber $ "reversing for client: " ++ show from |
775 | froms <- do -- flip (maybe $ return [from]) k . const $ do | 775 | froms <- do -- flip (maybe $ return [from]) k . const $ do |
776 | (_,trip) <- multiplyJIDForClient ck from | 776 | (_,trip) <- multiplyJIDForClient ck from |
777 | return (map unsplitJID trip) | 777 | return (map unsplitJID trip) |
778 | 778 | ||
779 | putStrLn $ "sending to client: " ++ show (stanzaType stanza,froms) | 779 | dput XJabber $ "sending to client: " ++ show (stanzaType stanza,froms) |
780 | forM_ froms $ \from' -> do | 780 | forM_ froms $ \from' -> do |
781 | dup <- cloneStanza stanza | 781 | dup <- cloneStanza stanza |
782 | sendModifiedStanzaToClient (dup { stanzaFrom=Just from' }) | 782 | sendModifiedStanzaToClient (dup { stanzaFrom=Just from' }) |
@@ -789,7 +789,7 @@ consoleClients _ = return Map.empty | |||
789 | 789 | ||
790 | answerProbe :: PresenceState -> Maybe Text -> PeerAddress -> TChan Stanza -> IO () | 790 | answerProbe :: PresenceState -> Maybe Text -> PeerAddress -> TChan Stanza -> IO () |
791 | answerProbe state mto k chan = do | 791 | answerProbe state mto k chan = do |
792 | -- putStrLn $ "answerProbe! " ++ show (stanzaType stanza) | 792 | -- dput XJabber $ "answerProbe! " ++ show (stanzaType stanza) |
793 | ktc <- atomically $ readTVar (pkeyToChan state) | 793 | ktc <- atomically $ readTVar (pkeyToChan state) |
794 | muser <- runTraversableT $ do | 794 | muser <- runTraversableT $ do |
795 | to <- liftT $ mto | 795 | to <- liftT $ mto |
@@ -966,7 +966,7 @@ clientSubscriptionRequest :: PresenceState -> IO () -> ClientAddress -> Stanza - | |||
966 | clientSubscriptionRequest state fail k stanza chan = do | 966 | clientSubscriptionRequest state fail k stanza chan = do |
967 | forClient state k fail $ \client -> do | 967 | forClient state k fail $ \client -> do |
968 | fromMaybe fail $ (splitJID <$> stanzaTo stanza) <&> \(mu,h,_) -> do | 968 | fromMaybe fail $ (splitJID <$> stanzaTo stanza) <&> \(mu,h,_) -> do |
969 | putStrLn $ "Forwarding solictation to peer" | 969 | dput XJabber $ "Forwarding solictation to peer" |
970 | let to = unsplitJID (mu,h,Nothing) -- deleted resource | 970 | let to = unsplitJID (mu,h,Nothing) -- deleted resource |
971 | cuser = clientUser client | 971 | cuser = clientUser client |
972 | cprof = clientProfile client | 972 | cprof = clientProfile client |
@@ -1069,7 +1069,7 @@ releventProfiles ctyp user = do | |||
1069 | 1069 | ||
1070 | peerSubscriptionRequest :: PresenceState -> IO () -> PeerAddress -> Stanza -> TChan Stanza -> IO () | 1070 | peerSubscriptionRequest :: PresenceState -> IO () -> PeerAddress -> Stanza -> TChan Stanza -> IO () |
1071 | peerSubscriptionRequest state fail k stanza chan = do | 1071 | peerSubscriptionRequest state fail k stanza chan = do |
1072 | putStrLn $ "Handling pending subscription from remote" | 1072 | dput XJabber $ "Handling pending subscription from remote" |
1073 | fromMaybe fail $ (stanzaFrom stanza) <&> \from -> do | 1073 | fromMaybe fail $ (stanzaFrom stanza) <&> \from -> do |
1074 | fromMaybe fail $ (stanzaTo stanza) <&> \to -> do | 1074 | fromMaybe fail $ (stanzaTo stanza) <&> \to -> do |
1075 | let (mto_u,h,_) = splitJID to | 1075 | let (mto_u,h,_) = splitJID to |
@@ -1148,7 +1148,7 @@ clientInformSubscription :: PresenceState | |||
1148 | clientInformSubscription state fail k stanza = do | 1148 | clientInformSubscription state fail k stanza = do |
1149 | forClient state k fail $ \client -> do | 1149 | forClient state k fail $ \client -> do |
1150 | fromMaybe fail $ (stanzaTo stanza) <&> \to -> do | 1150 | fromMaybe fail $ (stanzaTo stanza) <&> \to -> do |
1151 | putStrLn $ "clientInformSubscription" | 1151 | dput XJabber $ "clientInformSubscription" |
1152 | let (mu,h,mr) = splitJID to | 1152 | let (mu,h,mr) = splitJID to |
1153 | addrs <- resolvePeer h | 1153 | addrs <- resolvePeer h |
1154 | -- remove from pending | 1154 | -- remove from pending |
@@ -1171,7 +1171,7 @@ clientInformSubscription state fail k stanza = do | |||
1171 | 1171 | ||
1172 | do | 1172 | do |
1173 | cbu <- atomically $ readTVar (clientsByUser state) | 1173 | cbu <- atomically $ readTVar (clientsByUser state) |
1174 | putStrLn $ "cbu = " ++ show (fmap (fmap clientPid . networkClients) cbu) | 1174 | dput XJabber $ "cbu = " ++ show (fmap (fmap clientPid . networkClients) cbu) |
1175 | 1175 | ||
1176 | -- send roster update to clients | 1176 | -- send roster update to clients |
1177 | (clients,ktc,pktc) <- atomically $ do | 1177 | (clients,ktc,pktc) <- atomically $ do |
@@ -1183,7 +1183,7 @@ clientInformSubscription state fail k stanza = do | |||
1183 | return (cs,ktc,pktc) | 1183 | return (cs,ktc,pktc) |
1184 | forM_ clients $ \(ck, client) -> do | 1184 | forM_ clients $ \(ck, client) -> do |
1185 | is_intereseted <- atomically $ clientIsInterested client | 1185 | is_intereseted <- atomically $ clientIsInterested client |
1186 | putStrLn $ "clientIsInterested: "++show is_intereseted | 1186 | dput XJabber $ "clientIsInterested: "++show is_intereseted |
1187 | is_intereseted <- atomically $ clientIsInterested client | 1187 | is_intereseted <- atomically $ clientIsInterested client |
1188 | when is_intereseted $ do | 1188 | when is_intereseted $ do |
1189 | forM_ (Map.lookup ck ktc) $ \con -> do | 1189 | forM_ (Map.lookup ck ktc) $ \con -> do |
@@ -1211,7 +1211,7 @@ peerInformSubscription :: PresenceState | |||
1211 | -> StanzaWrap (LockedChan Event) | 1211 | -> StanzaWrap (LockedChan Event) |
1212 | -> IO () | 1212 | -> IO () |
1213 | peerInformSubscription state fail k stanza = do | 1213 | peerInformSubscription state fail k stanza = do |
1214 | putStrLn $ "TODO: peerInformSubscription" | 1214 | dput XJabber $ "TODO: peerInformSubscription" |
1215 | -- remove from solicited | 1215 | -- remove from solicited |
1216 | fromMaybe fail $ (stanzaFrom stanza) <&> \from -> do | 1216 | fromMaybe fail $ (stanzaFrom stanza) <&> \from -> do |
1217 | (ktc,cktc,cmap) <- atomically $ do | 1217 | (ktc,cktc,cmap) <- atomically $ do |
@@ -1219,7 +1219,7 @@ peerInformSubscription state fail k stanza = do | |||
1219 | cktc <- readTVar (ckeyToChan state) | 1219 | cktc <- readTVar (ckeyToChan state) |
1220 | cmap <- readTVar (clients state) | 1220 | cmap <- readTVar (clients state) |
1221 | return (pktc,cktc,cmap) | 1221 | return (pktc,cktc,cmap) |
1222 | fromMaybe fail $ (Map.lookup k ktc) | 1222 | fromMaybe fail $ Map.lookup k ktc |
1223 | <&> \(Conn { connChan=sender_chan | 1223 | <&> \(Conn { connChan=sender_chan |
1224 | , auxData =ConnectionData (Left laddr) ctyp profile}) -> do | 1224 | , auxData =ConnectionData (Left laddr) ctyp profile}) -> do |
1225 | (_,(from_u,from_h,_)) <- rewriteJIDForClient laddr from [] | 1225 | (_,(from_u,from_h,_)) <- rewriteJIDForClient laddr from [] |
@@ -1232,11 +1232,13 @@ peerInformSubscription state fail k stanza = do | |||
1232 | -- should probably mean unsubscribed for all users. | 1232 | -- should probably mean unsubscribed for all users. |
1233 | -- This would allow us to answer anonymous probes with 'unsubscribed'. | 1233 | -- This would allow us to answer anonymous probes with 'unsubscribed'. |
1234 | fromMaybe fail $ muser <&> \user -> do | 1234 | fromMaybe fail $ muser <&> \user -> do |
1235 | |||
1235 | addrs <- resolvePeer from_h | 1236 | addrs <- resolvePeer from_h |
1236 | was_solicited <- removeFromRosterFile ConfigFiles.modifySolicited user profile from'' addrs | 1237 | was_solicited <- removeFromRosterFile ConfigFiles.modifySolicited user profile from'' addrs |
1238 | |||
1237 | subs <- resolvedFromRoster ConfigFiles.getSubscribers user profile | 1239 | subs <- resolvedFromRoster ConfigFiles.getSubscribers user profile |
1238 | let is_sub = not . null $ map (from_u,) addrs `intersect` subs | 1240 | let is_sub = not . null $ map (from_u,) addrs `intersect` subs |
1239 | putStrLn $ "DEBUG peerInformSubscription (is_sub,typ)=" ++ show (is_sub,stanzaType stanza) | 1241 | dput XJabber $ "DEBUG peerInformSubscription (is_sub,typ)=" ++ show (is_sub,stanzaType stanza) |
1240 | let (relationship,addf,remf) = | 1242 | let (relationship,addf,remf) = |
1241 | case stanzaType stanza of | 1243 | case stanzaType stanza of |
1242 | PresenceInformSubscription True -> | 1244 | PresenceInformSubscription True -> |