diff options
author | joe <joe@jerkface.net> | 2013-07-15 14:22:37 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2013-07-15 14:22:37 -0400 |
commit | be81364d881a30508dceeb0f100bc1da0597d859 (patch) | |
tree | a4272c8f827e6b5209994feb9a58e80b3f3c49b2 /Presence/main.hs | |
parent | 43d147c7470edea26656987b8b16d08beae93e45 (diff) |
Moved all output to module: Logging
Diffstat (limited to 'Presence/main.hs')
-rw-r--r-- | Presence/main.hs | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/Presence/main.hs b/Presence/main.hs index 83f11df3..ef6a0e66 100644 --- a/Presence/main.hs +++ b/Presence/main.hs | |||
@@ -31,6 +31,7 @@ import Data.HList | |||
31 | import Control.Exception hiding (catch) | 31 | import Control.Exception hiding (catch) |
32 | import LocalPeerCred | 32 | import LocalPeerCred |
33 | import System.Posix.User | 33 | import System.Posix.User |
34 | import Logging | ||
34 | import qualified Data.Set as Set | 35 | import qualified Data.Set as Set |
35 | import Data.Set as Set (Set,(\\)) | 36 | import Data.Set as Set (Set,(\\)) |
36 | import qualified Data.Map as Map | 37 | import qualified Data.Map as Map |
@@ -43,7 +44,7 @@ import Control.Monad.IO.Class | |||
43 | 44 | ||
44 | import ByteStringOperators | 45 | import ByteStringOperators |
45 | import qualified Data.ByteString.Lazy.Char8 as L | 46 | import qualified Data.ByteString.Lazy.Char8 as L |
46 | import Data.ByteString.Lazy.Char8 as L (ByteString,putStrLn) | 47 | import Data.ByteString.Lazy.Char8 as L (ByteString) |
47 | import qualified Prelude | 48 | import qualified Prelude |
48 | import Prelude hiding (putStrLn) | 49 | import Prelude hiding (putStrLn) |
49 | import System.Environment | 50 | import System.Environment |
@@ -149,7 +150,7 @@ instance JabberClientSession ClientSession where | |||
149 | -- muid <- getLocalPeerCred sock | 150 | -- muid <- getLocalPeerCred sock |
150 | addr <- getPeerName sock | 151 | addr <- getPeerName sock |
151 | muid <- getLocalPeerCred' addr | 152 | muid <- getLocalPeerCred' addr |
152 | L.putStrLn $ "CLIENT SESSION: open " <++> bshow muid | 153 | debugL $ "CLIENT SESSION: open " <++> bshow muid |
153 | uid_ref <- newIORef muid | 154 | uid_ref <- newIORef muid |
154 | (mtty,pid) <- getTTYandPID muid | 155 | (mtty,pid) <- getTTYandPID muid |
155 | res_ref <- newIORef mtty | 156 | res_ref <- newIORef mtty |
@@ -171,7 +172,7 @@ instance JabberClientSession ClientSession where | |||
171 | rsc <- readIORef (unix_resource s) | 172 | rsc <- readIORef (unix_resource s) |
172 | let rsc' = maybe wanted_resource id rsc | 173 | let rsc' = maybe wanted_resource id rsc |
173 | writeIORef (unix_resource s) (Just rsc') | 174 | writeIORef (unix_resource s) (Just rsc') |
174 | L.putStrLn $ "CLIENT SESSION: resource " <++> rsc' | 175 | debugL $ "CLIENT SESSION: resource " <++> rsc' |
175 | 176 | ||
176 | getJID s = do | 177 | getJID s = do |
177 | let host = localhost s | 178 | let host = localhost s |
@@ -179,7 +180,7 @@ instance JabberClientSession ClientSession where | |||
179 | 180 | ||
180 | rsc <- readIORef (unix_resource s) | 181 | rsc <- readIORef (unix_resource s) |
181 | -- let jid = user <++> "@" <++> host <++?> "/" <++$> rsc | 182 | -- let jid = user <++> "@" <++> host <++?> "/" <++$> rsc |
182 | -- L.putStrLn $ "CLIENT SESSION: jid " <++> L.show (JID (Just user) host rsc) | 183 | -- debugL $ "CLIENT SESSION: jid " <++> L.show (JID (Just user) host rsc) |
183 | return (JID (Just user) host rsc) | 184 | return (JID (Just user) host rsc) |
184 | 185 | ||
185 | closeSession session = do | 186 | closeSession session = do |
@@ -187,7 +188,7 @@ instance JabberClientSession ClientSession where | |||
187 | cs <- readTVar (chans session) | 188 | cs <- readTVar (chans session) |
188 | forM_ cs $ \(RefCountedChan c) -> do | 189 | forM_ cs $ \(RefCountedChan c) -> do |
189 | unsubscribeToChan c | 190 | unsubscribeToChan c |
190 | L.putStrLn "CLIENT SESSION: close" | 191 | debugL "CLIENT SESSION: close" |
191 | 192 | ||
192 | subscribe session Nothing = do | 193 | subscribe session Nothing = do |
193 | let tmvar = localSubscriber (presence_state session) | 194 | let tmvar = localSubscriber (presence_state session) |
@@ -210,7 +211,7 @@ instance JabberClientSession ClientSession where | |||
210 | 211 | ||
211 | forCachedPresence s action = do | 212 | forCachedPresence s action = do |
212 | jid <- getJID s | 213 | jid <- getJID s |
213 | L.putStrLn $ "forCachedPresence "<++> bshow jid | 214 | debugL $ "forCachedPresence "<++> bshow jid |
214 | withJust (name jid) $ \user -> do | 215 | withJust (name jid) $ \user -> do |
215 | let parseHostNameJID' str = do | 216 | let parseHostNameJID' str = do |
216 | handle (\(SomeException _) -> return Nothing) | 217 | handle (\(SomeException _) -> return Nothing) |
@@ -220,19 +221,19 @@ instance JabberClientSession ClientSession where | |||
220 | fmap catMaybes (mapM parseHostNameJID' buddies) | 221 | fmap catMaybes (mapM parseHostNameJID' buddies) |
221 | remotes <- readTVarIO . remoteUsers . presence_state $ s | 222 | remotes <- readTVarIO . remoteUsers . presence_state $ s |
222 | forM_ buddies $ \buddy -> do | 223 | forM_ buddies $ \buddy -> do |
223 | L.putStrLn $ "forCachedPresence buddy = "<++> bshow buddy | 224 | debugL $ "forCachedPresence buddy = "<++> bshow buddy |
224 | let mjids = fmap snd $ Map.lookup (peer buddy) remotes | 225 | let mjids = fmap snd $ Map.lookup (peer buddy) remotes |
225 | jids <- maybe (return MM.empty) readTVarIO mjids | 226 | jids <- maybe (return MM.empty) readTVarIO mjids |
226 | L.putStrLn $ "forCachedPresence jids = "<++> bshow jids | 227 | debugL $ "forCachedPresence jids = "<++> bshow jids |
227 | withJust (splitResource buddy) $ \(buddyU,_) -> do | 228 | withJust (splitResource buddy) $ \(buddyU,_) -> do |
228 | forM_ (Set.toList . MM.lookup buddyU $ jids) $ \(rsc,status) -> do | 229 | forM_ (Set.toList . MM.lookup buddyU $ jids) $ \(rsc,status) -> do |
229 | let p = Presence buddy status | 230 | let p = Presence buddy status |
230 | L.putStrLn $ "cached presence: " <++> bshow p | 231 | debugL $ "cached presence: " <++> bshow p |
231 | action p | 232 | action p |
232 | 233 | ||
233 | sendPending s = do | 234 | sendPending s = do |
234 | jid <- getJID s | 235 | jid <- getJID s |
235 | putStrLn $ "sendPending "<++> bshow jid | 236 | debugL $ "sendPending "<++> bshow jid |
236 | flip (maybe (return ())) (name jid) $ \user -> do | 237 | flip (maybe (return ())) (name jid) $ \user -> do |
237 | pending <- ConfigFiles.getPending user | 238 | pending <- ConfigFiles.getPending user |
238 | let getRChan = do | 239 | let getRChan = do |
@@ -279,7 +280,7 @@ instance JabberClientSession ClientSession where | |||
279 | handleIO (\e -> return False) $ do | 280 | handleIO (\e -> return False) $ do |
280 | user <- readIORef (unix_uid s) >>= getJabberUserForId | 281 | user <- readIORef (unix_uid s) >>= getJabberUserForId |
281 | subs <- ConfigFiles.getSubscribers user | 282 | subs <- ConfigFiles.getSubscribers user |
282 | putStrLn $ "isSubscribed parsing: "<++>contact | 283 | debugL $ "isSubscribed parsing: "<++>contact |
283 | cjid <- parseHostNameJID contact | 284 | cjid <- parseHostNameJID contact |
284 | msubs <- mapM (cmpJID cjid) subs | 285 | msubs <- mapM (cmpJID cjid) subs |
285 | return (Nothing `elem` msubs) | 286 | return (Nothing `elem` msubs) |
@@ -288,7 +289,7 @@ instance JabberClientSession ClientSession where | |||
288 | handleIO (\e -> return False) $ do | 289 | handleIO (\e -> return False) $ do |
289 | user <- readIORef (unix_uid s) >>= getJabberUserForId | 290 | user <- readIORef (unix_uid s) >>= getJabberUserForId |
290 | subs <- ConfigFiles.getBuddies user | 291 | subs <- ConfigFiles.getBuddies user |
291 | putStrLn $ "isBuddy parsing: "<++>contact | 292 | debugL $ "isBuddy parsing: "<++>contact |
292 | cjid <- parseHostNameJID contact | 293 | cjid <- parseHostNameJID contact |
293 | msubs <- mapM (cmpJID cjid) subs | 294 | msubs <- mapM (cmpJID cjid) subs |
294 | return (Nothing `elem` msubs) | 295 | return (Nothing `elem` msubs) |
@@ -369,13 +370,13 @@ instance JabberPeerSession PeerSession where | |||
369 | 370 | ||
370 | newPeerSession (PeerSessions state) sock = do | 371 | newPeerSession (PeerSessions state) sock = do |
371 | me <- fmap (RemotePeer . withoutPort) (getPeerName sock) | 372 | me <- fmap (RemotePeer . withoutPort) (getPeerName sock) |
372 | L.putStrLn $ "PEER SESSION: open "<++>showPeer me | 373 | debugL $ "PEER SESSION: open "<++>showPeer me |
373 | let remotes = remoteUsers state | 374 | let remotes = remoteUsers state |
374 | jids <- atomically $ getRefFromMap remotes me (newTVar MM.empty) return | 375 | jids <- atomically $ getRefFromMap remotes me (newTVar MM.empty) return |
375 | return $ PeerSession jids me state | 376 | return $ PeerSession jids me state |
376 | 377 | ||
377 | closePeerSession session = do | 378 | closePeerSession session = do |
378 | L.putStrLn $ "PEER SESSION: close "<++>showPeer (peer_name session) | 379 | debugL $ "PEER SESSION: close "<++>showPeer (peer_name session) |
379 | let offline jid = Presence jid Offline | 380 | let offline jid = Presence jid Offline |
380 | unrefFromMap (remoteUsers . peer_global $ session) (peer_name session) | 381 | unrefFromMap (remoteUsers . peer_global $ session) (peer_name session) |
381 | $ do | 382 | $ do |
@@ -409,7 +410,7 @@ instance JabberPeerSession PeerSession where | |||
409 | 410 | ||
410 | sendPeerMessage session msg = do | 411 | sendPeerMessage session msg = do |
411 | let cons = remotePeers . peer_global $ session | 412 | let cons = remotePeers . peer_global $ session |
412 | putStrLn $ "sendPeerMessage " <++> bshow msg <++> " --> "<++>bshow (peer_name session) | 413 | debugL $ "sendPeerMessage " <++> bshow msg <++> " --> "<++>bshow (peer_name session) |
413 | sendMessage cons msg (peer_name session) | 414 | sendMessage cons msg (peer_name session) |
414 | 415 | ||
415 | getBuddies _ user = ConfigFiles.getBuddies user | 416 | getBuddies _ user = ConfigFiles.getBuddies user |
@@ -442,7 +443,7 @@ instance JabberPeerSession PeerSession where | |||
442 | hbuddy <- asHostNameJID buddy | 443 | hbuddy <- asHostNameJID buddy |
443 | modify user (cmpJID buddy) hbuddy | 444 | modify user (cmpJID buddy) hbuddy |
444 | was_pending <- addjid ConfigFiles.modifyPending user buddy | 445 | was_pending <- addjid ConfigFiles.modifyPending user buddy |
445 | putStrLn $ "processRequest was_pending="<++>bshow was_pending | 446 | debugL $ "processRequest was_pending="<++>bshow was_pending |
446 | -- "all available resources in accordence with section 8" | 447 | -- "all available resources in accordence with section 8" |
447 | -- Section 8 says (for presence of type "subscribe", the server MUST | 448 | -- Section 8 says (for presence of type "subscribe", the server MUST |
448 | -- adhere to the rules defined under Section 3 and summarized under | 449 | -- adhere to the rules defined under Section 3 and summarized under |
@@ -492,7 +493,7 @@ getJabberUserForId muid = | |||
492 | muid | 493 | muid |
493 | 494 | ||
494 | cmpJID newitem jid = do | 495 | cmpJID newitem jid = do |
495 | -- putStrLn $ "Comparing "<++>bshow jid | 496 | -- debugL $ "Comparing "<++>bshow jid |
496 | olditem <- parseHostNameJID jid | 497 | olditem <- parseHostNameJID jid |
497 | if olditem==newitem then return Nothing | 498 | if olditem==newitem then return Nothing |
498 | else return $ Just jid | 499 | else return $ Just jid |
@@ -505,7 +506,7 @@ addRawJid modify user jid = do | |||
505 | 506 | ||
506 | addJid modify user jid = do | 507 | addJid modify user jid = do |
507 | hjid <- asHostNameJID jid | 508 | hjid <- asHostNameJID jid |
508 | putStrLn $ "addJid (asHostNameJID) --> "<++>bshow hjid | 509 | debugL $ "addJid (asHostNameJID) --> "<++>bshow hjid |
509 | withJust hjid $ \hjid -> do | 510 | withJust hjid $ \hjid -> do |
510 | modify user (cmpJID jid) (Just hjid) | 511 | modify user (cmpJID jid) (Just hjid) |
511 | return () | 512 | return () |
@@ -598,10 +599,10 @@ update_presence locals_greedy subscribers state getStatus = | |||
598 | runMaybeT $ do | 599 | runMaybeT $ do |
599 | chan <- MaybeT . return $ locals_greedy | 600 | chan <- MaybeT . return $ locals_greedy |
600 | sendPresence chan jid status | 601 | sendPresence chan jid status |
601 | putStrLn $ bshow jid <++> " " <++> bshow status | 602 | debugL $ bshow jid <++> " " <++> bshow status |
602 | 603 | ||
603 | sendProbes state jid = do | 604 | sendProbes state jid = do |
604 | L.putStrLn $ "sending probes for " <++> bshow jid | 605 | debugL $ "sending probes for " <++> bshow jid |
605 | withJust (name jid) $ \user -> do | 606 | withJust (name jid) $ \user -> do |
606 | let parseHostNameJID' str = do | 607 | let parseHostNameJID' str = do |
607 | handle (\(SomeException _) -> return Nothing) | 608 | handle (\(SomeException _) -> return Nothing) |
@@ -609,7 +610,7 @@ sendProbes state jid = do | |||
609 | buddies <- do | 610 | buddies <- do |
610 | buddies <- ConfigFiles.getBuddies user | 611 | buddies <- ConfigFiles.getBuddies user |
611 | fmap catMaybes (mapM parseHostNameJID' buddies) | 612 | fmap catMaybes (mapM parseHostNameJID' buddies) |
612 | L.putStrLn $ "buddies for " <++> bshow jid <++> " = " <++> bshow buddies | 613 | debugL $ "buddies for " <++> bshow jid <++> " = " <++> bshow buddies |
613 | wanted <- do | 614 | wanted <- do |
614 | wanted <- ConfigFiles.getSolicited user | 615 | wanted <- ConfigFiles.getSolicited user |
615 | fmap catMaybes (mapM parseHostNameJID' wanted) | 616 | fmap catMaybes (mapM parseHostNameJID' wanted) |
@@ -621,7 +622,7 @@ sendProbes state jid = do | |||
621 | let noinfo = not (MM.member buddyU jids) | 622 | let noinfo = not (MM.member buddyU jids) |
622 | when noinfo $ do | 623 | when noinfo $ do |
623 | let msg = if got then PresenceProbe jid buddy else Solicitation jid buddy | 624 | let msg = if got then PresenceProbe jid buddy else Solicitation jid buddy |
624 | L.putStrLn $ "sendMessage " <++> bshow msg | 625 | debugL $ "sendMessage " <++> bshow msg |
625 | sendMessage (remotePeers state) msg (peer buddy) | 626 | sendMessage (remotePeers state) msg (peer buddy) |
626 | 627 | ||
627 | 628 | ||
@@ -651,7 +652,7 @@ track_login host state e = do | |||
651 | 652 | ||
652 | on_chvt state vtnum = do | 653 | on_chvt state vtnum = do |
653 | let tty = L.snoc "tty" $ intToDigit (fromIntegral vtnum) | 654 | let tty = L.snoc "tty" $ intToDigit (fromIntegral vtnum) |
654 | L.putStrLn $ "VT switch: " <++> tty | 655 | debugL $ "VT switch: " <++> tty |
655 | (users,subs,locals_greedy) <- atomically $ do | 656 | (users,subs,locals_greedy) <- atomically $ do |
656 | us <- readTVar $ activeUsers state | 657 | us <- readTVar $ activeUsers state |
657 | subs <- readTVar $ subscriberMap state | 658 | subs <- readTVar $ subscriberMap state |
@@ -694,19 +695,19 @@ start ip4or6 = do | |||
694 | 695 | ||
695 | threadDelay 1000 -- wait a moment to obtain current tty | 696 | threadDelay 1000 -- wait a moment to obtain current tty |
696 | dologin () | 697 | dologin () |
697 | putStrLn "\nHit enter to terminate...\n" | 698 | L.putStrLn "\nHit enter to terminate...\n" |
698 | getLine | 699 | getLine |
699 | killThread remotes | 700 | killThread remotes |
700 | quitListening clients | 701 | quitListening clients |
701 | quitListening peers | 702 | quitListening peers |
702 | -- threadDelay 1000 | 703 | -- threadDelay 1000 |
703 | putStrLn "closed listener." | 704 | debugL "closed listener." |
704 | unmonitorTTY mtty | 705 | unmonitorTTY mtty |
705 | putStrLn "unhooked tty monitor." | 706 | debugL "unhooked tty monitor." |
706 | #ifndef NOUTMP | 707 | #ifndef NOUTMP |
707 | removeWatch wd | 708 | removeWatch wd |
708 | #endif | 709 | #endif |
709 | putStrLn "Normal termination." | 710 | debugL "Normal termination." |
710 | 711 | ||
711 | sendUSR1 pid = do | 712 | sendUSR1 pid = do |
712 | signalProcess sigUSR1 pid | 713 | signalProcess sigUSR1 pid |
@@ -721,11 +722,11 @@ getStartupAction (p:ps) = do | |||
721 | where | 722 | where |
722 | onEr (SomeException _) = do | 723 | onEr (SomeException _) = do |
723 | pid <- getProcessID | 724 | pid <- getProcessID |
724 | putStrLn $ "starting pid = " <++> bshow pid | 725 | debugL $ "starting pid = " <++> bshow pid |
725 | handle (\(SomeException _) -> getStartupAction ps) | 726 | handle (\(SomeException _) -> getStartupAction ps) |
726 | (do | 727 | (do |
727 | writeFile p (show pid) | 728 | writeFile p (show pid) |
728 | putStrLn $ "writing " <++> bshow p | 729 | debugL $ "writing " <++> bshow p |
729 | -- start daemon | 730 | -- start daemon |
730 | return (Right p) ) | 731 | return (Right p) ) |
731 | 732 | ||