diff options
author | joe <joe@jerkface.net> | 2013-07-10 23:50:14 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2013-07-10 23:50:14 -0400 |
commit | e532b9d2ae3263513d7de4aec4913e234b3f3b46 (patch) | |
tree | 6d7368fe428579e6cd2a3005b7db8a0dc9786f02 /Presence/main.hs | |
parent | 8ad4ea00e0fc2bbbf768bfc013c67b271a1da67d (diff) |
Send subscription requests to client for approval, and then
forward the answer to the remote peer. Todo: related roster update.
Diffstat (limited to 'Presence/main.hs')
-rw-r--r-- | Presence/main.hs | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/Presence/main.hs b/Presence/main.hs index eab02e88..5cccffea 100644 --- a/Presence/main.hs +++ b/Presence/main.hs | |||
@@ -207,6 +207,23 @@ instance JabberClientSession ClientSession where | |||
207 | L.putStrLn $ "cached presence: " <++> bshow p | 207 | L.putStrLn $ "cached presence: " <++> bshow p |
208 | action p | 208 | action p |
209 | 209 | ||
210 | sendPending s = do | ||
211 | jid <- getJID s | ||
212 | putStrLn $ "sendPending "<++> bshow jid | ||
213 | flip (maybe (return ())) (name jid) $ \user -> do | ||
214 | pending <- ConfigFiles.getPending user | ||
215 | let getRChan = do | ||
216 | let rchan = rosterChannel . presence_state $ s | ||
217 | isempty <- isEmptyTMVar rchan | ||
218 | if (not isempty) | ||
219 | then do | ||
220 | (_,ch) <- readTMVar rchan | ||
221 | return . Just $ ch | ||
222 | else return Nothing | ||
223 | atomically $ do | ||
224 | whenJust getRChan $ \rchan -> do | ||
225 | forM_ pending (writeTChan rchan . PendingBuddy user) | ||
226 | |||
210 | addSolicited s jid_str jid = do | 227 | addSolicited s jid_str jid = do |
211 | me <- getJID s | 228 | me <- getJID s |
212 | withJust (name me) $ \user -> do | 229 | withJust (name me) $ \user -> do |
@@ -247,6 +264,21 @@ instance JabberClientSession ClientSession where | |||
247 | msubs <- mapM (cmpJID cjid) subs | 264 | msubs <- mapM (cmpJID cjid) subs |
248 | return (Nothing `elem` msubs) | 265 | return (Nothing `elem` msubs) |
249 | 266 | ||
267 | approveSubscriber s contact = do | ||
268 | user <- readIORef (unix_uid s) >>= getJabberUserForId | ||
269 | cjid <- parseHostNameJID contact | ||
270 | let rmjid modify user buddy = modify user (cmpJID buddy) Nothing | ||
271 | addRawJid ConfigFiles.modifySubscribers user contact -- add subscribers | ||
272 | rmjid ConfigFiles.modifyPending user cjid | ||
273 | rmjid ConfigFiles.modifyOthers user cjid | ||
274 | -- TODO | ||
275 | -- roster push (to other clients, or do we include the approver?) | ||
276 | sendMessage (outGoingConnections . presence_state $ s) | ||
277 | (Approval (JID (Just user) LocalHost Nothing) | ||
278 | cjid) | ||
279 | (peer cjid) | ||
280 | |||
281 | |||
250 | tupleToJID (user,tty,pid) = jid user LocalHost tty | 282 | tupleToJID (user,tty,pid) = jid user LocalHost tty |
251 | 283 | ||
252 | data PeerSession = PeerSession { | 284 | data PeerSession = PeerSession { |
@@ -330,7 +362,29 @@ instance JabberPeerSession PeerSession where | |||
330 | (_,ch) <- readTMVar rchan | 362 | (_,ch) <- readTMVar rchan |
331 | writeTChan ch (NewBuddy user buddy) | 363 | writeTChan ch (NewBuddy user buddy) |
332 | return () | 364 | return () |
333 | 365 | processRequest session user buddy = do | |
366 | let addjid modify user buddy = do | ||
367 | hbuddy <- asHostNameJID buddy | ||
368 | modify user (cmpJID buddy) hbuddy | ||
369 | was_pending <- addjid ConfigFiles.modifyPending user buddy | ||
370 | putStrLn $ "processRequest was_pending="<++>bshow was_pending | ||
371 | -- "all available resources in accordence with section 8" | ||
372 | -- Section 8 says (for presence of type "subscribe", the server MUST | ||
373 | -- adhere to the rules defined under Section 3 and summarized under | ||
374 | -- Appendix A. | ||
375 | -- Appendex A.3.1 says | ||
376 | -- contact ∈ subscribers --> SHOULD NOT, already handled | ||
377 | -- contact ∉ subscribers & contact ∈ pending --> SHOULD NOT | ||
378 | -- contact ∉ subscribers & contact ∉ pending --> MUST | ||
379 | when (not was_pending) $ do | ||
380 | let rchan = rosterChannel . peer_global $ session | ||
381 | mbuddy <- asHostNameJID buddy | ||
382 | withJust mbuddy $ \buddy -> do | ||
383 | atomically $ do | ||
384 | isempty <- isEmptyTMVar rchan | ||
385 | when (not isempty) $ do | ||
386 | (_,ch) <- readTMVar rchan | ||
387 | writeTChan ch (PendingBuddy user buddy) | ||
334 | 388 | ||
335 | 389 | ||
336 | data RefCountedChan = forall a. RefCountedChan (TMVar (RefCount,TChan a)) | 390 | data RefCountedChan = forall a. RefCountedChan (TMVar (RefCount,TChan a)) |