summaryrefslogtreecommitdiff
path: root/Presence
diff options
context:
space:
mode:
Diffstat (limited to 'Presence')
-rw-r--r--Presence/ControlMaybe.hs9
-rw-r--r--Presence/LocalPeerCred.hs6
-rw-r--r--Presence/XMPP.hs42
3 files changed, 32 insertions, 25 deletions
diff --git a/Presence/ControlMaybe.hs b/Presence/ControlMaybe.hs
index e277df12..37f6f93c 100644
--- a/Presence/ControlMaybe.hs
+++ b/Presence/ControlMaybe.hs
@@ -1,5 +1,9 @@
1{-# LANGUAGE ScopedTypeVariables #-}
1module ControlMaybe where 2module ControlMaybe where
2 3
4-- import GHC.IO.Exception (IOException(..))
5import Control.Exception as Exception (IOException(..),catch)
6
3withJust (Just x) f = f x 7withJust (Just x) f = f x
4withJust Nothing f = return () 8withJust Nothing f = return ()
5 9
@@ -8,3 +12,8 @@ whenJust acn f = do
8 withJust x f 12 withJust x f
9 13
10 14
15catchIO_ :: IO a -> IO a -> IO a
16catchIO_ a h = Exception.catch a (\(_ :: IOException) -> h)
17
18handleIO_ = flip catchIO_
19
diff --git a/Presence/LocalPeerCred.hs b/Presence/LocalPeerCred.hs
index d3b8d189..b6ec9491 100644
--- a/Presence/LocalPeerCred.hs
+++ b/Presence/LocalPeerCred.hs
@@ -57,7 +57,7 @@ getLocalPeerCred sock = do
57 addr <- getPeerName sock 57 addr <- getPeerName sock
58 muid <- getLocalPeerCred' addr 58 muid <- getLocalPeerCred' addr
59 case muid of 59 case muid of
60 Just uid -> return (Just uid) 60 Just (uid,inode) -> return (Just uid)
61 Nothing -> trace "proc failed." $ fmap (validate . CUid . fromIntegral . sndOf3) (getPeerCred sock) 61 Nothing -> trace "proc failed." $ fmap (validate . CUid . fromIntegral . sndOf3) (getPeerCred sock)
62 where sndOf3 (pid,uid,gid) = uid 62 where sndOf3 (pid,uid,gid) = uid
63 where 63 where
@@ -81,10 +81,12 @@ parseProcNet port host h = do
81 addr <- fmap parseHex $ listToMaybe zs 81 addr <- fmap parseHex $ listToMaybe zs
82 port <- fmap (fromIntegral . as16 . decode . parseHex) $ listToMaybe $ snd (Prelude.splitAt 1 zs) 82 port <- fmap (fromIntegral . as16 . decode . parseHex) $ listToMaybe $ snd (Prelude.splitAt 1 zs)
83 let ys' = snd (Prelude.splitAt 5 (tail ys)) 83 let ys' = snd (Prelude.splitAt 5 (tail ys))
84 ys'' = snd (Prelude.splitAt 2 ys')
84 uid <- listToMaybe ys' 85 uid <- listToMaybe ys'
86 inode <- listToMaybe ys''
85 let peer = (port,decode addr) 87 let peer = (port,decode addr)
86 user = toEnum (read (unpack uid) ::Int) ::UserID -- CUid . fromIntegral $ (read (unpack uid)::Int) 88 user = toEnum (read (unpack uid) ::Int) ::UserID -- CUid . fromIntegral $ (read (unpack uid)::Int)
87 return $ {- trace ("peer:"++show(peer,user)) -} (peer,user) 89 return $ {-trace ("peer:"++show(peer,user,inode))-} (peer,(user,inode))
88 ) 90 )
89 fmap snd . listToMaybe $ filter ((==(port,host)).fst) rs 91 fmap snd . listToMaybe $ filter ((==(port,host)).fst) rs
90 {- trace ("found: "++show u) -} 92 {- trace ("found: "++show u) -}
diff --git a/Presence/XMPP.hs b/Presence/XMPP.hs
index 3f81f000..d35e5617 100644
--- a/Presence/XMPP.hs
+++ b/Presence/XMPP.hs
@@ -241,21 +241,25 @@ tagName (EventBeginElement n _) = n
241tagName _ = "" 241tagName _ = ""
242 242
243handleIQSetBind session cmdChan stanza_id = do 243handleIQSetBind session cmdChan stanza_id = do
244 whenJust nextElement $ \child -> do 244 mchild <- nextElement
245 let unhandledBind = liftIO $ putStrLn $ "unhandled-bind: "++show child 245 case mchild of
246 case tagName child of 246 Just child -> do
247 "{urn:ietf:params:xml:ns:xmpp-bind}resource" 247 let unhandledBind = liftIO $ putStrLn $ "unhandled-bind: "++show child
248 -> do 248 case tagName child of
249 rsc <- lift content 249 "{urn:ietf:params:xml:ns:xmpp-bind}resource"
250 liftIO $ do 250 -> do
251 putStrLn $ "iq-set-bind-resource " ++ show rsc 251 rsc <- lift content
252 setResource session (L.fromChunks [S.encodeUtf8 rsc]) 252 liftIO $ do
253 jid <- getJID session 253 putStrLn $ "iq-set-bind-resource " ++ show rsc
254 atomically $ writeTChan cmdChan (Send $ iq_bind_reply stanza_id (toStrict $ L.decodeUtf8 $ L.show jid) ) 254 setResource session (L.fromChunks [S.encodeUtf8 rsc])
255 forCachedPresence session $ \presence -> do 255 jid <- getJID session
256 xs <- xmlifyPresenceForClient presence 256 atomically $ writeTChan cmdChan (Send $ iq_bind_reply stanza_id (toStrict $ L.decodeUtf8 $ L.show jid) )
257 atomically . writeTChan cmdChan . Send $ xs 257 forCachedPresence session $ \presence -> do
258 _ -> unhandledBind 258 xs <- xmlifyPresenceForClient presence
259 atomically . writeTChan cmdChan . Send $ xs
260 _ -> unhandledBind
261 Nothing -> do
262 liftIO $ putStrLn $ "empty bind request!"
259 263
260 264
261iq_session_reply host stanza_id = 265iq_session_reply host stanza_id =
@@ -598,14 +602,6 @@ fromPeer session = doNestingXML $ do
598 602
599 603
600 604
601{-
602seekRemotePeers :: XMPPConfig config =>
603 config -> TChan Presence -> IO ()
604seekRemotePeers config chan = do
605 putStrLn "unimplemented: seekRemotePeers"
606 -- TODO
607 return ()
608-}
609 605
610data OutBoundMessage = OutBoundPresence Presence | PresenceProbe JID JID 606data OutBoundMessage = OutBoundPresence Presence | PresenceProbe JID JID
611 deriving Prelude.Show 607 deriving Prelude.Show